js-beautify 1.9.1 → 1.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/README.md +20 -17
- package/js/lib/beautifier.js +192 -69
- package/js/lib/beautifier.min.js +1 -1
- package/js/lib/beautify-css.js +45 -22
- package/js/lib/beautify-html.js +123 -31
- package/js/lib/beautify.js +46 -16
- package/js/lib/cli.js +3 -0
- package/js/src/cli.js +3 -0
- package/js/src/core/options.js +5 -0
- package/js/src/core/templatablepattern.js +12 -0
- package/js/src/css/beautifier.js +40 -22
- package/js/src/html/beautifier.js +61 -17
- package/js/src/html/options.js +4 -0
- package/js/src/html/tokenizer.js +41 -14
- package/js/src/javascript/beautifier.js +26 -11
- package/js/src/javascript/tokenizer.js +3 -5
- package/package.json +9 -7
|
@@ -54,6 +54,7 @@ function TemplatablePattern(input_scanner, parent) {
|
|
|
54
54
|
var pattern = new Pattern(input_scanner);
|
|
55
55
|
this.__patterns = {
|
|
56
56
|
handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
|
|
57
|
+
handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
|
|
57
58
|
handlebars: pattern.starting_with(/{{/).until_after(/}}/),
|
|
58
59
|
php: pattern.starting_with(/<\?(?:[=]|php)/).until_after(/\?>/),
|
|
59
60
|
erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
|
|
@@ -80,6 +81,15 @@ TemplatablePattern.prototype.disable = function(language) {
|
|
|
80
81
|
return result;
|
|
81
82
|
};
|
|
82
83
|
|
|
84
|
+
TemplatablePattern.prototype.read_options = function(options) {
|
|
85
|
+
var result = this._create();
|
|
86
|
+
for (var language in template_names) {
|
|
87
|
+
result._disabled[language] = options.templating.indexOf(language) === -1;
|
|
88
|
+
}
|
|
89
|
+
result._update();
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
|
|
83
93
|
TemplatablePattern.prototype.exclude = function(language) {
|
|
84
94
|
var result = this._create();
|
|
85
95
|
result._excluded[language] = true;
|
|
@@ -155,6 +165,8 @@ TemplatablePattern.prototype._read_template = function() {
|
|
|
155
165
|
if (!this._disabled.handlebars && !this._excluded.handlebars) {
|
|
156
166
|
resulting_string = resulting_string ||
|
|
157
167
|
this.__patterns.handlebars_comment.read();
|
|
168
|
+
resulting_string = resulting_string ||
|
|
169
|
+
this.__patterns.handlebars_unescaped.read();
|
|
158
170
|
resulting_string = resulting_string ||
|
|
159
171
|
this.__patterns.handlebars.read();
|
|
160
172
|
}
|
package/js/src/css/beautifier.js
CHANGED
|
@@ -202,6 +202,9 @@ Beautifier.prototype.beautify = function() {
|
|
|
202
202
|
isAfterSpace = whitespace !== '';
|
|
203
203
|
previous_ch = topCharacter;
|
|
204
204
|
this._ch = this._input.next();
|
|
205
|
+
if (this._ch === '\\' && this._input.hasNext()) {
|
|
206
|
+
this._ch += this._input.next();
|
|
207
|
+
}
|
|
205
208
|
topCharacter = this._ch;
|
|
206
209
|
|
|
207
210
|
if (!this._ch) {
|
|
@@ -334,7 +337,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
334
337
|
}
|
|
335
338
|
}
|
|
336
339
|
} else if (this._ch === ":") {
|
|
337
|
-
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend) {
|
|
340
|
+
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
|
|
338
341
|
// 'property: value' delimiter
|
|
339
342
|
// which could be in a conditional group query
|
|
340
343
|
this.print_string(':');
|
|
@@ -366,51 +369,66 @@ Beautifier.prototype.beautify = function() {
|
|
|
366
369
|
this.print_string(this._ch + this.eatString(this._ch));
|
|
367
370
|
this.eatWhitespace(true);
|
|
368
371
|
} else if (this._ch === ';') {
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.
|
|
372
|
+
if (parenLevel === 0) {
|
|
373
|
+
if (insidePropertyValue) {
|
|
374
|
+
this.outdent();
|
|
375
|
+
insidePropertyValue = false;
|
|
376
|
+
}
|
|
377
|
+
insideAtExtend = false;
|
|
378
|
+
insideAtImport = false;
|
|
379
|
+
this.print_string(this._ch);
|
|
380
|
+
this.eatWhitespace(true);
|
|
381
|
+
|
|
382
|
+
// This maintains single line comments on the same
|
|
383
|
+
// line. Block comments are also affected, but
|
|
384
|
+
// a new line is always output before one inside
|
|
385
|
+
// that section
|
|
386
|
+
if (this._input.peek() !== '/') {
|
|
387
|
+
this._output.add_new_line();
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
this.print_string(this._ch);
|
|
391
|
+
this.eatWhitespace(true);
|
|
392
|
+
this._output.space_before_token = true;
|
|
384
393
|
}
|
|
385
394
|
} else if (this._ch === '(') { // may be a url
|
|
386
395
|
if (this._input.lookBack("url")) {
|
|
387
396
|
this.print_string(this._ch);
|
|
388
397
|
this.eatWhitespace();
|
|
398
|
+
parenLevel++;
|
|
399
|
+
this.indent();
|
|
389
400
|
this._ch = this._input.next();
|
|
390
401
|
if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
|
|
391
402
|
this._input.back();
|
|
392
|
-
parenLevel++;
|
|
393
403
|
} else if (this._ch) {
|
|
394
404
|
this.print_string(this._ch + this.eatString(')'));
|
|
405
|
+
if (parenLevel) {
|
|
406
|
+
parenLevel--;
|
|
407
|
+
this.outdent();
|
|
408
|
+
}
|
|
395
409
|
}
|
|
396
410
|
} else {
|
|
397
|
-
parenLevel++;
|
|
398
411
|
this.preserveSingleSpace(isAfterSpace);
|
|
399
412
|
this.print_string(this._ch);
|
|
400
413
|
this.eatWhitespace();
|
|
414
|
+
parenLevel++;
|
|
415
|
+
this.indent();
|
|
401
416
|
}
|
|
402
417
|
} else if (this._ch === ')') {
|
|
418
|
+
if (parenLevel) {
|
|
419
|
+
parenLevel--;
|
|
420
|
+
this.outdent();
|
|
421
|
+
}
|
|
403
422
|
this.print_string(this._ch);
|
|
404
|
-
parenLevel--;
|
|
405
423
|
} else if (this._ch === ',') {
|
|
406
424
|
this.print_string(this._ch);
|
|
407
425
|
this.eatWhitespace(true);
|
|
408
|
-
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel
|
|
426
|
+
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport) {
|
|
409
427
|
this._output.add_new_line();
|
|
410
428
|
} else {
|
|
411
429
|
this._output.space_before_token = true;
|
|
412
430
|
}
|
|
413
|
-
} else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel
|
|
431
|
+
} else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
|
|
414
432
|
//handle combinator spacing
|
|
415
433
|
if (this._options.space_around_combinator) {
|
|
416
434
|
this._output.space_before_token = true;
|
|
@@ -435,7 +453,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
435
453
|
if (whitespaceChar.test(this._ch)) {
|
|
436
454
|
this._ch = '';
|
|
437
455
|
}
|
|
438
|
-
} else if (this._ch === '!') { // !important
|
|
456
|
+
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
|
|
439
457
|
this.print_string(' ');
|
|
440
458
|
this.print_string(this._ch);
|
|
441
459
|
} else {
|
|
@@ -442,10 +442,12 @@ Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token)
|
|
|
442
442
|
Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
|
|
443
443
|
var local = this;
|
|
444
444
|
if (raw_token.text !== '') {
|
|
445
|
-
|
|
445
|
+
|
|
446
446
|
var text = raw_token.text,
|
|
447
447
|
_beautifier,
|
|
448
|
-
script_indent_level = 1
|
|
448
|
+
script_indent_level = 1,
|
|
449
|
+
pre = '',
|
|
450
|
+
post = '';
|
|
449
451
|
if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
|
|
450
452
|
_beautifier = this._js_beautify;
|
|
451
453
|
} else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
|
|
@@ -457,7 +459,6 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
|
|
|
457
459
|
};
|
|
458
460
|
}
|
|
459
461
|
|
|
460
|
-
|
|
461
462
|
if (this._options.indent_scripts === "keep") {
|
|
462
463
|
script_indent_level = 0;
|
|
463
464
|
} else if (this._options.indent_scripts === "separate") {
|
|
@@ -470,24 +471,67 @@ Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token,
|
|
|
470
471
|
// we'll be adding one back after the text but before the containing tag.
|
|
471
472
|
text = text.replace(/\n[ \t]*$/, '');
|
|
472
473
|
|
|
473
|
-
|
|
474
|
+
// Handle the case where content is wrapped in a comment or cdata.
|
|
475
|
+
if (last_tag_token.custom_beautifier_name !== 'html' &&
|
|
476
|
+
text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
|
|
477
|
+
var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
|
|
474
478
|
|
|
475
|
-
//
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
Child_options.prototype = this._options.raw_options;
|
|
480
|
-
var child_options = new Child_options();
|
|
481
|
-
text = _beautifier(indentation + text, child_options);
|
|
482
|
-
} else {
|
|
483
|
-
// simply indent the string otherwise
|
|
484
|
-
var white = raw_token.whitespace_before;
|
|
485
|
-
if (white) {
|
|
486
|
-
text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
|
|
479
|
+
// if we start to wrap but don't finish, print raw
|
|
480
|
+
if (!matched) {
|
|
481
|
+
printer.add_raw_token(raw_token);
|
|
482
|
+
return;
|
|
487
483
|
}
|
|
488
484
|
|
|
489
|
-
|
|
485
|
+
pre = indentation + matched[1] + '\n';
|
|
486
|
+
text = matched[4];
|
|
487
|
+
if (matched[5]) {
|
|
488
|
+
post = indentation + matched[5];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// if there is at least one empty line at the end of this text, strip it
|
|
492
|
+
// we'll be adding one back after the text but before the containing tag.
|
|
493
|
+
text = text.replace(/\n[ \t]*$/, '');
|
|
494
|
+
|
|
495
|
+
if (matched[2] || matched[3].indexOf('\n') !== -1) {
|
|
496
|
+
// if the first line of the non-comment text has spaces
|
|
497
|
+
// use that as the basis for indenting in null case.
|
|
498
|
+
matched = matched[3].match(/[ \t]+$/);
|
|
499
|
+
if (matched) {
|
|
500
|
+
raw_token.whitespace_before = matched[0];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
490
503
|
}
|
|
504
|
+
|
|
505
|
+
if (text) {
|
|
506
|
+
if (_beautifier) {
|
|
507
|
+
|
|
508
|
+
// call the Beautifier if avaliable
|
|
509
|
+
var Child_options = function() {
|
|
510
|
+
this.eol = '\n';
|
|
511
|
+
};
|
|
512
|
+
Child_options.prototype = this._options.raw_options;
|
|
513
|
+
var child_options = new Child_options();
|
|
514
|
+
text = _beautifier(indentation + text, child_options);
|
|
515
|
+
} else {
|
|
516
|
+
// simply indent the string otherwise
|
|
517
|
+
var white = raw_token.whitespace_before;
|
|
518
|
+
if (white) {
|
|
519
|
+
text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
text = indentation + text.replace(/\n/g, '\n' + indentation);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (pre) {
|
|
527
|
+
if (!text) {
|
|
528
|
+
text = pre + post;
|
|
529
|
+
} else {
|
|
530
|
+
text = pre + text + '\n' + post;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
printer.print_newline(false);
|
|
491
535
|
if (text) {
|
|
492
536
|
raw_token.text = text;
|
|
493
537
|
raw_token.whitespace_before = '';
|
package/js/src/html/options.js
CHANGED
|
@@ -32,6 +32,9 @@ var BaseOptions = require('../core/options').Options;
|
|
|
32
32
|
|
|
33
33
|
function Options(options) {
|
|
34
34
|
BaseOptions.call(this, options, 'html');
|
|
35
|
+
if (this.templating.length === 1 && this.templating[0] === 'auto') {
|
|
36
|
+
this.templating = ['django', 'erb', 'handlebars', 'php'];
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
this.indent_inner_html = this._get_boolean('indent_inner_html');
|
|
37
40
|
this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
|
|
@@ -79,6 +82,7 @@ function Options(options) {
|
|
|
79
82
|
]);
|
|
80
83
|
this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
|
|
81
84
|
this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
|
|
85
|
+
|
|
82
86
|
}
|
|
83
87
|
Options.prototype = new BaseOptions();
|
|
84
88
|
|
package/js/src/html/tokenizer.js
CHANGED
|
@@ -56,7 +56,7 @@ var Tokenizer = function(input_string, options) {
|
|
|
56
56
|
|
|
57
57
|
// Words end at whitespace or when a tag starts
|
|
58
58
|
// if we are indenting handlebars, they are considered tags
|
|
59
|
-
var templatable_reader = new TemplatablePattern(this._input);
|
|
59
|
+
var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
|
|
60
60
|
var pattern_reader = new Pattern(this._input);
|
|
61
61
|
|
|
62
62
|
this.__patterns = {
|
|
@@ -71,7 +71,7 @@ var Tokenizer = function(input_string, options) {
|
|
|
71
71
|
handlebars_open: pattern_reader.until(/[\n\r\t }]/),
|
|
72
72
|
handlebars_raw_close: pattern_reader.until(/}}/),
|
|
73
73
|
comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
|
|
74
|
-
cdata: pattern_reader.starting_with(/<!\[
|
|
74
|
+
cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
|
|
75
75
|
// https://en.wikipedia.org/wiki/Conditional_comment
|
|
76
76
|
conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
|
|
77
77
|
processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
|
|
@@ -122,27 +122,27 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
|
|
|
122
122
|
|
|
123
123
|
token = token || this._read_open_handlebars(c, open_token);
|
|
124
124
|
token = token || this._read_attribute(c, previous_token, open_token);
|
|
125
|
-
token = token || this._read_raw_content(previous_token, open_token);
|
|
125
|
+
token = token || this._read_raw_content(c, previous_token, open_token);
|
|
126
126
|
token = token || this._read_close(c, open_token);
|
|
127
127
|
token = token || this._read_content_word(c);
|
|
128
|
-
token = token || this.
|
|
128
|
+
token = token || this._read_comment_or_cdata(c);
|
|
129
|
+
token = token || this._read_processing(c);
|
|
129
130
|
token = token || this._read_open(c, open_token);
|
|
130
131
|
token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
|
|
131
132
|
|
|
132
133
|
return token;
|
|
133
134
|
};
|
|
134
135
|
|
|
135
|
-
Tokenizer.prototype.
|
|
136
|
+
Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
|
|
136
137
|
var token = null;
|
|
137
138
|
var resulting_string = null;
|
|
138
139
|
var directives = null;
|
|
139
140
|
|
|
140
141
|
if (c === '<') {
|
|
141
142
|
var peek1 = this._input.peek(1);
|
|
142
|
-
//if we're in a comment, do something special
|
|
143
143
|
// We treat all comments as literals, even more than preformatted tags
|
|
144
|
-
// we
|
|
145
|
-
if (
|
|
144
|
+
// we only look for the appropriate closing marker
|
|
145
|
+
if (peek1 === '!') {
|
|
146
146
|
resulting_string = this.__patterns.comment.read();
|
|
147
147
|
|
|
148
148
|
// only process directive on html comments
|
|
@@ -153,8 +153,6 @@ Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
|
|
|
153
153
|
}
|
|
154
154
|
} else {
|
|
155
155
|
resulting_string = this.__patterns.cdata.read();
|
|
156
|
-
resulting_string = resulting_string || this.__patterns.conditional_comment.read();
|
|
157
|
-
resulting_string = resulting_string || this.__patterns.processing.read();
|
|
158
156
|
}
|
|
159
157
|
}
|
|
160
158
|
|
|
@@ -167,6 +165,27 @@ Tokenizer.prototype._read_comment = function(c) { // jshint unused:false
|
|
|
167
165
|
return token;
|
|
168
166
|
};
|
|
169
167
|
|
|
168
|
+
Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
|
|
169
|
+
var token = null;
|
|
170
|
+
var resulting_string = null;
|
|
171
|
+
var directives = null;
|
|
172
|
+
|
|
173
|
+
if (c === '<') {
|
|
174
|
+
var peek1 = this._input.peek(1);
|
|
175
|
+
if (peek1 === '!' || peek1 === '?') {
|
|
176
|
+
resulting_string = this.__patterns.conditional_comment.read();
|
|
177
|
+
resulting_string = resulting_string || this.__patterns.processing.read();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (resulting_string) {
|
|
181
|
+
token = this._create_token(TOKEN.COMMENT, resulting_string);
|
|
182
|
+
token.directives = directives;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return token;
|
|
187
|
+
};
|
|
188
|
+
|
|
170
189
|
Tokenizer.prototype._read_open = function(c, open_token) {
|
|
171
190
|
var resulting_string = null;
|
|
172
191
|
var token = null;
|
|
@@ -258,19 +277,27 @@ Tokenizer.prototype._is_content_unformatted = function(tag_name) {
|
|
|
258
277
|
// script and style tags should always be read as unformatted content
|
|
259
278
|
// finally content_unformatted and unformatted element contents are unformatted
|
|
260
279
|
return this._options.void_elements.indexOf(tag_name) === -1 &&
|
|
261
|
-
(tag_name
|
|
262
|
-
this._options.content_unformatted.indexOf(tag_name) !== -1 ||
|
|
280
|
+
(this._options.content_unformatted.indexOf(tag_name) !== -1 ||
|
|
263
281
|
this._options.unformatted.indexOf(tag_name) !== -1);
|
|
264
282
|
};
|
|
265
283
|
|
|
266
284
|
|
|
267
|
-
Tokenizer.prototype._read_raw_content = function(previous_token, open_token) { // jshint unused:false
|
|
285
|
+
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
|
|
268
286
|
var resulting_string = '';
|
|
269
287
|
if (open_token && open_token.text[0] === '{') {
|
|
270
288
|
resulting_string = this.__patterns.handlebars_raw_close.read();
|
|
271
289
|
} else if (previous_token.type === TOKEN.TAG_CLOSE && (previous_token.opened.text[0] === '<')) {
|
|
272
290
|
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
|
|
273
|
-
if (
|
|
291
|
+
if (tag_name === 'script' || tag_name === 'style') {
|
|
292
|
+
// Script and style tags are allowed to have comments wrapping their content
|
|
293
|
+
// or just have regular content.
|
|
294
|
+
var token = this._read_comment_or_cdata(c);
|
|
295
|
+
if (token) {
|
|
296
|
+
token.type = TOKEN.TEXT;
|
|
297
|
+
return token;
|
|
298
|
+
}
|
|
299
|
+
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
|
300
|
+
} else if (this._is_content_unformatted(tag_name)) {
|
|
274
301
|
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
|
|
275
302
|
}
|
|
276
303
|
}
|
|
@@ -400,7 +400,7 @@ Beautifier.prototype.print_token_line_indentation = function(current_token) {
|
|
|
400
400
|
}
|
|
401
401
|
};
|
|
402
402
|
|
|
403
|
-
Beautifier.prototype.print_token = function(current_token
|
|
403
|
+
Beautifier.prototype.print_token = function(current_token) {
|
|
404
404
|
if (this._output.raw) {
|
|
405
405
|
this._output.add_raw_token(current_token);
|
|
406
406
|
return;
|
|
@@ -426,10 +426,9 @@ Beautifier.prototype.print_token = function(current_token, printable_token) {
|
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
printable_token = printable_token || current_token.text;
|
|
430
429
|
this.print_token_line_indentation(current_token);
|
|
431
430
|
this._output.non_breaking_space = true;
|
|
432
|
-
this._output.add_token(
|
|
431
|
+
this._output.add_token(current_token.text);
|
|
433
432
|
if (this._output.previous_token_wrapped) {
|
|
434
433
|
this._flags.multiline_frame = true;
|
|
435
434
|
}
|
|
@@ -683,6 +682,8 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
683
682
|
if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
|
|
684
683
|
this.set_mode(MODE.BlockStatement);
|
|
685
684
|
this._flags.in_case_statement = true;
|
|
685
|
+
} else if (this._flags.case_body) {
|
|
686
|
+
this.set_mode(MODE.BlockStatement);
|
|
686
687
|
} else if (second_token && (
|
|
687
688
|
(in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
|
|
688
689
|
(in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
|
|
@@ -868,11 +869,12 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
868
869
|
|
|
869
870
|
if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
|
|
870
871
|
this.print_newline();
|
|
871
|
-
if (this._flags.case_body || this._options.jslint_happy) {
|
|
872
|
+
if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) {
|
|
872
873
|
// switch cases following one another
|
|
873
874
|
this.deindent();
|
|
874
|
-
this._flags.case_body = false;
|
|
875
875
|
}
|
|
876
|
+
this._flags.case_body = false;
|
|
877
|
+
|
|
876
878
|
this.print_token(current_token);
|
|
877
879
|
this._flags.in_case = true;
|
|
878
880
|
return;
|
|
@@ -1170,11 +1172,16 @@ Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1170
1172
|
}
|
|
1171
1173
|
|
|
1172
1174
|
if (current_token.text === ':' && this._flags.in_case) {
|
|
1173
|
-
this._flags.case_body = true;
|
|
1174
|
-
this.indent();
|
|
1175
1175
|
this.print_token(current_token);
|
|
1176
|
-
|
|
1176
|
+
|
|
1177
1177
|
this._flags.in_case = false;
|
|
1178
|
+
this._flags.case_body = true;
|
|
1179
|
+
if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
|
|
1180
|
+
this.indent();
|
|
1181
|
+
this.print_newline();
|
|
1182
|
+
} else {
|
|
1183
|
+
this._output.space_before_token = true;
|
|
1184
|
+
}
|
|
1178
1185
|
return;
|
|
1179
1186
|
}
|
|
1180
1187
|
|
|
@@ -1337,8 +1344,12 @@ Beautifier.prototype.handle_block_comment = function(current_token, preserve_sta
|
|
|
1337
1344
|
this.print_token(current_token);
|
|
1338
1345
|
this._output.space_before_token = true;
|
|
1339
1346
|
return;
|
|
1347
|
+
} else {
|
|
1348
|
+
this.print_block_commment(current_token, preserve_statement_flags);
|
|
1340
1349
|
}
|
|
1350
|
+
};
|
|
1341
1351
|
|
|
1352
|
+
Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
|
|
1342
1353
|
var lines = split_linebreaks(current_token.text);
|
|
1343
1354
|
var j; // iterator for this case
|
|
1344
1355
|
var javadoc = false;
|
|
@@ -1350,7 +1361,8 @@ Beautifier.prototype.handle_block_comment = function(current_token, preserve_sta
|
|
|
1350
1361
|
this.print_newline(false, preserve_statement_flags);
|
|
1351
1362
|
|
|
1352
1363
|
// first line always indented
|
|
1353
|
-
this.
|
|
1364
|
+
this.print_token_line_indentation(current_token);
|
|
1365
|
+
this._output.add_token(lines[0]);
|
|
1354
1366
|
this.print_newline(false, preserve_statement_flags);
|
|
1355
1367
|
|
|
1356
1368
|
|
|
@@ -1366,10 +1378,12 @@ Beautifier.prototype.handle_block_comment = function(current_token, preserve_sta
|
|
|
1366
1378
|
for (j = 0; j < lines.length; j++) {
|
|
1367
1379
|
if (javadoc) {
|
|
1368
1380
|
// javadoc: reformat and re-indent
|
|
1369
|
-
this.
|
|
1381
|
+
this.print_token_line_indentation(current_token);
|
|
1382
|
+
this._output.add_token(ltrim(lines[j]));
|
|
1370
1383
|
} else if (starless && lines[j]) {
|
|
1371
1384
|
// starless: re-indent non-empty content, avoiding trim
|
|
1372
|
-
this.
|
|
1385
|
+
this.print_token_line_indentation(current_token);
|
|
1386
|
+
this._output.add_token(lines[j].substring(lastIndentLength));
|
|
1373
1387
|
} else {
|
|
1374
1388
|
// normal comments output raw
|
|
1375
1389
|
this._output.current_line.set_indent(-1);
|
|
@@ -1384,6 +1398,7 @@ Beautifier.prototype.handle_block_comment = function(current_token, preserve_sta
|
|
|
1384
1398
|
}
|
|
1385
1399
|
};
|
|
1386
1400
|
|
|
1401
|
+
|
|
1387
1402
|
Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
|
|
1388
1403
|
if (current_token.newlines) {
|
|
1389
1404
|
this.print_newline(false, preserve_statement_flags);
|
|
@@ -108,10 +108,8 @@ var Tokenizer = function(input_string, options) {
|
|
|
108
108
|
/\u2028\u2029/.source);
|
|
109
109
|
|
|
110
110
|
var pattern_reader = new Pattern(this._input);
|
|
111
|
-
var templatable = new TemplatablePattern(this._input)
|
|
112
|
-
|
|
113
|
-
templatable = templatable.disable('django');
|
|
114
|
-
|
|
111
|
+
var templatable = new TemplatablePattern(this._input)
|
|
112
|
+
.read_options(this._options);
|
|
115
113
|
|
|
116
114
|
this.__patterns = {
|
|
117
115
|
template: templatable,
|
|
@@ -280,7 +278,7 @@ Tokenizer.prototype._read_non_javascript = function(c) {
|
|
|
280
278
|
|
|
281
279
|
this._input.back();
|
|
282
280
|
|
|
283
|
-
} else if (c === '<') {
|
|
281
|
+
} else if (c === '<' && this._is_first_token()) {
|
|
284
282
|
resulting_string = this.__patterns.html_comment_start.read();
|
|
285
283
|
if (resulting_string) {
|
|
286
284
|
while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-beautify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "beautifier.io for node",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -46,19 +46,21 @@
|
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"config-chain": "^1.1.12",
|
|
49
|
-
"editorconfig": "^0.15.
|
|
49
|
+
"editorconfig": "^0.15.3",
|
|
50
50
|
"glob": "^7.1.3",
|
|
51
|
-
"mkdirp": "~0.5.
|
|
51
|
+
"mkdirp": "~0.5.1",
|
|
52
52
|
"nopt": "~4.0.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"benchmark": "^2.1.4",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
56
|
+
"codemirror": "^5.48.2",
|
|
57
|
+
"jquery": "^3.4.1",
|
|
58
|
+
"jshint": "^2.10.2",
|
|
59
|
+
"mocha": "^6.1.4",
|
|
58
60
|
"mustache": "^3.0.1",
|
|
59
61
|
"node-static": "^0.7.11",
|
|
60
62
|
"requirejs": "^2.3.6",
|
|
61
|
-
"webpack": "^4.
|
|
62
|
-
"webpack-
|
|
63
|
+
"webpack": "^4.36.1",
|
|
64
|
+
"webpack-cli": "^3.3.5"
|
|
63
65
|
}
|
|
64
66
|
}
|