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
package/CHANGELOG.md CHANGED
@@ -1,36 +1,61 @@
1
1
  # Changelog
2
- ## v1.8.4
2
+ ## v1.8.9
3
3
 
4
4
  ### Description
5
- Broader adoption of 1.8.x revealed a few more high priority fixes
6
5
 
7
6
 
8
7
  ### Closed Issues
9
- * Multiple newlines added between empty textarea and "unformatted" inline elements ([#1534](https://github.com/beautify-web/js-beautify/issues/1534))
10
- * unindent_chained_methods broken ([#1533](https://github.com/beautify-web/js-beautify/issues/1533))
8
+ * Won't run from CLI - bad option name `files` ([#1583](https://github.com/beautify-web/js-beautify/issues/1583))
9
+ * in the .vue file `space_after_anon_function` is invalid ([#1425](https://github.com/beautify-web/js-beautify/issues/1425))
10
+ * Add function default_options() to beautifier.js ([#1364](https://github.com/beautify-web/js-beautify/issues/1364))
11
+ * Support globs in CLI ([#787](https://github.com/beautify-web/js-beautify/issues/787))
11
12
 
12
13
 
13
- ## v1.8.3
14
+ ## v1.8.8
14
15
 
15
16
  ### Description
16
17
 
17
18
 
18
19
  ### Closed Issues
19
- * Missing Bower Assets ([#1521](https://github.com/beautify-web/js-beautify/issues/1521))
20
- * Javascript ternary breaked with `await` ([#1519](https://github.com/beautify-web/js-beautify/issues/1519))
21
- * Object property indented after `await` ([#1517](https://github.com/beautify-web/js-beautify/issues/1517))
22
- * Handlebars formatting problems ([#870](https://github.com/beautify-web/js-beautify/issues/870))
23
- * beautify.js doesn't have indent_level option ([#724](https://github.com/beautify-web/js-beautify/issues/724))
20
+ * async function in object wrong indentation ([#1573](https://github.com/beautify-web/js-beautify/issues/1573))
24
21
 
25
22
 
26
- ## v1.8.1
23
+ ## v1.8.7
27
24
 
28
25
  ### Description
29
26
 
30
27
 
31
28
  ### Closed Issues
32
- * Why npm is a dependency? ([#1516](https://github.com/beautify-web/js-beautify/issues/1516))
33
- * indent_inner_html not working in v1.8.0 ([#1514](https://github.com/beautify-web/js-beautify/issues/1514))
29
+ * Add tests for html `indent_scripts` option ([#1518](https://github.com/beautify-web/js-beautify/issues/1518))
30
+ * Support dynamic import ([#1197](https://github.com/beautify-web/js-beautify/issues/1197))
31
+ * HTML: add an option to preserve manual wrapping of attributes ([#1125](https://github.com/beautify-web/js-beautify/issues/1125))
32
+ * js-beautify adds a space between # and include ([#1114](https://github.com/beautify-web/js-beautify/issues/1114))
33
+ * space_after_anon_function doesn't work with anon async functions ([#1034](https://github.com/beautify-web/js-beautify/issues/1034))
34
+ * Space before function arguments (space-after-function) (space-after-named-function) ([#608](https://github.com/beautify-web/js-beautify/issues/608))
35
+
36
+
37
+ ## v1.8.6
38
+
39
+ ### Description
40
+ Beautifier has moved to https://beautifier.io
41
+
42
+ ### Closed Issues
43
+ * JS beautify break the angular compile ([#1544](https://github.com/beautify-web/js-beautify/issues/1544))
44
+ * base64 string is broken with v1.8.4 ([#1535](https://github.com/beautify-web/js-beautify/issues/1535))
45
+ * Bookmarklet becomes totally useless ([#1408](https://github.com/beautify-web/js-beautify/issues/1408))
46
+ * HTTPS ([#1399](https://github.com/beautify-web/js-beautify/issues/1399))
47
+ * Beautify breaks when js starts with space followed by multi-line comment ([#789](https://github.com/beautify-web/js-beautify/issues/789))
48
+
49
+
50
+ ## v1.8.4
51
+
52
+ ### Description
53
+ Broader adoption of 1.8.x revealed a few more high priority fixes
54
+
55
+
56
+ ### Closed Issues
57
+ * Multiple newlines added between empty textarea and "unformatted" inline elements ([#1534](https://github.com/beautify-web/js-beautify/issues/1534))
58
+ * unindent_chained_methods broken ([#1533](https://github.com/beautify-web/js-beautify/issues/1533))
34
59
 
35
60
 
36
61
  ## v1.8.0
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # JS Beautifier
2
- [![Build Status](https://api.travis-ci.org/beautify-web/js-beautify.svg?branch=master)](http://travis-ci.org/beautify-web/js-beautify)
3
- [![Build status](https://ci.appveyor.com/api/projects/status/5bxmpvew5n3e58te/branch/master?svg=true)](https://ci.appveyor.com/project/beautify-web/js-beautify/branch/master)
2
+ [![Build Status](https://dev.azure.com/beautifier-io/js-beautify/_apis/build/status/beautify-web.js-beautify)](https://dev.azure.com/beautifier-io/js-beautify/_build/latest?definitionId=1)
4
3
 
5
4
  [![PyPI version](https://img.shields.io/pypi/v/jsbeautifier.svg)](https://pypi.python.org/pypi/jsbeautifier)
6
5
  [![CDNJS version](https://img.shields.io/cdnjs/v/js-beautify.svg)](https://cdnjs.com/libraries/js-beautify)
@@ -62,17 +61,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
62
61
 
63
62
  To pull the latest version from one of these services include one set of the script tags below in your document:
64
63
  ```html
65
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify.js"></script>
66
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify-css.js"></script>
67
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify-html.js"></script>
64
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify.js"></script>
65
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-css.js"></script>
66
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-html.js"></script>
68
67
 
69
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify.min.js"></script>
70
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify-css.min.js"></script>
71
- <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.5/beautify-html.min.js"></script>
68
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify.min.js"></script>
69
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-css.min.js"></script>
70
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-html.min.js"></script>
72
71
 
73
- <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.5/js/lib/beautify.js"></script>
74
- <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.5/js/lib/beautify-css.js"></script>
75
- <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.5/js/lib/beautify-html.js"></script>
72
+ <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify.js"></script>
73
+ <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify-css.js"></script>
74
+ <script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify-html.js"></script>
76
75
  ```
77
76
 
78
77
  Older versions are available by changing the version number.
@@ -160,7 +159,7 @@ CLI Options:
160
159
  -r, --replace Write output in-place, replacing input
161
160
  -o, --outfile Write output to file (default stdout)
162
161
  --config Path to config file
163
- --type [js|css|html] ["js"]
162
+ --type [js|css|html] ["js"] Select beautifier type (NOTE: Does *not* filter files, only defines which beautifier type to run)
164
163
  -q, --quiet Suppress logging to stdout
165
164
  -h, --help Show this help
166
165
  -v, --version Show the version
@@ -180,6 +179,7 @@ Beautifier Options:
180
179
  -E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )
181
180
  -j, --jslint-happy Enable jslint-stricter mode
182
181
  -a, --space-after-anon-function Add a space before an anonymous function's parens, ie. function ()
182
+ --space-after-named-function Add a space before a named function's parens, i.e. function example ()
183
183
  -b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline]
184
184
  -u, --unindent-chained-methods Don't indent chained method calls
185
185
  -B, --break-chained-methods Break chained method calls across subsequent lines
@@ -200,6 +200,7 @@ Which correspond to the underscored option keys for both library interfaces
200
200
  "indent_size": 4,
201
201
  "indent_char": " ",
202
202
  "indent_with_tabs": false,
203
+ "editorconfig": false,
203
204
  "eol": "\n",
204
205
  "end_with_newline": false,
205
206
  "indent_level": 0,
@@ -209,6 +210,7 @@ Which correspond to the underscored option keys for both library interfaces
209
210
  "space_in_empty_paren": false,
210
211
  "jslint_happy": false,
211
212
  "space_after_anon_function": false,
213
+ "space_after_named_function": false,
212
214
  "brace_style": "collapse",
213
215
  "unindent_chained_methods": false,
214
216
  "break_chained_methods": false,
@@ -327,13 +329,14 @@ HTML Beautifier Options:
327
329
  -b, --brace-style [collapse-preserve-inline|collapse|expand|end-expand|none] ["collapse"]
328
330
  -S, --indent-scripts [keep|separate|normal] ["normal"]
329
331
  -w, --wrap-line-length Maximum characters per line (0 disables) [250]
330
- -A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple] ["auto"]
332
+ -A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]
331
333
  -i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "aligned")
332
334
  -d, --inline List of tags to be considered inline tags
333
335
  -U, --unformatted List of tags (defaults to inline) that should not be reformatted
334
336
  -T, --content_unformatted List of tags (defaults to pre) whose content should not be reformatted
335
337
  -E, --extra_liners List of tags (defaults to [head,body,/html] that should have an extra newline before them.
336
338
  --editorconfig Use EditorConfig to set up the options
339
+ --indent_scripts Sets indent level inside script tags ("normal", "keep", "separate")
337
340
  ```
338
341
 
339
342
  ## Directives to Ignore or Preserve sections (Javascript beautifier only)
@@ -374,4 +377,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
374
377
  Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
375
378
  Mathias Bynens, Vittorio Gambaletta and others.
376
379
 
377
- (README.md: js-beautify@1.8.5)
380
+ (README.md: js-beautify@1.8.9)
@@ -138,11 +138,13 @@ function style_html(html_source, options, js, css) {
138
138
  css = css || css_beautify;
139
139
  return html_beautify(html_source, options, js, css);
140
140
  }
141
+ style_html.defaultOptions = html_beautify.defaultOptions;
141
142
 
142
143
  module.exports.js = js_beautify;
143
144
  module.exports.css = css_beautify;
144
145
  module.exports.html = style_html;
145
146
 
147
+
146
148
  /***/ }),
147
149
  /* 1 */
148
150
  /***/ (function(module, exports, __webpack_require__) {
@@ -178,7 +180,8 @@ module.exports.html = style_html;
178
180
 
179
181
 
180
182
 
181
- var Beautifier = __webpack_require__(2).Beautifier;
183
+ var Beautifier = __webpack_require__(2).Beautifier,
184
+ Options = __webpack_require__(6).Options;
182
185
 
183
186
  function js_beautify(js_source_text, options) {
184
187
  var beautifier = new Beautifier(js_source_text, options);
@@ -186,6 +189,10 @@ function js_beautify(js_source_text, options) {
186
189
  }
187
190
 
188
191
  module.exports = js_beautify;
192
+ module.exports.defaultOptions = function() {
193
+ return new Options();
194
+ };
195
+
189
196
 
190
197
  /***/ }),
191
198
  /* 2 */
@@ -667,7 +674,7 @@ Beautifier.prototype.start_of_statement = function(current_token) {
667
674
  var start = false;
668
675
  start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
669
676
  start = start || reserved_word(this._flags.last_token, 'do');
670
- start = start || (reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines);
677
+ 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;
671
678
  start = start || reserved_word(this._flags.last_token, 'else') &&
672
679
  !(reserved_word(current_token, 'if') && !current_token.comments_before);
673
680
  start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
@@ -761,6 +768,30 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
761
768
  }
762
769
  } else if (this._flags.last_token.type === TOKEN.WORD) {
763
770
  this._output.space_before_token = false;
771
+
772
+ // function name() vs function name ()
773
+ // function* name() vs function* name ()
774
+ // async name() vs async name ()
775
+ // In ES6, you can also define the method properties of an object
776
+ // var obj = {a: function() {}}
777
+ // It can be abbreviated
778
+ // var obj = {a() {}}
779
+ // var obj = { a() {}} vs var obj = { a () {}}
780
+ // var obj = { * a() {}} vs var obj = { * a () {}}
781
+ var peek_back_two = this._tokens.peek(-3);
782
+ if (this._options.space_after_named_function && peek_back_two) {
783
+ // peek starts at next character so -1 is current token
784
+ var peek_back_three = this._tokens.peek(-4);
785
+ if (reserved_array(peek_back_two, ['async', 'function']) ||
786
+ (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
787
+ this._output.space_before_token = true;
788
+ } else if (this._flags.mode === MODE.ObjectLiteral) {
789
+ if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
790
+ (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
791
+ this._output.space_before_token = true;
792
+ }
793
+ }
794
+ }
764
795
  } else {
765
796
  // Support preserving wrapped arrow function expressions
766
797
  // a.b('c',
@@ -776,10 +807,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
776
807
  (this._flags.last_token.text === '*' &&
777
808
  (in_array(this._last_last_text, ['function', 'yield']) ||
778
809
  (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
779
-
780
810
  this._output.space_before_token = this._options.space_after_anon_function;
781
811
  }
782
-
783
812
  }
784
813
 
785
814
  if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
@@ -930,6 +959,11 @@ Beautifier.prototype.handle_start_block = function(current_token) {
930
959
  }
931
960
  this.print_token(current_token);
932
961
  this.indent();
962
+
963
+ // Except for specific cases, open braces are followed by a new line.
964
+ if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
965
+ this.print_newline();
966
+ }
933
967
  };
934
968
 
935
969
  Beautifier.prototype.handle_end_block = function(current_token) {
@@ -970,6 +1004,8 @@ Beautifier.prototype.handle_word = function(current_token) {
970
1004
  if (current_token.type === TOKEN.RESERVED) {
971
1005
  if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
972
1006
  current_token.type = TOKEN.WORD;
1007
+ } else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
1008
+ current_token.type = TOKEN.WORD;
973
1009
  } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
974
1010
  current_token.type = TOKEN.WORD;
975
1011
  } else if (this._flags.mode === MODE.ObjectLiteral) {
@@ -1588,6 +1624,7 @@ Beautifier.prototype.handle_eof = function(current_token) {
1588
1624
 
1589
1625
  module.exports.Beautifier = Beautifier;
1590
1626
 
1627
+
1591
1628
  /***/ }),
1592
1629
  /* 3 */
1593
1630
  /***/ (function(module, exports, __webpack_require__) {
@@ -1903,6 +1940,7 @@ Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
1903
1940
 
1904
1941
  module.exports.Output = Output;
1905
1942
 
1943
+
1906
1944
  /***/ }),
1907
1945
  /* 4 */
1908
1946
  /***/ (function(module, exports, __webpack_require__) {
@@ -1963,6 +2001,7 @@ function Token(type, text, newlines, whitespace_before) {
1963
2001
 
1964
2002
  module.exports.Token = Token;
1965
2003
 
2004
+
1966
2005
  /***/ }),
1967
2006
  /* 5 */
1968
2007
  /***/ (function(module, exports, __webpack_require__) {
@@ -2025,6 +2064,7 @@ exports.newline = /[\n\r\u2028\u2029]/;
2025
2064
  exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
2026
2065
  exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
2027
2066
 
2067
+
2028
2068
  /***/ }),
2029
2069
  /* 6 */
2030
2070
  /***/ (function(module, exports, __webpack_require__) {
@@ -2101,6 +2141,7 @@ function Options(options) {
2101
2141
  this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
2102
2142
  this.jslint_happy = this._get_boolean('jslint_happy');
2103
2143
  this.space_after_anon_function = this._get_boolean('space_after_anon_function');
2144
+ this.space_after_named_function = this._get_boolean('space_after_named_function');
2104
2145
  this.keep_array_indentation = this._get_boolean('keep_array_indentation');
2105
2146
  this.space_before_conditional = this._get_boolean('space_before_conditional', true);
2106
2147
  this.unescape_strings = this._get_boolean('unescape_strings');
@@ -2115,6 +2156,7 @@ function Options(options) {
2115
2156
  if (this.jslint_happy) {
2116
2157
  this.space_after_anon_function = true;
2117
2158
  }
2159
+
2118
2160
  }
2119
2161
  Options.prototype = new BaseOptions();
2120
2162
 
@@ -2122,6 +2164,7 @@ Options.prototype = new BaseOptions();
2122
2164
 
2123
2165
  module.exports.Options = Options;
2124
2166
 
2167
+
2125
2168
  /***/ }),
2126
2169
  /* 7 */
2127
2170
  /***/ (function(module, exports, __webpack_require__) {
@@ -2158,8 +2201,7 @@ module.exports.Options = Options;
2158
2201
 
2159
2202
 
2160
2203
  function Options(options, merge_child_field) {
2161
- options = _mergeOpts(options, merge_child_field);
2162
- this.raw_options = _normalizeOpts(options);
2204
+ this.raw_options = _mergeOpts(options, merge_child_field);
2163
2205
 
2164
2206
  // Support passing the source text back with no change
2165
2207
  this.disabled = this._get_boolean('disabled');
@@ -2270,10 +2312,10 @@ Options.prototype._is_valid_selection = function(result, selection_list) {
2270
2312
  // Example: obj = {a: 1, b: {a: 2}}
2271
2313
  // mergeOpts(obj, 'b')
2272
2314
  //
2273
- // Returns: {a: 2, b: {a: 2}}
2315
+ // Returns: {a: 2}
2274
2316
  function _mergeOpts(allOptions, childFieldName) {
2275
2317
  var finalOpts = {};
2276
- allOptions = allOptions || {};
2318
+ allOptions = _normalizeOpts(allOptions);
2277
2319
  var name;
2278
2320
 
2279
2321
  for (name in allOptions) {
@@ -2306,6 +2348,7 @@ module.exports.Options = Options;
2306
2348
  module.exports.normalizeOpts = _normalizeOpts;
2307
2349
  module.exports.mergeOpts = _mergeOpts;
2308
2350
 
2351
+
2309
2352
  /***/ }),
2310
2353
  /* 8 */
2311
2354
  /***/ (function(module, exports, __webpack_require__) {
@@ -2400,6 +2443,8 @@ punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
2400
2443
  punct = punct.replace(/ /g, '|');
2401
2444
 
2402
2445
  var punct_pattern = new RegExp(punct, 'g');
2446
+ var shebang_pattern = /#![^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
2447
+ var include_pattern = /#include[^\n\r\u2028\u2029]*(?:\r\n|[\n\r\u2028\u2029])?/g;
2403
2448
 
2404
2449
  // words which should always start on new line.
2405
2450
  var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
@@ -2526,18 +2571,23 @@ Tokenizer.prototype._read_non_javascript = function(c) {
2526
2571
  var resulting_string = '';
2527
2572
 
2528
2573
  if (c === '#') {
2529
- c = this._input.next();
2574
+ if (this._is_first_token()) {
2575
+ resulting_string = this._input.read(shebang_pattern);
2530
2576
 
2531
- if (this._is_first_token() && this._input.peek() === '!') {
2532
- // shebang
2533
- resulting_string = c;
2534
- while (this._input.hasNext() && c !== '\n') {
2535
- c = this._input.next();
2536
- resulting_string += c;
2577
+ if (resulting_string) {
2578
+ return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
2537
2579
  }
2580
+ }
2581
+
2582
+ // handles extendscript #includes
2583
+ resulting_string = this._input.read(include_pattern);
2584
+
2585
+ if (resulting_string) {
2538
2586
  return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
2539
2587
  }
2540
2588
 
2589
+ c = this._input.next();
2590
+
2541
2591
  // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
2542
2592
  var sharp = '#';
2543
2593
  if (this._input.hasNext() && this._input.testChar(digit)) {
@@ -2846,6 +2896,7 @@ module.exports.TOKEN = TOKEN;
2846
2896
  module.exports.positionable_operators = positionable_operators.slice();
2847
2897
  module.exports.line_starters = line_starters.slice();
2848
2898
 
2899
+
2849
2900
  /***/ }),
2850
2901
  /* 9 */
2851
2902
  /***/ (function(module, exports, __webpack_require__) {
@@ -3000,6 +3051,7 @@ InputScanner.prototype.lookBack = function(testVal) {
3000
3051
 
3001
3052
  module.exports.InputScanner = InputScanner;
3002
3053
 
3054
+
3003
3055
  /***/ }),
3004
3056
  /* 10 */
3005
3057
  /***/ (function(module, exports, __webpack_require__) {
@@ -3158,6 +3210,7 @@ Tokenizer.prototype._readWhitespace = function() {
3158
3210
  module.exports.Tokenizer = Tokenizer;
3159
3211
  module.exports.TOKEN = TOKEN;
3160
3212
 
3213
+
3161
3214
  /***/ }),
3162
3215
  /* 11 */
3163
3216
  /***/ (function(module, exports, __webpack_require__) {
@@ -3242,6 +3295,7 @@ TokenStream.prototype.add = function(token) {
3242
3295
 
3243
3296
  module.exports.TokenStream = TokenStream;
3244
3297
 
3298
+
3245
3299
  /***/ }),
3246
3300
  /* 12 */
3247
3301
  /***/ (function(module, exports, __webpack_require__) {
@@ -3310,6 +3364,7 @@ Directives.prototype.readIgnored = function(input) {
3310
3364
 
3311
3365
  module.exports.Directives = Directives;
3312
3366
 
3367
+
3313
3368
  /***/ }),
3314
3369
  /* 13 */
3315
3370
  /***/ (function(module, exports, __webpack_require__) {
@@ -3345,7 +3400,8 @@ module.exports.Directives = Directives;
3345
3400
 
3346
3401
 
3347
3402
 
3348
- var Beautifier = __webpack_require__(14).Beautifier;
3403
+ var Beautifier = __webpack_require__(14).Beautifier,
3404
+ Options = __webpack_require__(15).Options;
3349
3405
 
3350
3406
  function css_beautify(source_text, options) {
3351
3407
  var beautifier = new Beautifier(source_text, options);
@@ -3353,6 +3409,10 @@ function css_beautify(source_text, options) {
3353
3409
  }
3354
3410
 
3355
3411
  module.exports = css_beautify;
3412
+ module.exports.defaultOptions = function() {
3413
+ return new Options();
3414
+ };
3415
+
3356
3416
 
3357
3417
  /***/ }),
3358
3418
  /* 14 */
@@ -3798,6 +3858,7 @@ Beautifier.prototype.beautify = function() {
3798
3858
 
3799
3859
  module.exports.Beautifier = Beautifier;
3800
3860
 
3861
+
3801
3862
  /***/ }),
3802
3863
  /* 15 */
3803
3864
  /***/ (function(module, exports, __webpack_require__) {
@@ -3850,6 +3911,7 @@ Options.prototype = new BaseOptions();
3850
3911
 
3851
3912
  module.exports.Options = Options;
3852
3913
 
3914
+
3853
3915
  /***/ }),
3854
3916
  /* 16 */
3855
3917
  /***/ (function(module, exports, __webpack_require__) {
@@ -3885,7 +3947,8 @@ module.exports.Options = Options;
3885
3947
 
3886
3948
 
3887
3949
 
3888
- var Beautifier = __webpack_require__(17).Beautifier;
3950
+ var Beautifier = __webpack_require__(17).Beautifier,
3951
+ Options = __webpack_require__(18).Options;
3889
3952
 
3890
3953
  function style_html(html_source, options, js_beautify, css_beautify) {
3891
3954
  var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
@@ -3893,6 +3956,10 @@ function style_html(html_source, options, js_beautify, css_beautify) {
3893
3956
  }
3894
3957
 
3895
3958
  module.exports = style_html;
3959
+ module.exports.defaultOptions = function() {
3960
+ return new Options();
3961
+ };
3962
+
3896
3963
 
3897
3964
  /***/ }),
3898
3965
  /* 17 */
@@ -4144,6 +4211,8 @@ function Beautifier(source_text, options, js_beautify, css_beautify) {
4144
4211
  this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
4145
4212
  this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
4146
4213
  this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
4214
+ this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
4215
+ this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
4147
4216
  }
4148
4217
 
4149
4218
  Beautifier.prototype.beautify = function() {
@@ -4210,7 +4279,10 @@ Beautifier.prototype.beautify = function() {
4210
4279
  };
4211
4280
 
4212
4281
  Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
4213
- var parser_token = { text: raw_token.text, type: raw_token.type };
4282
+ var parser_token = {
4283
+ text: raw_token.text,
4284
+ type: raw_token.type
4285
+ };
4214
4286
  printer.alignment_size = 0;
4215
4287
  last_tag_token.tag_complete = true;
4216
4288
 
@@ -4238,7 +4310,10 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
4238
4310
  };
4239
4311
 
4240
4312
  Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
4241
- var parser_token = { text: raw_token.text, type: raw_token.type };
4313
+ var parser_token = {
4314
+ text: raw_token.text,
4315
+ type: raw_token.type
4316
+ };
4242
4317
  printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
4243
4318
  if (last_tag_token.is_unformatted) {
4244
4319
  printer.add_raw_token(raw_token);
@@ -4260,12 +4335,19 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
4260
4335
  }
4261
4336
 
4262
4337
  if (printer._output.space_before_token && last_tag_token.tag_start_char === '<') {
4338
+ // Allow the current attribute to wrap
4339
+ // Set wrapped to true if the line is wrapped
4263
4340
  var wrapped = printer.print_space_or_wrap(raw_token.text);
4264
4341
  if (raw_token.type === TOKEN.ATTRIBUTE) {
4265
- var indentAttrs = wrapped && !this._is_wrap_attributes_force;
4342
+ if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
4343
+ printer.traverse_whitespace(raw_token);
4344
+ wrapped = wrapped || raw_token.newlines !== 0;
4345
+ }
4346
+ // Save whether we have wrapped any attributes
4347
+ last_tag_token.has_wrapped_attrs = last_tag_token.has_wrapped_attrs || wrapped;
4266
4348
 
4267
4349
  if (this._is_wrap_attributes_force) {
4268
- var force_first_attr_wrap = false;
4350
+ var force_attr_wrap = last_tag_token.attr_count > 1;
4269
4351
  if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
4270
4352
  var is_only_attribute = true;
4271
4353
  var peek_index = 0;
@@ -4279,17 +4361,14 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
4279
4361
  peek_index += 1;
4280
4362
  } while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
4281
4363
 
4282
- force_first_attr_wrap = !is_only_attribute;
4364
+ force_attr_wrap = !is_only_attribute;
4283
4365
  }
4284
4366
 
4285
- if (last_tag_token.attr_count > 1 || force_first_attr_wrap) {
4367
+ if (force_attr_wrap) {
4286
4368
  printer.print_newline(false);
4287
- indentAttrs = true;
4369
+ last_tag_token.has_wrapped_attrs = true;
4288
4370
  }
4289
4371
  }
4290
- if (indentAttrs) {
4291
- last_tag_token.has_wrapped_attrs = true;
4292
- }
4293
4372
  }
4294
4373
  }
4295
4374
  printer.print_token(raw_token.text);
@@ -4298,7 +4377,10 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
4298
4377
  };
4299
4378
 
4300
4379
  Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
4301
- var parser_token = { text: raw_token.text, type: 'TK_CONTENT' };
4380
+ var parser_token = {
4381
+ text: raw_token.text,
4382
+ type: 'TK_CONTENT'
4383
+ };
4302
4384
  if (last_tag_token.custom_beautifier) { //check if we need to format javascript
4303
4385
  this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
4304
4386
  } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
@@ -4373,7 +4455,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
4373
4455
  }
4374
4456
 
4375
4457
  //indent attributes an auto, forced, aligned or forced-align line-wrap
4376
- if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple) {
4458
+ if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
4377
4459
  parser_token.alignment_size = raw_token.text.length + 1;
4378
4460
  }
4379
4461
 
@@ -4643,6 +4725,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
4643
4725
 
4644
4726
  module.exports.Beautifier = Beautifier;
4645
4727
 
4728
+
4646
4729
  /***/ }),
4647
4730
  /* 18 */
4648
4731
  /***/ (function(module, exports, __webpack_require__) {
@@ -4689,7 +4772,7 @@ function Options(options) {
4689
4772
 
4690
4773
  this.indent_handlebars = this._get_boolean('indent_handlebars', true);
4691
4774
  this.wrap_attributes = this._get_selection('wrap_attributes',
4692
- ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple']);
4775
+ ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
4693
4776
  this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
4694
4777
  this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
4695
4778
 
@@ -4731,6 +4814,7 @@ Options.prototype = new BaseOptions();
4731
4814
 
4732
4815
  module.exports.Options = Options;
4733
4816
 
4817
+
4734
4818
  /***/ }),
4735
4819
  /* 19 */
4736
4820
  /***/ (function(module, exports, __webpack_require__) {
@@ -5025,6 +5109,7 @@ Tokenizer.prototype._read_content_word = function() {
5025
5109
  module.exports.Tokenizer = Tokenizer;
5026
5110
  module.exports.TOKEN = TOKEN;
5027
5111
 
5112
+
5028
5113
  /***/ })
5029
5114
  /******/ ]);
5030
5115
  });