js-beautify 1.8.4 → 1.8.8
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 +33 -10
- package/README.md +18 -15
- package/js/lib/beautifier.js +108 -46
- package/js/lib/beautifier.min.js +1 -1
- package/js/lib/beautify-css.js +12 -7
- package/js/lib/beautify-html.js +62 -39
- package/js/lib/beautify.js +56 -15
- package/js/lib/cli.js +5 -3
- package/js/lib/unpackers/javascriptobfuscator_unpacker.js +2 -2
- package/js/lib/unpackers/myobfuscate_unpacker.js +2 -2
- package/js/lib/unpackers/p_a_c_k_e_r_unpacker.js +1 -1
- package/js/lib/unpackers/urlencode_unpacker.js +2 -2
- package/js/src/cli.js +5 -3
- package/js/src/core/directives.js +1 -1
- package/js/src/core/inputscanner.js +1 -1
- package/js/src/core/options.js +4 -5
- package/js/src/core/output.js +1 -1
- package/js/src/core/token.js +1 -1
- package/js/src/core/tokenizer.js +1 -1
- package/js/src/core/tokenstream.js +1 -1
- package/js/src/css/beautifier.js +2 -2
- package/js/src/css/index.js +1 -1
- package/js/src/css/options.js +1 -1
- package/js/src/css/tokenizer.js +1 -1
- package/js/src/html/beautifier.js +46 -33
- package/js/src/html/index.js +1 -1
- package/js/src/html/options.js +2 -2
- package/js/src/html/tokenizer.js +1 -1
- package/js/src/index.js +1 -1
- package/js/src/javascript/acorn.js +1 -1
- package/js/src/javascript/beautifier.js +23 -2
- package/js/src/javascript/index.js +1 -1
- package/js/src/javascript/options.js +3 -1
- package/js/src/javascript/tokenizer.js +15 -8
- package/js/src/unpackers/javascriptobfuscator_unpacker.js +2 -2
- package/js/src/unpackers/myobfuscate_unpacker.js +2 -2
- package/js/src/unpackers/p_a_c_k_e_r_unpacker.js +1 -1
- package/js/src/unpackers/urlencode_unpacker.js +2 -2
- package/package.json +5 -5
package/js/lib/beautify-html.js
CHANGED
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
|
|
32
32
|
Written by Nochum Sossonko, (nsossonko@hotmail.com)
|
|
33
33
|
|
|
34
|
-
Based on code initially developed by: Einar Lielmanis, <einar@
|
|
35
|
-
|
|
34
|
+
Based on code initially developed by: Einar Lielmanis, <einar@beautifier.io>
|
|
35
|
+
https://beautifier.io/
|
|
36
36
|
|
|
37
37
|
Usage:
|
|
38
38
|
style_html(html_source);
|
|
@@ -479,6 +479,7 @@ Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
|
|
|
479
479
|
|
|
480
480
|
module.exports.Output = Output;
|
|
481
481
|
|
|
482
|
+
|
|
482
483
|
/***/ }),
|
|
483
484
|
/* 3 */
|
|
484
485
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -539,6 +540,7 @@ function Token(type, text, newlines, whitespace_before) {
|
|
|
539
540
|
|
|
540
541
|
module.exports.Token = Token;
|
|
541
542
|
|
|
543
|
+
|
|
542
544
|
/***/ }),
|
|
543
545
|
/* 4 */,
|
|
544
546
|
/* 5 */,
|
|
@@ -577,8 +579,7 @@ module.exports.Token = Token;
|
|
|
577
579
|
|
|
578
580
|
|
|
579
581
|
function Options(options, merge_child_field) {
|
|
580
|
-
|
|
581
|
-
this.raw_options = _normalizeOpts(options);
|
|
582
|
+
this.raw_options = _mergeOpts(options, merge_child_field);
|
|
582
583
|
|
|
583
584
|
// Support passing the source text back with no change
|
|
584
585
|
this.disabled = this._get_boolean('disabled');
|
|
@@ -689,10 +690,10 @@ Options.prototype._is_valid_selection = function(result, selection_list) {
|
|
|
689
690
|
// Example: obj = {a: 1, b: {a: 2}}
|
|
690
691
|
// mergeOpts(obj, 'b')
|
|
691
692
|
//
|
|
692
|
-
// Returns: {a: 2
|
|
693
|
+
// Returns: {a: 2}
|
|
693
694
|
function _mergeOpts(allOptions, childFieldName) {
|
|
694
695
|
var finalOpts = {};
|
|
695
|
-
allOptions = allOptions
|
|
696
|
+
allOptions = _normalizeOpts(allOptions);
|
|
696
697
|
var name;
|
|
697
698
|
|
|
698
699
|
for (name in allOptions) {
|
|
@@ -725,6 +726,7 @@ module.exports.Options = Options;
|
|
|
725
726
|
module.exports.normalizeOpts = _normalizeOpts;
|
|
726
727
|
module.exports.mergeOpts = _mergeOpts;
|
|
727
728
|
|
|
729
|
+
|
|
728
730
|
/***/ }),
|
|
729
731
|
/* 7 */,
|
|
730
732
|
/* 8 */
|
|
@@ -880,6 +882,7 @@ InputScanner.prototype.lookBack = function(testVal) {
|
|
|
880
882
|
|
|
881
883
|
module.exports.InputScanner = InputScanner;
|
|
882
884
|
|
|
885
|
+
|
|
883
886
|
/***/ }),
|
|
884
887
|
/* 9 */
|
|
885
888
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1038,6 +1041,7 @@ Tokenizer.prototype._readWhitespace = function() {
|
|
|
1038
1041
|
module.exports.Tokenizer = Tokenizer;
|
|
1039
1042
|
module.exports.TOKEN = TOKEN;
|
|
1040
1043
|
|
|
1044
|
+
|
|
1041
1045
|
/***/ }),
|
|
1042
1046
|
/* 10 */
|
|
1043
1047
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1122,6 +1126,7 @@ TokenStream.prototype.add = function(token) {
|
|
|
1122
1126
|
|
|
1123
1127
|
module.exports.TokenStream = TokenStream;
|
|
1124
1128
|
|
|
1129
|
+
|
|
1125
1130
|
/***/ }),
|
|
1126
1131
|
/* 11 */
|
|
1127
1132
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1190,6 +1195,7 @@ Directives.prototype.readIgnored = function(input) {
|
|
|
1190
1195
|
|
|
1191
1196
|
module.exports.Directives = Directives;
|
|
1192
1197
|
|
|
1198
|
+
|
|
1193
1199
|
/***/ }),
|
|
1194
1200
|
/* 12 */,
|
|
1195
1201
|
/* 13 */,
|
|
@@ -1237,6 +1243,7 @@ function style_html(html_source, options, js_beautify, css_beautify) {
|
|
|
1237
1243
|
|
|
1238
1244
|
module.exports = style_html;
|
|
1239
1245
|
|
|
1246
|
+
|
|
1240
1247
|
/***/ }),
|
|
1241
1248
|
/* 16 */
|
|
1242
1249
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1304,23 +1311,25 @@ Printer.prototype.add_raw_token = function(token) {
|
|
|
1304
1311
|
this._output.add_raw_token(token);
|
|
1305
1312
|
};
|
|
1306
1313
|
|
|
1307
|
-
Printer.prototype.
|
|
1308
|
-
|
|
1309
|
-
|
|
1314
|
+
Printer.prototype.print_preserved_newlines = function(raw_token) {
|
|
1315
|
+
var newlines = 0;
|
|
1316
|
+
if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
|
|
1317
|
+
newlines = raw_token.newlines ? 1 : 0;
|
|
1318
|
+
}
|
|
1310
1319
|
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1320
|
+
if (this.preserve_newlines) {
|
|
1321
|
+
newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
|
|
1322
|
+
}
|
|
1323
|
+
for (var n = 0; n < newlines; n++) {
|
|
1324
|
+
this.print_newline(n > 0);
|
|
1325
|
+
}
|
|
1314
1326
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
}
|
|
1327
|
+
return newlines !== 0;
|
|
1328
|
+
};
|
|
1318
1329
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
}
|
|
1323
|
-
} else {
|
|
1330
|
+
Printer.prototype.traverse_whitespace = function(raw_token) {
|
|
1331
|
+
if (raw_token.whitespace_before || raw_token.newlines) {
|
|
1332
|
+
if (!this.print_preserved_newlines(raw_token)) {
|
|
1324
1333
|
this._output.space_before_token = true;
|
|
1325
1334
|
this.print_space_or_wrap(raw_token.text);
|
|
1326
1335
|
}
|
|
@@ -1485,6 +1494,8 @@ function Beautifier(source_text, options, js_beautify, css_beautify) {
|
|
|
1485
1494
|
this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
|
|
1486
1495
|
this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
|
|
1487
1496
|
this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
|
|
1497
|
+
this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
|
|
1498
|
+
this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
|
|
1488
1499
|
}
|
|
1489
1500
|
|
|
1490
1501
|
Beautifier.prototype.beautify = function() {
|
|
@@ -1583,25 +1594,37 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
1583
1594
|
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
|
|
1584
1595
|
if (last_tag_token.is_unformatted) {
|
|
1585
1596
|
printer.add_raw_token(raw_token);
|
|
1597
|
+
} else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
|
|
1598
|
+
// For the insides of handlebars allow newlines or a single space between open and contents
|
|
1599
|
+
if (printer.print_preserved_newlines(raw_token)) {
|
|
1600
|
+
printer.print_raw_text(raw_token.whitespace_before + raw_token.text);
|
|
1601
|
+
} else {
|
|
1602
|
+
printer.print_token(raw_token.text);
|
|
1603
|
+
}
|
|
1586
1604
|
} else {
|
|
1587
|
-
if (
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
printer.set_space_before_token(false);
|
|
1595
|
-
}
|
|
1605
|
+
if (raw_token.type === TOKEN.ATTRIBUTE) {
|
|
1606
|
+
printer.set_space_before_token(true);
|
|
1607
|
+
last_tag_token.attr_count += 1;
|
|
1608
|
+
} else if (raw_token.type === TOKEN.EQUALS) { //no space before =
|
|
1609
|
+
printer.set_space_before_token(false);
|
|
1610
|
+
} else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
|
|
1611
|
+
printer.set_space_before_token(false);
|
|
1596
1612
|
}
|
|
1597
1613
|
|
|
1598
1614
|
if (printer._output.space_before_token && last_tag_token.tag_start_char === '<') {
|
|
1615
|
+
// Allow the current attribute to wrap
|
|
1616
|
+
// Set wrapped to true if the line is wrapped
|
|
1599
1617
|
var wrapped = printer.print_space_or_wrap(raw_token.text);
|
|
1600
1618
|
if (raw_token.type === TOKEN.ATTRIBUTE) {
|
|
1601
|
-
|
|
1619
|
+
if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
|
|
1620
|
+
printer.traverse_whitespace(raw_token);
|
|
1621
|
+
wrapped = wrapped || raw_token.newlines !== 0;
|
|
1622
|
+
}
|
|
1623
|
+
// Save whether we have wrapped any attributes
|
|
1624
|
+
last_tag_token.has_wrapped_attrs = last_tag_token.has_wrapped_attrs || wrapped;
|
|
1602
1625
|
|
|
1603
1626
|
if (this._is_wrap_attributes_force) {
|
|
1604
|
-
var
|
|
1627
|
+
var force_attr_wrap = last_tag_token.attr_count > 1;
|
|
1605
1628
|
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
|
|
1606
1629
|
var is_only_attribute = true;
|
|
1607
1630
|
var peek_index = 0;
|
|
@@ -1615,17 +1638,14 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
1615
1638
|
peek_index += 1;
|
|
1616
1639
|
} while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
|
|
1617
1640
|
|
|
1618
|
-
|
|
1641
|
+
force_attr_wrap = !is_only_attribute;
|
|
1619
1642
|
}
|
|
1620
1643
|
|
|
1621
|
-
if (
|
|
1644
|
+
if (force_attr_wrap) {
|
|
1622
1645
|
printer.print_newline(false);
|
|
1623
|
-
|
|
1646
|
+
last_tag_token.has_wrapped_attrs = true;
|
|
1624
1647
|
}
|
|
1625
1648
|
}
|
|
1626
|
-
if (indentAttrs) {
|
|
1627
|
-
last_tag_token.has_wrapped_attrs = true;
|
|
1628
|
-
}
|
|
1629
1649
|
}
|
|
1630
1650
|
}
|
|
1631
1651
|
printer.print_token(raw_token.text);
|
|
@@ -1709,7 +1729,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
|
|
|
1709
1729
|
}
|
|
1710
1730
|
|
|
1711
1731
|
//indent attributes an auto, forced, aligned or forced-align line-wrap
|
|
1712
|
-
if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple) {
|
|
1732
|
+
if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
|
|
1713
1733
|
parser_token.alignment_size = raw_token.text.length + 1;
|
|
1714
1734
|
}
|
|
1715
1735
|
|
|
@@ -1979,6 +1999,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
|
|
|
1979
1999
|
|
|
1980
2000
|
module.exports.Beautifier = Beautifier;
|
|
1981
2001
|
|
|
2002
|
+
|
|
1982
2003
|
/***/ }),
|
|
1983
2004
|
/* 17 */
|
|
1984
2005
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2025,7 +2046,7 @@ function Options(options) {
|
|
|
2025
2046
|
|
|
2026
2047
|
this.indent_handlebars = this._get_boolean('indent_handlebars', true);
|
|
2027
2048
|
this.wrap_attributes = this._get_selection('wrap_attributes',
|
|
2028
|
-
['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple']);
|
|
2049
|
+
['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
|
|
2029
2050
|
this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
|
|
2030
2051
|
this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
|
|
2031
2052
|
|
|
@@ -2067,6 +2088,7 @@ Options.prototype = new BaseOptions();
|
|
|
2067
2088
|
|
|
2068
2089
|
module.exports.Options = Options;
|
|
2069
2090
|
|
|
2091
|
+
|
|
2070
2092
|
/***/ }),
|
|
2071
2093
|
/* 18 */
|
|
2072
2094
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2361,6 +2383,7 @@ Tokenizer.prototype._read_content_word = function() {
|
|
|
2361
2383
|
module.exports.Tokenizer = Tokenizer;
|
|
2362
2384
|
module.exports.TOKEN = TOKEN;
|
|
2363
2385
|
|
|
2386
|
+
|
|
2364
2387
|
/***/ })
|
|
2365
2388
|
/******/ ]);
|
|
2366
2389
|
var style_html = legacy_beautify_html;
|
package/js/lib/beautify.js
CHANGED
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
---------------
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
Written by Einar Lielmanis, <einar@
|
|
33
|
-
|
|
32
|
+
Written by Einar Lielmanis, <einar@beautifier.io>
|
|
33
|
+
https://beautifier.io/
|
|
34
34
|
|
|
35
35
|
Originally converted to javascript by Vital, <vital76@gmail.com>
|
|
36
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@
|
|
37
|
+
Parsing improvements for brace-less statements by Liam Newman <bitwiseman@beautifier.io>
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
Usage:
|
|
@@ -219,6 +219,7 @@ function js_beautify(js_source_text, options) {
|
|
|
219
219
|
|
|
220
220
|
module.exports = js_beautify;
|
|
221
221
|
|
|
222
|
+
|
|
222
223
|
/***/ }),
|
|
223
224
|
/* 1 */
|
|
224
225
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -699,7 +700,7 @@ Beautifier.prototype.start_of_statement = function(current_token) {
|
|
|
699
700
|
var start = false;
|
|
700
701
|
start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
|
|
701
702
|
start = start || reserved_word(this._flags.last_token, 'do');
|
|
702
|
-
start = start || (reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines
|
|
703
|
+
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;
|
|
703
704
|
start = start || reserved_word(this._flags.last_token, 'else') &&
|
|
704
705
|
!(reserved_word(current_token, 'if') && !current_token.comments_before);
|
|
705
706
|
start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
|
|
@@ -793,6 +794,19 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
793
794
|
}
|
|
794
795
|
} else if (this._flags.last_token.type === TOKEN.WORD) {
|
|
795
796
|
this._output.space_before_token = false;
|
|
797
|
+
|
|
798
|
+
// function name() vs function name ()
|
|
799
|
+
// function* name() vs function* name ()
|
|
800
|
+
// async name() vs async name ()
|
|
801
|
+
if (this._options.space_after_named_function) {
|
|
802
|
+
// peek starts at next character so -1 is current token
|
|
803
|
+
var peek_back_three = this._tokens.peek(-4);
|
|
804
|
+
var peek_back_two = this._tokens.peek(-3);
|
|
805
|
+
if (reserved_array(peek_back_two, ['async', 'function']) ||
|
|
806
|
+
(reserved_array(peek_back_three, ['async', 'function']) && peek_back_two.text === '*')) {
|
|
807
|
+
this._output.space_before_token = true;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
796
810
|
} else {
|
|
797
811
|
// Support preserving wrapped arrow function expressions
|
|
798
812
|
// a.b('c',
|
|
@@ -1002,6 +1016,8 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
1002
1016
|
if (current_token.type === TOKEN.RESERVED) {
|
|
1003
1017
|
if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
|
|
1004
1018
|
current_token.type = TOKEN.WORD;
|
|
1019
|
+
} else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
|
|
1020
|
+
current_token.type = TOKEN.WORD;
|
|
1005
1021
|
} else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
|
|
1006
1022
|
current_token.type = TOKEN.WORD;
|
|
1007
1023
|
} else if (this._flags.mode === MODE.ObjectLiteral) {
|
|
@@ -1092,6 +1108,9 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
1092
1108
|
this._output.space_before_token = true;
|
|
1093
1109
|
} else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
|
|
1094
1110
|
this._output.space_before_token = true;
|
|
1111
|
+
} else if (this._flags.last_token.text === 'declare') {
|
|
1112
|
+
// accomodates Typescript declare function formatting
|
|
1113
|
+
this._output.space_before_token = true;
|
|
1095
1114
|
} else {
|
|
1096
1115
|
this.print_newline();
|
|
1097
1116
|
}
|
|
@@ -1180,6 +1199,9 @@ Beautifier.prototype.handle_word = function(current_token) {
|
|
|
1180
1199
|
if (reserved_array(this._flags.last_token, special_words)) {
|
|
1181
1200
|
// no newline between 'return nnn'
|
|
1182
1201
|
this._output.space_before_token = true;
|
|
1202
|
+
} else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
|
|
1203
|
+
// accomodates Typescript declare formatting
|
|
1204
|
+
this._output.space_before_token = true;
|
|
1183
1205
|
} else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
|
|
1184
1206
|
if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
|
|
1185
1207
|
// no need to force newline on 'var': for (var x = 0...)
|
|
@@ -1614,6 +1636,7 @@ Beautifier.prototype.handle_eof = function(current_token) {
|
|
|
1614
1636
|
|
|
1615
1637
|
module.exports.Beautifier = Beautifier;
|
|
1616
1638
|
|
|
1639
|
+
|
|
1617
1640
|
/***/ }),
|
|
1618
1641
|
/* 2 */
|
|
1619
1642
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1929,6 +1952,7 @@ Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
|
|
|
1929
1952
|
|
|
1930
1953
|
module.exports.Output = Output;
|
|
1931
1954
|
|
|
1955
|
+
|
|
1932
1956
|
/***/ }),
|
|
1933
1957
|
/* 3 */
|
|
1934
1958
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -1989,6 +2013,7 @@ function Token(type, text, newlines, whitespace_before) {
|
|
|
1989
2013
|
|
|
1990
2014
|
module.exports.Token = Token;
|
|
1991
2015
|
|
|
2016
|
+
|
|
1992
2017
|
/***/ }),
|
|
1993
2018
|
/* 4 */
|
|
1994
2019
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2051,6 +2076,7 @@ exports.newline = /[\n\r\u2028\u2029]/;
|
|
|
2051
2076
|
exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
|
|
2052
2077
|
exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
|
|
2053
2078
|
|
|
2079
|
+
|
|
2054
2080
|
/***/ }),
|
|
2055
2081
|
/* 5 */
|
|
2056
2082
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2127,6 +2153,7 @@ function Options(options) {
|
|
|
2127
2153
|
this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
|
|
2128
2154
|
this.jslint_happy = this._get_boolean('jslint_happy');
|
|
2129
2155
|
this.space_after_anon_function = this._get_boolean('space_after_anon_function');
|
|
2156
|
+
this.space_after_named_function = this._get_boolean('space_after_named_function');
|
|
2130
2157
|
this.keep_array_indentation = this._get_boolean('keep_array_indentation');
|
|
2131
2158
|
this.space_before_conditional = this._get_boolean('space_before_conditional', true);
|
|
2132
2159
|
this.unescape_strings = this._get_boolean('unescape_strings');
|
|
@@ -2141,6 +2168,7 @@ function Options(options) {
|
|
|
2141
2168
|
if (this.jslint_happy) {
|
|
2142
2169
|
this.space_after_anon_function = true;
|
|
2143
2170
|
}
|
|
2171
|
+
|
|
2144
2172
|
}
|
|
2145
2173
|
Options.prototype = new BaseOptions();
|
|
2146
2174
|
|
|
@@ -2148,6 +2176,7 @@ Options.prototype = new BaseOptions();
|
|
|
2148
2176
|
|
|
2149
2177
|
module.exports.Options = Options;
|
|
2150
2178
|
|
|
2179
|
+
|
|
2151
2180
|
/***/ }),
|
|
2152
2181
|
/* 6 */
|
|
2153
2182
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2184,8 +2213,7 @@ module.exports.Options = Options;
|
|
|
2184
2213
|
|
|
2185
2214
|
|
|
2186
2215
|
function Options(options, merge_child_field) {
|
|
2187
|
-
|
|
2188
|
-
this.raw_options = _normalizeOpts(options);
|
|
2216
|
+
this.raw_options = _mergeOpts(options, merge_child_field);
|
|
2189
2217
|
|
|
2190
2218
|
// Support passing the source text back with no change
|
|
2191
2219
|
this.disabled = this._get_boolean('disabled');
|
|
@@ -2296,10 +2324,10 @@ Options.prototype._is_valid_selection = function(result, selection_list) {
|
|
|
2296
2324
|
// Example: obj = {a: 1, b: {a: 2}}
|
|
2297
2325
|
// mergeOpts(obj, 'b')
|
|
2298
2326
|
//
|
|
2299
|
-
// Returns: {a: 2
|
|
2327
|
+
// Returns: {a: 2}
|
|
2300
2328
|
function _mergeOpts(allOptions, childFieldName) {
|
|
2301
2329
|
var finalOpts = {};
|
|
2302
|
-
allOptions = allOptions
|
|
2330
|
+
allOptions = _normalizeOpts(allOptions);
|
|
2303
2331
|
var name;
|
|
2304
2332
|
|
|
2305
2333
|
for (name in allOptions) {
|
|
@@ -2332,6 +2360,7 @@ module.exports.Options = Options;
|
|
|
2332
2360
|
module.exports.normalizeOpts = _normalizeOpts;
|
|
2333
2361
|
module.exports.mergeOpts = _mergeOpts;
|
|
2334
2362
|
|
|
2363
|
+
|
|
2335
2364
|
/***/ }),
|
|
2336
2365
|
/* 7 */
|
|
2337
2366
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -2426,6 +2455,8 @@ punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
|
|
|
2426
2455
|
punct = punct.replace(/ /g, '|');
|
|
2427
2456
|
|
|
2428
2457
|
var punct_pattern = new RegExp(punct, 'g');
|
|
2458
|
+
var shebang_pattern = /#![^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
|
|
2459
|
+
var include_pattern = /#include[^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
|
|
2429
2460
|
|
|
2430
2461
|
// words which should always start on new line.
|
|
2431
2462
|
var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
|
|
@@ -2552,18 +2583,23 @@ Tokenizer.prototype._read_non_javascript = function(c) {
|
|
|
2552
2583
|
var resulting_string = '';
|
|
2553
2584
|
|
|
2554
2585
|
if (c === '#') {
|
|
2555
|
-
|
|
2586
|
+
if (this._is_first_token()) {
|
|
2587
|
+
resulting_string = this._input.read(shebang_pattern);
|
|
2556
2588
|
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
resulting_string = c;
|
|
2560
|
-
while (this._input.hasNext() && c !== '\n') {
|
|
2561
|
-
c = this._input.next();
|
|
2562
|
-
resulting_string += c;
|
|
2589
|
+
if (resulting_string) {
|
|
2590
|
+
return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
|
2563
2591
|
}
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
// handles extendscript #includes
|
|
2595
|
+
resulting_string = this._input.read(include_pattern);
|
|
2596
|
+
|
|
2597
|
+
if (resulting_string) {
|
|
2564
2598
|
return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
|
|
2565
2599
|
}
|
|
2566
2600
|
|
|
2601
|
+
c = this._input.next();
|
|
2602
|
+
|
|
2567
2603
|
// Spidermonkey-specific sharp variables for circular references. Considered obsolete.
|
|
2568
2604
|
var sharp = '#';
|
|
2569
2605
|
if (this._input.hasNext() && this._input.testChar(digit)) {
|
|
@@ -2872,6 +2908,7 @@ module.exports.TOKEN = TOKEN;
|
|
|
2872
2908
|
module.exports.positionable_operators = positionable_operators.slice();
|
|
2873
2909
|
module.exports.line_starters = line_starters.slice();
|
|
2874
2910
|
|
|
2911
|
+
|
|
2875
2912
|
/***/ }),
|
|
2876
2913
|
/* 8 */
|
|
2877
2914
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -3026,6 +3063,7 @@ InputScanner.prototype.lookBack = function(testVal) {
|
|
|
3026
3063
|
|
|
3027
3064
|
module.exports.InputScanner = InputScanner;
|
|
3028
3065
|
|
|
3066
|
+
|
|
3029
3067
|
/***/ }),
|
|
3030
3068
|
/* 9 */
|
|
3031
3069
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -3184,6 +3222,7 @@ Tokenizer.prototype._readWhitespace = function() {
|
|
|
3184
3222
|
module.exports.Tokenizer = Tokenizer;
|
|
3185
3223
|
module.exports.TOKEN = TOKEN;
|
|
3186
3224
|
|
|
3225
|
+
|
|
3187
3226
|
/***/ }),
|
|
3188
3227
|
/* 10 */
|
|
3189
3228
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -3268,6 +3307,7 @@ TokenStream.prototype.add = function(token) {
|
|
|
3268
3307
|
|
|
3269
3308
|
module.exports.TokenStream = TokenStream;
|
|
3270
3309
|
|
|
3310
|
+
|
|
3271
3311
|
/***/ }),
|
|
3272
3312
|
/* 11 */
|
|
3273
3313
|
/***/ (function(module, exports, __webpack_require__) {
|
|
@@ -3336,6 +3376,7 @@ Directives.prototype.readIgnored = function(input) {
|
|
|
3336
3376
|
|
|
3337
3377
|
module.exports.Directives = Directives;
|
|
3338
3378
|
|
|
3379
|
+
|
|
3339
3380
|
/***/ })
|
|
3340
3381
|
/******/ ]);
|
|
3341
3382
|
var js_beautify = legacy_beautify_js;
|
package/js/lib/cli.js
CHANGED
|
@@ -78,13 +78,14 @@ var path = require('path'),
|
|
|
78
78
|
"space_in_empty_paren": Boolean,
|
|
79
79
|
"jslint_happy": Boolean,
|
|
80
80
|
"space_after_anon_function": Boolean,
|
|
81
|
+
"space_after_named_function": Boolean,
|
|
81
82
|
"brace_style": "brace_style", //See above for validation
|
|
82
83
|
"unindent_chained_methods": Boolean,
|
|
83
84
|
"break_chained_methods": Boolean,
|
|
84
85
|
"keep_array_indentation": Boolean,
|
|
85
86
|
"unescape_strings": Boolean,
|
|
86
87
|
"wrap_line_length": Number,
|
|
87
|
-
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple"],
|
|
88
|
+
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
|
|
88
89
|
"wrap_attributes_indent_size": Number,
|
|
89
90
|
"e4x": Boolean,
|
|
90
91
|
"end_with_newline": Boolean,
|
|
@@ -354,6 +355,7 @@ function usage(err) {
|
|
|
354
355
|
msg.push(' -E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )');
|
|
355
356
|
msg.push(' -j, --jslint-happy Enable jslint-stricter mode');
|
|
356
357
|
msg.push(' -a, --space-after-anon-function Add a space before an anonymous function\'s parens, ie. function ()');
|
|
358
|
+
msg.push(' --space_after_named_function Add a space before a named function\'s parens, ie. function example ()');
|
|
357
359
|
msg.push(' -b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline]');
|
|
358
360
|
msg.push(' -u, --unindent-chained-methods Don\'t indent chained method calls');
|
|
359
361
|
msg.push(' -B, --break-chained-methods Break chained method calls across subsequent lines');
|
|
@@ -371,7 +373,7 @@ function usage(err) {
|
|
|
371
373
|
msg.push(' -H, --indent-handlebars Indent handlebars. Default is false.');
|
|
372
374
|
msg.push(' -S, --indent-scripts [keep|separate|normal] ["normal"]');
|
|
373
375
|
msg.push(' -w, --wrap-line-length Wrap lines at next opportunity after N characters [0]');
|
|
374
|
-
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force] ["auto"]');
|
|
376
|
+
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
|
|
375
377
|
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');
|
|
376
378
|
msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');
|
|
377
379
|
msg.push(' -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]');
|
|
@@ -637,4 +639,4 @@ function logToStdout(str, config) {
|
|
|
637
639
|
if (typeof config.quiet === "undefined" || !config.quiet) {
|
|
638
640
|
console.log(str);
|
|
639
641
|
}
|
|
640
|
-
}
|
|
642
|
+
}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
//
|
|
29
29
|
// simple unpacker/deobfuscator for scripts messed up with javascriptobfuscator.com
|
|
30
|
-
// written by Einar Lielmanis <einar@
|
|
30
|
+
// written by Einar Lielmanis <einar@beautifier.io>
|
|
31
31
|
//
|
|
32
32
|
// usage:
|
|
33
33
|
//
|
|
@@ -129,4 +129,4 @@ var JavascriptObfuscator = {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
|
|
132
|
-
};
|
|
132
|
+
};
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
//
|
|
32
32
|
// trivial bookmarklet/escaped script detector for the javascript beautifier
|
|
33
|
-
// written by Einar Lielmanis <einar@
|
|
33
|
+
// written by Einar Lielmanis <einar@beautifier.io>
|
|
34
34
|
//
|
|
35
35
|
// usage:
|
|
36
36
|
//
|
|
@@ -101,4 +101,4 @@ var Urlencoded = {
|
|
|
101
101
|
|
|
102
102
|
if (isNode) {
|
|
103
103
|
module.exports = Urlencoded;
|
|
104
|
-
}
|
|
104
|
+
}
|
package/js/src/cli.js
CHANGED
|
@@ -78,13 +78,14 @@ var path = require('path'),
|
|
|
78
78
|
"space_in_empty_paren": Boolean,
|
|
79
79
|
"jslint_happy": Boolean,
|
|
80
80
|
"space_after_anon_function": Boolean,
|
|
81
|
+
"space_after_named_function": Boolean,
|
|
81
82
|
"brace_style": "brace_style", //See above for validation
|
|
82
83
|
"unindent_chained_methods": Boolean,
|
|
83
84
|
"break_chained_methods": Boolean,
|
|
84
85
|
"keep_array_indentation": Boolean,
|
|
85
86
|
"unescape_strings": Boolean,
|
|
86
87
|
"wrap_line_length": Number,
|
|
87
|
-
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple"],
|
|
88
|
+
"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
|
|
88
89
|
"wrap_attributes_indent_size": Number,
|
|
89
90
|
"e4x": Boolean,
|
|
90
91
|
"end_with_newline": Boolean,
|
|
@@ -354,6 +355,7 @@ function usage(err) {
|
|
|
354
355
|
msg.push(' -E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )');
|
|
355
356
|
msg.push(' -j, --jslint-happy Enable jslint-stricter mode');
|
|
356
357
|
msg.push(' -a, --space-after-anon-function Add a space before an anonymous function\'s parens, ie. function ()');
|
|
358
|
+
msg.push(' --space_after_named_function Add a space before a named function\'s parens, ie. function example ()');
|
|
357
359
|
msg.push(' -b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline]');
|
|
358
360
|
msg.push(' -u, --unindent-chained-methods Don\'t indent chained method calls');
|
|
359
361
|
msg.push(' -B, --break-chained-methods Break chained method calls across subsequent lines');
|
|
@@ -371,7 +373,7 @@ function usage(err) {
|
|
|
371
373
|
msg.push(' -H, --indent-handlebars Indent handlebars. Default is false.');
|
|
372
374
|
msg.push(' -S, --indent-scripts [keep|separate|normal] ["normal"]');
|
|
373
375
|
msg.push(' -w, --wrap-line-length Wrap lines at next opportunity after N characters [0]');
|
|
374
|
-
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force] ["auto"]');
|
|
376
|
+
msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
|
|
375
377
|
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');
|
|
376
378
|
msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');
|
|
377
379
|
msg.push(' -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]');
|
|
@@ -637,4 +639,4 @@ function logToStdout(str, config) {
|
|
|
637
639
|
if (typeof config.quiet === "undefined" || !config.quiet) {
|
|
638
640
|
console.log(str);
|
|
639
641
|
}
|
|
640
|
-
}
|
|
642
|
+
}
|
package/js/src/core/options.js
CHANGED
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
'use strict';
|
|
30
30
|
|
|
31
31
|
function Options(options, merge_child_field) {
|
|
32
|
-
|
|
33
|
-
this.raw_options = _normalizeOpts(options);
|
|
32
|
+
this.raw_options = _mergeOpts(options, merge_child_field);
|
|
34
33
|
|
|
35
34
|
// Support passing the source text back with no change
|
|
36
35
|
this.disabled = this._get_boolean('disabled');
|
|
@@ -141,10 +140,10 @@ Options.prototype._is_valid_selection = function(result, selection_list) {
|
|
|
141
140
|
// Example: obj = {a: 1, b: {a: 2}}
|
|
142
141
|
// mergeOpts(obj, 'b')
|
|
143
142
|
//
|
|
144
|
-
// Returns: {a: 2
|
|
143
|
+
// Returns: {a: 2}
|
|
145
144
|
function _mergeOpts(allOptions, childFieldName) {
|
|
146
145
|
var finalOpts = {};
|
|
147
|
-
allOptions = allOptions
|
|
146
|
+
allOptions = _normalizeOpts(allOptions);
|
|
148
147
|
var name;
|
|
149
148
|
|
|
150
149
|
for (name in allOptions) {
|
|
@@ -175,4 +174,4 @@ function _normalizeOpts(options) {
|
|
|
175
174
|
|
|
176
175
|
module.exports.Options = Options;
|
|
177
176
|
module.exports.normalizeOpts = _normalizeOpts;
|
|
178
|
-
module.exports.mergeOpts = _mergeOpts;
|
|
177
|
+
module.exports.mergeOpts = _mergeOpts;
|