@bmewburn/js-beautify 1.13.0 → 1.14.7-next1
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/README.md +58 -30
- package/js/src/cli.js +16 -4
- package/js/src/core/options.js +2 -2
- package/js/src/core/templatablepattern.js +23 -3
- package/js/src/css/beautifier.js +62 -14
- package/js/src/html/beautifier.js +21 -8
- package/js/src/javascript/beautifier.js +35 -18
- package/js/src/javascript/tokenizer.js +21 -6
- package/package.json +19 -14
- package/CHANGELOG.md +0 -877
|
@@ -186,12 +186,14 @@ Beautifier.prototype.create_flags = function(flags_base, mode) {
|
|
|
186
186
|
inline_frame: false,
|
|
187
187
|
if_block: false,
|
|
188
188
|
else_block: false,
|
|
189
|
+
class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
|
|
189
190
|
do_block: false,
|
|
190
191
|
do_while: false,
|
|
191
192
|
import_block: false,
|
|
192
193
|
in_case_statement: false, // switch(..){ INSIDE HERE }
|
|
193
194
|
in_case: false, // we're on the exact line with "case 0:"
|
|
194
195
|
case_body: false, // the indented case-action block
|
|
196
|
+
case_block: false, // the indented case-action block is wrapped with {}
|
|
195
197
|
indentation_level: next_indent_level,
|
|
196
198
|
alignment: 0,
|
|
197
199
|
line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
|
|
@@ -547,7 +549,7 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
547
549
|
}
|
|
548
550
|
}
|
|
549
551
|
|
|
550
|
-
if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR])) {
|
|
552
|
+
if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
|
|
551
553
|
this._output.space_before_token = true;
|
|
552
554
|
}
|
|
553
555
|
} else {
|
|
@@ -555,7 +557,7 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
555
557
|
if (this._flags.last_token.text === 'for') {
|
|
556
558
|
this._output.space_before_token = this._options.space_before_conditional;
|
|
557
559
|
next_mode = MODE.ForInitializer;
|
|
558
|
-
} else if (in_array(this._flags.last_token.text, ['if', 'while'])) {
|
|
560
|
+
} else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
|
|
559
561
|
this._output.space_before_token = this._options.space_before_conditional;
|
|
560
562
|
next_mode = MODE.Conditional;
|
|
561
563
|
} else if (in_array(this._flags.last_word, ['await', 'async'])) {
|
|
@@ -597,6 +599,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
597
599
|
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
|
|
598
600
|
this._output.space_before_token = true;
|
|
599
601
|
}
|
|
602
|
+
} else if (this._flags.parent && this._flags.parent.class_start_block) {
|
|
603
|
+
this._output.space_before_token = true;
|
|
600
604
|
}
|
|
601
605
|
}
|
|
602
606
|
} else {
|
|
@@ -691,10 +695,10 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
691
695
|
)) {
|
|
692
696
|
// We don't support TypeScript,but we didn't break it for a very long time.
|
|
693
697
|
// We'll try to keep not breaking it.
|
|
694
|
-
if (
|
|
695
|
-
this.set_mode(MODE.ObjectLiteral);
|
|
696
|
-
} else {
|
|
698
|
+
if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
|
|
697
699
|
this.set_mode(MODE.BlockStatement);
|
|
700
|
+
} else {
|
|
701
|
+
this.set_mode(MODE.ObjectLiteral);
|
|
698
702
|
}
|
|
699
703
|
} else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
|
|
700
704
|
// arrow function: (param1, paramN) => { statements }
|
|
@@ -711,6 +715,12 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
711
715
|
this.set_mode(MODE.BlockStatement);
|
|
712
716
|
}
|
|
713
717
|
|
|
718
|
+
if (this._flags.last_token) {
|
|
719
|
+
if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
|
|
720
|
+
this._flags.class_start_block = true;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
714
724
|
var empty_braces = !next_token.comments_before && next_token.text === '}';
|
|
715
725
|
var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
|
|
716
726
|
this._flags.last_token.type === TOKEN.END_EXPR;
|
|
@@ -756,7 +766,7 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
756
766
|
}
|
|
757
767
|
}
|
|
758
768
|
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
|
|
759
|
-
if (this._flags.last_token.type
|
|
769
|
+
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
|
|
760
770
|
this.print_newline();
|
|
761
771
|
} else {
|
|
762
772
|
this._output.space_before_token = true;
|
|
@@ -810,7 +820,7 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
810
820
|
if (current_token.type === TOKEN.RESERVED) {
|
|
811
821
|
if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
|
|
812
822
|
current_token.type = TOKEN.WORD;
|
|
813
|
-
} else if (current_token.text === 'import' && this._tokens.peek().text
|
|
823
|
+
} else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
|
|
814
824
|
current_token.type = TOKEN.WORD;
|
|
815
825
|
} else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
|
|
816
826
|
current_token.type = TOKEN.WORD;
|
|
@@ -870,7 +880,7 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
870
880
|
|
|
871
881
|
if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
|
|
872
882
|
this.print_newline();
|
|
873
|
-
if (this._flags.
|
|
883
|
+
if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
|
|
874
884
|
// switch cases following one another
|
|
875
885
|
this.deindent();
|
|
876
886
|
}
|
|
@@ -1069,7 +1079,9 @@ Beautifier.prototype.handle_semicolon = function(current_token) {
|
|
|
1069
1079
|
};
|
|
1070
1080
|
|
|
1071
1081
|
Beautifier.prototype.handle_string = function(current_token) {
|
|
1072
|
-
if (
|
|
1082
|
+
if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) {
|
|
1083
|
+
//Conditional for detectign backtick strings
|
|
1084
|
+
} else if (this.start_of_statement(current_token)) {
|
|
1073
1085
|
// The conditional starts the statement if appropriate.
|
|
1074
1086
|
// One difference - strings want at least a space before
|
|
1075
1087
|
this._output.space_before_token = true;
|
|
@@ -1081,6 +1093,8 @@ Beautifier.prototype.handle_string = function(current_token) {
|
|
|
1081
1093
|
if (!this.start_of_object_property()) {
|
|
1082
1094
|
this.allow_wrap_or_preserved_newline(current_token);
|
|
1083
1095
|
}
|
|
1096
|
+
} 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)) {
|
|
1097
|
+
this._output.space_before_token = true;
|
|
1084
1098
|
} else {
|
|
1085
1099
|
this.print_newline();
|
|
1086
1100
|
}
|
|
@@ -1158,13 +1172,6 @@ Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1158
1172
|
this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
|
|
1159
1173
|
}
|
|
1160
1174
|
|
|
1161
|
-
if (reserved_array(this._flags.last_token, special_words)) {
|
|
1162
|
-
// "return" had a special handling in TK_WORD. Now we need to return the favor
|
|
1163
|
-
this._output.space_before_token = true;
|
|
1164
|
-
this.print_token(current_token);
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
1175
|
// hack for actionscript's import .*;
|
|
1169
1176
|
if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
|
|
1170
1177
|
this.print_token(current_token);
|
|
@@ -1191,7 +1198,9 @@ Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1191
1198
|
if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
|
|
1192
1199
|
this.indent();
|
|
1193
1200
|
this.print_newline();
|
|
1201
|
+
this._flags.case_block = false;
|
|
1194
1202
|
} else {
|
|
1203
|
+
this._flags.case_block = true;
|
|
1195
1204
|
this._output.space_before_token = true;
|
|
1196
1205
|
}
|
|
1197
1206
|
return;
|
|
@@ -1289,8 +1298,12 @@ Beautifier.prototype.handle_operator = function(current_token) {
|
|
|
1289
1298
|
|
|
1290
1299
|
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
|
|
1291
1300
|
// if there is a newline between -- or ++ and anything else we should preserve it.
|
|
1292
|
-
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) {
|
|
1293
|
-
this.
|
|
1301
|
+
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
|
|
1302
|
+
var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
|
|
1303
|
+
if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
|
|
1304
|
+
this.restore_mode();
|
|
1305
|
+
}
|
|
1306
|
+
this.print_newline(new_line_needed, true);
|
|
1294
1307
|
}
|
|
1295
1308
|
|
|
1296
1309
|
if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
|
|
@@ -1430,6 +1443,10 @@ Beautifier.prototype.handle_dot = function(current_token) {
|
|
|
1430
1443
|
this.handle_whitespace_and_comments(current_token, true);
|
|
1431
1444
|
}
|
|
1432
1445
|
|
|
1446
|
+
if (this._flags.last_token.text.match('^[0-9]+$')) {
|
|
1447
|
+
this._output.space_before_token = true;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1433
1450
|
if (reserved_array(this._flags.last_token, special_words)) {
|
|
1434
1451
|
this._output.space_before_token = false;
|
|
1435
1452
|
} else {
|
|
@@ -66,7 +66,7 @@ var TOKEN = {
|
|
|
66
66
|
|
|
67
67
|
var directives_core = new Directives(/\/\*/, /\*\//);
|
|
68
68
|
|
|
69
|
-
var number_pattern = /0[xX][
|
|
69
|
+
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_]+)?/;
|
|
70
70
|
|
|
71
71
|
var digit = /[0-9]/;
|
|
72
72
|
|
|
@@ -74,7 +74,7 @@ var digit = /[0-9]/;
|
|
|
74
74
|
var dot_pattern = /[^\d\.]/;
|
|
75
75
|
|
|
76
76
|
var positionable_operators = (
|
|
77
|
-
">>> === !== " +
|
|
77
|
+
">>> === !== &&= ??= ||= " +
|
|
78
78
|
"<< && >= ** != == <= >> || ?? |> " +
|
|
79
79
|
"< / - + > : & % ? ^ | *").split(' ');
|
|
80
80
|
|
|
@@ -82,7 +82,7 @@ var positionable_operators = (
|
|
|
82
82
|
// Also, you must update possitionable operators separately from punct
|
|
83
83
|
var punct =
|
|
84
84
|
">>>= " +
|
|
85
|
-
"... >>= <<= === >>> !== **= " +
|
|
85
|
+
"... >>= <<= === >>> !== **= &&= ??= ||= " +
|
|
86
86
|
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
|
|
87
87
|
"= ! ? > < : / ^ - + * & % ~ |";
|
|
88
88
|
|
|
@@ -95,7 +95,7 @@ var punct_pattern = new RegExp(punct);
|
|
|
95
95
|
|
|
96
96
|
// words which should always start on new line.
|
|
97
97
|
var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
|
|
98
|
-
var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as']);
|
|
98
|
+
var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
|
|
99
99
|
var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
|
|
100
100
|
|
|
101
101
|
// var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
|
|
@@ -126,7 +126,7 @@ var Tokenizer = function(input_string, options) {
|
|
|
126
126
|
html_comment_end: pattern_reader.matching(/-->/),
|
|
127
127
|
include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
|
|
128
128
|
shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
|
|
129
|
-
xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[
|
|
129
|
+
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*>/),
|
|
130
130
|
single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
|
|
131
131
|
double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
|
|
132
132
|
template_text: templatable.until(/[`\\$]/),
|
|
@@ -167,6 +167,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
|
|
|
167
167
|
|
|
168
168
|
token = token || this._read_non_javascript(c);
|
|
169
169
|
token = token || this._read_string(c);
|
|
170
|
+
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
|
|
170
171
|
token = token || this._read_word(previous_token);
|
|
171
172
|
token = token || this._read_singles(c);
|
|
172
173
|
token = token || this._read_comment(c);
|
|
@@ -186,7 +187,8 @@ Tokenizer.prototype._read_word = function(previous_token) {
|
|
|
186
187
|
if (!(previous_token.type === TOKEN.DOT ||
|
|
187
188
|
(previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
|
|
188
189
|
reserved_word_pattern.test(resulting_string)) {
|
|
189
|
-
if (resulting_string === 'in' || resulting_string === 'of')
|
|
190
|
+
if ((resulting_string === 'in' || resulting_string === 'of') &&
|
|
191
|
+
(previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
|
|
190
192
|
return this._create_token(TOKEN.OPERATOR, resulting_string);
|
|
191
193
|
}
|
|
192
194
|
return this._create_token(TOKEN.RESERVED, resulting_string);
|
|
@@ -224,6 +226,19 @@ Tokenizer.prototype._read_singles = function(c) {
|
|
|
224
226
|
return token;
|
|
225
227
|
};
|
|
226
228
|
|
|
229
|
+
Tokenizer.prototype._read_pair = function(c, d) {
|
|
230
|
+
var token = null;
|
|
231
|
+
if (c === '#' && d === '{') {
|
|
232
|
+
token = this._create_token(TOKEN.START_BLOCK, c + d);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (token) {
|
|
236
|
+
this._input.next();
|
|
237
|
+
this._input.next();
|
|
238
|
+
}
|
|
239
|
+
return token;
|
|
240
|
+
};
|
|
241
|
+
|
|
227
242
|
Tokenizer.prototype._read_punctuation = function() {
|
|
228
243
|
var resulting_string = this.__patterns.punct.read();
|
|
229
244
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bmewburn/js-beautify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.7-next1",
|
|
4
4
|
"description": "beautifier.io for node",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,24 +44,29 @@
|
|
|
44
44
|
"Liam Newman <bitwiseman@beautifier.io>"
|
|
45
45
|
],
|
|
46
46
|
"license": "MIT",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=10"
|
|
49
|
+
},
|
|
50
|
+
"browserslist": "ie 11",
|
|
47
51
|
"dependencies": {
|
|
48
|
-
"config-chain": "^1.1.
|
|
52
|
+
"config-chain": "^1.1.13",
|
|
49
53
|
"editorconfig": "^0.15.3",
|
|
50
|
-
"glob": "^
|
|
51
|
-
"
|
|
52
|
-
"nopt": "^5.0.0"
|
|
54
|
+
"glob": "^8.0.3",
|
|
55
|
+
"nopt": "^6.0.0"
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
58
|
+
"ansi-regex": "^6.0.1",
|
|
55
59
|
"benchmark": "^2.1.4",
|
|
56
|
-
"codemirror": "^5.
|
|
57
|
-
"jquery": "^3.
|
|
58
|
-
"jshint": "^2.
|
|
59
|
-
"minimist": "
|
|
60
|
-
"mocha": "^
|
|
61
|
-
"mustache": "^4.0
|
|
62
|
-
"serve": "^11.3.2",
|
|
60
|
+
"codemirror": "^5.65.2",
|
|
61
|
+
"jquery": "^3.6.0",
|
|
62
|
+
"jshint": "^2.13.4",
|
|
63
|
+
"minimist": "^1.2.6",
|
|
64
|
+
"mocha": "^10.0.0",
|
|
65
|
+
"mustache": "^4.2.0",
|
|
63
66
|
"requirejs": "^2.3.6",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
67
|
+
"serve": "^14.0.1",
|
|
68
|
+
"strip-ansi": "^7.0.1",
|
|
69
|
+
"webpack": "^5.74.0",
|
|
70
|
+
"webpack-cli": "^4.10.0"
|
|
66
71
|
}
|
|
67
72
|
}
|