1 |
efrain |
1 |
/* AUTO-GENERATED. DO NOT MODIFY. */
|
|
|
2 |
/*
|
|
|
3 |
|
|
|
4 |
The MIT License (MIT)
|
|
|
5 |
|
|
|
6 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
7 |
|
|
|
8 |
Permission is hereby granted, free of charge, to any person
|
|
|
9 |
obtaining a copy of this software and associated documentation files
|
|
|
10 |
(the "Software"), to deal in the Software without restriction,
|
|
|
11 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
12 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
13 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
14 |
subject to the following conditions:
|
|
|
15 |
|
|
|
16 |
The above copyright notice and this permission notice shall be
|
|
|
17 |
included in all copies or substantial portions of the Software.
|
|
|
18 |
|
|
|
19 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
21 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
23 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
24 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
25 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
26 |
SOFTWARE.
|
|
|
27 |
|
|
|
28 |
JS Beautifier
|
|
|
29 |
---------------
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
Written by Einar Lielmanis, <einar@beautifier.io>
|
|
|
33 |
https://beautifier.io/
|
|
|
34 |
|
|
|
35 |
Originally converted to javascript by Vital, <vital76@gmail.com>
|
|
|
36 |
"End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
|
|
|
37 |
Parsing improvements for brace-less statements by Liam Newman <bitwiseman@beautifier.io>
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
Usage:
|
|
|
41 |
js_beautify(js_source_text);
|
|
|
42 |
js_beautify(js_source_text, options);
|
|
|
43 |
|
|
|
44 |
The options are:
|
|
|
45 |
indent_size (default 4) - indentation size,
|
|
|
46 |
indent_char (default space) - character to indent with,
|
|
|
47 |
preserve_newlines (default true) - whether existing line breaks should be preserved,
|
|
|
48 |
max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
|
|
|
49 |
|
|
|
50 |
jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
|
|
|
51 |
|
|
|
52 |
jslint_happy !jslint_happy
|
|
|
53 |
---------------------------------
|
|
|
54 |
function () function()
|
|
|
55 |
|
|
|
56 |
switch () { switch() {
|
|
|
57 |
case 1: case 1:
|
|
|
58 |
break; break;
|
|
|
59 |
} }
|
|
|
60 |
|
|
|
61 |
space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
|
|
|
62 |
NOTE: This option is overridden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
|
|
|
63 |
|
|
|
64 |
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline"
|
|
|
65 |
put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
|
|
|
66 |
preserve-inline will try to preserve inline blocks of curly braces
|
|
|
67 |
|
|
|
68 |
space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
|
|
|
69 |
|
|
|
70 |
unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
|
|
|
71 |
|
|
|
72 |
wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
|
|
|
73 |
NOTE: This is not a hard limit. Lines will continue until a point where a newline would
|
|
|
74 |
be preserved if it were present.
|
|
|
75 |
|
|
|
76 |
end_with_newline (default false) - end output with a newline
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
e.g
|
|
|
80 |
|
|
|
81 |
js_beautify(js_source_text, {
|
|
|
82 |
'indent_size': 1,
|
|
|
83 |
'indent_char': '\t'
|
|
|
84 |
});
|
|
|
85 |
|
|
|
86 |
*/
|
|
|
87 |
|
|
|
88 |
(function() {
|
|
|
89 |
|
|
|
90 |
/* GENERATED_BUILD_OUTPUT */
|
|
|
91 |
var legacy_beautify_js;
|
|
|
92 |
/******/ (function() { // webpackBootstrap
|
|
|
93 |
/******/ "use strict";
|
|
|
94 |
/******/ var __webpack_modules__ = ([
|
|
|
95 |
/* 0 */
|
|
|
96 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
97 |
|
|
|
98 |
/*jshint node:true */
|
|
|
99 |
/*
|
|
|
100 |
|
|
|
101 |
The MIT License (MIT)
|
|
|
102 |
|
|
|
103 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
104 |
|
|
|
105 |
Permission is hereby granted, free of charge, to any person
|
|
|
106 |
obtaining a copy of this software and associated documentation files
|
|
|
107 |
(the "Software"), to deal in the Software without restriction,
|
|
|
108 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
109 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
110 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
111 |
subject to the following conditions:
|
|
|
112 |
|
|
|
113 |
The above copyright notice and this permission notice shall be
|
|
|
114 |
included in all copies or substantial portions of the Software.
|
|
|
115 |
|
|
|
116 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
117 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
118 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
119 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
120 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
121 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
122 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
123 |
SOFTWARE.
|
|
|
124 |
*/
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
var Beautifier = (__webpack_require__(1).Beautifier),
|
|
|
129 |
Options = (__webpack_require__(5).Options);
|
|
|
130 |
|
|
|
131 |
function js_beautify(js_source_text, options) {
|
|
|
132 |
var beautifier = new Beautifier(js_source_text, options);
|
|
|
133 |
return beautifier.beautify();
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
module.exports = js_beautify;
|
|
|
137 |
module.exports.defaultOptions = function() {
|
|
|
138 |
return new Options();
|
|
|
139 |
};
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
/***/ }),
|
|
|
143 |
/* 1 */
|
|
|
144 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
145 |
|
|
|
146 |
/*jshint node:true */
|
|
|
147 |
/*
|
|
|
148 |
|
|
|
149 |
The MIT License (MIT)
|
|
|
150 |
|
|
|
151 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
152 |
|
|
|
153 |
Permission is hereby granted, free of charge, to any person
|
|
|
154 |
obtaining a copy of this software and associated documentation files
|
|
|
155 |
(the "Software"), to deal in the Software without restriction,
|
|
|
156 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
157 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
158 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
159 |
subject to the following conditions:
|
|
|
160 |
|
|
|
161 |
The above copyright notice and this permission notice shall be
|
|
|
162 |
included in all copies or substantial portions of the Software.
|
|
|
163 |
|
|
|
164 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
165 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
166 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
167 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
168 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
169 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
170 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
171 |
SOFTWARE.
|
|
|
172 |
*/
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
var Output = (__webpack_require__(2).Output);
|
|
|
177 |
var Token = (__webpack_require__(3).Token);
|
|
|
178 |
var acorn = __webpack_require__(4);
|
|
|
179 |
var Options = (__webpack_require__(5).Options);
|
|
|
180 |
var Tokenizer = (__webpack_require__(7).Tokenizer);
|
|
|
181 |
var line_starters = (__webpack_require__(7).line_starters);
|
|
|
182 |
var positionable_operators = (__webpack_require__(7).positionable_operators);
|
|
|
183 |
var TOKEN = (__webpack_require__(7).TOKEN);
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
function in_array(what, arr) {
|
|
|
187 |
return arr.indexOf(what) !== -1;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
function ltrim(s) {
|
|
|
191 |
return s.replace(/^\s+/g, '');
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
function generateMapFromStrings(list) {
|
|
|
195 |
var result = {};
|
|
|
196 |
for (var x = 0; x < list.length; x++) {
|
|
|
197 |
// make the mapped names underscored instead of dash
|
|
|
198 |
result[list[x].replace(/-/g, '_')] = list[x];
|
|
|
199 |
}
|
|
|
200 |
return result;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
function reserved_word(token, word) {
|
|
|
204 |
return token && token.type === TOKEN.RESERVED && token.text === word;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
function reserved_array(token, words) {
|
|
|
208 |
return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
|
|
|
209 |
}
|
|
|
210 |
// Unsure of what they mean, but they work. Worth cleaning up in future.
|
|
|
211 |
var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
|
|
|
212 |
|
|
|
213 |
var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
|
|
|
214 |
|
|
|
215 |
// Generate map from array
|
|
|
216 |
var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
|
|
|
217 |
|
|
|
218 |
var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
|
|
|
219 |
|
|
|
220 |
var MODE = {
|
|
|
221 |
BlockStatement: 'BlockStatement', // 'BLOCK'
|
|
|
222 |
Statement: 'Statement', // 'STATEMENT'
|
|
|
223 |
ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
|
|
|
224 |
ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
|
|
|
225 |
ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
|
|
|
226 |
Conditional: 'Conditional', //'(COND-EXPRESSION)',
|
|
|
227 |
Expression: 'Expression' //'(EXPRESSION)'
|
|
|
228 |
};
|
|
|
229 |
|
|
|
230 |
function remove_redundant_indentation(output, frame) {
|
|
|
231 |
// This implementation is effective but has some issues:
|
|
|
232 |
// - can cause line wrap to happen too soon due to indent removal
|
|
|
233 |
// after wrap points are calculated
|
|
|
234 |
// These issues are minor compared to ugly indentation.
|
|
|
235 |
|
|
|
236 |
if (frame.multiline_frame ||
|
|
|
237 |
frame.mode === MODE.ForInitializer ||
|
|
|
238 |
frame.mode === MODE.Conditional) {
|
|
|
239 |
return;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
// remove one indent from each line inside this section
|
|
|
243 |
output.remove_indent(frame.start_line_index);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
// we could use just string.split, but
|
|
|
247 |
// IE doesn't like returning empty strings
|
|
|
248 |
function split_linebreaks(s) {
|
|
|
249 |
//return s.split(/\x0d\x0a|\x0a/);
|
|
|
250 |
|
|
|
251 |
s = s.replace(acorn.allLineBreaks, '\n');
|
|
|
252 |
var out = [],
|
|
|
253 |
idx = s.indexOf("\n");
|
|
|
254 |
while (idx !== -1) {
|
|
|
255 |
out.push(s.substring(0, idx));
|
|
|
256 |
s = s.substring(idx + 1);
|
|
|
257 |
idx = s.indexOf("\n");
|
|
|
258 |
}
|
|
|
259 |
if (s.length) {
|
|
|
260 |
out.push(s);
|
|
|
261 |
}
|
|
|
262 |
return out;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
function is_array(mode) {
|
|
|
266 |
return mode === MODE.ArrayLiteral;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
function is_expression(mode) {
|
|
|
270 |
return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
function all_lines_start_with(lines, c) {
|
|
|
274 |
for (var i = 0; i < lines.length; i++) {
|
|
|
275 |
var line = lines[i].trim();
|
|
|
276 |
if (line.charAt(0) !== c) {
|
|
|
277 |
return false;
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
return true;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
function each_line_matches_indent(lines, indent) {
|
|
|
284 |
var i = 0,
|
|
|
285 |
len = lines.length,
|
|
|
286 |
line;
|
|
|
287 |
for (; i < len; i++) {
|
|
|
288 |
line = lines[i];
|
|
|
289 |
// allow empty lines to pass through
|
|
|
290 |
if (line && line.indexOf(indent) !== 0) {
|
|
|
291 |
return false;
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
return true;
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
function Beautifier(source_text, options) {
|
|
|
299 |
options = options || {};
|
|
|
300 |
this._source_text = source_text || '';
|
|
|
301 |
|
|
|
302 |
this._output = null;
|
|
|
303 |
this._tokens = null;
|
|
|
304 |
this._last_last_text = null;
|
|
|
305 |
this._flags = null;
|
|
|
306 |
this._previous_flags = null;
|
|
|
307 |
|
|
|
308 |
this._flag_store = null;
|
|
|
309 |
this._options = new Options(options);
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
Beautifier.prototype.create_flags = function(flags_base, mode) {
|
|
|
313 |
var next_indent_level = 0;
|
|
|
314 |
if (flags_base) {
|
|
|
315 |
next_indent_level = flags_base.indentation_level;
|
|
|
316 |
if (!this._output.just_added_newline() &&
|
|
|
317 |
flags_base.line_indent_level > next_indent_level) {
|
|
|
318 |
next_indent_level = flags_base.line_indent_level;
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
var next_flags = {
|
|
|
323 |
mode: mode,
|
|
|
324 |
parent: flags_base,
|
|
|
325 |
last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
|
|
|
326 |
last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
|
|
|
327 |
declaration_statement: false,
|
|
|
328 |
declaration_assignment: false,
|
|
|
329 |
multiline_frame: false,
|
|
|
330 |
inline_frame: false,
|
|
|
331 |
if_block: false,
|
|
|
332 |
else_block: false,
|
|
|
333 |
class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
|
|
|
334 |
do_block: false,
|
|
|
335 |
do_while: false,
|
|
|
336 |
import_block: false,
|
|
|
337 |
in_case_statement: false, // switch(..){ INSIDE HERE }
|
|
|
338 |
in_case: false, // we're on the exact line with "case 0:"
|
|
|
339 |
case_body: false, // the indented case-action block
|
|
|
340 |
case_block: false, // the indented case-action block is wrapped with {}
|
|
|
341 |
indentation_level: next_indent_level,
|
|
|
342 |
alignment: 0,
|
|
|
343 |
line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
|
|
|
344 |
start_line_index: this._output.get_line_number(),
|
|
|
345 |
ternary_depth: 0
|
|
|
346 |
};
|
|
|
347 |
return next_flags;
|
|
|
348 |
};
|
|
|
349 |
|
|
|
350 |
Beautifier.prototype._reset = function(source_text) {
|
|
|
351 |
var baseIndentString = source_text.match(/^[\t ]*/)[0];
|
|
|
352 |
|
|
|
353 |
this._last_last_text = ''; // pre-last token text
|
|
|
354 |
this._output = new Output(this._options, baseIndentString);
|
|
|
355 |
|
|
|
356 |
// If testing the ignore directive, start with output disable set to true
|
|
|
357 |
this._output.raw = this._options.test_output_raw;
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
// Stack of parsing/formatting states, including MODE.
|
|
|
361 |
// We tokenize, parse, and output in an almost purely a forward-only stream of token input
|
|
|
362 |
// and formatted output. This makes the beautifier less accurate than full parsers
|
|
|
363 |
// but also far more tolerant of syntax errors.
|
|
|
364 |
//
|
|
|
365 |
// For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
|
|
|
366 |
// MODE.BlockStatement on the the stack, even though it could be object literal. If we later
|
|
|
367 |
// encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
|
|
|
368 |
// most full parsers would die, but the beautifier gracefully falls back to
|
|
|
369 |
// MODE.BlockStatement and continues on.
|
|
|
370 |
this._flag_store = [];
|
|
|
371 |
this.set_mode(MODE.BlockStatement);
|
|
|
372 |
var tokenizer = new Tokenizer(source_text, this._options);
|
|
|
373 |
this._tokens = tokenizer.tokenize();
|
|
|
374 |
return source_text;
|
|
|
375 |
};
|
|
|
376 |
|
|
|
377 |
Beautifier.prototype.beautify = function() {
|
|
|
378 |
// if disabled, return the input unchanged.
|
|
|
379 |
if (this._options.disabled) {
|
|
|
380 |
return this._source_text;
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
var sweet_code;
|
|
|
384 |
var source_text = this._reset(this._source_text);
|
|
|
385 |
|
|
|
386 |
var eol = this._options.eol;
|
|
|
387 |
if (this._options.eol === 'auto') {
|
|
|
388 |
eol = '\n';
|
|
|
389 |
if (source_text && acorn.lineBreak.test(source_text || '')) {
|
|
|
390 |
eol = source_text.match(acorn.lineBreak)[0];
|
|
|
391 |
}
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
var current_token = this._tokens.next();
|
|
|
395 |
while (current_token) {
|
|
|
396 |
this.handle_token(current_token);
|
|
|
397 |
|
|
|
398 |
this._last_last_text = this._flags.last_token.text;
|
|
|
399 |
this._flags.last_token = current_token;
|
|
|
400 |
|
|
|
401 |
current_token = this._tokens.next();
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
sweet_code = this._output.get_code(eol);
|
|
|
405 |
|
|
|
406 |
return sweet_code;
|
|
|
407 |
};
|
|
|
408 |
|
|
|
409 |
Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
|
|
|
410 |
if (current_token.type === TOKEN.START_EXPR) {
|
|
|
411 |
this.handle_start_expr(current_token);
|
|
|
412 |
} else if (current_token.type === TOKEN.END_EXPR) {
|
|
|
413 |
this.handle_end_expr(current_token);
|
|
|
414 |
} else if (current_token.type === TOKEN.START_BLOCK) {
|
|
|
415 |
this.handle_start_block(current_token);
|
|
|
416 |
} else if (current_token.type === TOKEN.END_BLOCK) {
|
|
|
417 |
this.handle_end_block(current_token);
|
|
|
418 |
} else if (current_token.type === TOKEN.WORD) {
|
|
|
419 |
this.handle_word(current_token);
|
|
|
420 |
} else if (current_token.type === TOKEN.RESERVED) {
|
|
|
421 |
this.handle_word(current_token);
|
|
|
422 |
} else if (current_token.type === TOKEN.SEMICOLON) {
|
|
|
423 |
this.handle_semicolon(current_token);
|
|
|
424 |
} else if (current_token.type === TOKEN.STRING) {
|
|
|
425 |
this.handle_string(current_token);
|
|
|
426 |
} else if (current_token.type === TOKEN.EQUALS) {
|
|
|
427 |
this.handle_equals(current_token);
|
|
|
428 |
} else if (current_token.type === TOKEN.OPERATOR) {
|
|
|
429 |
this.handle_operator(current_token);
|
|
|
430 |
} else if (current_token.type === TOKEN.COMMA) {
|
|
|
431 |
this.handle_comma(current_token);
|
|
|
432 |
} else if (current_token.type === TOKEN.BLOCK_COMMENT) {
|
|
|
433 |
this.handle_block_comment(current_token, preserve_statement_flags);
|
|
|
434 |
} else if (current_token.type === TOKEN.COMMENT) {
|
|
|
435 |
this.handle_comment(current_token, preserve_statement_flags);
|
|
|
436 |
} else if (current_token.type === TOKEN.DOT) {
|
|
|
437 |
this.handle_dot(current_token);
|
|
|
438 |
} else if (current_token.type === TOKEN.EOF) {
|
|
|
439 |
this.handle_eof(current_token);
|
|
|
440 |
} else if (current_token.type === TOKEN.UNKNOWN) {
|
|
|
441 |
this.handle_unknown(current_token, preserve_statement_flags);
|
|
|
442 |
} else {
|
|
|
443 |
this.handle_unknown(current_token, preserve_statement_flags);
|
|
|
444 |
}
|
|
|
445 |
};
|
|
|
446 |
|
|
|
447 |
Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
|
|
|
448 |
var newlines = current_token.newlines;
|
|
|
449 |
var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
|
|
|
450 |
|
|
|
451 |
if (current_token.comments_before) {
|
|
|
452 |
var comment_token = current_token.comments_before.next();
|
|
|
453 |
while (comment_token) {
|
|
|
454 |
// The cleanest handling of inline comments is to treat them as though they aren't there.
|
|
|
455 |
// Just continue formatting and the behavior should be logical.
|
|
|
456 |
// Also ignore unknown tokens. Again, this should result in better behavior.
|
|
|
457 |
this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
|
|
|
458 |
this.handle_token(comment_token, preserve_statement_flags);
|
|
|
459 |
comment_token = current_token.comments_before.next();
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
if (keep_whitespace) {
|
|
|
464 |
for (var i = 0; i < newlines; i += 1) {
|
|
|
465 |
this.print_newline(i > 0, preserve_statement_flags);
|
|
|
466 |
}
|
|
|
467 |
} else {
|
|
|
468 |
if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
|
|
|
469 |
newlines = this._options.max_preserve_newlines;
|
|
|
470 |
}
|
|
|
471 |
|
|
|
472 |
if (this._options.preserve_newlines) {
|
|
|
473 |
if (newlines > 1) {
|
|
|
474 |
this.print_newline(false, preserve_statement_flags);
|
|
|
475 |
for (var j = 1; j < newlines; j += 1) {
|
|
|
476 |
this.print_newline(true, preserve_statement_flags);
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
};
|
|
|
483 |
|
|
|
484 |
var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
|
|
|
485 |
|
|
|
486 |
Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
|
|
|
487 |
force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
|
|
|
488 |
|
|
|
489 |
// Never wrap the first token on a line
|
|
|
490 |
if (this._output.just_added_newline()) {
|
|
|
491 |
return;
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
|
|
|
495 |
var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
|
|
|
496 |
in_array(current_token.text, positionable_operators);
|
|
|
497 |
|
|
|
498 |
if (operatorLogicApplies) {
|
|
|
499 |
var shouldPrintOperatorNewline = (
|
|
|
500 |
in_array(this._flags.last_token.text, positionable_operators) &&
|
|
|
501 |
in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
|
|
|
502 |
) ||
|
|
|
503 |
in_array(current_token.text, positionable_operators);
|
|
|
504 |
shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
if (shouldPreserveOrForce) {
|
|
|
508 |
this.print_newline(false, true);
|
|
|
509 |
} else if (this._options.wrap_line_length) {
|
|
|
510 |
if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
|
|
|
511 |
// These tokens should never have a newline inserted
|
|
|
512 |
// between them and the following expression.
|
|
|
513 |
return;
|
|
|
514 |
}
|
|
|
515 |
this._output.set_wrap_point();
|
|
|
516 |
}
|
|
|
517 |
};
|
|
|
518 |
|
|
|
519 |
Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
|
|
|
520 |
if (!preserve_statement_flags) {
|
|
|
521 |
if (this._flags.last_token.text !== ';' && this._flags.last_token.text !== ',' && this._flags.last_token.text !== '=' && (this._flags.last_token.type !== TOKEN.OPERATOR || this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) {
|
|
|
522 |
var next_token = this._tokens.peek();
|
|
|
523 |
while (this._flags.mode === MODE.Statement &&
|
|
|
524 |
!(this._flags.if_block && reserved_word(next_token, 'else')) &&
|
|
|
525 |
!this._flags.do_block) {
|
|
|
526 |
this.restore_mode();
|
|
|
527 |
}
|
|
|
528 |
}
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
if (this._output.add_new_line(force_newline)) {
|
|
|
532 |
this._flags.multiline_frame = true;
|
|
|
533 |
}
|
|
|
534 |
};
|
|
|
535 |
|
|
|
536 |
Beautifier.prototype.print_token_line_indentation = function(current_token) {
|
|
|
537 |
if (this._output.just_added_newline()) {
|
|
|
538 |
if (this._options.keep_array_indentation &&
|
|
|
539 |
current_token.newlines &&
|
|
|
540 |
(current_token.text === '[' || is_array(this._flags.mode))) {
|
|
|
541 |
this._output.current_line.set_indent(-1);
|
|
|
542 |
this._output.current_line.push(current_token.whitespace_before);
|
|
|
543 |
this._output.space_before_token = false;
|
|
|
544 |
} else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
|
|
|
545 |
this._flags.line_indent_level = this._flags.indentation_level;
|
|
|
546 |
}
|
|
|
547 |
}
|
|
|
548 |
};
|
|
|
549 |
|
|
|
550 |
Beautifier.prototype.print_token = function(current_token) {
|
|
|
551 |
if (this._output.raw) {
|
|
|
552 |
this._output.add_raw_token(current_token);
|
|
|
553 |
return;
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
|
|
|
557 |
this._output.just_added_newline()) {
|
|
|
558 |
if (this._output.previous_line.last() === ',') {
|
|
|
559 |
var popped = this._output.previous_line.pop();
|
|
|
560 |
// if the comma was already at the start of the line,
|
|
|
561 |
// pull back onto that line and reprint the indentation
|
|
|
562 |
if (this._output.previous_line.is_empty()) {
|
|
|
563 |
this._output.previous_line.push(popped);
|
|
|
564 |
this._output.trim(true);
|
|
|
565 |
this._output.current_line.pop();
|
|
|
566 |
this._output.trim();
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
// add the comma in front of the next token
|
|
|
570 |
this.print_token_line_indentation(current_token);
|
|
|
571 |
this._output.add_token(',');
|
|
|
572 |
this._output.space_before_token = true;
|
|
|
573 |
}
|
|
|
574 |
}
|
|
|
575 |
|
|
|
576 |
this.print_token_line_indentation(current_token);
|
|
|
577 |
this._output.non_breaking_space = true;
|
|
|
578 |
this._output.add_token(current_token.text);
|
|
|
579 |
if (this._output.previous_token_wrapped) {
|
|
|
580 |
this._flags.multiline_frame = true;
|
|
|
581 |
}
|
|
|
582 |
};
|
|
|
583 |
|
|
|
584 |
Beautifier.prototype.indent = function() {
|
|
|
585 |
this._flags.indentation_level += 1;
|
|
|
586 |
this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
|
|
587 |
};
|
|
|
588 |
|
|
|
589 |
Beautifier.prototype.deindent = function() {
|
|
|
590 |
if (this._flags.indentation_level > 0 &&
|
|
|
591 |
((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
|
|
|
592 |
this._flags.indentation_level -= 1;
|
|
|
593 |
this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
|
|
594 |
}
|
|
|
595 |
};
|
|
|
596 |
|
|
|
597 |
Beautifier.prototype.set_mode = function(mode) {
|
|
|
598 |
if (this._flags) {
|
|
|
599 |
this._flag_store.push(this._flags);
|
|
|
600 |
this._previous_flags = this._flags;
|
|
|
601 |
} else {
|
|
|
602 |
this._previous_flags = this.create_flags(null, mode);
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
this._flags = this.create_flags(this._previous_flags, mode);
|
|
|
606 |
this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
|
|
607 |
};
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
Beautifier.prototype.restore_mode = function() {
|
|
|
611 |
if (this._flag_store.length > 0) {
|
|
|
612 |
this._previous_flags = this._flags;
|
|
|
613 |
this._flags = this._flag_store.pop();
|
|
|
614 |
if (this._previous_flags.mode === MODE.Statement) {
|
|
|
615 |
remove_redundant_indentation(this._output, this._previous_flags);
|
|
|
616 |
}
|
|
|
617 |
this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
|
|
|
618 |
}
|
|
|
619 |
};
|
|
|
620 |
|
|
|
621 |
Beautifier.prototype.start_of_object_property = function() {
|
|
|
622 |
return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
|
|
|
623 |
(this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
|
|
|
624 |
};
|
|
|
625 |
|
|
|
626 |
Beautifier.prototype.start_of_statement = function(current_token) {
|
|
|
627 |
var start = false;
|
|
|
628 |
start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
|
|
|
629 |
start = start || reserved_word(this._flags.last_token, 'do');
|
|
|
630 |
start = start || (!(this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement)) && reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines;
|
|
|
631 |
start = start || reserved_word(this._flags.last_token, 'else') &&
|
|
|
632 |
!(reserved_word(current_token, 'if') && !current_token.comments_before);
|
|
|
633 |
start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
|
|
|
634 |
start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
|
|
|
635 |
!this._flags.in_case &&
|
|
|
636 |
!(current_token.text === '--' || current_token.text === '++') &&
|
|
|
637 |
this._last_last_text !== 'function' &&
|
|
|
638 |
current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
|
|
|
639 |
start = start || (this._flags.mode === MODE.ObjectLiteral && (
|
|
|
640 |
(this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
|
|
|
641 |
|
|
|
642 |
if (start) {
|
|
|
643 |
this.set_mode(MODE.Statement);
|
|
|
644 |
this.indent();
|
|
|
645 |
|
|
|
646 |
this.handle_whitespace_and_comments(current_token, true);
|
|
|
647 |
|
|
|
648 |
// Issue #276:
|
|
|
649 |
// If starting a new statement with [if, for, while, do], push to a new line.
|
|
|
650 |
// if (a) if (b) if(c) d(); else e(); else f();
|
|
|
651 |
if (!this.start_of_object_property()) {
|
|
|
652 |
this.allow_wrap_or_preserved_newline(current_token,
|
|
|
653 |
reserved_array(current_token, ['do', 'for', 'if', 'while']));
|
|
|
654 |
}
|
|
|
655 |
return true;
|
|
|
656 |
}
|
|
|
657 |
return false;
|
|
|
658 |
};
|
|
|
659 |
|
|
|
660 |
Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
661 |
// The conditional starts the statement if appropriate.
|
|
|
662 |
if (!this.start_of_statement(current_token)) {
|
|
|
663 |
this.handle_whitespace_and_comments(current_token);
|
|
|
664 |
}
|
|
|
665 |
|
|
|
666 |
var next_mode = MODE.Expression;
|
|
|
667 |
if (current_token.text === '[') {
|
|
|
668 |
|
|
|
669 |
if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
|
|
|
670 |
// this is array index specifier, break immediately
|
|
|
671 |
// a[x], fn()[x]
|
|
|
672 |
if (reserved_array(this._flags.last_token, line_starters)) {
|
|
|
673 |
this._output.space_before_token = true;
|
|
|
674 |
}
|
|
|
675 |
this.print_token(current_token);
|
|
|
676 |
this.set_mode(next_mode);
|
|
|
677 |
this.indent();
|
|
|
678 |
if (this._options.space_in_paren) {
|
|
|
679 |
this._output.space_before_token = true;
|
|
|
680 |
}
|
|
|
681 |
return;
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
next_mode = MODE.ArrayLiteral;
|
|
|
685 |
if (is_array(this._flags.mode)) {
|
|
|
686 |
if (this._flags.last_token.text === '[' ||
|
|
|
687 |
(this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
|
|
|
688 |
// ], [ goes to new line
|
|
|
689 |
// }, [ goes to new line
|
|
|
690 |
if (!this._options.keep_array_indentation) {
|
|
|
691 |
this.print_newline();
|
|
|
692 |
}
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
|
|
|
697 |
this._output.space_before_token = true;
|
|
|
698 |
}
|
|
|
699 |
} else {
|
|
|
700 |
if (this._flags.last_token.type === TOKEN.RESERVED) {
|
|
|
701 |
if (this._flags.last_token.text === 'for') {
|
|
|
702 |
this._output.space_before_token = this._options.space_before_conditional;
|
|
|
703 |
next_mode = MODE.ForInitializer;
|
|
|
704 |
} else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
|
|
|
705 |
this._output.space_before_token = this._options.space_before_conditional;
|
|
|
706 |
next_mode = MODE.Conditional;
|
|
|
707 |
} else if (in_array(this._flags.last_word, ['await', 'async'])) {
|
|
|
708 |
// Should be a space between await and an IIFE, or async and an arrow function
|
|
|
709 |
this._output.space_before_token = true;
|
|
|
710 |
} else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
|
|
|
711 |
this._output.space_before_token = false;
|
|
|
712 |
} else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
|
|
|
713 |
this._output.space_before_token = true;
|
|
|
714 |
}
|
|
|
715 |
} else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
|
|
716 |
// Support of this kind of newline preservation.
|
|
|
717 |
// a = (b &&
|
|
|
718 |
// (c || d));
|
|
|
719 |
if (!this.start_of_object_property()) {
|
|
|
720 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
721 |
}
|
|
|
722 |
} else if (this._flags.last_token.type === TOKEN.WORD) {
|
|
|
723 |
this._output.space_before_token = false;
|
|
|
724 |
|
|
|
725 |
// function name() vs function name ()
|
|
|
726 |
// function* name() vs function* name ()
|
|
|
727 |
// async name() vs async name ()
|
|
|
728 |
// In ES6, you can also define the method properties of an object
|
|
|
729 |
// var obj = {a: function() {}}
|
|
|
730 |
// It can be abbreviated
|
|
|
731 |
// var obj = {a() {}}
|
|
|
732 |
// var obj = { a() {}} vs var obj = { a () {}}
|
|
|
733 |
// var obj = { * a() {}} vs var obj = { * a () {}}
|
|
|
734 |
var peek_back_two = this._tokens.peek(-3);
|
|
|
735 |
if (this._options.space_after_named_function && peek_back_two) {
|
|
|
736 |
// peek starts at next character so -1 is current token
|
|
|
737 |
var peek_back_three = this._tokens.peek(-4);
|
|
|
738 |
if (reserved_array(peek_back_two, ['async', 'function']) ||
|
|
|
739 |
(peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
|
|
|
740 |
this._output.space_before_token = true;
|
|
|
741 |
} else if (this._flags.mode === MODE.ObjectLiteral) {
|
|
|
742 |
if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
|
|
|
743 |
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
|
|
|
744 |
this._output.space_before_token = true;
|
|
|
745 |
}
|
|
|
746 |
} else if (this._flags.parent && this._flags.parent.class_start_block) {
|
|
|
747 |
this._output.space_before_token = true;
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
} else {
|
|
|
751 |
// Support preserving wrapped arrow function expressions
|
|
|
752 |
// a.b('c',
|
|
|
753 |
// () => d.e
|
|
|
754 |
// )
|
|
|
755 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
// function() vs function ()
|
|
|
759 |
// yield*() vs yield* ()
|
|
|
760 |
// function*() vs function* ()
|
|
|
761 |
if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
|
|
|
762 |
(this._flags.last_token.text === '*' &&
|
|
|
763 |
(in_array(this._last_last_text, ['function', 'yield']) ||
|
|
|
764 |
(this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
|
|
765 |
this._output.space_before_token = this._options.space_after_anon_function;
|
|
|
766 |
}
|
|
|
767 |
}
|
|
|
768 |
|
|
|
769 |
if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
|
|
|
770 |
this.print_newline();
|
|
|
771 |
} else if (this._flags.last_token.type === TOKEN.END_EXPR || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.END_BLOCK || this._flags.last_token.text === '.' || this._flags.last_token.type === TOKEN.COMMA) {
|
|
|
772 |
// do nothing on (( and )( and ][ and ]( and .(
|
|
|
773 |
// TODO: Consider whether forcing this is required. Review failing tests when removed.
|
|
|
774 |
this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
|
|
|
775 |
}
|
|
|
776 |
|
|
|
777 |
this.print_token(current_token);
|
|
|
778 |
this.set_mode(next_mode);
|
|
|
779 |
if (this._options.space_in_paren) {
|
|
|
780 |
this._output.space_before_token = true;
|
|
|
781 |
}
|
|
|
782 |
|
|
|
783 |
// In all cases, if we newline while inside an expression it should be indented.
|
|
|
784 |
this.indent();
|
|
|
785 |
};
|
|
|
786 |
|
|
|
787 |
Beautifier.prototype.handle_end_expr = function(current_token) {
|
|
|
788 |
// statements inside expressions are not valid syntax, but...
|
|
|
789 |
// statements must all be closed when their container closes
|
|
|
790 |
while (this._flags.mode === MODE.Statement) {
|
|
|
791 |
this.restore_mode();
|
|
|
792 |
}
|
|
|
793 |
|
|
|
794 |
this.handle_whitespace_and_comments(current_token);
|
|
|
795 |
|
|
|
796 |
if (this._flags.multiline_frame) {
|
|
|
797 |
this.allow_wrap_or_preserved_newline(current_token,
|
|
|
798 |
current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
|
|
|
799 |
}
|
|
|
800 |
|
|
|
801 |
if (this._options.space_in_paren) {
|
|
|
802 |
if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
|
|
|
803 |
// () [] no inner space in empty parens like these, ever, ref #320
|
|
|
804 |
this._output.trim();
|
|
|
805 |
this._output.space_before_token = false;
|
|
|
806 |
} else {
|
|
|
807 |
this._output.space_before_token = true;
|
|
|
808 |
}
|
|
|
809 |
}
|
|
|
810 |
this.deindent();
|
|
|
811 |
this.print_token(current_token);
|
|
|
812 |
this.restore_mode();
|
|
|
813 |
|
|
|
814 |
remove_redundant_indentation(this._output, this._previous_flags);
|
|
|
815 |
|
|
|
816 |
// do {} while () // no statement required after
|
|
|
817 |
if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
|
|
|
818 |
this._previous_flags.mode = MODE.Expression;
|
|
|
819 |
this._flags.do_block = false;
|
|
|
820 |
this._flags.do_while = false;
|
|
|
821 |
|
|
|
822 |
}
|
|
|
823 |
};
|
|
|
824 |
|
|
|
825 |
Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
826 |
this.handle_whitespace_and_comments(current_token);
|
|
|
827 |
|
|
|
828 |
// Check if this is should be treated as a ObjectLiteral
|
|
|
829 |
var next_token = this._tokens.peek();
|
|
|
830 |
var second_token = this._tokens.peek(1);
|
|
|
831 |
if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
|
|
|
832 |
this.set_mode(MODE.BlockStatement);
|
|
|
833 |
this._flags.in_case_statement = true;
|
|
|
834 |
} else if (this._flags.case_body) {
|
|
|
835 |
this.set_mode(MODE.BlockStatement);
|
|
|
836 |
} else if (second_token && (
|
|
|
837 |
(in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
|
|
|
838 |
(in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
|
|
|
839 |
)) {
|
|
|
840 |
// We don't support TypeScript,but we didn't break it for a very long time.
|
|
|
841 |
// We'll try to keep not breaking it.
|
|
|
842 |
if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
|
|
|
843 |
this.set_mode(MODE.BlockStatement);
|
|
|
844 |
} else {
|
|
|
845 |
this.set_mode(MODE.ObjectLiteral);
|
|
|
846 |
}
|
|
|
847 |
} else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
|
|
|
848 |
// arrow function: (param1, paramN) => { statements }
|
|
|
849 |
this.set_mode(MODE.BlockStatement);
|
|
|
850 |
} else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
|
|
|
851 |
reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
|
|
|
852 |
) {
|
|
|
853 |
// Detecting shorthand function syntax is difficult by scanning forward,
|
|
|
854 |
// so check the surrounding context.
|
|
|
855 |
// If the block is being returned, imported, export default, passed as arg,
|
|
|
856 |
// assigned with = or assigned in a nested object, treat as an ObjectLiteral.
|
|
|
857 |
this.set_mode(MODE.ObjectLiteral);
|
|
|
858 |
} else {
|
|
|
859 |
this.set_mode(MODE.BlockStatement);
|
|
|
860 |
}
|
|
|
861 |
|
|
|
862 |
if (this._flags.last_token) {
|
|
|
863 |
if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
|
|
|
864 |
this._flags.class_start_block = true;
|
|
|
865 |
}
|
|
|
866 |
}
|
|
|
867 |
|
|
|
868 |
var empty_braces = !next_token.comments_before && next_token.text === '}';
|
|
|
869 |
var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
|
|
|
870 |
this._flags.last_token.type === TOKEN.END_EXPR;
|
|
|
871 |
|
|
|
872 |
if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
|
|
|
873 |
{
|
|
|
874 |
// search forward for a newline wanted inside this block
|
|
|
875 |
var index = 0;
|
|
|
876 |
var check_token = null;
|
|
|
877 |
this._flags.inline_frame = true;
|
|
|
878 |
do {
|
|
|
879 |
index += 1;
|
|
|
880 |
check_token = this._tokens.peek(index - 1);
|
|
|
881 |
if (check_token.newlines) {
|
|
|
882 |
this._flags.inline_frame = false;
|
|
|
883 |
break;
|
|
|
884 |
}
|
|
|
885 |
} while (check_token.type !== TOKEN.EOF &&
|
|
|
886 |
!(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
if ((this._options.brace_style === "expand" ||
|
|
|
890 |
(this._options.brace_style === "none" && current_token.newlines)) &&
|
|
|
891 |
!this._flags.inline_frame) {
|
|
|
892 |
if (this._flags.last_token.type !== TOKEN.OPERATOR &&
|
|
|
893 |
(empty_anonymous_function ||
|
|
|
894 |
this._flags.last_token.type === TOKEN.EQUALS ||
|
|
|
895 |
(reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
|
|
|
896 |
this._output.space_before_token = true;
|
|
|
897 |
} else {
|
|
|
898 |
this.print_newline(false, true);
|
|
|
899 |
}
|
|
|
900 |
} else { // collapse || inline_frame
|
|
|
901 |
if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
|
|
|
902 |
if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
|
|
|
903 |
this._output.space_before_token = true;
|
|
|
904 |
}
|
|
|
905 |
|
|
|
906 |
if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
|
|
|
907 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
908 |
this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
|
|
|
909 |
this._flags.multiline_frame = false;
|
|
|
910 |
}
|
|
|
911 |
}
|
|
|
912 |
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
|
|
|
913 |
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
|
|
|
914 |
this.print_newline();
|
|
|
915 |
} else {
|
|
|
916 |
this._output.space_before_token = true;
|
|
|
917 |
}
|
|
|
918 |
}
|
|
|
919 |
}
|
|
|
920 |
this.print_token(current_token);
|
|
|
921 |
this.indent();
|
|
|
922 |
|
|
|
923 |
// Except for specific cases, open braces are followed by a new line.
|
|
|
924 |
if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
|
|
|
925 |
this.print_newline();
|
|
|
926 |
}
|
|
|
927 |
};
|
|
|
928 |
|
|
|
929 |
Beautifier.prototype.handle_end_block = function(current_token) {
|
|
|
930 |
// statements must all be closed when their container closes
|
|
|
931 |
this.handle_whitespace_and_comments(current_token);
|
|
|
932 |
|
|
|
933 |
while (this._flags.mode === MODE.Statement) {
|
|
|
934 |
this.restore_mode();
|
|
|
935 |
}
|
|
|
936 |
|
|
|
937 |
var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
|
|
|
938 |
|
|
|
939 |
if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
|
|
|
940 |
this._output.space_before_token = true;
|
|
|
941 |
} else if (this._options.brace_style === "expand") {
|
|
|
942 |
if (!empty_braces) {
|
|
|
943 |
this.print_newline();
|
|
|
944 |
}
|
|
|
945 |
} else {
|
|
|
946 |
// skip {}
|
|
|
947 |
if (!empty_braces) {
|
|
|
948 |
if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
|
|
|
949 |
// we REALLY need a newline here, but newliner would skip that
|
|
|
950 |
this._options.keep_array_indentation = false;
|
|
|
951 |
this.print_newline();
|
|
|
952 |
this._options.keep_array_indentation = true;
|
|
|
953 |
|
|
|
954 |
} else {
|
|
|
955 |
this.print_newline();
|
|
|
956 |
}
|
|
|
957 |
}
|
|
|
958 |
}
|
|
|
959 |
this.restore_mode();
|
|
|
960 |
this.print_token(current_token);
|
|
|
961 |
};
|
|
|
962 |
|
|
|
963 |
Beautifier.prototype.handle_word = function(current_token) {
|
|
|
964 |
if (current_token.type === TOKEN.RESERVED) {
|
|
|
965 |
if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
|
|
|
966 |
current_token.type = TOKEN.WORD;
|
|
|
967 |
} else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
|
|
|
968 |
current_token.type = TOKEN.WORD;
|
|
|
969 |
} else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
|
|
|
970 |
current_token.type = TOKEN.WORD;
|
|
|
971 |
} else if (this._flags.mode === MODE.ObjectLiteral) {
|
|
|
972 |
var next_token = this._tokens.peek();
|
|
|
973 |
if (next_token.text === ':') {
|
|
|
974 |
current_token.type = TOKEN.WORD;
|
|
|
975 |
}
|
|
|
976 |
}
|
|
|
977 |
}
|
|
|
978 |
|
|
|
979 |
if (this.start_of_statement(current_token)) {
|
|
|
980 |
// The conditional starts the statement if appropriate.
|
|
|
981 |
if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
|
|
|
982 |
this._flags.declaration_statement = true;
|
|
|
983 |
}
|
|
|
984 |
} else if (current_token.newlines && !is_expression(this._flags.mode) &&
|
|
|
985 |
(this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
|
|
|
986 |
this._flags.last_token.type !== TOKEN.EQUALS &&
|
|
|
987 |
(this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
|
|
|
988 |
this.handle_whitespace_and_comments(current_token);
|
|
|
989 |
this.print_newline();
|
|
|
990 |
} else {
|
|
|
991 |
this.handle_whitespace_and_comments(current_token);
|
|
|
992 |
}
|
|
|
993 |
|
|
|
994 |
if (this._flags.do_block && !this._flags.do_while) {
|
|
|
995 |
if (reserved_word(current_token, 'while')) {
|
|
|
996 |
// do {} ## while ()
|
|
|
997 |
this._output.space_before_token = true;
|
|
|
998 |
this.print_token(current_token);
|
|
|
999 |
this._output.space_before_token = true;
|
|
|
1000 |
this._flags.do_while = true;
|
|
|
1001 |
return;
|
|
|
1002 |
} else {
|
|
|
1003 |
// do {} should always have while as the next word.
|
|
|
1004 |
// if we don't see the expected while, recover
|
|
|
1005 |
this.print_newline();
|
|
|
1006 |
this._flags.do_block = false;
|
|
|
1007 |
}
|
|
|
1008 |
}
|
|
|
1009 |
|
|
|
1010 |
// if may be followed by else, or not
|
|
|
1011 |
// Bare/inline ifs are tricky
|
|
|
1012 |
// Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
|
|
|
1013 |
if (this._flags.if_block) {
|
|
|
1014 |
if (!this._flags.else_block && reserved_word(current_token, 'else')) {
|
|
|
1015 |
this._flags.else_block = true;
|
|
|
1016 |
} else {
|
|
|
1017 |
while (this._flags.mode === MODE.Statement) {
|
|
|
1018 |
this.restore_mode();
|
|
|
1019 |
}
|
|
|
1020 |
this._flags.if_block = false;
|
|
|
1021 |
this._flags.else_block = false;
|
|
|
1022 |
}
|
|
|
1023 |
}
|
|
|
1024 |
|
|
|
1025 |
if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
|
|
|
1026 |
this.print_newline();
|
|
|
1027 |
if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
|
|
|
1028 |
// switch cases following one another
|
|
|
1029 |
this.deindent();
|
|
|
1030 |
}
|
|
|
1031 |
this._flags.case_body = false;
|
|
|
1032 |
|
|
|
1033 |
this.print_token(current_token);
|
|
|
1034 |
this._flags.in_case = true;
|
|
|
1035 |
return;
|
|
|
1036 |
}
|
|
|
1037 |
|
|
|
1038 |
if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
|
|
1039 |
if (!this.start_of_object_property() && !(
|
|
|
1040 |
// start of object property is different for numeric values with +/- prefix operators
|
|
|
1041 |
in_array(this._flags.last_token.text, ['+', '-']) && this._last_last_text === ':' && this._flags.parent.mode === MODE.ObjectLiteral)) {
|
|
|
1042 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1043 |
}
|
|
|
1044 |
}
|
|
|
1045 |
|
|
|
1046 |
if (reserved_word(current_token, 'function')) {
|
|
|
1047 |
if (in_array(this._flags.last_token.text, ['}', ';']) ||
|
|
|
1048 |
(this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
|
|
|
1049 |
// make sure there is a nice clean space of at least one blank line
|
|
|
1050 |
// before a new function definition
|
|
|
1051 |
if (!this._output.just_added_blankline() && !current_token.comments_before) {
|
|
|
1052 |
this.print_newline();
|
|
|
1053 |
this.print_newline(true);
|
|
|
1054 |
}
|
|
|
1055 |
}
|
|
|
1056 |
if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
|
|
|
1057 |
if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
|
|
|
1058 |
reserved_array(this._flags.last_token, newline_restricted_tokens)) {
|
|
|
1059 |
this._output.space_before_token = true;
|
|
|
1060 |
} else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
|
|
|
1061 |
this._output.space_before_token = true;
|
|
|
1062 |
} else if (this._flags.last_token.text === 'declare') {
|
|
|
1063 |
// accomodates Typescript declare function formatting
|
|
|
1064 |
this._output.space_before_token = true;
|
|
|
1065 |
} else {
|
|
|
1066 |
this.print_newline();
|
|
|
1067 |
}
|
|
|
1068 |
} else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
|
|
|
1069 |
// foo = function
|
|
|
1070 |
this._output.space_before_token = true;
|
|
|
1071 |
} else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) {
|
|
|
1072 |
// (function
|
|
|
1073 |
} else {
|
|
|
1074 |
this.print_newline();
|
|
|
1075 |
}
|
|
|
1076 |
|
|
|
1077 |
this.print_token(current_token);
|
|
|
1078 |
this._flags.last_word = current_token.text;
|
|
|
1079 |
return;
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
var prefix = 'NONE';
|
|
|
1083 |
|
|
|
1084 |
if (this._flags.last_token.type === TOKEN.END_BLOCK) {
|
|
|
1085 |
|
|
|
1086 |
if (this._previous_flags.inline_frame) {
|
|
|
1087 |
prefix = 'SPACE';
|
|
|
1088 |
} else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
|
|
|
1089 |
prefix = 'NEWLINE';
|
|
|
1090 |
} else {
|
|
|
1091 |
if (this._options.brace_style === "expand" ||
|
|
|
1092 |
this._options.brace_style === "end-expand" ||
|
|
|
1093 |
(this._options.brace_style === "none" && current_token.newlines)) {
|
|
|
1094 |
prefix = 'NEWLINE';
|
|
|
1095 |
} else {
|
|
|
1096 |
prefix = 'SPACE';
|
|
|
1097 |
this._output.space_before_token = true;
|
|
|
1098 |
}
|
|
|
1099 |
}
|
|
|
1100 |
} else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
|
|
|
1101 |
// TODO: Should this be for STATEMENT as well?
|
|
|
1102 |
prefix = 'NEWLINE';
|
|
|
1103 |
} else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
|
|
|
1104 |
prefix = 'SPACE';
|
|
|
1105 |
} else if (this._flags.last_token.type === TOKEN.STRING) {
|
|
|
1106 |
prefix = 'NEWLINE';
|
|
|
1107 |
} else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
|
|
|
1108 |
(this._flags.last_token.text === '*' &&
|
|
|
1109 |
(in_array(this._last_last_text, ['function', 'yield']) ||
|
|
|
1110 |
(this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
|
|
1111 |
prefix = 'SPACE';
|
|
|
1112 |
} else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
|
|
|
1113 |
if (this._flags.inline_frame) {
|
|
|
1114 |
prefix = 'SPACE';
|
|
|
1115 |
} else {
|
|
|
1116 |
prefix = 'NEWLINE';
|
|
|
1117 |
}
|
|
|
1118 |
} else if (this._flags.last_token.type === TOKEN.END_EXPR) {
|
|
|
1119 |
this._output.space_before_token = true;
|
|
|
1120 |
prefix = 'NEWLINE';
|
|
|
1121 |
}
|
|
|
1122 |
|
|
|
1123 |
if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
|
|
|
1124 |
if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
|
|
|
1125 |
prefix = 'SPACE';
|
|
|
1126 |
} else {
|
|
|
1127 |
prefix = 'NEWLINE';
|
|
|
1128 |
}
|
|
|
1129 |
|
|
|
1130 |
}
|
|
|
1131 |
|
|
|
1132 |
if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
|
|
|
1133 |
if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
|
|
|
1134 |
this._options.brace_style === "expand" ||
|
|
|
1135 |
this._options.brace_style === "end-expand" ||
|
|
|
1136 |
(this._options.brace_style === "none" && current_token.newlines)) &&
|
|
|
1137 |
!this._flags.inline_frame) {
|
|
|
1138 |
this.print_newline();
|
|
|
1139 |
} else {
|
|
|
1140 |
this._output.trim(true);
|
|
|
1141 |
var line = this._output.current_line;
|
|
|
1142 |
// If we trimmed and there's something other than a close block before us
|
|
|
1143 |
// put a newline back in. Handles '} // comment' scenario.
|
|
|
1144 |
if (line.last() !== '}') {
|
|
|
1145 |
this.print_newline();
|
|
|
1146 |
}
|
|
|
1147 |
this._output.space_before_token = true;
|
|
|
1148 |
}
|
|
|
1149 |
} else if (prefix === 'NEWLINE') {
|
|
|
1150 |
if (reserved_array(this._flags.last_token, special_words)) {
|
|
|
1151 |
// no newline between 'return nnn'
|
|
|
1152 |
this._output.space_before_token = true;
|
|
|
1153 |
} else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
|
|
|
1154 |
// accomodates Typescript declare formatting
|
|
|
1155 |
this._output.space_before_token = true;
|
|
|
1156 |
} else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
|
|
|
1157 |
if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
|
|
|
1158 |
// no need to force newline on 'var': for (var x = 0...)
|
|
|
1159 |
if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
|
|
|
1160 |
// no newline for } else if {
|
|
|
1161 |
this._output.space_before_token = true;
|
|
|
1162 |
} else {
|
|
|
1163 |
this.print_newline();
|
|
|
1164 |
}
|
|
|
1165 |
}
|
|
|
1166 |
} else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
|
|
|
1167 |
this.print_newline();
|
|
|
1168 |
}
|
|
|
1169 |
} else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
|
|
|
1170 |
this.print_newline(); // }, in lists get a newline treatment
|
|
|
1171 |
} else if (prefix === 'SPACE') {
|
|
|
1172 |
this._output.space_before_token = true;
|
|
|
1173 |
}
|
|
|
1174 |
if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
|
|
|
1175 |
this._output.space_before_token = true;
|
|
|
1176 |
}
|
|
|
1177 |
this.print_token(current_token);
|
|
|
1178 |
this._flags.last_word = current_token.text;
|
|
|
1179 |
|
|
|
1180 |
if (current_token.type === TOKEN.RESERVED) {
|
|
|
1181 |
if (current_token.text === 'do') {
|
|
|
1182 |
this._flags.do_block = true;
|
|
|
1183 |
} else if (current_token.text === 'if') {
|
|
|
1184 |
this._flags.if_block = true;
|
|
|
1185 |
} else if (current_token.text === 'import') {
|
|
|
1186 |
this._flags.import_block = true;
|
|
|
1187 |
} else if (this._flags.import_block && reserved_word(current_token, 'from')) {
|
|
|
1188 |
this._flags.import_block = false;
|
|
|
1189 |
}
|
|
|
1190 |
}
|
|
|
1191 |
};
|
|
|
1192 |
|
|
|
1193 |
Beautifier.prototype.handle_semicolon = function(current_token) {
|
|
|
1194 |
if (this.start_of_statement(current_token)) {
|
|
|
1195 |
// The conditional starts the statement if appropriate.
|
|
|
1196 |
// Semicolon can be the start (and end) of a statement
|
|
|
1197 |
this._output.space_before_token = false;
|
|
|
1198 |
} else {
|
|
|
1199 |
this.handle_whitespace_and_comments(current_token);
|
|
|
1200 |
}
|
|
|
1201 |
|
|
|
1202 |
var next_token = this._tokens.peek();
|
|
|
1203 |
while (this._flags.mode === MODE.Statement &&
|
|
|
1204 |
!(this._flags.if_block && reserved_word(next_token, 'else')) &&
|
|
|
1205 |
!this._flags.do_block) {
|
|
|
1206 |
this.restore_mode();
|
|
|
1207 |
}
|
|
|
1208 |
|
|
|
1209 |
// hacky but effective for the moment
|
|
|
1210 |
if (this._flags.import_block) {
|
|
|
1211 |
this._flags.import_block = false;
|
|
|
1212 |
}
|
|
|
1213 |
this.print_token(current_token);
|
|
|
1214 |
};
|
|
|
1215 |
|
|
|
1216 |
Beautifier.prototype.handle_string = function(current_token) {
|
|
|
1217 |
if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) {
|
|
|
1218 |
//Conditional for detectign backtick strings
|
|
|
1219 |
} else if (this.start_of_statement(current_token)) {
|
|
|
1220 |
// The conditional starts the statement if appropriate.
|
|
|
1221 |
// One difference - strings want at least a space before
|
|
|
1222 |
this._output.space_before_token = true;
|
|
|
1223 |
} else {
|
|
|
1224 |
this.handle_whitespace_and_comments(current_token);
|
|
|
1225 |
if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
|
|
|
1226 |
this._output.space_before_token = true;
|
|
|
1227 |
} else if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
|
|
|
1228 |
if (!this.start_of_object_property()) {
|
|
|
1229 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1230 |
}
|
|
|
1231 |
} else if ((current_token.text.startsWith("`") && this._flags.last_token.type === TOKEN.END_EXPR && (current_token.previous.text === ']' || current_token.previous.text === ')') && current_token.newlines === 0)) {
|
|
|
1232 |
this._output.space_before_token = true;
|
|
|
1233 |
} else {
|
|
|
1234 |
this.print_newline();
|
|
|
1235 |
}
|
|
|
1236 |
}
|
|
|
1237 |
this.print_token(current_token);
|
|
|
1238 |
};
|
|
|
1239 |
|
|
|
1240 |
Beautifier.prototype.handle_equals = function(current_token) {
|
|
|
1241 |
if (this.start_of_statement(current_token)) {
|
|
|
1242 |
// The conditional starts the statement if appropriate.
|
|
|
1243 |
} else {
|
|
|
1244 |
this.handle_whitespace_and_comments(current_token);
|
|
|
1245 |
}
|
|
|
1246 |
|
|
|
1247 |
if (this._flags.declaration_statement) {
|
|
|
1248 |
// just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
|
|
|
1249 |
this._flags.declaration_assignment = true;
|
|
|
1250 |
}
|
|
|
1251 |
this._output.space_before_token = true;
|
|
|
1252 |
this.print_token(current_token);
|
|
|
1253 |
this._output.space_before_token = true;
|
|
|
1254 |
};
|
|
|
1255 |
|
|
|
1256 |
Beautifier.prototype.handle_comma = function(current_token) {
|
|
|
1257 |
this.handle_whitespace_and_comments(current_token, true);
|
|
|
1258 |
|
|
|
1259 |
this.print_token(current_token);
|
|
|
1260 |
this._output.space_before_token = true;
|
|
|
1261 |
if (this._flags.declaration_statement) {
|
|
|
1262 |
if (is_expression(this._flags.parent.mode)) {
|
|
|
1263 |
// do not break on comma, for(var a = 1, b = 2)
|
|
|
1264 |
this._flags.declaration_assignment = false;
|
|
|
1265 |
}
|
|
|
1266 |
|
|
|
1267 |
if (this._flags.declaration_assignment) {
|
|
|
1268 |
this._flags.declaration_assignment = false;
|
|
|
1269 |
this.print_newline(false, true);
|
|
|
1270 |
} else if (this._options.comma_first) {
|
|
|
1271 |
// for comma-first, we want to allow a newline before the comma
|
|
|
1272 |
// to turn into a newline after the comma, which we will fixup later
|
|
|
1273 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1274 |
}
|
|
|
1275 |
} else if (this._flags.mode === MODE.ObjectLiteral ||
|
|
|
1276 |
(this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
|
|
|
1277 |
if (this._flags.mode === MODE.Statement) {
|
|
|
1278 |
this.restore_mode();
|
|
|
1279 |
}
|
|
|
1280 |
|
|
|
1281 |
if (!this._flags.inline_frame) {
|
|
|
1282 |
this.print_newline();
|
|
|
1283 |
}
|
|
|
1284 |
} else if (this._options.comma_first) {
|
|
|
1285 |
// EXPR or DO_BLOCK
|
|
|
1286 |
// for comma-first, we want to allow a newline before the comma
|
|
|
1287 |
// to turn into a newline after the comma, which we will fixup later
|
|
|
1288 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1289 |
}
|
|
|
1290 |
};
|
|
|
1291 |
|
|
|
1292 |
Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1293 |
var isGeneratorAsterisk = current_token.text === '*' &&
|
|
|
1294 |
(reserved_array(this._flags.last_token, ['function', 'yield']) ||
|
|
|
1295 |
(in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
|
|
|
1296 |
);
|
|
|
1297 |
var isUnary = in_array(current_token.text, ['-', '+']) && (
|
|
|
1298 |
in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
|
|
|
1299 |
in_array(this._flags.last_token.text, line_starters) ||
|
|
|
1300 |
this._flags.last_token.text === ','
|
|
|
1301 |
);
|
|
|
1302 |
|
|
|
1303 |
if (this.start_of_statement(current_token)) {
|
|
|
1304 |
// The conditional starts the statement if appropriate.
|
|
|
1305 |
} else {
|
|
|
1306 |
var preserve_statement_flags = !isGeneratorAsterisk;
|
|
|
1307 |
this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
|
|
|
1308 |
}
|
|
|
1309 |
|
|
|
1310 |
// hack for actionscript's import .*;
|
|
|
1311 |
if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
|
|
|
1312 |
this.print_token(current_token);
|
|
|
1313 |
return;
|
|
|
1314 |
}
|
|
|
1315 |
|
|
|
1316 |
if (current_token.text === '::') {
|
|
|
1317 |
// no spaces around exotic namespacing syntax operator
|
|
|
1318 |
this.print_token(current_token);
|
|
|
1319 |
return;
|
|
|
1320 |
}
|
|
|
1321 |
|
|
|
1322 |
if (in_array(current_token.text, ['-', '+']) && this.start_of_object_property()) {
|
|
|
1323 |
// numeric value with +/- symbol in front as a property
|
|
|
1324 |
this.print_token(current_token);
|
|
|
1325 |
return;
|
|
|
1326 |
}
|
|
|
1327 |
|
|
|
1328 |
// Allow line wrapping between operators when operator_position is
|
|
|
1329 |
// set to before or preserve
|
|
|
1330 |
if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
|
|
|
1331 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1332 |
}
|
|
|
1333 |
|
|
|
1334 |
if (current_token.text === ':' && this._flags.in_case) {
|
|
|
1335 |
this.print_token(current_token);
|
|
|
1336 |
|
|
|
1337 |
this._flags.in_case = false;
|
|
|
1338 |
this._flags.case_body = true;
|
|
|
1339 |
if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
|
|
|
1340 |
this.indent();
|
|
|
1341 |
this.print_newline();
|
|
|
1342 |
this._flags.case_block = false;
|
|
|
1343 |
} else {
|
|
|
1344 |
this._flags.case_block = true;
|
|
|
1345 |
this._output.space_before_token = true;
|
|
|
1346 |
}
|
|
|
1347 |
return;
|
|
|
1348 |
}
|
|
|
1349 |
|
|
|
1350 |
var space_before = true;
|
|
|
1351 |
var space_after = true;
|
|
|
1352 |
var in_ternary = false;
|
|
|
1353 |
if (current_token.text === ':') {
|
|
|
1354 |
if (this._flags.ternary_depth === 0) {
|
|
|
1355 |
// Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
|
|
|
1356 |
space_before = false;
|
|
|
1357 |
} else {
|
|
|
1358 |
this._flags.ternary_depth -= 1;
|
|
|
1359 |
in_ternary = true;
|
|
|
1360 |
}
|
|
|
1361 |
} else if (current_token.text === '?') {
|
|
|
1362 |
this._flags.ternary_depth += 1;
|
|
|
1363 |
}
|
|
|
1364 |
|
|
|
1365 |
// let's handle the operator_position option prior to any conflicting logic
|
|
|
1366 |
if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
|
|
|
1367 |
var isColon = current_token.text === ':';
|
|
|
1368 |
var isTernaryColon = (isColon && in_ternary);
|
|
|
1369 |
var isOtherColon = (isColon && !in_ternary);
|
|
|
1370 |
|
|
|
1371 |
switch (this._options.operator_position) {
|
|
|
1372 |
case OPERATOR_POSITION.before_newline:
|
|
|
1373 |
// if the current token is : and it's not a ternary statement then we set space_before to false
|
|
|
1374 |
this._output.space_before_token = !isOtherColon;
|
|
|
1375 |
|
|
|
1376 |
this.print_token(current_token);
|
|
|
1377 |
|
|
|
1378 |
if (!isColon || isTernaryColon) {
|
|
|
1379 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1380 |
}
|
|
|
1381 |
|
|
|
1382 |
this._output.space_before_token = true;
|
|
|
1383 |
return;
|
|
|
1384 |
|
|
|
1385 |
case OPERATOR_POSITION.after_newline:
|
|
|
1386 |
// if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
|
|
|
1387 |
// then print a newline.
|
|
|
1388 |
|
|
|
1389 |
this._output.space_before_token = true;
|
|
|
1390 |
|
|
|
1391 |
if (!isColon || isTernaryColon) {
|
|
|
1392 |
if (this._tokens.peek().newlines) {
|
|
|
1393 |
this.print_newline(false, true);
|
|
|
1394 |
} else {
|
|
|
1395 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1396 |
}
|
|
|
1397 |
} else {
|
|
|
1398 |
this._output.space_before_token = false;
|
|
|
1399 |
}
|
|
|
1400 |
|
|
|
1401 |
this.print_token(current_token);
|
|
|
1402 |
|
|
|
1403 |
this._output.space_before_token = true;
|
|
|
1404 |
return;
|
|
|
1405 |
|
|
|
1406 |
case OPERATOR_POSITION.preserve_newline:
|
|
|
1407 |
if (!isOtherColon) {
|
|
|
1408 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1409 |
}
|
|
|
1410 |
|
|
|
1411 |
// if we just added a newline, or the current token is : and it's not a ternary statement,
|
|
|
1412 |
// then we set space_before to false
|
|
|
1413 |
space_before = !(this._output.just_added_newline() || isOtherColon);
|
|
|
1414 |
|
|
|
1415 |
this._output.space_before_token = space_before;
|
|
|
1416 |
this.print_token(current_token);
|
|
|
1417 |
this._output.space_before_token = true;
|
|
|
1418 |
return;
|
|
|
1419 |
}
|
|
|
1420 |
}
|
|
|
1421 |
|
|
|
1422 |
if (isGeneratorAsterisk) {
|
|
|
1423 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1424 |
space_before = false;
|
|
|
1425 |
var next_token = this._tokens.peek();
|
|
|
1426 |
space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
|
|
|
1427 |
} else if (current_token.text === '...') {
|
|
|
1428 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1429 |
space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
|
|
|
1430 |
space_after = false;
|
|
|
1431 |
} else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
|
|
|
1432 |
// unary operators (and binary +/- pretending to be unary) special cases
|
|
|
1433 |
if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
|
|
|
1434 |
this.allow_wrap_or_preserved_newline(current_token);
|
|
|
1435 |
}
|
|
|
1436 |
|
|
|
1437 |
space_before = false;
|
|
|
1438 |
space_after = false;
|
|
|
1439 |
|
|
|
1440 |
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
|
|
|
1441 |
// if there is a newline between -- or ++ and anything else we should preserve it.
|
|
|
1442 |
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
|
|
|
1443 |
var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
|
|
|
1444 |
if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
|
|
|
1445 |
this.restore_mode();
|
|
|
1446 |
}
|
|
|
1447 |
this.print_newline(new_line_needed, true);
|
|
|
1448 |
}
|
|
|
1449 |
|
|
|
1450 |
if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
|
|
|
1451 |
// for (;; ++i)
|
|
|
1452 |
// ^^^
|
|
|
1453 |
space_before = true;
|
|
|
1454 |
}
|
|
|
1455 |
|
|
|
1456 |
if (this._flags.last_token.type === TOKEN.RESERVED) {
|
|
|
1457 |
space_before = true;
|
|
|
1458 |
} else if (this._flags.last_token.type === TOKEN.END_EXPR) {
|
|
|
1459 |
space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
|
|
|
1460 |
} else if (this._flags.last_token.type === TOKEN.OPERATOR) {
|
|
|
1461 |
// a++ + ++b;
|
|
|
1462 |
// a - -b
|
|
|
1463 |
space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
|
|
|
1464 |
// + and - are not unary when preceeded by -- or ++ operator
|
|
|
1465 |
// a-- + b
|
|
|
1466 |
// a * +b
|
|
|
1467 |
// a - -b
|
|
|
1468 |
if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
|
|
|
1469 |
space_after = true;
|
|
|
1470 |
}
|
|
|
1471 |
}
|
|
|
1472 |
|
|
|
1473 |
|
|
|
1474 |
if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
|
|
|
1475 |
(this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
|
|
|
1476 |
// { foo; --i }
|
|
|
1477 |
// foo(); --bar;
|
|
|
1478 |
this.print_newline();
|
|
|
1479 |
}
|
|
|
1480 |
}
|
|
|
1481 |
|
|
|
1482 |
this._output.space_before_token = this._output.space_before_token || space_before;
|
|
|
1483 |
this.print_token(current_token);
|
|
|
1484 |
this._output.space_before_token = space_after;
|
|
|
1485 |
};
|
|
|
1486 |
|
|
|
1487 |
Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
|
|
|
1488 |
if (this._output.raw) {
|
|
|
1489 |
this._output.add_raw_token(current_token);
|
|
|
1490 |
if (current_token.directives && current_token.directives.preserve === 'end') {
|
|
|
1491 |
// If we're testing the raw output behavior, do not allow a directive to turn it off.
|
|
|
1492 |
this._output.raw = this._options.test_output_raw;
|
|
|
1493 |
}
|
|
|
1494 |
return;
|
|
|
1495 |
}
|
|
|
1496 |
|
|
|
1497 |
if (current_token.directives) {
|
|
|
1498 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1499 |
this.print_token(current_token);
|
|
|
1500 |
if (current_token.directives.preserve === 'start') {
|
|
|
1501 |
this._output.raw = true;
|
|
|
1502 |
}
|
|
|
1503 |
this.print_newline(false, true);
|
|
|
1504 |
return;
|
|
|
1505 |
}
|
|
|
1506 |
|
|
|
1507 |
// inline block
|
|
|
1508 |
if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
|
|
|
1509 |
this._output.space_before_token = true;
|
|
|
1510 |
this.print_token(current_token);
|
|
|
1511 |
this._output.space_before_token = true;
|
|
|
1512 |
return;
|
|
|
1513 |
} else {
|
|
|
1514 |
this.print_block_commment(current_token, preserve_statement_flags);
|
|
|
1515 |
}
|
|
|
1516 |
};
|
|
|
1517 |
|
|
|
1518 |
Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
|
|
|
1519 |
var lines = split_linebreaks(current_token.text);
|
|
|
1520 |
var j; // iterator for this case
|
|
|
1521 |
var javadoc = false;
|
|
|
1522 |
var starless = false;
|
|
|
1523 |
var lastIndent = current_token.whitespace_before;
|
|
|
1524 |
var lastIndentLength = lastIndent.length;
|
|
|
1525 |
|
|
|
1526 |
// block comment starts with a new line
|
|
|
1527 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1528 |
|
|
|
1529 |
// first line always indented
|
|
|
1530 |
this.print_token_line_indentation(current_token);
|
|
|
1531 |
this._output.add_token(lines[0]);
|
|
|
1532 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1533 |
|
|
|
1534 |
|
|
|
1535 |
if (lines.length > 1) {
|
|
|
1536 |
lines = lines.slice(1);
|
|
|
1537 |
javadoc = all_lines_start_with(lines, '*');
|
|
|
1538 |
starless = each_line_matches_indent(lines, lastIndent);
|
|
|
1539 |
|
|
|
1540 |
if (javadoc) {
|
|
|
1541 |
this._flags.alignment = 1;
|
|
|
1542 |
}
|
|
|
1543 |
|
|
|
1544 |
for (j = 0; j < lines.length; j++) {
|
|
|
1545 |
if (javadoc) {
|
|
|
1546 |
// javadoc: reformat and re-indent
|
|
|
1547 |
this.print_token_line_indentation(current_token);
|
|
|
1548 |
this._output.add_token(ltrim(lines[j]));
|
|
|
1549 |
} else if (starless && lines[j]) {
|
|
|
1550 |
// starless: re-indent non-empty content, avoiding trim
|
|
|
1551 |
this.print_token_line_indentation(current_token);
|
|
|
1552 |
this._output.add_token(lines[j].substring(lastIndentLength));
|
|
|
1553 |
} else {
|
|
|
1554 |
// normal comments output raw
|
|
|
1555 |
this._output.current_line.set_indent(-1);
|
|
|
1556 |
this._output.add_token(lines[j]);
|
|
|
1557 |
}
|
|
|
1558 |
|
|
|
1559 |
// for comments on their own line or more than one line, make sure there's a new line after
|
|
|
1560 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1561 |
}
|
|
|
1562 |
|
|
|
1563 |
this._flags.alignment = 0;
|
|
|
1564 |
}
|
|
|
1565 |
};
|
|
|
1566 |
|
|
|
1567 |
|
|
|
1568 |
Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
|
|
|
1569 |
if (current_token.newlines) {
|
|
|
1570 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1571 |
} else {
|
|
|
1572 |
this._output.trim(true);
|
|
|
1573 |
}
|
|
|
1574 |
|
|
|
1575 |
this._output.space_before_token = true;
|
|
|
1576 |
this.print_token(current_token);
|
|
|
1577 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1578 |
};
|
|
|
1579 |
|
|
|
1580 |
Beautifier.prototype.handle_dot = function(current_token) {
|
|
|
1581 |
if (this.start_of_statement(current_token)) {
|
|
|
1582 |
// The conditional starts the statement if appropriate.
|
|
|
1583 |
} else {
|
|
|
1584 |
this.handle_whitespace_and_comments(current_token, true);
|
|
|
1585 |
}
|
|
|
1586 |
|
|
|
1587 |
if (this._flags.last_token.text.match('^[0-9]+$')) {
|
|
|
1588 |
this._output.space_before_token = true;
|
|
|
1589 |
}
|
|
|
1590 |
|
|
|
1591 |
if (reserved_array(this._flags.last_token, special_words)) {
|
|
|
1592 |
this._output.space_before_token = false;
|
|
|
1593 |
} else {
|
|
|
1594 |
// allow preserved newlines before dots in general
|
|
|
1595 |
// force newlines on dots after close paren when break_chained - for bar().baz()
|
|
|
1596 |
this.allow_wrap_or_preserved_newline(current_token,
|
|
|
1597 |
this._flags.last_token.text === ')' && this._options.break_chained_methods);
|
|
|
1598 |
}
|
|
|
1599 |
|
|
|
1600 |
// Only unindent chained method dot if this dot starts a new line.
|
|
|
1601 |
// Otherwise the automatic extra indentation removal will handle the over indent
|
|
|
1602 |
if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
|
|
|
1603 |
this.deindent();
|
|
|
1604 |
}
|
|
|
1605 |
|
|
|
1606 |
this.print_token(current_token);
|
|
|
1607 |
};
|
|
|
1608 |
|
|
|
1609 |
Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
|
|
|
1610 |
this.print_token(current_token);
|
|
|
1611 |
|
|
|
1612 |
if (current_token.text[current_token.text.length - 1] === '\n') {
|
|
|
1613 |
this.print_newline(false, preserve_statement_flags);
|
|
|
1614 |
}
|
|
|
1615 |
};
|
|
|
1616 |
|
|
|
1617 |
Beautifier.prototype.handle_eof = function(current_token) {
|
|
|
1618 |
// Unwind any open statements
|
|
|
1619 |
while (this._flags.mode === MODE.Statement) {
|
|
|
1620 |
this.restore_mode();
|
|
|
1621 |
}
|
|
|
1622 |
this.handle_whitespace_and_comments(current_token);
|
|
|
1623 |
};
|
|
|
1624 |
|
|
|
1625 |
module.exports.Beautifier = Beautifier;
|
|
|
1626 |
|
|
|
1627 |
|
|
|
1628 |
/***/ }),
|
|
|
1629 |
/* 2 */
|
|
|
1630 |
/***/ (function(module) {
|
|
|
1631 |
|
|
|
1632 |
/*jshint node:true */
|
|
|
1633 |
/*
|
|
|
1634 |
The MIT License (MIT)
|
|
|
1635 |
|
|
|
1636 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
1637 |
|
|
|
1638 |
Permission is hereby granted, free of charge, to any person
|
|
|
1639 |
obtaining a copy of this software and associated documentation files
|
|
|
1640 |
(the "Software"), to deal in the Software without restriction,
|
|
|
1641 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
1642 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
1643 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
1644 |
subject to the following conditions:
|
|
|
1645 |
|
|
|
1646 |
The above copyright notice and this permission notice shall be
|
|
|
1647 |
included in all copies or substantial portions of the Software.
|
|
|
1648 |
|
|
|
1649 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
1650 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
1651 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
1652 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
1653 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
1654 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
1655 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
1656 |
SOFTWARE.
|
|
|
1657 |
*/
|
|
|
1658 |
|
|
|
1659 |
|
|
|
1660 |
|
|
|
1661 |
function OutputLine(parent) {
|
|
|
1662 |
this.__parent = parent;
|
|
|
1663 |
this.__character_count = 0;
|
|
|
1664 |
// use indent_count as a marker for this.__lines that have preserved indentation
|
|
|
1665 |
this.__indent_count = -1;
|
|
|
1666 |
this.__alignment_count = 0;
|
|
|
1667 |
this.__wrap_point_index = 0;
|
|
|
1668 |
this.__wrap_point_character_count = 0;
|
|
|
1669 |
this.__wrap_point_indent_count = -1;
|
|
|
1670 |
this.__wrap_point_alignment_count = 0;
|
|
|
1671 |
|
|
|
1672 |
this.__items = [];
|
|
|
1673 |
}
|
|
|
1674 |
|
|
|
1675 |
OutputLine.prototype.clone_empty = function() {
|
|
|
1676 |
var line = new OutputLine(this.__parent);
|
|
|
1677 |
line.set_indent(this.__indent_count, this.__alignment_count);
|
|
|
1678 |
return line;
|
|
|
1679 |
};
|
|
|
1680 |
|
|
|
1681 |
OutputLine.prototype.item = function(index) {
|
|
|
1682 |
if (index < 0) {
|
|
|
1683 |
return this.__items[this.__items.length + index];
|
|
|
1684 |
} else {
|
|
|
1685 |
return this.__items[index];
|
|
|
1686 |
}
|
|
|
1687 |
};
|
|
|
1688 |
|
|
|
1689 |
OutputLine.prototype.has_match = function(pattern) {
|
|
|
1690 |
for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
|
|
|
1691 |
if (this.__items[lastCheckedOutput].match(pattern)) {
|
|
|
1692 |
return true;
|
|
|
1693 |
}
|
|
|
1694 |
}
|
|
|
1695 |
return false;
|
|
|
1696 |
};
|
|
|
1697 |
|
|
|
1698 |
OutputLine.prototype.set_indent = function(indent, alignment) {
|
|
|
1699 |
if (this.is_empty()) {
|
|
|
1700 |
this.__indent_count = indent || 0;
|
|
|
1701 |
this.__alignment_count = alignment || 0;
|
|
|
1702 |
this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
|
|
|
1703 |
}
|
|
|
1704 |
};
|
|
|
1705 |
|
|
|
1706 |
OutputLine.prototype._set_wrap_point = function() {
|
|
|
1707 |
if (this.__parent.wrap_line_length) {
|
|
|
1708 |
this.__wrap_point_index = this.__items.length;
|
|
|
1709 |
this.__wrap_point_character_count = this.__character_count;
|
|
|
1710 |
this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
|
|
|
1711 |
this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
|
|
|
1712 |
}
|
|
|
1713 |
};
|
|
|
1714 |
|
|
|
1715 |
OutputLine.prototype._should_wrap = function() {
|
|
|
1716 |
return this.__wrap_point_index &&
|
|
|
1717 |
this.__character_count > this.__parent.wrap_line_length &&
|
|
|
1718 |
this.__wrap_point_character_count > this.__parent.next_line.__character_count;
|
|
|
1719 |
};
|
|
|
1720 |
|
|
|
1721 |
OutputLine.prototype._allow_wrap = function() {
|
|
|
1722 |
if (this._should_wrap()) {
|
|
|
1723 |
this.__parent.add_new_line();
|
|
|
1724 |
var next = this.__parent.current_line;
|
|
|
1725 |
next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
|
|
|
1726 |
next.__items = this.__items.slice(this.__wrap_point_index);
|
|
|
1727 |
this.__items = this.__items.slice(0, this.__wrap_point_index);
|
|
|
1728 |
|
|
|
1729 |
next.__character_count += this.__character_count - this.__wrap_point_character_count;
|
|
|
1730 |
this.__character_count = this.__wrap_point_character_count;
|
|
|
1731 |
|
|
|
1732 |
if (next.__items[0] === " ") {
|
|
|
1733 |
next.__items.splice(0, 1);
|
|
|
1734 |
next.__character_count -= 1;
|
|
|
1735 |
}
|
|
|
1736 |
return true;
|
|
|
1737 |
}
|
|
|
1738 |
return false;
|
|
|
1739 |
};
|
|
|
1740 |
|
|
|
1741 |
OutputLine.prototype.is_empty = function() {
|
|
|
1742 |
return this.__items.length === 0;
|
|
|
1743 |
};
|
|
|
1744 |
|
|
|
1745 |
OutputLine.prototype.last = function() {
|
|
|
1746 |
if (!this.is_empty()) {
|
|
|
1747 |
return this.__items[this.__items.length - 1];
|
|
|
1748 |
} else {
|
|
|
1749 |
return null;
|
|
|
1750 |
}
|
|
|
1751 |
};
|
|
|
1752 |
|
|
|
1753 |
OutputLine.prototype.push = function(item) {
|
|
|
1754 |
this.__items.push(item);
|
|
|
1755 |
var last_newline_index = item.lastIndexOf('\n');
|
|
|
1756 |
if (last_newline_index !== -1) {
|
|
|
1757 |
this.__character_count = item.length - last_newline_index;
|
|
|
1758 |
} else {
|
|
|
1759 |
this.__character_count += item.length;
|
|
|
1760 |
}
|
|
|
1761 |
};
|
|
|
1762 |
|
|
|
1763 |
OutputLine.prototype.pop = function() {
|
|
|
1764 |
var item = null;
|
|
|
1765 |
if (!this.is_empty()) {
|
|
|
1766 |
item = this.__items.pop();
|
|
|
1767 |
this.__character_count -= item.length;
|
|
|
1768 |
}
|
|
|
1769 |
return item;
|
|
|
1770 |
};
|
|
|
1771 |
|
|
|
1772 |
|
|
|
1773 |
OutputLine.prototype._remove_indent = function() {
|
|
|
1774 |
if (this.__indent_count > 0) {
|
|
|
1775 |
this.__indent_count -= 1;
|
|
|
1776 |
this.__character_count -= this.__parent.indent_size;
|
|
|
1777 |
}
|
|
|
1778 |
};
|
|
|
1779 |
|
|
|
1780 |
OutputLine.prototype._remove_wrap_indent = function() {
|
|
|
1781 |
if (this.__wrap_point_indent_count > 0) {
|
|
|
1782 |
this.__wrap_point_indent_count -= 1;
|
|
|
1783 |
}
|
|
|
1784 |
};
|
|
|
1785 |
OutputLine.prototype.trim = function() {
|
|
|
1786 |
while (this.last() === ' ') {
|
|
|
1787 |
this.__items.pop();
|
|
|
1788 |
this.__character_count -= 1;
|
|
|
1789 |
}
|
|
|
1790 |
};
|
|
|
1791 |
|
|
|
1792 |
OutputLine.prototype.toString = function() {
|
|
|
1793 |
var result = '';
|
|
|
1794 |
if (this.is_empty()) {
|
|
|
1795 |
if (this.__parent.indent_empty_lines) {
|
|
|
1796 |
result = this.__parent.get_indent_string(this.__indent_count);
|
|
|
1797 |
}
|
|
|
1798 |
} else {
|
|
|
1799 |
result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
|
|
|
1800 |
result += this.__items.join('');
|
|
|
1801 |
}
|
|
|
1802 |
return result;
|
|
|
1803 |
};
|
|
|
1804 |
|
|
|
1805 |
function IndentStringCache(options, baseIndentString) {
|
|
|
1806 |
this.__cache = [''];
|
|
|
1807 |
this.__indent_size = options.indent_size;
|
|
|
1808 |
this.__indent_string = options.indent_char;
|
|
|
1809 |
if (!options.indent_with_tabs) {
|
|
|
1810 |
this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
|
|
|
1811 |
}
|
|
|
1812 |
|
|
|
1813 |
// Set to null to continue support for auto detection of base indent
|
|
|
1814 |
baseIndentString = baseIndentString || '';
|
|
|
1815 |
if (options.indent_level > 0) {
|
|
|
1816 |
baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
|
|
|
1817 |
}
|
|
|
1818 |
|
|
|
1819 |
this.__base_string = baseIndentString;
|
|
|
1820 |
this.__base_string_length = baseIndentString.length;
|
|
|
1821 |
}
|
|
|
1822 |
|
|
|
1823 |
IndentStringCache.prototype.get_indent_size = function(indent, column) {
|
|
|
1824 |
var result = this.__base_string_length;
|
|
|
1825 |
column = column || 0;
|
|
|
1826 |
if (indent < 0) {
|
|
|
1827 |
result = 0;
|
|
|
1828 |
}
|
|
|
1829 |
result += indent * this.__indent_size;
|
|
|
1830 |
result += column;
|
|
|
1831 |
return result;
|
|
|
1832 |
};
|
|
|
1833 |
|
|
|
1834 |
IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
|
|
|
1835 |
var result = this.__base_string;
|
|
|
1836 |
column = column || 0;
|
|
|
1837 |
if (indent_level < 0) {
|
|
|
1838 |
indent_level = 0;
|
|
|
1839 |
result = '';
|
|
|
1840 |
}
|
|
|
1841 |
column += indent_level * this.__indent_size;
|
|
|
1842 |
this.__ensure_cache(column);
|
|
|
1843 |
result += this.__cache[column];
|
|
|
1844 |
return result;
|
|
|
1845 |
};
|
|
|
1846 |
|
|
|
1847 |
IndentStringCache.prototype.__ensure_cache = function(column) {
|
|
|
1848 |
while (column >= this.__cache.length) {
|
|
|
1849 |
this.__add_column();
|
|
|
1850 |
}
|
|
|
1851 |
};
|
|
|
1852 |
|
|
|
1853 |
IndentStringCache.prototype.__add_column = function() {
|
|
|
1854 |
var column = this.__cache.length;
|
|
|
1855 |
var indent = 0;
|
|
|
1856 |
var result = '';
|
|
|
1857 |
if (this.__indent_size && column >= this.__indent_size) {
|
|
|
1858 |
indent = Math.floor(column / this.__indent_size);
|
|
|
1859 |
column -= indent * this.__indent_size;
|
|
|
1860 |
result = new Array(indent + 1).join(this.__indent_string);
|
|
|
1861 |
}
|
|
|
1862 |
if (column) {
|
|
|
1863 |
result += new Array(column + 1).join(' ');
|
|
|
1864 |
}
|
|
|
1865 |
|
|
|
1866 |
this.__cache.push(result);
|
|
|
1867 |
};
|
|
|
1868 |
|
|
|
1869 |
function Output(options, baseIndentString) {
|
|
|
1870 |
this.__indent_cache = new IndentStringCache(options, baseIndentString);
|
|
|
1871 |
this.raw = false;
|
|
|
1872 |
this._end_with_newline = options.end_with_newline;
|
|
|
1873 |
this.indent_size = options.indent_size;
|
|
|
1874 |
this.wrap_line_length = options.wrap_line_length;
|
|
|
1875 |
this.indent_empty_lines = options.indent_empty_lines;
|
|
|
1876 |
this.__lines = [];
|
|
|
1877 |
this.previous_line = null;
|
|
|
1878 |
this.current_line = null;
|
|
|
1879 |
this.next_line = new OutputLine(this);
|
|
|
1880 |
this.space_before_token = false;
|
|
|
1881 |
this.non_breaking_space = false;
|
|
|
1882 |
this.previous_token_wrapped = false;
|
|
|
1883 |
// initialize
|
|
|
1884 |
this.__add_outputline();
|
|
|
1885 |
}
|
|
|
1886 |
|
|
|
1887 |
Output.prototype.__add_outputline = function() {
|
|
|
1888 |
this.previous_line = this.current_line;
|
|
|
1889 |
this.current_line = this.next_line.clone_empty();
|
|
|
1890 |
this.__lines.push(this.current_line);
|
|
|
1891 |
};
|
|
|
1892 |
|
|
|
1893 |
Output.prototype.get_line_number = function() {
|
|
|
1894 |
return this.__lines.length;
|
|
|
1895 |
};
|
|
|
1896 |
|
|
|
1897 |
Output.prototype.get_indent_string = function(indent, column) {
|
|
|
1898 |
return this.__indent_cache.get_indent_string(indent, column);
|
|
|
1899 |
};
|
|
|
1900 |
|
|
|
1901 |
Output.prototype.get_indent_size = function(indent, column) {
|
|
|
1902 |
return this.__indent_cache.get_indent_size(indent, column);
|
|
|
1903 |
};
|
|
|
1904 |
|
|
|
1905 |
Output.prototype.is_empty = function() {
|
|
|
1906 |
return !this.previous_line && this.current_line.is_empty();
|
|
|
1907 |
};
|
|
|
1908 |
|
|
|
1909 |
Output.prototype.add_new_line = function(force_newline) {
|
|
|
1910 |
// never newline at the start of file
|
|
|
1911 |
// otherwise, newline only if we didn't just add one or we're forced
|
|
|
1912 |
if (this.is_empty() ||
|
|
|
1913 |
(!force_newline && this.just_added_newline())) {
|
|
|
1914 |
return false;
|
|
|
1915 |
}
|
|
|
1916 |
|
|
|
1917 |
// if raw output is enabled, don't print additional newlines,
|
|
|
1918 |
// but still return True as though you had
|
|
|
1919 |
if (!this.raw) {
|
|
|
1920 |
this.__add_outputline();
|
|
|
1921 |
}
|
|
|
1922 |
return true;
|
|
|
1923 |
};
|
|
|
1924 |
|
|
|
1925 |
Output.prototype.get_code = function(eol) {
|
|
|
1926 |
this.trim(true);
|
|
|
1927 |
|
|
|
1928 |
// handle some edge cases where the last tokens
|
|
|
1929 |
// has text that ends with newline(s)
|
|
|
1930 |
var last_item = this.current_line.pop();
|
|
|
1931 |
if (last_item) {
|
|
|
1932 |
if (last_item[last_item.length - 1] === '\n') {
|
|
|
1933 |
last_item = last_item.replace(/\n+$/g, '');
|
|
|
1934 |
}
|
|
|
1935 |
this.current_line.push(last_item);
|
|
|
1936 |
}
|
|
|
1937 |
|
|
|
1938 |
if (this._end_with_newline) {
|
|
|
1939 |
this.__add_outputline();
|
|
|
1940 |
}
|
|
|
1941 |
|
|
|
1942 |
var sweet_code = this.__lines.join('\n');
|
|
|
1943 |
|
|
|
1944 |
if (eol !== '\n') {
|
|
|
1945 |
sweet_code = sweet_code.replace(/[\n]/g, eol);
|
|
|
1946 |
}
|
|
|
1947 |
return sweet_code;
|
|
|
1948 |
};
|
|
|
1949 |
|
|
|
1950 |
Output.prototype.set_wrap_point = function() {
|
|
|
1951 |
this.current_line._set_wrap_point();
|
|
|
1952 |
};
|
|
|
1953 |
|
|
|
1954 |
Output.prototype.set_indent = function(indent, alignment) {
|
|
|
1955 |
indent = indent || 0;
|
|
|
1956 |
alignment = alignment || 0;
|
|
|
1957 |
|
|
|
1958 |
// Next line stores alignment values
|
|
|
1959 |
this.next_line.set_indent(indent, alignment);
|
|
|
1960 |
|
|
|
1961 |
// Never indent your first output indent at the start of the file
|
|
|
1962 |
if (this.__lines.length > 1) {
|
|
|
1963 |
this.current_line.set_indent(indent, alignment);
|
|
|
1964 |
return true;
|
|
|
1965 |
}
|
|
|
1966 |
|
|
|
1967 |
this.current_line.set_indent();
|
|
|
1968 |
return false;
|
|
|
1969 |
};
|
|
|
1970 |
|
|
|
1971 |
Output.prototype.add_raw_token = function(token) {
|
|
|
1972 |
for (var x = 0; x < token.newlines; x++) {
|
|
|
1973 |
this.__add_outputline();
|
|
|
1974 |
}
|
|
|
1975 |
this.current_line.set_indent(-1);
|
|
|
1976 |
this.current_line.push(token.whitespace_before);
|
|
|
1977 |
this.current_line.push(token.text);
|
|
|
1978 |
this.space_before_token = false;
|
|
|
1979 |
this.non_breaking_space = false;
|
|
|
1980 |
this.previous_token_wrapped = false;
|
|
|
1981 |
};
|
|
|
1982 |
|
|
|
1983 |
Output.prototype.add_token = function(printable_token) {
|
|
|
1984 |
this.__add_space_before_token();
|
|
|
1985 |
this.current_line.push(printable_token);
|
|
|
1986 |
this.space_before_token = false;
|
|
|
1987 |
this.non_breaking_space = false;
|
|
|
1988 |
this.previous_token_wrapped = this.current_line._allow_wrap();
|
|
|
1989 |
};
|
|
|
1990 |
|
|
|
1991 |
Output.prototype.__add_space_before_token = function() {
|
|
|
1992 |
if (this.space_before_token && !this.just_added_newline()) {
|
|
|
1993 |
if (!this.non_breaking_space) {
|
|
|
1994 |
this.set_wrap_point();
|
|
|
1995 |
}
|
|
|
1996 |
this.current_line.push(' ');
|
|
|
1997 |
}
|
|
|
1998 |
};
|
|
|
1999 |
|
|
|
2000 |
Output.prototype.remove_indent = function(index) {
|
|
|
2001 |
var output_length = this.__lines.length;
|
|
|
2002 |
while (index < output_length) {
|
|
|
2003 |
this.__lines[index]._remove_indent();
|
|
|
2004 |
index++;
|
|
|
2005 |
}
|
|
|
2006 |
this.current_line._remove_wrap_indent();
|
|
|
2007 |
};
|
|
|
2008 |
|
|
|
2009 |
Output.prototype.trim = function(eat_newlines) {
|
|
|
2010 |
eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
|
|
|
2011 |
|
|
|
2012 |
this.current_line.trim();
|
|
|
2013 |
|
|
|
2014 |
while (eat_newlines && this.__lines.length > 1 &&
|
|
|
2015 |
this.current_line.is_empty()) {
|
|
|
2016 |
this.__lines.pop();
|
|
|
2017 |
this.current_line = this.__lines[this.__lines.length - 1];
|
|
|
2018 |
this.current_line.trim();
|
|
|
2019 |
}
|
|
|
2020 |
|
|
|
2021 |
this.previous_line = this.__lines.length > 1 ?
|
|
|
2022 |
this.__lines[this.__lines.length - 2] : null;
|
|
|
2023 |
};
|
|
|
2024 |
|
|
|
2025 |
Output.prototype.just_added_newline = function() {
|
|
|
2026 |
return this.current_line.is_empty();
|
|
|
2027 |
};
|
|
|
2028 |
|
|
|
2029 |
Output.prototype.just_added_blankline = function() {
|
|
|
2030 |
return this.is_empty() ||
|
|
|
2031 |
(this.current_line.is_empty() && this.previous_line.is_empty());
|
|
|
2032 |
};
|
|
|
2033 |
|
|
|
2034 |
Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
|
|
|
2035 |
var index = this.__lines.length - 2;
|
|
|
2036 |
while (index >= 0) {
|
|
|
2037 |
var potentialEmptyLine = this.__lines[index];
|
|
|
2038 |
if (potentialEmptyLine.is_empty()) {
|
|
|
2039 |
break;
|
|
|
2040 |
} else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
|
|
|
2041 |
potentialEmptyLine.item(-1) !== ends_with) {
|
|
|
2042 |
this.__lines.splice(index + 1, 0, new OutputLine(this));
|
|
|
2043 |
this.previous_line = this.__lines[this.__lines.length - 2];
|
|
|
2044 |
break;
|
|
|
2045 |
}
|
|
|
2046 |
index--;
|
|
|
2047 |
}
|
|
|
2048 |
};
|
|
|
2049 |
|
|
|
2050 |
module.exports.Output = Output;
|
|
|
2051 |
|
|
|
2052 |
|
|
|
2053 |
/***/ }),
|
|
|
2054 |
/* 3 */
|
|
|
2055 |
/***/ (function(module) {
|
|
|
2056 |
|
|
|
2057 |
/*jshint node:true */
|
|
|
2058 |
/*
|
|
|
2059 |
|
|
|
2060 |
The MIT License (MIT)
|
|
|
2061 |
|
|
|
2062 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
2063 |
|
|
|
2064 |
Permission is hereby granted, free of charge, to any person
|
|
|
2065 |
obtaining a copy of this software and associated documentation files
|
|
|
2066 |
(the "Software"), to deal in the Software without restriction,
|
|
|
2067 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
2068 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
2069 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
2070 |
subject to the following conditions:
|
|
|
2071 |
|
|
|
2072 |
The above copyright notice and this permission notice shall be
|
|
|
2073 |
included in all copies or substantial portions of the Software.
|
|
|
2074 |
|
|
|
2075 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
2076 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
2077 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
2078 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
2079 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
2080 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
2081 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2082 |
SOFTWARE.
|
|
|
2083 |
*/
|
|
|
2084 |
|
|
|
2085 |
|
|
|
2086 |
|
|
|
2087 |
function Token(type, text, newlines, whitespace_before) {
|
|
|
2088 |
this.type = type;
|
|
|
2089 |
this.text = text;
|
|
|
2090 |
|
|
|
2091 |
// comments_before are
|
|
|
2092 |
// comments that have a new line before them
|
|
|
2093 |
// and may or may not have a newline after
|
|
|
2094 |
// this is a set of comments before
|
|
|
2095 |
this.comments_before = null; /* inline comment*/
|
|
|
2096 |
|
|
|
2097 |
|
|
|
2098 |
// this.comments_after = new TokenStream(); // no new line before and newline after
|
|
|
2099 |
this.newlines = newlines || 0;
|
|
|
2100 |
this.whitespace_before = whitespace_before || '';
|
|
|
2101 |
this.parent = null;
|
|
|
2102 |
this.next = null;
|
|
|
2103 |
this.previous = null;
|
|
|
2104 |
this.opened = null;
|
|
|
2105 |
this.closed = null;
|
|
|
2106 |
this.directives = null;
|
|
|
2107 |
}
|
|
|
2108 |
|
|
|
2109 |
|
|
|
2110 |
module.exports.Token = Token;
|
|
|
2111 |
|
|
|
2112 |
|
|
|
2113 |
/***/ }),
|
|
|
2114 |
/* 4 */
|
|
|
2115 |
/***/ (function(__unused_webpack_module, exports) {
|
|
|
2116 |
|
|
|
2117 |
/* jshint node: true, curly: false */
|
|
|
2118 |
// Parts of this section of code is taken from acorn.
|
|
|
2119 |
//
|
|
|
2120 |
// Acorn was written by Marijn Haverbeke and released under an MIT
|
|
|
2121 |
// license. The Unicode regexps (for identifiers and whitespace) were
|
|
|
2122 |
// taken from [Esprima](http://esprima.org) by Ariya Hidayat.
|
|
|
2123 |
//
|
|
|
2124 |
// Git repositories for Acorn are available at
|
|
|
2125 |
//
|
|
|
2126 |
// http://marijnhaverbeke.nl/git/acorn
|
|
|
2127 |
// https://github.com/marijnh/acorn.git
|
|
|
2128 |
|
|
|
2129 |
// ## Character categories
|
|
|
2130 |
|
|
|
2131 |
|
|
|
2132 |
|
|
|
2133 |
|
|
|
2134 |
// acorn used char codes to squeeze the last bit of performance out
|
|
|
2135 |
// Beautifier is okay without that, so we're using regex
|
|
|
2136 |
// permit # (23), $ (36), and @ (64). @ is used in ES7 decorators.
|
|
|
2137 |
// 65 through 91 are uppercase letters.
|
|
|
2138 |
// permit _ (95).
|
|
|
2139 |
// 97 through 123 are lowercase letters.
|
|
|
2140 |
var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
|
|
|
2141 |
|
|
|
2142 |
// inside an identifier @ is not allowed but 0-9 are.
|
|
|
2143 |
var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
|
|
|
2144 |
|
|
|
2145 |
// Big ugly regular expressions that match characters in the
|
|
|
2146 |
// whitespace, identifier, and identifier-start categories. These
|
|
|
2147 |
// are only applied when a character is found to actually have a
|
|
|
2148 |
// code point above 128.
|
|
|
2149 |
var nonASCIIidentifierStartChars = "\\xaa\\xb5\\xba\\xc0-\\xd6\\xd8-\\xf6\\xf8-\\u02c1\\u02c6-\\u02d1\\u02e0-\\u02e4\\u02ec\\u02ee\\u0370-\\u0374\\u0376\\u0377\\u037a-\\u037d\\u0386\\u0388-\\u038a\\u038c\\u038e-\\u03a1\\u03a3-\\u03f5\\u03f7-\\u0481\\u048a-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05d0-\\u05ea\\u05f0-\\u05f2\\u0620-\\u064a\\u066e\\u066f\\u0671-\\u06d3\\u06d5\\u06e5\\u06e6\\u06ee\\u06ef\\u06fa-\\u06fc\\u06ff\\u0710\\u0712-\\u072f\\u074d-\\u07a5\\u07b1\\u07ca-\\u07ea\\u07f4\\u07f5\\u07fa\\u0800-\\u0815\\u081a\\u0824\\u0828\\u0840-\\u0858\\u08a0\\u08a2-\\u08ac\\u0904-\\u0939\\u093d\\u0950\\u0958-\\u0961\\u0971-\\u0977\\u0979-\\u097f\\u0985-\\u098c\\u098f\\u0990\\u0993-\\u09a8\\u09aa-\\u09b0\\u09b2\\u09b6-\\u09b9\\u09bd\\u09ce\\u09dc\\u09dd\\u09df-\\u09e1\\u09f0\\u09f1\\u0a05-\\u0a0a\\u0a0f\\u0a10\\u0a13-\\u0a28\\u0a2a-\\u0a30\\u0a32\\u0a33\\u0a35\\u0a36\\u0a38\\u0a39\\u0a59-\\u0a5c\\u0a5e\\u0a72-\\u0a74\\u0a85-\\u0a8d\\u0a8f-\\u0a91\\u0a93-\\u0aa8\\u0aaa-\\u0ab0\\u0ab2\\u0ab3\\u0ab5-\\u0ab9\\u0abd\\u0ad0\\u0ae0\\u0ae1\\u0b05-\\u0b0c\\u0b0f\\u0b10\\u0b13-\\u0b28\\u0b2a-\\u0b30\\u0b32\\u0b33\\u0b35-\\u0b39\\u0b3d\\u0b5c\\u0b5d\\u0b5f-\\u0b61\\u0b71\\u0b83\\u0b85-\\u0b8a\\u0b8e-\\u0b90\\u0b92-\\u0b95\\u0b99\\u0b9a\\u0b9c\\u0b9e\\u0b9f\\u0ba3\\u0ba4\\u0ba8-\\u0baa\\u0bae-\\u0bb9\\u0bd0\\u0c05-\\u0c0c\\u0c0e-\\u0c10\\u0c12-\\u0c28\\u0c2a-\\u0c33\\u0c35-\\u0c39\\u0c3d\\u0c58\\u0c59\\u0c60\\u0c61\\u0c85-\\u0c8c\\u0c8e-\\u0c90\\u0c92-\\u0ca8\\u0caa-\\u0cb3\\u0cb5-\\u0cb9\\u0cbd\\u0cde\\u0ce0\\u0ce1\\u0cf1\\u0cf2\\u0d05-\\u0d0c\\u0d0e-\\u0d10\\u0d12-\\u0d3a\\u0d3d\\u0d4e\\u0d60\\u0d61\\u0d7a-\\u0d7f\\u0d85-\\u0d96\\u0d9a-\\u0db1\\u0db3-\\u0dbb\\u0dbd\\u0dc0-\\u0dc6\\u0e01-\\u0e30\\u0e32\\u0e33\\u0e40-\\u0e46\\u0e81\\u0e82\\u0e84\\u0e87\\u0e88\\u0e8a\\u0e8d\\u0e94-\\u0e97\\u0e99-\\u0e9f\\u0ea1-\\u0ea3\\u0ea5\\u0ea7\\u0eaa\\u0eab\\u0ead-\\u0eb0\\u0eb2\\u0eb3\\u0ebd\\u0ec0-\\u0ec4\\u0ec6\\u0edc-\\u0edf\\u0f00\\u0f40-\\u0f47\\u0f49-\\u0f6c\\u0f88-\\u0f8c\\u1000-\\u102a\\u103f\\u1050-\\u1055\\u105a-\\u105d\\u1061\\u1065\\u1066\\u106e-\\u1070\\u1075-\\u1081\\u108e\\u10a0-\\u10c5\\u10c7\\u10cd\\u10d0-\\u10fa\\u10fc-\\u1248\\u124a-\\u124d\\u1250-\\u1256\\u1258\\u125a-\\u125d\\u1260-\\u1288\\u128a-\\u128d\\u1290-\\u12b0\\u12b2-\\u12b5\\u12b8-\\u12be\\u12c0\\u12c2-\\u12c5\\u12c8-\\u12d6\\u12d8-\\u1310\\u1312-\\u1315\\u1318-\\u135a\\u1380-\\u138f\\u13a0-\\u13f4\\u1401-\\u166c\\u166f-\\u167f\\u1681-\\u169a\\u16a0-\\u16ea\\u16ee-\\u16f0\\u1700-\\u170c\\u170e-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176c\\u176e-\\u1770\\u1780-\\u17b3\\u17d7\\u17dc\\u1820-\\u1877\\u1880-\\u18a8\\u18aa\\u18b0-\\u18f5\\u1900-\\u191c\\u1950-\\u196d\\u1970-\\u1974\\u1980-\\u19ab\\u19c1-\\u19c7\\u1a00-\\u1a16\\u1a20-\\u1a54\\u1aa7\\u1b05-\\u1b33\\u1b45-\\u1b4b\\u1b83-\\u1ba0\\u1bae\\u1baf\\u1bba-\\u1be5\\u1c00-\\u1c23\\u1c4d-\\u1c4f\\u1c5a-\\u1c7d\\u1ce9-\\u1cec\\u1cee-\\u1cf1\\u1cf5\\u1cf6\\u1d00-\\u1dbf\\u1e00-\\u1f15\\u1f18-\\u1f1d\\u1f20-\\u1f45\\u1f48-\\u1f4d\\u1f50-\\u1f57\\u1f59\\u1f5b\\u1f5d\\u1f5f-\\u1f7d\\u1f80-\\u1fb4\\u1fb6-\\u1fbc\\u1fbe\\u1fc2-\\u1fc4\\u1fc6-\\u1fcc\\u1fd0-\\u1fd3\\u1fd6-\\u1fdb\\u1fe0-\\u1fec\\u1ff2-\\u1ff4\\u1ff6-\\u1ffc\\u2071\\u207f\\u2090-\\u209c\\u2102\\u2107\\u210a-\\u2113\\u2115\\u2119-\\u211d\\u2124\\u2126\\u2128\\u212a-\\u212d\\u212f-\\u2139\\u213c-\\u213f\\u2145-\\u2149\\u214e\\u2160-\\u2188\\u2c00-\\u2c2e\\u2c30-\\u2c5e\\u2c60-\\u2ce4\\u2ceb-\\u2cee\\u2cf2\\u2cf3\\u2d00-\\u2d25\\u2d27\\u2d2d\\u2d30-\\u2d67\\u2d6f\\u2d80-\\u2d96\\u2da0-\\u2da6\\u2da8-\\u2dae\\u2db0-\\u2db6\\u2db8-\\u2dbe\\u2dc0-\\u2dc6\\u2dc8-\\u2dce\\u2dd0-\\u2dd6\\u2dd8-\\u2dde\\u2e2f\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303c\\u3041-\\u3096\\u309d-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312d\\u3131-\\u318e\\u31a0-\\u31ba\\u31f0-\\u31ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\ua000-\\ua48c\\ua4d0-\\ua4fd\\ua500-\\ua60c\\ua610-\\ua61f\\ua62a\\ua62b\\ua640-\\ua66e\\ua67f-\\ua697\\ua6a0-\\ua6ef\\ua717-\\ua71f\\ua722-\\ua788\\ua78b-\\ua78e\\ua790-\\ua793\\ua7a0-\\ua7aa\\ua7f8-\\ua801\\ua803-\\ua805\\ua807-\\ua80a\\ua80c-\\ua822\\ua840-\\ua873\\ua882-\\ua8b3\\ua8f2-\\ua8f7\\ua8fb\\ua90a-\\ua925\\ua930-\\ua946\\ua960-\\ua97c\\ua984-\\ua9b2\\ua9cf\\uaa00-\\uaa28\\uaa40-\\uaa42\\uaa44-\\uaa4b\\uaa60-\\uaa76\\uaa7a\\uaa80-\\uaaaf\\uaab1\\uaab5\\uaab6\\uaab9-\\uaabd\\uaac0\\uaac2\\uaadb-\\uaadd\\uaae0-\\uaaea\\uaaf2-\\uaaf4\\uab01-\\uab06\\uab09-\\uab0e\\uab11-\\uab16\\uab20-\\uab26\\uab28-\\uab2e\\uabc0-\\uabe2\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufb00-\\ufb06\\ufb13-\\ufb17\\ufb1d\\ufb1f-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40\\ufb41\\ufb43\\ufb44\\ufb46-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc";
|
|
|
2150 |
var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u05bf\\u05c1\\u05c2\\u05c4\\u05c5\\u05c7\\u0610-\\u061a\\u0620-\\u0649\\u0672-\\u06d3\\u06e7-\\u06e8\\u06fb-\\u06fc\\u0730-\\u074a\\u0800-\\u0814\\u081b-\\u0823\\u0825-\\u0827\\u0829-\\u082d\\u0840-\\u0857\\u08e4-\\u08fe\\u0900-\\u0903\\u093a-\\u093c\\u093e-\\u094f\\u0951-\\u0957\\u0962-\\u0963\\u0966-\\u096f\\u0981-\\u0983\\u09bc\\u09be-\\u09c4\\u09c7\\u09c8\\u09d7\\u09df-\\u09e0\\u0a01-\\u0a03\\u0a3c\\u0a3e-\\u0a42\\u0a47\\u0a48\\u0a4b-\\u0a4d\\u0a51\\u0a66-\\u0a71\\u0a75\\u0a81-\\u0a83\\u0abc\\u0abe-\\u0ac5\\u0ac7-\\u0ac9\\u0acb-\\u0acd\\u0ae2-\\u0ae3\\u0ae6-\\u0aef\\u0b01-\\u0b03\\u0b3c\\u0b3e-\\u0b44\\u0b47\\u0b48\\u0b4b-\\u0b4d\\u0b56\\u0b57\\u0b5f-\\u0b60\\u0b66-\\u0b6f\\u0b82\\u0bbe-\\u0bc2\\u0bc6-\\u0bc8\\u0bca-\\u0bcd\\u0bd7\\u0be6-\\u0bef\\u0c01-\\u0c03\\u0c46-\\u0c48\\u0c4a-\\u0c4d\\u0c55\\u0c56\\u0c62-\\u0c63\\u0c66-\\u0c6f\\u0c82\\u0c83\\u0cbc\\u0cbe-\\u0cc4\\u0cc6-\\u0cc8\\u0cca-\\u0ccd\\u0cd5\\u0cd6\\u0ce2-\\u0ce3\\u0ce6-\\u0cef\\u0d02\\u0d03\\u0d46-\\u0d48\\u0d57\\u0d62-\\u0d63\\u0d66-\\u0d6f\\u0d82\\u0d83\\u0dca\\u0dcf-\\u0dd4\\u0dd6\\u0dd8-\\u0ddf\\u0df2\\u0df3\\u0e34-\\u0e3a\\u0e40-\\u0e45\\u0e50-\\u0e59\\u0eb4-\\u0eb9\\u0ec8-\\u0ecd\\u0ed0-\\u0ed9\\u0f18\\u0f19\\u0f20-\\u0f29\\u0f35\\u0f37\\u0f39\\u0f41-\\u0f47\\u0f71-\\u0f84\\u0f86-\\u0f87\\u0f8d-\\u0f97\\u0f99-\\u0fbc\\u0fc6\\u1000-\\u1029\\u1040-\\u1049\\u1067-\\u106d\\u1071-\\u1074\\u1082-\\u108d\\u108f-\\u109d\\u135d-\\u135f\\u170e-\\u1710\\u1720-\\u1730\\u1740-\\u1750\\u1772\\u1773\\u1780-\\u17b2\\u17dd\\u17e0-\\u17e9\\u180b-\\u180d\\u1810-\\u1819\\u1920-\\u192b\\u1930-\\u193b\\u1951-\\u196d\\u19b0-\\u19c0\\u19c8-\\u19c9\\u19d0-\\u19d9\\u1a00-\\u1a15\\u1a20-\\u1a53\\u1a60-\\u1a7c\\u1a7f-\\u1a89\\u1a90-\\u1a99\\u1b46-\\u1b4b\\u1b50-\\u1b59\\u1b6b-\\u1b73\\u1bb0-\\u1bb9\\u1be6-\\u1bf3\\u1c00-\\u1c22\\u1c40-\\u1c49\\u1c5b-\\u1c7d\\u1cd0-\\u1cd2\\u1d00-\\u1dbe\\u1e01-\\u1f15\\u200c\\u200d\\u203f\\u2040\\u2054\\u20d0-\\u20dc\\u20e1\\u20e5-\\u20f0\\u2d81-\\u2d96\\u2de0-\\u2dff\\u3021-\\u3028\\u3099\\u309a\\ua640-\\ua66d\\ua674-\\ua67d\\ua69f\\ua6f0-\\ua6f1\\ua7f8-\\ua800\\ua806\\ua80b\\ua823-\\ua827\\ua880-\\ua881\\ua8b4-\\ua8c4\\ua8d0-\\ua8d9\\ua8f3-\\ua8f7\\ua900-\\ua909\\ua926-\\ua92d\\ua930-\\ua945\\ua980-\\ua983\\ua9b3-\\ua9c0\\uaa00-\\uaa27\\uaa40-\\uaa41\\uaa4c-\\uaa4d\\uaa50-\\uaa59\\uaa7b\\uaae0-\\uaae9\\uaaf2-\\uaaf3\\uabc0-\\uabe1\\uabec\\uabed\\uabf0-\\uabf9\\ufb20-\\ufb28\\ufe00-\\ufe0f\\ufe20-\\ufe26\\ufe33\\ufe34\\ufe4d-\\ufe4f\\uff10-\\uff19\\uff3f";
|
|
|
2151 |
//var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|
|
2152 |
//var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|
|
2153 |
|
|
|
2154 |
var unicodeEscapeOrCodePoint = "\\\\u[0-9a-fA-F]{4}|\\\\u\\{[0-9a-fA-F]+\\}";
|
|
|
2155 |
var identifierStart = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
|
|
|
2156 |
var identifierChars = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
|
|
|
2157 |
|
|
|
2158 |
exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
|
|
|
2159 |
exports.identifierStart = new RegExp(identifierStart);
|
|
|
2160 |
exports.identifierMatch = new RegExp("(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
|
|
|
2161 |
|
|
|
2162 |
var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
|
|
|
2163 |
|
|
|
2164 |
// Whether a single character denotes a newline.
|
|
|
2165 |
|
|
|
2166 |
exports.newline = /[\n\r\u2028\u2029]/;
|
|
|
2167 |
|
|
|
2168 |
// Matches a whole line break (where CRLF is considered a single
|
|
|
2169 |
// line break). Used to count lines.
|
|
|
2170 |
|
|
|
2171 |
// in javascript, these two differ
|
|
|
2172 |
// in python they are the same, different methods are called on them
|
|
|
2173 |
exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
|
|
|
2174 |
exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
|
|
|
2175 |
|
|
|
2176 |
|
|
|
2177 |
/***/ }),
|
|
|
2178 |
/* 5 */
|
|
|
2179 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
2180 |
|
|
|
2181 |
/*jshint node:true */
|
|
|
2182 |
/*
|
|
|
2183 |
|
|
|
2184 |
The MIT License (MIT)
|
|
|
2185 |
|
|
|
2186 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
2187 |
|
|
|
2188 |
Permission is hereby granted, free of charge, to any person
|
|
|
2189 |
obtaining a copy of this software and associated documentation files
|
|
|
2190 |
(the "Software"), to deal in the Software without restriction,
|
|
|
2191 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
2192 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
2193 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
2194 |
subject to the following conditions:
|
|
|
2195 |
|
|
|
2196 |
The above copyright notice and this permission notice shall be
|
|
|
2197 |
included in all copies or substantial portions of the Software.
|
|
|
2198 |
|
|
|
2199 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
2200 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
2201 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
2202 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
2203 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
2204 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
2205 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2206 |
SOFTWARE.
|
|
|
2207 |
*/
|
|
|
2208 |
|
|
|
2209 |
|
|
|
2210 |
|
|
|
2211 |
var BaseOptions = (__webpack_require__(6).Options);
|
|
|
2212 |
|
|
|
2213 |
var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
|
|
|
2214 |
|
|
|
2215 |
function Options(options) {
|
|
|
2216 |
BaseOptions.call(this, options, 'js');
|
|
|
2217 |
|
|
|
2218 |
// compatibility, re
|
|
|
2219 |
var raw_brace_style = this.raw_options.brace_style || null;
|
|
|
2220 |
if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
|
|
|
2221 |
this.raw_options.brace_style = "expand";
|
|
|
2222 |
} else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
|
|
|
2223 |
this.raw_options.brace_style = "collapse,preserve-inline";
|
|
|
2224 |
} else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
|
|
|
2225 |
this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
|
|
|
2226 |
// } else if (!raw_brace_style) { //Nothing exists to set it
|
|
|
2227 |
// raw_brace_style = "collapse";
|
|
|
2228 |
}
|
|
|
2229 |
|
|
|
2230 |
//preserve-inline in delimited string will trigger brace_preserve_inline, everything
|
|
|
2231 |
//else is considered a brace_style and the last one only will have an effect
|
|
|
2232 |
|
|
|
2233 |
var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
|
|
|
2234 |
|
|
|
2235 |
this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
|
|
|
2236 |
this.brace_style = "collapse";
|
|
|
2237 |
|
|
|
2238 |
for (var bs = 0; bs < brace_style_split.length; bs++) {
|
|
|
2239 |
if (brace_style_split[bs] === "preserve-inline") {
|
|
|
2240 |
this.brace_preserve_inline = true;
|
|
|
2241 |
} else {
|
|
|
2242 |
this.brace_style = brace_style_split[bs];
|
|
|
2243 |
}
|
|
|
2244 |
}
|
|
|
2245 |
|
|
|
2246 |
this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
|
|
|
2247 |
this.break_chained_methods = this._get_boolean('break_chained_methods');
|
|
|
2248 |
this.space_in_paren = this._get_boolean('space_in_paren');
|
|
|
2249 |
this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
|
|
|
2250 |
this.jslint_happy = this._get_boolean('jslint_happy');
|
|
|
2251 |
this.space_after_anon_function = this._get_boolean('space_after_anon_function');
|
|
|
2252 |
this.space_after_named_function = this._get_boolean('space_after_named_function');
|
|
|
2253 |
this.keep_array_indentation = this._get_boolean('keep_array_indentation');
|
|
|
2254 |
this.space_before_conditional = this._get_boolean('space_before_conditional', true);
|
|
|
2255 |
this.unescape_strings = this._get_boolean('unescape_strings');
|
|
|
2256 |
this.e4x = this._get_boolean('e4x');
|
|
|
2257 |
this.comma_first = this._get_boolean('comma_first');
|
|
|
2258 |
this.operator_position = this._get_selection('operator_position', validPositionValues);
|
|
|
2259 |
|
|
|
2260 |
// For testing of beautify preserve:start directive
|
|
|
2261 |
this.test_output_raw = this._get_boolean('test_output_raw');
|
|
|
2262 |
|
|
|
2263 |
// force this._options.space_after_anon_function to true if this._options.jslint_happy
|
|
|
2264 |
if (this.jslint_happy) {
|
|
|
2265 |
this.space_after_anon_function = true;
|
|
|
2266 |
}
|
|
|
2267 |
|
|
|
2268 |
}
|
|
|
2269 |
Options.prototype = new BaseOptions();
|
|
|
2270 |
|
|
|
2271 |
|
|
|
2272 |
|
|
|
2273 |
module.exports.Options = Options;
|
|
|
2274 |
|
|
|
2275 |
|
|
|
2276 |
/***/ }),
|
|
|
2277 |
/* 6 */
|
|
|
2278 |
/***/ (function(module) {
|
|
|
2279 |
|
|
|
2280 |
/*jshint node:true */
|
|
|
2281 |
/*
|
|
|
2282 |
|
|
|
2283 |
The MIT License (MIT)
|
|
|
2284 |
|
|
|
2285 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
2286 |
|
|
|
2287 |
Permission is hereby granted, free of charge, to any person
|
|
|
2288 |
obtaining a copy of this software and associated documentation files
|
|
|
2289 |
(the "Software"), to deal in the Software without restriction,
|
|
|
2290 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
2291 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
2292 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
2293 |
subject to the following conditions:
|
|
|
2294 |
|
|
|
2295 |
The above copyright notice and this permission notice shall be
|
|
|
2296 |
included in all copies or substantial portions of the Software.
|
|
|
2297 |
|
|
|
2298 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
2299 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
2300 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
2301 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
2302 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
2303 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
2304 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2305 |
SOFTWARE.
|
|
|
2306 |
*/
|
|
|
2307 |
|
|
|
2308 |
|
|
|
2309 |
|
|
|
2310 |
function Options(options, merge_child_field) {
|
|
|
2311 |
this.raw_options = _mergeOpts(options, merge_child_field);
|
|
|
2312 |
|
|
|
2313 |
// Support passing the source text back with no change
|
|
|
2314 |
this.disabled = this._get_boolean('disabled');
|
|
|
2315 |
|
|
|
2316 |
this.eol = this._get_characters('eol', 'auto');
|
|
|
2317 |
this.end_with_newline = this._get_boolean('end_with_newline');
|
|
|
2318 |
this.indent_size = this._get_number('indent_size', 4);
|
|
|
2319 |
this.indent_char = this._get_characters('indent_char', ' ');
|
|
|
2320 |
this.indent_level = this._get_number('indent_level');
|
|
|
2321 |
|
|
|
2322 |
this.preserve_newlines = this._get_boolean('preserve_newlines', true);
|
|
|
2323 |
this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
|
|
|
2324 |
if (!this.preserve_newlines) {
|
|
|
2325 |
this.max_preserve_newlines = 0;
|
|
|
2326 |
}
|
|
|
2327 |
|
|
|
2328 |
this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
|
|
|
2329 |
if (this.indent_with_tabs) {
|
|
|
2330 |
this.indent_char = '\t';
|
|
|
2331 |
|
|
|
2332 |
// indent_size behavior changed after 1.8.6
|
|
|
2333 |
// It used to be that indent_size would be
|
|
|
2334 |
// set to 1 for indent_with_tabs. That is no longer needed and
|
|
|
2335 |
// actually doesn't make sense - why not use spaces? Further,
|
|
|
2336 |
// that might produce unexpected behavior - tabs being used
|
|
|
2337 |
// for single-column alignment. So, when indent_with_tabs is true
|
|
|
2338 |
// and indent_size is 1, reset indent_size to 4.
|
|
|
2339 |
if (this.indent_size === 1) {
|
|
|
2340 |
this.indent_size = 4;
|
|
|
2341 |
}
|
|
|
2342 |
}
|
|
|
2343 |
|
|
|
2344 |
// Backwards compat with 1.3.x
|
|
|
2345 |
this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
|
|
|
2346 |
|
|
|
2347 |
this.indent_empty_lines = this._get_boolean('indent_empty_lines');
|
|
|
2348 |
|
|
|
2349 |
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular']
|
|
|
2350 |
// For now, 'auto' = all off for javascript, all except angular on for html (and inline javascript/css).
|
|
|
2351 |
// other values ignored
|
|
|
2352 |
this.templating = this._get_selection_list('templating', ['auto', 'none', 'angular', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
|
|
|
2353 |
}
|
|
|
2354 |
|
|
|
2355 |
Options.prototype._get_array = function(name, default_value) {
|
|
|
2356 |
var option_value = this.raw_options[name];
|
|
|
2357 |
var result = default_value || [];
|
|
|
2358 |
if (typeof option_value === 'object') {
|
|
|
2359 |
if (option_value !== null && typeof option_value.concat === 'function') {
|
|
|
2360 |
result = option_value.concat();
|
|
|
2361 |
}
|
|
|
2362 |
} else if (typeof option_value === 'string') {
|
|
|
2363 |
result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
|
|
|
2364 |
}
|
|
|
2365 |
return result;
|
|
|
2366 |
};
|
|
|
2367 |
|
|
|
2368 |
Options.prototype._get_boolean = function(name, default_value) {
|
|
|
2369 |
var option_value = this.raw_options[name];
|
|
|
2370 |
var result = option_value === undefined ? !!default_value : !!option_value;
|
|
|
2371 |
return result;
|
|
|
2372 |
};
|
|
|
2373 |
|
|
|
2374 |
Options.prototype._get_characters = function(name, default_value) {
|
|
|
2375 |
var option_value = this.raw_options[name];
|
|
|
2376 |
var result = default_value || '';
|
|
|
2377 |
if (typeof option_value === 'string') {
|
|
|
2378 |
result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
|
|
|
2379 |
}
|
|
|
2380 |
return result;
|
|
|
2381 |
};
|
|
|
2382 |
|
|
|
2383 |
Options.prototype._get_number = function(name, default_value) {
|
|
|
2384 |
var option_value = this.raw_options[name];
|
|
|
2385 |
default_value = parseInt(default_value, 10);
|
|
|
2386 |
if (isNaN(default_value)) {
|
|
|
2387 |
default_value = 0;
|
|
|
2388 |
}
|
|
|
2389 |
var result = parseInt(option_value, 10);
|
|
|
2390 |
if (isNaN(result)) {
|
|
|
2391 |
result = default_value;
|
|
|
2392 |
}
|
|
|
2393 |
return result;
|
|
|
2394 |
};
|
|
|
2395 |
|
|
|
2396 |
Options.prototype._get_selection = function(name, selection_list, default_value) {
|
|
|
2397 |
var result = this._get_selection_list(name, selection_list, default_value);
|
|
|
2398 |
if (result.length !== 1) {
|
|
|
2399 |
throw new Error(
|
|
|
2400 |
"Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
|
|
|
2401 |
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
|
|
|
2402 |
}
|
|
|
2403 |
|
|
|
2404 |
return result[0];
|
|
|
2405 |
};
|
|
|
2406 |
|
|
|
2407 |
|
|
|
2408 |
Options.prototype._get_selection_list = function(name, selection_list, default_value) {
|
|
|
2409 |
if (!selection_list || selection_list.length === 0) {
|
|
|
2410 |
throw new Error("Selection list cannot be empty.");
|
|
|
2411 |
}
|
|
|
2412 |
|
|
|
2413 |
default_value = default_value || [selection_list[0]];
|
|
|
2414 |
if (!this._is_valid_selection(default_value, selection_list)) {
|
|
|
2415 |
throw new Error("Invalid Default Value!");
|
|
|
2416 |
}
|
|
|
2417 |
|
|
|
2418 |
var result = this._get_array(name, default_value);
|
|
|
2419 |
if (!this._is_valid_selection(result, selection_list)) {
|
|
|
2420 |
throw new Error(
|
|
|
2421 |
"Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
|
|
|
2422 |
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
|
|
|
2423 |
}
|
|
|
2424 |
|
|
|
2425 |
return result;
|
|
|
2426 |
};
|
|
|
2427 |
|
|
|
2428 |
Options.prototype._is_valid_selection = function(result, selection_list) {
|
|
|
2429 |
return result.length && selection_list.length &&
|
|
|
2430 |
!result.some(function(item) { return selection_list.indexOf(item) === -1; });
|
|
|
2431 |
};
|
|
|
2432 |
|
|
|
2433 |
|
|
|
2434 |
// merges child options up with the parent options object
|
|
|
2435 |
// Example: obj = {a: 1, b: {a: 2}}
|
|
|
2436 |
// mergeOpts(obj, 'b')
|
|
|
2437 |
//
|
|
|
2438 |
// Returns: {a: 2}
|
|
|
2439 |
function _mergeOpts(allOptions, childFieldName) {
|
|
|
2440 |
var finalOpts = {};
|
|
|
2441 |
allOptions = _normalizeOpts(allOptions);
|
|
|
2442 |
var name;
|
|
|
2443 |
|
|
|
2444 |
for (name in allOptions) {
|
|
|
2445 |
if (name !== childFieldName) {
|
|
|
2446 |
finalOpts[name] = allOptions[name];
|
|
|
2447 |
}
|
|
|
2448 |
}
|
|
|
2449 |
|
|
|
2450 |
//merge in the per type settings for the childFieldName
|
|
|
2451 |
if (childFieldName && allOptions[childFieldName]) {
|
|
|
2452 |
for (name in allOptions[childFieldName]) {
|
|
|
2453 |
finalOpts[name] = allOptions[childFieldName][name];
|
|
|
2454 |
}
|
|
|
2455 |
}
|
|
|
2456 |
return finalOpts;
|
|
|
2457 |
}
|
|
|
2458 |
|
|
|
2459 |
function _normalizeOpts(options) {
|
|
|
2460 |
var convertedOpts = {};
|
|
|
2461 |
var key;
|
|
|
2462 |
|
|
|
2463 |
for (key in options) {
|
|
|
2464 |
var newKey = key.replace(/-/g, "_");
|
|
|
2465 |
convertedOpts[newKey] = options[key];
|
|
|
2466 |
}
|
|
|
2467 |
return convertedOpts;
|
|
|
2468 |
}
|
|
|
2469 |
|
|
|
2470 |
module.exports.Options = Options;
|
|
|
2471 |
module.exports.normalizeOpts = _normalizeOpts;
|
|
|
2472 |
module.exports.mergeOpts = _mergeOpts;
|
|
|
2473 |
|
|
|
2474 |
|
|
|
2475 |
/***/ }),
|
|
|
2476 |
/* 7 */
|
|
|
2477 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
2478 |
|
|
|
2479 |
/*jshint node:true */
|
|
|
2480 |
/*
|
|
|
2481 |
|
|
|
2482 |
The MIT License (MIT)
|
|
|
2483 |
|
|
|
2484 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
2485 |
|
|
|
2486 |
Permission is hereby granted, free of charge, to any person
|
|
|
2487 |
obtaining a copy of this software and associated documentation files
|
|
|
2488 |
(the "Software"), to deal in the Software without restriction,
|
|
|
2489 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
2490 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
2491 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
2492 |
subject to the following conditions:
|
|
|
2493 |
|
|
|
2494 |
The above copyright notice and this permission notice shall be
|
|
|
2495 |
included in all copies or substantial portions of the Software.
|
|
|
2496 |
|
|
|
2497 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
2498 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
2499 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
2500 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
2501 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
2502 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
2503 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2504 |
SOFTWARE.
|
|
|
2505 |
*/
|
|
|
2506 |
|
|
|
2507 |
|
|
|
2508 |
|
|
|
2509 |
var InputScanner = (__webpack_require__(8).InputScanner);
|
|
|
2510 |
var BaseTokenizer = (__webpack_require__(9).Tokenizer);
|
|
|
2511 |
var BASETOKEN = (__webpack_require__(9).TOKEN);
|
|
|
2512 |
var Directives = (__webpack_require__(13).Directives);
|
|
|
2513 |
var acorn = __webpack_require__(4);
|
|
|
2514 |
var Pattern = (__webpack_require__(12).Pattern);
|
|
|
2515 |
var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
|
|
|
2516 |
|
|
|
2517 |
|
|
|
2518 |
function in_array(what, arr) {
|
|
|
2519 |
return arr.indexOf(what) !== -1;
|
|
|
2520 |
}
|
|
|
2521 |
|
|
|
2522 |
|
|
|
2523 |
var TOKEN = {
|
|
|
2524 |
START_EXPR: 'TK_START_EXPR',
|
|
|
2525 |
END_EXPR: 'TK_END_EXPR',
|
|
|
2526 |
START_BLOCK: 'TK_START_BLOCK',
|
|
|
2527 |
END_BLOCK: 'TK_END_BLOCK',
|
|
|
2528 |
WORD: 'TK_WORD',
|
|
|
2529 |
RESERVED: 'TK_RESERVED',
|
|
|
2530 |
SEMICOLON: 'TK_SEMICOLON',
|
|
|
2531 |
STRING: 'TK_STRING',
|
|
|
2532 |
EQUALS: 'TK_EQUALS',
|
|
|
2533 |
OPERATOR: 'TK_OPERATOR',
|
|
|
2534 |
COMMA: 'TK_COMMA',
|
|
|
2535 |
BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
|
|
|
2536 |
COMMENT: 'TK_COMMENT',
|
|
|
2537 |
DOT: 'TK_DOT',
|
|
|
2538 |
UNKNOWN: 'TK_UNKNOWN',
|
|
|
2539 |
START: BASETOKEN.START,
|
|
|
2540 |
RAW: BASETOKEN.RAW,
|
|
|
2541 |
EOF: BASETOKEN.EOF
|
|
|
2542 |
};
|
|
|
2543 |
|
|
|
2544 |
|
|
|
2545 |
var directives_core = new Directives(/\/\*/, /\*\//);
|
|
|
2546 |
|
|
|
2547 |
var number_pattern = /0[xX][0123456789abcdefABCDEF_]*n?|0[oO][01234567_]*n?|0[bB][01_]*n?|\d[\d_]*n|(?:\.\d[\d_]*|\d[\d_]*\.?[\d_]*)(?:[eE][+-]?[\d_]+)?/;
|
|
|
2548 |
|
|
|
2549 |
var digit = /[0-9]/;
|
|
|
2550 |
|
|
|
2551 |
// Dot "." must be distinguished from "..." and decimal
|
|
|
2552 |
var dot_pattern = /[^\d\.]/;
|
|
|
2553 |
|
|
|
2554 |
var positionable_operators = (
|
|
|
2555 |
">>> === !== &&= ??= ||= " +
|
|
|
2556 |
"<< && >= ** != == <= >> || ?? |> " +
|
|
|
2557 |
"< / - + > : & % ? ^ | *").split(' ');
|
|
|
2558 |
|
|
|
2559 |
// IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
|
|
|
2560 |
// Also, you must update possitionable operators separately from punct
|
|
|
2561 |
var punct =
|
|
|
2562 |
">>>= " +
|
|
|
2563 |
"... >>= <<= === >>> !== **= &&= ??= ||= " +
|
|
|
2564 |
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
|
|
|
2565 |
"= ! ? > < : / ^ - + * & % ~ |";
|
|
|
2566 |
|
|
|
2567 |
punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
|
|
|
2568 |
// ?. but not if followed by a number
|
|
|
2569 |
punct = '\\?\\.(?!\\d) ' + punct;
|
|
|
2570 |
punct = punct.replace(/ /g, '|');
|
|
|
2571 |
|
|
|
2572 |
var punct_pattern = new RegExp(punct);
|
|
|
2573 |
|
|
|
2574 |
// words which should always start on new line.
|
|
|
2575 |
var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
|
|
|
2576 |
var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
|
|
|
2577 |
var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
|
|
|
2578 |
|
|
|
2579 |
// var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
|
|
|
2580 |
|
|
|
2581 |
var in_html_comment;
|
|
|
2582 |
|
|
|
2583 |
var Tokenizer = function(input_string, options) {
|
|
|
2584 |
BaseTokenizer.call(this, input_string, options);
|
|
|
2585 |
|
|
|
2586 |
this._patterns.whitespace = this._patterns.whitespace.matching(
|
|
|
2587 |
/\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
|
|
|
2588 |
/\u2028\u2029/.source);
|
|
|
2589 |
|
|
|
2590 |
var pattern_reader = new Pattern(this._input);
|
|
|
2591 |
var templatable = new TemplatablePattern(this._input)
|
|
|
2592 |
.read_options(this._options);
|
|
|
2593 |
|
|
|
2594 |
this.__patterns = {
|
|
|
2595 |
template: templatable,
|
|
|
2596 |
identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
|
|
|
2597 |
number: pattern_reader.matching(number_pattern),
|
|
|
2598 |
punct: pattern_reader.matching(punct_pattern),
|
|
|
2599 |
// comment ends just before nearest linefeed or end of file
|
|
|
2600 |
comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
|
|
|
2601 |
// /* ... */ comment ends with nearest */ or end of file
|
|
|
2602 |
block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
|
|
|
2603 |
html_comment_start: pattern_reader.matching(/<!--/),
|
|
|
2604 |
html_comment_end: pattern_reader.matching(/-->/),
|
|
|
2605 |
include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
|
|
|
2606 |
shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
|
|
|
2607 |
xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
|
|
|
2608 |
single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
|
|
|
2609 |
double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
|
|
|
2610 |
template_text: templatable.until(/[`\\$]/),
|
|
|
2611 |
template_expression: templatable.until(/[`}\\]/)
|
|
|
2612 |
};
|
|
|
2613 |
|
|
|
2614 |
};
|
|
|
2615 |
Tokenizer.prototype = new BaseTokenizer();
|
|
|
2616 |
|
|
|
2617 |
Tokenizer.prototype._is_comment = function(current_token) {
|
|
|
2618 |
return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
|
|
|
2619 |
};
|
|
|
2620 |
|
|
|
2621 |
Tokenizer.prototype._is_opening = function(current_token) {
|
|
|
2622 |
return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
|
|
|
2623 |
};
|
|
|
2624 |
|
|
|
2625 |
Tokenizer.prototype._is_closing = function(current_token, open_token) {
|
|
|
2626 |
return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
|
|
|
2627 |
(open_token && (
|
|
|
2628 |
(current_token.text === ']' && open_token.text === '[') ||
|
|
|
2629 |
(current_token.text === ')' && open_token.text === '(') ||
|
|
|
2630 |
(current_token.text === '}' && open_token.text === '{')));
|
|
|
2631 |
};
|
|
|
2632 |
|
|
|
2633 |
Tokenizer.prototype._reset = function() {
|
|
|
2634 |
in_html_comment = false;
|
|
|
2635 |
};
|
|
|
2636 |
|
|
|
2637 |
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
|
|
|
2638 |
var token = null;
|
|
|
2639 |
this._readWhitespace();
|
|
|
2640 |
var c = this._input.peek();
|
|
|
2641 |
|
|
|
2642 |
if (c === null) {
|
|
|
2643 |
return this._create_token(TOKEN.EOF, '');
|
|
|
2644 |
}
|
|
|
2645 |
|
|
|
2646 |
token = token || this._read_non_javascript(c);
|
|
|
2647 |
token = token || this._read_string(c);
|
|
|
2648 |
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
|
|
|
2649 |
token = token || this._read_word(previous_token);
|
|
|
2650 |
token = token || this._read_singles(c);
|
|
|
2651 |
token = token || this._read_comment(c);
|
|
|
2652 |
token = token || this._read_regexp(c, previous_token);
|
|
|
2653 |
token = token || this._read_xml(c, previous_token);
|
|
|
2654 |
token = token || this._read_punctuation();
|
|
|
2655 |
token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
|
|
|
2656 |
|
|
|
2657 |
return token;
|
|
|
2658 |
};
|
|
|
2659 |
|
|
|
2660 |
Tokenizer.prototype._read_word = function(previous_token) {
|
|
|
2661 |
var resulting_string;
|
|
|
2662 |
resulting_string = this.__patterns.identifier.read();
|
|
|
2663 |
if (resulting_string !== '') {
|
|
|
2664 |
resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
|
|
|
2665 |
if (!(previous_token.type === TOKEN.DOT ||
|
|
|
2666 |
(previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
|
|
|
2667 |
reserved_word_pattern.test(resulting_string)) {
|
|
|
2668 |
if ((resulting_string === 'in' || resulting_string === 'of') &&
|
|
|
2669 |
(previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
|
|
|
2670 |
return this._create_token(TOKEN.OPERATOR, resulting_string);
|
|
|
2671 |
}
|
|
|
2672 |
return this._create_token(TOKEN.RESERVED, resulting_string);
|
|
|
2673 |
}
|
|
|
2674 |
return this._create_token(TOKEN.WORD, resulting_string);
|
|
|
2675 |
}
|
|
|
2676 |
|
|
|
2677 |
resulting_string = this.__patterns.number.read();
|
|
|
2678 |
if (resulting_string !== '') {
|
|
|
2679 |
return this._create_token(TOKEN.WORD, resulting_string);
|
|
|
2680 |
}
|
|
|
2681 |
};
|
|
|
2682 |
|
|
|
2683 |
Tokenizer.prototype._read_singles = function(c) {
|
|
|
2684 |
var token = null;
|
|
|
2685 |
if (c === '(' || c === '[') {
|
|
|
2686 |
token = this._create_token(TOKEN.START_EXPR, c);
|
|
|
2687 |
} else if (c === ')' || c === ']') {
|
|
|
2688 |
token = this._create_token(TOKEN.END_EXPR, c);
|
|
|
2689 |
} else if (c === '{') {
|
|
|
2690 |
token = this._create_token(TOKEN.START_BLOCK, c);
|
|
|
2691 |
} else if (c === '}') {
|
|
|
2692 |
token = this._create_token(TOKEN.END_BLOCK, c);
|
|
|
2693 |
} else if (c === ';') {
|
|
|
2694 |
token = this._create_token(TOKEN.SEMICOLON, c);
|
|
|
2695 |
} else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
|
|
|
2696 |
token = this._create_token(TOKEN.DOT, c);
|
|
|
2697 |
} else if (c === ',') {
|
|
|
2698 |
token = this._create_token(TOKEN.COMMA, c);
|
|
|
2699 |
}
|
|
|
2700 |
|
|
|
2701 |
if (token) {
|
|
|
2702 |
this._input.next();
|
|
|
2703 |
}
|
|
|
2704 |
return token;
|
|
|
2705 |
};
|
|
|
2706 |
|
|
|
2707 |
Tokenizer.prototype._read_pair = function(c, d) {
|
|
|
2708 |
var token = null;
|
|
|
2709 |
if (c === '#' && d === '{') {
|
|
|
2710 |
token = this._create_token(TOKEN.START_BLOCK, c + d);
|
|
|
2711 |
}
|
|
|
2712 |
|
|
|
2713 |
if (token) {
|
|
|
2714 |
this._input.next();
|
|
|
2715 |
this._input.next();
|
|
|
2716 |
}
|
|
|
2717 |
return token;
|
|
|
2718 |
};
|
|
|
2719 |
|
|
|
2720 |
Tokenizer.prototype._read_punctuation = function() {
|
|
|
2721 |
var resulting_string = this.__patterns.punct.read();
|
|
|
2722 |
|
|
|
2723 |
if (resulting_string !== '') {
|
|
|
2724 |
if (resulting_string === '=') {
|
|
|
2725 |
return this._create_token(TOKEN.EQUALS, resulting_string);
|
|
|
2726 |
} else if (resulting_string === '?.') {
|
|
|
2727 |
return this._create_token(TOKEN.DOT, resulting_string);
|
|
|
2728 |
} else {
|
|
|
2729 |
return this._create_token(TOKEN.OPERATOR, resulting_string);
|
|
|
2730 |
}
|
|
|
2731 |
}
|
|
|
2732 |
};
|
|
|
2733 |
|
|
|
2734 |
Tokenizer.prototype._read_non_javascript = function(c) {
|
|
|
2735 |
var resulting_string = '';
|
|
|
2736 |
|
|
|
2737 |
if (c === '#') {
|
|
|
2738 |
if (this._is_first_token()) {
|
|
|
2739 |
resulting_string = this.__patterns.shebang.read();
|
|
|
2740 |
|
|
|
2741 |
if (resulting_string) {
|
|
|
2742 |
return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
|
|
2743 |
}
|
|
|
2744 |
}
|
|
|
2745 |
|
|
|
2746 |
// handles extendscript #includes
|
|
|
2747 |
resulting_string = this.__patterns.include.read();
|
|
|
2748 |
|
|
|
2749 |
if (resulting_string) {
|
|
|
2750 |
return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
|
|
2751 |
}
|
|
|
2752 |
|
|
|
2753 |
c = this._input.next();
|
|
|
2754 |
|
|
|
2755 |
// Spidermonkey-specific sharp variables for circular references. Considered obsolete.
|
|
|
2756 |
var sharp = '#';
|
|
|
2757 |
if (this._input.hasNext() && this._input.testChar(digit)) {
|
|
|
2758 |
do {
|
|
|
2759 |
c = this._input.next();
|
|
|
2760 |
sharp += c;
|
|
|
2761 |
} while (this._input.hasNext() && c !== '#' && c !== '=');
|
|
|
2762 |
if (c === '#') {
|
|
|
2763 |
//
|
|
|
2764 |
} else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
|
|
|
2765 |
sharp += '[]';
|
|
|
2766 |
this._input.next();
|
|
|
2767 |
this._input.next();
|
|
|
2768 |
} else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
|
|
|
2769 |
sharp += '{}';
|
|
|
2770 |
this._input.next();
|
|
|
2771 |
this._input.next();
|
|
|
2772 |
}
|
|
|
2773 |
return this._create_token(TOKEN.WORD, sharp);
|
|
|
2774 |
}
|
|
|
2775 |
|
|
|
2776 |
this._input.back();
|
|
|
2777 |
|
|
|
2778 |
} else if (c === '<' && this._is_first_token()) {
|
|
|
2779 |
resulting_string = this.__patterns.html_comment_start.read();
|
|
|
2780 |
if (resulting_string) {
|
|
|
2781 |
while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
|
|
|
2782 |
resulting_string += this._input.next();
|
|
|
2783 |
}
|
|
|
2784 |
in_html_comment = true;
|
|
|
2785 |
return this._create_token(TOKEN.COMMENT, resulting_string);
|
|
|
2786 |
}
|
|
|
2787 |
} else if (in_html_comment && c === '-') {
|
|
|
2788 |
resulting_string = this.__patterns.html_comment_end.read();
|
|
|
2789 |
if (resulting_string) {
|
|
|
2790 |
in_html_comment = false;
|
|
|
2791 |
return this._create_token(TOKEN.COMMENT, resulting_string);
|
|
|
2792 |
}
|
|
|
2793 |
}
|
|
|
2794 |
|
|
|
2795 |
return null;
|
|
|
2796 |
};
|
|
|
2797 |
|
|
|
2798 |
Tokenizer.prototype._read_comment = function(c) {
|
|
|
2799 |
var token = null;
|
|
|
2800 |
if (c === '/') {
|
|
|
2801 |
var comment = '';
|
|
|
2802 |
if (this._input.peek(1) === '*') {
|
|
|
2803 |
// peek for comment /* ... */
|
|
|
2804 |
comment = this.__patterns.block_comment.read();
|
|
|
2805 |
var directives = directives_core.get_directives(comment);
|
|
|
2806 |
if (directives && directives.ignore === 'start') {
|
|
|
2807 |
comment += directives_core.readIgnored(this._input);
|
|
|
2808 |
}
|
|
|
2809 |
comment = comment.replace(acorn.allLineBreaks, '\n');
|
|
|
2810 |
token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
|
|
|
2811 |
token.directives = directives;
|
|
|
2812 |
} else if (this._input.peek(1) === '/') {
|
|
|
2813 |
// peek for comment // ...
|
|
|
2814 |
comment = this.__patterns.comment.read();
|
|
|
2815 |
token = this._create_token(TOKEN.COMMENT, comment);
|
|
|
2816 |
}
|
|
|
2817 |
}
|
|
|
2818 |
return token;
|
|
|
2819 |
};
|
|
|
2820 |
|
|
|
2821 |
Tokenizer.prototype._read_string = function(c) {
|
|
|
2822 |
if (c === '`' || c === "'" || c === '"') {
|
|
|
2823 |
var resulting_string = this._input.next();
|
|
|
2824 |
this.has_char_escapes = false;
|
|
|
2825 |
|
|
|
2826 |
if (c === '`') {
|
|
|
2827 |
resulting_string += this._read_string_recursive('`', true, '${');
|
|
|
2828 |
} else {
|
|
|
2829 |
resulting_string += this._read_string_recursive(c);
|
|
|
2830 |
}
|
|
|
2831 |
|
|
|
2832 |
if (this.has_char_escapes && this._options.unescape_strings) {
|
|
|
2833 |
resulting_string = unescape_string(resulting_string);
|
|
|
2834 |
}
|
|
|
2835 |
|
|
|
2836 |
if (this._input.peek() === c) {
|
|
|
2837 |
resulting_string += this._input.next();
|
|
|
2838 |
}
|
|
|
2839 |
|
|
|
2840 |
resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
|
|
|
2841 |
|
|
|
2842 |
return this._create_token(TOKEN.STRING, resulting_string);
|
|
|
2843 |
}
|
|
|
2844 |
|
|
|
2845 |
return null;
|
|
|
2846 |
};
|
|
|
2847 |
|
|
|
2848 |
Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
|
|
|
2849 |
// regex and xml can only appear in specific locations during parsing
|
|
|
2850 |
return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
|
|
|
2851 |
(previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
|
|
|
2852 |
previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
|
|
|
2853 |
(in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
|
|
|
2854 |
TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
|
|
|
2855 |
]));
|
|
|
2856 |
};
|
|
|
2857 |
|
|
|
2858 |
Tokenizer.prototype._read_regexp = function(c, previous_token) {
|
|
|
2859 |
|
|
|
2860 |
if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
|
|
|
2861 |
// handle regexp
|
|
|
2862 |
//
|
|
|
2863 |
var resulting_string = this._input.next();
|
|
|
2864 |
var esc = false;
|
|
|
2865 |
|
|
|
2866 |
var in_char_class = false;
|
|
|
2867 |
while (this._input.hasNext() &&
|
|
|
2868 |
((esc || in_char_class || this._input.peek() !== c) &&
|
|
|
2869 |
!this._input.testChar(acorn.newline))) {
|
|
|
2870 |
resulting_string += this._input.peek();
|
|
|
2871 |
if (!esc) {
|
|
|
2872 |
esc = this._input.peek() === '\\';
|
|
|
2873 |
if (this._input.peek() === '[') {
|
|
|
2874 |
in_char_class = true;
|
|
|
2875 |
} else if (this._input.peek() === ']') {
|
|
|
2876 |
in_char_class = false;
|
|
|
2877 |
}
|
|
|
2878 |
} else {
|
|
|
2879 |
esc = false;
|
|
|
2880 |
}
|
|
|
2881 |
this._input.next();
|
|
|
2882 |
}
|
|
|
2883 |
|
|
|
2884 |
if (this._input.peek() === c) {
|
|
|
2885 |
resulting_string += this._input.next();
|
|
|
2886 |
|
|
|
2887 |
// regexps may have modifiers /regexp/MOD , so fetch those, too
|
|
|
2888 |
// Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
|
|
|
2889 |
resulting_string += this._input.read(acorn.identifier);
|
|
|
2890 |
}
|
|
|
2891 |
return this._create_token(TOKEN.STRING, resulting_string);
|
|
|
2892 |
}
|
|
|
2893 |
return null;
|
|
|
2894 |
};
|
|
|
2895 |
|
|
|
2896 |
Tokenizer.prototype._read_xml = function(c, previous_token) {
|
|
|
2897 |
|
|
|
2898 |
if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
|
|
|
2899 |
var xmlStr = '';
|
|
|
2900 |
var match = this.__patterns.xml.read_match();
|
|
|
2901 |
// handle e4x xml literals
|
|
|
2902 |
//
|
|
|
2903 |
if (match) {
|
|
|
2904 |
// Trim root tag to attempt to
|
|
|
2905 |
var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
|
|
|
2906 |
var isCurlyRoot = rootTag.indexOf('{') === 0;
|
|
|
2907 |
var depth = 0;
|
|
|
2908 |
while (match) {
|
|
|
2909 |
var isEndTag = !!match[1];
|
|
|
2910 |
var tagName = match[2];
|
|
|
2911 |
var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
|
|
|
2912 |
if (!isSingletonTag &&
|
|
|
2913 |
(tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
|
|
|
2914 |
if (isEndTag) {
|
|
|
2915 |
--depth;
|
|
|
2916 |
} else {
|
|
|
2917 |
++depth;
|
|
|
2918 |
}
|
|
|
2919 |
}
|
|
|
2920 |
xmlStr += match[0];
|
|
|
2921 |
if (depth <= 0) {
|
|
|
2922 |
break;
|
|
|
2923 |
}
|
|
|
2924 |
match = this.__patterns.xml.read_match();
|
|
|
2925 |
}
|
|
|
2926 |
// if we didn't close correctly, keep unformatted.
|
|
|
2927 |
if (!match) {
|
|
|
2928 |
xmlStr += this._input.match(/[\s\S]*/g)[0];
|
|
|
2929 |
}
|
|
|
2930 |
xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
|
|
|
2931 |
return this._create_token(TOKEN.STRING, xmlStr);
|
|
|
2932 |
}
|
|
|
2933 |
}
|
|
|
2934 |
|
|
|
2935 |
return null;
|
|
|
2936 |
};
|
|
|
2937 |
|
|
|
2938 |
function unescape_string(s) {
|
|
|
2939 |
// You think that a regex would work for this
|
|
|
2940 |
// return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
|
|
|
2941 |
// return String.fromCharCode(parseInt(val, 16));
|
|
|
2942 |
// })
|
|
|
2943 |
// However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
|
|
|
2944 |
var out = '',
|
|
|
2945 |
escaped = 0;
|
|
|
2946 |
|
|
|
2947 |
var input_scan = new InputScanner(s);
|
|
|
2948 |
var matched = null;
|
|
|
2949 |
|
|
|
2950 |
while (input_scan.hasNext()) {
|
|
|
2951 |
// Keep any whitespace, non-slash characters
|
|
|
2952 |
// also keep slash pairs.
|
|
|
2953 |
matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
|
|
|
2954 |
|
|
|
2955 |
if (matched) {
|
|
|
2956 |
out += matched[0];
|
|
|
2957 |
}
|
|
|
2958 |
|
|
|
2959 |
if (input_scan.peek() === '\\') {
|
|
|
2960 |
input_scan.next();
|
|
|
2961 |
if (input_scan.peek() === 'x') {
|
|
|
2962 |
matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
|
|
|
2963 |
} else if (input_scan.peek() === 'u') {
|
|
|
2964 |
matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
|
|
|
2965 |
if (!matched) {
|
|
|
2966 |
matched = input_scan.match(/u\{([0-9A-Fa-f]+)\}/g);
|
|
|
2967 |
}
|
|
|
2968 |
} else {
|
|
|
2969 |
out += '\\';
|
|
|
2970 |
if (input_scan.hasNext()) {
|
|
|
2971 |
out += input_scan.next();
|
|
|
2972 |
}
|
|
|
2973 |
continue;
|
|
|
2974 |
}
|
|
|
2975 |
|
|
|
2976 |
// If there's some error decoding, return the original string
|
|
|
2977 |
if (!matched) {
|
|
|
2978 |
return s;
|
|
|
2979 |
}
|
|
|
2980 |
|
|
|
2981 |
escaped = parseInt(matched[1], 16);
|
|
|
2982 |
|
|
|
2983 |
if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
|
|
|
2984 |
// we bail out on \x7f..\xff,
|
|
|
2985 |
// leaving whole string escaped,
|
|
|
2986 |
// as it's probably completely binary
|
|
|
2987 |
return s;
|
|
|
2988 |
} else if (escaped >= 0x00 && escaped < 0x20) {
|
|
|
2989 |
// leave 0x00...0x1f escaped
|
|
|
2990 |
out += '\\' + matched[0];
|
|
|
2991 |
} else if (escaped > 0x10FFFF) {
|
|
|
2992 |
// If the escape sequence is out of bounds, keep the original sequence and continue conversion
|
|
|
2993 |
out += '\\' + matched[0];
|
|
|
2994 |
} else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
|
|
|
2995 |
// single-quote, apostrophe, backslash - escape these
|
|
|
2996 |
out += '\\' + String.fromCharCode(escaped);
|
|
|
2997 |
} else {
|
|
|
2998 |
out += String.fromCharCode(escaped);
|
|
|
2999 |
}
|
|
|
3000 |
}
|
|
|
3001 |
}
|
|
|
3002 |
|
|
|
3003 |
return out;
|
|
|
3004 |
}
|
|
|
3005 |
|
|
|
3006 |
// handle string
|
|
|
3007 |
//
|
|
|
3008 |
Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
|
|
|
3009 |
var current_char;
|
|
|
3010 |
var pattern;
|
|
|
3011 |
if (delimiter === '\'') {
|
|
|
3012 |
pattern = this.__patterns.single_quote;
|
|
|
3013 |
} else if (delimiter === '"') {
|
|
|
3014 |
pattern = this.__patterns.double_quote;
|
|
|
3015 |
} else if (delimiter === '`') {
|
|
|
3016 |
pattern = this.__patterns.template_text;
|
|
|
3017 |
} else if (delimiter === '}') {
|
|
|
3018 |
pattern = this.__patterns.template_expression;
|
|
|
3019 |
}
|
|
|
3020 |
|
|
|
3021 |
var resulting_string = pattern.read();
|
|
|
3022 |
var next = '';
|
|
|
3023 |
while (this._input.hasNext()) {
|
|
|
3024 |
next = this._input.next();
|
|
|
3025 |
if (next === delimiter ||
|
|
|
3026 |
(!allow_unescaped_newlines && acorn.newline.test(next))) {
|
|
|
3027 |
this._input.back();
|
|
|
3028 |
break;
|
|
|
3029 |
} else if (next === '\\' && this._input.hasNext()) {
|
|
|
3030 |
current_char = this._input.peek();
|
|
|
3031 |
|
|
|
3032 |
if (current_char === 'x' || current_char === 'u') {
|
|
|
3033 |
this.has_char_escapes = true;
|
|
|
3034 |
} else if (current_char === '\r' && this._input.peek(1) === '\n') {
|
|
|
3035 |
this._input.next();
|
|
|
3036 |
}
|
|
|
3037 |
next += this._input.next();
|
|
|
3038 |
} else if (start_sub) {
|
|
|
3039 |
if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
|
|
|
3040 |
next += this._input.next();
|
|
|
3041 |
}
|
|
|
3042 |
|
|
|
3043 |
if (start_sub === next) {
|
|
|
3044 |
if (delimiter === '`') {
|
|
|
3045 |
next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
|
|
|
3046 |
} else {
|
|
|
3047 |
next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
|
|
|
3048 |
}
|
|
|
3049 |
if (this._input.hasNext()) {
|
|
|
3050 |
next += this._input.next();
|
|
|
3051 |
}
|
|
|
3052 |
}
|
|
|
3053 |
}
|
|
|
3054 |
next += pattern.read();
|
|
|
3055 |
resulting_string += next;
|
|
|
3056 |
}
|
|
|
3057 |
|
|
|
3058 |
return resulting_string;
|
|
|
3059 |
};
|
|
|
3060 |
|
|
|
3061 |
module.exports.Tokenizer = Tokenizer;
|
|
|
3062 |
module.exports.TOKEN = TOKEN;
|
|
|
3063 |
module.exports.positionable_operators = positionable_operators.slice();
|
|
|
3064 |
module.exports.line_starters = line_starters.slice();
|
|
|
3065 |
|
|
|
3066 |
|
|
|
3067 |
/***/ }),
|
|
|
3068 |
/* 8 */
|
|
|
3069 |
/***/ (function(module) {
|
|
|
3070 |
|
|
|
3071 |
/*jshint node:true */
|
|
|
3072 |
/*
|
|
|
3073 |
|
|
|
3074 |
The MIT License (MIT)
|
|
|
3075 |
|
|
|
3076 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3077 |
|
|
|
3078 |
Permission is hereby granted, free of charge, to any person
|
|
|
3079 |
obtaining a copy of this software and associated documentation files
|
|
|
3080 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3081 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3082 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3083 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3084 |
subject to the following conditions:
|
|
|
3085 |
|
|
|
3086 |
The above copyright notice and this permission notice shall be
|
|
|
3087 |
included in all copies or substantial portions of the Software.
|
|
|
3088 |
|
|
|
3089 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3090 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3091 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3092 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3093 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3094 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3095 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3096 |
SOFTWARE.
|
|
|
3097 |
*/
|
|
|
3098 |
|
|
|
3099 |
|
|
|
3100 |
|
|
|
3101 |
var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
|
|
|
3102 |
|
|
|
3103 |
function InputScanner(input_string) {
|
|
|
3104 |
this.__input = input_string || '';
|
|
|
3105 |
this.__input_length = this.__input.length;
|
|
|
3106 |
this.__position = 0;
|
|
|
3107 |
}
|
|
|
3108 |
|
|
|
3109 |
InputScanner.prototype.restart = function() {
|
|
|
3110 |
this.__position = 0;
|
|
|
3111 |
};
|
|
|
3112 |
|
|
|
3113 |
InputScanner.prototype.back = function() {
|
|
|
3114 |
if (this.__position > 0) {
|
|
|
3115 |
this.__position -= 1;
|
|
|
3116 |
}
|
|
|
3117 |
};
|
|
|
3118 |
|
|
|
3119 |
InputScanner.prototype.hasNext = function() {
|
|
|
3120 |
return this.__position < this.__input_length;
|
|
|
3121 |
};
|
|
|
3122 |
|
|
|
3123 |
InputScanner.prototype.next = function() {
|
|
|
3124 |
var val = null;
|
|
|
3125 |
if (this.hasNext()) {
|
|
|
3126 |
val = this.__input.charAt(this.__position);
|
|
|
3127 |
this.__position += 1;
|
|
|
3128 |
}
|
|
|
3129 |
return val;
|
|
|
3130 |
};
|
|
|
3131 |
|
|
|
3132 |
InputScanner.prototype.peek = function(index) {
|
|
|
3133 |
var val = null;
|
|
|
3134 |
index = index || 0;
|
|
|
3135 |
index += this.__position;
|
|
|
3136 |
if (index >= 0 && index < this.__input_length) {
|
|
|
3137 |
val = this.__input.charAt(index);
|
|
|
3138 |
}
|
|
|
3139 |
return val;
|
|
|
3140 |
};
|
|
|
3141 |
|
|
|
3142 |
// This is a JavaScript only helper function (not in python)
|
|
|
3143 |
// Javascript doesn't have a match method
|
|
|
3144 |
// and not all implementation support "sticky" flag.
|
|
|
3145 |
// If they do not support sticky then both this.match() and this.test() method
|
|
|
3146 |
// must get the match and check the index of the match.
|
|
|
3147 |
// If sticky is supported and set, this method will use it.
|
|
|
3148 |
// Otherwise it will check that global is set, and fall back to the slower method.
|
|
|
3149 |
InputScanner.prototype.__match = function(pattern, index) {
|
|
|
3150 |
pattern.lastIndex = index;
|
|
|
3151 |
var pattern_match = pattern.exec(this.__input);
|
|
|
3152 |
|
|
|
3153 |
if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
|
|
|
3154 |
if (pattern_match.index !== index) {
|
|
|
3155 |
pattern_match = null;
|
|
|
3156 |
}
|
|
|
3157 |
}
|
|
|
3158 |
|
|
|
3159 |
return pattern_match;
|
|
|
3160 |
};
|
|
|
3161 |
|
|
|
3162 |
InputScanner.prototype.test = function(pattern, index) {
|
|
|
3163 |
index = index || 0;
|
|
|
3164 |
index += this.__position;
|
|
|
3165 |
|
|
|
3166 |
if (index >= 0 && index < this.__input_length) {
|
|
|
3167 |
return !!this.__match(pattern, index);
|
|
|
3168 |
} else {
|
|
|
3169 |
return false;
|
|
|
3170 |
}
|
|
|
3171 |
};
|
|
|
3172 |
|
|
|
3173 |
InputScanner.prototype.testChar = function(pattern, index) {
|
|
|
3174 |
// test one character regex match
|
|
|
3175 |
var val = this.peek(index);
|
|
|
3176 |
pattern.lastIndex = 0;
|
|
|
3177 |
return val !== null && pattern.test(val);
|
|
|
3178 |
};
|
|
|
3179 |
|
|
|
3180 |
InputScanner.prototype.match = function(pattern) {
|
|
|
3181 |
var pattern_match = this.__match(pattern, this.__position);
|
|
|
3182 |
if (pattern_match) {
|
|
|
3183 |
this.__position += pattern_match[0].length;
|
|
|
3184 |
} else {
|
|
|
3185 |
pattern_match = null;
|
|
|
3186 |
}
|
|
|
3187 |
return pattern_match;
|
|
|
3188 |
};
|
|
|
3189 |
|
|
|
3190 |
InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
|
|
|
3191 |
var val = '';
|
|
|
3192 |
var match;
|
|
|
3193 |
if (starting_pattern) {
|
|
|
3194 |
match = this.match(starting_pattern);
|
|
|
3195 |
if (match) {
|
|
|
3196 |
val += match[0];
|
|
|
3197 |
}
|
|
|
3198 |
}
|
|
|
3199 |
if (until_pattern && (match || !starting_pattern)) {
|
|
|
3200 |
val += this.readUntil(until_pattern, until_after);
|
|
|
3201 |
}
|
|
|
3202 |
return val;
|
|
|
3203 |
};
|
|
|
3204 |
|
|
|
3205 |
InputScanner.prototype.readUntil = function(pattern, until_after) {
|
|
|
3206 |
var val = '';
|
|
|
3207 |
var match_index = this.__position;
|
|
|
3208 |
pattern.lastIndex = this.__position;
|
|
|
3209 |
var pattern_match = pattern.exec(this.__input);
|
|
|
3210 |
if (pattern_match) {
|
|
|
3211 |
match_index = pattern_match.index;
|
|
|
3212 |
if (until_after) {
|
|
|
3213 |
match_index += pattern_match[0].length;
|
|
|
3214 |
}
|
|
|
3215 |
} else {
|
|
|
3216 |
match_index = this.__input_length;
|
|
|
3217 |
}
|
|
|
3218 |
|
|
|
3219 |
val = this.__input.substring(this.__position, match_index);
|
|
|
3220 |
this.__position = match_index;
|
|
|
3221 |
return val;
|
|
|
3222 |
};
|
|
|
3223 |
|
|
|
3224 |
InputScanner.prototype.readUntilAfter = function(pattern) {
|
|
|
3225 |
return this.readUntil(pattern, true);
|
|
|
3226 |
};
|
|
|
3227 |
|
|
|
3228 |
InputScanner.prototype.get_regexp = function(pattern, match_from) {
|
|
|
3229 |
var result = null;
|
|
|
3230 |
var flags = 'g';
|
|
|
3231 |
if (match_from && regexp_has_sticky) {
|
|
|
3232 |
flags = 'y';
|
|
|
3233 |
}
|
|
|
3234 |
// strings are converted to regexp
|
|
|
3235 |
if (typeof pattern === "string" && pattern !== '') {
|
|
|
3236 |
// result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
|
|
|
3237 |
result = new RegExp(pattern, flags);
|
|
|
3238 |
} else if (pattern) {
|
|
|
3239 |
result = new RegExp(pattern.source, flags);
|
|
|
3240 |
}
|
|
|
3241 |
return result;
|
|
|
3242 |
};
|
|
|
3243 |
|
|
|
3244 |
InputScanner.prototype.get_literal_regexp = function(literal_string) {
|
|
|
3245 |
return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
|
|
3246 |
};
|
|
|
3247 |
|
|
|
3248 |
/* css beautifier legacy helpers */
|
|
|
3249 |
InputScanner.prototype.peekUntilAfter = function(pattern) {
|
|
|
3250 |
var start = this.__position;
|
|
|
3251 |
var val = this.readUntilAfter(pattern);
|
|
|
3252 |
this.__position = start;
|
|
|
3253 |
return val;
|
|
|
3254 |
};
|
|
|
3255 |
|
|
|
3256 |
InputScanner.prototype.lookBack = function(testVal) {
|
|
|
3257 |
var start = this.__position - 1;
|
|
|
3258 |
return start >= testVal.length && this.__input.substring(start - testVal.length, start)
|
|
|
3259 |
.toLowerCase() === testVal;
|
|
|
3260 |
};
|
|
|
3261 |
|
|
|
3262 |
module.exports.InputScanner = InputScanner;
|
|
|
3263 |
|
|
|
3264 |
|
|
|
3265 |
/***/ }),
|
|
|
3266 |
/* 9 */
|
|
|
3267 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
3268 |
|
|
|
3269 |
/*jshint node:true */
|
|
|
3270 |
/*
|
|
|
3271 |
|
|
|
3272 |
The MIT License (MIT)
|
|
|
3273 |
|
|
|
3274 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3275 |
|
|
|
3276 |
Permission is hereby granted, free of charge, to any person
|
|
|
3277 |
obtaining a copy of this software and associated documentation files
|
|
|
3278 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3279 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3280 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3281 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3282 |
subject to the following conditions:
|
|
|
3283 |
|
|
|
3284 |
The above copyright notice and this permission notice shall be
|
|
|
3285 |
included in all copies or substantial portions of the Software.
|
|
|
3286 |
|
|
|
3287 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3288 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3289 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3290 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3291 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3292 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3293 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3294 |
SOFTWARE.
|
|
|
3295 |
*/
|
|
|
3296 |
|
|
|
3297 |
|
|
|
3298 |
|
|
|
3299 |
var InputScanner = (__webpack_require__(8).InputScanner);
|
|
|
3300 |
var Token = (__webpack_require__(3).Token);
|
|
|
3301 |
var TokenStream = (__webpack_require__(10).TokenStream);
|
|
|
3302 |
var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);
|
|
|
3303 |
|
|
|
3304 |
var TOKEN = {
|
|
|
3305 |
START: 'TK_START',
|
|
|
3306 |
RAW: 'TK_RAW',
|
|
|
3307 |
EOF: 'TK_EOF'
|
|
|
3308 |
};
|
|
|
3309 |
|
|
|
3310 |
var Tokenizer = function(input_string, options) {
|
|
|
3311 |
this._input = new InputScanner(input_string);
|
|
|
3312 |
this._options = options || {};
|
|
|
3313 |
this.__tokens = null;
|
|
|
3314 |
|
|
|
3315 |
this._patterns = {};
|
|
|
3316 |
this._patterns.whitespace = new WhitespacePattern(this._input);
|
|
|
3317 |
};
|
|
|
3318 |
|
|
|
3319 |
Tokenizer.prototype.tokenize = function() {
|
|
|
3320 |
this._input.restart();
|
|
|
3321 |
this.__tokens = new TokenStream();
|
|
|
3322 |
|
|
|
3323 |
this._reset();
|
|
|
3324 |
|
|
|
3325 |
var current;
|
|
|
3326 |
var previous = new Token(TOKEN.START, '');
|
|
|
3327 |
var open_token = null;
|
|
|
3328 |
var open_stack = [];
|
|
|
3329 |
var comments = new TokenStream();
|
|
|
3330 |
|
|
|
3331 |
while (previous.type !== TOKEN.EOF) {
|
|
|
3332 |
current = this._get_next_token(previous, open_token);
|
|
|
3333 |
while (this._is_comment(current)) {
|
|
|
3334 |
comments.add(current);
|
|
|
3335 |
current = this._get_next_token(previous, open_token);
|
|
|
3336 |
}
|
|
|
3337 |
|
|
|
3338 |
if (!comments.isEmpty()) {
|
|
|
3339 |
current.comments_before = comments;
|
|
|
3340 |
comments = new TokenStream();
|
|
|
3341 |
}
|
|
|
3342 |
|
|
|
3343 |
current.parent = open_token;
|
|
|
3344 |
|
|
|
3345 |
if (this._is_opening(current)) {
|
|
|
3346 |
open_stack.push(open_token);
|
|
|
3347 |
open_token = current;
|
|
|
3348 |
} else if (open_token && this._is_closing(current, open_token)) {
|
|
|
3349 |
current.opened = open_token;
|
|
|
3350 |
open_token.closed = current;
|
|
|
3351 |
open_token = open_stack.pop();
|
|
|
3352 |
current.parent = open_token;
|
|
|
3353 |
}
|
|
|
3354 |
|
|
|
3355 |
current.previous = previous;
|
|
|
3356 |
previous.next = current;
|
|
|
3357 |
|
|
|
3358 |
this.__tokens.add(current);
|
|
|
3359 |
previous = current;
|
|
|
3360 |
}
|
|
|
3361 |
|
|
|
3362 |
return this.__tokens;
|
|
|
3363 |
};
|
|
|
3364 |
|
|
|
3365 |
|
|
|
3366 |
Tokenizer.prototype._is_first_token = function() {
|
|
|
3367 |
return this.__tokens.isEmpty();
|
|
|
3368 |
};
|
|
|
3369 |
|
|
|
3370 |
Tokenizer.prototype._reset = function() {};
|
|
|
3371 |
|
|
|
3372 |
Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
|
|
|
3373 |
this._readWhitespace();
|
|
|
3374 |
var resulting_string = this._input.read(/.+/g);
|
|
|
3375 |
if (resulting_string) {
|
|
|
3376 |
return this._create_token(TOKEN.RAW, resulting_string);
|
|
|
3377 |
} else {
|
|
|
3378 |
return this._create_token(TOKEN.EOF, '');
|
|
|
3379 |
}
|
|
|
3380 |
};
|
|
|
3381 |
|
|
|
3382 |
Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
|
|
|
3383 |
return false;
|
|
|
3384 |
};
|
|
|
3385 |
|
|
|
3386 |
Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
|
|
|
3387 |
return false;
|
|
|
3388 |
};
|
|
|
3389 |
|
|
|
3390 |
Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
|
|
|
3391 |
return false;
|
|
|
3392 |
};
|
|
|
3393 |
|
|
|
3394 |
Tokenizer.prototype._create_token = function(type, text) {
|
|
|
3395 |
var token = new Token(type, text,
|
|
|
3396 |
this._patterns.whitespace.newline_count,
|
|
|
3397 |
this._patterns.whitespace.whitespace_before_token);
|
|
|
3398 |
return token;
|
|
|
3399 |
};
|
|
|
3400 |
|
|
|
3401 |
Tokenizer.prototype._readWhitespace = function() {
|
|
|
3402 |
return this._patterns.whitespace.read();
|
|
|
3403 |
};
|
|
|
3404 |
|
|
|
3405 |
|
|
|
3406 |
|
|
|
3407 |
module.exports.Tokenizer = Tokenizer;
|
|
|
3408 |
module.exports.TOKEN = TOKEN;
|
|
|
3409 |
|
|
|
3410 |
|
|
|
3411 |
/***/ }),
|
|
|
3412 |
/* 10 */
|
|
|
3413 |
/***/ (function(module) {
|
|
|
3414 |
|
|
|
3415 |
/*jshint node:true */
|
|
|
3416 |
/*
|
|
|
3417 |
|
|
|
3418 |
The MIT License (MIT)
|
|
|
3419 |
|
|
|
3420 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3421 |
|
|
|
3422 |
Permission is hereby granted, free of charge, to any person
|
|
|
3423 |
obtaining a copy of this software and associated documentation files
|
|
|
3424 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3425 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3426 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3427 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3428 |
subject to the following conditions:
|
|
|
3429 |
|
|
|
3430 |
The above copyright notice and this permission notice shall be
|
|
|
3431 |
included in all copies or substantial portions of the Software.
|
|
|
3432 |
|
|
|
3433 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3434 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3435 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3436 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3437 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3438 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3439 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3440 |
SOFTWARE.
|
|
|
3441 |
*/
|
|
|
3442 |
|
|
|
3443 |
|
|
|
3444 |
|
|
|
3445 |
function TokenStream(parent_token) {
|
|
|
3446 |
// private
|
|
|
3447 |
this.__tokens = [];
|
|
|
3448 |
this.__tokens_length = this.__tokens.length;
|
|
|
3449 |
this.__position = 0;
|
|
|
3450 |
this.__parent_token = parent_token;
|
|
|
3451 |
}
|
|
|
3452 |
|
|
|
3453 |
TokenStream.prototype.restart = function() {
|
|
|
3454 |
this.__position = 0;
|
|
|
3455 |
};
|
|
|
3456 |
|
|
|
3457 |
TokenStream.prototype.isEmpty = function() {
|
|
|
3458 |
return this.__tokens_length === 0;
|
|
|
3459 |
};
|
|
|
3460 |
|
|
|
3461 |
TokenStream.prototype.hasNext = function() {
|
|
|
3462 |
return this.__position < this.__tokens_length;
|
|
|
3463 |
};
|
|
|
3464 |
|
|
|
3465 |
TokenStream.prototype.next = function() {
|
|
|
3466 |
var val = null;
|
|
|
3467 |
if (this.hasNext()) {
|
|
|
3468 |
val = this.__tokens[this.__position];
|
|
|
3469 |
this.__position += 1;
|
|
|
3470 |
}
|
|
|
3471 |
return val;
|
|
|
3472 |
};
|
|
|
3473 |
|
|
|
3474 |
TokenStream.prototype.peek = function(index) {
|
|
|
3475 |
var val = null;
|
|
|
3476 |
index = index || 0;
|
|
|
3477 |
index += this.__position;
|
|
|
3478 |
if (index >= 0 && index < this.__tokens_length) {
|
|
|
3479 |
val = this.__tokens[index];
|
|
|
3480 |
}
|
|
|
3481 |
return val;
|
|
|
3482 |
};
|
|
|
3483 |
|
|
|
3484 |
TokenStream.prototype.add = function(token) {
|
|
|
3485 |
if (this.__parent_token) {
|
|
|
3486 |
token.parent = this.__parent_token;
|
|
|
3487 |
}
|
|
|
3488 |
this.__tokens.push(token);
|
|
|
3489 |
this.__tokens_length += 1;
|
|
|
3490 |
};
|
|
|
3491 |
|
|
|
3492 |
module.exports.TokenStream = TokenStream;
|
|
|
3493 |
|
|
|
3494 |
|
|
|
3495 |
/***/ }),
|
|
|
3496 |
/* 11 */
|
|
|
3497 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
3498 |
|
|
|
3499 |
/*jshint node:true */
|
|
|
3500 |
/*
|
|
|
3501 |
|
|
|
3502 |
The MIT License (MIT)
|
|
|
3503 |
|
|
|
3504 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3505 |
|
|
|
3506 |
Permission is hereby granted, free of charge, to any person
|
|
|
3507 |
obtaining a copy of this software and associated documentation files
|
|
|
3508 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3509 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3510 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3511 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3512 |
subject to the following conditions:
|
|
|
3513 |
|
|
|
3514 |
The above copyright notice and this permission notice shall be
|
|
|
3515 |
included in all copies or substantial portions of the Software.
|
|
|
3516 |
|
|
|
3517 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3518 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3519 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3520 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3521 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3522 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3523 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3524 |
SOFTWARE.
|
|
|
3525 |
*/
|
|
|
3526 |
|
|
|
3527 |
|
|
|
3528 |
|
|
|
3529 |
var Pattern = (__webpack_require__(12).Pattern);
|
|
|
3530 |
|
|
|
3531 |
function WhitespacePattern(input_scanner, parent) {
|
|
|
3532 |
Pattern.call(this, input_scanner, parent);
|
|
|
3533 |
if (parent) {
|
|
|
3534 |
this._line_regexp = this._input.get_regexp(parent._line_regexp);
|
|
|
3535 |
} else {
|
|
|
3536 |
this.__set_whitespace_patterns('', '');
|
|
|
3537 |
}
|
|
|
3538 |
|
|
|
3539 |
this.newline_count = 0;
|
|
|
3540 |
this.whitespace_before_token = '';
|
|
|
3541 |
}
|
|
|
3542 |
WhitespacePattern.prototype = new Pattern();
|
|
|
3543 |
|
|
|
3544 |
WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
|
|
|
3545 |
whitespace_chars += '\\t ';
|
|
|
3546 |
newline_chars += '\\n\\r';
|
|
|
3547 |
|
|
|
3548 |
this._match_pattern = this._input.get_regexp(
|
|
|
3549 |
'[' + whitespace_chars + newline_chars + ']+', true);
|
|
|
3550 |
this._newline_regexp = this._input.get_regexp(
|
|
|
3551 |
'\\r\\n|[' + newline_chars + ']');
|
|
|
3552 |
};
|
|
|
3553 |
|
|
|
3554 |
WhitespacePattern.prototype.read = function() {
|
|
|
3555 |
this.newline_count = 0;
|
|
|
3556 |
this.whitespace_before_token = '';
|
|
|
3557 |
|
|
|
3558 |
var resulting_string = this._input.read(this._match_pattern);
|
|
|
3559 |
if (resulting_string === ' ') {
|
|
|
3560 |
this.whitespace_before_token = ' ';
|
|
|
3561 |
} else if (resulting_string) {
|
|
|
3562 |
var matches = this.__split(this._newline_regexp, resulting_string);
|
|
|
3563 |
this.newline_count = matches.length - 1;
|
|
|
3564 |
this.whitespace_before_token = matches[this.newline_count];
|
|
|
3565 |
}
|
|
|
3566 |
|
|
|
3567 |
return resulting_string;
|
|
|
3568 |
};
|
|
|
3569 |
|
|
|
3570 |
WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
|
|
|
3571 |
var result = this._create();
|
|
|
3572 |
result.__set_whitespace_patterns(whitespace_chars, newline_chars);
|
|
|
3573 |
result._update();
|
|
|
3574 |
return result;
|
|
|
3575 |
};
|
|
|
3576 |
|
|
|
3577 |
WhitespacePattern.prototype._create = function() {
|
|
|
3578 |
return new WhitespacePattern(this._input, this);
|
|
|
3579 |
};
|
|
|
3580 |
|
|
|
3581 |
WhitespacePattern.prototype.__split = function(regexp, input_string) {
|
|
|
3582 |
regexp.lastIndex = 0;
|
|
|
3583 |
var start_index = 0;
|
|
|
3584 |
var result = [];
|
|
|
3585 |
var next_match = regexp.exec(input_string);
|
|
|
3586 |
while (next_match) {
|
|
|
3587 |
result.push(input_string.substring(start_index, next_match.index));
|
|
|
3588 |
start_index = next_match.index + next_match[0].length;
|
|
|
3589 |
next_match = regexp.exec(input_string);
|
|
|
3590 |
}
|
|
|
3591 |
|
|
|
3592 |
if (start_index < input_string.length) {
|
|
|
3593 |
result.push(input_string.substring(start_index, input_string.length));
|
|
|
3594 |
} else {
|
|
|
3595 |
result.push('');
|
|
|
3596 |
}
|
|
|
3597 |
|
|
|
3598 |
return result;
|
|
|
3599 |
};
|
|
|
3600 |
|
|
|
3601 |
|
|
|
3602 |
|
|
|
3603 |
module.exports.WhitespacePattern = WhitespacePattern;
|
|
|
3604 |
|
|
|
3605 |
|
|
|
3606 |
/***/ }),
|
|
|
3607 |
/* 12 */
|
|
|
3608 |
/***/ (function(module) {
|
|
|
3609 |
|
|
|
3610 |
/*jshint node:true */
|
|
|
3611 |
/*
|
|
|
3612 |
|
|
|
3613 |
The MIT License (MIT)
|
|
|
3614 |
|
|
|
3615 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3616 |
|
|
|
3617 |
Permission is hereby granted, free of charge, to any person
|
|
|
3618 |
obtaining a copy of this software and associated documentation files
|
|
|
3619 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3620 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3621 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3622 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3623 |
subject to the following conditions:
|
|
|
3624 |
|
|
|
3625 |
The above copyright notice and this permission notice shall be
|
|
|
3626 |
included in all copies or substantial portions of the Software.
|
|
|
3627 |
|
|
|
3628 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3629 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3630 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3631 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3632 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3633 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3634 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3635 |
SOFTWARE.
|
|
|
3636 |
*/
|
|
|
3637 |
|
|
|
3638 |
|
|
|
3639 |
|
|
|
3640 |
function Pattern(input_scanner, parent) {
|
|
|
3641 |
this._input = input_scanner;
|
|
|
3642 |
this._starting_pattern = null;
|
|
|
3643 |
this._match_pattern = null;
|
|
|
3644 |
this._until_pattern = null;
|
|
|
3645 |
this._until_after = false;
|
|
|
3646 |
|
|
|
3647 |
if (parent) {
|
|
|
3648 |
this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
|
|
|
3649 |
this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
|
|
|
3650 |
this._until_pattern = this._input.get_regexp(parent._until_pattern);
|
|
|
3651 |
this._until_after = parent._until_after;
|
|
|
3652 |
}
|
|
|
3653 |
}
|
|
|
3654 |
|
|
|
3655 |
Pattern.prototype.read = function() {
|
|
|
3656 |
var result = this._input.read(this._starting_pattern);
|
|
|
3657 |
if (!this._starting_pattern || result) {
|
|
|
3658 |
result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
|
|
|
3659 |
}
|
|
|
3660 |
return result;
|
|
|
3661 |
};
|
|
|
3662 |
|
|
|
3663 |
Pattern.prototype.read_match = function() {
|
|
|
3664 |
return this._input.match(this._match_pattern);
|
|
|
3665 |
};
|
|
|
3666 |
|
|
|
3667 |
Pattern.prototype.until_after = function(pattern) {
|
|
|
3668 |
var result = this._create();
|
|
|
3669 |
result._until_after = true;
|
|
|
3670 |
result._until_pattern = this._input.get_regexp(pattern);
|
|
|
3671 |
result._update();
|
|
|
3672 |
return result;
|
|
|
3673 |
};
|
|
|
3674 |
|
|
|
3675 |
Pattern.prototype.until = function(pattern) {
|
|
|
3676 |
var result = this._create();
|
|
|
3677 |
result._until_after = false;
|
|
|
3678 |
result._until_pattern = this._input.get_regexp(pattern);
|
|
|
3679 |
result._update();
|
|
|
3680 |
return result;
|
|
|
3681 |
};
|
|
|
3682 |
|
|
|
3683 |
Pattern.prototype.starting_with = function(pattern) {
|
|
|
3684 |
var result = this._create();
|
|
|
3685 |
result._starting_pattern = this._input.get_regexp(pattern, true);
|
|
|
3686 |
result._update();
|
|
|
3687 |
return result;
|
|
|
3688 |
};
|
|
|
3689 |
|
|
|
3690 |
Pattern.prototype.matching = function(pattern) {
|
|
|
3691 |
var result = this._create();
|
|
|
3692 |
result._match_pattern = this._input.get_regexp(pattern, true);
|
|
|
3693 |
result._update();
|
|
|
3694 |
return result;
|
|
|
3695 |
};
|
|
|
3696 |
|
|
|
3697 |
Pattern.prototype._create = function() {
|
|
|
3698 |
return new Pattern(this._input, this);
|
|
|
3699 |
};
|
|
|
3700 |
|
|
|
3701 |
Pattern.prototype._update = function() {};
|
|
|
3702 |
|
|
|
3703 |
module.exports.Pattern = Pattern;
|
|
|
3704 |
|
|
|
3705 |
|
|
|
3706 |
/***/ }),
|
|
|
3707 |
/* 13 */
|
|
|
3708 |
/***/ (function(module) {
|
|
|
3709 |
|
|
|
3710 |
/*jshint node:true */
|
|
|
3711 |
/*
|
|
|
3712 |
|
|
|
3713 |
The MIT License (MIT)
|
|
|
3714 |
|
|
|
3715 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3716 |
|
|
|
3717 |
Permission is hereby granted, free of charge, to any person
|
|
|
3718 |
obtaining a copy of this software and associated documentation files
|
|
|
3719 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3720 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3721 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3722 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3723 |
subject to the following conditions:
|
|
|
3724 |
|
|
|
3725 |
The above copyright notice and this permission notice shall be
|
|
|
3726 |
included in all copies or substantial portions of the Software.
|
|
|
3727 |
|
|
|
3728 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3729 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3730 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3731 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3732 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3733 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3734 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3735 |
SOFTWARE.
|
|
|
3736 |
*/
|
|
|
3737 |
|
|
|
3738 |
|
|
|
3739 |
|
|
|
3740 |
function Directives(start_block_pattern, end_block_pattern) {
|
|
|
3741 |
start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
|
|
|
3742 |
end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
|
|
|
3743 |
this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
|
|
|
3744 |
this.__directive_pattern = / (\w+)[:](\w+)/g;
|
|
|
3745 |
|
|
|
3746 |
this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
|
|
|
3747 |
}
|
|
|
3748 |
|
|
|
3749 |
Directives.prototype.get_directives = function(text) {
|
|
|
3750 |
if (!text.match(this.__directives_block_pattern)) {
|
|
|
3751 |
return null;
|
|
|
3752 |
}
|
|
|
3753 |
|
|
|
3754 |
var directives = {};
|
|
|
3755 |
this.__directive_pattern.lastIndex = 0;
|
|
|
3756 |
var directive_match = this.__directive_pattern.exec(text);
|
|
|
3757 |
|
|
|
3758 |
while (directive_match) {
|
|
|
3759 |
directives[directive_match[1]] = directive_match[2];
|
|
|
3760 |
directive_match = this.__directive_pattern.exec(text);
|
|
|
3761 |
}
|
|
|
3762 |
|
|
|
3763 |
return directives;
|
|
|
3764 |
};
|
|
|
3765 |
|
|
|
3766 |
Directives.prototype.readIgnored = function(input) {
|
|
|
3767 |
return input.readUntilAfter(this.__directives_end_ignore_pattern);
|
|
|
3768 |
};
|
|
|
3769 |
|
|
|
3770 |
|
|
|
3771 |
module.exports.Directives = Directives;
|
|
|
3772 |
|
|
|
3773 |
|
|
|
3774 |
/***/ }),
|
|
|
3775 |
/* 14 */
|
|
|
3776 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
|
3777 |
|
|
|
3778 |
/*jshint node:true */
|
|
|
3779 |
/*
|
|
|
3780 |
|
|
|
3781 |
The MIT License (MIT)
|
|
|
3782 |
|
|
|
3783 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
|
3784 |
|
|
|
3785 |
Permission is hereby granted, free of charge, to any person
|
|
|
3786 |
obtaining a copy of this software and associated documentation files
|
|
|
3787 |
(the "Software"), to deal in the Software without restriction,
|
|
|
3788 |
including without limitation the rights to use, copy, modify, merge,
|
|
|
3789 |
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
3790 |
and to permit persons to whom the Software is furnished to do so,
|
|
|
3791 |
subject to the following conditions:
|
|
|
3792 |
|
|
|
3793 |
The above copyright notice and this permission notice shall be
|
|
|
3794 |
included in all copies or substantial portions of the Software.
|
|
|
3795 |
|
|
|
3796 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
3797 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
3798 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
3799 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
3800 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
3801 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
3802 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3803 |
SOFTWARE.
|
|
|
3804 |
*/
|
|
|
3805 |
|
|
|
3806 |
|
|
|
3807 |
|
|
|
3808 |
var Pattern = (__webpack_require__(12).Pattern);
|
|
|
3809 |
|
|
|
3810 |
|
|
|
3811 |
var template_names = {
|
|
|
3812 |
django: false,
|
|
|
3813 |
erb: false,
|
|
|
3814 |
handlebars: false,
|
|
|
3815 |
php: false,
|
|
|
3816 |
smarty: false,
|
|
|
3817 |
angular: false
|
|
|
3818 |
};
|
|
|
3819 |
|
|
|
3820 |
// This lets templates appear anywhere we would do a readUntil
|
|
|
3821 |
// The cost is higher but it is pay to play.
|
|
|
3822 |
function TemplatablePattern(input_scanner, parent) {
|
|
|
3823 |
Pattern.call(this, input_scanner, parent);
|
|
|
3824 |
this.__template_pattern = null;
|
|
|
3825 |
this._disabled = Object.assign({}, template_names);
|
|
|
3826 |
this._excluded = Object.assign({}, template_names);
|
|
|
3827 |
|
|
|
3828 |
if (parent) {
|
|
|
3829 |
this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
|
|
|
3830 |
this._excluded = Object.assign(this._excluded, parent._excluded);
|
|
|
3831 |
this._disabled = Object.assign(this._disabled, parent._disabled);
|
|
|
3832 |
}
|
|
|
3833 |
var pattern = new Pattern(input_scanner);
|
|
|
3834 |
this.__patterns = {
|
|
|
3835 |
handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
|
|
|
3836 |
handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
|
|
|
3837 |
handlebars: pattern.starting_with(/{{/).until_after(/}}/),
|
|
|
3838 |
php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
|
|
|
3839 |
erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
|
|
|
3840 |
// django coflicts with handlebars a bit.
|
|
|
3841 |
django: pattern.starting_with(/{%/).until_after(/%}/),
|
|
|
3842 |
django_value: pattern.starting_with(/{{/).until_after(/}}/),
|
|
|
3843 |
django_comment: pattern.starting_with(/{#/).until_after(/#}/),
|
|
|
3844 |
smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
|
|
|
3845 |
smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
|
|
|
3846 |
smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
|
|
|
3847 |
};
|
|
|
3848 |
}
|
|
|
3849 |
TemplatablePattern.prototype = new Pattern();
|
|
|
3850 |
|
|
|
3851 |
TemplatablePattern.prototype._create = function() {
|
|
|
3852 |
return new TemplatablePattern(this._input, this);
|
|
|
3853 |
};
|
|
|
3854 |
|
|
|
3855 |
TemplatablePattern.prototype._update = function() {
|
|
|
3856 |
this.__set_templated_pattern();
|
|
|
3857 |
};
|
|
|
3858 |
|
|
|
3859 |
TemplatablePattern.prototype.disable = function(language) {
|
|
|
3860 |
var result = this._create();
|
|
|
3861 |
result._disabled[language] = true;
|
|
|
3862 |
result._update();
|
|
|
3863 |
return result;
|
|
|
3864 |
};
|
|
|
3865 |
|
|
|
3866 |
TemplatablePattern.prototype.read_options = function(options) {
|
|
|
3867 |
var result = this._create();
|
|
|
3868 |
for (var language in template_names) {
|
|
|
3869 |
result._disabled[language] = options.templating.indexOf(language) === -1;
|
|
|
3870 |
}
|
|
|
3871 |
result._update();
|
|
|
3872 |
return result;
|
|
|
3873 |
};
|
|
|
3874 |
|
|
|
3875 |
TemplatablePattern.prototype.exclude = function(language) {
|
|
|
3876 |
var result = this._create();
|
|
|
3877 |
result._excluded[language] = true;
|
|
|
3878 |
result._update();
|
|
|
3879 |
return result;
|
|
|
3880 |
};
|
|
|
3881 |
|
|
|
3882 |
TemplatablePattern.prototype.read = function() {
|
|
|
3883 |
var result = '';
|
|
|
3884 |
if (this._match_pattern) {
|
|
|
3885 |
result = this._input.read(this._starting_pattern);
|
|
|
3886 |
} else {
|
|
|
3887 |
result = this._input.read(this._starting_pattern, this.__template_pattern);
|
|
|
3888 |
}
|
|
|
3889 |
var next = this._read_template();
|
|
|
3890 |
while (next) {
|
|
|
3891 |
if (this._match_pattern) {
|
|
|
3892 |
next += this._input.read(this._match_pattern);
|
|
|
3893 |
} else {
|
|
|
3894 |
next += this._input.readUntil(this.__template_pattern);
|
|
|
3895 |
}
|
|
|
3896 |
result += next;
|
|
|
3897 |
next = this._read_template();
|
|
|
3898 |
}
|
|
|
3899 |
|
|
|
3900 |
if (this._until_after) {
|
|
|
3901 |
result += this._input.readUntilAfter(this._until_pattern);
|
|
|
3902 |
}
|
|
|
3903 |
return result;
|
|
|
3904 |
};
|
|
|
3905 |
|
|
|
3906 |
TemplatablePattern.prototype.__set_templated_pattern = function() {
|
|
|
3907 |
var items = [];
|
|
|
3908 |
|
|
|
3909 |
if (!this._disabled.php) {
|
|
|
3910 |
items.push(this.__patterns.php._starting_pattern.source);
|
|
|
3911 |
}
|
|
|
3912 |
if (!this._disabled.handlebars) {
|
|
|
3913 |
items.push(this.__patterns.handlebars._starting_pattern.source);
|
|
|
3914 |
}
|
|
|
3915 |
if (!this._disabled.erb) {
|
|
|
3916 |
items.push(this.__patterns.erb._starting_pattern.source);
|
|
|
3917 |
}
|
|
|
3918 |
if (!this._disabled.django) {
|
|
|
3919 |
items.push(this.__patterns.django._starting_pattern.source);
|
|
|
3920 |
// The starting pattern for django is more complex because it has different
|
|
|
3921 |
// patterns for value, comment, and other sections
|
|
|
3922 |
items.push(this.__patterns.django_value._starting_pattern.source);
|
|
|
3923 |
items.push(this.__patterns.django_comment._starting_pattern.source);
|
|
|
3924 |
}
|
|
|
3925 |
if (!this._disabled.smarty) {
|
|
|
3926 |
items.push(this.__patterns.smarty._starting_pattern.source);
|
|
|
3927 |
}
|
|
|
3928 |
|
|
|
3929 |
if (this._until_pattern) {
|
|
|
3930 |
items.push(this._until_pattern.source);
|
|
|
3931 |
}
|
|
|
3932 |
this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
|
|
|
3933 |
};
|
|
|
3934 |
|
|
|
3935 |
TemplatablePattern.prototype._read_template = function() {
|
|
|
3936 |
var resulting_string = '';
|
|
|
3937 |
var c = this._input.peek();
|
|
|
3938 |
if (c === '<') {
|
|
|
3939 |
var peek1 = this._input.peek(1);
|
|
|
3940 |
//if we're in a comment, do something special
|
|
|
3941 |
// We treat all comments as literals, even more than preformatted tags
|
|
|
3942 |
// we just look for the appropriate close tag
|
|
|
3943 |
if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
|
|
|
3944 |
resulting_string = resulting_string ||
|
|
|
3945 |
this.__patterns.php.read();
|
|
|
3946 |
}
|
|
|
3947 |
if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
|
|
|
3948 |
resulting_string = resulting_string ||
|
|
|
3949 |
this.__patterns.erb.read();
|
|
|
3950 |
}
|
|
|
3951 |
} else if (c === '{') {
|
|
|
3952 |
if (!this._disabled.handlebars && !this._excluded.handlebars) {
|
|
|
3953 |
resulting_string = resulting_string ||
|
|
|
3954 |
this.__patterns.handlebars_comment.read();
|
|
|
3955 |
resulting_string = resulting_string ||
|
|
|
3956 |
this.__patterns.handlebars_unescaped.read();
|
|
|
3957 |
resulting_string = resulting_string ||
|
|
|
3958 |
this.__patterns.handlebars.read();
|
|
|
3959 |
}
|
|
|
3960 |
if (!this._disabled.django) {
|
|
|
3961 |
// django coflicts with handlebars a bit.
|
|
|
3962 |
if (!this._excluded.django && !this._excluded.handlebars) {
|
|
|
3963 |
resulting_string = resulting_string ||
|
|
|
3964 |
this.__patterns.django_value.read();
|
|
|
3965 |
}
|
|
|
3966 |
if (!this._excluded.django) {
|
|
|
3967 |
resulting_string = resulting_string ||
|
|
|
3968 |
this.__patterns.django_comment.read();
|
|
|
3969 |
resulting_string = resulting_string ||
|
|
|
3970 |
this.__patterns.django.read();
|
|
|
3971 |
}
|
|
|
3972 |
}
|
|
|
3973 |
if (!this._disabled.smarty) {
|
|
|
3974 |
// smarty cannot be enabled with django or handlebars enabled
|
|
|
3975 |
if (this._disabled.django && this._disabled.handlebars) {
|
|
|
3976 |
resulting_string = resulting_string ||
|
|
|
3977 |
this.__patterns.smarty_comment.read();
|
|
|
3978 |
resulting_string = resulting_string ||
|
|
|
3979 |
this.__patterns.smarty_literal.read();
|
|
|
3980 |
resulting_string = resulting_string ||
|
|
|
3981 |
this.__patterns.smarty.read();
|
|
|
3982 |
}
|
|
|
3983 |
}
|
|
|
3984 |
}
|
|
|
3985 |
return resulting_string;
|
|
|
3986 |
};
|
|
|
3987 |
|
|
|
3988 |
|
|
|
3989 |
module.exports.TemplatablePattern = TemplatablePattern;
|
|
|
3990 |
|
|
|
3991 |
|
|
|
3992 |
/***/ })
|
|
|
3993 |
/******/ ]);
|
|
|
3994 |
/************************************************************************/
|
|
|
3995 |
/******/ // The module cache
|
|
|
3996 |
/******/ var __webpack_module_cache__ = {};
|
|
|
3997 |
/******/
|
|
|
3998 |
/******/ // The require function
|
|
|
3999 |
/******/ function __webpack_require__(moduleId) {
|
|
|
4000 |
/******/ // Check if module is in cache
|
|
|
4001 |
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
|
4002 |
/******/ if (cachedModule !== undefined) {
|
|
|
4003 |
/******/ return cachedModule.exports;
|
|
|
4004 |
/******/ }
|
|
|
4005 |
/******/ // Create a new module (and put it into the cache)
|
|
|
4006 |
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
|
4007 |
/******/ // no module.id needed
|
|
|
4008 |
/******/ // no module.loaded needed
|
|
|
4009 |
/******/ exports: {}
|
|
|
4010 |
/******/ };
|
|
|
4011 |
/******/
|
|
|
4012 |
/******/ // Execute the module function
|
|
|
4013 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
|
4014 |
/******/
|
|
|
4015 |
/******/ // Return the exports of the module
|
|
|
4016 |
/******/ return module.exports;
|
|
|
4017 |
/******/ }
|
|
|
4018 |
/******/
|
|
|
4019 |
/************************************************************************/
|
|
|
4020 |
/******/
|
|
|
4021 |
/******/ // startup
|
|
|
4022 |
/******/ // Load entry module and return exports
|
|
|
4023 |
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
|
4024 |
/******/ var __webpack_exports__ = __webpack_require__(0);
|
|
|
4025 |
/******/ legacy_beautify_js = __webpack_exports__;
|
|
|
4026 |
/******/
|
|
|
4027 |
/******/ })()
|
|
|
4028 |
;
|
|
|
4029 |
var js_beautify = legacy_beautify_js;
|
|
|
4030 |
/* Footer */
|
|
|
4031 |
if (typeof define === "function" && define.amd) {
|
|
|
4032 |
// Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
|
|
|
4033 |
define([], function() {
|
|
|
4034 |
return { js_beautify: js_beautify };
|
|
|
4035 |
});
|
|
|
4036 |
} else if (typeof exports !== "undefined") {
|
|
|
4037 |
// Add support for CommonJS. Just put this file somewhere on your require.paths
|
|
|
4038 |
// and you will be able to `var js_beautify = require("beautify").js_beautify`.
|
|
|
4039 |
exports.js_beautify = js_beautify;
|
|
|
4040 |
} else if (typeof window !== "undefined") {
|
|
|
4041 |
// If we're running a web page and don't have either of the above, add our one global
|
|
|
4042 |
window.js_beautify = js_beautify;
|
|
|
4043 |
} else if (typeof global !== "undefined") {
|
|
|
4044 |
// If we don't even have window, try global.
|
|
|
4045 |
global.js_beautify = js_beautify;
|
|
|
4046 |
}
|
|
|
4047 |
|
|
|
4048 |
}());
|
|
|
4049 |
|