View Javadoc

1   package delight.nashornsandbox.internal;
2   
3   import org.eclipse.xtend2.lib.StringConcatenation;
4   import org.eclipse.xtext.xbase.lib.Functions.Function0;
5   
6   @SuppressWarnings("all")
7   public class BeautifyJs {
8     public final static String CODE = new Function0<String>() {
9       public String apply() {
10        StringConcatenation _builder = new StringConcatenation();
11        _builder.append("\t");
12        _builder.newLine();
13        _builder.append("/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */");
14        _builder.newLine();
15        _builder.append("/*");
16        _builder.newLine();
17        _builder.newLine();
18        _builder.append("  ");
19        _builder.append("The MIT License (MIT)");
20        _builder.newLine();
21        _builder.newLine();
22        _builder.append("  ");
23        _builder.append("Copyright (c) 2007-2013 Einar Lielmanis and contributors.");
24        _builder.newLine();
25        _builder.newLine();
26        _builder.append("  ");
27        _builder.append("Permission is hereby granted, free of charge, to any person");
28        _builder.newLine();
29        _builder.append("  ");
30        _builder.append("obtaining a copy of this software and associated documentation files");
31        _builder.newLine();
32        _builder.append("  ");
33        _builder.append("(the \"Software\"), to deal in the Software without restriction,");
34        _builder.newLine();
35        _builder.append("  ");
36        _builder.append("including without limitation the rights to use, copy, modify, merge,");
37        _builder.newLine();
38        _builder.append("  ");
39        _builder.append("publish, distribute, sublicense, and/or sell copies of the Software,");
40        _builder.newLine();
41        _builder.append("  ");
42        _builder.append("and to permit persons to whom the Software is furnished to do so,");
43        _builder.newLine();
44        _builder.append("  ");
45        _builder.append("subject to the following conditions:");
46        _builder.newLine();
47        _builder.newLine();
48        _builder.append("  ");
49        _builder.append("The above copyright notice and this permission notice shall be");
50        _builder.newLine();
51        _builder.append("  ");
52        _builder.append("included in all copies or substantial portions of the Software.");
53        _builder.newLine();
54        _builder.newLine();
55        _builder.append("  ");
56        _builder.append("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,");
57        _builder.newLine();
58        _builder.append("  ");
59        _builder.append("EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF");
60        _builder.newLine();
61        _builder.append("  ");
62        _builder.append("MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND");
63        _builder.newLine();
64        _builder.append("  ");
65        _builder.append("NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS");
66        _builder.newLine();
67        _builder.append("  ");
68        _builder.append("BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN");
69        _builder.newLine();
70        _builder.append("  ");
71        _builder.append("ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN");
72        _builder.newLine();
73        _builder.append("  ");
74        _builder.append("CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE");
75        _builder.newLine();
76        _builder.append("  ");
77        _builder.append("SOFTWARE.");
78        _builder.newLine();
79        _builder.newLine();
80        _builder.append(" ");
81        _builder.append("JS Beautifier");
82        _builder.newLine();
83        _builder.append("---------------");
84        _builder.newLine();
85        _builder.newLine();
86        _builder.newLine();
87        _builder.append("  ");
88        _builder.append("Written by Einar Lielmanis, <einar@jsbeautifier.org>");
89        _builder.newLine();
90        _builder.append("      ");
91        _builder.append("http://jsbeautifier.org/");
92        _builder.newLine();
93        _builder.newLine();
94        _builder.append("  ");
95        _builder.append("Originally converted to javascript by Vital, <vital76@gmail.com>");
96        _builder.newLine();
97        _builder.append("  ");
98        _builder.append("\"End braces on own line\" added by Chris J. Shull, <chrisjshull@gmail.com>");
99        _builder.newLine();
100       _builder.append("  ");
101       _builder.append("Parsing improvements for brace-less statements by Liam Newman <bitwiseman@gmail.com>");
102       _builder.newLine();
103       _builder.newLine();
104       _builder.newLine();
105       _builder.append("  ");
106       _builder.append("Usage:");
107       _builder.newLine();
108       _builder.append("    ");
109       _builder.append("js_beautify(js_source_text);");
110       _builder.newLine();
111       _builder.append("    ");
112       _builder.append("js_beautify(js_source_text, options);");
113       _builder.newLine();
114       _builder.newLine();
115       _builder.append("  ");
116       _builder.append("The options are:");
117       _builder.newLine();
118       _builder.append("    ");
119       _builder.append("indent_size (default 4)          - indentation size,");
120       _builder.newLine();
121       _builder.append("    ");
122       _builder.append("indent_char (default space)      - character to indent with,");
123       _builder.newLine();
124       _builder.append("    ");
125       _builder.append("preserve_newlines (default true) - whether existing line breaks should be preserved,");
126       _builder.newLine();
127       _builder.append("    ");
128       _builder.append("max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,");
129       _builder.newLine();
130       _builder.newLine();
131       _builder.append("    ");
132       _builder.append("jslint_happy (default false) - if true, then jslint-stricter mode is enforced.");
133       _builder.newLine();
134       _builder.newLine();
135       _builder.append("            ");
136       _builder.append("jslint_happy        !jslint_happy");
137       _builder.newLine();
138       _builder.append("            ");
139       _builder.append("---------------------------------");
140       _builder.newLine();
141       _builder.append("            ");
142       _builder.append("function ()         function()");
143       _builder.newLine();
144       _builder.newLine();
145       _builder.append("            ");
146       _builder.append("switch () {         switch() {");
147       _builder.newLine();
148       _builder.append("            ");
149       _builder.append("case 1:               case 1:");
150       _builder.newLine();
151       _builder.append("              ");
152       _builder.append("break;                break;");
153       _builder.newLine();
154       _builder.append("            ");
155       _builder.append("}                   }");
156       _builder.newLine();
157       _builder.newLine();
158       _builder.append("    ");
159       _builder.append("space_after_anon_function (default false) - should the space before an anonymous function\'s parens be added, \"function()\" vs \"function ()\",");
160       _builder.newLine();
161       _builder.append("          ");
162       _builder.append("NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)");
163       _builder.newLine();
164       _builder.newLine();
165       _builder.append("    ");
166       _builder.append("brace_style (default \"collapse\") - \"collapse\" | \"expand\" | \"end-expand\" | \"none\"");
167       _builder.newLine();
168       _builder.append("            ");
169       _builder.append("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.");
170       _builder.newLine();
171       _builder.newLine();
172       _builder.append("    ");
173       _builder.append("space_before_conditional (default true) - should the space before conditional statement be added, \"if(true)\" vs \"if (true)\",");
174       _builder.newLine();
175       _builder.newLine();
176       _builder.append("    ");
177       _builder.append("unescape_strings (default false) - should printable characters in strings encoded in \\xNN notation be unescaped, \"example\" vs \"\\x65\\x78\\x61\\x6d\\x70\\x6c\\x65\"");
178       _builder.newLine();
179       _builder.newLine();
180       _builder.append("    ");
181       _builder.append("wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.");
182       _builder.newLine();
183       _builder.append("          ");
184       _builder.append("NOTE: This is not a hard limit. Lines will continue until a point where a newline would");
185       _builder.newLine();
186       _builder.append("                ");
187       _builder.append("be preserved if it were present.");
188       _builder.newLine();
189       _builder.newLine();
190       _builder.append("    ");
191       _builder.append("end_with_newline (default false)  - end output with a newline");
192       _builder.newLine();
193       _builder.newLine();
194       _builder.newLine();
195       _builder.append("    ");
196       _builder.append("e.g");
197       _builder.newLine();
198       _builder.newLine();
199       _builder.append("    ");
200       _builder.append("js_beautify(js_source_text, {");
201       _builder.newLine();
202       _builder.append("      ");
203       _builder.append("\'indent_size\': 1,");
204       _builder.newLine();
205       _builder.append("      ");
206       _builder.append("\'indent_char\': \'\\t\'");
207       _builder.newLine();
208       _builder.append("    ");
209       _builder.append("});");
210       _builder.newLine();
211       _builder.newLine();
212       _builder.append("*/");
213       _builder.newLine();
214       _builder.newLine();
215       _builder.append("(function() {");
216       _builder.newLine();
217       _builder.newLine();
218       _builder.append("    ");
219       _builder.append("var acorn = {};");
220       _builder.newLine();
221       _builder.append("    ");
222       _builder.append("(function (exports) {");
223       _builder.newLine();
224       _builder.append("      ");
225       _builder.append("// This section of code is taken from acorn.");
226       _builder.newLine();
227       _builder.append("      ");
228       _builder.append("//");
229       _builder.newLine();
230       _builder.append("      ");
231       _builder.append("// Acorn was written by Marijn Haverbeke and released under an MIT");
232       _builder.newLine();
233       _builder.append("      ");
234       _builder.append("// license. The Unicode regexps (for identifiers and whitespace) were");
235       _builder.newLine();
236       _builder.append("      ");
237       _builder.append("// taken from [Esprima](http://esprima.org) by Ariya Hidayat.");
238       _builder.newLine();
239       _builder.append("      ");
240       _builder.append("//");
241       _builder.newLine();
242       _builder.append("      ");
243       _builder.append("// Git repositories for Acorn are available at");
244       _builder.newLine();
245       _builder.append("      ");
246       _builder.append("//");
247       _builder.newLine();
248       _builder.append("      ");
249       _builder.append("//     http://marijnhaverbeke.nl/git/acorn");
250       _builder.newLine();
251       _builder.append("      ");
252       _builder.append("//     https://github.com/marijnh/acorn.git");
253       _builder.newLine();
254       _builder.newLine();
255       _builder.append("      ");
256       _builder.append("// ## Character categories");
257       _builder.newLine();
258       _builder.newLine();
259       _builder.append("      ");
260       _builder.append("// Big ugly regular expressions that match characters in the");
261       _builder.newLine();
262       _builder.append("      ");
263       _builder.append("// whitespace, identifier, and identifier-start categories. These");
264       _builder.newLine();
265       _builder.append("      ");
266       _builder.append("// are only applied when a character is found to actually have a");
267       _builder.newLine();
268       _builder.append("      ");
269       _builder.append("// code point above 128.");
270       _builder.newLine();
271       _builder.newLine();
272       _builder.append("      ");
273       _builder.append("var nonASCIIwhitespace = /[\\u1680\\u180e\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/;");
274       _builder.newLine();
275       _builder.append("      ");
276       _builder.append("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\";");
277       _builder.newLine();
278       _builder.append("      ");
279       _builder.append("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\";");
280       _builder.newLine();
281       _builder.append("      ");
282       _builder.append("var nonASCIIidentifierStart = new RegExp(\"[\" + nonASCIIidentifierStartChars + \"]\");");
283       _builder.newLine();
284       _builder.append("      ");
285       _builder.append("var nonASCIIidentifier = new RegExp(\"[\" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + \"]\");");
286       _builder.newLine();
287       _builder.newLine();
288       _builder.append("      ");
289       _builder.append("// Whether a single character denotes a newline.");
290       _builder.newLine();
291       _builder.newLine();
292       _builder.append("      ");
293       _builder.append("var newline = exports.newline = /[\\n\\r\\u2028\\u2029]/;");
294       _builder.newLine();
295       _builder.newLine();
296       _builder.append("      ");
297       _builder.append("// Matches a whole line break (where CRLF is considered a single");
298       _builder.newLine();
299       _builder.append("      ");
300       _builder.append("// line break). Used to count lines.");
301       _builder.newLine();
302       _builder.newLine();
303       _builder.append("      ");
304       _builder.append("var lineBreak = exports.lineBreak = /\\r\\n|[\\n\\r\\u2028\\u2029]/g;");
305       _builder.newLine();
306       _builder.newLine();
307       _builder.append("      ");
308       _builder.append("// Test whether a given character code starts an identifier.");
309       _builder.newLine();
310       _builder.newLine();
311       _builder.append("      ");
312       _builder.append("var isIdentifierStart = exports.isIdentifierStart = function(code) {");
313       _builder.newLine();
314       _builder.append("        ");
315       _builder.append("if (code < 65) return code === 36;");
316       _builder.newLine();
317       _builder.append("        ");
318       _builder.append("if (code < 91) return true;");
319       _builder.newLine();
320       _builder.append("        ");
321       _builder.append("if (code < 97) return code === 95;");
322       _builder.newLine();
323       _builder.append("        ");
324       _builder.append("if (code < 123)return true;");
325       _builder.newLine();
326       _builder.append("        ");
327       _builder.append("return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));");
328       _builder.newLine();
329       _builder.append("      ");
330       _builder.append("};");
331       _builder.newLine();
332       _builder.newLine();
333       _builder.append("      ");
334       _builder.append("// Test whether a given character is part of an identifier.");
335       _builder.newLine();
336       _builder.newLine();
337       _builder.append("      ");
338       _builder.append("var isIdentifierChar = exports.isIdentifierChar = function(code) {");
339       _builder.newLine();
340       _builder.append("        ");
341       _builder.append("if (code < 48) return code === 36;");
342       _builder.newLine();
343       _builder.append("        ");
344       _builder.append("if (code < 58) return true;");
345       _builder.newLine();
346       _builder.append("        ");
347       _builder.append("if (code < 65) return false;");
348       _builder.newLine();
349       _builder.append("        ");
350       _builder.append("if (code < 91) return true;");
351       _builder.newLine();
352       _builder.append("        ");
353       _builder.append("if (code < 97) return code === 95;");
354       _builder.newLine();
355       _builder.append("        ");
356       _builder.append("if (code < 123)return true;");
357       _builder.newLine();
358       _builder.append("        ");
359       _builder.append("return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));");
360       _builder.newLine();
361       _builder.append("      ");
362       _builder.append("};");
363       _builder.newLine();
364       _builder.append("    ");
365       _builder.append("})(acorn);");
366       _builder.newLine();
367       _builder.newLine();
368       _builder.append("    ");
369       _builder.append("function in_array(what, arr) {");
370       _builder.newLine();
371       _builder.append("        ");
372       _builder.append("for (var i = 0; i < arr.length; i += 1) {");
373       _builder.newLine();
374       _builder.append("            ");
375       _builder.append("if (arr[i] === what) {");
376       _builder.newLine();
377       _builder.append("                ");
378       _builder.append("return true;");
379       _builder.newLine();
380       _builder.append("            ");
381       _builder.append("}");
382       _builder.newLine();
383       _builder.append("        ");
384       _builder.append("}");
385       _builder.newLine();
386       _builder.append("        ");
387       _builder.append("return false;");
388       _builder.newLine();
389       _builder.append("    ");
390       _builder.append("}");
391       _builder.newLine();
392       _builder.newLine();
393       _builder.append("    ");
394       _builder.append("function trim(s) {");
395       _builder.newLine();
396       _builder.append("        ");
397       _builder.append("return s.replace(/^\\s+|\\s+$/g, \'\');");
398       _builder.newLine();
399       _builder.append("    ");
400       _builder.append("}");
401       _builder.newLine();
402       _builder.newLine();
403       _builder.append("    ");
404       _builder.append("function ltrim(s) {");
405       _builder.newLine();
406       _builder.append("        ");
407       _builder.append("return s.replace(/^\\s+/g, \'\');");
408       _builder.newLine();
409       _builder.append("    ");
410       _builder.append("}");
411       _builder.newLine();
412       _builder.newLine();
413       _builder.append("    ");
414       _builder.append("function rtrim(s) {");
415       _builder.newLine();
416       _builder.append("        ");
417       _builder.append("return s.replace(/\\s+$/g, \'\');");
418       _builder.newLine();
419       _builder.append("    ");
420       _builder.append("}");
421       _builder.newLine();
422       _builder.newLine();
423       _builder.append("    ");
424       _builder.append("function js_beautify(js_source_text, options) {");
425       _builder.newLine();
426       _builder.append("        ");
427       _builder.append("\"use strict\";");
428       _builder.newLine();
429       _builder.append("        ");
430       _builder.append("var beautifier = new Beautifier(js_source_text, options);");
431       _builder.newLine();
432       _builder.append("        ");
433       _builder.append("return beautifier.beautify();");
434       _builder.newLine();
435       _builder.append("    ");
436       _builder.append("}");
437       _builder.newLine();
438       _builder.newLine();
439       _builder.append("    ");
440       _builder.append("var MODE = {");
441       _builder.newLine();
442       _builder.append("            ");
443       _builder.append("BlockStatement: \'BlockStatement\', // \'BLOCK\'");
444       _builder.newLine();
445       _builder.append("            ");
446       _builder.append("Statement: \'Statement\', // \'STATEMENT\'");
447       _builder.newLine();
448       _builder.append("            ");
449       _builder.append("ObjectLiteral: \'ObjectLiteral\', // \'OBJECT\',");
450       _builder.newLine();
451       _builder.append("            ");
452       _builder.append("ArrayLiteral: \'ArrayLiteral\', //\'[EXPRESSION]\',");
453       _builder.newLine();
454       _builder.append("            ");
455       _builder.append("ForInitializer: \'ForInitializer\', //\'(FOR-EXPRESSION)\',");
456       _builder.newLine();
457       _builder.append("            ");
458       _builder.append("Conditional: \'Conditional\', //\'(COND-EXPRESSION)\',");
459       _builder.newLine();
460       _builder.append("            ");
461       _builder.append("Expression: \'Expression\' //\'(EXPRESSION)\'");
462       _builder.newLine();
463       _builder.append("        ");
464       _builder.append("};");
465       _builder.newLine();
466       _builder.newLine();
467       _builder.append("    ");
468       _builder.append("function Beautifier(js_source_text, options) {");
469       _builder.newLine();
470       _builder.append("        ");
471       _builder.append("\"use strict\";");
472       _builder.newLine();
473       _builder.append("        ");
474       _builder.append("var output");
475       _builder.newLine();
476       _builder.append("        ");
477       _builder.append("var tokens = [], token_pos;");
478       _builder.newLine();
479       _builder.append("        ");
480       _builder.append("var Tokenizer;");
481       _builder.newLine();
482       _builder.append("        ");
483       _builder.append("var current_token;");
484       _builder.newLine();
485       _builder.append("        ");
486       _builder.append("var last_type, last_last_text, indent_string;");
487       _builder.newLine();
488       _builder.append("        ");
489       _builder.append("var flags, previous_flags, flag_store;");
490       _builder.newLine();
491       _builder.append("        ");
492       _builder.append("var prefix;");
493       _builder.newLine();
494       _builder.newLine();
495       _builder.append("        ");
496       _builder.append("var handlers, opt;");
497       _builder.newLine();
498       _builder.append("        ");
499       _builder.append("var baseIndentString = \'\';");
500       _builder.newLine();
501       _builder.newLine();
502       _builder.append("        ");
503       _builder.append("handlers = {");
504       _builder.newLine();
505       _builder.append("            ");
506       _builder.append("\'TK_START_EXPR\': handle_start_expr,");
507       _builder.newLine();
508       _builder.append("            ");
509       _builder.append("\'TK_END_EXPR\': handle_end_expr,");
510       _builder.newLine();
511       _builder.append("            ");
512       _builder.append("\'TK_START_BLOCK\': handle_start_block,");
513       _builder.newLine();
514       _builder.append("            ");
515       _builder.append("\'TK_END_BLOCK\': handle_end_block,");
516       _builder.newLine();
517       _builder.append("            ");
518       _builder.append("\'TK_WORD\': handle_word,");
519       _builder.newLine();
520       _builder.append("            ");
521       _builder.append("\'TK_RESERVED\': handle_word,");
522       _builder.newLine();
523       _builder.append("            ");
524       _builder.append("\'TK_SEMICOLON\': handle_semicolon,");
525       _builder.newLine();
526       _builder.append("            ");
527       _builder.append("\'TK_STRING\': handle_string,");
528       _builder.newLine();
529       _builder.append("            ");
530       _builder.append("\'TK_EQUALS\': handle_equals,");
531       _builder.newLine();
532       _builder.append("            ");
533       _builder.append("\'TK_OPERATOR\': handle_operator,");
534       _builder.newLine();
535       _builder.append("            ");
536       _builder.append("\'TK_COMMA\': handle_comma,");
537       _builder.newLine();
538       _builder.append("            ");
539       _builder.append("\'TK_BLOCK_COMMENT\': handle_block_comment,");
540       _builder.newLine();
541       _builder.append("            ");
542       _builder.append("\'TK_COMMENT\': handle_comment,");
543       _builder.newLine();
544       _builder.append("            ");
545       _builder.append("\'TK_DOT\': handle_dot,");
546       _builder.newLine();
547       _builder.append("            ");
548       _builder.append("\'TK_UNKNOWN\': handle_unknown,");
549       _builder.newLine();
550       _builder.append("            ");
551       _builder.append("\'TK_EOF\': handle_eof");
552       _builder.newLine();
553       _builder.append("        ");
554       _builder.append("};");
555       _builder.newLine();
556       _builder.newLine();
557       _builder.append("        ");
558       _builder.append("function create_flags(flags_base, mode) {");
559       _builder.newLine();
560       _builder.append("            ");
561       _builder.append("var next_indent_level = 0;");
562       _builder.newLine();
563       _builder.append("            ");
564       _builder.append("if (flags_base) {");
565       _builder.newLine();
566       _builder.append("                ");
567       _builder.append("next_indent_level = flags_base.indentation_level;");
568       _builder.newLine();
569       _builder.append("                ");
570       _builder.append("if (!output.just_added_newline() &&");
571       _builder.newLine();
572       _builder.append("                    ");
573       _builder.append("flags_base.line_indent_level > next_indent_level) {");
574       _builder.newLine();
575       _builder.append("                    ");
576       _builder.append("next_indent_level = flags_base.line_indent_level;");
577       _builder.newLine();
578       _builder.append("                ");
579       _builder.append("}");
580       _builder.newLine();
581       _builder.append("            ");
582       _builder.append("}");
583       _builder.newLine();
584       _builder.newLine();
585       _builder.append("            ");
586       _builder.append("var next_flags = {");
587       _builder.newLine();
588       _builder.append("                ");
589       _builder.append("mode: mode,");
590       _builder.newLine();
591       _builder.append("                ");
592       _builder.append("parent: flags_base,");
593       _builder.newLine();
594       _builder.append("                ");
595       _builder.append("last_text: flags_base ? flags_base.last_text : \'\', // last token text");
596       _builder.newLine();
597       _builder.append("                ");
598       _builder.append("last_word: flags_base ? flags_base.last_word : \'\', // last \'TK_WORD\' passed");
599       _builder.newLine();
600       _builder.append("                ");
601       _builder.append("declaration_statement: false,");
602       _builder.newLine();
603       _builder.append("                ");
604       _builder.append("declaration_assignment: false,");
605       _builder.newLine();
606       _builder.append("                ");
607       _builder.append("multiline_frame: false,");
608       _builder.newLine();
609       _builder.append("                ");
610       _builder.append("if_block: false,");
611       _builder.newLine();
612       _builder.append("                ");
613       _builder.append("else_block: false,");
614       _builder.newLine();
615       _builder.append("                ");
616       _builder.append("do_block: false,");
617       _builder.newLine();
618       _builder.append("                ");
619       _builder.append("do_while: false,");
620       _builder.newLine();
621       _builder.append("                ");
622       _builder.append("in_case_statement: false, // switch(..){ INSIDE HERE }");
623       _builder.newLine();
624       _builder.append("                ");
625       _builder.append("in_case: false, // we\'re on the exact line with \"case 0:\"");
626       _builder.newLine();
627       _builder.append("                ");
628       _builder.append("case_body: false, // the indented case-action block");
629       _builder.newLine();
630       _builder.append("                ");
631       _builder.append("indentation_level: next_indent_level,");
632       _builder.newLine();
633       _builder.append("                ");
634       _builder.append("line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,");
635       _builder.newLine();
636       _builder.append("                ");
637       _builder.append("start_line_index: output.get_line_number(),");
638       _builder.newLine();
639       _builder.append("                ");
640       _builder.append("ternary_depth: 0");
641       _builder.newLine();
642       _builder.append("            ");
643       _builder.append("};");
644       _builder.newLine();
645       _builder.append("            ");
646       _builder.append("return next_flags;");
647       _builder.newLine();
648       _builder.append("        ");
649       _builder.append("}");
650       _builder.newLine();
651       _builder.newLine();
652       _builder.append("        ");
653       _builder.append("// Some interpreters have unexpected results with foo = baz || bar;");
654       _builder.newLine();
655       _builder.append("        ");
656       _builder.append("options = options ? options : {};");
657       _builder.newLine();
658       _builder.append("        ");
659       _builder.append("opt = {};");
660       _builder.newLine();
661       _builder.newLine();
662       _builder.append("        ");
663       _builder.append("// compatibility");
664       _builder.newLine();
665       _builder.append("        ");
666       _builder.append("if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option");
667       _builder.newLine();
668       _builder.append("            ");
669       _builder.append("opt.brace_style = options.braces_on_own_line ? \"expand\" : \"collapse\";");
670       _builder.newLine();
671       _builder.append("        ");
672       _builder.append("}");
673       _builder.newLine();
674       _builder.append("        ");
675       _builder.append("opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : \"collapse\");");
676       _builder.newLine();
677       _builder.newLine();
678       _builder.append("        ");
679       _builder.append("// graceful handling of deprecated option");
680       _builder.newLine();
681       _builder.append("        ");
682       _builder.append("if (opt.brace_style === \"expand-strict\") {");
683       _builder.newLine();
684       _builder.append("            ");
685       _builder.append("opt.brace_style = \"expand\";");
686       _builder.newLine();
687       _builder.append("        ");
688       _builder.append("}");
689       _builder.newLine();
690       _builder.newLine();
691       _builder.newLine();
692       _builder.append("        ");
693       _builder.append("opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;");
694       _builder.newLine();
695       _builder.append("        ");
696       _builder.append("opt.indent_char = options.indent_char ? options.indent_char : \' \';");
697       _builder.newLine();
698       _builder.append("        ");
699       _builder.append("opt.eol = options.eol ? options.eol : \'\\n\';");
700       _builder.newLine();
701       _builder.append("        ");
702       _builder.append("opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;");
703       _builder.newLine();
704       _builder.append("        ");
705       _builder.append("opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;");
706       _builder.newLine();
707       _builder.append("        ");
708       _builder.append("opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);");
709       _builder.newLine();
710       _builder.append("        ");
711       _builder.append("opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;");
712       _builder.newLine();
713       _builder.append("        ");
714       _builder.append("opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;");
715       _builder.newLine();
716       _builder.append("        ");
717       _builder.append("opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;");
718       _builder.newLine();
719       _builder.append("        ");
720       _builder.append("opt.space_after_anon_function = (options.space_after_anon_function === undefined) ? false : options.space_after_anon_function;");
721       _builder.newLine();
722       _builder.append("        ");
723       _builder.append("opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;");
724       _builder.newLine();
725       _builder.append("        ");
726       _builder.append("opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;");
727       _builder.newLine();
728       _builder.append("        ");
729       _builder.append("opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;");
730       _builder.newLine();
731       _builder.append("        ");
732       _builder.append("opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);");
733       _builder.newLine();
734       _builder.append("        ");
735       _builder.append("opt.e4x = (options.e4x === undefined) ? false : options.e4x;");
736       _builder.newLine();
737       _builder.append("        ");
738       _builder.append("opt.end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;");
739       _builder.newLine();
740       _builder.append("        ");
741       _builder.append("opt.comma_first = (options.comma_first === undefined) ? false : options.comma_first;");
742       _builder.newLine();
743       _builder.newLine();
744       _builder.append("        ");
745       _builder.append("// For testing of beautify ignore:start directive");
746       _builder.newLine();
747       _builder.append("        ");
748       _builder.append("opt.test_output_raw = (options.test_output_raw === undefined) ? false : options.test_output_raw;");
749       _builder.newLine();
750       _builder.newLine();
751       _builder.append("        ");
752       _builder.append("// force opt.space_after_anon_function to true if opt.jslint_happy");
753       _builder.newLine();
754       _builder.append("        ");
755       _builder.append("if(opt.jslint_happy) {");
756       _builder.newLine();
757       _builder.append("            ");
758       _builder.append("opt.space_after_anon_function = true;");
759       _builder.newLine();
760       _builder.append("        ");
761       _builder.append("}");
762       _builder.newLine();
763       _builder.newLine();
764       _builder.append("        ");
765       _builder.append("if(options.indent_with_tabs){");
766       _builder.newLine();
767       _builder.append("            ");
768       _builder.append("opt.indent_char = \'\\t\';");
769       _builder.newLine();
770       _builder.append("            ");
771       _builder.append("opt.indent_size = 1;");
772       _builder.newLine();
773       _builder.append("        ");
774       _builder.append("}");
775       _builder.newLine();
776       _builder.newLine();
777       _builder.append("        ");
778       _builder.append("opt.eol = opt.eol.replace(/\\\\r/, \'\\r\').replace(/\\\\n/, \'\\n\')");
779       _builder.newLine();
780       _builder.newLine();
781       _builder.append("        ");
782       _builder.append("//----------------------------------");
783       _builder.newLine();
784       _builder.append("        ");
785       _builder.append("indent_string = \'\';");
786       _builder.newLine();
787       _builder.append("        ");
788       _builder.append("while (opt.indent_size > 0) {");
789       _builder.newLine();
790       _builder.append("            ");
791       _builder.append("indent_string += opt.indent_char;");
792       _builder.newLine();
793       _builder.append("            ");
794       _builder.append("opt.indent_size -= 1;");
795       _builder.newLine();
796       _builder.append("        ");
797       _builder.append("}");
798       _builder.newLine();
799       _builder.newLine();
800       _builder.append("        ");
801       _builder.append("var preindent_index = 0;");
802       _builder.newLine();
803       _builder.append("        ");
804       _builder.append("if(js_source_text && js_source_text.length) {");
805       _builder.newLine();
806       _builder.append("            ");
807       _builder.append("while ( (js_source_text.charAt(preindent_index) === \' \' ||");
808       _builder.newLine();
809       _builder.append("                    ");
810       _builder.append("js_source_text.charAt(preindent_index) === \'\\t\')) {");
811       _builder.newLine();
812       _builder.append("                ");
813       _builder.append("baseIndentString += js_source_text.charAt(preindent_index);");
814       _builder.newLine();
815       _builder.append("                ");
816       _builder.append("preindent_index += 1;");
817       _builder.newLine();
818       _builder.append("            ");
819       _builder.append("}");
820       _builder.newLine();
821       _builder.append("            ");
822       _builder.append("js_source_text = js_source_text.substring(preindent_index);");
823       _builder.newLine();
824       _builder.append("        ");
825       _builder.append("}");
826       _builder.newLine();
827       _builder.newLine();
828       _builder.append("        ");
829       _builder.append("last_type = \'TK_START_BLOCK\'; // last token type");
830       _builder.newLine();
831       _builder.append("        ");
832       _builder.append("last_last_text = \'\'; // pre-last token text");
833       _builder.newLine();
834       _builder.append("        ");
835       _builder.append("output = new Output(indent_string, baseIndentString);");
836       _builder.newLine();
837       _builder.newLine();
838       _builder.append("        ");
839       _builder.append("// If testing the ignore directive, start with output disable set to true");
840       _builder.newLine();
841       _builder.append("        ");
842       _builder.append("output.raw = opt.test_output_raw;");
843       _builder.newLine();
844       _builder.newLine();
845       _builder.newLine();
846       _builder.append("        ");
847       _builder.append("// Stack of parsing/formatting states, including MODE.");
848       _builder.newLine();
849       _builder.append("        ");
850       _builder.append("// We tokenize, parse, and output in an almost purely a forward-only stream of token input");
851       _builder.newLine();
852       _builder.append("        ");
853       _builder.append("// and formatted output.  This makes the beautifier less accurate than full parsers");
854       _builder.newLine();
855       _builder.append("        ");
856       _builder.append("// but also far more tolerant of syntax errors.");
857       _builder.newLine();
858       _builder.append("        ");
859       _builder.append("//");
860       _builder.newLine();
861       _builder.append("        ");
862       _builder.append("// For example, the default mode is MODE.BlockStatement. If we see a \'{\' we push a new frame of type");
863       _builder.newLine();
864       _builder.append("        ");
865       _builder.append("// MODE.BlockStatement on the the stack, even though it could be object literal.  If we later");
866       _builder.newLine();
867       _builder.append("        ");
868       _builder.append("// encounter a \":\", we\'ll switch to to MODE.ObjectLiteral.  If we then see a \";\",");
869       _builder.newLine();
870       _builder.append("        ");
871       _builder.append("// most full parsers would die, but the beautifier gracefully falls back to");
872       _builder.newLine();
873       _builder.append("        ");
874       _builder.append("// MODE.BlockStatement and continues on.");
875       _builder.newLine();
876       _builder.append("        ");
877       _builder.append("flag_store = [];");
878       _builder.newLine();
879       _builder.append("        ");
880       _builder.append("set_mode(MODE.BlockStatement);");
881       _builder.newLine();
882       _builder.newLine();
883       _builder.append("        ");
884       _builder.append("this.beautify = function() {");
885       _builder.newLine();
886       _builder.newLine();
887       _builder.append("            ");
888       _builder.append("/*jshint onevar:true */");
889       _builder.newLine();
890       _builder.append("            ");
891       _builder.append("var local_token, sweet_code;");
892       _builder.newLine();
893       _builder.append("            ");
894       _builder.append("Tokenizer = new tokenizer(js_source_text, opt, indent_string);");
895       _builder.newLine();
896       _builder.append("            ");
897       _builder.append("tokens = Tokenizer.tokenize();");
898       _builder.newLine();
899       _builder.append("            ");
900       _builder.append("token_pos = 0;");
901       _builder.newLine();
902       _builder.newLine();
903       _builder.append("            ");
904       _builder.append("while (local_token = get_token()) {");
905       _builder.newLine();
906       _builder.append("                ");
907       _builder.append("for(var i = 0; i < local_token.comments_before.length; i++) {");
908       _builder.newLine();
909       _builder.append("                    ");
910       _builder.append("// The cleanest handling of inline comments is to treat them as though they aren\'t there.");
911       _builder.newLine();
912       _builder.append("                    ");
913       _builder.append("// Just continue formatting and the behavior should be logical.");
914       _builder.newLine();
915       _builder.append("                    ");
916       _builder.append("// Also ignore unknown tokens.  Again, this should result in better behavior.");
917       _builder.newLine();
918       _builder.append("                    ");
919       _builder.append("handle_token(local_token.comments_before[i]);");
920       _builder.newLine();
921       _builder.append("                ");
922       _builder.append("}");
923       _builder.newLine();
924       _builder.append("                ");
925       _builder.append("handle_token(local_token);");
926       _builder.newLine();
927       _builder.newLine();
928       _builder.append("                ");
929       _builder.append("last_last_text = flags.last_text;");
930       _builder.newLine();
931       _builder.append("                ");
932       _builder.append("last_type = local_token.type;");
933       _builder.newLine();
934       _builder.append("                ");
935       _builder.append("flags.last_text = local_token.text;");
936       _builder.newLine();
937       _builder.newLine();
938       _builder.append("                ");
939       _builder.append("token_pos += 1;");
940       _builder.newLine();
941       _builder.append("            ");
942       _builder.append("}");
943       _builder.newLine();
944       _builder.newLine();
945       _builder.append("            ");
946       _builder.append("sweet_code = output.get_code();");
947       _builder.newLine();
948       _builder.append("            ");
949       _builder.append("if (opt.end_with_newline) {");
950       _builder.newLine();
951       _builder.append("                ");
952       _builder.append("sweet_code += \'\\n\';");
953       _builder.newLine();
954       _builder.append("            ");
955       _builder.append("}");
956       _builder.newLine();
957       _builder.newLine();
958       _builder.append("            ");
959       _builder.append("if (opt.eol != \'\\n\') {");
960       _builder.newLine();
961       _builder.append("                ");
962       _builder.append("sweet_code = sweet_code.replace(/[\\n]/g, opt.eol);");
963       _builder.newLine();
964       _builder.append("            ");
965       _builder.append("}");
966       _builder.newLine();
967       _builder.newLine();
968       _builder.append("            ");
969       _builder.append("return sweet_code;");
970       _builder.newLine();
971       _builder.append("        ");
972       _builder.append("};");
973       _builder.newLine();
974       _builder.newLine();
975       _builder.append("        ");
976       _builder.append("function handle_token(local_token) {");
977       _builder.newLine();
978       _builder.append("            ");
979       _builder.append("var newlines = local_token.newlines;");
980       _builder.newLine();
981       _builder.append("            ");
982       _builder.append("var keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);");
983       _builder.newLine();
984       _builder.newLine();
985       _builder.append("            ");
986       _builder.append("if (keep_whitespace) {");
987       _builder.newLine();
988       _builder.append("                ");
989       _builder.append("for (i = 0; i < newlines; i += 1) {");
990       _builder.newLine();
991       _builder.append("                    ");
992       _builder.append("print_newline(i > 0);");
993       _builder.newLine();
994       _builder.append("                ");
995       _builder.append("}");
996       _builder.newLine();
997       _builder.append("            ");
998       _builder.append("} else {");
999       _builder.newLine();
1000       _builder.append("                ");
1001       _builder.append("if (opt.max_preserve_newlines && newlines > opt.max_preserve_newlines) {");
1002       _builder.newLine();
1003       _builder.append("                    ");
1004       _builder.append("newlines = opt.max_preserve_newlines;");
1005       _builder.newLine();
1006       _builder.append("                ");
1007       _builder.append("}");
1008       _builder.newLine();
1009       _builder.newLine();
1010       _builder.append("                ");
1011       _builder.append("if (opt.preserve_newlines) {");
1012       _builder.newLine();
1013       _builder.append("                    ");
1014       _builder.append("if (local_token.newlines > 1) {");
1015       _builder.newLine();
1016       _builder.append("                        ");
1017       _builder.append("print_newline();");
1018       _builder.newLine();
1019       _builder.append("                        ");
1020       _builder.append("for (var i = 1; i < newlines; i += 1) {");
1021       _builder.newLine();
1022       _builder.append("                            ");
1023       _builder.append("print_newline(true);");
1024       _builder.newLine();
1025       _builder.append("                        ");
1026       _builder.append("}");
1027       _builder.newLine();
1028       _builder.append("                    ");
1029       _builder.append("}");
1030       _builder.newLine();
1031       _builder.append("                ");
1032       _builder.append("}");
1033       _builder.newLine();
1034       _builder.append("            ");
1035       _builder.append("}");
1036       _builder.newLine();
1037       _builder.newLine();
1038       _builder.append("            ");
1039       _builder.append("current_token = local_token;");
1040       _builder.newLine();
1041       _builder.append("            ");
1042       _builder.append("handlers[current_token.type]();");
1043       _builder.newLine();
1044       _builder.append("        ");
1045       _builder.append("}");
1046       _builder.newLine();
1047       _builder.newLine();
1048       _builder.append("        ");
1049       _builder.append("// we could use just string.split, but");
1050       _builder.newLine();
1051       _builder.append("        ");
1052       _builder.append("// IE doesn\'t like returning empty strings");
1053       _builder.newLine();
1054       _builder.append("        ");
1055       _builder.append("function split_newlines(s) {");
1056       _builder.newLine();
1057       _builder.append("            ");
1058       _builder.append("//return s.split(/\\x0d\\x0a|\\x0a/);");
1059       _builder.newLine();
1060       _builder.newLine();
1061       _builder.append("            ");
1062       _builder.append("s = s.replace(/\\x0d/g, \'\');");
1063       _builder.newLine();
1064       _builder.append("            ");
1065       _builder.append("var out = [],");
1066       _builder.newLine();
1067       _builder.append("                ");
1068       _builder.append("idx = s.indexOf(\"\\n\");");
1069       _builder.newLine();
1070       _builder.append("            ");
1071       _builder.append("while (idx !== -1) {");
1072       _builder.newLine();
1073       _builder.append("                ");
1074       _builder.append("out.push(s.substring(0, idx));");
1075       _builder.newLine();
1076       _builder.append("                ");
1077       _builder.append("s = s.substring(idx + 1);");
1078       _builder.newLine();
1079       _builder.append("                ");
1080       _builder.append("idx = s.indexOf(\"\\n\");");
1081       _builder.newLine();
1082       _builder.append("            ");
1083       _builder.append("}");
1084       _builder.newLine();
1085       _builder.append("            ");
1086       _builder.append("if (s.length) {");
1087       _builder.newLine();
1088       _builder.append("                ");
1089       _builder.append("out.push(s);");
1090       _builder.newLine();
1091       _builder.append("            ");
1092       _builder.append("}");
1093       _builder.newLine();
1094       _builder.append("            ");
1095       _builder.append("return out;");
1096       _builder.newLine();
1097       _builder.append("        ");
1098       _builder.append("}");
1099       _builder.newLine();
1100       _builder.newLine();
1101       _builder.append("        ");
1102       _builder.append("function allow_wrap_or_preserved_newline(force_linewrap) {");
1103       _builder.newLine();
1104       _builder.append("            ");
1105       _builder.append("force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;");
1106       _builder.newLine();
1107       _builder.newLine();
1108       _builder.append("            ");
1109       _builder.append("// Never wrap the first token on a line");
1110       _builder.newLine();
1111       _builder.append("            ");
1112       _builder.append("if (output.just_added_newline()) {");
1113       _builder.newLine();
1114       _builder.append("                ");
1115       _builder.append("return");
1116       _builder.newLine();
1117       _builder.append("            ");
1118       _builder.append("}");
1119       _builder.newLine();
1120       _builder.newLine();
1121       _builder.append("            ");
1122       _builder.append("if ((opt.preserve_newlines && current_token.wanted_newline) || force_linewrap) {");
1123       _builder.newLine();
1124       _builder.append("                ");
1125       _builder.append("print_newline(false, true);");
1126       _builder.newLine();
1127       _builder.append("            ");
1128       _builder.append("} else if (opt.wrap_line_length) {");
1129       _builder.newLine();
1130       _builder.append("                ");
1131       _builder.append("var proposed_line_length = output.current_line.get_character_count() + current_token.text.length +");
1132       _builder.newLine();
1133       _builder.append("                    ");
1134       _builder.append("(output.space_before_token ? 1 : 0);");
1135       _builder.newLine();
1136       _builder.append("                ");
1137       _builder.append("if (proposed_line_length >= opt.wrap_line_length) {");
1138       _builder.newLine();
1139       _builder.append("                    ");
1140       _builder.append("print_newline(false, true);");
1141       _builder.newLine();
1142       _builder.append("                ");
1143       _builder.append("}");
1144       _builder.newLine();
1145       _builder.append("            ");
1146       _builder.append("}");
1147       _builder.newLine();
1148       _builder.append("        ");
1149       _builder.append("}");
1150       _builder.newLine();
1151       _builder.newLine();
1152       _builder.append("        ");
1153       _builder.append("function print_newline(force_newline, preserve_statement_flags) {");
1154       _builder.newLine();
1155       _builder.append("            ");
1156       _builder.append("if (!preserve_statement_flags) {");
1157       _builder.newLine();
1158       _builder.append("                ");
1159       _builder.append("if (flags.last_text !== \';\' && flags.last_text !== \',\' && flags.last_text !== \'=\' && last_type !== \'TK_OPERATOR\') {");
1160       _builder.newLine();
1161       _builder.append("                    ");
1162       _builder.append("while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {");
1163       _builder.newLine();
1164       _builder.append("                        ");
1165       _builder.append("restore_mode();");
1166       _builder.newLine();
1167       _builder.append("                    ");
1168       _builder.append("}");
1169       _builder.newLine();
1170       _builder.append("                ");
1171       _builder.append("}");
1172       _builder.newLine();
1173       _builder.append("            ");
1174       _builder.append("}");
1175       _builder.newLine();
1176       _builder.newLine();
1177       _builder.append("            ");
1178       _builder.append("if (output.add_new_line(force_newline)) {");
1179       _builder.newLine();
1180       _builder.append("                ");
1181       _builder.append("flags.multiline_frame = true;");
1182       _builder.newLine();
1183       _builder.append("            ");
1184       _builder.append("}");
1185       _builder.newLine();
1186       _builder.append("        ");
1187       _builder.append("}");
1188       _builder.newLine();
1189       _builder.newLine();
1190       _builder.append("        ");
1191       _builder.append("function print_token_line_indentation() {");
1192       _builder.newLine();
1193       _builder.append("            ");
1194       _builder.append("if (output.just_added_newline()) {");
1195       _builder.newLine();
1196       _builder.append("                ");
1197       _builder.append("if (opt.keep_array_indentation && is_array(flags.mode) && current_token.wanted_newline) {");
1198       _builder.newLine();
1199       _builder.append("                    ");
1200       _builder.append("output.current_line.push(current_token.whitespace_before);");
1201       _builder.newLine();
1202       _builder.append("                    ");
1203       _builder.append("output.space_before_token = false;");
1204       _builder.newLine();
1205       _builder.append("                ");
1206       _builder.append("} else if (output.set_indent(flags.indentation_level)) {");
1207       _builder.newLine();
1208       _builder.append("                    ");
1209       _builder.append("flags.line_indent_level = flags.indentation_level;");
1210       _builder.newLine();
1211       _builder.append("                ");
1212       _builder.append("}");
1213       _builder.newLine();
1214       _builder.append("            ");
1215       _builder.append("}");
1216       _builder.newLine();
1217       _builder.append("        ");
1218       _builder.append("}");
1219       _builder.newLine();
1220       _builder.newLine();
1221       _builder.append("        ");
1222       _builder.append("function print_token(printable_token) {");
1223       _builder.newLine();
1224       _builder.append("            ");
1225       _builder.append("if (output.raw) {");
1226       _builder.newLine();
1227       _builder.append("                ");
1228       _builder.append("output.add_raw_token(current_token)");
1229       _builder.newLine();
1230       _builder.append("                ");
1231       _builder.append("return;");
1232       _builder.newLine();
1233       _builder.append("            ");
1234       _builder.append("}");
1235       _builder.newLine();
1236       _builder.newLine();
1237       _builder.append("            ");
1238       _builder.append("if (opt.comma_first && last_type === \'TK_COMMA\'");
1239       _builder.newLine();
1240       _builder.append("                ");
1241       _builder.append("&& output.just_added_newline()) {");
1242       _builder.newLine();
1243       _builder.append("                ");
1244       _builder.append("if(output.previous_line.last() === \',\') {");
1245       _builder.newLine();
1246       _builder.append("                    ");
1247       _builder.append("output.previous_line.pop();");
1248       _builder.newLine();
1249       _builder.append("                    ");
1250       _builder.append("print_token_line_indentation();");
1251       _builder.newLine();
1252       _builder.append("                    ");
1253       _builder.append("output.add_token(\',\');");
1254       _builder.newLine();
1255       _builder.append("                    ");
1256       _builder.append("output.space_before_token = true;");
1257       _builder.newLine();
1258       _builder.append("                ");
1259       _builder.append("}");
1260       _builder.newLine();
1261       _builder.append("            ");
1262       _builder.append("}");
1263       _builder.newLine();
1264       _builder.newLine();
1265       _builder.append("            ");
1266       _builder.append("printable_token = printable_token || current_token.text;");
1267       _builder.newLine();
1268       _builder.append("            ");
1269       _builder.append("print_token_line_indentation();");
1270       _builder.newLine();
1271       _builder.append("            ");
1272       _builder.append("output.add_token(printable_token);");
1273       _builder.newLine();
1274       _builder.append("        ");
1275       _builder.append("}");
1276       _builder.newLine();
1277       _builder.newLine();
1278       _builder.append("        ");
1279       _builder.append("function indent() {");
1280       _builder.newLine();
1281       _builder.append("            ");
1282       _builder.append("flags.indentation_level += 1;");
1283       _builder.newLine();
1284       _builder.append("        ");
1285       _builder.append("}");
1286       _builder.newLine();
1287       _builder.newLine();
1288       _builder.append("        ");
1289       _builder.append("function deindent() {");
1290       _builder.newLine();
1291       _builder.append("            ");
1292       _builder.append("if (flags.indentation_level > 0 &&");
1293       _builder.newLine();
1294       _builder.append("                ");
1295       _builder.append("((!flags.parent) || flags.indentation_level > flags.parent.indentation_level))");
1296       _builder.newLine();
1297       _builder.append("                ");
1298       _builder.append("flags.indentation_level -= 1;");
1299       _builder.newLine();
1300       _builder.append("        ");
1301       _builder.append("}");
1302       _builder.newLine();
1303       _builder.newLine();
1304       _builder.append("        ");
1305       _builder.append("function set_mode(mode) {");
1306       _builder.newLine();
1307       _builder.append("            ");
1308       _builder.append("if (flags) {");
1309       _builder.newLine();
1310       _builder.append("                ");
1311       _builder.append("flag_store.push(flags);");
1312       _builder.newLine();
1313       _builder.append("                ");
1314       _builder.append("previous_flags = flags;");
1315       _builder.newLine();
1316       _builder.append("            ");
1317       _builder.append("} else {");
1318       _builder.newLine();
1319       _builder.append("                ");
1320       _builder.append("previous_flags = create_flags(null, mode);");
1321       _builder.newLine();
1322       _builder.append("            ");
1323       _builder.append("}");
1324       _builder.newLine();
1325       _builder.newLine();
1326       _builder.append("            ");
1327       _builder.append("flags = create_flags(previous_flags, mode);");
1328       _builder.newLine();
1329       _builder.append("        ");
1330       _builder.append("}");
1331       _builder.newLine();
1332       _builder.newLine();
1333       _builder.append("        ");
1334       _builder.append("function is_array(mode) {");
1335       _builder.newLine();
1336       _builder.append("            ");
1337       _builder.append("return mode === MODE.ArrayLiteral;");
1338       _builder.newLine();
1339       _builder.append("        ");
1340       _builder.append("}");
1341       _builder.newLine();
1342       _builder.newLine();
1343       _builder.append("        ");
1344       _builder.append("function is_expression(mode) {");
1345       _builder.newLine();
1346       _builder.append("            ");
1347       _builder.append("return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);");
1348       _builder.newLine();
1349       _builder.append("        ");
1350       _builder.append("}");
1351       _builder.newLine();
1352       _builder.newLine();
1353       _builder.append("        ");
1354       _builder.append("function restore_mode() {");
1355       _builder.newLine();
1356       _builder.append("            ");
1357       _builder.append("if (flag_store.length > 0) {");
1358       _builder.newLine();
1359       _builder.append("                ");
1360       _builder.append("previous_flags = flags;");
1361       _builder.newLine();
1362       _builder.append("                ");
1363       _builder.append("flags = flag_store.pop();");
1364       _builder.newLine();
1365       _builder.append("                ");
1366       _builder.append("if (previous_flags.mode === MODE.Statement) {");
1367       _builder.newLine();
1368       _builder.append("                    ");
1369       _builder.append("output.remove_redundant_indentation(previous_flags);");
1370       _builder.newLine();
1371       _builder.append("                ");
1372       _builder.append("}");
1373       _builder.newLine();
1374       _builder.append("            ");
1375       _builder.append("}");
1376       _builder.newLine();
1377       _builder.append("        ");
1378       _builder.append("}");
1379       _builder.newLine();
1380       _builder.newLine();
1381       _builder.append("        ");
1382       _builder.append("function start_of_object_property() {");
1383       _builder.newLine();
1384       _builder.append("            ");
1385       _builder.append("return flags.parent.mode === MODE.ObjectLiteral && flags.mode === MODE.Statement && (");
1386       _builder.newLine();
1387       _builder.append("                ");
1388       _builder.append("(flags.last_text === \':\' && flags.ternary_depth === 0) || (last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'get\', \'set\'])));");
1389       _builder.newLine();
1390       _builder.append("        ");
1391       _builder.append("}");
1392       _builder.newLine();
1393       _builder.newLine();
1394       _builder.append("        ");
1395       _builder.append("function start_of_statement() {");
1396       _builder.newLine();
1397       _builder.append("            ");
1398       _builder.append("if (");
1399       _builder.newLine();
1400       _builder.append("                    ");
1401       _builder.append("(last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'var\', \'let\', \'const\']) && current_token.type === \'TK_WORD\') ||");
1402       _builder.newLine();
1403       _builder.append("                    ");
1404       _builder.append("(last_type === \'TK_RESERVED\' && flags.last_text === \'do\') ||");
1405       _builder.newLine();
1406       _builder.append("                    ");
1407       _builder.append("(last_type === \'TK_RESERVED\' && flags.last_text === \'return\' && !current_token.wanted_newline) ||");
1408       _builder.newLine();
1409       _builder.append("                    ");
1410       _builder.append("(last_type === \'TK_RESERVED\' && flags.last_text === \'else\' && !(current_token.type === \'TK_RESERVED\' && current_token.text === \'if\')) ||");
1411       _builder.newLine();
1412       _builder.append("                    ");
1413       _builder.append("(last_type === \'TK_END_EXPR\' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)) ||");
1414       _builder.newLine();
1415       _builder.append("                    ");
1416       _builder.append("(last_type === \'TK_WORD\' && flags.mode === MODE.BlockStatement");
1417       _builder.newLine();
1418       _builder.append("                        ");
1419       _builder.append("&& !flags.in_case");
1420       _builder.newLine();
1421       _builder.append("                        ");
1422       _builder.append("&& !(current_token.text === \'--\' || current_token.text === \'++\')");
1423       _builder.newLine();
1424       _builder.append("                        ");
1425       _builder.append("&& last_last_text !== \'function\'");
1426       _builder.newLine();
1427       _builder.append("                        ");
1428       _builder.append("&& current_token.type !== \'TK_WORD\' && current_token.type !== \'TK_RESERVED\') ||");
1429       _builder.newLine();
1430       _builder.append("                    ");
1431       _builder.append("(flags.mode === MODE.ObjectLiteral && (");
1432       _builder.newLine();
1433       _builder.append("                        ");
1434       _builder.append("(flags.last_text === \':\' && flags.ternary_depth === 0) || (last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'get\', \'set\']))))");
1435       _builder.newLine();
1436       _builder.append("                ");
1437       _builder.append(") {");
1438       _builder.newLine();
1439       _builder.newLine();
1440       _builder.append("                ");
1441       _builder.append("set_mode(MODE.Statement);");
1442       _builder.newLine();
1443       _builder.append("                ");
1444       _builder.append("indent();");
1445       _builder.newLine();
1446       _builder.newLine();
1447       _builder.append("                ");
1448       _builder.append("if (last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'var\', \'let\', \'const\']) && current_token.type === \'TK_WORD\') {");
1449       _builder.newLine();
1450       _builder.append("                    ");
1451       _builder.append("flags.declaration_statement = true;");
1452       _builder.newLine();
1453       _builder.append("                ");
1454       _builder.append("}");
1455       _builder.newLine();
1456       _builder.newLine();
1457       _builder.append("                ");
1458       _builder.append("// Issue #276:");
1459       _builder.newLine();
1460       _builder.append("                ");
1461       _builder.append("// If starting a new statement with [if, for, while, do], push to a new line.");
1462       _builder.newLine();
1463       _builder.append("                ");
1464       _builder.append("// if (a) if (b) if(c) d(); else e(); else f();");
1465       _builder.newLine();
1466       _builder.append("                ");
1467       _builder.append("if (!start_of_object_property()) {");
1468       _builder.newLine();
1469       _builder.append("                    ");
1470       _builder.append("allow_wrap_or_preserved_newline(");
1471       _builder.newLine();
1472       _builder.append("                        ");
1473       _builder.append("current_token.type === \'TK_RESERVED\' && in_array(current_token.text, [\'do\', \'for\', \'if\', \'while\']));");
1474       _builder.newLine();
1475       _builder.append("                ");
1476       _builder.append("}");
1477       _builder.newLine();
1478       _builder.newLine();
1479       _builder.append("                ");
1480       _builder.append("return true;");
1481       _builder.newLine();
1482       _builder.append("            ");
1483       _builder.append("}");
1484       _builder.newLine();
1485       _builder.append("            ");
1486       _builder.append("return false;");
1487       _builder.newLine();
1488       _builder.append("        ");
1489       _builder.append("}");
1490       _builder.newLine();
1491       _builder.newLine();
1492       _builder.append("        ");
1493       _builder.append("function all_lines_start_with(lines, c) {");
1494       _builder.newLine();
1495       _builder.append("            ");
1496       _builder.append("for (var i = 0; i < lines.length; i++) {");
1497       _builder.newLine();
1498       _builder.append("                ");
1499       _builder.append("var line = trim(lines[i]);");
1500       _builder.newLine();
1501       _builder.append("                ");
1502       _builder.append("if (line.charAt(0) !== c) {");
1503       _builder.newLine();
1504       _builder.append("                    ");
1505       _builder.append("return false;");
1506       _builder.newLine();
1507       _builder.append("                ");
1508       _builder.append("}");
1509       _builder.newLine();
1510       _builder.append("            ");
1511       _builder.append("}");
1512       _builder.newLine();
1513       _builder.append("            ");
1514       _builder.append("return true;");
1515       _builder.newLine();
1516       _builder.append("        ");
1517       _builder.append("}");
1518       _builder.newLine();
1519       _builder.newLine();
1520       _builder.append("        ");
1521       _builder.append("function each_line_matches_indent(lines, indent) {");
1522       _builder.newLine();
1523       _builder.append("            ");
1524       _builder.append("var i = 0,");
1525       _builder.newLine();
1526       _builder.append("                ");
1527       _builder.append("len = lines.length,");
1528       _builder.newLine();
1529       _builder.append("                ");
1530       _builder.append("line;");
1531       _builder.newLine();
1532       _builder.append("            ");
1533       _builder.append("for (; i < len; i++) {");
1534       _builder.newLine();
1535       _builder.append("                ");
1536       _builder.append("line = lines[i];");
1537       _builder.newLine();
1538       _builder.append("                ");
1539       _builder.append("// allow empty lines to pass through");
1540       _builder.newLine();
1541       _builder.append("                ");
1542       _builder.append("if (line && line.indexOf(indent) !== 0) {");
1543       _builder.newLine();
1544       _builder.append("                    ");
1545       _builder.append("return false;");
1546       _builder.newLine();
1547       _builder.append("                ");
1548       _builder.append("}");
1549       _builder.newLine();
1550       _builder.append("            ");
1551       _builder.append("}");
1552       _builder.newLine();
1553       _builder.append("            ");
1554       _builder.append("return true;");
1555       _builder.newLine();
1556       _builder.append("        ");
1557       _builder.append("}");
1558       _builder.newLine();
1559       _builder.newLine();
1560       _builder.append("        ");
1561       _builder.append("function is_special_word(word) {");
1562       _builder.newLine();
1563       _builder.append("            ");
1564       _builder.append("return in_array(word, [\'case\', \'return\', \'do\', \'if\', \'throw\', \'else\']);");
1565       _builder.newLine();
1566       _builder.append("        ");
1567       _builder.append("}");
1568       _builder.newLine();
1569       _builder.newLine();
1570       _builder.append("        ");
1571       _builder.append("function get_token(offset) {");
1572       _builder.newLine();
1573       _builder.append("            ");
1574       _builder.append("var index = token_pos + (offset || 0);");
1575       _builder.newLine();
1576       _builder.append("            ");
1577       _builder.append("return (index < 0 || index >= tokens.length) ? null : tokens[index];");
1578       _builder.newLine();
1579       _builder.append("        ");
1580       _builder.append("}");
1581       _builder.newLine();
1582       _builder.newLine();
1583       _builder.append("        ");
1584       _builder.append("function handle_start_expr() {");
1585       _builder.newLine();
1586       _builder.append("            ");
1587       _builder.append("if (start_of_statement()) {");
1588       _builder.newLine();
1589       _builder.append("                ");
1590       _builder.append("// The conditional starts the statement if appropriate.");
1591       _builder.newLine();
1592       _builder.append("            ");
1593       _builder.append("}");
1594       _builder.newLine();
1595       _builder.newLine();
1596       _builder.append("            ");
1597       _builder.append("var next_mode = MODE.Expression;");
1598       _builder.newLine();
1599       _builder.append("            ");
1600       _builder.append("if (current_token.text === \'[\') {");
1601       _builder.newLine();
1602       _builder.newLine();
1603       _builder.append("                ");
1604       _builder.append("if (last_type === \'TK_WORD\' || flags.last_text === \')\') {");
1605       _builder.newLine();
1606       _builder.append("                    ");
1607       _builder.append("// this is array index specifier, break immediately");
1608       _builder.newLine();
1609       _builder.append("                    ");
1610       _builder.append("// a[x], fn()[x]");
1611       _builder.newLine();
1612       _builder.append("                    ");
1613       _builder.append("if (last_type === \'TK_RESERVED\' && in_array(flags.last_text, Tokenizer.line_starters)) {");
1614       _builder.newLine();
1615       _builder.append("                        ");
1616       _builder.append("output.space_before_token = true;");
1617       _builder.newLine();
1618       _builder.append("                    ");
1619       _builder.append("}");
1620       _builder.newLine();
1621       _builder.append("                    ");
1622       _builder.append("set_mode(next_mode);");
1623       _builder.newLine();
1624       _builder.append("                    ");
1625       _builder.append("print_token();");
1626       _builder.newLine();
1627       _builder.append("                    ");
1628       _builder.append("indent();");
1629       _builder.newLine();
1630       _builder.append("                    ");
1631       _builder.append("if (opt.space_in_paren) {");
1632       _builder.newLine();
1633       _builder.append("                        ");
1634       _builder.append("output.space_before_token = true;");
1635       _builder.newLine();
1636       _builder.append("                    ");
1637       _builder.append("}");
1638       _builder.newLine();
1639       _builder.append("                    ");
1640       _builder.append("return;");
1641       _builder.newLine();
1642       _builder.append("                ");
1643       _builder.append("}");
1644       _builder.newLine();
1645       _builder.newLine();
1646       _builder.append("                ");
1647       _builder.append("next_mode = MODE.ArrayLiteral;");
1648       _builder.newLine();
1649       _builder.append("                ");
1650       _builder.append("if (is_array(flags.mode)) {");
1651       _builder.newLine();
1652       _builder.append("                    ");
1653       _builder.append("if (flags.last_text === \'[\' ||");
1654       _builder.newLine();
1655       _builder.append("                        ");
1656       _builder.append("(flags.last_text === \',\' && (last_last_text === \']\' || last_last_text === \'}\'))) {");
1657       _builder.newLine();
1658       _builder.append("                        ");
1659       _builder.append("// ], [ goes to new line");
1660       _builder.newLine();
1661       _builder.append("                        ");
1662       _builder.append("// }, [ goes to new line");
1663       _builder.newLine();
1664       _builder.append("                        ");
1665       _builder.append("if (!opt.keep_array_indentation) {");
1666       _builder.newLine();
1667       _builder.append("                            ");
1668       _builder.append("print_newline();");
1669       _builder.newLine();
1670       _builder.append("                        ");
1671       _builder.append("}");
1672       _builder.newLine();
1673       _builder.append("                    ");
1674       _builder.append("}");
1675       _builder.newLine();
1676       _builder.append("                ");
1677       _builder.append("}");
1678       _builder.newLine();
1679       _builder.newLine();
1680       _builder.append("            ");
1681       _builder.append("} else {");
1682       _builder.newLine();
1683       _builder.append("                ");
1684       _builder.append("if (last_type === \'TK_RESERVED\' && flags.last_text === \'for\') {");
1685       _builder.newLine();
1686       _builder.append("                    ");
1687       _builder.append("next_mode = MODE.ForInitializer;");
1688       _builder.newLine();
1689       _builder.append("                ");
1690       _builder.append("} else if (last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'if\', \'while\'])) {");
1691       _builder.newLine();
1692       _builder.append("                    ");
1693       _builder.append("next_mode = MODE.Conditional;");
1694       _builder.newLine();
1695       _builder.append("                ");
1696       _builder.append("} else {");
1697       _builder.newLine();
1698       _builder.append("                    ");
1699       _builder.append("// next_mode = MODE.Expression;");
1700       _builder.newLine();
1701       _builder.append("                ");
1702       _builder.append("}");
1703       _builder.newLine();
1704       _builder.append("            ");
1705       _builder.append("}");
1706       _builder.newLine();
1707       _builder.newLine();
1708       _builder.append("            ");
1709       _builder.append("if (flags.last_text === \';\' || last_type === \'TK_START_BLOCK\') {");
1710       _builder.newLine();
1711       _builder.append("                ");
1712       _builder.append("print_newline();");
1713       _builder.newLine();
1714       _builder.append("            ");
1715       _builder.append("} else if (last_type === \'TK_END_EXPR\' || last_type === \'TK_START_EXPR\' || last_type === \'TK_END_BLOCK\' || flags.last_text === \'.\') {");
1716       _builder.newLine();
1717       _builder.append("                ");
1718       _builder.append("// TODO: Consider whether forcing this is required.  Review failing tests when removed.");
1719       _builder.newLine();
1720       _builder.append("                ");
1721       _builder.append("allow_wrap_or_preserved_newline(current_token.wanted_newline);");
1722       _builder.newLine();
1723       _builder.append("                ");
1724       _builder.append("// do nothing on (( and )( and ][ and ]( and .(");
1725       _builder.newLine();
1726       _builder.append("            ");
1727       _builder.append("} else if (!(last_type === \'TK_RESERVED\' && current_token.text === \'(\') && last_type !== \'TK_WORD\' && last_type !== \'TK_OPERATOR\') {");
1728       _builder.newLine();
1729       _builder.append("                ");
1730       _builder.append("output.space_before_token = true;");
1731       _builder.newLine();
1732       _builder.append("            ");
1733       _builder.append("} else if ((last_type === \'TK_RESERVED\' && (flags.last_word === \'function\' || flags.last_word === \'typeof\')) ||");
1734       _builder.newLine();
1735       _builder.append("                ");
1736       _builder.append("(flags.last_text === \'*\' && last_last_text === \'function\')) {");
1737       _builder.newLine();
1738       _builder.append("                ");
1739       _builder.append("// function() vs function ()");
1740       _builder.newLine();
1741       _builder.append("                ");
1742       _builder.append("if (opt.space_after_anon_function) {");
1743       _builder.newLine();
1744       _builder.append("                    ");
1745       _builder.append("output.space_before_token = true;");
1746       _builder.newLine();
1747       _builder.append("                ");
1748       _builder.append("}");
1749       _builder.newLine();
1750       _builder.append("            ");
1751       _builder.append("} else if (last_type === \'TK_RESERVED\' && (in_array(flags.last_text, Tokenizer.line_starters) || flags.last_text === \'catch\')) {");
1752       _builder.newLine();
1753       _builder.append("                ");
1754       _builder.append("if (opt.space_before_conditional) {");
1755       _builder.newLine();
1756       _builder.append("                    ");
1757       _builder.append("output.space_before_token = true;");
1758       _builder.newLine();
1759       _builder.append("                ");
1760       _builder.append("}");
1761       _builder.newLine();
1762       _builder.append("            ");
1763       _builder.append("}");
1764       _builder.newLine();
1765       _builder.newLine();
1766       _builder.append("            ");
1767       _builder.append("// Should be a space between await and an IIFE");
1768       _builder.newLine();
1769       _builder.append("            ");
1770       _builder.append("if(current_token.text === \'(\' && last_type === \'TK_RESERVED\' && flags.last_word === \'await\'){");
1771       _builder.newLine();
1772       _builder.append("                ");
1773       _builder.append("output.space_before_token = true;");
1774       _builder.newLine();
1775       _builder.append("            ");
1776       _builder.append("}");
1777       _builder.newLine();
1778       _builder.newLine();
1779       _builder.append("            ");
1780       _builder.append("// Support of this kind of newline preservation.");
1781       _builder.newLine();
1782       _builder.append("            ");
1783       _builder.append("// a = (b &&");
1784       _builder.newLine();
1785       _builder.append("            ");
1786       _builder.append("//     (c || d));");
1787       _builder.newLine();
1788       _builder.append("            ");
1789       _builder.append("if (current_token.text === \'(\') {");
1790       _builder.newLine();
1791       _builder.append("                ");
1792       _builder.append("if (last_type === \'TK_EQUALS\' || last_type === \'TK_OPERATOR\') {");
1793       _builder.newLine();
1794       _builder.append("                    ");
1795       _builder.append("if (!start_of_object_property()) {");
1796       _builder.newLine();
1797       _builder.append("                        ");
1798       _builder.append("allow_wrap_or_preserved_newline();");
1799       _builder.newLine();
1800       _builder.append("                    ");
1801       _builder.append("}");
1802       _builder.newLine();
1803       _builder.append("                ");
1804       _builder.append("}");
1805       _builder.newLine();
1806       _builder.append("            ");
1807       _builder.append("}");
1808       _builder.newLine();
1809       _builder.newLine();
1810       _builder.append("            ");
1811       _builder.append("set_mode(next_mode);");
1812       _builder.newLine();
1813       _builder.append("            ");
1814       _builder.append("print_token();");
1815       _builder.newLine();
1816       _builder.append("            ");
1817       _builder.append("if (opt.space_in_paren) {");
1818       _builder.newLine();
1819       _builder.append("                ");
1820       _builder.append("output.space_before_token = true;");
1821       _builder.newLine();
1822       _builder.append("            ");
1823       _builder.append("}");
1824       _builder.newLine();
1825       _builder.newLine();
1826       _builder.append("            ");
1827       _builder.append("// In all cases, if we newline while inside an expression it should be indented.");
1828       _builder.newLine();
1829       _builder.append("            ");
1830       _builder.append("indent();");
1831       _builder.newLine();
1832       _builder.append("        ");
1833       _builder.append("}");
1834       _builder.newLine();
1835       _builder.newLine();
1836       _builder.append("        ");
1837       _builder.append("function handle_end_expr() {");
1838       _builder.newLine();
1839       _builder.append("            ");
1840       _builder.append("// statements inside expressions are not valid syntax, but...");
1841       _builder.newLine();
1842       _builder.append("            ");
1843       _builder.append("// statements must all be closed when their container closes");
1844       _builder.newLine();
1845       _builder.append("            ");
1846       _builder.append("while (flags.mode === MODE.Statement) {");
1847       _builder.newLine();
1848       _builder.append("                ");
1849       _builder.append("restore_mode();");
1850       _builder.newLine();
1851       _builder.append("            ");
1852       _builder.append("}");
1853       _builder.newLine();
1854       _builder.newLine();
1855       _builder.append("            ");
1856       _builder.append("if (flags.multiline_frame) {");
1857       _builder.newLine();
1858       _builder.append("                ");
1859       _builder.append("allow_wrap_or_preserved_newline(current_token.text === \']\' && is_array(flags.mode) && !opt.keep_array_indentation);");
1860       _builder.newLine();
1861       _builder.append("            ");
1862       _builder.append("}");
1863       _builder.newLine();
1864       _builder.newLine();
1865       _builder.append("            ");
1866       _builder.append("if (opt.space_in_paren) {");
1867       _builder.newLine();
1868       _builder.append("                ");
1869       _builder.append("if (last_type === \'TK_START_EXPR\' && ! opt.space_in_empty_paren) {");
1870       _builder.newLine();
1871       _builder.append("                    ");
1872       _builder.append("// () [] no inner space in empty parens like these, ever, ref #320");
1873       _builder.newLine();
1874       _builder.append("                    ");
1875       _builder.append("output.trim();");
1876       _builder.newLine();
1877       _builder.append("                    ");
1878       _builder.append("output.space_before_token = false;");
1879       _builder.newLine();
1880       _builder.append("                ");
1881       _builder.append("} else {");
1882       _builder.newLine();
1883       _builder.append("                    ");
1884       _builder.append("output.space_before_token = true;");
1885       _builder.newLine();
1886       _builder.append("                ");
1887       _builder.append("}");
1888       _builder.newLine();
1889       _builder.append("            ");
1890       _builder.append("}");
1891       _builder.newLine();
1892       _builder.append("            ");
1893       _builder.append("if (current_token.text === \']\' && opt.keep_array_indentation) {");
1894       _builder.newLine();
1895       _builder.append("                ");
1896       _builder.append("print_token();");
1897       _builder.newLine();
1898       _builder.append("                ");
1899       _builder.append("restore_mode();");
1900       _builder.newLine();
1901       _builder.append("            ");
1902       _builder.append("} else {");
1903       _builder.newLine();
1904       _builder.append("                ");
1905       _builder.append("restore_mode();");
1906       _builder.newLine();
1907       _builder.append("                ");
1908       _builder.append("print_token();");
1909       _builder.newLine();
1910       _builder.append("            ");
1911       _builder.append("}");
1912       _builder.newLine();
1913       _builder.append("            ");
1914       _builder.append("output.remove_redundant_indentation(previous_flags);");
1915       _builder.newLine();
1916       _builder.newLine();
1917       _builder.append("            ");
1918       _builder.append("// do {} while () // no statement required after");
1919       _builder.newLine();
1920       _builder.append("            ");
1921       _builder.append("if (flags.do_while && previous_flags.mode === MODE.Conditional) {");
1922       _builder.newLine();
1923       _builder.append("                ");
1924       _builder.append("previous_flags.mode = MODE.Expression;");
1925       _builder.newLine();
1926       _builder.append("                ");
1927       _builder.append("flags.do_block = false;");
1928       _builder.newLine();
1929       _builder.append("                ");
1930       _builder.append("flags.do_while = false;");
1931       _builder.newLine();
1932       _builder.newLine();
1933       _builder.append("            ");
1934       _builder.append("}");
1935       _builder.newLine();
1936       _builder.append("        ");
1937       _builder.append("}");
1938       _builder.newLine();
1939       _builder.newLine();
1940       _builder.append("        ");
1941       _builder.append("function handle_start_block() {");
1942       _builder.newLine();
1943       _builder.append("            ");
1944       _builder.append("// Check if this is should be treated as a ObjectLiteral");
1945       _builder.newLine();
1946       _builder.append("            ");
1947       _builder.append("var next_token = get_token(1)");
1948       _builder.newLine();
1949       _builder.append("            ");
1950       _builder.append("var second_token = get_token(2)");
1951       _builder.newLine();
1952       _builder.append("            ");
1953       _builder.append("if (second_token && (");
1954       _builder.newLine();
1955       _builder.append("                    ");
1956       _builder.append("(second_token.text === \':\' && in_array(next_token.type, [\'TK_STRING\', \'TK_WORD\', \'TK_RESERVED\']))");
1957       _builder.newLine();
1958       _builder.append("                    ");
1959       _builder.append("|| (in_array(next_token.text, [\'get\', \'set\']) && in_array(second_token.type, [\'TK_WORD\', \'TK_RESERVED\']))");
1960       _builder.newLine();
1961       _builder.append("                ");
1962       _builder.append(")) {");
1963       _builder.newLine();
1964       _builder.append("                ");
1965       _builder.append("// We don\'t support TypeScript,but we didn\'t break it for a very long time.");
1966       _builder.newLine();
1967       _builder.append("                ");
1968       _builder.append("// We\'ll try to keep not breaking it.");
1969       _builder.newLine();
1970       _builder.append("                ");
1971       _builder.append("if (!in_array(last_last_text, [\'class\',\'interface\'])) {");
1972       _builder.newLine();
1973       _builder.append("                    ");
1974       _builder.append("set_mode(MODE.ObjectLiteral);");
1975       _builder.newLine();
1976       _builder.append("                ");
1977       _builder.append("} else {");
1978       _builder.newLine();
1979       _builder.append("                    ");
1980       _builder.append("set_mode(MODE.BlockStatement);");
1981       _builder.newLine();
1982       _builder.append("                ");
1983       _builder.append("}");
1984       _builder.newLine();
1985       _builder.append("            ");
1986       _builder.append("} else {");
1987       _builder.newLine();
1988       _builder.append("                ");
1989       _builder.append("set_mode(MODE.BlockStatement);");
1990       _builder.newLine();
1991       _builder.append("            ");
1992       _builder.append("}");
1993       _builder.newLine();
1994       _builder.newLine();
1995       _builder.append("            ");
1996       _builder.append("var empty_braces = !next_token.comments_before.length &&  next_token.text === \'}\';");
1997       _builder.newLine();
1998       _builder.append("            ");
1999       _builder.append("var empty_anonymous_function = empty_braces && flags.last_word === \'function\' &&");
2000       _builder.newLine();
2001       _builder.append("                ");
2002       _builder.append("last_type === \'TK_END_EXPR\';");
2003       _builder.newLine();
2004       _builder.newLine();
2005       _builder.append("            ");
2006       _builder.append("if (opt.brace_style === \"expand\" ||");
2007       _builder.newLine();
2008       _builder.append("                ");
2009       _builder.append("(opt.brace_style === \"none\" && current_token.wanted_newline)) {");
2010       _builder.newLine();
2011       _builder.append("                ");
2012       _builder.append("if (last_type !== \'TK_OPERATOR\' &&");
2013       _builder.newLine();
2014       _builder.append("                    ");
2015       _builder.append("(empty_anonymous_function ||");
2016       _builder.newLine();
2017       _builder.append("                        ");
2018       _builder.append("last_type === \'TK_EQUALS\' ||");
2019       _builder.newLine();
2020       _builder.append("                        ");
2021       _builder.append("(last_type === \'TK_RESERVED\' && is_special_word(flags.last_text) && flags.last_text !== \'else\'))) {");
2022       _builder.newLine();
2023       _builder.append("                    ");
2024       _builder.append("output.space_before_token = true;");
2025       _builder.newLine();
2026       _builder.append("                ");
2027       _builder.append("} else {");
2028       _builder.newLine();
2029       _builder.append("                    ");
2030       _builder.append("print_newline(false, true);");
2031       _builder.newLine();
2032       _builder.append("                ");
2033       _builder.append("}");
2034       _builder.newLine();
2035       _builder.append("            ");
2036       _builder.append("} else { // collapse");
2037       _builder.newLine();
2038       _builder.append("                ");
2039       _builder.append("if (last_type !== \'TK_OPERATOR\' && last_type !== \'TK_START_EXPR\') {");
2040       _builder.newLine();
2041       _builder.append("                    ");
2042       _builder.append("if (last_type === \'TK_START_BLOCK\') {");
2043       _builder.newLine();
2044       _builder.append("                        ");
2045       _builder.append("print_newline();");
2046       _builder.newLine();
2047       _builder.append("                    ");
2048       _builder.append("} else {");
2049       _builder.newLine();
2050       _builder.append("                        ");
2051       _builder.append("output.space_before_token = true;");
2052       _builder.newLine();
2053       _builder.append("                    ");
2054       _builder.append("}");
2055       _builder.newLine();
2056       _builder.append("                ");
2057       _builder.append("} else {");
2058       _builder.newLine();
2059       _builder.append("                    ");
2060       _builder.append("// if TK_OPERATOR or TK_START_EXPR");
2061       _builder.newLine();
2062       _builder.append("                    ");
2063       _builder.append("if (is_array(previous_flags.mode) && flags.last_text === \',\') {");
2064       _builder.newLine();
2065       _builder.append("                        ");
2066       _builder.append("if (last_last_text === \'}\') {");
2067       _builder.newLine();
2068       _builder.append("                            ");
2069       _builder.append("// }, { in array context");
2070       _builder.newLine();
2071       _builder.append("                            ");
2072       _builder.append("output.space_before_token = true;");
2073       _builder.newLine();
2074       _builder.append("                        ");
2075       _builder.append("} else {");
2076       _builder.newLine();
2077       _builder.append("                            ");
2078       _builder.append("print_newline(); // [a, b, c, {");
2079       _builder.newLine();
2080       _builder.append("                        ");
2081       _builder.append("}");
2082       _builder.newLine();
2083       _builder.append("                    ");
2084       _builder.append("}");
2085       _builder.newLine();
2086       _builder.append("                ");
2087       _builder.append("}");
2088       _builder.newLine();
2089       _builder.append("            ");
2090       _builder.append("}");
2091       _builder.newLine();
2092       _builder.append("            ");
2093       _builder.append("print_token();");
2094       _builder.newLine();
2095       _builder.append("            ");
2096       _builder.append("indent();");
2097       _builder.newLine();
2098       _builder.append("        ");
2099       _builder.append("}");
2100       _builder.newLine();
2101       _builder.newLine();
2102       _builder.append("        ");
2103       _builder.append("function handle_end_block() {");
2104       _builder.newLine();
2105       _builder.append("            ");
2106       _builder.append("// statements must all be closed when their container closes");
2107       _builder.newLine();
2108       _builder.append("            ");
2109       _builder.append("while (flags.mode === MODE.Statement) {");
2110       _builder.newLine();
2111       _builder.append("                ");
2112       _builder.append("restore_mode();");
2113       _builder.newLine();
2114       _builder.append("            ");
2115       _builder.append("}");
2116       _builder.newLine();
2117       _builder.append("            ");
2118       _builder.append("var empty_braces = last_type === \'TK_START_BLOCK\';");
2119       _builder.newLine();
2120       _builder.newLine();
2121       _builder.append("            ");
2122       _builder.append("if (opt.brace_style === \"expand\") {");
2123       _builder.newLine();
2124       _builder.append("                ");
2125       _builder.append("if (!empty_braces) {");
2126       _builder.newLine();
2127       _builder.append("                    ");
2128       _builder.append("print_newline();");
2129       _builder.newLine();
2130       _builder.append("                ");
2131       _builder.append("}");
2132       _builder.newLine();
2133       _builder.append("            ");
2134       _builder.append("} else {");
2135       _builder.newLine();
2136       _builder.append("                ");
2137       _builder.append("// skip {}");
2138       _builder.newLine();
2139       _builder.append("                ");
2140       _builder.append("if (!empty_braces) {");
2141       _builder.newLine();
2142       _builder.append("                    ");
2143       _builder.append("if (is_array(flags.mode) && opt.keep_array_indentation) {");
2144       _builder.newLine();
2145       _builder.append("                        ");
2146       _builder.append("// we REALLY need a newline here, but newliner would skip that");
2147       _builder.newLine();
2148       _builder.append("                        ");
2149       _builder.append("opt.keep_array_indentation = false;");
2150       _builder.newLine();
2151       _builder.append("                        ");
2152       _builder.append("print_newline();");
2153       _builder.newLine();
2154       _builder.append("                        ");
2155       _builder.append("opt.keep_array_indentation = true;");
2156       _builder.newLine();
2157       _builder.newLine();
2158       _builder.append("                    ");
2159       _builder.append("} else {");
2160       _builder.newLine();
2161       _builder.append("                        ");
2162       _builder.append("print_newline();");
2163       _builder.newLine();
2164       _builder.append("                    ");
2165       _builder.append("}");
2166       _builder.newLine();
2167       _builder.append("                ");
2168       _builder.append("}");
2169       _builder.newLine();
2170       _builder.append("            ");
2171       _builder.append("}");
2172       _builder.newLine();
2173       _builder.append("            ");
2174       _builder.append("restore_mode();");
2175       _builder.newLine();
2176       _builder.append("            ");
2177       _builder.append("print_token();");
2178       _builder.newLine();
2179       _builder.append("        ");
2180       _builder.append("}");
2181       _builder.newLine();
2182       _builder.newLine();
2183       _builder.append("        ");
2184       _builder.append("function handle_word() {");
2185       _builder.newLine();
2186       _builder.append("            ");
2187       _builder.append("if (current_token.type === \'TK_RESERVED\' && flags.mode !== MODE.ObjectLiteral &&");
2188       _builder.newLine();
2189       _builder.append("                ");
2190       _builder.append("in_array(current_token.text, [\'set\', \'get\'])) {");
2191       _builder.newLine();
2192       _builder.append("                ");
2193       _builder.append("current_token.type = \'TK_WORD\';");
2194       _builder.newLine();
2195       _builder.append("            ");
2196       _builder.append("}");
2197       _builder.newLine();
2198       _builder.newLine();
2199       _builder.append("            ");
2200       _builder.append("if (current_token.type === \'TK_RESERVED\' && flags.mode === MODE.ObjectLiteral) {");
2201       _builder.newLine();
2202       _builder.append("                ");
2203       _builder.append("var next_token = get_token(1);");
2204       _builder.newLine();
2205       _builder.append("                ");
2206       _builder.append("if (next_token.text == \':\') {");
2207       _builder.newLine();
2208       _builder.append("                    ");
2209       _builder.append("current_token.type = \'TK_WORD\';");
2210       _builder.newLine();
2211       _builder.append("                ");
2212       _builder.append("}");
2213       _builder.newLine();
2214       _builder.append("            ");
2215       _builder.append("}");
2216       _builder.newLine();
2217       _builder.newLine();
2218       _builder.append("            ");
2219       _builder.append("if (start_of_statement()) {");
2220       _builder.newLine();
2221       _builder.append("                ");
2222       _builder.append("// The conditional starts the statement if appropriate.");
2223       _builder.newLine();
2224       _builder.append("            ");
2225       _builder.append("} else if (current_token.wanted_newline && !is_expression(flags.mode) &&");
2226       _builder.newLine();
2227       _builder.append("                ");
2228       _builder.append("(last_type !== \'TK_OPERATOR\' || (flags.last_text === \'--\' || flags.last_text === \'++\')) &&");
2229       _builder.newLine();
2230       _builder.append("                ");
2231       _builder.append("last_type !== \'TK_EQUALS\' &&");
2232       _builder.newLine();
2233       _builder.append("                ");
2234       _builder.append("(opt.preserve_newlines || !(last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'var\', \'let\', \'const\', \'set\', \'get\'])))) {");
2235       _builder.newLine();
2236       _builder.newLine();
2237       _builder.append("                ");
2238       _builder.append("print_newline();");
2239       _builder.newLine();
2240       _builder.append("            ");
2241       _builder.append("}");
2242       _builder.newLine();
2243       _builder.newLine();
2244       _builder.append("            ");
2245       _builder.append("if (flags.do_block && !flags.do_while) {");
2246       _builder.newLine();
2247       _builder.append("                ");
2248       _builder.append("if (current_token.type === \'TK_RESERVED\' && current_token.text === \'while\') {");
2249       _builder.newLine();
2250       _builder.append("                    ");
2251       _builder.append("// do {} ## while ()");
2252       _builder.newLine();
2253       _builder.append("                    ");
2254       _builder.append("output.space_before_token = true;");
2255       _builder.newLine();
2256       _builder.append("                    ");
2257       _builder.append("print_token();");
2258       _builder.newLine();
2259       _builder.append("                    ");
2260       _builder.append("output.space_before_token = true;");
2261       _builder.newLine();
2262       _builder.append("                    ");
2263       _builder.append("flags.do_while = true;");
2264       _builder.newLine();
2265       _builder.append("                    ");
2266       _builder.append("return;");
2267       _builder.newLine();
2268       _builder.append("                ");
2269       _builder.append("} else {");
2270       _builder.newLine();
2271       _builder.append("                    ");
2272       _builder.append("// do {} should always have while as the next word.");
2273       _builder.newLine();
2274       _builder.append("                    ");
2275       _builder.append("// if we don\'t see the expected while, recover");
2276       _builder.newLine();
2277       _builder.append("                    ");
2278       _builder.append("print_newline();");
2279       _builder.newLine();
2280       _builder.append("                    ");
2281       _builder.append("flags.do_block = false;");
2282       _builder.newLine();
2283       _builder.append("                ");
2284       _builder.append("}");
2285       _builder.newLine();
2286       _builder.append("            ");
2287       _builder.append("}");
2288       _builder.newLine();
2289       _builder.newLine();
2290       _builder.append("            ");
2291       _builder.append("// if may be followed by else, or not");
2292       _builder.newLine();
2293       _builder.append("            ");
2294       _builder.append("// Bare/inline ifs are tricky");
2295       _builder.newLine();
2296       _builder.append("            ");
2297       _builder.append("// Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();");
2298       _builder.newLine();
2299       _builder.append("            ");
2300       _builder.append("if (flags.if_block) {");
2301       _builder.newLine();
2302       _builder.append("                ");
2303       _builder.append("if (!flags.else_block && (current_token.type === \'TK_RESERVED\' && current_token.text === \'else\')) {");
2304       _builder.newLine();
2305       _builder.append("                    ");
2306       _builder.append("flags.else_block = true;");
2307       _builder.newLine();
2308       _builder.append("                ");
2309       _builder.append("} else {");
2310       _builder.newLine();
2311       _builder.append("                    ");
2312       _builder.append("while (flags.mode === MODE.Statement) {");
2313       _builder.newLine();
2314       _builder.append("                        ");
2315       _builder.append("restore_mode();");
2316       _builder.newLine();
2317       _builder.append("                    ");
2318       _builder.append("}");
2319       _builder.newLine();
2320       _builder.append("                    ");
2321       _builder.append("flags.if_block = false;");
2322       _builder.newLine();
2323       _builder.append("                    ");
2324       _builder.append("flags.else_block = false;");
2325       _builder.newLine();
2326       _builder.append("                ");
2327       _builder.append("}");
2328       _builder.newLine();
2329       _builder.append("            ");
2330       _builder.append("}");
2331       _builder.newLine();
2332       _builder.newLine();
2333       _builder.append("            ");
2334       _builder.append("if (current_token.type === \'TK_RESERVED\' && (current_token.text === \'case\' || (current_token.text === \'default\' && flags.in_case_statement))) {");
2335       _builder.newLine();
2336       _builder.append("                ");
2337       _builder.append("print_newline();");
2338       _builder.newLine();
2339       _builder.append("                ");
2340       _builder.append("if (flags.case_body || opt.jslint_happy) {");
2341       _builder.newLine();
2342       _builder.append("                    ");
2343       _builder.append("// switch cases following one another");
2344       _builder.newLine();
2345       _builder.append("                    ");
2346       _builder.append("deindent();");
2347       _builder.newLine();
2348       _builder.append("                    ");
2349       _builder.append("flags.case_body = false;");
2350       _builder.newLine();
2351       _builder.append("                ");
2352       _builder.append("}");
2353       _builder.newLine();
2354       _builder.append("                ");
2355       _builder.append("print_token();");
2356       _builder.newLine();
2357       _builder.append("                ");
2358       _builder.append("flags.in_case = true;");
2359       _builder.newLine();
2360       _builder.append("                ");
2361       _builder.append("flags.in_case_statement = true;");
2362       _builder.newLine();
2363       _builder.append("                ");
2364       _builder.append("return;");
2365       _builder.newLine();
2366       _builder.append("            ");
2367       _builder.append("}");
2368       _builder.newLine();
2369       _builder.newLine();
2370       _builder.append("            ");
2371       _builder.append("if (current_token.type === \'TK_RESERVED\' && current_token.text === \'function\') {");
2372       _builder.newLine();
2373       _builder.append("                ");
2374       _builder.append("if (in_array(flags.last_text, [\'}\', \';\']) || (output.just_added_newline() && ! in_array(flags.last_text, [\'[\', \'{\', \':\', \'=\', \',\']))) {");
2375       _builder.newLine();
2376       _builder.append("                    ");
2377       _builder.append("// make sure there is a nice clean space of at least one blank line");
2378       _builder.newLine();
2379       _builder.append("                    ");
2380       _builder.append("// before a new function definition");
2381       _builder.newLine();
2382       _builder.append("                    ");
2383       _builder.append("if ( !output.just_added_blankline() && !current_token.comments_before.length) {");
2384       _builder.newLine();
2385       _builder.append("                        ");
2386       _builder.append("print_newline();");
2387       _builder.newLine();
2388       _builder.append("                        ");
2389       _builder.append("print_newline(true);");
2390       _builder.newLine();
2391       _builder.append("                    ");
2392       _builder.append("}");
2393       _builder.newLine();
2394       _builder.append("                ");
2395       _builder.append("}");
2396       _builder.newLine();
2397       _builder.append("                ");
2398       _builder.append("if (last_type === \'TK_RESERVED\' || last_type === \'TK_WORD\') {");
2399       _builder.newLine();
2400       _builder.append("                    ");
2401       _builder.append("if (last_type === \'TK_RESERVED\' && in_array(flags.last_text, [\'get\', \'set\', \'new\', \'return\', \'export\', \'async\'])) {");
2402       _builder.newLine();
2403       _builder.append("                        ");
2404       _builder.append("output.space_before_token = true;");
2405       _builder.newLine();
2406       _builder.append("                    ");
2407       _builder.append("} else if (last_type === \'TK_RESERVED\' && flags.last_text === \'default\' && last_last_text === \'export\') {");
2408       _builder.newLine();
2409       _builder.append("                        ");
2410       _builder.append("output.space_before_token = true;");
2411       _builder.newLine();
2412       _builder.append("                    ");
2413       _builder.append("} else {");
2414       _builder.newLine();
2415       _builder.append("                        ");
2416       _builder.append("print_newline();");
2417       _builder.newLine();
2418       _builder.append("                    ");
2419       _builder.append("}");
2420       _builder.newLine();
2421       _builder.append("                ");
2422       _builder.append("} else if (last_type === \'TK_OPERATOR\' || flags.last_text === \'=\') {");
2423       _builder.newLine();
2424       _builder.append("                    ");
2425       _builder.append("// foo = function");
2426       _builder.newLine();
2427       _builder.append("                    ");
2428       _builder.append("output.space_before_token = true;");
2429       _builder.newLine();
2430       _builder.append("                ");
2431       _builder.append("} else if (!flags.multiline_frame && (is_expression(flags.mode) || is_array(flags.mode))) {");
2432       _builder.newLine();
2433       _builder.append("                    ");
2434       _builder.append("// (function");
2435       _builder.newLine();
2436       _builder.append("                ");
2437       _builder.append("} else {");
2438       _builder.newLine();
2439       _builder.append("                    ");
2440       _builder.append("print_newline();");
2441       _builder.newLine();
2442       _builder.append("                ");
2443       _builder.append("}");
2444       _builder.newLine();
2445       _builder.append("            ");
2446       _builder.append("}");
2447       _builder.newLine();
2448       _builder.newLine();
2449       _builder.append("            ");
2450       _builder.append("if (last_type === \'TK_COMMA\' || last_type === \'TK_START_EXPR\' || last_type === \'TK_EQUALS\' || last_type === \'TK_OPERATOR\') {");
2451       _builder.newLine();
2452       _builder.append("                ");
2453       _builder.append("if (!start_of_object_property()) {");
2454       _builder.newLine();
2455       _builder.append("                    ");
2456       _builder.append("allow_wrap_or_preserved_newline();");
2457       _builder.newLine();
2458       _builder.append("                ");
2459       _builder.append("}");
2460       _builder.newLine();
2461       _builder.append("            ");
2462       _builder.append("}");
2463       _builder.newLine();
2464       _builder.newLine();
2465       _builder.append("            ");
2466       _builder.append("if (current_token.type === \'TK_RESERVED\' &&  in_array(current_token.text, [\'function\', \'get\', \'set\'])) {");
2467       _builder.newLine();
2468       _builder.append("                ");
2469       _builder.append("print_token();");
2470       _builder.newLine();
2471       _builder.append("                ");
2472       _builder.append("flags.last_word = current_token.text;");
2473       _builder.newLine();
2474       _builder.append("                ");
2475       _builder.append("return;");
2476       _builder.newLine();
2477       _builder.append("            ");
2478       _builder.append("}");
2479       _builder.newLine();
2480       _builder.newLine();
2481       _builder.append("            ");
2482       _builder.append("prefix = \'NONE\';");
2483       _builder.newLine();
2484       _builder.newLine();
2485       _builder.append("            ");
2486       _builder.append("if (last_type === \'TK_END_BLOCK\') {");
2487       _builder.newLine();
2488       _builder.append("                ");
2489       _builder.append("if (!(current_token.type === \'TK_RESERVED\' && in_array(current_token.text, [\'else\', \'catch\', \'finally\']))) {");
2490       _builder.newLine();
2491       _builder.append("                    ");
2492       _builder.append("prefix = \'NEWLINE\';");
2493       _builder.newLine();
2494       _builder.append("                ");
2495       _builder.append("} else {");
2496       _builder.newLine();
2497       _builder.append("                    ");
2498       _builder.append("if (opt.brace_style === \"expand\" ||");
2499       _builder.newLine();
2500       _builder.append("                        ");
2501       _builder.append("opt.brace_style === \"end-expand\" ||");
2502       _builder.newLine();
2503       _builder.append("                        ");
2504       _builder.append("(opt.brace_style === \"none\" && current_token.wanted_newline)) {");
2505       _builder.newLine();
2506       _builder.append("                        ");
2507       _builder.append("prefix = \'NEWLINE\';");
2508       _builder.newLine();
2509       _builder.append("                    ");
2510       _builder.append("} else {");
2511       _builder.newLine();
2512       _builder.append("                        ");
2513       _builder.append("prefix = \'SPACE\';");
2514       _builder.newLine();
2515       _builder.append("                        ");
2516       _builder.append("output.space_before_token = true;");
2517       _builder.newLine();
2518       _builder.append("                    ");
2519       _builder.append("}");
2520       _builder.newLine();
2521       _builder.append("                ");
2522       _builder.append("}");
2523       _builder.newLine();
2524       _builder.append("            ");
2525       _builder.append("} else if (last_type === \'TK_SEMICOLON\' && flags.mode === MODE.BlockStatement) {");
2526       _builder.newLine();
2527       _builder.append("                ");
2528       _builder.append("// TODO: Should this be for STATEMENT as well?");
2529       _builder.newLine();
2530       _builder.append("                ");
2531       _builder.append("prefix = \'NEWLINE\';");
2532       _builder.newLine();
2533       _builder.append("            ");
2534       _builder.append("} else if (last_type === \'TK_SEMICOLON\' && is_expression(flags.mode)) {");
2535       _builder.newLine();
2536       _builder.append("                ");
2537       _builder.append("prefix = \'SPACE\';");
2538       _builder.newLine();
2539       _builder.append("            ");
2540       _builder.append("} else if (last_type === \'TK_STRING\') {");
2541       _builder.newLine();
2542       _builder.append("                ");
2543       _builder.append("prefix = \'NEWLINE\';");
2544       _builder.newLine();
2545       _builder.append("            ");
2546       _builder.append("} else if (last_type === \'TK_RESERVED\' || last_type === \'TK_WORD\' ||");
2547       _builder.newLine();
2548       _builder.append("                ");
2549       _builder.append("(flags.last_text === \'*\' && last_last_text === \'function\')) {");
2550       _builder.newLine();
2551       _builder.append("                ");
2552       _builder.append("prefix = \'SPACE\';");
2553       _builder.newLine();
2554       _builder.append("            ");
2555       _builder.append("} else if (last_type === \'TK_START_BLOCK\') {");
2556       _builder.newLine();
2557       _builder.append("                ");
2558       _builder.append("prefix = \'NEWLINE\';");
2559       _builder.newLine();
2560       _builder.append("            ");
2561       _builder.append("} else if (last_type === \'TK_END_EXPR\') {");
2562       _builder.newLine();
2563       _builder.append("                ");
2564       _builder.append("output.space_before_token = true;");
2565       _builder.newLine();
2566       _builder.append("                ");
2567       _builder.append("prefix = \'NEWLINE\';");
2568       _builder.newLine();
2569       _builder.append("            ");
2570       _builder.append("}");
2571       _builder.newLine();
2572       _builder.newLine();
2573       _builder.append("            ");
2574       _builder.append("if (current_token.type === \'TK_RESERVED\' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== \')\') {");
2575       _builder.newLine();
2576       _builder.append("                ");
2577       _builder.append("if (flags.last_text === \'else\' || flags.last_text === \'export\') {");
2578       _builder.newLine();
2579       _builder.append("                    ");
2580       _builder.append("prefix = \'SPACE\';");
2581       _builder.newLine();
2582       _builder.append("                ");
2583       _builder.append("} else {");
2584       _builder.newLine();
2585       _builder.append("                    ");
2586       _builder.append("prefix = \'NEWLINE\';");
2587       _builder.newLine();
2588       _builder.append("                ");
2589       _builder.append("}");
2590       _builder.newLine();
2591       _builder.newLine();
2592       _builder.append("            ");
2593       _builder.append("}");
2594       _builder.newLine();
2595       _builder.newLine();
2596       _builder.append("            ");
2597       _builder.append("if (current_token.type === \'TK_RESERVED\' && in_array(current_token.text, [\'else\', \'catch\', \'finally\'])) {");
2598       _builder.newLine();
2599       _builder.append("                ");
2600       _builder.append("if (last_type !== \'TK_END_BLOCK\' ||");
2601       _builder.newLine();
2602       _builder.append("                    ");
2603       _builder.append("opt.brace_style === \"expand\" ||");
2604       _builder.newLine();
2605       _builder.append("                    ");
2606       _builder.append("opt.brace_style === \"end-expand\" ||");
2607       _builder.newLine();
2608       _builder.append("                    ");
2609       _builder.append("(opt.brace_style === \"none\" && current_token.wanted_newline)) {");
2610       _builder.newLine();
2611       _builder.append("                    ");
2612       _builder.append("print_newline();");
2613       _builder.newLine();
2614       _builder.append("                ");
2615       _builder.append("} else {");
2616       _builder.newLine();
2617       _builder.append("                    ");
2618       _builder.append("output.trim(true);");
2619       _builder.newLine();
2620       _builder.append("                    ");
2621       _builder.append("var line = output.current_line;");
2622       _builder.newLine();
2623       _builder.append("                    ");
2624       _builder.append("// If we trimmed and there\'s something other than a close block before us");
2625       _builder.newLine();
2626       _builder.append("                    ");
2627       _builder.append("// put a newline back in.  Handles \'} // comment\' scenario.");
2628       _builder.newLine();
2629       _builder.append("                    ");
2630       _builder.append("if (line.last() !== \'}\') {");
2631       _builder.newLine();
2632       _builder.append("                        ");
2633       _builder.append("print_newline();");
2634       _builder.newLine();
2635       _builder.append("                    ");
2636       _builder.append("}");
2637       _builder.newLine();
2638       _builder.append("                    ");
2639       _builder.append("output.space_before_token = true;");
2640       _builder.newLine();
2641       _builder.append("                ");
2642       _builder.append("}");
2643       _builder.newLine();
2644       _builder.append("            ");
2645       _builder.append("} else if (prefix === \'NEWLINE\') {");
2646       _builder.newLine();
2647       _builder.append("                ");
2648       _builder.append("if (last_type === \'TK_RESERVED\' && is_special_word(flags.last_text)) {");
2649       _builder.newLine();
2650       _builder.append("                    ");
2651       _builder.append("// no newline between \'return nnn\'");
2652       _builder.newLine();
2653       _builder.append("                    ");
2654       _builder.append("output.space_before_token = true;");
2655       _builder.newLine();
2656       _builder.append("                ");
2657       _builder.append("} else if (last_type !== \'TK_END_EXPR\') {");
2658       _builder.newLine();
2659       _builder.append("                    ");
2660       _builder.append("if ((last_type !== \'TK_START_EXPR\' || !(current_token.type === \'TK_RESERVED\' && in_array(current_token.text, [\'var\', \'let\', \'const\']))) && flags.last_text !== \':\') {");
2661       _builder.newLine();
2662       _builder.append("                        ");
2663       _builder.append("// no need to force newline on \'var\': for (var x = 0...)");
2664       _builder.newLine();
2665       _builder.append("                        ");
2666       _builder.append("if (current_token.type === \'TK_RESERVED\' && current_token.text === \'if\' && flags.last_text === \'else\') {");
2667       _builder.newLine();
2668       _builder.append("                            ");
2669       _builder.append("// no newline for } else if {");
2670       _builder.newLine();
2671       _builder.append("                            ");
2672       _builder.append("output.space_before_token = true;");
2673       _builder.newLine();
2674       _builder.append("                        ");
2675       _builder.append("} else {");
2676       _builder.newLine();
2677       _builder.append("                            ");
2678       _builder.append("print_newline();");
2679       _builder.newLine();
2680       _builder.append("                        ");
2681       _builder.append("}");
2682       _builder.newLine();
2683       _builder.append("                    ");
2684       _builder.append("}");
2685       _builder.newLine();
2686       _builder.append("                ");
2687       _builder.append("} else if (current_token.type === \'TK_RESERVED\' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== \')\') {");
2688       _builder.newLine();
2689       _builder.append("                    ");
2690       _builder.append("print_newline();");
2691       _builder.newLine();
2692       _builder.append("                ");
2693       _builder.append("}");
2694       _builder.newLine();
2695       _builder.append("            ");
2696       _builder.append("} else if (flags.multiline_frame && is_array(flags.mode) && flags.last_text === \',\' && last_last_text === \'}\') {");
2697       _builder.newLine();
2698       _builder.append("                ");
2699       _builder.append("print_newline(); // }, in lists get a newline treatment");
2700       _builder.newLine();
2701       _builder.append("            ");
2702       _builder.append("} else if (prefix === \'SPACE\') {");
2703       _builder.newLine();
2704       _builder.append("                ");
2705       _builder.append("output.space_before_token = true;");
2706       _builder.newLine();
2707       _builder.append("            ");
2708       _builder.append("}");
2709       _builder.newLine();
2710       _builder.append("            ");
2711       _builder.append("print_token();");
2712       _builder.newLine();
2713       _builder.append("            ");
2714       _builder.append("flags.last_word = current_token.text;");
2715       _builder.newLine();
2716       _builder.newLine();
2717       _builder.append("            ");
2718       _builder.append("if (current_token.type === \'TK_RESERVED\' && current_token.text === \'do\') {");
2719       _builder.newLine();
2720       _builder.append("                ");
2721       _builder.append("flags.do_block = true;");
2722       _builder.newLine();
2723       _builder.append("            ");
2724       _builder.append("}");
2725       _builder.newLine();
2726       _builder.newLine();
2727       _builder.append("            ");
2728       _builder.append("if (current_token.type === \'TK_RESERVED\' && current_token.text === \'if\') {");
2729       _builder.newLine();
2730       _builder.append("                ");
2731       _builder.append("flags.if_block = true;");
2732       _builder.newLine();
2733       _builder.append("            ");
2734       _builder.append("}");
2735       _builder.newLine();
2736       _builder.append("        ");
2737       _builder.append("}");
2738       _builder.newLine();
2739       _builder.newLine();
2740       _builder.append("        ");
2741       _builder.append("function handle_semicolon() {");
2742       _builder.newLine();
2743       _builder.append("            ");
2744       _builder.append("if (start_of_statement()) {");
2745       _builder.newLine();
2746       _builder.append("                ");
2747       _builder.append("// The conditional starts the statement if appropriate.");
2748       _builder.newLine();
2749       _builder.append("                ");
2750       _builder.append("// Semicolon can be the start (and end) of a statement");
2751       _builder.newLine();
2752       _builder.append("                ");
2753       _builder.append("output.space_before_token = false;");
2754       _builder.newLine();
2755       _builder.append("            ");
2756       _builder.append("}");
2757       _builder.newLine();
2758       _builder.append("            ");
2759       _builder.append("while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {");
2760       _builder.newLine();
2761       _builder.append("                ");
2762       _builder.append("restore_mode();");
2763       _builder.newLine();
2764       _builder.append("            ");
2765       _builder.append("}");
2766       _builder.newLine();
2767       _builder.append("            ");
2768       _builder.append("print_token();");
2769       _builder.newLine();
2770       _builder.append("        ");
2771       _builder.append("}");
2772       _builder.newLine();
2773       _builder.newLine();
2774       _builder.append("        ");
2775       _builder.append("function handle_string() {");
2776       _builder.newLine();
2777       _builder.append("            ");
2778       _builder.append("if (start_of_statement()) {");
2779       _builder.newLine();
2780       _builder.append("                ");
2781       _builder.append("// The conditional starts the statement if appropriate.");
2782       _builder.newLine();
2783       _builder.append("                ");
2784       _builder.append("// One difference - strings want at least a space before");
2785       _builder.newLine();
2786       _builder.append("                ");
2787       _builder.append("output.space_before_token = true;");
2788       _builder.newLine();
2789       _builder.append("            ");
2790       _builder.append("} else if (last_type === \'TK_RESERVED\' || last_type === \'TK_WORD\') {");
2791       _builder.newLine();
2792       _builder.append("                ");
2793       _builder.append("output.space_before_token = true;");
2794       _builder.newLine();
2795       _builder.append("            ");
2796       _builder.append("} else if (last_type === \'TK_COMMA\' || last_type === \'TK_START_EXPR\' || last_type === \'TK_EQUALS\' || last_type === \'TK_OPERATOR\') {");
2797       _builder.newLine();
2798       _builder.append("                ");
2799       _builder.append("if (!start_of_object_property()) {");
2800       _builder.newLine();
2801       _builder.append("                    ");
2802       _builder.append("allow_wrap_or_preserved_newline();");
2803       _builder.newLine();
2804       _builder.append("                ");
2805       _builder.append("}");
2806       _builder.newLine();
2807       _builder.append("            ");
2808       _builder.append("} else {");
2809       _builder.newLine();
2810       _builder.append("                ");
2811       _builder.append("print_newline();");
2812       _builder.newLine();
2813       _builder.append("            ");
2814       _builder.append("}");
2815       _builder.newLine();
2816       _builder.append("            ");
2817       _builder.append("print_token();");
2818       _builder.newLine();
2819       _builder.append("        ");
2820       _builder.append("}");
2821       _builder.newLine();
2822       _builder.newLine();
2823       _builder.append("        ");
2824       _builder.append("function handle_equals() {");
2825       _builder.newLine();
2826       _builder.append("            ");
2827       _builder.append("if (start_of_statement()) {");
2828       _builder.newLine();
2829       _builder.append("                ");
2830       _builder.append("// The conditional starts the statement if appropriate.");
2831       _builder.newLine();
2832       _builder.append("            ");
2833       _builder.append("}");
2834       _builder.newLine();
2835       _builder.newLine();
2836       _builder.append("            ");
2837       _builder.append("if (flags.declaration_statement) {");
2838       _builder.newLine();
2839       _builder.append("                ");
2840       _builder.append("// just got an \'=\' in a var-line, different formatting/line-breaking, etc will now be done");
2841       _builder.newLine();
2842       _builder.append("                ");
2843       _builder.append("flags.declaration_assignment = true;");
2844       _builder.newLine();
2845       _builder.append("            ");
2846       _builder.append("}");
2847       _builder.newLine();
2848       _builder.append("            ");
2849       _builder.append("output.space_before_token = true;");
2850       _builder.newLine();
2851       _builder.append("            ");
2852       _builder.append("print_token();");
2853       _builder.newLine();
2854       _builder.append("            ");
2855       _builder.append("output.space_before_token = true;");
2856       _builder.newLine();
2857       _builder.append("        ");
2858       _builder.append("}");
2859       _builder.newLine();
2860       _builder.newLine();
2861       _builder.append("        ");
2862       _builder.append("function handle_comma() {");
2863       _builder.newLine();
2864       _builder.append("            ");
2865       _builder.append("if (flags.declaration_statement) {");
2866       _builder.newLine();
2867       _builder.append("                ");
2868       _builder.append("if (is_expression(flags.parent.mode)) {");
2869       _builder.newLine();
2870       _builder.append("                    ");
2871       _builder.append("// do not break on comma, for(var a = 1, b = 2)");
2872       _builder.newLine();
2873       _builder.append("                    ");
2874       _builder.append("flags.declaration_assignment = false;");
2875       _builder.newLine();
2876       _builder.append("                ");
2877       _builder.append("}");
2878       _builder.newLine();
2879       _builder.newLine();
2880       _builder.append("                ");
2881       _builder.append("print_token();");
2882       _builder.newLine();
2883       _builder.newLine();
2884       _builder.append("                ");
2885       _builder.append("if (flags.declaration_assignment) {");
2886       _builder.newLine();
2887       _builder.append("                    ");
2888       _builder.append("flags.declaration_assignment = false;");
2889       _builder.newLine();
2890       _builder.append("                    ");
2891       _builder.append("print_newline(false, true);");
2892       _builder.newLine();
2893       _builder.append("                ");
2894       _builder.append("} else {");
2895       _builder.newLine();
2896       _builder.append("                    ");
2897       _builder.append("output.space_before_token = true;");
2898       _builder.newLine();
2899       _builder.append("                    ");
2900       _builder.append("// for comma-first, we want to allow a newline before the comma");
2901       _builder.newLine();
2902       _builder.append("                    ");
2903       _builder.append("// to turn into a newline after the comma, which we will fixup later");
2904       _builder.newLine();
2905       _builder.append("                    ");
2906       _builder.append("if (opt.comma_first) {");
2907       _builder.newLine();
2908       _builder.append("                        ");
2909       _builder.append("allow_wrap_or_preserved_newline();");
2910       _builder.newLine();
2911       _builder.append("                    ");
2912       _builder.append("}");
2913       _builder.newLine();
2914       _builder.append("                ");
2915       _builder.append("}");
2916       _builder.newLine();
2917       _builder.append("                ");
2918       _builder.append("return;");
2919       _builder.newLine();
2920       _builder.append("            ");
2921       _builder.append("}");
2922       _builder.newLine();
2923       _builder.newLine();
2924       _builder.append("            ");
2925       _builder.append("print_token();");
2926       _builder.newLine();
2927       _builder.append("            ");
2928       _builder.append("if (flags.mode === MODE.ObjectLiteral ||");
2929       _builder.newLine();
2930       _builder.append("                ");
2931       _builder.append("(flags.mode === MODE.Statement && flags.parent.mode === MODE.ObjectLiteral)) {");
2932       _builder.newLine();
2933       _builder.append("                ");
2934       _builder.append("if (flags.mode === MODE.Statement) {");
2935       _builder.newLine();
2936       _builder.append("                    ");
2937       _builder.append("restore_mode();");
2938       _builder.newLine();
2939       _builder.append("                ");
2940       _builder.append("}");
2941       _builder.newLine();
2942       _builder.append("                ");
2943       _builder.append("print_newline();");
2944       _builder.newLine();
2945       _builder.append("            ");
2946       _builder.append("} else {");
2947       _builder.newLine();
2948       _builder.append("                ");
2949       _builder.append("// EXPR or DO_BLOCK");
2950       _builder.newLine();
2951       _builder.append("                ");
2952       _builder.append("output.space_before_token = true;");
2953       _builder.newLine();
2954       _builder.append("                ");
2955       _builder.append("// for comma-first, we want to allow a newline before the comma");
2956       _builder.newLine();
2957       _builder.append("                ");
2958       _builder.append("// to turn into a newline after the comma, which we will fixup later");
2959       _builder.newLine();
2960       _builder.append("                ");
2961       _builder.append("if (opt.comma_first) {");
2962       _builder.newLine();
2963       _builder.append("                    ");
2964       _builder.append("allow_wrap_or_preserved_newline();");
2965       _builder.newLine();
2966       _builder.append("                ");
2967       _builder.append("}");
2968       _builder.newLine();
2969       _builder.append("            ");
2970       _builder.append("}");
2971       _builder.newLine();
2972       _builder.newLine();
2973       _builder.append("        ");
2974       _builder.append("}");
2975       _builder.newLine();
2976       _builder.newLine();
2977       _builder.append("        ");
2978       _builder.append("function handle_operator() {");
2979       _builder.newLine();
2980       _builder.append("            ");
2981       _builder.append("if (start_of_statement()) {");
2982       _builder.newLine();
2983       _builder.append("                ");
2984       _builder.append("// The conditional starts the statement if appropriate.");
2985       _builder.newLine();
2986       _builder.append("            ");
2987       _builder.append("}");
2988       _builder.newLine();
2989       _builder.newLine();
2990       _builder.append("            ");
2991       _builder.append("if (last_type === \'TK_RESERVED\' && is_special_word(flags.last_text)) {");
2992       _builder.newLine();
2993       _builder.append("                ");
2994       _builder.append("// \"return\" had a special handling in TK_WORD. Now we need to return the favor");
2995       _builder.newLine();
2996       _builder.append("                ");
2997       _builder.append("output.space_before_token = true;");
2998       _builder.newLine();
2999       _builder.append("                ");
3000       _builder.append("print_token();");
3001       _builder.newLine();
3002       _builder.append("                ");
3003       _builder.append("return;");
3004       _builder.newLine();
3005       _builder.append("            ");
3006       _builder.append("}");
3007       _builder.newLine();
3008       _builder.newLine();
3009       _builder.append("            ");
3010       _builder.append("// hack for actionscript\'s import .*;");
3011       _builder.newLine();
3012       _builder.append("            ");
3013       _builder.append("if (current_token.text === \'*\' && last_type === \'TK_DOT\') {");
3014       _builder.newLine();
3015       _builder.append("                ");
3016       _builder.append("print_token();");
3017       _builder.newLine();
3018       _builder.append("                ");
3019       _builder.append("return;");
3020       _builder.newLine();
3021       _builder.append("            ");
3022       _builder.append("}");
3023       _builder.newLine();
3024       _builder.newLine();
3025       _builder.append("            ");
3026       _builder.append("if (current_token.text === \':\' && flags.in_case) {");
3027       _builder.newLine();
3028       _builder.append("                ");
3029       _builder.append("flags.case_body = true;");
3030       _builder.newLine();
3031       _builder.append("                ");
3032       _builder.append("indent();");
3033       _builder.newLine();
3034       _builder.append("                ");
3035       _builder.append("print_token();");
3036       _builder.newLine();
3037       _builder.append("                ");
3038       _builder.append("print_newline();");
3039       _builder.newLine();
3040       _builder.append("                ");
3041       _builder.append("flags.in_case = false;");
3042       _builder.newLine();
3043       _builder.append("                ");
3044       _builder.append("return;");
3045       _builder.newLine();
3046       _builder.append("            ");
3047       _builder.append("}");
3048       _builder.newLine();
3049       _builder.newLine();
3050       _builder.append("            ");
3051       _builder.append("if (current_token.text === \'::\') {");
3052       _builder.newLine();
3053       _builder.append("                ");
3054       _builder.append("// no spaces around exotic namespacing syntax operator");
3055       _builder.newLine();
3056       _builder.append("                ");
3057       _builder.append("print_token();");
3058       _builder.newLine();
3059       _builder.append("                ");
3060       _builder.append("return;");
3061       _builder.newLine();
3062       _builder.append("            ");
3063       _builder.append("}");
3064       _builder.newLine();
3065       _builder.newLine();
3066       _builder.append("            ");
3067       _builder.append("// Allow line wrapping between operators");
3068       _builder.newLine();
3069       _builder.append("            ");
3070       _builder.append("if (last_type === \'TK_OPERATOR\') {");
3071       _builder.newLine();
3072       _builder.append("                ");
3073       _builder.append("allow_wrap_or_preserved_newline();");
3074       _builder.newLine();
3075       _builder.append("            ");
3076       _builder.append("}");
3077       _builder.newLine();
3078       _builder.newLine();
3079       _builder.append("            ");
3080       _builder.append("var space_before = true;");
3081       _builder.newLine();
3082       _builder.append("            ");
3083       _builder.append("var space_after = true;");
3084       _builder.newLine();
3085       _builder.newLine();
3086       _builder.append("            ");
3087       _builder.append("if (in_array(current_token.text, [\'--\', \'++\', \'!\', \'~\']) || (in_array(current_token.text, [\'-\', \'+\']) && (in_array(last_type, [\'TK_START_BLOCK\', \'TK_START_EXPR\', \'TK_EQUALS\', \'TK_OPERATOR\']) || in_array(flags.last_text, Tokenizer.line_starters) || flags.last_text === \',\'))) {");
3088       _builder.newLine();
3089       _builder.append("                ");
3090       _builder.append("// unary operators (and binary +/- pretending to be unary) special cases");
3091       _builder.newLine();
3092       _builder.newLine();
3093       _builder.append("                ");
3094       _builder.append("space_before = false;");
3095       _builder.newLine();
3096       _builder.append("                ");
3097       _builder.append("space_after = false;");
3098       _builder.newLine();
3099       _builder.newLine();
3100       _builder.append("                ");
3101       _builder.append("// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1");
3102       _builder.newLine();
3103       _builder.append("                ");
3104       _builder.append("// if there is a newline between -- or ++ and anything else we should preserve it.");
3105       _builder.newLine();
3106       _builder.append("                ");
3107       _builder.append("if (current_token.wanted_newline && (current_token.text === \'--\' || current_token.text === \'++\')) {");
3108       _builder.newLine();
3109       _builder.append("                    ");
3110       _builder.append("print_newline(false, true);");
3111       _builder.newLine();
3112       _builder.append("                ");
3113       _builder.append("}");
3114       _builder.newLine();
3115       _builder.newLine();
3116       _builder.append("                ");
3117       _builder.append("if (flags.last_text === \';\' && is_expression(flags.mode)) {");
3118       _builder.newLine();
3119       _builder.append("                    ");
3120       _builder.append("// for (;; ++i)");
3121       _builder.newLine();
3122       _builder.append("                    ");
3123       _builder.append("//        ^^^");
3124       _builder.newLine();
3125       _builder.append("                    ");
3126       _builder.append("space_before = true;");
3127       _builder.newLine();
3128       _builder.append("                ");
3129       _builder.append("}");
3130       _builder.newLine();
3131       _builder.newLine();
3132       _builder.append("                ");
3133       _builder.append("if (last_type === \'TK_RESERVED\') {");
3134       _builder.newLine();
3135       _builder.append("                    ");
3136       _builder.append("space_before = true;");
3137       _builder.newLine();
3138       _builder.append("                ");
3139       _builder.append("} else if (last_type === \'TK_END_EXPR\') {");
3140       _builder.newLine();
3141       _builder.append("                    ");
3142       _builder.append("space_before = !(flags.last_text === \']\' && (current_token.text === \'--\' || current_token.text === \'++\'));");
3143       _builder.newLine();
3144       _builder.append("                ");
3145       _builder.append("} else if (last_type === \'TK_OPERATOR\') {");
3146       _builder.newLine();
3147       _builder.append("                    ");
3148       _builder.append("// a++ + ++b;");
3149       _builder.newLine();
3150       _builder.append("                    ");
3151       _builder.append("// a - -b");
3152       _builder.newLine();
3153       _builder.append("                    ");
3154       _builder.append("space_before = in_array(current_token.text, [\'--\', \'-\', \'++\', \'+\']) && in_array(flags.last_text, [\'--\', \'-\', \'++\', \'+\']);");
3155       _builder.newLine();
3156       _builder.append("                    ");
3157       _builder.append("// + and - are not unary when preceeded by -- or ++ operator");
3158       _builder.newLine();
3159       _builder.append("                    ");
3160       _builder.append("// a-- + b");
3161       _builder.newLine();
3162       _builder.append("                    ");
3163       _builder.append("// a * +b");
3164       _builder.newLine();
3165       _builder.append("                    ");
3166       _builder.append("// a - -b");
3167       _builder.newLine();
3168       _builder.append("                    ");
3169       _builder.append("if (in_array(current_token.text, [\'+\', \'-\']) && in_array(flags.last_text, [\'--\', \'++\'])) {");
3170       _builder.newLine();
3171       _builder.append("                        ");
3172       _builder.append("space_after = true;");
3173       _builder.newLine();
3174       _builder.append("                    ");
3175       _builder.append("}");
3176       _builder.newLine();
3177       _builder.append("                ");
3178       _builder.append("}");
3179       _builder.newLine();
3180       _builder.newLine();
3181       _builder.append("                ");
3182       _builder.append("if ((flags.mode === MODE.BlockStatement || flags.mode === MODE.Statement) && (flags.last_text === \'{\' || flags.last_text === \';\')) {");
3183       _builder.newLine();
3184       _builder.append("                    ");
3185       _builder.append("// { foo; --i }");
3186       _builder.newLine();
3187       _builder.append("                    ");
3188       _builder.append("// foo(); --bar;");
3189       _builder.newLine();
3190       _builder.append("                    ");
3191       _builder.append("print_newline();");
3192       _builder.newLine();
3193       _builder.append("                ");
3194       _builder.append("}");
3195       _builder.newLine();
3196       _builder.append("            ");
3197       _builder.append("} else if (current_token.text === \':\') {");
3198       _builder.newLine();
3199       _builder.append("                ");
3200       _builder.append("if (flags.ternary_depth === 0) {");
3201       _builder.newLine();
3202       _builder.append("                    ");
3203       _builder.append("// Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.");
3204       _builder.newLine();
3205       _builder.append("                    ");
3206       _builder.append("space_before = false;");
3207       _builder.newLine();
3208       _builder.append("                ");
3209       _builder.append("} else {");
3210       _builder.newLine();
3211       _builder.append("                    ");
3212       _builder.append("flags.ternary_depth -= 1;");
3213       _builder.newLine();
3214       _builder.append("                ");
3215       _builder.append("}");
3216       _builder.newLine();
3217       _builder.append("            ");
3218       _builder.append("} else if (current_token.text === \'?\') {");
3219       _builder.newLine();
3220       _builder.append("                ");
3221       _builder.append("flags.ternary_depth += 1;");
3222       _builder.newLine();
3223       _builder.append("            ");
3224       _builder.append("} else if (current_token.text === \'*\' && last_type === \'TK_RESERVED\' && flags.last_text === \'function\') {");
3225       _builder.newLine();
3226       _builder.append("                ");
3227       _builder.append("space_before = false;");
3228       _builder.newLine();
3229       _builder.append("                ");
3230       _builder.append("space_after = false;");
3231       _builder.newLine();
3232       _builder.append("            ");
3233       _builder.append("}");
3234       _builder.newLine();
3235       _builder.append("            ");
3236       _builder.append("output.space_before_token = output.space_before_token || space_before;");
3237       _builder.newLine();
3238       _builder.append("            ");
3239       _builder.append("print_token();");
3240       _builder.newLine();
3241       _builder.append("            ");
3242       _builder.append("output.space_before_token = space_after;");
3243       _builder.newLine();
3244       _builder.append("        ");
3245       _builder.append("}");
3246       _builder.newLine();
3247       _builder.newLine();
3248       _builder.append("        ");
3249       _builder.append("function handle_block_comment() {");
3250       _builder.newLine();
3251       _builder.append("            ");
3252       _builder.append("if (output.raw) {");
3253       _builder.newLine();
3254       _builder.append("                ");
3255       _builder.append("output.add_raw_token(current_token)");
3256       _builder.newLine();
3257       _builder.append("                ");
3258       _builder.append("if (current_token.directives && current_token.directives[\'preserve\'] === \'end\') {");
3259       _builder.newLine();
3260       _builder.append("                    ");
3261       _builder.append("// If we\'re testing the raw output behavior, do not allow a directive to turn it off.");
3262       _builder.newLine();
3263       _builder.append("                    ");
3264       _builder.append("if (!opt.test_output_raw) {");
3265       _builder.newLine();
3266       _builder.append("                        ");
3267       _builder.append("output.raw = false;");
3268       _builder.newLine();
3269       _builder.append("                    ");
3270       _builder.append("}");
3271       _builder.newLine();
3272       _builder.append("                ");
3273       _builder.append("}");
3274       _builder.newLine();
3275       _builder.append("                ");
3276       _builder.append("return;");
3277       _builder.newLine();
3278       _builder.append("            ");
3279       _builder.append("}");
3280       _builder.newLine();
3281       _builder.newLine();
3282       _builder.append("            ");
3283       _builder.append("if (current_token.directives) {");
3284       _builder.newLine();
3285       _builder.append("                ");
3286       _builder.append("print_newline(false, true);");
3287       _builder.newLine();
3288       _builder.append("                ");
3289       _builder.append("print_token();");
3290       _builder.newLine();
3291       _builder.append("                ");
3292       _builder.append("if (current_token.directives[\'preserve\'] === \'start\') {");
3293       _builder.newLine();
3294       _builder.append("                    ");
3295       _builder.append("output.raw = true;");
3296       _builder.newLine();
3297       _builder.append("                ");
3298       _builder.append("}");
3299       _builder.newLine();
3300       _builder.append("                ");
3301       _builder.append("print_newline(false, true);");
3302       _builder.newLine();
3303       _builder.append("                ");
3304       _builder.append("return;");
3305       _builder.newLine();
3306       _builder.append("            ");
3307       _builder.append("}");
3308       _builder.newLine();
3309       _builder.newLine();
3310       _builder.append("            ");
3311       _builder.append("// inline block");
3312       _builder.newLine();
3313       _builder.append("            ");
3314       _builder.append("if (!acorn.newline.test(current_token.text) && !current_token.wanted_newline) {");
3315       _builder.newLine();
3316       _builder.append("                ");
3317       _builder.append("output.space_before_token = true;");
3318       _builder.newLine();
3319       _builder.append("                ");
3320       _builder.append("print_token();");
3321       _builder.newLine();
3322       _builder.append("                ");
3323       _builder.append("output.space_before_token = true;");
3324       _builder.newLine();
3325       _builder.append("                ");
3326       _builder.append("return;");
3327       _builder.newLine();
3328       _builder.append("            ");
3329       _builder.append("}");
3330       _builder.newLine();
3331       _builder.newLine();
3332       _builder.append("            ");
3333       _builder.append("var lines = split_newlines(current_token.text);");
3334       _builder.newLine();
3335       _builder.append("            ");
3336       _builder.append("var j; // iterator for this case");
3337       _builder.newLine();
3338       _builder.append("            ");
3339       _builder.append("var javadoc = false;");
3340       _builder.newLine();
3341       _builder.append("            ");
3342       _builder.append("var starless = false;");
3343       _builder.newLine();
3344       _builder.append("            ");
3345       _builder.append("var lastIndent = current_token.whitespace_before;");
3346       _builder.newLine();
3347       _builder.append("            ");
3348       _builder.append("var lastIndentLength = lastIndent.length;");
3349       _builder.newLine();
3350       _builder.newLine();
3351       _builder.append("            ");
3352       _builder.append("// block comment starts with a new line");
3353       _builder.newLine();
3354       _builder.append("            ");
3355       _builder.append("print_newline(false, true);");
3356       _builder.newLine();
3357       _builder.append("            ");
3358       _builder.append("if (lines.length > 1) {");
3359       _builder.newLine();
3360       _builder.append("                ");
3361       _builder.append("if (all_lines_start_with(lines.slice(1), \'*\')) {");
3362       _builder.newLine();
3363       _builder.append("                    ");
3364       _builder.append("javadoc = true;");
3365       _builder.newLine();
3366       _builder.append("                ");
3367       _builder.append("}");
3368       _builder.newLine();
3369       _builder.append("                ");
3370       _builder.append("else if (each_line_matches_indent(lines.slice(1), lastIndent)) {");
3371       _builder.newLine();
3372       _builder.append("                    ");
3373       _builder.append("starless = true;");
3374       _builder.newLine();
3375       _builder.append("                ");
3376       _builder.append("}");
3377       _builder.newLine();
3378       _builder.append("            ");
3379       _builder.append("}");
3380       _builder.newLine();
3381       _builder.newLine();
3382       _builder.append("            ");
3383       _builder.append("// first line always indented");
3384       _builder.newLine();
3385       _builder.append("            ");
3386       _builder.append("print_token(lines[0]);");
3387       _builder.newLine();
3388       _builder.append("            ");
3389       _builder.append("for (j = 1; j < lines.length; j++) {");
3390       _builder.newLine();
3391       _builder.append("                ");
3392       _builder.append("print_newline(false, true);");
3393       _builder.newLine();
3394       _builder.append("                ");
3395       _builder.append("if (javadoc) {");
3396       _builder.newLine();
3397       _builder.append("                    ");
3398       _builder.append("// javadoc: reformat and re-indent");
3399       _builder.newLine();
3400       _builder.append("                    ");
3401       _builder.append("print_token(\' \' + ltrim(lines[j]));");
3402       _builder.newLine();
3403       _builder.append("                ");
3404       _builder.append("} else if (starless && lines[j].length > lastIndentLength) {");
3405       _builder.newLine();
3406       _builder.append("                    ");
3407       _builder.append("// starless: re-indent non-empty content, avoiding trim");
3408       _builder.newLine();
3409       _builder.append("                    ");
3410       _builder.append("print_token(lines[j].substring(lastIndentLength));");
3411       _builder.newLine();
3412       _builder.append("                ");
3413       _builder.append("} else {");
3414       _builder.newLine();
3415       _builder.append("                    ");
3416       _builder.append("// normal comments output raw");
3417       _builder.newLine();
3418       _builder.append("                    ");
3419       _builder.append("output.add_token(lines[j]);");
3420       _builder.newLine();
3421       _builder.append("                ");
3422       _builder.append("}");
3423       _builder.newLine();
3424       _builder.append("            ");
3425       _builder.append("}");
3426       _builder.newLine();
3427       _builder.newLine();
3428       _builder.append("            ");
3429       _builder.append("// for comments of more than one line, make sure there\'s a new line after");
3430       _builder.newLine();
3431       _builder.append("            ");
3432       _builder.append("print_newline(false, true);");
3433       _builder.newLine();
3434       _builder.append("        ");
3435       _builder.append("}");
3436       _builder.newLine();
3437       _builder.newLine();
3438       _builder.append("        ");
3439       _builder.append("function handle_comment() {");
3440       _builder.newLine();
3441       _builder.append("            ");
3442       _builder.append("if (current_token.wanted_newline) {");
3443       _builder.newLine();
3444       _builder.append("                ");
3445       _builder.append("print_newline(false, true);");
3446       _builder.newLine();
3447       _builder.append("            ");
3448       _builder.append("} else {");
3449       _builder.newLine();
3450       _builder.append("                ");
3451       _builder.append("output.trim(true);");
3452       _builder.newLine();
3453       _builder.append("            ");
3454       _builder.append("}");
3455       _builder.newLine();
3456       _builder.newLine();
3457       _builder.append("            ");
3458       _builder.append("output.space_before_token = true;");
3459       _builder.newLine();
3460       _builder.append("            ");
3461       _builder.append("print_token();");
3462       _builder.newLine();
3463       _builder.append("            ");
3464       _builder.append("print_newline(false, true);");
3465       _builder.newLine();
3466       _builder.append("        ");
3467       _builder.append("}");
3468       _builder.newLine();
3469       _builder.newLine();
3470       _builder.append("        ");
3471       _builder.append("function handle_dot() {");
3472       _builder.newLine();
3473       _builder.append("            ");
3474       _builder.append("if (start_of_statement()) {");
3475       _builder.newLine();
3476       _builder.append("                ");
3477       _builder.append("// The conditional starts the statement if appropriate.");
3478       _builder.newLine();
3479       _builder.append("            ");
3480       _builder.append("}");
3481       _builder.newLine();
3482       _builder.newLine();
3483       _builder.append("            ");
3484       _builder.append("if (last_type === \'TK_RESERVED\' && is_special_word(flags.last_text)) {");
3485       _builder.newLine();
3486       _builder.append("                ");
3487       _builder.append("output.space_before_token = true;");
3488       _builder.newLine();
3489       _builder.append("            ");
3490       _builder.append("} else {");
3491       _builder.newLine();
3492       _builder.append("                ");
3493       _builder.append("// allow preserved newlines before dots in general");
3494       _builder.newLine();
3495       _builder.append("                ");
3496       _builder.append("// force newlines on dots after close paren when break_chained - for bar().baz()");
3497       _builder.newLine();
3498       _builder.append("                ");
3499       _builder.append("allow_wrap_or_preserved_newline(flags.last_text === \')\' && opt.break_chained_methods);");
3500       _builder.newLine();
3501       _builder.append("            ");
3502       _builder.append("}");
3503       _builder.newLine();
3504       _builder.newLine();
3505       _builder.append("            ");
3506       _builder.append("print_token();");
3507       _builder.newLine();
3508       _builder.append("        ");
3509       _builder.append("}");
3510       _builder.newLine();
3511       _builder.newLine();
3512       _builder.append("        ");
3513       _builder.append("function handle_unknown() {");
3514       _builder.newLine();
3515       _builder.append("            ");
3516       _builder.append("print_token();");
3517       _builder.newLine();
3518       _builder.newLine();
3519       _builder.append("            ");
3520       _builder.append("if (current_token.text[current_token.text.length - 1] === \'\\n\') {");
3521       _builder.newLine();
3522       _builder.append("                ");
3523       _builder.append("print_newline();");
3524       _builder.newLine();
3525       _builder.append("            ");
3526       _builder.append("}");
3527       _builder.newLine();
3528       _builder.append("        ");
3529       _builder.append("}");
3530       _builder.newLine();
3531       _builder.newLine();
3532       _builder.append("        ");
3533       _builder.append("function handle_eof() {");
3534       _builder.newLine();
3535       _builder.append("            ");
3536       _builder.append("// Unwind any open statements");
3537       _builder.newLine();
3538       _builder.append("            ");
3539       _builder.append("while (flags.mode === MODE.Statement) {");
3540       _builder.newLine();
3541       _builder.append("                ");
3542       _builder.append("restore_mode();");
3543       _builder.newLine();
3544       _builder.append("            ");
3545       _builder.append("}");
3546       _builder.newLine();
3547       _builder.append("        ");
3548       _builder.append("}");
3549       _builder.newLine();
3550       _builder.append("    ");
3551       _builder.append("}");
3552       _builder.newLine();
3553       _builder.newLine();
3554       _builder.newLine();
3555       _builder.append("    ");
3556       _builder.append("function OutputLine(parent) {");
3557       _builder.newLine();
3558       _builder.append("        ");
3559       _builder.append("var _character_count = 0;");
3560       _builder.newLine();
3561       _builder.append("        ");
3562       _builder.append("// use indent_count as a marker for lines that have preserved indentation");
3563       _builder.newLine();
3564       _builder.append("        ");
3565       _builder.append("var _indent_count = -1;");
3566       _builder.newLine();
3567       _builder.newLine();
3568       _builder.append("        ");
3569       _builder.append("var _items = [];");
3570       _builder.newLine();
3571       _builder.append("        ");
3572       _builder.append("var _empty = true;");
3573       _builder.newLine();
3574       _builder.newLine();
3575       _builder.append("        ");
3576       _builder.append("this.set_indent = function(level) {");
3577       _builder.newLine();
3578       _builder.append("            ");
3579       _builder.append("_character_count = parent.baseIndentLength + level * parent.indent_length");
3580       _builder.newLine();
3581       _builder.append("            ");
3582       _builder.append("_indent_count = level;");
3583       _builder.newLine();
3584       _builder.append("        ");
3585       _builder.append("}");
3586       _builder.newLine();
3587       _builder.newLine();
3588       _builder.append("        ");
3589       _builder.append("this.get_character_count = function() {");
3590       _builder.newLine();
3591       _builder.append("            ");
3592       _builder.append("return _character_count;");
3593       _builder.newLine();
3594       _builder.append("        ");
3595       _builder.append("}");
3596       _builder.newLine();
3597       _builder.newLine();
3598       _builder.append("        ");
3599       _builder.append("this.is_empty = function() {");
3600       _builder.newLine();
3601       _builder.append("            ");
3602       _builder.append("return _empty;");
3603       _builder.newLine();
3604       _builder.append("        ");
3605       _builder.append("}");
3606       _builder.newLine();
3607       _builder.newLine();
3608       _builder.append("        ");
3609       _builder.append("this.last = function() {");
3610       _builder.newLine();
3611       _builder.append("            ");
3612       _builder.append("if (!this._empty) {");
3613       _builder.newLine();
3614       _builder.append("              ");
3615       _builder.append("return _items[_items.length - 1];");
3616       _builder.newLine();
3617       _builder.append("            ");
3618       _builder.append("} else {");
3619       _builder.newLine();
3620       _builder.append("              ");
3621       _builder.append("return null;");
3622       _builder.newLine();
3623       _builder.append("            ");
3624       _builder.append("}");
3625       _builder.newLine();
3626       _builder.append("        ");
3627       _builder.append("}");
3628       _builder.newLine();
3629       _builder.newLine();
3630       _builder.append("        ");
3631       _builder.append("this.push = function(input) {");
3632       _builder.newLine();
3633       _builder.append("            ");
3634       _builder.append("_items.push(input);");
3635       _builder.newLine();
3636       _builder.append("            ");
3637       _builder.append("_character_count += input.length;");
3638       _builder.newLine();
3639       _builder.append("            ");
3640       _builder.append("_empty = false;");
3641       _builder.newLine();
3642       _builder.append("        ");
3643       _builder.append("}");
3644       _builder.newLine();
3645       _builder.newLine();
3646       _builder.append("        ");
3647       _builder.append("this.pop = function() {");
3648       _builder.newLine();
3649       _builder.append("            ");
3650       _builder.append("var item = null;");
3651       _builder.newLine();
3652       _builder.append("            ");
3653       _builder.append("if (!_empty) {");
3654       _builder.newLine();
3655       _builder.append("                ");
3656       _builder.append("item = _items.pop();");
3657       _builder.newLine();
3658       _builder.append("                ");
3659       _builder.append("_character_count -= item.length;");
3660       _builder.newLine();
3661       _builder.append("                ");
3662       _builder.append("_empty = _items.length === 0;");
3663       _builder.newLine();
3664       _builder.append("            ");
3665       _builder.append("}");
3666       _builder.newLine();
3667       _builder.append("            ");
3668       _builder.append("return item;");
3669       _builder.newLine();
3670       _builder.append("        ");
3671       _builder.append("}");
3672       _builder.newLine();
3673       _builder.newLine();
3674       _builder.append("        ");
3675       _builder.append("this.remove_indent = function() {");
3676       _builder.newLine();
3677       _builder.append("            ");
3678       _builder.append("if (_indent_count > 0) {");
3679       _builder.newLine();
3680       _builder.append("                ");
3681       _builder.append("_indent_count -= 1;");
3682       _builder.newLine();
3683       _builder.append("                ");
3684       _builder.append("_character_count -= parent.indent_length");
3685       _builder.newLine();
3686       _builder.append("            ");
3687       _builder.append("}");
3688       _builder.newLine();
3689       _builder.append("        ");
3690       _builder.append("}");
3691       _builder.newLine();
3692       _builder.newLine();
3693       _builder.append("        ");
3694       _builder.append("this.trim = function() {");
3695       _builder.newLine();
3696       _builder.append("            ");
3697       _builder.append("while (this.last() === \' \') {");
3698       _builder.newLine();
3699       _builder.append("                ");
3700       _builder.append("var item = _items.pop();");
3701       _builder.newLine();
3702       _builder.append("                ");
3703       _builder.append("_character_count -= 1;");
3704       _builder.newLine();
3705       _builder.append("            ");
3706       _builder.append("}");
3707       _builder.newLine();
3708       _builder.append("            ");
3709       _builder.append("_empty = _items.length === 0;");
3710       _builder.newLine();
3711       _builder.append("        ");
3712       _builder.append("}");
3713       _builder.newLine();
3714       _builder.newLine();
3715       _builder.append("        ");
3716       _builder.append("this.toString = function() {");
3717       _builder.newLine();
3718       _builder.append("            ");
3719       _builder.append("var result = \'\';");
3720       _builder.newLine();
3721       _builder.append("            ");
3722       _builder.append("if (!this._empty) {");
3723       _builder.newLine();
3724       _builder.append("                ");
3725       _builder.append("if (_indent_count >= 0) {");
3726       _builder.newLine();
3727       _builder.append("                    ");
3728       _builder.append("result = parent.indent_cache[_indent_count];");
3729       _builder.newLine();
3730       _builder.append("                ");
3731       _builder.append("}");
3732       _builder.newLine();
3733       _builder.append("                ");
3734       _builder.append("result += _items.join(\'\')");
3735       _builder.newLine();
3736       _builder.append("            ");
3737       _builder.append("}");
3738       _builder.newLine();
3739       _builder.append("            ");
3740       _builder.append("return result;");
3741       _builder.newLine();
3742       _builder.append("        ");
3743       _builder.append("}");
3744       _builder.newLine();
3745       _builder.append("    ");
3746       _builder.append("}");
3747       _builder.newLine();
3748       _builder.newLine();
3749       _builder.append("    ");
3750       _builder.append("function Output(indent_string, baseIndentString) {");
3751       _builder.newLine();
3752       _builder.append("        ");
3753       _builder.append("baseIndentString = baseIndentString || \'\';");
3754       _builder.newLine();
3755       _builder.append("        ");
3756       _builder.append("this.indent_cache = [ baseIndentString ];");
3757       _builder.newLine();
3758       _builder.append("        ");
3759       _builder.append("this.baseIndentLength = baseIndentString.length;");
3760       _builder.newLine();
3761       _builder.append("        ");
3762       _builder.append("this.indent_length = indent_string.length;");
3763       _builder.newLine();
3764       _builder.append("        ");
3765       _builder.append("this.raw = false;");
3766       _builder.newLine();
3767       _builder.newLine();
3768       _builder.append("        ");
3769       _builder.append("var lines =[];");
3770       _builder.newLine();
3771       _builder.append("        ");
3772       _builder.append("this.baseIndentString = baseIndentString;");
3773       _builder.newLine();
3774       _builder.append("        ");
3775       _builder.append("this.indent_string = indent_string;");
3776       _builder.newLine();
3777       _builder.append("        ");
3778       _builder.append("this.previous_line = null;");
3779       _builder.newLine();
3780       _builder.append("        ");
3781       _builder.append("this.current_line = null;");
3782       _builder.newLine();
3783       _builder.append("        ");
3784       _builder.append("this.space_before_token = false;");
3785       _builder.newLine();
3786       _builder.newLine();
3787       _builder.append("        ");
3788       _builder.append("this.add_outputline = function() {");
3789       _builder.newLine();
3790       _builder.append("            ");
3791       _builder.append("this.previous_line = this.current_line;");
3792       _builder.newLine();
3793       _builder.append("            ");
3794       _builder.append("this.current_line = new OutputLine(this);");
3795       _builder.newLine();
3796       _builder.append("            ");
3797       _builder.append("lines.push(this.current_line);");
3798       _builder.newLine();
3799       _builder.append("        ");
3800       _builder.append("}");
3801       _builder.newLine();
3802       _builder.newLine();
3803       _builder.append("        ");
3804       _builder.append("// initialize");
3805       _builder.newLine();
3806       _builder.append("        ");
3807       _builder.append("this.add_outputline();");
3808       _builder.newLine();
3809       _builder.newLine();
3810       _builder.newLine();
3811       _builder.append("        ");
3812       _builder.append("this.get_line_number = function() {");
3813       _builder.newLine();
3814       _builder.append("            ");
3815       _builder.append("return lines.length;");
3816       _builder.newLine();
3817       _builder.append("        ");
3818       _builder.append("}");
3819       _builder.newLine();
3820       _builder.newLine();
3821       _builder.append("        ");
3822       _builder.append("// Using object instead of string to allow for later expansion of info about each line");
3823       _builder.newLine();
3824       _builder.append("        ");
3825       _builder.append("this.add_new_line = function(force_newline) {");
3826       _builder.newLine();
3827       _builder.append("            ");
3828       _builder.append("if (this.get_line_number() === 1 && this.just_added_newline()) {");
3829       _builder.newLine();
3830       _builder.append("                ");
3831       _builder.append("return false; // no newline on start of file");
3832       _builder.newLine();
3833       _builder.append("            ");
3834       _builder.append("}");
3835       _builder.newLine();
3836       _builder.newLine();
3837       _builder.append("            ");
3838       _builder.append("if (force_newline || !this.just_added_newline()) {");
3839       _builder.newLine();
3840       _builder.append("                ");
3841       _builder.append("if (!this.raw) {");
3842       _builder.newLine();
3843       _builder.append("                    ");
3844       _builder.append("this.add_outputline();");
3845       _builder.newLine();
3846       _builder.append("                ");
3847       _builder.append("}");
3848       _builder.newLine();
3849       _builder.append("                ");
3850       _builder.append("return true;");
3851       _builder.newLine();
3852       _builder.append("            ");
3853       _builder.append("}");
3854       _builder.newLine();
3855       _builder.newLine();
3856       _builder.append("            ");
3857       _builder.append("return false;");
3858       _builder.newLine();
3859       _builder.append("        ");
3860       _builder.append("}");
3861       _builder.newLine();
3862       _builder.newLine();
3863       _builder.append("        ");
3864       _builder.append("this.get_code = function() {");
3865       _builder.newLine();
3866       _builder.append("            ");
3867       _builder.append("var sweet_code = lines.join(\'\\n\').replace(/[\\r\\n\\t ]+$/, \'\');");
3868       _builder.newLine();
3869       _builder.append("            ");
3870       _builder.append("return sweet_code;");
3871       _builder.newLine();
3872       _builder.append("        ");
3873       _builder.append("}");
3874       _builder.newLine();
3875       _builder.newLine();
3876       _builder.append("        ");
3877       _builder.append("this.set_indent = function(level) {");
3878       _builder.newLine();
3879       _builder.append("            ");
3880       _builder.append("// Never indent your first output indent at the start of the file");
3881       _builder.newLine();
3882       _builder.append("            ");
3883       _builder.append("if (lines.length > 1) {");
3884       _builder.newLine();
3885       _builder.append("                ");
3886       _builder.append("while(level >= this.indent_cache.length) {");
3887       _builder.newLine();
3888       _builder.append("                    ");
3889       _builder.append("this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);");
3890       _builder.newLine();
3891       _builder.append("                ");
3892       _builder.append("}");
3893       _builder.newLine();
3894       _builder.newLine();
3895       _builder.append("                ");
3896       _builder.append("this.current_line.set_indent(level);");
3897       _builder.newLine();
3898       _builder.append("                ");
3899       _builder.append("return true;");
3900       _builder.newLine();
3901       _builder.append("            ");
3902       _builder.append("}");
3903       _builder.newLine();
3904       _builder.append("            ");
3905       _builder.append("this.current_line.set_indent(0);");
3906       _builder.newLine();
3907       _builder.append("            ");
3908       _builder.append("return false;");
3909       _builder.newLine();
3910       _builder.append("        ");
3911       _builder.append("}");
3912       _builder.newLine();
3913       _builder.newLine();
3914       _builder.append("        ");
3915       _builder.append("this.add_raw_token = function(token) {");
3916       _builder.newLine();
3917       _builder.append("            ");
3918       _builder.append("for (var x = 0; x < token.newlines; x++) {");
3919       _builder.newLine();
3920       _builder.append("                ");
3921       _builder.append("this.add_outputline();");
3922       _builder.newLine();
3923       _builder.append("            ");
3924       _builder.append("}");
3925       _builder.newLine();
3926       _builder.append("            ");
3927       _builder.append("this.current_line.push(token.whitespace_before);");
3928       _builder.newLine();
3929       _builder.append("            ");
3930       _builder.append("this.current_line.push(token.text);");
3931       _builder.newLine();
3932       _builder.append("            ");
3933       _builder.append("this.space_before_token = false;");
3934       _builder.newLine();
3935       _builder.append("        ");
3936       _builder.append("}");
3937       _builder.newLine();
3938       _builder.newLine();
3939       _builder.append("        ");
3940       _builder.append("this.add_token = function(printable_token) {");
3941       _builder.newLine();
3942       _builder.append("            ");
3943       _builder.append("this.add_space_before_token();");
3944       _builder.newLine();
3945       _builder.append("            ");
3946       _builder.append("this.current_line.push(printable_token);");
3947       _builder.newLine();
3948       _builder.append("        ");
3949       _builder.append("}");
3950       _builder.newLine();
3951       _builder.newLine();
3952       _builder.append("        ");
3953       _builder.append("this.add_space_before_token = function() {");
3954       _builder.newLine();
3955       _builder.append("            ");
3956       _builder.append("if (this.space_before_token && !this.just_added_newline()) {");
3957       _builder.newLine();
3958       _builder.append("                ");
3959       _builder.append("this.current_line.push(\' \');");
3960       _builder.newLine();
3961       _builder.append("            ");
3962       _builder.append("}");
3963       _builder.newLine();
3964       _builder.append("            ");
3965       _builder.append("this.space_before_token = false;");
3966       _builder.newLine();
3967       _builder.append("        ");
3968       _builder.append("}");
3969       _builder.newLine();
3970       _builder.newLine();
3971       _builder.append("        ");
3972       _builder.append("this.remove_redundant_indentation = function (frame) {");
3973       _builder.newLine();
3974       _builder.append("            ");
3975       _builder.append("// This implementation is effective but has some issues:");
3976       _builder.newLine();
3977       _builder.append("            ");
3978       _builder.append("//     - can cause line wrap to happen too soon due to indent removal");
3979       _builder.newLine();
3980       _builder.append("            ");
3981       _builder.append("//           after wrap points are calculated");
3982       _builder.newLine();
3983       _builder.append("            ");
3984       _builder.append("// These issues are minor compared to ugly indentation.");
3985       _builder.newLine();
3986       _builder.newLine();
3987       _builder.append("            ");
3988       _builder.append("if (frame.multiline_frame ||");
3989       _builder.newLine();
3990       _builder.append("                ");
3991       _builder.append("frame.mode === MODE.ForInitializer ||");
3992       _builder.newLine();
3993       _builder.append("                ");
3994       _builder.append("frame.mode === MODE.Conditional) {");
3995       _builder.newLine();
3996       _builder.append("                ");
3997       _builder.append("return;");
3998       _builder.newLine();
3999       _builder.append("            ");
4000       _builder.append("}");
4001       _builder.newLine();
4002       _builder.newLine();
4003       _builder.append("            ");
4004       _builder.append("// remove one indent from each line inside this section");
4005       _builder.newLine();
4006       _builder.append("            ");
4007       _builder.append("var index = frame.start_line_index;");
4008       _builder.newLine();
4009       _builder.append("            ");
4010       _builder.append("var line;");
4011       _builder.newLine();
4012       _builder.newLine();
4013       _builder.append("            ");
4014       _builder.append("var output_length = lines.length;");
4015       _builder.newLine();
4016       _builder.append("            ");
4017       _builder.append("while (index < output_length) {");
4018       _builder.newLine();
4019       _builder.append("                ");
4020       _builder.append("lines[index].remove_indent();");
4021       _builder.newLine();
4022       _builder.append("                ");
4023       _builder.append("index++;");
4024       _builder.newLine();
4025       _builder.append("            ");
4026       _builder.append("}");
4027       _builder.newLine();
4028       _builder.append("        ");
4029       _builder.append("}");
4030       _builder.newLine();
4031       _builder.newLine();
4032       _builder.append("        ");
4033       _builder.append("this.trim = function(eat_newlines) {");
4034       _builder.newLine();
4035       _builder.append("            ");
4036       _builder.append("eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;");
4037       _builder.newLine();
4038       _builder.newLine();
4039       _builder.append("            ");
4040       _builder.append("this.current_line.trim(indent_string, baseIndentString);");
4041       _builder.newLine();
4042       _builder.newLine();
4043       _builder.append("            ");
4044       _builder.append("while (eat_newlines && lines.length > 1 &&");
4045       _builder.newLine();
4046       _builder.append("                ");
4047       _builder.append("this.current_line.is_empty()) {");
4048       _builder.newLine();
4049       _builder.append("                ");
4050       _builder.append("lines.pop();");
4051       _builder.newLine();
4052       _builder.append("                ");
4053       _builder.append("this.current_line = lines[lines.length - 1]");
4054       _builder.newLine();
4055       _builder.append("                ");
4056       _builder.append("this.current_line.trim();");
4057       _builder.newLine();
4058       _builder.append("            ");
4059       _builder.append("}");
4060       _builder.newLine();
4061       _builder.newLine();
4062       _builder.append("            ");
4063       _builder.append("this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;");
4064       _builder.newLine();
4065       _builder.append("        ");
4066       _builder.append("}");
4067       _builder.newLine();
4068       _builder.newLine();
4069       _builder.append("        ");
4070       _builder.append("this.just_added_newline = function() {");
4071       _builder.newLine();
4072       _builder.append("            ");
4073       _builder.append("return this.current_line.is_empty();");
4074       _builder.newLine();
4075       _builder.append("        ");
4076       _builder.append("}");
4077       _builder.newLine();
4078       _builder.newLine();
4079       _builder.append("        ");
4080       _builder.append("this.just_added_blankline = function() {");
4081       _builder.newLine();
4082       _builder.append("            ");
4083       _builder.append("if (this.just_added_newline()) {");
4084       _builder.newLine();
4085       _builder.append("                ");
4086       _builder.append("if (lines.length === 1) {");
4087       _builder.newLine();
4088       _builder.append("                    ");
4089       _builder.append("return true; // start of the file and newline = blank");
4090       _builder.newLine();
4091       _builder.append("                ");
4092       _builder.append("}");
4093       _builder.newLine();
4094       _builder.newLine();
4095       _builder.append("                ");
4096       _builder.append("var line = lines[lines.length - 2];");
4097       _builder.newLine();
4098       _builder.append("                ");
4099       _builder.append("return line.is_empty();");
4100       _builder.newLine();
4101       _builder.append("            ");
4102       _builder.append("}");
4103       _builder.newLine();
4104       _builder.append("            ");
4105       _builder.append("return false;");
4106       _builder.newLine();
4107       _builder.append("        ");
4108       _builder.append("}");
4109       _builder.newLine();
4110       _builder.append("    ");
4111       _builder.append("}");
4112       _builder.newLine();
4113       _builder.newLine();
4114       _builder.newLine();
4115       _builder.append("    ");
4116       _builder.append("var Token = function(type, text, newlines, whitespace_before, mode, parent) {");
4117       _builder.newLine();
4118       _builder.append("        ");
4119       _builder.append("this.type = type;");
4120       _builder.newLine();
4121       _builder.append("        ");
4122       _builder.append("this.text = text;");
4123       _builder.newLine();
4124       _builder.append("        ");
4125       _builder.append("this.comments_before = [];");
4126       _builder.newLine();
4127       _builder.append("        ");
4128       _builder.append("this.newlines = newlines || 0;");
4129       _builder.newLine();
4130       _builder.append("        ");
4131       _builder.append("this.wanted_newline = newlines > 0;");
4132       _builder.newLine();
4133       _builder.append("        ");
4134       _builder.append("this.whitespace_before = whitespace_before || \'\';");
4135       _builder.newLine();
4136       _builder.append("        ");
4137       _builder.append("this.parent = null;");
4138       _builder.newLine();
4139       _builder.append("        ");
4140       _builder.append("this.directives = null;");
4141       _builder.newLine();
4142       _builder.append("    ");
4143       _builder.append("}");
4144       _builder.newLine();
4145       _builder.newLine();
4146       _builder.append("    ");
4147       _builder.append("function tokenizer(input, opts, indent_string) {");
4148       _builder.newLine();
4149       _builder.newLine();
4150       _builder.append("        ");
4151       _builder.append("var whitespace = \"\\n\\r\\t \".split(\'\');");
4152       _builder.newLine();
4153       _builder.append("        ");
4154       _builder.append("var digit = /[0-9]/;");
4155       _builder.newLine();
4156       _builder.append("        ");
4157       _builder.append("var digit_hex = /[0123456789abcdefABCDEF]/;");
4158       _builder.newLine();
4159       _builder.newLine();
4160       _builder.append("        ");
4161       _builder.append("var punct = (\'+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: =>\').split(\' \'); ");
4162       _builder.newLine();
4163       _builder.append("        ");
4164       _builder.append("// words which should always start on new line.");
4165       _builder.newLine();
4166       _builder.append("        ");
4167       _builder.append("this.line_starters = \'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export\'.split(\',\');");
4168       _builder.newLine();
4169       _builder.append("        ");
4170       _builder.append("var reserved_words = this.line_starters.concat([\'do\', \'in\', \'else\', \'get\', \'set\', \'new\', \'catch\', \'finally\', \'typeof\', \'yield\', \'async\', \'await\']);");
4171       _builder.newLine();
4172       _builder.newLine();
4173       _builder.append("        ");
4174       _builder.append("//  /* ... */ comment ends with nearest */ or end of file");
4175       _builder.newLine();
4176       _builder.append("        ");
4177       _builder.append("var block_comment_pattern = /([\\s\\S]*?)((?:\\*\\/)|$)/g;");
4178       _builder.newLine();
4179       _builder.newLine();
4180       _builder.append("        ");
4181       _builder.append("// comment ends just before nearest linefeed or end of file");
4182       _builder.newLine();
4183       _builder.append("        ");
4184       _builder.append("var comment_pattern = /([^\\n\\r\\u2028\\u2029]*)/g;");
4185       _builder.newLine();
4186       _builder.newLine();
4187       _builder.append("        ");
4188       _builder.append("var directives_block_pattern = /\\/\\* beautify( \\w+[:]\\w+)+ \\*\\//g;");
4189       _builder.newLine();
4190       _builder.append("        ");
4191       _builder.append("var directive_pattern = / (\\w+)[:](\\w+)/g;");
4192       _builder.newLine();
4193       _builder.append("        ");
4194       _builder.append("var directives_end_ignore_pattern = /([\\s\\S]*?)((?:\\/\\*\\sbeautify\\signore:end\\s\\*\\/)|$)/g;");
4195       _builder.newLine();
4196       _builder.newLine();
4197       _builder.append("        ");
4198       _builder.append("var template_pattern = /((<\\?php|<\\?=)[\\s\\S]*?\\?>)|(<%[\\s\\S]*?%>)/g");
4199       _builder.newLine();
4200       _builder.newLine();
4201       _builder.append("        ");
4202       _builder.append("var n_newlines, whitespace_before_token, in_html_comment, tokens, parser_pos;");
4203       _builder.newLine();
4204       _builder.append("        ");
4205       _builder.append("var input_length;");
4206       _builder.newLine();
4207       _builder.newLine();
4208       _builder.append("        ");
4209       _builder.append("this.tokenize = function() {");
4210       _builder.newLine();
4211       _builder.append("            ");
4212       _builder.append("// cache the source\'s length.");
4213       _builder.newLine();
4214       _builder.append("            ");
4215       _builder.append("input_length = input.length");
4216       _builder.newLine();
4217       _builder.append("            ");
4218       _builder.append("parser_pos = 0;");
4219       _builder.newLine();
4220       _builder.append("            ");
4221       _builder.append("in_html_comment = false");
4222       _builder.newLine();
4223       _builder.append("            ");
4224       _builder.append("tokens = [];");
4225       _builder.newLine();
4226       _builder.newLine();
4227       _builder.append("            ");
4228       _builder.append("var next, last;");
4229       _builder.newLine();
4230       _builder.append("            ");
4231       _builder.append("var token_values;");
4232       _builder.newLine();
4233       _builder.append("            ");
4234       _builder.append("var open = null;");
4235       _builder.newLine();
4236       _builder.append("            ");
4237       _builder.append("var open_stack = [];");
4238       _builder.newLine();
4239       _builder.append("            ");
4240       _builder.append("var comments = [];");
4241       _builder.newLine();
4242       _builder.newLine();
4243       _builder.append("            ");
4244       _builder.append("while (!(last && last.type === \'TK_EOF\')) {");
4245       _builder.newLine();
4246       _builder.append("                ");
4247       _builder.append("token_values = tokenize_next();");
4248       _builder.newLine();
4249       _builder.append("                ");
4250       _builder.append("next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);");
4251       _builder.newLine();
4252       _builder.append("                ");
4253       _builder.append("while(next.type === \'TK_COMMENT\' || next.type === \'TK_BLOCK_COMMENT\' || next.type === \'TK_UNKNOWN\') {");
4254       _builder.newLine();
4255       _builder.append("                    ");
4256       _builder.append("if (next.type === \'TK_BLOCK_COMMENT\') {");
4257       _builder.newLine();
4258       _builder.append("                        ");
4259       _builder.append("next.directives = token_values[2];");
4260       _builder.newLine();
4261       _builder.append("                    ");
4262       _builder.append("}");
4263       _builder.newLine();
4264       _builder.append("                    ");
4265       _builder.append("comments.push(next);");
4266       _builder.newLine();
4267       _builder.append("                    ");
4268       _builder.append("token_values = tokenize_next();");
4269       _builder.newLine();
4270       _builder.append("                    ");
4271       _builder.append("next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);");
4272       _builder.newLine();
4273       _builder.append("                ");
4274       _builder.append("}");
4275       _builder.newLine();
4276       _builder.newLine();
4277       _builder.append("                ");
4278       _builder.append("if (comments.length) {");
4279       _builder.newLine();
4280       _builder.append("                    ");
4281       _builder.append("next.comments_before = comments;");
4282       _builder.newLine();
4283       _builder.append("                    ");
4284       _builder.append("comments = [];");
4285       _builder.newLine();
4286       _builder.append("                ");
4287       _builder.append("}");
4288       _builder.newLine();
4289       _builder.newLine();
4290       _builder.append("                ");
4291       _builder.append("if (next.type === \'TK_START_BLOCK\' || next.type === \'TK_START_EXPR\') {");
4292       _builder.newLine();
4293       _builder.append("                    ");
4294       _builder.append("next.parent = last;");
4295       _builder.newLine();
4296       _builder.append("                    ");
4297       _builder.append("open_stack.push(open);");
4298       _builder.newLine();
4299       _builder.append("                    ");
4300       _builder.append("open = next;");
4301       _builder.newLine();
4302       _builder.append("                ");
4303       _builder.append("}  else if ((next.type === \'TK_END_BLOCK\' || next.type === \'TK_END_EXPR\') &&");
4304       _builder.newLine();
4305       _builder.append("                    ");
4306       _builder.append("(open && (");
4307       _builder.newLine();
4308       _builder.append("                        ");
4309       _builder.append("(next.text === \']\' && open.text === \'[\') ||");
4310       _builder.newLine();
4311       _builder.append("                        ");
4312       _builder.append("(next.text === \')\' && open.text === \'(\') ||");
4313       _builder.newLine();
4314       _builder.append("                        ");
4315       _builder.append("(next.text === \'}\' && open.text === \'{\')))) {");
4316       _builder.newLine();
4317       _builder.append("                    ");
4318       _builder.append("next.parent = open.parent;");
4319       _builder.newLine();
4320       _builder.append("                    ");
4321       _builder.append("open = open_stack.pop();");
4322       _builder.newLine();
4323       _builder.append("                ");
4324       _builder.append("}");
4325       _builder.newLine();
4326       _builder.newLine();
4327       _builder.append("                ");
4328       _builder.append("tokens.push(next);");
4329       _builder.newLine();
4330       _builder.append("                ");
4331       _builder.append("last = next;");
4332       _builder.newLine();
4333       _builder.append("            ");
4334       _builder.append("}");
4335       _builder.newLine();
4336       _builder.newLine();
4337       _builder.append("            ");
4338       _builder.append("return tokens;");
4339       _builder.newLine();
4340       _builder.append("        ");
4341       _builder.append("}");
4342       _builder.newLine();
4343       _builder.newLine();
4344       _builder.append("        ");
4345       _builder.append("function get_directives (text) {");
4346       _builder.newLine();
4347       _builder.append("            ");
4348       _builder.append("if (!text.match(directives_block_pattern)) {");
4349       _builder.newLine();
4350       _builder.append("                ");
4351       _builder.append("return null;");
4352       _builder.newLine();
4353       _builder.append("            ");
4354       _builder.append("}");
4355       _builder.newLine();
4356       _builder.newLine();
4357       _builder.append("            ");
4358       _builder.append("var directives = {};");
4359       _builder.newLine();
4360       _builder.append("            ");
4361       _builder.append("directive_pattern.lastIndex = 0;");
4362       _builder.newLine();
4363       _builder.append("            ");
4364       _builder.append("var directive_match = directive_pattern.exec(text);");
4365       _builder.newLine();
4366       _builder.newLine();
4367       _builder.append("            ");
4368       _builder.append("while (directive_match) {");
4369       _builder.newLine();
4370       _builder.append("                ");
4371       _builder.append("directives[directive_match[1]] = directive_match[2];");
4372       _builder.newLine();
4373       _builder.append("                ");
4374       _builder.append("directive_match = directive_pattern.exec(text);");
4375       _builder.newLine();
4376       _builder.append("            ");
4377       _builder.append("}");
4378       _builder.newLine();
4379       _builder.newLine();
4380       _builder.append("            ");
4381       _builder.append("return directives;");
4382       _builder.newLine();
4383       _builder.append("        ");
4384       _builder.append("}");
4385       _builder.newLine();
4386       _builder.newLine();
4387       _builder.append("        ");
4388       _builder.append("function tokenize_next() {");
4389       _builder.newLine();
4390       _builder.append("            ");
4391       _builder.append("var i, resulting_string;");
4392       _builder.newLine();
4393       _builder.append("            ");
4394       _builder.append("var whitespace_on_this_line = [];");
4395       _builder.newLine();
4396       _builder.newLine();
4397       _builder.append("            ");
4398       _builder.append("n_newlines = 0;");
4399       _builder.newLine();
4400       _builder.append("            ");
4401       _builder.append("whitespace_before_token = \'\';");
4402       _builder.newLine();
4403       _builder.newLine();
4404       _builder.append("            ");
4405       _builder.append("if (parser_pos >= input_length) {");
4406       _builder.newLine();
4407       _builder.append("                ");
4408       _builder.append("return [\'\', \'TK_EOF\'];");
4409       _builder.newLine();
4410       _builder.append("            ");
4411       _builder.append("}");
4412       _builder.newLine();
4413       _builder.newLine();
4414       _builder.append("            ");
4415       _builder.append("var last_token;");
4416       _builder.newLine();
4417       _builder.append("            ");
4418       _builder.append("if (tokens.length) {");
4419       _builder.newLine();
4420       _builder.append("                ");
4421       _builder.append("last_token = tokens[tokens.length-1];");
4422       _builder.newLine();
4423       _builder.append("            ");
4424       _builder.append("} else {");
4425       _builder.newLine();
4426       _builder.append("                ");
4427       _builder.append("// For the sake of tokenizing we can pretend that there was on open brace to start");
4428       _builder.newLine();
4429       _builder.append("                ");
4430       _builder.append("last_token = new Token(\'TK_START_BLOCK\', \'{\');");
4431       _builder.newLine();
4432       _builder.append("            ");
4433       _builder.append("}");
4434       _builder.newLine();
4435       _builder.newLine();
4436       _builder.newLine();
4437       _builder.append("            ");
4438       _builder.append("var c = input.charAt(parser_pos);");
4439       _builder.newLine();
4440       _builder.append("            ");
4441       _builder.append("parser_pos += 1;");
4442       _builder.newLine();
4443       _builder.newLine();
4444       _builder.append("            ");
4445       _builder.append("while (in_array(c, whitespace)) {");
4446       _builder.newLine();
4447       _builder.newLine();
4448       _builder.append("                ");
4449       _builder.append("if (acorn.newline.test(c)) {");
4450       _builder.newLine();
4451       _builder.append("                    ");
4452       _builder.append("if (!(c === \'\\n\' && input.charAt(parser_pos-2) === \'\\r\')) {");
4453       _builder.newLine();
4454       _builder.append("                        ");
4455       _builder.append("n_newlines += 1;");
4456       _builder.newLine();
4457       _builder.append("                        ");
4458       _builder.append("whitespace_on_this_line = [];");
4459       _builder.newLine();
4460       _builder.append("                    ");
4461       _builder.append("}");
4462       _builder.newLine();
4463       _builder.append("                ");
4464       _builder.append("} else {");
4465       _builder.newLine();
4466       _builder.append("                    ");
4467       _builder.append("whitespace_on_this_line.push(c);");
4468       _builder.newLine();
4469       _builder.append("                ");
4470       _builder.append("}");
4471       _builder.newLine();
4472       _builder.newLine();
4473       _builder.append("                ");
4474       _builder.append("if (parser_pos >= input_length) {");
4475       _builder.newLine();
4476       _builder.append("                    ");
4477       _builder.append("return [\'\', \'TK_EOF\'];");
4478       _builder.newLine();
4479       _builder.append("                ");
4480       _builder.append("}");
4481       _builder.newLine();
4482       _builder.newLine();
4483       _builder.append("                ");
4484       _builder.append("c = input.charAt(parser_pos);");
4485       _builder.newLine();
4486       _builder.append("                ");
4487       _builder.append("parser_pos += 1;");
4488       _builder.newLine();
4489       _builder.append("            ");
4490       _builder.append("}");
4491       _builder.newLine();
4492       _builder.newLine();
4493       _builder.append("            ");
4494       _builder.append("if(whitespace_on_this_line.length) {");
4495       _builder.newLine();
4496       _builder.append("                ");
4497       _builder.append("whitespace_before_token = whitespace_on_this_line.join(\'\');");
4498       _builder.newLine();
4499       _builder.append("            ");
4500       _builder.append("}");
4501       _builder.newLine();
4502       _builder.newLine();
4503       _builder.append("            ");
4504       _builder.append("if (digit.test(c)) {");
4505       _builder.newLine();
4506       _builder.append("                ");
4507       _builder.append("var allow_decimal = true;");
4508       _builder.newLine();
4509       _builder.append("                ");
4510       _builder.append("var allow_e = true;");
4511       _builder.newLine();
4512       _builder.append("                ");
4513       _builder.append("var local_digit = digit;");
4514       _builder.newLine();
4515       _builder.newLine();
4516       _builder.append("                ");
4517       _builder.append("if (c === \'0\' && parser_pos < input_length && /[Xx]/.test(input.charAt(parser_pos))) {");
4518       _builder.newLine();
4519       _builder.append("                    ");
4520       _builder.append("// switch to hex number, no decimal or e, just hex digits");
4521       _builder.newLine();
4522       _builder.append("                    ");
4523       _builder.append("allow_decimal = false;");
4524       _builder.newLine();
4525       _builder.append("                    ");
4526       _builder.append("allow_e = false;");
4527       _builder.newLine();
4528       _builder.append("                    ");
4529       _builder.append("c += input.charAt(parser_pos);");
4530       _builder.newLine();
4531       _builder.append("                    ");
4532       _builder.append("parser_pos += 1;");
4533       _builder.newLine();
4534       _builder.append("                    ");
4535       _builder.append("local_digit = digit_hex");
4536       _builder.newLine();
4537       _builder.append("                ");
4538       _builder.append("} else {");
4539       _builder.newLine();
4540       _builder.append("                    ");
4541       _builder.append("// we know this first loop will run.  It keeps the logic simpler.");
4542       _builder.newLine();
4543       _builder.append("                    ");
4544       _builder.append("c = \'\';");
4545       _builder.newLine();
4546       _builder.append("                    ");
4547       _builder.append("parser_pos -= 1");
4548       _builder.newLine();
4549       _builder.append("                ");
4550       _builder.append("}");
4551       _builder.newLine();
4552       _builder.newLine();
4553       _builder.append("                ");
4554       _builder.append("// Add the digits");
4555       _builder.newLine();
4556       _builder.append("                ");
4557       _builder.append("while (parser_pos < input_length && local_digit.test(input.charAt(parser_pos))) {");
4558       _builder.newLine();
4559       _builder.append("                    ");
4560       _builder.append("c += input.charAt(parser_pos);");
4561       _builder.newLine();
4562       _builder.append("                    ");
4563       _builder.append("parser_pos += 1;");
4564       _builder.newLine();
4565       _builder.newLine();
4566       _builder.append("                    ");
4567       _builder.append("if (allow_decimal && parser_pos < input_length && input.charAt(parser_pos) === \'.\') {");
4568       _builder.newLine();
4569       _builder.append("                        ");
4570       _builder.append("c += input.charAt(parser_pos);");
4571       _builder.newLine();
4572       _builder.append("                        ");
4573       _builder.append("parser_pos += 1;");
4574       _builder.newLine();
4575       _builder.append("                        ");
4576       _builder.append("allow_decimal = false;");
4577       _builder.newLine();
4578       _builder.append("                    ");
4579       _builder.append("}");
4580       _builder.newLine();
4581       _builder.newLine();
4582       _builder.append("                    ");
4583       _builder.append("if (allow_e && parser_pos < input_length && /[Ee]/.test(input.charAt(parser_pos))) {");
4584       _builder.newLine();
4585       _builder.append("                        ");
4586       _builder.append("c += input.charAt(parser_pos);");
4587       _builder.newLine();
4588       _builder.append("                        ");
4589       _builder.append("parser_pos += 1;");
4590       _builder.newLine();
4591       _builder.newLine();
4592       _builder.append("                        ");
4593       _builder.append("if (parser_pos < input_length && /[+-]/.test(input.charAt(parser_pos))) {");
4594       _builder.newLine();
4595       _builder.append("                            ");
4596       _builder.append("c += input.charAt(parser_pos);");
4597       _builder.newLine();
4598       _builder.append("                            ");
4599       _builder.append("parser_pos += 1;");
4600       _builder.newLine();
4601       _builder.append("                        ");
4602       _builder.append("}");
4603       _builder.newLine();
4604       _builder.newLine();
4605       _builder.append("                        ");
4606       _builder.append("allow_e = false;");
4607       _builder.newLine();
4608       _builder.append("                        ");
4609       _builder.append("allow_decimal = false;");
4610       _builder.newLine();
4611       _builder.append("                    ");
4612       _builder.append("}");
4613       _builder.newLine();
4614       _builder.append("                ");
4615       _builder.append("}");
4616       _builder.newLine();
4617       _builder.newLine();
4618       _builder.append("                ");
4619       _builder.append("return [c, \'TK_WORD\'];");
4620       _builder.newLine();
4621       _builder.append("            ");
4622       _builder.append("}");
4623       _builder.newLine();
4624       _builder.newLine();
4625       _builder.append("            ");
4626       _builder.append("if (acorn.isIdentifierStart(input.charCodeAt(parser_pos-1))) {");
4627       _builder.newLine();
4628       _builder.append("                ");
4629       _builder.append("if (parser_pos < input_length) {");
4630       _builder.newLine();
4631       _builder.append("                    ");
4632       _builder.append("while (acorn.isIdentifierChar(input.charCodeAt(parser_pos))) {");
4633       _builder.newLine();
4634       _builder.append("                        ");
4635       _builder.append("c += input.charAt(parser_pos);");
4636       _builder.newLine();
4637       _builder.append("                        ");
4638       _builder.append("parser_pos += 1;");
4639       _builder.newLine();
4640       _builder.append("                        ");
4641       _builder.append("if (parser_pos === input_length) {");
4642       _builder.newLine();
4643       _builder.append("                            ");
4644       _builder.append("break;");
4645       _builder.newLine();
4646       _builder.append("                        ");
4647       _builder.append("}");
4648       _builder.newLine();
4649       _builder.append("                    ");
4650       _builder.append("}");
4651       _builder.newLine();
4652       _builder.append("                ");
4653       _builder.append("}");
4654       _builder.newLine();
4655       _builder.newLine();
4656       _builder.append("                ");
4657       _builder.append("if (!(last_token.type === \'TK_DOT\' ||");
4658       _builder.newLine();
4659       _builder.append("                        ");
4660       _builder.append("(last_token.type === \'TK_RESERVED\' && in_array(last_token.text, [\'set\', \'get\'])))");
4661       _builder.newLine();
4662       _builder.append("                    ");
4663       _builder.append("&& in_array(c, reserved_words)) {");
4664       _builder.newLine();
4665       _builder.append("                    ");
4666       _builder.append("if (c === \'in\') { // hack for \'in\' operator");
4667       _builder.newLine();
4668       _builder.append("                        ");
4669       _builder.append("return [c, \'TK_OPERATOR\'];");
4670       _builder.newLine();
4671       _builder.append("                    ");
4672       _builder.append("}");
4673       _builder.newLine();
4674       _builder.append("                    ");
4675       _builder.append("return [c, \'TK_RESERVED\'];");
4676       _builder.newLine();
4677       _builder.append("                ");
4678       _builder.append("}");
4679       _builder.newLine();
4680       _builder.newLine();
4681       _builder.append("                ");
4682       _builder.append("return [c, \'TK_WORD\'];");
4683       _builder.newLine();
4684       _builder.append("            ");
4685       _builder.append("}");
4686       _builder.newLine();
4687       _builder.newLine();
4688       _builder.append("            ");
4689       _builder.append("if (c === \'(\' || c === \'[\') {");
4690       _builder.newLine();
4691       _builder.append("                ");
4692       _builder.append("return [c, \'TK_START_EXPR\'];");
4693       _builder.newLine();
4694       _builder.append("            ");
4695       _builder.append("}");
4696       _builder.newLine();
4697       _builder.newLine();
4698       _builder.append("            ");
4699       _builder.append("if (c === \')\' || c === \']\') {");
4700       _builder.newLine();
4701       _builder.append("                ");
4702       _builder.append("return [c, \'TK_END_EXPR\'];");
4703       _builder.newLine();
4704       _builder.append("            ");
4705       _builder.append("}");
4706       _builder.newLine();
4707       _builder.newLine();
4708       _builder.append("            ");
4709       _builder.append("if (c === \'{\') {");
4710       _builder.newLine();
4711       _builder.append("                ");
4712       _builder.append("return [c, \'TK_START_BLOCK\'];");
4713       _builder.newLine();
4714       _builder.append("            ");
4715       _builder.append("}");
4716       _builder.newLine();
4717       _builder.newLine();
4718       _builder.append("            ");
4719       _builder.append("if (c === \'}\') {");
4720       _builder.newLine();
4721       _builder.append("                ");
4722       _builder.append("return [c, \'TK_END_BLOCK\'];");
4723       _builder.newLine();
4724       _builder.append("            ");
4725       _builder.append("}");
4726       _builder.newLine();
4727       _builder.newLine();
4728       _builder.append("            ");
4729       _builder.append("if (c === \';\') {");
4730       _builder.newLine();
4731       _builder.append("                ");
4732       _builder.append("return [c, \'TK_SEMICOLON\'];");
4733       _builder.newLine();
4734       _builder.append("            ");
4735       _builder.append("}");
4736       _builder.newLine();
4737       _builder.newLine();
4738       _builder.append("            ");
4739       _builder.append("if (c === \'/\') {");
4740       _builder.newLine();
4741       _builder.append("                ");
4742       _builder.append("var comment = \'\';");
4743       _builder.newLine();
4744       _builder.append("                ");
4745       _builder.append("// peek for comment /* ... */");
4746       _builder.newLine();
4747       _builder.append("                ");
4748       _builder.append("if (input.charAt(parser_pos) === \'*\') {");
4749       _builder.newLine();
4750       _builder.append("                    ");
4751       _builder.append("parser_pos += 1;");
4752       _builder.newLine();
4753       _builder.append("                    ");
4754       _builder.append("block_comment_pattern.lastIndex = parser_pos;");
4755       _builder.newLine();
4756       _builder.append("                    ");
4757       _builder.append("var comment_match = block_comment_pattern.exec(input);");
4758       _builder.newLine();
4759       _builder.append("                    ");
4760       _builder.append("comment = \'/*\' + comment_match[0];");
4761       _builder.newLine();
4762       _builder.append("                    ");
4763       _builder.append("parser_pos += comment_match[0].length;");
4764       _builder.newLine();
4765       _builder.append("                    ");
4766       _builder.append("var directives = get_directives(comment);");
4767       _builder.newLine();
4768       _builder.append("                    ");
4769       _builder.append("if (directives && directives[\'ignore\'] === \'start\') {");
4770       _builder.newLine();
4771       _builder.append("                        ");
4772       _builder.append("directives_end_ignore_pattern.lastIndex = parser_pos;");
4773       _builder.newLine();
4774       _builder.append("                        ");
4775       _builder.append("comment_match = directives_end_ignore_pattern.exec(input)");
4776       _builder.newLine();
4777       _builder.append("                        ");
4778       _builder.append("comment += comment_match[0];");
4779       _builder.newLine();
4780       _builder.append("                        ");
4781       _builder.append("parser_pos += comment_match[0].length;");
4782       _builder.newLine();
4783       _builder.append("                    ");
4784       _builder.append("}");
4785       _builder.newLine();
4786       _builder.append("                    ");
4787       _builder.append("comment = comment.replace(acorn.lineBreak, \'\\n\');");
4788       _builder.newLine();
4789       _builder.append("                    ");
4790       _builder.append("return [comment, \'TK_BLOCK_COMMENT\', directives];");
4791       _builder.newLine();
4792       _builder.append("                ");
4793       _builder.append("}");
4794       _builder.newLine();
4795       _builder.append("                ");
4796       _builder.append("// peek for comment // ...");
4797       _builder.newLine();
4798       _builder.append("                ");
4799       _builder.append("if (input.charAt(parser_pos) === \'/\') {");
4800       _builder.newLine();
4801       _builder.append("                    ");
4802       _builder.append("parser_pos += 1;");
4803       _builder.newLine();
4804       _builder.append("                    ");
4805       _builder.append("comment_pattern.lastIndex = parser_pos;");
4806       _builder.newLine();
4807       _builder.append("                    ");
4808       _builder.append("var comment_match = comment_pattern.exec(input);");
4809       _builder.newLine();
4810       _builder.append("                    ");
4811       _builder.append("comment = \'//\' + comment_match[0];");
4812       _builder.newLine();
4813       _builder.append("                    ");
4814       _builder.append("parser_pos += comment_match[0].length;");
4815       _builder.newLine();
4816       _builder.append("                    ");
4817       _builder.append("return [comment, \'TK_COMMENT\'];");
4818       _builder.newLine();
4819       _builder.append("                ");
4820       _builder.append("}");
4821       _builder.newLine();
4822       _builder.newLine();
4823       _builder.append("            ");
4824       _builder.append("}");
4825       _builder.newLine();
4826       _builder.newLine();
4827       _builder.append("            ");
4828       _builder.append("if (c === \'`\' || c === \"\'\" || c === \'\"\' || // string");
4829       _builder.newLine();
4830       _builder.append("                ");
4831       _builder.append("(");
4832       _builder.newLine();
4833       _builder.append("                    ");
4834       _builder.append("(c === \'/\') || // regexp");
4835       _builder.newLine();
4836       _builder.append("                    ");
4837       _builder.append("(opts.e4x && c === \"<\" && input.slice(parser_pos - 1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\\[CDATA\\[[\\s\\S]*?\\]\\])(\\s+[-a-zA-Z:0-9_.]+\\s*=\\s*(\'[^\']*\'|\"[^\"]*\"|{.*?}))*\\s*(\\/?)\\s*>/)) // xml");
4838       _builder.newLine();
4839       _builder.append("                ");
4840       _builder.append(") && ( // regex and xml can only appear in specific locations during parsing");
4841       _builder.newLine();
4842       _builder.append("                    ");
4843       _builder.append("(last_token.type === \'TK_RESERVED\' && in_array(last_token.text , [\'return\', \'case\', \'throw\', \'else\', \'do\', \'typeof\', \'yield\'])) ||");
4844       _builder.newLine();
4845       _builder.append("                    ");
4846       _builder.append("(last_token.type === \'TK_END_EXPR\' && last_token.text === \')\' &&");
4847       _builder.newLine();
4848       _builder.append("                        ");
4849       _builder.append("last_token.parent && last_token.parent.type === \'TK_RESERVED\' && in_array(last_token.parent.text, [\'if\', \'while\', \'for\'])) ||");
4850       _builder.newLine();
4851       _builder.append("                    ");
4852       _builder.append("(in_array(last_token.type, [\'TK_COMMENT\', \'TK_START_EXPR\', \'TK_START_BLOCK\',");
4853       _builder.newLine();
4854       _builder.append("                        ");
4855       _builder.append("\'TK_END_BLOCK\', \'TK_OPERATOR\', \'TK_EQUALS\', \'TK_EOF\', \'TK_SEMICOLON\', \'TK_COMMA\'");
4856       _builder.newLine();
4857       _builder.append("                    ");
4858       _builder.append("]))");
4859       _builder.newLine();
4860       _builder.append("                ");
4861       _builder.append(")) {");
4862       _builder.newLine();
4863       _builder.newLine();
4864       _builder.append("                ");
4865       _builder.append("var sep = c,");
4866       _builder.newLine();
4867       _builder.append("                    ");
4868       _builder.append("esc = false,");
4869       _builder.newLine();
4870       _builder.append("                    ");
4871       _builder.append("has_char_escapes = false;");
4872       _builder.newLine();
4873       _builder.newLine();
4874       _builder.append("                ");
4875       _builder.append("resulting_string = c;");
4876       _builder.newLine();
4877       _builder.newLine();
4878       _builder.append("                ");
4879       _builder.append("if (sep === \'/\') {");
4880       _builder.newLine();
4881       _builder.append("                    ");
4882       _builder.append("//");
4883       _builder.newLine();
4884       _builder.append("                    ");
4885       _builder.append("// handle regexp");
4886       _builder.newLine();
4887       _builder.append("                    ");
4888       _builder.append("//");
4889       _builder.newLine();
4890       _builder.append("                    ");
4891       _builder.append("var in_char_class = false;");
4892       _builder.newLine();
4893       _builder.append("                    ");
4894       _builder.append("while (parser_pos < input_length &&");
4895       _builder.newLine();
4896       _builder.append("                            ");
4897       _builder.append("((esc || in_char_class || input.charAt(parser_pos) !== sep) &&");
4898       _builder.newLine();
4899       _builder.append("                            ");
4900       _builder.append("!acorn.newline.test(input.charAt(parser_pos)))) {");
4901       _builder.newLine();
4902       _builder.append("                        ");
4903       _builder.append("resulting_string += input.charAt(parser_pos);");
4904       _builder.newLine();
4905       _builder.append("                        ");
4906       _builder.append("if (!esc) {");
4907       _builder.newLine();
4908       _builder.append("                            ");
4909       _builder.append("esc = input.charAt(parser_pos) === \'\\\\\';");
4910       _builder.newLine();
4911       _builder.append("                            ");
4912       _builder.append("if (input.charAt(parser_pos) === \'[\') {");
4913       _builder.newLine();
4914       _builder.append("                                ");
4915       _builder.append("in_char_class = true;");
4916       _builder.newLine();
4917       _builder.append("                            ");
4918       _builder.append("} else if (input.charAt(parser_pos) === \']\') {");
4919       _builder.newLine();
4920       _builder.append("                                ");
4921       _builder.append("in_char_class = false;");
4922       _builder.newLine();
4923       _builder.append("                            ");
4924       _builder.append("}");
4925       _builder.newLine();
4926       _builder.append("                        ");
4927       _builder.append("} else {");
4928       _builder.newLine();
4929       _builder.append("                            ");
4930       _builder.append("esc = false;");
4931       _builder.newLine();
4932       _builder.append("                        ");
4933       _builder.append("}");
4934       _builder.newLine();
4935       _builder.append("                        ");
4936       _builder.append("parser_pos += 1;");
4937       _builder.newLine();
4938       _builder.append("                    ");
4939       _builder.append("}");
4940       _builder.newLine();
4941       _builder.append("                ");
4942       _builder.append("} else if (opts.e4x && sep === \'<\') {");
4943       _builder.newLine();
4944       _builder.append("                    ");
4945       _builder.append("//");
4946       _builder.newLine();
4947       _builder.append("                    ");
4948       _builder.append("// handle e4x xml literals");
4949       _builder.newLine();
4950       _builder.append("                    ");
4951       _builder.append("//");
4952       _builder.newLine();
4953       _builder.append("                    ");
4954       _builder.append("var xmlRegExp = /<(\\/?)([-a-zA-Z:0-9_.]+|{[^{}]*}|!\\[CDATA\\[[\\s\\S]*?\\]\\])(\\s+[-a-zA-Z:0-9_.]+\\s*=\\s*(\'[^\']*\'|\"[^\"]*\"|{.*?}))*\\s*(\\/?)\\s*>/g;");
4955       _builder.newLine();
4956       _builder.append("                    ");
4957       _builder.append("var xmlStr = input.slice(parser_pos - 1);");
4958       _builder.newLine();
4959       _builder.append("                    ");
4960       _builder.append("var match = xmlRegExp.exec(xmlStr);");
4961       _builder.newLine();
4962       _builder.append("                    ");
4963       _builder.append("if (match && match.index === 0) {");
4964       _builder.newLine();
4965       _builder.append("                        ");
4966       _builder.append("var rootTag = match[2];");
4967       _builder.newLine();
4968       _builder.append("                        ");
4969       _builder.append("var depth = 0;");
4970       _builder.newLine();
4971       _builder.append("                        ");
4972       _builder.append("while (match) {");
4973       _builder.newLine();
4974       _builder.append("                            ");
4975       _builder.append("var isEndTag = !! match[1];");
4976       _builder.newLine();
4977       _builder.append("                            ");
4978       _builder.append("var tagName = match[2];");
4979       _builder.newLine();
4980       _builder.append("                            ");
4981       _builder.append("var isSingletonTag = ( !! match[match.length - 1]) || (tagName.slice(0, 8) === \"![CDATA[\");");
4982       _builder.newLine();
4983       _builder.append("                            ");
4984       _builder.append("if (tagName === rootTag && !isSingletonTag) {");
4985       _builder.newLine();
4986       _builder.append("                                ");
4987       _builder.append("if (isEndTag) {");
4988       _builder.newLine();
4989       _builder.append("                                    ");
4990       _builder.append("--depth;");
4991       _builder.newLine();
4992       _builder.append("                                ");
4993       _builder.append("} else {");
4994       _builder.newLine();
4995       _builder.append("                                    ");
4996       _builder.append("++depth;");
4997       _builder.newLine();
4998       _builder.append("                                ");
4999       _builder.append("}");
5000       _builder.newLine();
5001       _builder.append("                            ");
5002       _builder.append("}");
5003       _builder.newLine();
5004       _builder.append("                            ");
5005       _builder.append("if (depth <= 0) {");
5006       _builder.newLine();
5007       _builder.append("                                ");
5008       _builder.append("break;");
5009       _builder.newLine();
5010       _builder.append("                            ");
5011       _builder.append("}");
5012       _builder.newLine();
5013       _builder.append("                            ");
5014       _builder.append("match = xmlRegExp.exec(xmlStr);");
5015       _builder.newLine();
5016       _builder.append("                        ");
5017       _builder.append("}");
5018       _builder.newLine();
5019       _builder.append("                        ");
5020       _builder.append("var xmlLength = match ? match.index + match[0].length : xmlStr.length;");
5021       _builder.newLine();
5022       _builder.append("                        ");
5023       _builder.append("xmlStr = xmlStr.slice(0, xmlLength);");
5024       _builder.newLine();
5025       _builder.append("                        ");
5026       _builder.append("parser_pos += xmlLength - 1;");
5027       _builder.newLine();
5028       _builder.append("                        ");
5029       _builder.append("xmlStr = xmlStr.replace(acorn.lineBreak, \'\\n\');");
5030       _builder.newLine();
5031       _builder.append("                        ");
5032       _builder.append("return [xmlStr, \"TK_STRING\"];");
5033       _builder.newLine();
5034       _builder.append("                    ");
5035       _builder.append("}");
5036       _builder.newLine();
5037       _builder.append("                ");
5038       _builder.append("} else {");
5039       _builder.newLine();
5040       _builder.append("                    ");
5041       _builder.append("//");
5042       _builder.newLine();
5043       _builder.append("                    ");
5044       _builder.append("// handle string");
5045       _builder.newLine();
5046       _builder.append("                    ");
5047       _builder.append("//");
5048       _builder.newLine();
5049       _builder.append("                    ");
5050       _builder.append("// Template strings can travers lines without escape characters.");
5051       _builder.newLine();
5052       _builder.append("                    ");
5053       _builder.append("// Other strings cannot");
5054       _builder.newLine();
5055       _builder.append("                    ");
5056       _builder.append("while (parser_pos < input_length &&");
5057       _builder.newLine();
5058       _builder.append("                            ");
5059       _builder.append("(esc || (input.charAt(parser_pos) !== sep &&");
5060       _builder.newLine();
5061       _builder.append("                            ");
5062       _builder.append("(sep === \'`\' || !acorn.newline.test(input.charAt(parser_pos)))))) {");
5063       _builder.newLine();
5064       _builder.append("                        ");
5065       _builder.append("// Handle \\r\\n linebreaks after escapes or in template strings");
5066       _builder.newLine();
5067       _builder.append("                        ");
5068       _builder.append("if ((esc || sep === \'`\') && acorn.newline.test(input.charAt(parser_pos))) {");
5069       _builder.newLine();
5070       _builder.append("                            ");
5071       _builder.append("if (input.charAt(parser_pos) === \'\\r\' && input.charAt(parser_pos + 1) === \'\\n\') {");
5072       _builder.newLine();
5073       _builder.append("                                ");
5074       _builder.append("parser_pos += 1;");
5075       _builder.newLine();
5076       _builder.append("                            ");
5077       _builder.append("}");
5078       _builder.newLine();
5079       _builder.append("                            ");
5080       _builder.append("resulting_string += \'\\n\';");
5081       _builder.newLine();
5082       _builder.append("                        ");
5083       _builder.append("} else {");
5084       _builder.newLine();
5085       _builder.append("                            ");
5086       _builder.append("resulting_string += input.charAt(parser_pos);");
5087       _builder.newLine();
5088       _builder.append("                        ");
5089       _builder.append("}");
5090       _builder.newLine();
5091       _builder.append("                        ");
5092       _builder.append("if (esc) {");
5093       _builder.newLine();
5094       _builder.append("                            ");
5095       _builder.append("if (input.charAt(parser_pos) === \'x\' || input.charAt(parser_pos) === \'u\') {");
5096       _builder.newLine();
5097       _builder.append("                                ");
5098       _builder.append("has_char_escapes = true;");
5099       _builder.newLine();
5100       _builder.append("                            ");
5101       _builder.append("}");
5102       _builder.newLine();
5103       _builder.append("                            ");
5104       _builder.append("esc = false;");
5105       _builder.newLine();
5106       _builder.append("                        ");
5107       _builder.append("} else {");
5108       _builder.newLine();
5109       _builder.append("                            ");
5110       _builder.append("esc = input.charAt(parser_pos) === \'\\\\\';");
5111       _builder.newLine();
5112       _builder.append("                        ");
5113       _builder.append("}");
5114       _builder.newLine();
5115       _builder.append("                        ");
5116       _builder.append("parser_pos += 1;");
5117       _builder.newLine();
5118       _builder.append("                    ");
5119       _builder.append("}");
5120       _builder.newLine();
5121       _builder.newLine();
5122       _builder.append("                ");
5123       _builder.append("}");
5124       _builder.newLine();
5125       _builder.newLine();
5126       _builder.append("                ");
5127       _builder.append("if (has_char_escapes && opts.unescape_strings) {");
5128       _builder.newLine();
5129       _builder.append("                    ");
5130       _builder.append("resulting_string = unescape_string(resulting_string);");
5131       _builder.newLine();
5132       _builder.append("                ");
5133       _builder.append("}");
5134       _builder.newLine();
5135       _builder.newLine();
5136       _builder.append("                ");
5137       _builder.append("if (parser_pos < input_length && input.charAt(parser_pos) === sep) {");
5138       _builder.newLine();
5139       _builder.append("                    ");
5140       _builder.append("resulting_string += sep;");
5141       _builder.newLine();
5142       _builder.append("                    ");
5143       _builder.append("parser_pos += 1;");
5144       _builder.newLine();
5145       _builder.newLine();
5146       _builder.append("                    ");
5147       _builder.append("if (sep === \'/\') {");
5148       _builder.newLine();
5149       _builder.append("                        ");
5150       _builder.append("// regexps may have modifiers /regexp/MOD , so fetch those, too");
5151       _builder.newLine();
5152       _builder.append("                        ");
5153       _builder.append("// Only [gim] are valid, but if the user puts in garbage, do what we can to take it.");
5154       _builder.newLine();
5155       _builder.append("                        ");
5156       _builder.append("while (parser_pos < input_length && acorn.isIdentifierStart(input.charCodeAt(parser_pos))) {");
5157       _builder.newLine();
5158       _builder.append("                            ");
5159       _builder.append("resulting_string += input.charAt(parser_pos);");
5160       _builder.newLine();
5161       _builder.append("                            ");
5162       _builder.append("parser_pos += 1;");
5163       _builder.newLine();
5164       _builder.append("                        ");
5165       _builder.append("}");
5166       _builder.newLine();
5167       _builder.append("                    ");
5168       _builder.append("}");
5169       _builder.newLine();
5170       _builder.append("                ");
5171       _builder.append("}");
5172       _builder.newLine();
5173       _builder.append("                ");
5174       _builder.append("return [resulting_string, \'TK_STRING\'];");
5175       _builder.newLine();
5176       _builder.append("            ");
5177       _builder.append("}");
5178       _builder.newLine();
5179       _builder.newLine();
5180       _builder.append("            ");
5181       _builder.append("if (c === \'#\') {");
5182       _builder.newLine();
5183       _builder.newLine();
5184       _builder.append("                ");
5185       _builder.append("if (tokens.length === 0 && input.charAt(parser_pos) === \'!\') {");
5186       _builder.newLine();
5187       _builder.append("                    ");
5188       _builder.append("// shebang");
5189       _builder.newLine();
5190       _builder.append("                    ");
5191       _builder.append("resulting_string = c;");
5192       _builder.newLine();
5193       _builder.append("                    ");
5194       _builder.append("while (parser_pos < input_length && c !== \'\\n\') {");
5195       _builder.newLine();
5196       _builder.append("                        ");
5197       _builder.append("c = input.charAt(parser_pos);");
5198       _builder.newLine();
5199       _builder.append("                        ");
5200       _builder.append("resulting_string += c;");
5201       _builder.newLine();
5202       _builder.append("                        ");
5203       _builder.append("parser_pos += 1;");
5204       _builder.newLine();
5205       _builder.append("                    ");
5206       _builder.append("}");
5207       _builder.newLine();
5208       _builder.append("                    ");
5209       _builder.append("return [trim(resulting_string) + \'\\n\', \'TK_UNKNOWN\'];");
5210       _builder.newLine();
5211       _builder.append("                ");
5212       _builder.append("}");
5213       _builder.newLine();
5214       _builder.newLine();
5215       _builder.newLine();
5216       _builder.newLine();
5217       _builder.append("                ");
5218       _builder.append("// Spidermonkey-specific sharp variables for circular references");
5219       _builder.newLine();
5220       _builder.append("                ");
5221       _builder.append("// https://developer.mozilla.org/En/Sharp_variables_in_JavaScript");
5222       _builder.newLine();
5223       _builder.append("                ");
5224       _builder.append("// http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935");
5225       _builder.newLine();
5226       _builder.append("                ");
5227       _builder.append("var sharp = \'#\';");
5228       _builder.newLine();
5229       _builder.append("                ");
5230       _builder.append("if (parser_pos < input_length && digit.test(input.charAt(parser_pos))) {");
5231       _builder.newLine();
5232       _builder.append("                    ");
5233       _builder.append("do {");
5234       _builder.newLine();
5235       _builder.append("                        ");
5236       _builder.append("c = input.charAt(parser_pos);");
5237       _builder.newLine();
5238       _builder.append("                        ");
5239       _builder.append("sharp += c;");
5240       _builder.newLine();
5241       _builder.append("                        ");
5242       _builder.append("parser_pos += 1;");
5243       _builder.newLine();
5244       _builder.append("                    ");
5245       _builder.append("} while (parser_pos < input_length && c !== \'#\' && c !== \'=\');");
5246       _builder.newLine();
5247       _builder.append("                    ");
5248       _builder.append("if (c === \'#\') {");
5249       _builder.newLine();
5250       _builder.append("                        ");
5251       _builder.append("//");
5252       _builder.newLine();
5253       _builder.append("                    ");
5254       _builder.append("} else if (input.charAt(parser_pos) === \'[\' && input.charAt(parser_pos + 1) === \']\') {");
5255       _builder.newLine();
5256       _builder.append("                        ");
5257       _builder.append("sharp += \'[]\';");
5258       _builder.newLine();
5259       _builder.append("                        ");
5260       _builder.append("parser_pos += 2;");
5261       _builder.newLine();
5262       _builder.append("                    ");
5263       _builder.append("} else if (input.charAt(parser_pos) === \'{\' && input.charAt(parser_pos + 1) === \'}\') {");
5264       _builder.newLine();
5265       _builder.append("                        ");
5266       _builder.append("sharp += \'{}\';");
5267       _builder.newLine();
5268       _builder.append("                        ");
5269       _builder.append("parser_pos += 2;");
5270       _builder.newLine();
5271       _builder.append("                    ");
5272       _builder.append("}");
5273       _builder.newLine();
5274       _builder.append("                    ");
5275       _builder.append("return [sharp, \'TK_WORD\'];");
5276       _builder.newLine();
5277       _builder.append("                ");
5278       _builder.append("}");
5279       _builder.newLine();
5280       _builder.append("            ");
5281       _builder.append("}");
5282       _builder.newLine();
5283       _builder.newLine();
5284       _builder.append("            ");
5285       _builder.append("if (c === \'<\' && (input.charAt(parser_pos) === \'?\' || input.charAt(parser_pos) === \'%\')) {");
5286       _builder.newLine();
5287       _builder.append("                ");
5288       _builder.append("template_pattern.lastIndex = parser_pos - 1;");
5289       _builder.newLine();
5290       _builder.append("                ");
5291       _builder.append("var template_match = template_pattern.exec(input);");
5292       _builder.newLine();
5293       _builder.append("                ");
5294       _builder.append("if(template_match) {");
5295       _builder.newLine();
5296       _builder.append("                    ");
5297       _builder.append("c = template_match[0];");
5298       _builder.newLine();
5299       _builder.append("                    ");
5300       _builder.append("parser_pos += c.length - 1;");
5301       _builder.newLine();
5302       _builder.append("                    ");
5303       _builder.append("c = c.replace(acorn.lineBreak, \'\\n\');");
5304       _builder.newLine();
5305       _builder.append("                    ");
5306       _builder.append("return [c, \'TK_STRING\'];");
5307       _builder.newLine();
5308       _builder.append("                ");
5309       _builder.append("}");
5310       _builder.newLine();
5311       _builder.append("            ");
5312       _builder.append("}");
5313       _builder.newLine();
5314       _builder.newLine();
5315       _builder.append("            ");
5316       _builder.append("if (c === \'<\' && input.substring(parser_pos - 1, parser_pos + 3) === \'<!--\') {");
5317       _builder.newLine();
5318       _builder.append("                ");
5319       _builder.append("parser_pos += 3;");
5320       _builder.newLine();
5321       _builder.append("                ");
5322       _builder.append("c = \'<!--\';");
5323       _builder.newLine();
5324       _builder.append("                ");
5325       _builder.append("while (!acorn.newline.test(input.charAt(parser_pos)) && parser_pos < input_length) {");
5326       _builder.newLine();
5327       _builder.append("                    ");
5328       _builder.append("c += input.charAt(parser_pos);");
5329       _builder.newLine();
5330       _builder.append("                    ");
5331       _builder.append("parser_pos++;");
5332       _builder.newLine();
5333       _builder.append("                ");
5334       _builder.append("}");
5335       _builder.newLine();
5336       _builder.append("                ");
5337       _builder.append("in_html_comment = true;");
5338       _builder.newLine();
5339       _builder.append("                ");
5340       _builder.append("return [c, \'TK_COMMENT\'];");
5341       _builder.newLine();
5342       _builder.append("            ");
5343       _builder.append("}");
5344       _builder.newLine();
5345       _builder.newLine();
5346       _builder.append("            ");
5347       _builder.append("if (c === \'-\' && in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === \'-->\') {");
5348       _builder.newLine();
5349       _builder.append("                ");
5350       _builder.append("in_html_comment = false;");
5351       _builder.newLine();
5352       _builder.append("                ");
5353       _builder.append("parser_pos += 2;");
5354       _builder.newLine();
5355       _builder.append("                ");
5356       _builder.append("return [\'-->\', \'TK_COMMENT\'];");
5357       _builder.newLine();
5358       _builder.append("            ");
5359       _builder.append("}");
5360       _builder.newLine();
5361       _builder.newLine();
5362       _builder.append("            ");
5363       _builder.append("if (c === \'.\') {");
5364       _builder.newLine();
5365       _builder.append("                ");
5366       _builder.append("return [c, \'TK_DOT\'];");
5367       _builder.newLine();
5368       _builder.append("            ");
5369       _builder.append("}");
5370       _builder.newLine();
5371       _builder.newLine();
5372       _builder.append("            ");
5373       _builder.append("if (in_array(c, punct)) {");
5374       _builder.newLine();
5375       _builder.append("                ");
5376       _builder.append("while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {");
5377       _builder.newLine();
5378       _builder.append("                    ");
5379       _builder.append("c += input.charAt(parser_pos);");
5380       _builder.newLine();
5381       _builder.append("                    ");
5382       _builder.append("parser_pos += 1;");
5383       _builder.newLine();
5384       _builder.append("                    ");
5385       _builder.append("if (parser_pos >= input_length) {");
5386       _builder.newLine();
5387       _builder.append("                        ");
5388       _builder.append("break;");
5389       _builder.newLine();
5390       _builder.append("                    ");
5391       _builder.append("}");
5392       _builder.newLine();
5393       _builder.append("                ");
5394       _builder.append("}");
5395       _builder.newLine();
5396       _builder.newLine();
5397       _builder.append("                ");
5398       _builder.append("if (c === \',\') {");
5399       _builder.newLine();
5400       _builder.append("                    ");
5401       _builder.append("return [c, \'TK_COMMA\'];");
5402       _builder.newLine();
5403       _builder.append("                ");
5404       _builder.append("} else if (c === \'=\') {");
5405       _builder.newLine();
5406       _builder.append("                    ");
5407       _builder.append("return [c, \'TK_EQUALS\'];");
5408       _builder.newLine();
5409       _builder.append("                ");
5410       _builder.append("} else {");
5411       _builder.newLine();
5412       _builder.append("                    ");
5413       _builder.append("return [c, \'TK_OPERATOR\'];");
5414       _builder.newLine();
5415       _builder.append("                ");
5416       _builder.append("}");
5417       _builder.newLine();
5418       _builder.append("            ");
5419       _builder.append("}");
5420       _builder.newLine();
5421       _builder.newLine();
5422       _builder.append("            ");
5423       _builder.append("return [c, \'TK_UNKNOWN\'];");
5424       _builder.newLine();
5425       _builder.append("        ");
5426       _builder.append("}");
5427       _builder.newLine();
5428       _builder.newLine();
5429       _builder.newLine();
5430       _builder.append("        ");
5431       _builder.append("function unescape_string(s) {");
5432       _builder.newLine();
5433       _builder.append("            ");
5434       _builder.append("var esc = false,");
5435       _builder.newLine();
5436       _builder.append("                ");
5437       _builder.append("out = \'\',");
5438       _builder.newLine();
5439       _builder.append("                ");
5440       _builder.append("pos = 0,");
5441       _builder.newLine();
5442       _builder.append("                ");
5443       _builder.append("s_hex = \'\',");
5444       _builder.newLine();
5445       _builder.append("                ");
5446       _builder.append("escaped = 0,");
5447       _builder.newLine();
5448       _builder.append("                ");
5449       _builder.append("c;");
5450       _builder.newLine();
5451       _builder.newLine();
5452       _builder.append("            ");
5453       _builder.append("while (esc || pos < s.length) {");
5454       _builder.newLine();
5455       _builder.newLine();
5456       _builder.append("                ");
5457       _builder.append("c = s.charAt(pos);");
5458       _builder.newLine();
5459       _builder.append("                ");
5460       _builder.append("pos++;");
5461       _builder.newLine();
5462       _builder.newLine();
5463       _builder.append("                ");
5464       _builder.append("if (esc) {");
5465       _builder.newLine();
5466       _builder.append("                    ");
5467       _builder.append("esc = false;");
5468       _builder.newLine();
5469       _builder.append("                    ");
5470       _builder.append("if (c === \'x\') {");
5471       _builder.newLine();
5472       _builder.append("                        ");
5473       _builder.append("// simple hex-escape \\x24");
5474       _builder.newLine();
5475       _builder.append("                        ");
5476       _builder.append("s_hex = s.substr(pos, 2);");
5477       _builder.newLine();
5478       _builder.append("                        ");
5479       _builder.append("pos += 2;");
5480       _builder.newLine();
5481       _builder.append("                    ");
5482       _builder.append("} else if (c === \'u\') {");
5483       _builder.newLine();
5484       _builder.append("                        ");
5485       _builder.append("// unicode-escape, \\u2134");
5486       _builder.newLine();
5487       _builder.append("                        ");
5488       _builder.append("s_hex = s.substr(pos, 4);");
5489       _builder.newLine();
5490       _builder.append("                        ");
5491       _builder.append("pos += 4;");
5492       _builder.newLine();
5493       _builder.append("                    ");
5494       _builder.append("} else {");
5495       _builder.newLine();
5496       _builder.append("                        ");
5497       _builder.append("// some common escape, e.g \\n");
5498       _builder.newLine();
5499       _builder.append("                        ");
5500       _builder.append("out += \'\\\\\' + c;");
5501       _builder.newLine();
5502       _builder.append("                        ");
5503       _builder.append("continue;");
5504       _builder.newLine();
5505       _builder.append("                    ");
5506       _builder.append("}");
5507       _builder.newLine();
5508       _builder.append("                    ");
5509       _builder.append("if (!s_hex.match(/^[0123456789abcdefABCDEF]+$/)) {");
5510       _builder.newLine();
5511       _builder.append("                        ");
5512       _builder.append("// some weird escaping, bail out,");
5513       _builder.newLine();
5514       _builder.append("                        ");
5515       _builder.append("// leaving whole string intact");
5516       _builder.newLine();
5517       _builder.append("                        ");
5518       _builder.append("return s;");
5519       _builder.newLine();
5520       _builder.append("                    ");
5521       _builder.append("}");
5522       _builder.newLine();
5523       _builder.newLine();
5524       _builder.append("                    ");
5525       _builder.append("escaped = parseInt(s_hex, 16);");
5526       _builder.newLine();
5527       _builder.newLine();
5528       _builder.append("                    ");
5529       _builder.append("if (escaped >= 0x00 && escaped < 0x20) {");
5530       _builder.newLine();
5531       _builder.append("                        ");
5532       _builder.append("// leave 0x00...0x1f escaped");
5533       _builder.newLine();
5534       _builder.append("                        ");
5535       _builder.append("if (c === \'x\') {");
5536       _builder.newLine();
5537       _builder.append("                            ");
5538       _builder.append("out += \'\\\\x\' + s_hex;");
5539       _builder.newLine();
5540       _builder.append("                        ");
5541       _builder.append("} else {");
5542       _builder.newLine();
5543       _builder.append("                            ");
5544       _builder.append("out += \'\\\\u\' + s_hex;");
5545       _builder.newLine();
5546       _builder.append("                        ");
5547       _builder.append("}");
5548       _builder.newLine();
5549       _builder.append("                        ");
5550       _builder.append("continue;");
5551       _builder.newLine();
5552       _builder.append("                    ");
5553       _builder.append("} else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {");
5554       _builder.newLine();
5555       _builder.append("                        ");
5556       _builder.append("// single-quote, apostrophe, backslash - escape these");
5557       _builder.newLine();
5558       _builder.append("                        ");
5559       _builder.append("out += \'\\\\\' + String.fromCharCode(escaped);");
5560       _builder.newLine();
5561       _builder.append("                    ");
5562       _builder.append("} else if (c === \'x\' && escaped > 0x7e && escaped <= 0xff) {");
5563       _builder.newLine();
5564       _builder.append("                        ");
5565       _builder.append("// we bail out on \\x7f..\\xff,");
5566       _builder.newLine();
5567       _builder.append("                        ");
5568       _builder.append("// leaving whole string escaped,");
5569       _builder.newLine();
5570       _builder.append("                        ");
5571       _builder.append("// as it\'s probably completely binary");
5572       _builder.newLine();
5573       _builder.append("                        ");
5574       _builder.append("return s;");
5575       _builder.newLine();
5576       _builder.append("                    ");
5577       _builder.append("} else {");
5578       _builder.newLine();
5579       _builder.append("                        ");
5580       _builder.append("out += String.fromCharCode(escaped);");
5581       _builder.newLine();
5582       _builder.append("                    ");
5583       _builder.append("}");
5584       _builder.newLine();
5585       _builder.append("                ");
5586       _builder.append("} else if (c === \'\\\\\') {");
5587       _builder.newLine();
5588       _builder.append("                    ");
5589       _builder.append("esc = true;");
5590       _builder.newLine();
5591       _builder.append("                ");
5592       _builder.append("} else {");
5593       _builder.newLine();
5594       _builder.append("                    ");
5595       _builder.append("out += c;");
5596       _builder.newLine();
5597       _builder.append("                ");
5598       _builder.append("}");
5599       _builder.newLine();
5600       _builder.append("            ");
5601       _builder.append("}");
5602       _builder.newLine();
5603       _builder.append("            ");
5604       _builder.append("return out;");
5605       _builder.newLine();
5606       _builder.append("        ");
5607       _builder.append("}");
5608       _builder.newLine();
5609       _builder.newLine();
5610       _builder.append("    ");
5611       _builder.append("}");
5612       _builder.newLine();
5613       _builder.newLine();
5614       _builder.newLine();
5615       _builder.append("    ");
5616       _builder.append("if (typeof define === \"function\" && define.amd) {");
5617       _builder.newLine();
5618       _builder.append("        ");
5619       _builder.append("// Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )");
5620       _builder.newLine();
5621       _builder.append("        ");
5622       _builder.append("define([], function() {");
5623       _builder.newLine();
5624       _builder.append("            ");
5625       _builder.append("return { js_beautify: js_beautify };");
5626       _builder.newLine();
5627       _builder.append("        ");
5628       _builder.append("});");
5629       _builder.newLine();
5630       _builder.append("    ");
5631       _builder.append("} else if (typeof exports !== \"undefined\") {");
5632       _builder.newLine();
5633       _builder.append("        ");
5634       _builder.append("// Add support for CommonJS. Just put this file somewhere on your require.paths");
5635       _builder.newLine();
5636       _builder.append("        ");
5637       _builder.append("// and you will be able to `var js_beautify = require(\"beautify\").js_beautify`.");
5638       _builder.newLine();
5639       _builder.append("        ");
5640       _builder.append("exports.js_beautify = js_beautify;");
5641       _builder.newLine();
5642       _builder.append("    ");
5643       _builder.append("} else if (typeof window !== \"undefined\") {");
5644       _builder.newLine();
5645       _builder.append("        ");
5646       _builder.append("// If we\'re running a web page and don\'t have either of the above, add our one global");
5647       _builder.newLine();
5648       _builder.append("        ");
5649       _builder.append("window.js_beautify = js_beautify;");
5650       _builder.newLine();
5651       _builder.append("    ");
5652       _builder.append("} else if (typeof global !== \"undefined\") {");
5653       _builder.newLine();
5654       _builder.append("        ");
5655       _builder.append("// If we don\'t even have window, try global.");
5656       _builder.newLine();
5657       _builder.append("        ");
5658       _builder.append("global.js_beautify = js_beautify;");
5659       _builder.newLine();
5660       _builder.append("    ");
5661       _builder.append("}");
5662       _builder.newLine();
5663       _builder.newLine();
5664       _builder.append("}());");
5665       _builder.newLine();
5666       _builder.append("\t");
5667       _builder.newLine();
5668       return _builder.toString();
5669     }
5670   }.apply();
5671 }