js-beautify 1.7.0 → 1.7.4

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 (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/CONTRIBUTING.md +3 -3
  3. package/README.md +15 -12
  4. package/js/bin/css-beautify.js +4 -0
  5. package/js/bin/html-beautify.js +4 -0
  6. package/js/bin/js-beautify.js +4 -0
  7. package/js/config/defaults.json +18 -0
  8. package/js/lib/beautify-css.js +1046 -0
  9. package/js/lib/beautify-html.js +1387 -0
  10. package/js/lib/beautify.js +2820 -0
  11. package/js/lib/cli.js +623 -0
  12. package/js/lib/unpackers/javascriptobfuscator_unpacker.js +103 -0
  13. package/js/lib/unpackers/myobfuscate_unpacker.js +90 -0
  14. package/js/lib/unpackers/p_a_c_k_e_r_unpacker.js +83 -0
  15. package/js/lib/unpackers/urlencode_unpacker.js +73 -0
  16. package/js/src/core/acorn.js +63 -0
  17. package/js/src/core/inputscanner.js +95 -0
  18. package/js/src/core/options.js +48 -0
  19. package/js/src/core/output.js +234 -0
  20. package/js/src/core/token.js +49 -0
  21. package/js/src/css/beautifier.js +477 -0
  22. package/js/src/css/index.js +36 -0
  23. package/js/src/html/beautifier.js +1035 -0
  24. package/js/src/html/index.js +36 -0
  25. package/js/src/index.js +27 -0
  26. package/js/src/javascript/beautifier.js +1449 -0
  27. package/js/src/javascript/index.js +36 -0
  28. package/js/src/javascript/tokenizer.js +620 -0
  29. package/js/test/amd-beautify-tests.js +62 -0
  30. package/js/test/generated/beautify-css-tests.js +1393 -0
  31. package/js/test/generated/beautify-html-tests.js +3212 -0
  32. package/js/test/generated/beautify-javascript-tests.js +5896 -0
  33. package/js/test/node-beautify-html-perf-tests.js +51 -0
  34. package/js/test/node-beautify-perf-tests.js +50 -0
  35. package/js/test/node-beautify-tests.js +45 -0
  36. package/js/test/requirejs-html-beautify.html +58 -0
  37. package/js/test/resources/configerror/.jsbeautifyrc +6 -0
  38. package/js/test/resources/configerror/subDir1/subDir2/empty.txt +0 -0
  39. package/js/test/resources/editorconfig/.editorconfig +6 -0
  40. package/js/test/resources/editorconfig/cr/.editorconfig +3 -0
  41. package/js/test/resources/editorconfig/crlf/.editorconfig +3 -0
  42. package/js/test/resources/editorconfig/error/.editorconfig +1 -0
  43. package/js/test/resources/editorconfig/example-base.js +3 -0
  44. package/js/test/resources/example1.js +3 -0
  45. package/js/test/resources/indent11chars/.jsbeautifyrc +6 -0
  46. package/js/test/resources/indent11chars/subDir1/subDir2/empty.txt +0 -0
  47. package/js/test/run-tests +17 -0
  48. package/js/test/sanitytest.js +144 -0
  49. package/js/test/shell-smoke-test.sh +383 -0
  50. package/package.json +1 -1
@@ -0,0 +1,2820 @@
1
+ /*jshint curly:false, eqeqeq:true, laxbreak:true, noempty:false */
2
+ /* AUTO-GENERATED. DO NOT MODIFY. */
3
+ /* see js/src/javascript/index.js */
4
+ /*
5
+
6
+ The MIT License (MIT)
7
+
8
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
9
+
10
+ Permission is hereby granted, free of charge, to any person
11
+ obtaining a copy of this software and associated documentation files
12
+ (the "Software"), to deal in the Software without restriction,
13
+ including without limitation the rights to use, copy, modify, merge,
14
+ publish, distribute, sublicense, and/or sell copies of the Software,
15
+ and to permit persons to whom the Software is furnished to do so,
16
+ subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be
19
+ included in all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ JS Beautifier
31
+ ---------------
32
+
33
+
34
+ Written by Einar Lielmanis, <einar@jsbeautifier.org>
35
+ http://jsbeautifier.org/
36
+
37
+ Originally converted to javascript by Vital, <vital76@gmail.com>
38
+ "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
39
+ Parsing improvements for brace-less statements by Liam Newman <bitwiseman@gmail.com>
40
+
41
+
42
+ Usage:
43
+ js_beautify(js_source_text);
44
+ js_beautify(js_source_text, options);
45
+
46
+ The options are:
47
+ indent_size (default 4) - indentation size,
48
+ indent_char (default space) - character to indent with,
49
+ preserve_newlines (default true) - whether existing line breaks should be preserved,
50
+ max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
51
+
52
+ jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
53
+
54
+ jslint_happy !jslint_happy
55
+ ---------------------------------
56
+ function () function()
57
+
58
+ switch () { switch() {
59
+ case 1: case 1:
60
+ break; break;
61
+ } }
62
+
63
+ space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
64
+ NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
65
+
66
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline"
67
+ put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
68
+ preserve-inline will try to preserve inline blocks of curly braces
69
+
70
+ space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
71
+
72
+ unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
73
+
74
+ wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
75
+ NOTE: This is not a hard limit. Lines will continue until a point where a newline would
76
+ be preserved if it were present.
77
+
78
+ end_with_newline (default false) - end output with a newline
79
+
80
+
81
+ e.g
82
+
83
+ js_beautify(js_source_text, {
84
+ 'indent_size': 1,
85
+ 'indent_char': '\t'
86
+ });
87
+
88
+ */
89
+
90
+ (function() {
91
+ var legacy_beautify_js =
92
+ /******/ (function(modules) { // webpackBootstrap
93
+ /******/ // The module cache
94
+ /******/ var installedModules = {};
95
+ /******/
96
+ /******/ // The require function
97
+ /******/ function __webpack_require__(moduleId) {
98
+ /******/
99
+ /******/ // Check if module is in cache
100
+ /******/ if(installedModules[moduleId]) {
101
+ /******/ return installedModules[moduleId].exports;
102
+ /******/ }
103
+ /******/ // Create a new module (and put it into the cache)
104
+ /******/ var module = installedModules[moduleId] = {
105
+ /******/ i: moduleId,
106
+ /******/ l: false,
107
+ /******/ exports: {}
108
+ /******/ };
109
+ /******/
110
+ /******/ // Execute the module function
111
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
112
+ /******/
113
+ /******/ // Flag the module as loaded
114
+ /******/ module.l = true;
115
+ /******/
116
+ /******/ // Return the exports of the module
117
+ /******/ return module.exports;
118
+ /******/ }
119
+ /******/
120
+ /******/
121
+ /******/ // expose the modules object (__webpack_modules__)
122
+ /******/ __webpack_require__.m = modules;
123
+ /******/
124
+ /******/ // expose the module cache
125
+ /******/ __webpack_require__.c = installedModules;
126
+ /******/
127
+ /******/ // identity function for calling harmony imports with the correct context
128
+ /******/ __webpack_require__.i = function(value) { return value; };
129
+ /******/
130
+ /******/ // define getter function for harmony exports
131
+ /******/ __webpack_require__.d = function(exports, name, getter) {
132
+ /******/ if(!__webpack_require__.o(exports, name)) {
133
+ /******/ Object.defineProperty(exports, name, {
134
+ /******/ configurable: false,
135
+ /******/ enumerable: true,
136
+ /******/ get: getter
137
+ /******/ });
138
+ /******/ }
139
+ /******/ };
140
+ /******/
141
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
142
+ /******/ __webpack_require__.n = function(module) {
143
+ /******/ var getter = module && module.__esModule ?
144
+ /******/ function getDefault() { return module['default']; } :
145
+ /******/ function getModuleExports() { return module; };
146
+ /******/ __webpack_require__.d(getter, 'a', getter);
147
+ /******/ return getter;
148
+ /******/ };
149
+ /******/
150
+ /******/ // Object.prototype.hasOwnProperty.call
151
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
152
+ /******/
153
+ /******/ // __webpack_public_path__
154
+ /******/ __webpack_require__.p = "";
155
+ /******/
156
+ /******/ // Load entry module and return exports
157
+ /******/ return __webpack_require__(__webpack_require__.s = 6);
158
+ /******/ })
159
+ /************************************************************************/
160
+ /******/ ([
161
+ /* 0 */
162
+ /***/ (function(module, exports) {
163
+
164
+ /* jshint curly: false */
165
+ // This section of code is taken from acorn.
166
+ //
167
+ // Acorn was written by Marijn Haverbeke and released under an MIT
168
+ // license. The Unicode regexps (for identifiers and whitespace) were
169
+ // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
170
+ //
171
+ // Git repositories for Acorn are available at
172
+ //
173
+ // http://marijnhaverbeke.nl/git/acorn
174
+ // https://github.com/marijnh/acorn.git
175
+
176
+ // ## Character categories
177
+
178
+ // Big ugly regular expressions that match characters in the
179
+ // whitespace, identifier, and identifier-start categories. These
180
+ // are only applied when a character is found to actually have a
181
+ // code point above 128.
182
+
183
+ var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
184
+ var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
185
+ var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
186
+ var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
187
+ var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
188
+
189
+ // Whether a single character denotes a newline.
190
+
191
+ exports.newline = /[\n\r\u2028\u2029]/;
192
+
193
+ // Matches a whole line break (where CRLF is considered a single
194
+ // line break). Used to count lines.
195
+
196
+ // in javascript, these two differ
197
+ // in python they are the same, different methods are called on them
198
+ exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
199
+ exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
200
+
201
+
202
+ // Test whether a given character code starts an identifier.
203
+
204
+ exports.isIdentifierStart = function(code) {
205
+ // permit $ (36) and @ (64). @ is used in ES7 decorators.
206
+ if (code < 65) return code === 36 || code === 64;
207
+ // 65 through 91 are uppercase letters.
208
+ if (code < 91) return true;
209
+ // permit _ (95).
210
+ if (code < 97) return code === 95;
211
+ // 97 through 123 are lowercase letters.
212
+ if (code < 123) return true;
213
+ return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
214
+ };
215
+
216
+ // Test whether a given character is part of an identifier.
217
+
218
+ exports.isIdentifierChar = function(code) {
219
+ if (code < 48) return code === 36;
220
+ if (code < 58) return true;
221
+ if (code < 65) return false;
222
+ if (code < 91) return true;
223
+ if (code < 97) return code === 95;
224
+ if (code < 123) return true;
225
+ return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
226
+ };
227
+
228
+
229
+ /***/ }),
230
+ /* 1 */
231
+ /***/ (function(module, exports, __webpack_require__) {
232
+
233
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
234
+ /*
235
+
236
+ The MIT License (MIT)
237
+
238
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
239
+
240
+ Permission is hereby granted, free of charge, to any person
241
+ obtaining a copy of this software and associated documentation files
242
+ (the "Software"), to deal in the Software without restriction,
243
+ including without limitation the rights to use, copy, modify, merge,
244
+ publish, distribute, sublicense, and/or sell copies of the Software,
245
+ and to permit persons to whom the Software is furnished to do so,
246
+ subject to the following conditions:
247
+
248
+ The above copyright notice and this permission notice shall be
249
+ included in all copies or substantial portions of the Software.
250
+
251
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
252
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
253
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
254
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
255
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
256
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
257
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
258
+ SOFTWARE.
259
+ */
260
+
261
+ var mergeOpts = __webpack_require__(3).mergeOpts;
262
+ var acorn = __webpack_require__(0);
263
+ var Output = __webpack_require__(4).Output;
264
+ var Tokenizer = __webpack_require__(7).Tokenizer;
265
+
266
+ function remove_redundant_indentation(output, frame) {
267
+ // This implementation is effective but has some issues:
268
+ // - can cause line wrap to happen too soon due to indent removal
269
+ // after wrap points are calculated
270
+ // These issues are minor compared to ugly indentation.
271
+
272
+ if (frame.multiline_frame ||
273
+ frame.mode === MODE.ForInitializer ||
274
+ frame.mode === MODE.Conditional) {
275
+ return;
276
+ }
277
+
278
+ // remove one indent from each line inside this section
279
+ var start_index = frame.start_line_index;
280
+
281
+ output.remove_indent(start_index);
282
+ }
283
+
284
+ function in_array(what, arr) {
285
+ for (var i = 0; i < arr.length; i += 1) {
286
+ if (arr[i] === what) {
287
+ return true;
288
+ }
289
+ }
290
+ return false;
291
+ }
292
+
293
+ function trim(s) {
294
+ return s.replace(/^\s+|\s+$/g, '');
295
+ }
296
+
297
+ function ltrim(s) {
298
+ return s.replace(/^\s+/g, '');
299
+ }
300
+
301
+ // function rtrim(s) {
302
+ // return s.replace(/\s+$/g, '');
303
+ // }
304
+
305
+
306
+ function generateMapFromStrings(list) {
307
+ var result = {};
308
+ for (var x = 0; x < list.length; x++) {
309
+ // make the mapped names underscored instead of dash
310
+ result[list[x].replace(/-/g, '_')] = list[x];
311
+ }
312
+ return result;
313
+ }
314
+
315
+ function sanitizeOperatorPosition(opPosition) {
316
+ opPosition = opPosition || OPERATOR_POSITION.before_newline;
317
+
318
+ if (!in_array(opPosition, validPositionValues)) {
319
+ throw new Error("Invalid Option Value: The option 'operator_position' must be one of the following values\n" +
320
+ validPositionValues +
321
+ "\nYou passed in: '" + opPosition + "'");
322
+ }
323
+
324
+ return opPosition;
325
+ }
326
+
327
+ var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
328
+
329
+ // Generate map from array
330
+ var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
331
+
332
+ var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
333
+
334
+ var MODE = {
335
+ BlockStatement: 'BlockStatement', // 'BLOCK'
336
+ Statement: 'Statement', // 'STATEMENT'
337
+ ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
338
+ ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
339
+ ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
340
+ Conditional: 'Conditional', //'(COND-EXPRESSION)',
341
+ Expression: 'Expression' //'(EXPRESSION)'
342
+ };
343
+
344
+ function Beautifier(js_source_text, options) {
345
+ "use strict";
346
+ var output;
347
+ var tokens = [],
348
+ token_pos;
349
+ var tokenizer;
350
+ var current_token;
351
+ var last_type, last_last_text, indent_string;
352
+ var flags, previous_flags, flag_store;
353
+ var prefix;
354
+
355
+ var handlers, opt;
356
+ var baseIndentString = '';
357
+
358
+ handlers = {
359
+ 'TK_START_EXPR': handle_start_expr,
360
+ 'TK_END_EXPR': handle_end_expr,
361
+ 'TK_START_BLOCK': handle_start_block,
362
+ 'TK_END_BLOCK': handle_end_block,
363
+ 'TK_WORD': handle_word,
364
+ 'TK_RESERVED': handle_word,
365
+ 'TK_SEMICOLON': handle_semicolon,
366
+ 'TK_STRING': handle_string,
367
+ 'TK_EQUALS': handle_equals,
368
+ 'TK_OPERATOR': handle_operator,
369
+ 'TK_COMMA': handle_comma,
370
+ 'TK_BLOCK_COMMENT': handle_block_comment,
371
+ 'TK_COMMENT': handle_comment,
372
+ 'TK_DOT': handle_dot,
373
+ 'TK_UNKNOWN': handle_unknown,
374
+ 'TK_EOF': handle_eof
375
+ };
376
+
377
+ function create_flags(flags_base, mode) {
378
+ var next_indent_level = 0;
379
+ if (flags_base) {
380
+ next_indent_level = flags_base.indentation_level;
381
+ if (!output.just_added_newline() &&
382
+ flags_base.line_indent_level > next_indent_level) {
383
+ next_indent_level = flags_base.line_indent_level;
384
+ }
385
+ }
386
+
387
+ var next_flags = {
388
+ mode: mode,
389
+ parent: flags_base,
390
+ last_text: flags_base ? flags_base.last_text : '', // last token text
391
+ last_word: flags_base ? flags_base.last_word : '', // last 'TK_WORD' passed
392
+ declaration_statement: false,
393
+ declaration_assignment: false,
394
+ multiline_frame: false,
395
+ inline_frame: false,
396
+ if_block: false,
397
+ else_block: false,
398
+ do_block: false,
399
+ do_while: false,
400
+ import_block: false,
401
+ in_case_statement: false, // switch(..){ INSIDE HERE }
402
+ in_case: false, // we're on the exact line with "case 0:"
403
+ case_body: false, // the indented case-action block
404
+ indentation_level: next_indent_level,
405
+ line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
406
+ start_line_index: output.get_line_number(),
407
+ ternary_depth: 0
408
+ };
409
+ return next_flags;
410
+ }
411
+
412
+ // Some interpreters have unexpected results with foo = baz || bar;
413
+ options = options ? options : {};
414
+
415
+ // Allow the setting of language/file-type specific options
416
+ // with inheritance of overall settings
417
+ options = mergeOpts(options, 'js');
418
+
419
+ opt = {};
420
+
421
+ // compatibility, re
422
+ if (options.brace_style === "expand-strict") { //graceful handling of deprecated option
423
+ options.brace_style = "expand";
424
+ } else if (options.brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
425
+ options.brace_style = "collapse,preserve-inline";
426
+ } else if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
427
+ options.brace_style = options.braces_on_own_line ? "expand" : "collapse";
428
+ } else if (!options.brace_style) //Nothing exists to set it
429
+ {
430
+ options.brace_style = "collapse";
431
+ }
432
+
433
+
434
+ var brace_style_split = options.brace_style.split(/[^a-zA-Z0-9_\-]+/);
435
+ opt.brace_style = brace_style_split[0];
436
+ opt.brace_preserve_inline = brace_style_split[1] ? brace_style_split[1] : false;
437
+
438
+ opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
439
+ opt.indent_char = options.indent_char ? options.indent_char : ' ';
440
+ opt.eol = options.eol ? options.eol : 'auto';
441
+ opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;
442
+ opt.unindent_chained_methods = (options.unindent_chained_methods === undefined) ? false : options.unindent_chained_methods;
443
+ opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;
444
+ opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);
445
+ opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
446
+ opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;
447
+ opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
448
+ opt.space_after_anon_function = (options.space_after_anon_function === undefined) ? false : options.space_after_anon_function;
449
+ opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;
450
+ opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;
451
+ opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;
452
+ opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);
453
+ opt.e4x = (options.e4x === undefined) ? false : options.e4x;
454
+ opt.end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
455
+ opt.comma_first = (options.comma_first === undefined) ? false : options.comma_first;
456
+ opt.operator_position = sanitizeOperatorPosition(options.operator_position);
457
+
458
+ // For testing of beautify ignore:start directive
459
+ opt.test_output_raw = (options.test_output_raw === undefined) ? false : options.test_output_raw;
460
+
461
+ // force opt.space_after_anon_function to true if opt.jslint_happy
462
+ if (opt.jslint_happy) {
463
+ opt.space_after_anon_function = true;
464
+ }
465
+
466
+ if (options.indent_with_tabs) {
467
+ opt.indent_char = '\t';
468
+ opt.indent_size = 1;
469
+ }
470
+
471
+ if (opt.eol === 'auto') {
472
+ opt.eol = '\n';
473
+ if (js_source_text && acorn.lineBreak.test(js_source_text || '')) {
474
+ opt.eol = js_source_text.match(acorn.lineBreak)[0];
475
+ }
476
+ }
477
+
478
+ opt.eol = opt.eol.replace(/\\r/, '\r').replace(/\\n/, '\n');
479
+
480
+ //----------------------------------
481
+ indent_string = '';
482
+ while (opt.indent_size > 0) {
483
+ indent_string += opt.indent_char;
484
+ opt.indent_size -= 1;
485
+ }
486
+
487
+ var preindent_index = 0;
488
+ if (js_source_text && js_source_text.length) {
489
+ while ((js_source_text.charAt(preindent_index) === ' ' ||
490
+ js_source_text.charAt(preindent_index) === '\t')) {
491
+ preindent_index += 1;
492
+ }
493
+ baseIndentString = js_source_text.substring(0, preindent_index);
494
+ js_source_text = js_source_text.substring(preindent_index);
495
+ }
496
+
497
+ last_type = 'TK_START_BLOCK'; // last token type
498
+ last_last_text = ''; // pre-last token text
499
+ output = new Output(indent_string, baseIndentString);
500
+
501
+ // If testing the ignore directive, start with output disable set to true
502
+ output.raw = opt.test_output_raw;
503
+
504
+
505
+ // Stack of parsing/formatting states, including MODE.
506
+ // We tokenize, parse, and output in an almost purely a forward-only stream of token input
507
+ // and formatted output. This makes the beautifier less accurate than full parsers
508
+ // but also far more tolerant of syntax errors.
509
+ //
510
+ // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
511
+ // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
512
+ // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
513
+ // most full parsers would die, but the beautifier gracefully falls back to
514
+ // MODE.BlockStatement and continues on.
515
+ flag_store = [];
516
+ set_mode(MODE.BlockStatement);
517
+
518
+ this.beautify = function() {
519
+
520
+ /*jshint onevar:true */
521
+ var sweet_code;
522
+ tokenizer = new Tokenizer(js_source_text, opt, indent_string);
523
+ tokens = tokenizer.tokenize();
524
+ token_pos = 0;
525
+
526
+ current_token = get_token();
527
+ while (current_token) {
528
+ handlers[current_token.type]();
529
+
530
+ last_last_text = flags.last_text;
531
+ last_type = current_token.type;
532
+ flags.last_text = current_token.text;
533
+
534
+ token_pos += 1;
535
+ current_token = get_token();
536
+ }
537
+
538
+ sweet_code = output.get_code(opt.end_with_newline, opt.eol);
539
+
540
+ return sweet_code;
541
+ };
542
+
543
+ function handle_whitespace_and_comments(local_token, preserve_statement_flags) {
544
+ var newlines = local_token.newlines;
545
+ var keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);
546
+ var temp_token = current_token;
547
+
548
+ for (var h = 0; h < local_token.comments_before.length; h++) {
549
+ // The cleanest handling of inline comments is to treat them as though they aren't there.
550
+ // Just continue formatting and the behavior should be logical.
551
+ // Also ignore unknown tokens. Again, this should result in better behavior.
552
+ current_token = local_token.comments_before[h];
553
+ handle_whitespace_and_comments(current_token, preserve_statement_flags);
554
+ handlers[current_token.type](preserve_statement_flags);
555
+ }
556
+ current_token = temp_token;
557
+
558
+ if (keep_whitespace) {
559
+ for (var i = 0; i < newlines; i += 1) {
560
+ print_newline(i > 0, preserve_statement_flags);
561
+ }
562
+ } else {
563
+ if (opt.max_preserve_newlines && newlines > opt.max_preserve_newlines) {
564
+ newlines = opt.max_preserve_newlines;
565
+ }
566
+
567
+ if (opt.preserve_newlines) {
568
+ if (local_token.newlines > 1) {
569
+ print_newline(false, preserve_statement_flags);
570
+ for (var j = 1; j < newlines; j += 1) {
571
+ print_newline(true, preserve_statement_flags);
572
+ }
573
+ }
574
+ }
575
+ }
576
+
577
+ }
578
+
579
+ // we could use just string.split, but
580
+ // IE doesn't like returning empty strings
581
+ function split_linebreaks(s) {
582
+ //return s.split(/\x0d\x0a|\x0a/);
583
+
584
+ s = s.replace(acorn.allLineBreaks, '\n');
585
+ var out = [],
586
+ idx = s.indexOf("\n");
587
+ while (idx !== -1) {
588
+ out.push(s.substring(0, idx));
589
+ s = s.substring(idx + 1);
590
+ idx = s.indexOf("\n");
591
+ }
592
+ if (s.length) {
593
+ out.push(s);
594
+ }
595
+ return out;
596
+ }
597
+
598
+ var newline_restricted_tokens = ['break', 'continue', 'return', 'throw', 'yield'];
599
+
600
+ function allow_wrap_or_preserved_newline(force_linewrap) {
601
+ force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
602
+
603
+ // Never wrap the first token on a line
604
+ if (output.just_added_newline()) {
605
+ return;
606
+ }
607
+
608
+ var shouldPreserveOrForce = (opt.preserve_newlines && current_token.wanted_newline) || force_linewrap;
609
+ var operatorLogicApplies = in_array(flags.last_text, tokenizer.positionable_operators) || in_array(current_token.text, tokenizer.positionable_operators);
610
+
611
+ if (operatorLogicApplies) {
612
+ var shouldPrintOperatorNewline = (
613
+ in_array(flags.last_text, tokenizer.positionable_operators) &&
614
+ in_array(opt.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
615
+ ) ||
616
+ in_array(current_token.text, tokenizer.positionable_operators);
617
+ shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
618
+ }
619
+
620
+ if (shouldPreserveOrForce) {
621
+ print_newline(false, true);
622
+ } else if (opt.wrap_line_length) {
623
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, newline_restricted_tokens)) {
624
+ // These tokens should never have a newline inserted
625
+ // between them and the following expression.
626
+ return;
627
+ }
628
+ var proposed_line_length = output.current_line.get_character_count() + current_token.text.length +
629
+ (output.space_before_token ? 1 : 0);
630
+ if (proposed_line_length >= opt.wrap_line_length) {
631
+ print_newline(false, true);
632
+ }
633
+ }
634
+ }
635
+
636
+ function print_newline(force_newline, preserve_statement_flags) {
637
+ if (!preserve_statement_flags) {
638
+ if (flags.last_text !== ';' && flags.last_text !== ',' && flags.last_text !== '=' && last_type !== 'TK_OPERATOR') {
639
+ var next_token = get_token(1);
640
+ while (flags.mode === MODE.Statement &&
641
+ !(flags.if_block && next_token && next_token.type === 'TK_RESERVED' && next_token.text === 'else') &&
642
+ !flags.do_block) {
643
+ restore_mode();
644
+ }
645
+ }
646
+ }
647
+
648
+ if (output.add_new_line(force_newline)) {
649
+ flags.multiline_frame = true;
650
+ }
651
+ }
652
+
653
+ function print_token_line_indentation() {
654
+ if (output.just_added_newline()) {
655
+ if (opt.keep_array_indentation && is_array(flags.mode) && current_token.wanted_newline) {
656
+ output.current_line.push(current_token.whitespace_before);
657
+ output.space_before_token = false;
658
+ } else if (output.set_indent(flags.indentation_level)) {
659
+ flags.line_indent_level = flags.indentation_level;
660
+ }
661
+ }
662
+ }
663
+
664
+ function print_token(printable_token) {
665
+ if (output.raw) {
666
+ output.add_raw_token(current_token);
667
+ return;
668
+ }
669
+
670
+ if (opt.comma_first && last_type === 'TK_COMMA' &&
671
+ output.just_added_newline()) {
672
+ if (output.previous_line.last() === ',') {
673
+ var popped = output.previous_line.pop();
674
+ // if the comma was already at the start of the line,
675
+ // pull back onto that line and reprint the indentation
676
+ if (output.previous_line.is_empty()) {
677
+ output.previous_line.push(popped);
678
+ output.trim(true);
679
+ output.current_line.pop();
680
+ output.trim();
681
+ }
682
+
683
+ // add the comma in front of the next token
684
+ print_token_line_indentation();
685
+ output.add_token(',');
686
+ output.space_before_token = true;
687
+ }
688
+ }
689
+
690
+ printable_token = printable_token || current_token.text;
691
+ print_token_line_indentation();
692
+ output.add_token(printable_token);
693
+ }
694
+
695
+ function indent() {
696
+ flags.indentation_level += 1;
697
+ }
698
+
699
+ function deindent() {
700
+ if (flags.indentation_level > 0 &&
701
+ ((!flags.parent) || flags.indentation_level > flags.parent.indentation_level)) {
702
+ flags.indentation_level -= 1;
703
+
704
+ }
705
+ }
706
+
707
+ function set_mode(mode) {
708
+ if (flags) {
709
+ flag_store.push(flags);
710
+ previous_flags = flags;
711
+ } else {
712
+ previous_flags = create_flags(null, mode);
713
+ }
714
+
715
+ flags = create_flags(previous_flags, mode);
716
+ }
717
+
718
+ function is_array(mode) {
719
+ return mode === MODE.ArrayLiteral;
720
+ }
721
+
722
+ function is_expression(mode) {
723
+ return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
724
+ }
725
+
726
+ function restore_mode() {
727
+ if (flag_store.length > 0) {
728
+ previous_flags = flags;
729
+ flags = flag_store.pop();
730
+ if (previous_flags.mode === MODE.Statement && !opt.unindent_chained_methods) {
731
+ remove_redundant_indentation(output, previous_flags);
732
+ }
733
+ }
734
+ }
735
+
736
+ function start_of_object_property() {
737
+ return flags.parent.mode === MODE.ObjectLiteral && flags.mode === MODE.Statement && (
738
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set'])));
739
+ }
740
+
741
+ function start_of_statement() {
742
+ if (
743
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') ||
744
+ (last_type === 'TK_RESERVED' && flags.last_text === 'do') ||
745
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, newline_restricted_tokens) && !current_token.wanted_newline) ||
746
+ (last_type === 'TK_RESERVED' && flags.last_text === 'else' &&
747
+ !(current_token.type === 'TK_RESERVED' && current_token.text === 'if' && !current_token.comments_before.length)) ||
748
+ (last_type === 'TK_END_EXPR' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)) ||
749
+ (last_type === 'TK_WORD' && flags.mode === MODE.BlockStatement &&
750
+ !flags.in_case &&
751
+ !(current_token.text === '--' || current_token.text === '++') &&
752
+ last_last_text !== 'function' &&
753
+ current_token.type !== 'TK_WORD' && current_token.type !== 'TK_RESERVED') ||
754
+ (flags.mode === MODE.ObjectLiteral && (
755
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set']))))
756
+ ) {
757
+
758
+ set_mode(MODE.Statement);
759
+ if (!opt.unindent_chained_methods) {
760
+ indent();
761
+ }
762
+
763
+ handle_whitespace_and_comments(current_token, true);
764
+
765
+ // Issue #276:
766
+ // If starting a new statement with [if, for, while, do], push to a new line.
767
+ // if (a) if (b) if(c) d(); else e(); else f();
768
+ if (!start_of_object_property()) {
769
+ allow_wrap_or_preserved_newline(
770
+ current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['do', 'for', 'if', 'while']));
771
+ }
772
+
773
+ return true;
774
+ }
775
+ return false;
776
+ }
777
+
778
+ function all_lines_start_with(lines, c) {
779
+ for (var i = 0; i < lines.length; i++) {
780
+ var line = trim(lines[i]);
781
+ if (line.charAt(0) !== c) {
782
+ return false;
783
+ }
784
+ }
785
+ return true;
786
+ }
787
+
788
+ function each_line_matches_indent(lines, indent) {
789
+ var i = 0,
790
+ len = lines.length,
791
+ line;
792
+ for (; i < len; i++) {
793
+ line = lines[i];
794
+ // allow empty lines to pass through
795
+ if (line && line.indexOf(indent) !== 0) {
796
+ return false;
797
+ }
798
+ }
799
+ return true;
800
+ }
801
+
802
+ function is_special_word(word) {
803
+ return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
804
+ }
805
+
806
+ function get_token(offset) {
807
+ var index = token_pos + (offset || 0);
808
+ return (index < 0 || index >= tokens.length) ? null : tokens[index];
809
+ }
810
+
811
+ function handle_start_expr() {
812
+ // The conditional starts the statement if appropriate.
813
+ if (!start_of_statement()) {
814
+ handle_whitespace_and_comments(current_token);
815
+ }
816
+
817
+ var next_mode = MODE.Expression;
818
+ if (current_token.text === '[') {
819
+
820
+ if (last_type === 'TK_WORD' || flags.last_text === ')') {
821
+ // this is array index specifier, break immediately
822
+ // a[x], fn()[x]
823
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, tokenizer.line_starters)) {
824
+ output.space_before_token = true;
825
+ }
826
+ set_mode(next_mode);
827
+ print_token();
828
+ indent();
829
+ if (opt.space_in_paren) {
830
+ output.space_before_token = true;
831
+ }
832
+ return;
833
+ }
834
+
835
+ next_mode = MODE.ArrayLiteral;
836
+ if (is_array(flags.mode)) {
837
+ if (flags.last_text === '[' ||
838
+ (flags.last_text === ',' && (last_last_text === ']' || last_last_text === '}'))) {
839
+ // ], [ goes to new line
840
+ // }, [ goes to new line
841
+ if (!opt.keep_array_indentation) {
842
+ print_newline();
843
+ }
844
+ }
845
+ }
846
+
847
+ } else {
848
+ if (last_type === 'TK_RESERVED' && flags.last_text === 'for') {
849
+ next_mode = MODE.ForInitializer;
850
+ } else if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['if', 'while'])) {
851
+ next_mode = MODE.Conditional;
852
+ } else {
853
+ // next_mode = MODE.Expression;
854
+ }
855
+ }
856
+
857
+ if (flags.last_text === ';' || last_type === 'TK_START_BLOCK') {
858
+ print_newline();
859
+ } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || flags.last_text === '.') {
860
+ // TODO: Consider whether forcing this is required. Review failing tests when removed.
861
+ allow_wrap_or_preserved_newline(current_token.wanted_newline);
862
+ // do nothing on (( and )( and ][ and ]( and .(
863
+ } else if (!(last_type === 'TK_RESERVED' && current_token.text === '(') && last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
864
+ output.space_before_token = true;
865
+ } else if ((last_type === 'TK_RESERVED' && (flags.last_word === 'function' || flags.last_word === 'typeof')) ||
866
+ (flags.last_text === '*' &&
867
+ (in_array(last_last_text, ['function', 'yield']) ||
868
+ (flags.mode === MODE.ObjectLiteral && in_array(last_last_text, ['{', ',']))))) {
869
+ // function() vs function ()
870
+ // yield*() vs yield* ()
871
+ // function*() vs function* ()
872
+ if (opt.space_after_anon_function) {
873
+ output.space_before_token = true;
874
+ }
875
+ } else if (last_type === 'TK_RESERVED' && (in_array(flags.last_text, tokenizer.line_starters) || flags.last_text === 'catch')) {
876
+ if (opt.space_before_conditional) {
877
+ output.space_before_token = true;
878
+ }
879
+ }
880
+
881
+ // Should be a space between await and an IIFE, or async and an arrow function
882
+ if (current_token.text === '(' && last_type === 'TK_RESERVED' && in_array(flags.last_word, ['await', 'async'])) {
883
+ output.space_before_token = true;
884
+ }
885
+
886
+ // Support of this kind of newline preservation.
887
+ // a = (b &&
888
+ // (c || d));
889
+ if (current_token.text === '(') {
890
+ if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
891
+ if (!start_of_object_property()) {
892
+ allow_wrap_or_preserved_newline();
893
+ }
894
+ }
895
+ }
896
+
897
+ // Support preserving wrapped arrow function expressions
898
+ // a.b('c',
899
+ // () => d.e
900
+ // )
901
+ if (current_token.text === '(' && last_type !== 'TK_WORD' && last_type !== 'TK_RESERVED') {
902
+ allow_wrap_or_preserved_newline();
903
+ }
904
+
905
+ set_mode(next_mode);
906
+ print_token();
907
+ if (opt.space_in_paren) {
908
+ output.space_before_token = true;
909
+ }
910
+
911
+ // In all cases, if we newline while inside an expression it should be indented.
912
+ indent();
913
+ }
914
+
915
+ function handle_end_expr() {
916
+ // statements inside expressions are not valid syntax, but...
917
+ // statements must all be closed when their container closes
918
+ while (flags.mode === MODE.Statement) {
919
+ restore_mode();
920
+ }
921
+
922
+ handle_whitespace_and_comments(current_token);
923
+
924
+ if (flags.multiline_frame) {
925
+ allow_wrap_or_preserved_newline(current_token.text === ']' && is_array(flags.mode) && !opt.keep_array_indentation);
926
+ }
927
+
928
+ if (opt.space_in_paren) {
929
+ if (last_type === 'TK_START_EXPR' && !opt.space_in_empty_paren) {
930
+ // () [] no inner space in empty parens like these, ever, ref #320
931
+ output.trim();
932
+ output.space_before_token = false;
933
+ } else {
934
+ output.space_before_token = true;
935
+ }
936
+ }
937
+ if (current_token.text === ']' && opt.keep_array_indentation) {
938
+ print_token();
939
+ restore_mode();
940
+ } else {
941
+ restore_mode();
942
+ print_token();
943
+ }
944
+ remove_redundant_indentation(output, previous_flags);
945
+
946
+ // do {} while () // no statement required after
947
+ if (flags.do_while && previous_flags.mode === MODE.Conditional) {
948
+ previous_flags.mode = MODE.Expression;
949
+ flags.do_block = false;
950
+ flags.do_while = false;
951
+
952
+ }
953
+ }
954
+
955
+ function handle_start_block() {
956
+ handle_whitespace_and_comments(current_token);
957
+
958
+ // Check if this is should be treated as a ObjectLiteral
959
+ var next_token = get_token(1);
960
+ var second_token = get_token(2);
961
+ if (second_token && (
962
+ (in_array(second_token.text, [':', ',']) && in_array(next_token.type, ['TK_STRING', 'TK_WORD', 'TK_RESERVED'])) ||
963
+ (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, ['TK_WORD', 'TK_RESERVED']))
964
+ )) {
965
+ // We don't support TypeScript,but we didn't break it for a very long time.
966
+ // We'll try to keep not breaking it.
967
+ if (!in_array(last_last_text, ['class', 'interface'])) {
968
+ set_mode(MODE.ObjectLiteral);
969
+ } else {
970
+ set_mode(MODE.BlockStatement);
971
+ }
972
+ } else if (last_type === 'TK_OPERATOR' && flags.last_text === '=>') {
973
+ // arrow function: (param1, paramN) => { statements }
974
+ set_mode(MODE.BlockStatement);
975
+ } else if (in_array(last_type, ['TK_EQUALS', 'TK_START_EXPR', 'TK_COMMA', 'TK_OPERATOR']) ||
976
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['return', 'throw', 'import', 'default']))
977
+ ) {
978
+ // Detecting shorthand function syntax is difficult by scanning forward,
979
+ // so check the surrounding context.
980
+ // If the block is being returned, imported, export default, passed as arg,
981
+ // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
982
+ set_mode(MODE.ObjectLiteral);
983
+ } else {
984
+ set_mode(MODE.BlockStatement);
985
+ }
986
+
987
+ var empty_braces = !next_token.comments_before.length && next_token.text === '}';
988
+ var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
989
+ last_type === 'TK_END_EXPR';
990
+
991
+ if (opt.brace_preserve_inline) // check for inline, set inline_frame if so
992
+ {
993
+ // search forward for a newline wanted inside this block
994
+ var index = 0;
995
+ var check_token = null;
996
+ flags.inline_frame = true;
997
+ do {
998
+ index += 1;
999
+ check_token = get_token(index);
1000
+ if (check_token.wanted_newline) {
1001
+ flags.inline_frame = false;
1002
+ break;
1003
+ }
1004
+ } while (check_token.type !== 'TK_EOF' &&
1005
+ !(check_token.type === 'TK_END_BLOCK' && check_token.opened === current_token));
1006
+ }
1007
+
1008
+ if ((opt.brace_style === "expand" ||
1009
+ (opt.brace_style === "none" && current_token.wanted_newline)) &&
1010
+ !flags.inline_frame) {
1011
+ if (last_type !== 'TK_OPERATOR' &&
1012
+ (empty_anonymous_function ||
1013
+ last_type === 'TK_EQUALS' ||
1014
+ (last_type === 'TK_RESERVED' && is_special_word(flags.last_text) && flags.last_text !== 'else'))) {
1015
+ output.space_before_token = true;
1016
+ } else {
1017
+ print_newline(false, true);
1018
+ }
1019
+ } else { // collapse || inline_frame
1020
+ if (is_array(previous_flags.mode) && (last_type === 'TK_START_EXPR' || last_type === 'TK_COMMA')) {
1021
+ if (last_type === 'TK_COMMA' || opt.space_in_paren) {
1022
+ output.space_before_token = true;
1023
+ }
1024
+
1025
+ if (last_type === 'TK_COMMA' || (last_type === 'TK_START_EXPR' && flags.inline_frame)) {
1026
+ allow_wrap_or_preserved_newline();
1027
+ previous_flags.multiline_frame = previous_flags.multiline_frame || flags.multiline_frame;
1028
+ flags.multiline_frame = false;
1029
+ }
1030
+ }
1031
+ if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
1032
+ if (last_type === 'TK_START_BLOCK' && !flags.inline_frame) {
1033
+ print_newline();
1034
+ } else {
1035
+ output.space_before_token = true;
1036
+ }
1037
+ }
1038
+ }
1039
+ print_token();
1040
+ indent();
1041
+ }
1042
+
1043
+ function handle_end_block() {
1044
+ // statements must all be closed when their container closes
1045
+ handle_whitespace_and_comments(current_token);
1046
+
1047
+ while (flags.mode === MODE.Statement) {
1048
+ restore_mode();
1049
+ }
1050
+
1051
+ var empty_braces = last_type === 'TK_START_BLOCK';
1052
+
1053
+ if (flags.inline_frame && !empty_braces) { // try inline_frame (only set if opt.braces-preserve-inline) first
1054
+ output.space_before_token = true;
1055
+ } else if (opt.brace_style === "expand") {
1056
+ if (!empty_braces) {
1057
+ print_newline();
1058
+ }
1059
+ } else {
1060
+ // skip {}
1061
+ if (!empty_braces) {
1062
+ if (is_array(flags.mode) && opt.keep_array_indentation) {
1063
+ // we REALLY need a newline here, but newliner would skip that
1064
+ opt.keep_array_indentation = false;
1065
+ print_newline();
1066
+ opt.keep_array_indentation = true;
1067
+
1068
+ } else {
1069
+ print_newline();
1070
+ }
1071
+ }
1072
+ }
1073
+ restore_mode();
1074
+ print_token();
1075
+ }
1076
+
1077
+ function handle_word() {
1078
+ if (current_token.type === 'TK_RESERVED') {
1079
+ if (in_array(current_token.text, ['set', 'get']) && flags.mode !== MODE.ObjectLiteral) {
1080
+ current_token.type = 'TK_WORD';
1081
+ } else if (in_array(current_token.text, ['as', 'from']) && !flags.import_block) {
1082
+ current_token.type = 'TK_WORD';
1083
+ } else if (flags.mode === MODE.ObjectLiteral) {
1084
+ var next_token = get_token(1);
1085
+ if (next_token.text === ':') {
1086
+ current_token.type = 'TK_WORD';
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ if (start_of_statement()) {
1092
+ // The conditional starts the statement if appropriate.
1093
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') {
1094
+ flags.declaration_statement = true;
1095
+ }
1096
+ } else if (current_token.wanted_newline && !is_expression(flags.mode) &&
1097
+ (last_type !== 'TK_OPERATOR' || (flags.last_text === '--' || flags.last_text === '++')) &&
1098
+ last_type !== 'TK_EQUALS' &&
1099
+ (opt.preserve_newlines || !(last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const', 'set', 'get'])))) {
1100
+ handle_whitespace_and_comments(current_token);
1101
+ print_newline();
1102
+ } else {
1103
+ handle_whitespace_and_comments(current_token);
1104
+ }
1105
+
1106
+ if (flags.do_block && !flags.do_while) {
1107
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'while') {
1108
+ // do {} ## while ()
1109
+ output.space_before_token = true;
1110
+ print_token();
1111
+ output.space_before_token = true;
1112
+ flags.do_while = true;
1113
+ return;
1114
+ } else {
1115
+ // do {} should always have while as the next word.
1116
+ // if we don't see the expected while, recover
1117
+ print_newline();
1118
+ flags.do_block = false;
1119
+ }
1120
+ }
1121
+
1122
+ // if may be followed by else, or not
1123
+ // Bare/inline ifs are tricky
1124
+ // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
1125
+ if (flags.if_block) {
1126
+ if (!flags.else_block && (current_token.type === 'TK_RESERVED' && current_token.text === 'else')) {
1127
+ flags.else_block = true;
1128
+ } else {
1129
+ while (flags.mode === MODE.Statement) {
1130
+ restore_mode();
1131
+ }
1132
+ flags.if_block = false;
1133
+ flags.else_block = false;
1134
+ }
1135
+ }
1136
+
1137
+ if (current_token.type === 'TK_RESERVED' && (current_token.text === 'case' || (current_token.text === 'default' && flags.in_case_statement))) {
1138
+ print_newline();
1139
+ if (flags.case_body || opt.jslint_happy) {
1140
+ // switch cases following one another
1141
+ deindent();
1142
+ flags.case_body = false;
1143
+ }
1144
+ print_token();
1145
+ flags.in_case = true;
1146
+ flags.in_case_statement = true;
1147
+ return;
1148
+ }
1149
+
1150
+ if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1151
+ if (!start_of_object_property()) {
1152
+ allow_wrap_or_preserved_newline();
1153
+ }
1154
+ }
1155
+
1156
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'function') {
1157
+ if (in_array(flags.last_text, ['}', ';']) ||
1158
+ (output.just_added_newline() && !(in_array(flags.last_text, ['(', '[', '{', ':', '=', ',']) || last_type === 'TK_OPERATOR'))) {
1159
+ // make sure there is a nice clean space of at least one blank line
1160
+ // before a new function definition
1161
+ if (!output.just_added_blankline() && !current_token.comments_before.length) {
1162
+ print_newline();
1163
+ print_newline(true);
1164
+ }
1165
+ }
1166
+ if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
1167
+ if (last_type === 'TK_RESERVED' && (
1168
+ in_array(flags.last_text, ['get', 'set', 'new', 'export', 'async']) ||
1169
+ in_array(flags.last_text, newline_restricted_tokens))) {
1170
+ output.space_before_token = true;
1171
+ } else if (last_type === 'TK_RESERVED' && flags.last_text === 'default' && last_last_text === 'export') {
1172
+ output.space_before_token = true;
1173
+ } else {
1174
+ print_newline();
1175
+ }
1176
+ } else if (last_type === 'TK_OPERATOR' || flags.last_text === '=') {
1177
+ // foo = function
1178
+ output.space_before_token = true;
1179
+ } else if (!flags.multiline_frame && (is_expression(flags.mode) || is_array(flags.mode))) {
1180
+ // (function
1181
+ } else {
1182
+ print_newline();
1183
+ }
1184
+
1185
+ print_token();
1186
+ flags.last_word = current_token.text;
1187
+ return;
1188
+ }
1189
+
1190
+ prefix = 'NONE';
1191
+
1192
+ if (last_type === 'TK_END_BLOCK') {
1193
+
1194
+ if (previous_flags.inline_frame) {
1195
+ prefix = 'SPACE';
1196
+ } else if (!(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally', 'from']))) {
1197
+ prefix = 'NEWLINE';
1198
+ } else {
1199
+ if (opt.brace_style === "expand" ||
1200
+ opt.brace_style === "end-expand" ||
1201
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
1202
+ prefix = 'NEWLINE';
1203
+ } else {
1204
+ prefix = 'SPACE';
1205
+ output.space_before_token = true;
1206
+ }
1207
+ }
1208
+ } else if (last_type === 'TK_SEMICOLON' && flags.mode === MODE.BlockStatement) {
1209
+ // TODO: Should this be for STATEMENT as well?
1210
+ prefix = 'NEWLINE';
1211
+ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
1212
+ prefix = 'SPACE';
1213
+ } else if (last_type === 'TK_STRING') {
1214
+ prefix = 'NEWLINE';
1215
+ } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' ||
1216
+ (flags.last_text === '*' &&
1217
+ (in_array(last_last_text, ['function', 'yield']) ||
1218
+ (flags.mode === MODE.ObjectLiteral && in_array(last_last_text, ['{', ',']))))) {
1219
+ prefix = 'SPACE';
1220
+ } else if (last_type === 'TK_START_BLOCK') {
1221
+ if (flags.inline_frame) {
1222
+ prefix = 'SPACE';
1223
+ } else {
1224
+ prefix = 'NEWLINE';
1225
+ }
1226
+ } else if (last_type === 'TK_END_EXPR') {
1227
+ output.space_before_token = true;
1228
+ prefix = 'NEWLINE';
1229
+ }
1230
+
1231
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, tokenizer.line_starters) && flags.last_text !== ')') {
1232
+ if (flags.inline_frame || flags.last_text === 'else' || flags.last_text === 'export') {
1233
+ prefix = 'SPACE';
1234
+ } else {
1235
+ prefix = 'NEWLINE';
1236
+ }
1237
+
1238
+ }
1239
+
1240
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally'])) {
1241
+ if ((!(last_type === 'TK_END_BLOCK' && previous_flags.mode === MODE.BlockStatement) ||
1242
+ opt.brace_style === "expand" ||
1243
+ opt.brace_style === "end-expand" ||
1244
+ (opt.brace_style === "none" && current_token.wanted_newline)) &&
1245
+ !flags.inline_frame) {
1246
+ print_newline();
1247
+ } else {
1248
+ output.trim(true);
1249
+ var line = output.current_line;
1250
+ // If we trimmed and there's something other than a close block before us
1251
+ // put a newline back in. Handles '} // comment' scenario.
1252
+ if (line.last() !== '}') {
1253
+ print_newline();
1254
+ }
1255
+ output.space_before_token = true;
1256
+ }
1257
+ } else if (prefix === 'NEWLINE') {
1258
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
1259
+ // no newline between 'return nnn'
1260
+ output.space_before_token = true;
1261
+ } else if (last_type !== 'TK_END_EXPR') {
1262
+ if ((last_type !== 'TK_START_EXPR' || !(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['var', 'let', 'const']))) && flags.last_text !== ':') {
1263
+ // no need to force newline on 'var': for (var x = 0...)
1264
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'if' && flags.last_text === 'else') {
1265
+ // no newline for } else if {
1266
+ output.space_before_token = true;
1267
+ } else {
1268
+ print_newline();
1269
+ }
1270
+ }
1271
+ } else if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, tokenizer.line_starters) && flags.last_text !== ')') {
1272
+ print_newline();
1273
+ }
1274
+ } else if (flags.multiline_frame && is_array(flags.mode) && flags.last_text === ',' && last_last_text === '}') {
1275
+ print_newline(); // }, in lists get a newline treatment
1276
+ } else if (prefix === 'SPACE') {
1277
+ output.space_before_token = true;
1278
+ }
1279
+ print_token();
1280
+ flags.last_word = current_token.text;
1281
+
1282
+ if (current_token.type === 'TK_RESERVED') {
1283
+ if (current_token.text === 'do') {
1284
+ flags.do_block = true;
1285
+ } else if (current_token.text === 'if') {
1286
+ flags.if_block = true;
1287
+ } else if (current_token.text === 'import') {
1288
+ flags.import_block = true;
1289
+ } else if (flags.import_block && current_token.type === 'TK_RESERVED' && current_token.text === 'from') {
1290
+ flags.import_block = false;
1291
+ }
1292
+ }
1293
+ }
1294
+
1295
+ function handle_semicolon() {
1296
+ if (start_of_statement()) {
1297
+ // The conditional starts the statement if appropriate.
1298
+ // Semicolon can be the start (and end) of a statement
1299
+ output.space_before_token = false;
1300
+ } else {
1301
+ handle_whitespace_and_comments(current_token);
1302
+ }
1303
+
1304
+ var next_token = get_token(1);
1305
+ while (flags.mode === MODE.Statement &&
1306
+ !(flags.if_block && next_token && next_token.type === 'TK_RESERVED' && next_token.text === 'else') &&
1307
+ !flags.do_block) {
1308
+ restore_mode();
1309
+ }
1310
+
1311
+ // hacky but effective for the moment
1312
+ if (flags.import_block) {
1313
+ flags.import_block = false;
1314
+ }
1315
+ print_token();
1316
+ }
1317
+
1318
+ function handle_string() {
1319
+ if (start_of_statement()) {
1320
+ // The conditional starts the statement if appropriate.
1321
+ // One difference - strings want at least a space before
1322
+ output.space_before_token = true;
1323
+ } else {
1324
+ handle_whitespace_and_comments(current_token);
1325
+ if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' || flags.inline_frame) {
1326
+ output.space_before_token = true;
1327
+ } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1328
+ if (!start_of_object_property()) {
1329
+ allow_wrap_or_preserved_newline();
1330
+ }
1331
+ } else {
1332
+ print_newline();
1333
+ }
1334
+ }
1335
+ print_token();
1336
+ }
1337
+
1338
+ function handle_equals() {
1339
+ if (start_of_statement()) {
1340
+ // The conditional starts the statement if appropriate.
1341
+ } else {
1342
+ handle_whitespace_and_comments(current_token);
1343
+ }
1344
+
1345
+ if (flags.declaration_statement) {
1346
+ // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
1347
+ flags.declaration_assignment = true;
1348
+ }
1349
+ output.space_before_token = true;
1350
+ print_token();
1351
+ output.space_before_token = true;
1352
+ }
1353
+
1354
+ function handle_comma() {
1355
+ handle_whitespace_and_comments(current_token, true);
1356
+
1357
+ print_token();
1358
+ output.space_before_token = true;
1359
+ if (flags.declaration_statement) {
1360
+ if (is_expression(flags.parent.mode)) {
1361
+ // do not break on comma, for(var a = 1, b = 2)
1362
+ flags.declaration_assignment = false;
1363
+ }
1364
+
1365
+ if (flags.declaration_assignment) {
1366
+ flags.declaration_assignment = false;
1367
+ print_newline(false, true);
1368
+ } else if (opt.comma_first) {
1369
+ // for comma-first, we want to allow a newline before the comma
1370
+ // to turn into a newline after the comma, which we will fixup later
1371
+ allow_wrap_or_preserved_newline();
1372
+ }
1373
+ } else if (flags.mode === MODE.ObjectLiteral ||
1374
+ (flags.mode === MODE.Statement && flags.parent.mode === MODE.ObjectLiteral)) {
1375
+ if (flags.mode === MODE.Statement) {
1376
+ restore_mode();
1377
+ }
1378
+
1379
+ if (!flags.inline_frame) {
1380
+ print_newline();
1381
+ }
1382
+ } else if (opt.comma_first) {
1383
+ // EXPR or DO_BLOCK
1384
+ // for comma-first, we want to allow a newline before the comma
1385
+ // to turn into a newline after the comma, which we will fixup later
1386
+ allow_wrap_or_preserved_newline();
1387
+ }
1388
+ }
1389
+
1390
+ function handle_operator() {
1391
+ var isGeneratorAsterisk = current_token.text === '*' &&
1392
+ ((last_type === 'TK_RESERVED' && in_array(flags.last_text, ['function', 'yield'])) ||
1393
+ (in_array(last_type, ['TK_START_BLOCK', 'TK_COMMA', 'TK_END_BLOCK', 'TK_SEMICOLON']))
1394
+ );
1395
+ var isUnary = in_array(current_token.text, ['-', '+']) && (
1396
+ in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) ||
1397
+ in_array(flags.last_text, tokenizer.line_starters) ||
1398
+ flags.last_text === ','
1399
+ );
1400
+
1401
+ if (start_of_statement()) {
1402
+ // The conditional starts the statement if appropriate.
1403
+ } else {
1404
+ var preserve_statement_flags = !isGeneratorAsterisk;
1405
+ handle_whitespace_and_comments(current_token, preserve_statement_flags);
1406
+ }
1407
+
1408
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
1409
+ // "return" had a special handling in TK_WORD. Now we need to return the favor
1410
+ output.space_before_token = true;
1411
+ print_token();
1412
+ return;
1413
+ }
1414
+
1415
+ // hack for actionscript's import .*;
1416
+ if (current_token.text === '*' && last_type === 'TK_DOT') {
1417
+ print_token();
1418
+ return;
1419
+ }
1420
+
1421
+ if (current_token.text === '::') {
1422
+ // no spaces around exotic namespacing syntax operator
1423
+ print_token();
1424
+ return;
1425
+ }
1426
+
1427
+ // Allow line wrapping between operators when operator_position is
1428
+ // set to before or preserve
1429
+ if (last_type === 'TK_OPERATOR' && in_array(opt.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
1430
+ allow_wrap_or_preserved_newline();
1431
+ }
1432
+
1433
+ if (current_token.text === ':' && flags.in_case) {
1434
+ flags.case_body = true;
1435
+ indent();
1436
+ print_token();
1437
+ print_newline();
1438
+ flags.in_case = false;
1439
+ return;
1440
+ }
1441
+
1442
+ var space_before = true;
1443
+ var space_after = true;
1444
+ var in_ternary = false;
1445
+ if (current_token.text === ':') {
1446
+ if (flags.ternary_depth === 0) {
1447
+ // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
1448
+ space_before = false;
1449
+ } else {
1450
+ flags.ternary_depth -= 1;
1451
+ in_ternary = true;
1452
+ }
1453
+ } else if (current_token.text === '?') {
1454
+ flags.ternary_depth += 1;
1455
+ }
1456
+
1457
+ // let's handle the operator_position option prior to any conflicting logic
1458
+ if (!isUnary && !isGeneratorAsterisk && opt.preserve_newlines && in_array(current_token.text, tokenizer.positionable_operators)) {
1459
+ var isColon = current_token.text === ':';
1460
+ var isTernaryColon = (isColon && in_ternary);
1461
+ var isOtherColon = (isColon && !in_ternary);
1462
+
1463
+ switch (opt.operator_position) {
1464
+ case OPERATOR_POSITION.before_newline:
1465
+ // if the current token is : and it's not a ternary statement then we set space_before to false
1466
+ output.space_before_token = !isOtherColon;
1467
+
1468
+ print_token();
1469
+
1470
+ if (!isColon || isTernaryColon) {
1471
+ allow_wrap_or_preserved_newline();
1472
+ }
1473
+
1474
+ output.space_before_token = true;
1475
+ return;
1476
+
1477
+ case OPERATOR_POSITION.after_newline:
1478
+ // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
1479
+ // then print a newline.
1480
+
1481
+ output.space_before_token = true;
1482
+
1483
+ if (!isColon || isTernaryColon) {
1484
+ if (get_token(1).wanted_newline) {
1485
+ print_newline(false, true);
1486
+ } else {
1487
+ allow_wrap_or_preserved_newline();
1488
+ }
1489
+ } else {
1490
+ output.space_before_token = false;
1491
+ }
1492
+
1493
+ print_token();
1494
+
1495
+ output.space_before_token = true;
1496
+ return;
1497
+
1498
+ case OPERATOR_POSITION.preserve_newline:
1499
+ if (!isOtherColon) {
1500
+ allow_wrap_or_preserved_newline();
1501
+ }
1502
+
1503
+ // if we just added a newline, or the current token is : and it's not a ternary statement,
1504
+ // then we set space_before to false
1505
+ space_before = !(output.just_added_newline() || isOtherColon);
1506
+
1507
+ output.space_before_token = space_before;
1508
+ print_token();
1509
+ output.space_before_token = true;
1510
+ return;
1511
+ }
1512
+ }
1513
+
1514
+ if (isGeneratorAsterisk) {
1515
+ allow_wrap_or_preserved_newline();
1516
+ space_before = false;
1517
+ var next_token = get_token(1);
1518
+ space_after = next_token && in_array(next_token.type, ['TK_WORD', 'TK_RESERVED']);
1519
+ } else if (current_token.text === '...') {
1520
+ allow_wrap_or_preserved_newline();
1521
+ space_before = last_type === 'TK_START_BLOCK';
1522
+ space_after = false;
1523
+ } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
1524
+ // unary operators (and binary +/- pretending to be unary) special cases
1525
+
1526
+ space_before = false;
1527
+ space_after = false;
1528
+
1529
+ // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
1530
+ // if there is a newline between -- or ++ and anything else we should preserve it.
1531
+ if (current_token.wanted_newline && (current_token.text === '--' || current_token.text === '++')) {
1532
+ print_newline(false, true);
1533
+ }
1534
+
1535
+ if (flags.last_text === ';' && is_expression(flags.mode)) {
1536
+ // for (;; ++i)
1537
+ // ^^^
1538
+ space_before = true;
1539
+ }
1540
+
1541
+ if (last_type === 'TK_RESERVED') {
1542
+ space_before = true;
1543
+ } else if (last_type === 'TK_END_EXPR') {
1544
+ space_before = !(flags.last_text === ']' && (current_token.text === '--' || current_token.text === '++'));
1545
+ } else if (last_type === 'TK_OPERATOR') {
1546
+ // a++ + ++b;
1547
+ // a - -b
1548
+ space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(flags.last_text, ['--', '-', '++', '+']);
1549
+ // + and - are not unary when preceeded by -- or ++ operator
1550
+ // a-- + b
1551
+ // a * +b
1552
+ // a - -b
1553
+ if (in_array(current_token.text, ['+', '-']) && in_array(flags.last_text, ['--', '++'])) {
1554
+ space_after = true;
1555
+ }
1556
+ }
1557
+
1558
+
1559
+ if (((flags.mode === MODE.BlockStatement && !flags.inline_frame) || flags.mode === MODE.Statement) &&
1560
+ (flags.last_text === '{' || flags.last_text === ';')) {
1561
+ // { foo; --i }
1562
+ // foo(); --bar;
1563
+ print_newline();
1564
+ }
1565
+ }
1566
+
1567
+ output.space_before_token = output.space_before_token || space_before;
1568
+ print_token();
1569
+ output.space_before_token = space_after;
1570
+ }
1571
+
1572
+ function handle_block_comment(preserve_statement_flags) {
1573
+ if (output.raw) {
1574
+ output.add_raw_token(current_token);
1575
+ if (current_token.directives && current_token.directives.preserve === 'end') {
1576
+ // If we're testing the raw output behavior, do not allow a directive to turn it off.
1577
+ output.raw = opt.test_output_raw;
1578
+ }
1579
+ return;
1580
+ }
1581
+
1582
+ if (current_token.directives) {
1583
+ print_newline(false, preserve_statement_flags);
1584
+ print_token();
1585
+ if (current_token.directives.preserve === 'start') {
1586
+ output.raw = true;
1587
+ }
1588
+ print_newline(false, true);
1589
+ return;
1590
+ }
1591
+
1592
+ // inline block
1593
+ if (!acorn.newline.test(current_token.text) && !current_token.wanted_newline) {
1594
+ output.space_before_token = true;
1595
+ print_token();
1596
+ output.space_before_token = true;
1597
+ return;
1598
+ }
1599
+
1600
+ var lines = split_linebreaks(current_token.text);
1601
+ var j; // iterator for this case
1602
+ var javadoc = false;
1603
+ var starless = false;
1604
+ var lastIndent = current_token.whitespace_before;
1605
+ var lastIndentLength = lastIndent.length;
1606
+
1607
+ // block comment starts with a new line
1608
+ print_newline(false, preserve_statement_flags);
1609
+ if (lines.length > 1) {
1610
+ javadoc = all_lines_start_with(lines.slice(1), '*');
1611
+ starless = each_line_matches_indent(lines.slice(1), lastIndent);
1612
+ }
1613
+
1614
+ // first line always indented
1615
+ print_token(lines[0]);
1616
+ for (j = 1; j < lines.length; j++) {
1617
+ print_newline(false, true);
1618
+ if (javadoc) {
1619
+ // javadoc: reformat and re-indent
1620
+ print_token(' ' + ltrim(lines[j]));
1621
+ } else if (starless && lines[j].length > lastIndentLength) {
1622
+ // starless: re-indent non-empty content, avoiding trim
1623
+ print_token(lines[j].substring(lastIndentLength));
1624
+ } else {
1625
+ // normal comments output raw
1626
+ output.add_token(lines[j]);
1627
+ }
1628
+ }
1629
+
1630
+ // for comments of more than one line, make sure there's a new line after
1631
+ print_newline(false, preserve_statement_flags);
1632
+ }
1633
+
1634
+ function handle_comment(preserve_statement_flags) {
1635
+ if (current_token.wanted_newline) {
1636
+ print_newline(false, preserve_statement_flags);
1637
+ } else {
1638
+ output.trim(true);
1639
+ }
1640
+
1641
+ output.space_before_token = true;
1642
+ print_token();
1643
+ print_newline(false, preserve_statement_flags);
1644
+ }
1645
+
1646
+ function handle_dot() {
1647
+ if (start_of_statement()) {
1648
+ // The conditional starts the statement if appropriate.
1649
+ } else {
1650
+ handle_whitespace_and_comments(current_token, true);
1651
+ }
1652
+
1653
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
1654
+ output.space_before_token = true;
1655
+ } else {
1656
+ // allow preserved newlines before dots in general
1657
+ // force newlines on dots after close paren when break_chained - for bar().baz()
1658
+ allow_wrap_or_preserved_newline(flags.last_text === ')' && opt.break_chained_methods);
1659
+ }
1660
+
1661
+ print_token();
1662
+ }
1663
+
1664
+ function handle_unknown(preserve_statement_flags) {
1665
+ print_token();
1666
+
1667
+ if (current_token.text[current_token.text.length - 1] === '\n') {
1668
+ print_newline(false, preserve_statement_flags);
1669
+ }
1670
+ }
1671
+
1672
+ function handle_eof() {
1673
+ // Unwind any open statements
1674
+ while (flags.mode === MODE.Statement) {
1675
+ restore_mode();
1676
+ }
1677
+ handle_whitespace_and_comments(current_token);
1678
+ }
1679
+ }
1680
+
1681
+ module.exports.Beautifier = Beautifier;
1682
+
1683
+ /***/ }),
1684
+ /* 2 */
1685
+ /***/ (function(module, exports) {
1686
+
1687
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
1688
+ /*
1689
+
1690
+ The MIT License (MIT)
1691
+
1692
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
1693
+
1694
+ Permission is hereby granted, free of charge, to any person
1695
+ obtaining a copy of this software and associated documentation files
1696
+ (the "Software"), to deal in the Software without restriction,
1697
+ including without limitation the rights to use, copy, modify, merge,
1698
+ publish, distribute, sublicense, and/or sell copies of the Software,
1699
+ and to permit persons to whom the Software is furnished to do so,
1700
+ subject to the following conditions:
1701
+
1702
+ The above copyright notice and this permission notice shall be
1703
+ included in all copies or substantial portions of the Software.
1704
+
1705
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1706
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1707
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1708
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1709
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1710
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1711
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1712
+ SOFTWARE.
1713
+ */
1714
+
1715
+ function InputScanner(input) {
1716
+ var _input = input;
1717
+ var _input_length = _input.length;
1718
+ var _position = 0;
1719
+
1720
+ this.back = function() {
1721
+ _position -= 1;
1722
+ };
1723
+
1724
+ this.hasNext = function() {
1725
+ return _position < _input_length;
1726
+ };
1727
+
1728
+ this.next = function() {
1729
+ var val = null;
1730
+ if (this.hasNext()) {
1731
+ val = _input.charAt(_position);
1732
+ _position += 1;
1733
+ }
1734
+ return val;
1735
+ };
1736
+
1737
+ this.peek = function(index) {
1738
+ var val = null;
1739
+ index = index || 0;
1740
+ index += _position;
1741
+ if (index >= 0 && index < _input_length) {
1742
+ val = _input.charAt(index);
1743
+ }
1744
+ return val;
1745
+ };
1746
+
1747
+ this.peekCharCode = function(index) {
1748
+ var val = 0;
1749
+ index = index || 0;
1750
+ index += _position;
1751
+ if (index >= 0 && index < _input_length) {
1752
+ val = _input.charCodeAt(index);
1753
+ }
1754
+ return val;
1755
+ };
1756
+
1757
+ this.test = function(pattern, index) {
1758
+ index = index || 0;
1759
+ pattern.lastIndex = _position + index;
1760
+ return pattern.test(_input);
1761
+ };
1762
+
1763
+ this.testChar = function(pattern, index) {
1764
+ var val = this.peek(index);
1765
+ return val !== null && pattern.test(val);
1766
+ };
1767
+
1768
+ this.match = function(pattern) {
1769
+ pattern.lastIndex = _position;
1770
+ var pattern_match = pattern.exec(_input);
1771
+ if (pattern_match && pattern_match.index === _position) {
1772
+ _position += pattern_match[0].length;
1773
+ } else {
1774
+ pattern_match = null;
1775
+ }
1776
+ return pattern_match;
1777
+ };
1778
+ }
1779
+
1780
+
1781
+ module.exports.InputScanner = InputScanner;
1782
+
1783
+
1784
+ /***/ }),
1785
+ /* 3 */
1786
+ /***/ (function(module, exports) {
1787
+
1788
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
1789
+ /*
1790
+
1791
+ The MIT License (MIT)
1792
+
1793
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
1794
+
1795
+ Permission is hereby granted, free of charge, to any person
1796
+ obtaining a copy of this software and associated documentation files
1797
+ (the "Software"), to deal in the Software without restriction,
1798
+ including without limitation the rights to use, copy, modify, merge,
1799
+ publish, distribute, sublicense, and/or sell copies of the Software,
1800
+ and to permit persons to whom the Software is furnished to do so,
1801
+ subject to the following conditions:
1802
+
1803
+ The above copyright notice and this permission notice shall be
1804
+ included in all copies or substantial portions of the Software.
1805
+
1806
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1807
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1808
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1809
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1810
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1811
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1812
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1813
+ SOFTWARE.
1814
+ */
1815
+
1816
+ function mergeOpts(allOptions, targetType) {
1817
+ var finalOpts = {};
1818
+ var name;
1819
+
1820
+ for (name in allOptions) {
1821
+ if (name !== targetType) {
1822
+ finalOpts[name] = allOptions[name];
1823
+ }
1824
+ }
1825
+
1826
+ //merge in the per type settings for the targetType
1827
+ if (targetType in allOptions) {
1828
+ for (name in allOptions[targetType]) {
1829
+ finalOpts[name] = allOptions[targetType][name];
1830
+ }
1831
+ }
1832
+ return finalOpts;
1833
+ }
1834
+
1835
+ module.exports.mergeOpts = mergeOpts;
1836
+
1837
+
1838
+ /***/ }),
1839
+ /* 4 */
1840
+ /***/ (function(module, exports) {
1841
+
1842
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
1843
+ /*
1844
+
1845
+ The MIT License (MIT)
1846
+
1847
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
1848
+
1849
+ Permission is hereby granted, free of charge, to any person
1850
+ obtaining a copy of this software and associated documentation files
1851
+ (the "Software"), to deal in the Software without restriction,
1852
+ including without limitation the rights to use, copy, modify, merge,
1853
+ publish, distribute, sublicense, and/or sell copies of the Software,
1854
+ and to permit persons to whom the Software is furnished to do so,
1855
+ subject to the following conditions:
1856
+
1857
+ The above copyright notice and this permission notice shall be
1858
+ included in all copies or substantial portions of the Software.
1859
+
1860
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1861
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1862
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1863
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1864
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1865
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1866
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1867
+ SOFTWARE.
1868
+ */
1869
+
1870
+ function OutputLine(parent) {
1871
+ var _character_count = 0;
1872
+ // use indent_count as a marker for lines that have preserved indentation
1873
+ var _indent_count = -1;
1874
+
1875
+ var _items = [];
1876
+ var _empty = true;
1877
+
1878
+ this.set_indent = function(level) {
1879
+ _character_count = parent.baseIndentLength + level * parent.indent_length;
1880
+ _indent_count = level;
1881
+ };
1882
+
1883
+ this.get_character_count = function() {
1884
+ return _character_count;
1885
+ };
1886
+
1887
+ this.is_empty = function() {
1888
+ return _empty;
1889
+ };
1890
+
1891
+ this.last = function() {
1892
+ if (!this._empty) {
1893
+ return _items[_items.length - 1];
1894
+ } else {
1895
+ return null;
1896
+ }
1897
+ };
1898
+
1899
+ this.push = function(input) {
1900
+ _items.push(input);
1901
+ _character_count += input.length;
1902
+ _empty = false;
1903
+ };
1904
+
1905
+ this.pop = function() {
1906
+ var item = null;
1907
+ if (!_empty) {
1908
+ item = _items.pop();
1909
+ _character_count -= item.length;
1910
+ _empty = _items.length === 0;
1911
+ }
1912
+ return item;
1913
+ };
1914
+
1915
+ this.remove_indent = function() {
1916
+ if (_indent_count > 0) {
1917
+ _indent_count -= 1;
1918
+ _character_count -= parent.indent_length;
1919
+ }
1920
+ };
1921
+
1922
+ this.trim = function() {
1923
+ while (this.last() === ' ') {
1924
+ _items.pop();
1925
+ _character_count -= 1;
1926
+ }
1927
+ _empty = _items.length === 0;
1928
+ };
1929
+
1930
+ this.toString = function() {
1931
+ var result = '';
1932
+ if (!this._empty) {
1933
+ if (_indent_count >= 0) {
1934
+ result = parent.indent_cache[_indent_count];
1935
+ }
1936
+ result += _items.join('');
1937
+ }
1938
+ return result;
1939
+ };
1940
+ }
1941
+
1942
+ function Output(indent_string, baseIndentString) {
1943
+ baseIndentString = baseIndentString || '';
1944
+ this.indent_cache = [baseIndentString];
1945
+ this.baseIndentLength = baseIndentString.length;
1946
+ this.indent_length = indent_string.length;
1947
+ this.raw = false;
1948
+
1949
+ var lines = [];
1950
+ this.baseIndentString = baseIndentString;
1951
+ this.indent_string = indent_string;
1952
+ this.previous_line = null;
1953
+ this.current_line = null;
1954
+ this.space_before_token = false;
1955
+
1956
+ this.add_outputline = function() {
1957
+ this.previous_line = this.current_line;
1958
+ this.current_line = new OutputLine(this);
1959
+ lines.push(this.current_line);
1960
+ };
1961
+
1962
+ // initialize
1963
+ this.add_outputline();
1964
+
1965
+
1966
+ this.get_line_number = function() {
1967
+ return lines.length;
1968
+ };
1969
+
1970
+ // Using object instead of string to allow for later expansion of info about each line
1971
+ this.add_new_line = function(force_newline) {
1972
+ if (this.get_line_number() === 1 && this.just_added_newline()) {
1973
+ return false; // no newline on start of file
1974
+ }
1975
+
1976
+ if (force_newline || !this.just_added_newline()) {
1977
+ if (!this.raw) {
1978
+ this.add_outputline();
1979
+ }
1980
+ return true;
1981
+ }
1982
+
1983
+ return false;
1984
+ };
1985
+
1986
+ this.get_code = function(end_with_newline, eol) {
1987
+ var sweet_code = lines.join('\n').replace(/[\r\n\t ]+$/, '');
1988
+
1989
+ if (end_with_newline) {
1990
+ sweet_code += '\n';
1991
+ }
1992
+
1993
+ if (eol !== '\n') {
1994
+ sweet_code = sweet_code.replace(/[\n]/g, eol);
1995
+ }
1996
+
1997
+ return sweet_code;
1998
+ };
1999
+
2000
+ this.set_indent = function(level) {
2001
+ // Never indent your first output indent at the start of the file
2002
+ if (lines.length > 1) {
2003
+ while (level >= this.indent_cache.length) {
2004
+ this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);
2005
+ }
2006
+
2007
+ this.current_line.set_indent(level);
2008
+ return true;
2009
+ }
2010
+ this.current_line.set_indent(0);
2011
+ return false;
2012
+ };
2013
+
2014
+ this.add_raw_token = function(token) {
2015
+ for (var x = 0; x < token.newlines; x++) {
2016
+ this.add_outputline();
2017
+ }
2018
+ this.current_line.push(token.whitespace_before);
2019
+ this.current_line.push(token.text);
2020
+ this.space_before_token = false;
2021
+ };
2022
+
2023
+ this.add_token = function(printable_token) {
2024
+ this.add_space_before_token();
2025
+ this.current_line.push(printable_token);
2026
+ };
2027
+
2028
+ this.add_space_before_token = function() {
2029
+ if (this.space_before_token && !this.just_added_newline()) {
2030
+ this.current_line.push(' ');
2031
+ }
2032
+ this.space_before_token = false;
2033
+ };
2034
+
2035
+ this.remove_indent = function(index) {
2036
+ var output_length = lines.length;
2037
+ while (index < output_length) {
2038
+ lines[index].remove_indent();
2039
+ index++;
2040
+ }
2041
+ };
2042
+
2043
+ this.trim = function(eat_newlines) {
2044
+ eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
2045
+
2046
+ this.current_line.trim(indent_string, baseIndentString);
2047
+
2048
+ while (eat_newlines && lines.length > 1 &&
2049
+ this.current_line.is_empty()) {
2050
+ lines.pop();
2051
+ this.current_line = lines[lines.length - 1];
2052
+ this.current_line.trim();
2053
+ }
2054
+
2055
+ this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;
2056
+ };
2057
+
2058
+ this.just_added_newline = function() {
2059
+ return this.current_line.is_empty();
2060
+ };
2061
+
2062
+ this.just_added_blankline = function() {
2063
+ if (this.just_added_newline()) {
2064
+ if (lines.length === 1) {
2065
+ return true; // start of the file and newline = blank
2066
+ }
2067
+
2068
+ var line = lines[lines.length - 2];
2069
+ return line.is_empty();
2070
+ }
2071
+ return false;
2072
+ };
2073
+ }
2074
+
2075
+ module.exports.Output = Output;
2076
+
2077
+
2078
+ /***/ }),
2079
+ /* 5 */
2080
+ /***/ (function(module, exports) {
2081
+
2082
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2083
+ /*
2084
+
2085
+ The MIT License (MIT)
2086
+
2087
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
2088
+
2089
+ Permission is hereby granted, free of charge, to any person
2090
+ obtaining a copy of this software and associated documentation files
2091
+ (the "Software"), to deal in the Software without restriction,
2092
+ including without limitation the rights to use, copy, modify, merge,
2093
+ publish, distribute, sublicense, and/or sell copies of the Software,
2094
+ and to permit persons to whom the Software is furnished to do so,
2095
+ subject to the following conditions:
2096
+
2097
+ The above copyright notice and this permission notice shall be
2098
+ included in all copies or substantial portions of the Software.
2099
+
2100
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2101
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2102
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2103
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2104
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2105
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2106
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2107
+ SOFTWARE.
2108
+ */
2109
+
2110
+ function Token(type, text, newlines, whitespace_before, parent) {
2111
+ this.type = type;
2112
+ this.text = text;
2113
+
2114
+ // comments_before are
2115
+ // comments that have a new line before them
2116
+ // and may or may not have a newline after
2117
+ // this is a set of comments before
2118
+ this.comments_before = /* inline comment*/ [];
2119
+
2120
+
2121
+ this.comments_after = []; // no new line before and newline after
2122
+ this.newlines = newlines || 0;
2123
+ this.wanted_newline = newlines > 0;
2124
+ this.whitespace_before = whitespace_before || '';
2125
+ this.parent = parent || null;
2126
+ this.opened = null;
2127
+ this.directives = null;
2128
+ }
2129
+
2130
+ module.exports.Token = Token;
2131
+
2132
+
2133
+ /***/ }),
2134
+ /* 6 */
2135
+ /***/ (function(module, exports, __webpack_require__) {
2136
+
2137
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2138
+ /*
2139
+
2140
+ The MIT License (MIT)
2141
+
2142
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
2143
+
2144
+ Permission is hereby granted, free of charge, to any person
2145
+ obtaining a copy of this software and associated documentation files
2146
+ (the "Software"), to deal in the Software without restriction,
2147
+ including without limitation the rights to use, copy, modify, merge,
2148
+ publish, distribute, sublicense, and/or sell copies of the Software,
2149
+ and to permit persons to whom the Software is furnished to do so,
2150
+ subject to the following conditions:
2151
+
2152
+ The above copyright notice and this permission notice shall be
2153
+ included in all copies or substantial portions of the Software.
2154
+
2155
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2156
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2157
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2158
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2159
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2160
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2161
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2162
+ SOFTWARE.
2163
+ */
2164
+
2165
+ var Beautifier = __webpack_require__(1).Beautifier;
2166
+
2167
+ function js_beautify(js_source_text, options) {
2168
+ var beautifier = new Beautifier(js_source_text, options);
2169
+ return beautifier.beautify();
2170
+ }
2171
+
2172
+ module.exports = js_beautify;
2173
+
2174
+ /***/ }),
2175
+ /* 7 */
2176
+ /***/ (function(module, exports, __webpack_require__) {
2177
+
2178
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2179
+ /*
2180
+
2181
+ The MIT License (MIT)
2182
+
2183
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
2184
+
2185
+ Permission is hereby granted, free of charge, to any person
2186
+ obtaining a copy of this software and associated documentation files
2187
+ (the "Software"), to deal in the Software without restriction,
2188
+ including without limitation the rights to use, copy, modify, merge,
2189
+ publish, distribute, sublicense, and/or sell copies of the Software,
2190
+ and to permit persons to whom the Software is furnished to do so,
2191
+ subject to the following conditions:
2192
+
2193
+ The above copyright notice and this permission notice shall be
2194
+ included in all copies or substantial portions of the Software.
2195
+
2196
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2197
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2198
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2199
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2200
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2201
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2202
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2203
+ SOFTWARE.
2204
+ */
2205
+
2206
+ var InputScanner = __webpack_require__(2).InputScanner;
2207
+ var Token = __webpack_require__(5).Token;
2208
+ var acorn = __webpack_require__(0);
2209
+
2210
+ function trim(s) {
2211
+ return s.replace(/^\s+|\s+$/g, '');
2212
+ }
2213
+
2214
+ function in_array(what, arr) {
2215
+ for (var i = 0; i < arr.length; i += 1) {
2216
+ if (arr[i] === what) {
2217
+ return true;
2218
+ }
2219
+ }
2220
+ return false;
2221
+ }
2222
+
2223
+ function Tokenizer(input_string, opts) {
2224
+
2225
+ var whitespace = "\n\r\t ".split('');
2226
+ var digit = /[0-9]/;
2227
+ var digit_bin = /[01]/;
2228
+ var digit_oct = /[01234567]/;
2229
+ var digit_hex = /[0123456789abcdefABCDEF]/;
2230
+
2231
+ this.positionable_operators = '!= !== % & && * ** + - / : < << <= == === > >= >> >>> ? ^ | ||'.split(' ');
2232
+ var punct = this.positionable_operators.concat(
2233
+ // non-positionable operators - these do not follow operator position settings
2234
+ '! %= &= *= **= ++ += , -- -= /= :: <<= = => >>= >>>= ^= |= ~ ...'.split(' '));
2235
+
2236
+ // words which should always start on new line.
2237
+ this.line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
2238
+ var reserved_words = this.line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as']);
2239
+
2240
+ // /* ... */ comment ends with nearest */ or end of file
2241
+ var block_comment_pattern = /([\s\S]*?)((?:\*\/)|$)/g;
2242
+
2243
+ // comment ends just before nearest linefeed or end of file
2244
+ var comment_pattern = /([^\n\r\u2028\u2029]*)/g;
2245
+
2246
+ var directives_block_pattern = /\/\* beautify( \w+[:]\w+)+ \*\//g;
2247
+ var directive_pattern = / (\w+)[:](\w+)/g;
2248
+ var directives_end_ignore_pattern = /([\s\S]*?)((?:\/\*\sbeautify\signore:end\s\*\/)|$)/g;
2249
+
2250
+ var template_pattern = /((<\?php|<\?=)[\s\S]*?\?>)|(<%[\s\S]*?%>)/g;
2251
+
2252
+ var n_newlines, whitespace_before_token, in_html_comment, tokens;
2253
+ var input;
2254
+
2255
+ this.tokenize = function() {
2256
+ input = new InputScanner(input_string);
2257
+ in_html_comment = false;
2258
+ tokens = [];
2259
+
2260
+ var next, last;
2261
+ var token_values;
2262
+ var open = null;
2263
+ var open_stack = [];
2264
+ var comments = [];
2265
+
2266
+ while (!(last && last.type === 'TK_EOF')) {
2267
+ token_values = tokenize_next();
2268
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
2269
+ while (next.type === 'TK_COMMENT' || next.type === 'TK_BLOCK_COMMENT' || next.type === 'TK_UNKNOWN') {
2270
+ if (next.type === 'TK_BLOCK_COMMENT') {
2271
+ next.directives = token_values[2];
2272
+ }
2273
+ comments.push(next);
2274
+ token_values = tokenize_next();
2275
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
2276
+ }
2277
+
2278
+ if (comments.length) {
2279
+ next.comments_before = comments;
2280
+ comments = [];
2281
+ }
2282
+
2283
+ if (next.type === 'TK_START_BLOCK' || next.type === 'TK_START_EXPR') {
2284
+ next.parent = last;
2285
+ open_stack.push(open);
2286
+ open = next;
2287
+ } else if ((next.type === 'TK_END_BLOCK' || next.type === 'TK_END_EXPR') &&
2288
+ (open && (
2289
+ (next.text === ']' && open.text === '[') ||
2290
+ (next.text === ')' && open.text === '(') ||
2291
+ (next.text === '}' && open.text === '{')))) {
2292
+ next.parent = open.parent;
2293
+ next.opened = open;
2294
+
2295
+ open = open_stack.pop();
2296
+ }
2297
+
2298
+ tokens.push(next);
2299
+ last = next;
2300
+ }
2301
+
2302
+ return tokens;
2303
+ };
2304
+
2305
+ function get_directives(text) {
2306
+ if (!text.match(directives_block_pattern)) {
2307
+ return null;
2308
+ }
2309
+
2310
+ var directives = {};
2311
+ directive_pattern.lastIndex = 0;
2312
+ var directive_match = directive_pattern.exec(text);
2313
+
2314
+ while (directive_match) {
2315
+ directives[directive_match[1]] = directive_match[2];
2316
+ directive_match = directive_pattern.exec(text);
2317
+ }
2318
+
2319
+ return directives;
2320
+ }
2321
+
2322
+ function tokenize_next() {
2323
+ var resulting_string;
2324
+ var whitespace_on_this_line = [];
2325
+
2326
+ n_newlines = 0;
2327
+ whitespace_before_token = '';
2328
+
2329
+ var c = input.next();
2330
+
2331
+ if (c === null) {
2332
+ return ['', 'TK_EOF'];
2333
+ }
2334
+
2335
+ var last_token;
2336
+ if (tokens.length) {
2337
+ last_token = tokens[tokens.length - 1];
2338
+ } else {
2339
+ // For the sake of tokenizing we can pretend that there was on open brace to start
2340
+ last_token = new Token('TK_START_BLOCK', '{');
2341
+ }
2342
+
2343
+ while (in_array(c, whitespace)) {
2344
+
2345
+ if (acorn.newline.test(c)) {
2346
+ if (!(c === '\n' && input.peek(-2) === '\r')) {
2347
+ n_newlines += 1;
2348
+ whitespace_on_this_line = [];
2349
+ }
2350
+ } else {
2351
+ whitespace_on_this_line.push(c);
2352
+ }
2353
+
2354
+ c = input.next();
2355
+
2356
+ if (c === null) {
2357
+ return ['', 'TK_EOF'];
2358
+ }
2359
+ }
2360
+
2361
+ if (whitespace_on_this_line.length) {
2362
+ whitespace_before_token = whitespace_on_this_line.join('');
2363
+ }
2364
+
2365
+ if (digit.test(c) || (c === '.' && input.testChar(digit))) {
2366
+ var allow_decimal = true;
2367
+ var allow_e = true;
2368
+ var local_digit = digit;
2369
+
2370
+ if (c === '0' && input.testChar(/[XxOoBb]/)) {
2371
+ // switch to hex/oct/bin number, no decimal or e, just hex/oct/bin digits
2372
+ allow_decimal = false;
2373
+ allow_e = false;
2374
+ if (input.testChar(/[Bb]/)) {
2375
+ local_digit = digit_bin;
2376
+ } else if (input.testChar(/[Oo]/)) {
2377
+ local_digit = digit_oct;
2378
+ } else {
2379
+ local_digit = digit_hex;
2380
+ }
2381
+ c += input.next();
2382
+ } else if (c === '.') {
2383
+ // Already have a decimal for this literal, don't allow another
2384
+ allow_decimal = false;
2385
+ } else {
2386
+ // we know this first loop will run. It keeps the logic simpler.
2387
+ c = '';
2388
+ input.back();
2389
+ }
2390
+
2391
+ // Add the digits
2392
+ while (input.testChar(local_digit)) {
2393
+ c += input.next();
2394
+
2395
+ if (allow_decimal && input.peek() === '.') {
2396
+ c += input.next();
2397
+ allow_decimal = false;
2398
+ }
2399
+
2400
+ // a = 1.e-7 is valid, so we test for . then e in one loop
2401
+ if (allow_e && input.testChar(/[Ee]/)) {
2402
+ c += input.next();
2403
+
2404
+ if (input.testChar(/[+-]/)) {
2405
+ c += input.next();
2406
+ }
2407
+
2408
+ allow_e = false;
2409
+ allow_decimal = false;
2410
+ }
2411
+ }
2412
+
2413
+ return [c, 'TK_WORD'];
2414
+ }
2415
+
2416
+ if (acorn.isIdentifierStart(input.peekCharCode(-1))) {
2417
+ if (input.hasNext()) {
2418
+ while (acorn.isIdentifierChar(input.peekCharCode())) {
2419
+ c += input.next();
2420
+ if (!input.hasNext()) {
2421
+ break;
2422
+ }
2423
+ }
2424
+ }
2425
+
2426
+ if (!(last_token.type === 'TK_DOT' ||
2427
+ (last_token.type === 'TK_RESERVED' && in_array(last_token.text, ['set', 'get']))) &&
2428
+ in_array(c, reserved_words)) {
2429
+ if (c === 'in' || c === 'of') { // hack for 'in' and 'of' operators
2430
+ return [c, 'TK_OPERATOR'];
2431
+ }
2432
+ return [c, 'TK_RESERVED'];
2433
+ }
2434
+
2435
+ return [c, 'TK_WORD'];
2436
+ }
2437
+
2438
+ if (c === '(' || c === '[') {
2439
+ return [c, 'TK_START_EXPR'];
2440
+ }
2441
+
2442
+ if (c === ')' || c === ']') {
2443
+ return [c, 'TK_END_EXPR'];
2444
+ }
2445
+
2446
+ if (c === '{') {
2447
+ return [c, 'TK_START_BLOCK'];
2448
+ }
2449
+
2450
+ if (c === '}') {
2451
+ return [c, 'TK_END_BLOCK'];
2452
+ }
2453
+
2454
+ if (c === ';') {
2455
+ return [c, 'TK_SEMICOLON'];
2456
+ }
2457
+
2458
+ if (c === '/') {
2459
+ var comment = '';
2460
+ var comment_match;
2461
+ // peek for comment /* ... */
2462
+ if (input.peek() === '*') {
2463
+ input.next();
2464
+ comment_match = input.match(block_comment_pattern);
2465
+ comment = '/*' + comment_match[0];
2466
+ var directives = get_directives(comment);
2467
+ if (directives && directives.ignore === 'start') {
2468
+ comment_match = input.match(directives_end_ignore_pattern);
2469
+ comment += comment_match[0];
2470
+ }
2471
+ comment = comment.replace(acorn.allLineBreaks, '\n');
2472
+ return [comment, 'TK_BLOCK_COMMENT', directives];
2473
+ }
2474
+ // peek for comment // ...
2475
+ if (input.peek() === '/') {
2476
+ input.next();
2477
+ comment_match = input.match(comment_pattern);
2478
+ comment = '//' + comment_match[0];
2479
+ return [comment, 'TK_COMMENT'];
2480
+ }
2481
+
2482
+ }
2483
+
2484
+ var startXmlRegExp = /<()([-a-zA-Z:0-9_.]+|{[\s\S]+?}|!\[CDATA\[[\s\S]*?\]\])(\s+{[\s\S]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{[\s\S]+?}))*\s*(\/?)\s*>/g;
2485
+
2486
+ if (c === '`' || c === "'" || c === '"' || // string
2487
+ (
2488
+ (c === '/') || // regexp
2489
+ (opts.e4x && c === "<" && input.test(startXmlRegExp, -1)) // xml
2490
+ ) && ( // regex and xml can only appear in specific locations during parsing
2491
+ (last_token.type === 'TK_RESERVED' && in_array(last_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
2492
+ (last_token.type === 'TK_END_EXPR' && last_token.text === ')' &&
2493
+ last_token.parent && last_token.parent.type === 'TK_RESERVED' && in_array(last_token.parent.text, ['if', 'while', 'for'])) ||
2494
+ (in_array(last_token.type, ['TK_COMMENT', 'TK_START_EXPR', 'TK_START_BLOCK',
2495
+ 'TK_END_BLOCK', 'TK_OPERATOR', 'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON', 'TK_COMMA'
2496
+ ]))
2497
+ )) {
2498
+
2499
+ var sep = c,
2500
+ esc = false,
2501
+ has_char_escapes = false;
2502
+
2503
+ resulting_string = c;
2504
+
2505
+ if (sep === '/') {
2506
+ //
2507
+ // handle regexp
2508
+ //
2509
+ var in_char_class = false;
2510
+ while (input.hasNext() &&
2511
+ ((esc || in_char_class || input.peek() !== sep) &&
2512
+ !input.testChar(acorn.newline))) {
2513
+ resulting_string += input.peek();
2514
+ if (!esc) {
2515
+ esc = input.peek() === '\\';
2516
+ if (input.peek() === '[') {
2517
+ in_char_class = true;
2518
+ } else if (input.peek() === ']') {
2519
+ in_char_class = false;
2520
+ }
2521
+ } else {
2522
+ esc = false;
2523
+ }
2524
+ input.next();
2525
+ }
2526
+ } else if (opts.e4x && sep === '<') {
2527
+ //
2528
+ // handle e4x xml literals
2529
+ //
2530
+
2531
+ var xmlRegExp = /[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[\s\S]+?}|!\[CDATA\[[\s\S]*?\]\])(\s+{[\s\S]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{[\s\S]+?}))*\s*(\/?)\s*>/g;
2532
+ input.back();
2533
+ var xmlStr = '';
2534
+ var match = input.match(startXmlRegExp);
2535
+ if (match) {
2536
+ // Trim root tag to attempt to
2537
+ var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
2538
+ var isCurlyRoot = rootTag.indexOf('{') === 0;
2539
+ var depth = 0;
2540
+ while (match) {
2541
+ var isEndTag = !!match[1];
2542
+ var tagName = match[2];
2543
+ var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
2544
+ if (!isSingletonTag &&
2545
+ (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
2546
+ if (isEndTag) {
2547
+ --depth;
2548
+ } else {
2549
+ ++depth;
2550
+ }
2551
+ }
2552
+ xmlStr += match[0];
2553
+ if (depth <= 0) {
2554
+ break;
2555
+ }
2556
+ match = input.match(xmlRegExp);
2557
+ }
2558
+ // if we didn't close correctly, keep unformatted.
2559
+ if (!match) {
2560
+ xmlStr += input.match(/[\s\S]*/g)[0];
2561
+ }
2562
+ xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
2563
+ return [xmlStr, "TK_STRING"];
2564
+ }
2565
+ } else {
2566
+ //
2567
+ // handle string
2568
+ //
2569
+ var parse_string = function(delimiter, allow_unescaped_newlines, start_sub) {
2570
+ // Template strings can travers lines without escape characters.
2571
+ // Other strings cannot
2572
+ var current_char;
2573
+ while (input.hasNext()) {
2574
+ current_char = input.peek();
2575
+ if (!(esc || (current_char !== delimiter &&
2576
+ (allow_unescaped_newlines || !acorn.newline.test(current_char))))) {
2577
+ break;
2578
+ }
2579
+
2580
+ // Handle \r\n linebreaks after escapes or in template strings
2581
+ if ((esc || allow_unescaped_newlines) && acorn.newline.test(current_char)) {
2582
+ if (current_char === '\r' && input.peek(1) === '\n') {
2583
+ input.next();
2584
+ current_char = input.peek();
2585
+ }
2586
+ resulting_string += '\n';
2587
+ } else {
2588
+ resulting_string += current_char;
2589
+ }
2590
+
2591
+ if (esc) {
2592
+ if (current_char === 'x' || current_char === 'u') {
2593
+ has_char_escapes = true;
2594
+ }
2595
+ esc = false;
2596
+ } else {
2597
+ esc = current_char === '\\';
2598
+ }
2599
+
2600
+ input.next();
2601
+
2602
+ if (start_sub && resulting_string.indexOf(start_sub, resulting_string.length - start_sub.length) !== -1) {
2603
+ if (delimiter === '`') {
2604
+ parse_string('}', allow_unescaped_newlines, '`');
2605
+ } else {
2606
+ parse_string('`', allow_unescaped_newlines, '${');
2607
+ }
2608
+
2609
+ if (input.hasNext()) {
2610
+ resulting_string += input.next();
2611
+ }
2612
+ }
2613
+ }
2614
+ };
2615
+
2616
+ if (sep === '`') {
2617
+ parse_string('`', true, '${');
2618
+ } else {
2619
+ parse_string(sep);
2620
+ }
2621
+ }
2622
+
2623
+ if (has_char_escapes && opts.unescape_strings) {
2624
+ resulting_string = unescape_string(resulting_string);
2625
+ }
2626
+
2627
+ if (input.peek() === sep) {
2628
+ resulting_string += sep;
2629
+ input.next();
2630
+
2631
+ if (sep === '/') {
2632
+ // regexps may have modifiers /regexp/MOD , so fetch those, too
2633
+ // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
2634
+ while (input.hasNext() && acorn.isIdentifierStart(input.peekCharCode())) {
2635
+ resulting_string += input.next();
2636
+ }
2637
+ }
2638
+ }
2639
+ return [resulting_string, 'TK_STRING'];
2640
+ }
2641
+
2642
+ if (c === '#') {
2643
+
2644
+ if (tokens.length === 0 && input.peek() === '!') {
2645
+ // shebang
2646
+ resulting_string = c;
2647
+ while (input.hasNext() && c !== '\n') {
2648
+ c = input.next();
2649
+ resulting_string += c;
2650
+ }
2651
+ return [trim(resulting_string) + '\n', 'TK_UNKNOWN'];
2652
+ }
2653
+
2654
+
2655
+
2656
+ // Spidermonkey-specific sharp variables for circular references
2657
+ // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
2658
+ // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
2659
+ var sharp = '#';
2660
+ if (input.hasNext() && input.testChar(digit)) {
2661
+ do {
2662
+ c = input.next();
2663
+ sharp += c;
2664
+ } while (input.hasNext() && c !== '#' && c !== '=');
2665
+ if (c === '#') {
2666
+ //
2667
+ } else if (input.peek() === '[' && input.peek(1) === ']') {
2668
+ sharp += '[]';
2669
+ input.next();
2670
+ input.next();
2671
+ } else if (input.peek() === '{' && input.peek(1) === '}') {
2672
+ sharp += '{}';
2673
+ input.next();
2674
+ input.next();
2675
+ }
2676
+ return [sharp, 'TK_WORD'];
2677
+ }
2678
+ }
2679
+
2680
+ if (c === '<' && (input.peek() === '?' || input.peek() === '%')) {
2681
+ input.back();
2682
+ var template_match = input.match(template_pattern);
2683
+ if (template_match) {
2684
+ c = template_match[0];
2685
+ c = c.replace(acorn.allLineBreaks, '\n');
2686
+ return [c, 'TK_STRING'];
2687
+ }
2688
+ }
2689
+
2690
+ if (c === '<' && input.match(/\!--/g)) {
2691
+ c = '<!--';
2692
+ while (input.hasNext() && !input.testChar(acorn.newline)) {
2693
+ c += input.next();
2694
+ }
2695
+ in_html_comment = true;
2696
+ return [c, 'TK_COMMENT'];
2697
+ }
2698
+
2699
+ if (c === '-' && in_html_comment && input.match(/->/g)) {
2700
+ in_html_comment = false;
2701
+ return ['-->', 'TK_COMMENT'];
2702
+ }
2703
+
2704
+ if (c === '.') {
2705
+ if (input.peek() === '.' && input.peek(1) === '.') {
2706
+ c += input.next() + input.next();
2707
+ return [c, 'TK_OPERATOR'];
2708
+ }
2709
+ return [c, 'TK_DOT'];
2710
+ }
2711
+
2712
+ if (in_array(c, punct)) {
2713
+ while (input.hasNext() && in_array(c + input.peek(), punct)) {
2714
+ c += input.next();
2715
+ if (!input.hasNext()) {
2716
+ break;
2717
+ }
2718
+ }
2719
+
2720
+ if (c === ',') {
2721
+ return [c, 'TK_COMMA'];
2722
+ } else if (c === '=') {
2723
+ return [c, 'TK_EQUALS'];
2724
+ } else {
2725
+ return [c, 'TK_OPERATOR'];
2726
+ }
2727
+ }
2728
+
2729
+ return [c, 'TK_UNKNOWN'];
2730
+ }
2731
+
2732
+
2733
+ function unescape_string(s) {
2734
+ // You think that a regex would work for this
2735
+ // return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
2736
+ // return String.fromCharCode(parseInt(val, 16));
2737
+ // })
2738
+ // However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
2739
+ var out = '',
2740
+ escaped = 0;
2741
+
2742
+ var input_scan = new InputScanner(s);
2743
+ var matched = null;
2744
+
2745
+ while (input_scan.hasNext()) {
2746
+ // Keep any whitespace, non-slash characters
2747
+ // also keep slash pairs.
2748
+ matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
2749
+
2750
+ if (matched) {
2751
+ out += matched[0];
2752
+ }
2753
+
2754
+ if (input_scan.peek() === '\\') {
2755
+ input_scan.next();
2756
+ if (input_scan.peek() === 'x') {
2757
+ matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
2758
+ } else if (input_scan.peek() === 'u') {
2759
+ matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
2760
+ } else {
2761
+ out += '\\';
2762
+ if (input_scan.hasNext()) {
2763
+ out += input_scan.next();
2764
+ }
2765
+ continue;
2766
+ }
2767
+
2768
+ // If there's some error decoding, return the original string
2769
+ if (!matched) {
2770
+ return s;
2771
+ }
2772
+
2773
+ escaped = parseInt(matched[1], 16);
2774
+
2775
+ if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
2776
+ // we bail out on \x7f..\xff,
2777
+ // leaving whole string escaped,
2778
+ // as it's probably completely binary
2779
+ return s;
2780
+ } else if (escaped >= 0x00 && escaped < 0x20) {
2781
+ // leave 0x00...0x1f escaped
2782
+ out += '\\' + matched[0];
2783
+ continue;
2784
+ } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
2785
+ // single-quote, apostrophe, backslash - escape these
2786
+ out += '\\' + String.fromCharCode(escaped);
2787
+ } else {
2788
+ out += String.fromCharCode(escaped);
2789
+ }
2790
+ }
2791
+ }
2792
+
2793
+ return out;
2794
+ }
2795
+ }
2796
+
2797
+ module.exports.Tokenizer = Tokenizer;
2798
+
2799
+ /***/ })
2800
+ /******/ ]);
2801
+ var js_beautify = legacy_beautify_js;
2802
+ /* Footer */
2803
+ if (typeof define === "function" && define.amd) {
2804
+ // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
2805
+ define([], function() {
2806
+ return { js_beautify: js_beautify };
2807
+ });
2808
+ } else if (typeof exports !== "undefined") {
2809
+ // Add support for CommonJS. Just put this file somewhere on your require.paths
2810
+ // and you will be able to `var js_beautify = require("beautify").js_beautify`.
2811
+ exports.js_beautify = js_beautify;
2812
+ } else if (typeof window !== "undefined") {
2813
+ // If we're running a web page and don't have either of the above, add our one global
2814
+ window.js_beautify = js_beautify;
2815
+ } else if (typeof global !== "undefined") {
2816
+ // If we don't even have window, try global.
2817
+ global.js_beautify = js_beautify;
2818
+ }
2819
+
2820
+ }());