js-beautify 1.8.5 → 1.8.9

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +38 -13
  2. package/README.md +17 -14
  3. package/js/lib/beautifier.js +115 -30
  4. package/js/lib/beautifier.min.js +1 -1
  5. package/js/lib/beautify-css.js +14 -5
  6. package/js/lib/beautify-html.js +47 -18
  7. package/js/lib/beautify.js +68 -15
  8. package/js/lib/cli.js +515 -482
  9. package/js/lib/unpackers/javascriptobfuscator_unpacker.js +1 -1
  10. package/js/lib/unpackers/myobfuscate_unpacker.js +1 -1
  11. package/js/lib/unpackers/p_a_c_k_e_r_unpacker.js +1 -1
  12. package/js/lib/unpackers/urlencode_unpacker.js +1 -1
  13. package/js/src/cli.js +515 -482
  14. package/js/src/core/directives.js +1 -1
  15. package/js/src/core/inputscanner.js +1 -1
  16. package/js/src/core/options.js +4 -5
  17. package/js/src/core/output.js +1 -1
  18. package/js/src/core/token.js +1 -1
  19. package/js/src/core/tokenizer.js +1 -1
  20. package/js/src/core/tokenstream.js +1 -1
  21. package/js/src/css/beautifier.js +1 -1
  22. package/js/src/css/index.js +6 -2
  23. package/js/src/css/options.js +1 -1
  24. package/js/src/css/tokenizer.js +1 -1
  25. package/js/src/html/beautifier.js +28 -13
  26. package/js/src/html/index.js +6 -2
  27. package/js/src/html/options.js +2 -2
  28. package/js/src/html/tokenizer.js +1 -1
  29. package/js/src/index.js +2 -1
  30. package/js/src/javascript/acorn.js +1 -1
  31. package/js/src/javascript/beautifier.js +33 -4
  32. package/js/src/javascript/index.js +6 -2
  33. package/js/src/javascript/options.js +3 -1
  34. package/js/src/javascript/tokenizer.js +15 -8
  35. package/js/src/unpackers/javascriptobfuscator_unpacker.js +1 -1
  36. package/js/src/unpackers/myobfuscate_unpacker.js +1 -1
  37. package/js/src/unpackers/p_a_c_k_e_r_unpacker.js +1 -1
  38. package/js/src/unpackers/urlencode_unpacker.js +1 -1
  39. package/package.json +8 -7
@@ -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
- options = _mergeOpts(options, merge_child_field);
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, b: {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 */,
@@ -1228,7 +1234,8 @@ module.exports.Directives = Directives;
1228
1234
 
1229
1235
 
1230
1236
 
1231
- var Beautifier = __webpack_require__(16).Beautifier;
1237
+ var Beautifier = __webpack_require__(16).Beautifier,
1238
+ Options = __webpack_require__(17).Options;
1232
1239
 
1233
1240
  function style_html(html_source, options, js_beautify, css_beautify) {
1234
1241
  var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
@@ -1236,6 +1243,10 @@ function style_html(html_source, options, js_beautify, css_beautify) {
1236
1243
  }
1237
1244
 
1238
1245
  module.exports = style_html;
1246
+ module.exports.defaultOptions = function() {
1247
+ return new Options();
1248
+ };
1249
+
1239
1250
 
1240
1251
  /***/ }),
1241
1252
  /* 16 */
@@ -1487,6 +1498,8 @@ function Beautifier(source_text, options, js_beautify, css_beautify) {
1487
1498
  this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
1488
1499
  this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
1489
1500
  this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
1501
+ this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
1502
+ this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
1490
1503
  }
1491
1504
 
1492
1505
  Beautifier.prototype.beautify = function() {
@@ -1553,7 +1566,10 @@ Beautifier.prototype.beautify = function() {
1553
1566
  };
1554
1567
 
1555
1568
  Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
1556
- var parser_token = { text: raw_token.text, type: raw_token.type };
1569
+ var parser_token = {
1570
+ text: raw_token.text,
1571
+ type: raw_token.type
1572
+ };
1557
1573
  printer.alignment_size = 0;
1558
1574
  last_tag_token.tag_complete = true;
1559
1575
 
@@ -1581,7 +1597,10 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
1581
1597
  };
1582
1598
 
1583
1599
  Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
1584
- var parser_token = { text: raw_token.text, type: raw_token.type };
1600
+ var parser_token = {
1601
+ text: raw_token.text,
1602
+ type: raw_token.type
1603
+ };
1585
1604
  printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
1586
1605
  if (last_tag_token.is_unformatted) {
1587
1606
  printer.add_raw_token(raw_token);
@@ -1603,12 +1622,19 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
1603
1622
  }
1604
1623
 
1605
1624
  if (printer._output.space_before_token && last_tag_token.tag_start_char === '<') {
1625
+ // Allow the current attribute to wrap
1626
+ // Set wrapped to true if the line is wrapped
1606
1627
  var wrapped = printer.print_space_or_wrap(raw_token.text);
1607
1628
  if (raw_token.type === TOKEN.ATTRIBUTE) {
1608
- var indentAttrs = wrapped && !this._is_wrap_attributes_force;
1629
+ if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
1630
+ printer.traverse_whitespace(raw_token);
1631
+ wrapped = wrapped || raw_token.newlines !== 0;
1632
+ }
1633
+ // Save whether we have wrapped any attributes
1634
+ last_tag_token.has_wrapped_attrs = last_tag_token.has_wrapped_attrs || wrapped;
1609
1635
 
1610
1636
  if (this._is_wrap_attributes_force) {
1611
- var force_first_attr_wrap = false;
1637
+ var force_attr_wrap = last_tag_token.attr_count > 1;
1612
1638
  if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
1613
1639
  var is_only_attribute = true;
1614
1640
  var peek_index = 0;
@@ -1622,17 +1648,14 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
1622
1648
  peek_index += 1;
1623
1649
  } while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
1624
1650
 
1625
- force_first_attr_wrap = !is_only_attribute;
1651
+ force_attr_wrap = !is_only_attribute;
1626
1652
  }
1627
1653
 
1628
- if (last_tag_token.attr_count > 1 || force_first_attr_wrap) {
1654
+ if (force_attr_wrap) {
1629
1655
  printer.print_newline(false);
1630
- indentAttrs = true;
1656
+ last_tag_token.has_wrapped_attrs = true;
1631
1657
  }
1632
1658
  }
1633
- if (indentAttrs) {
1634
- last_tag_token.has_wrapped_attrs = true;
1635
- }
1636
1659
  }
1637
1660
  }
1638
1661
  printer.print_token(raw_token.text);
@@ -1641,7 +1664,10 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
1641
1664
  };
1642
1665
 
1643
1666
  Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
1644
- var parser_token = { text: raw_token.text, type: 'TK_CONTENT' };
1667
+ var parser_token = {
1668
+ text: raw_token.text,
1669
+ type: 'TK_CONTENT'
1670
+ };
1645
1671
  if (last_tag_token.custom_beautifier) { //check if we need to format javascript
1646
1672
  this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
1647
1673
  } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
@@ -1716,7 +1742,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
1716
1742
  }
1717
1743
 
1718
1744
  //indent attributes an auto, forced, aligned or forced-align line-wrap
1719
- if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple) {
1745
+ if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
1720
1746
  parser_token.alignment_size = raw_token.text.length + 1;
1721
1747
  }
1722
1748
 
@@ -1986,6 +2012,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
1986
2012
 
1987
2013
  module.exports.Beautifier = Beautifier;
1988
2014
 
2015
+
1989
2016
  /***/ }),
1990
2017
  /* 17 */
1991
2018
  /***/ (function(module, exports, __webpack_require__) {
@@ -2032,7 +2059,7 @@ function Options(options) {
2032
2059
 
2033
2060
  this.indent_handlebars = this._get_boolean('indent_handlebars', true);
2034
2061
  this.wrap_attributes = this._get_selection('wrap_attributes',
2035
- ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple']);
2062
+ ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
2036
2063
  this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
2037
2064
  this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
2038
2065
 
@@ -2074,6 +2101,7 @@ Options.prototype = new BaseOptions();
2074
2101
 
2075
2102
  module.exports.Options = Options;
2076
2103
 
2104
+
2077
2105
  /***/ }),
2078
2106
  /* 18 */
2079
2107
  /***/ (function(module, exports, __webpack_require__) {
@@ -2368,6 +2396,7 @@ Tokenizer.prototype._read_content_word = function() {
2368
2396
  module.exports.Tokenizer = Tokenizer;
2369
2397
  module.exports.TOKEN = TOKEN;
2370
2398
 
2399
+
2371
2400
  /***/ })
2372
2401
  /******/ ]);
2373
2402
  var style_html = legacy_beautify_html;
@@ -210,7 +210,8 @@ var legacy_beautify_js =
210
210
 
211
211
 
212
212
 
213
- var Beautifier = __webpack_require__(1).Beautifier;
213
+ var Beautifier = __webpack_require__(1).Beautifier,
214
+ Options = __webpack_require__(5).Options;
214
215
 
215
216
  function js_beautify(js_source_text, options) {
216
217
  var beautifier = new Beautifier(js_source_text, options);
@@ -218,6 +219,10 @@ function js_beautify(js_source_text, options) {
218
219
  }
219
220
 
220
221
  module.exports = js_beautify;
222
+ module.exports.defaultOptions = function() {
223
+ return new Options();
224
+ };
225
+
221
226
 
222
227
  /***/ }),
223
228
  /* 1 */
@@ -699,7 +704,7 @@ Beautifier.prototype.start_of_statement = function(current_token) {
699
704
  var start = false;
700
705
  start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
701
706
  start = start || reserved_word(this._flags.last_token, 'do');
702
- start = start || (reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines);
707
+ 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
708
  start = start || reserved_word(this._flags.last_token, 'else') &&
704
709
  !(reserved_word(current_token, 'if') && !current_token.comments_before);
705
710
  start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
@@ -793,6 +798,30 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
793
798
  }
794
799
  } else if (this._flags.last_token.type === TOKEN.WORD) {
795
800
  this._output.space_before_token = false;
801
+
802
+ // function name() vs function name ()
803
+ // function* name() vs function* name ()
804
+ // async name() vs async name ()
805
+ // In ES6, you can also define the method properties of an object
806
+ // var obj = {a: function() {}}
807
+ // It can be abbreviated
808
+ // var obj = {a() {}}
809
+ // var obj = { a() {}} vs var obj = { a () {}}
810
+ // var obj = { * a() {}} vs var obj = { * a () {}}
811
+ var peek_back_two = this._tokens.peek(-3);
812
+ if (this._options.space_after_named_function && peek_back_two) {
813
+ // peek starts at next character so -1 is current token
814
+ var peek_back_three = this._tokens.peek(-4);
815
+ if (reserved_array(peek_back_two, ['async', 'function']) ||
816
+ (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
817
+ this._output.space_before_token = true;
818
+ } else if (this._flags.mode === MODE.ObjectLiteral) {
819
+ if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
820
+ (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
821
+ this._output.space_before_token = true;
822
+ }
823
+ }
824
+ }
796
825
  } else {
797
826
  // Support preserving wrapped arrow function expressions
798
827
  // a.b('c',
@@ -808,10 +837,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
808
837
  (this._flags.last_token.text === '*' &&
809
838
  (in_array(this._last_last_text, ['function', 'yield']) ||
810
839
  (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
811
-
812
840
  this._output.space_before_token = this._options.space_after_anon_function;
813
841
  }
814
-
815
842
  }
816
843
 
817
844
  if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
@@ -962,6 +989,11 @@ Beautifier.prototype.handle_start_block = function(current_token) {
962
989
  }
963
990
  this.print_token(current_token);
964
991
  this.indent();
992
+
993
+ // Except for specific cases, open braces are followed by a new line.
994
+ if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
995
+ this.print_newline();
996
+ }
965
997
  };
966
998
 
967
999
  Beautifier.prototype.handle_end_block = function(current_token) {
@@ -1002,6 +1034,8 @@ Beautifier.prototype.handle_word = function(current_token) {
1002
1034
  if (current_token.type === TOKEN.RESERVED) {
1003
1035
  if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
1004
1036
  current_token.type = TOKEN.WORD;
1037
+ } else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
1038
+ current_token.type = TOKEN.WORD;
1005
1039
  } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
1006
1040
  current_token.type = TOKEN.WORD;
1007
1041
  } else if (this._flags.mode === MODE.ObjectLiteral) {
@@ -1620,6 +1654,7 @@ Beautifier.prototype.handle_eof = function(current_token) {
1620
1654
 
1621
1655
  module.exports.Beautifier = Beautifier;
1622
1656
 
1657
+
1623
1658
  /***/ }),
1624
1659
  /* 2 */
1625
1660
  /***/ (function(module, exports, __webpack_require__) {
@@ -1935,6 +1970,7 @@ Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
1935
1970
 
1936
1971
  module.exports.Output = Output;
1937
1972
 
1973
+
1938
1974
  /***/ }),
1939
1975
  /* 3 */
1940
1976
  /***/ (function(module, exports, __webpack_require__) {
@@ -1995,6 +2031,7 @@ function Token(type, text, newlines, whitespace_before) {
1995
2031
 
1996
2032
  module.exports.Token = Token;
1997
2033
 
2034
+
1998
2035
  /***/ }),
1999
2036
  /* 4 */
2000
2037
  /***/ (function(module, exports, __webpack_require__) {
@@ -2057,6 +2094,7 @@ exports.newline = /[\n\r\u2028\u2029]/;
2057
2094
  exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
2058
2095
  exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
2059
2096
 
2097
+
2060
2098
  /***/ }),
2061
2099
  /* 5 */
2062
2100
  /***/ (function(module, exports, __webpack_require__) {
@@ -2133,6 +2171,7 @@ function Options(options) {
2133
2171
  this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
2134
2172
  this.jslint_happy = this._get_boolean('jslint_happy');
2135
2173
  this.space_after_anon_function = this._get_boolean('space_after_anon_function');
2174
+ this.space_after_named_function = this._get_boolean('space_after_named_function');
2136
2175
  this.keep_array_indentation = this._get_boolean('keep_array_indentation');
2137
2176
  this.space_before_conditional = this._get_boolean('space_before_conditional', true);
2138
2177
  this.unescape_strings = this._get_boolean('unescape_strings');
@@ -2147,6 +2186,7 @@ function Options(options) {
2147
2186
  if (this.jslint_happy) {
2148
2187
  this.space_after_anon_function = true;
2149
2188
  }
2189
+
2150
2190
  }
2151
2191
  Options.prototype = new BaseOptions();
2152
2192
 
@@ -2154,6 +2194,7 @@ Options.prototype = new BaseOptions();
2154
2194
 
2155
2195
  module.exports.Options = Options;
2156
2196
 
2197
+
2157
2198
  /***/ }),
2158
2199
  /* 6 */
2159
2200
  /***/ (function(module, exports, __webpack_require__) {
@@ -2190,8 +2231,7 @@ module.exports.Options = Options;
2190
2231
 
2191
2232
 
2192
2233
  function Options(options, merge_child_field) {
2193
- options = _mergeOpts(options, merge_child_field);
2194
- this.raw_options = _normalizeOpts(options);
2234
+ this.raw_options = _mergeOpts(options, merge_child_field);
2195
2235
 
2196
2236
  // Support passing the source text back with no change
2197
2237
  this.disabled = this._get_boolean('disabled');
@@ -2302,10 +2342,10 @@ Options.prototype._is_valid_selection = function(result, selection_list) {
2302
2342
  // Example: obj = {a: 1, b: {a: 2}}
2303
2343
  // mergeOpts(obj, 'b')
2304
2344
  //
2305
- // Returns: {a: 2, b: {a: 2}}
2345
+ // Returns: {a: 2}
2306
2346
  function _mergeOpts(allOptions, childFieldName) {
2307
2347
  var finalOpts = {};
2308
- allOptions = allOptions || {};
2348
+ allOptions = _normalizeOpts(allOptions);
2309
2349
  var name;
2310
2350
 
2311
2351
  for (name in allOptions) {
@@ -2338,6 +2378,7 @@ module.exports.Options = Options;
2338
2378
  module.exports.normalizeOpts = _normalizeOpts;
2339
2379
  module.exports.mergeOpts = _mergeOpts;
2340
2380
 
2381
+
2341
2382
  /***/ }),
2342
2383
  /* 7 */
2343
2384
  /***/ (function(module, exports, __webpack_require__) {
@@ -2432,6 +2473,8 @@ punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
2432
2473
  punct = punct.replace(/ /g, '|');
2433
2474
 
2434
2475
  var punct_pattern = new RegExp(punct, 'g');
2476
+ var shebang_pattern = /#![^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
2477
+ var include_pattern = /#include[^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
2435
2478
 
2436
2479
  // words which should always start on new line.
2437
2480
  var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
@@ -2558,18 +2601,23 @@ Tokenizer.prototype._read_non_javascript = function(c) {
2558
2601
  var resulting_string = '';
2559
2602
 
2560
2603
  if (c === '#') {
2561
- c = this._input.next();
2604
+ if (this._is_first_token()) {
2605
+ resulting_string = this._input.read(shebang_pattern);
2562
2606
 
2563
- if (this._is_first_token() && this._input.peek() === '!') {
2564
- // shebang
2565
- resulting_string = c;
2566
- while (this._input.hasNext() && c !== '\n') {
2567
- c = this._input.next();
2568
- resulting_string += c;
2607
+ if (resulting_string) {
2608
+ return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
2569
2609
  }
2610
+ }
2611
+
2612
+ // handles extendscript #includes
2613
+ resulting_string = this._input.read(include_pattern);
2614
+
2615
+ if (resulting_string) {
2570
2616
  return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
2571
2617
  }
2572
2618
 
2619
+ c = this._input.next();
2620
+
2573
2621
  // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
2574
2622
  var sharp = '#';
2575
2623
  if (this._input.hasNext() && this._input.testChar(digit)) {
@@ -2878,6 +2926,7 @@ module.exports.TOKEN = TOKEN;
2878
2926
  module.exports.positionable_operators = positionable_operators.slice();
2879
2927
  module.exports.line_starters = line_starters.slice();
2880
2928
 
2929
+
2881
2930
  /***/ }),
2882
2931
  /* 8 */
2883
2932
  /***/ (function(module, exports, __webpack_require__) {
@@ -3032,6 +3081,7 @@ InputScanner.prototype.lookBack = function(testVal) {
3032
3081
 
3033
3082
  module.exports.InputScanner = InputScanner;
3034
3083
 
3084
+
3035
3085
  /***/ }),
3036
3086
  /* 9 */
3037
3087
  /***/ (function(module, exports, __webpack_require__) {
@@ -3190,6 +3240,7 @@ Tokenizer.prototype._readWhitespace = function() {
3190
3240
  module.exports.Tokenizer = Tokenizer;
3191
3241
  module.exports.TOKEN = TOKEN;
3192
3242
 
3243
+
3193
3244
  /***/ }),
3194
3245
  /* 10 */
3195
3246
  /***/ (function(module, exports, __webpack_require__) {
@@ -3274,6 +3325,7 @@ TokenStream.prototype.add = function(token) {
3274
3325
 
3275
3326
  module.exports.TokenStream = TokenStream;
3276
3327
 
3328
+
3277
3329
  /***/ }),
3278
3330
  /* 11 */
3279
3331
  /***/ (function(module, exports, __webpack_require__) {
@@ -3342,6 +3394,7 @@ Directives.prototype.readIgnored = function(input) {
3342
3394
 
3343
3395
  module.exports.Directives = Directives;
3344
3396
 
3397
+
3345
3398
  /***/ })
3346
3399
  /******/ ]);
3347
3400
  var js_beautify = legacy_beautify_js;