mambascript 0.5.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/README.md +509 -267
  3. package/bin/mamba +1 -258
  4. package/decision.js +1 -246
  5. package/docs/coverage.md +70 -0
  6. package/docs/features.md +3348 -0
  7. package/docs/perf.md +94 -0
  8. package/docs/reference.md +1295 -0
  9. package/docs/vs-coffeescript.md +1593 -0
  10. package/docs/vs-iced-coffeescript.md +626 -0
  11. package/docs/vs-typescript.md +107 -0
  12. package/esm.js +8 -0
  13. package/jest.js +33 -0
  14. package/lib/black.js +17 -13
  15. package/lib/browser.js +2 -4
  16. package/lib/cli.js +207 -136
  17. package/lib/compiler.js +1162 -93
  18. package/lib/decision.js +10 -10
  19. package/lib/diagnostics.js +219 -0
  20. package/lib/esm-hooks.js +60 -0
  21. package/lib/fast-parser.js +3469 -0
  22. package/lib/functional-helpers.js +26 -9
  23. package/lib/helpers.js +67 -50
  24. package/lib/js-nodes.js +151 -12
  25. package/lib/lexer.js +1499 -0
  26. package/lib/light-module.js +200 -63
  27. package/lib/mamba.js +372 -0
  28. package/lib/module.js +23 -172
  29. package/lib/nodes.js +84 -21
  30. package/lib/optimiser.js +29 -9
  31. package/lib/optparse.js +32 -15
  32. package/lib/parser.js +9433 -4840
  33. package/lib/preprocessor.js +3 -5
  34. package/lib/register.js +49 -56
  35. package/lib/repl.js +28 -9
  36. package/lib/reporter.js +106 -69
  37. package/lib/run.js +3 -5
  38. package/lib/string-scanner.js +94 -0
  39. package/lib/syntax-tables.js +480 -0
  40. package/lib/type-checker.js +258 -44
  41. package/lib/type-helpers.js +28 -10
  42. package/lib/type-resolver.js +256 -34
  43. package/lib/type-scope.js +10 -6
  44. package/lib/type-walker.js +664 -85
  45. package/lib/types.js +17 -7
  46. package/lib/underscore.js +170 -76
  47. package/lib/unicode-classes.js +122 -0
  48. package/mambaview.js +1 -0
  49. package/package.json +49 -46
  50. package/stdlib.js +1 -0
  51. package/vendor/README.md +40 -0
  52. package/vendor/escodegen/LICENSE.BSD +19 -0
  53. package/vendor/escodegen/escodegen.js +2289 -0
  54. package/vendor/estraverse/LICENSE.BSD +19 -0
  55. package/vendor/estraverse/estraverse.js +706 -0
  56. package/vendor/mambacodegen/LICENSE +24 -0
  57. package/vendor/mambacodegen/lib/mscodegen.js +620 -0
  58. package/vendor/patches/escodegen.diff +130 -0
  59. package/vendor/patches/estraverse.diff +51 -0
  60. package/vendor/patches/pegjs.diff +70 -0
  61. package/vendor/patches/source-map.diff +160 -0
  62. package/vendor/source-map/LICENSE +28 -0
  63. package/vendor/source-map/lib/source-map/array-set.js +92 -0
  64. package/vendor/source-map/lib/source-map/base64-vlq.js +140 -0
  65. package/vendor/source-map/lib/source-map/base64.js +38 -0
  66. package/vendor/source-map/lib/source-map/binary-search.js +77 -0
  67. package/vendor/source-map/lib/source-map/source-map-consumer.js +404 -0
  68. package/vendor/source-map/lib/source-map/source-map-generator.js +229 -0
  69. package/vendor/source-map/lib/source-map/source-node.js +201 -0
  70. package/vendor/source-map/lib/source-map/util.js +57 -0
  71. package/vendor/source-map/lib/source-map.js +8 -0
  72. package/bin/fix +0 -17
  73. package/bin/updateImports +0 -46
  74. package/build.js +0 -25
  75. package/lib/module-esm.js +0 -901
  76. package/lib/pegjs-kofu-plugin.js +0 -35
  77. package/lib/pegjs-mamba-plugin.js +0 -35
  78. package/lib/processor-esm.js +0 -507
  79. package/mamba +0 -259
  80. package/msast.js +0 -1
  81. package/utils/gulp-mamba.js +0 -29
  82. /package/{lib/esm.js → vendor/patches/mambacodegen.diff} +0 -0
@@ -0,0 +1,2289 @@
1
+ /*
2
+ Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
3
+ Copyright (C) 2012-2013 Michael Ficarra <escodegen.copyright@michael.ficarra.me>
4
+ Copyright (C) 2012-2013 Mathias Bynens <mathias@qiwi.be>
5
+ Copyright (C) 2013 Irakli Gozalishvili <rfobic@gmail.com>
6
+ Copyright (C) 2012 Robert Gust-Bardon <donate@robert.gust-bardon.org>
7
+ Copyright (C) 2012 John Freeman <jfreeman08@gmail.com>
8
+ Copyright (C) 2011-2012 Ariya Hidayat <ariya.hidayat@gmail.com>
9
+ Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
10
+ Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
11
+ Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
12
+
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions are met:
15
+
16
+ * Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+ * Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in the
20
+ documentation and/or other materials provided with the distribution.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
26
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ */
33
+
34
+ /*global exports:true, generateStatement:true, generateExpression:true, require:true, global:true*/
35
+ /*
36
+ * Vendored into MambaScript from escodegen 0.0.28 (BSD-2-Clause, see LICENSE.BSD).
37
+ * In-house changes are listed in ../README.md and ../patches/escodegen.diff:
38
+ * relative requires, AwaitExpression + async function printing, esprima path removed.
39
+ */
40
+ (function () {
41
+ 'use strict';
42
+
43
+ var Syntax,
44
+ Precedence,
45
+ BinaryPrecedence,
46
+ Regex,
47
+ SourceNode,
48
+ estraverse,
49
+ isArray,
50
+ base,
51
+ indent,
52
+ json,
53
+ renumber,
54
+ hexadecimal,
55
+ quotes,
56
+ escapeless,
57
+ newline,
58
+ space,
59
+ parentheses,
60
+ semicolons,
61
+ safeConcatenation,
62
+ directive,
63
+ extra,
64
+ parse,
65
+ sourceMap,
66
+ FORMAT_MINIFY,
67
+ FORMAT_DEFAULTS;
68
+
69
+ estraverse = require('../estraverse/estraverse');
70
+
71
+ Syntax = {
72
+ AssignmentExpression: 'AssignmentExpression',
73
+ ArrayExpression: 'ArrayExpression',
74
+ ArrayPattern: 'ArrayPattern',
75
+ ArrowFunctionExpression: 'ArrowFunctionExpression',
76
+ AwaitExpression: 'AwaitExpression',
77
+ BlockStatement: 'BlockStatement',
78
+ BigIntLiteral: 'BigIntLiteral',
79
+ BinaryExpression: 'BinaryExpression',
80
+ BreakStatement: 'BreakStatement',
81
+ CallExpression: 'CallExpression',
82
+ CatchClause: 'CatchClause',
83
+ ComprehensionBlock: 'ComprehensionBlock',
84
+ ComprehensionExpression: 'ComprehensionExpression',
85
+ ConditionalExpression: 'ConditionalExpression',
86
+ ContinueStatement: 'ContinueStatement',
87
+ DirectiveStatement: 'DirectiveStatement',
88
+ DoWhileStatement: 'DoWhileStatement',
89
+ DebuggerStatement: 'DebuggerStatement',
90
+ EmptyStatement: 'EmptyStatement',
91
+ ExpressionStatement: 'ExpressionStatement',
92
+ ForStatement: 'ForStatement',
93
+ ForInStatement: 'ForInStatement',
94
+ ForOfStatement: 'ForOfStatement',
95
+ ImportDeclaration: 'ImportDeclaration',
96
+ ImportSpecifier: 'ImportSpecifier',
97
+ ImportDefaultSpecifier: 'ImportDefaultSpecifier',
98
+ ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
99
+ ImportExpression: 'ImportExpression',
100
+ ExportNamedDeclaration: 'ExportNamedDeclaration',
101
+ ExportSpecifier: 'ExportSpecifier',
102
+ ExportDefaultDeclaration: 'ExportDefaultDeclaration',
103
+ ExportAllDeclaration: 'ExportAllDeclaration',
104
+ FunctionDeclaration: 'FunctionDeclaration',
105
+ FunctionExpression: 'FunctionExpression',
106
+ Identifier: 'Identifier',
107
+ IfStatement: 'IfStatement',
108
+ Literal: 'Literal',
109
+ LabeledStatement: 'LabeledStatement',
110
+ LogicalExpression: 'LogicalExpression',
111
+ MemberExpression: 'MemberExpression',
112
+ NewExpression: 'NewExpression',
113
+ ObjectExpression: 'ObjectExpression',
114
+ ObjectPattern: 'ObjectPattern',
115
+ Program: 'Program',
116
+ Property: 'Property',
117
+ ReturnStatement: 'ReturnStatement',
118
+ SequenceExpression: 'SequenceExpression',
119
+ SwitchStatement: 'SwitchStatement',
120
+ TaggedTemplateExpression: 'TaggedTemplateExpression',
121
+ TemplateElement: 'TemplateElement',
122
+ TemplateLiteral: 'TemplateLiteral',
123
+ SwitchCase: 'SwitchCase',
124
+ ThisExpression: 'ThisExpression',
125
+ ThrowStatement: 'ThrowStatement',
126
+ TryStatement: 'TryStatement',
127
+ UnaryExpression: 'UnaryExpression',
128
+ UpdateExpression: 'UpdateExpression',
129
+ VariableDeclaration: 'VariableDeclaration',
130
+ VariableDeclarator: 'VariableDeclarator',
131
+ WhileStatement: 'WhileStatement',
132
+ WithStatement: 'WithStatement',
133
+ YieldExpression: 'YieldExpression'
134
+
135
+ };
136
+
137
+ Precedence = {
138
+ Sequence: 0,
139
+ Assignment: 1,
140
+ Yield: 1,
141
+ Conditional: 2,
142
+ ArrowFunction: 2,
143
+ LogicalOR: 3,
144
+ LogicalAND: 4,
145
+ BitwiseOR: 5,
146
+ BitwiseXOR: 6,
147
+ BitwiseAND: 7,
148
+ Equality: 8,
149
+ Relational: 9,
150
+ BitwiseSHIFT: 10,
151
+ Additive: 11,
152
+ Multiplicative: 12,
153
+ Unary: 13,
154
+ Await: 13,
155
+ Postfix: 14,
156
+ Call: 15,
157
+ TaggedTemplate: 15,
158
+ New: 16,
159
+ Member: 17,
160
+ Primary: 18
161
+ };
162
+
163
+ BinaryPrecedence = {
164
+ '||': Precedence.LogicalOR,
165
+ '&&': Precedence.LogicalAND,
166
+ '|': Precedence.BitwiseOR,
167
+ '^': Precedence.BitwiseXOR,
168
+ '&': Precedence.BitwiseAND,
169
+ '==': Precedence.Equality,
170
+ '!=': Precedence.Equality,
171
+ '===': Precedence.Equality,
172
+ '!==': Precedence.Equality,
173
+ 'is': Precedence.Equality,
174
+ 'isnt': Precedence.Equality,
175
+ '<': Precedence.Relational,
176
+ '>': Precedence.Relational,
177
+ '<=': Precedence.Relational,
178
+ '>=': Precedence.Relational,
179
+ 'in': Precedence.Relational,
180
+ 'instanceof': Precedence.Relational,
181
+ '<<': Precedence.BitwiseSHIFT,
182
+ '>>': Precedence.BitwiseSHIFT,
183
+ '>>>': Precedence.BitwiseSHIFT,
184
+ '+': Precedence.Additive,
185
+ '-': Precedence.Additive,
186
+ '*': Precedence.Multiplicative,
187
+ '%': Precedence.Multiplicative,
188
+ '/': Precedence.Multiplicative
189
+ };
190
+
191
+ Regex = {
192
+ NonAsciiIdentifierPart: new RegExp('[\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u0487\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f2\u0610-\u061a\u0620-\u0669\u066e-\u06d3\u06d5-\u06dc\u06df-\u06e8\u06ea-\u06fc\u06ff\u0710-\u074a\u074d-\u07b1\u07c0-\u07f5\u07fa\u0800-\u082d\u0840-\u085b\u08a0\u08a2-\u08ac\u08e4-\u08fe\u0900-\u0963\u0966-\u096f\u0971-\u0977\u0979-\u097f\u0981-\u0983\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bc-\u09c4\u09c7\u09c8\u09cb-\u09ce\u09d7\u09dc\u09dd\u09df-\u09e3\u09e6-\u09f1\u0a01-\u0a03\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a59-\u0a5c\u0a5e\u0a66-\u0a75\u0a81-\u0a83\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abc-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ad0\u0ae0-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3c-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5c\u0b5d\u0b5f-\u0b63\u0b66-\u0b6f\u0b71\u0b82\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd0\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c58\u0c59\u0c60-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbc-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0cde\u0ce0-\u0ce3\u0ce6-\u0cef\u0cf1\u0cf2\u0d02\u0d03\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d-\u0d44\u0d46-\u0d48\u0d4a-\u0d4e\u0d57\u0d60-\u0d63\u0d66-\u0d6f\u0d7a-\u0d7f\u0d82\u0d83\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e01-\u0e3a\u0e40-\u0e4e\u0e50-\u0e59\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb9\u0ebb-\u0ebd\u0ec0-\u0ec4\u0ec6\u0ec8-\u0ecd\u0ed0-\u0ed9\u0edc-\u0edf\u0f00\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e-\u0f47\u0f49-\u0f6c\u0f71-\u0f84\u0f86-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1049\u1050-\u109d\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\u135d-\u135f\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176c\u176e-\u1770\u1772\u1773\u1780-\u17d3\u17d7\u17dc\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1820-\u1877\u1880-\u18aa\u18b0-\u18f5\u1900-\u191c\u1920-\u192b\u1930-\u193b\u1946-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u19d0-\u19d9\u1a00-\u1a1b\u1a20-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1aa7\u1b00-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1bf3\u1c00-\u1c37\u1c40-\u1c49\u1c4d-\u1c7d\u1cd0-\u1cd2\u1cd4-\u1cf6\u1d00-\u1de6\u1dfc-\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\u200c\u200d\u203f\u2040\u2054\u2071\u207f\u2090-\u209c\u20d0-\u20dc\u20e1\u20e5-\u20f0\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-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d7f-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2de0-\u2dff\u2e2f\u3005-\u3007\u3021-\u302f\u3031-\u3035\u3038-\u303c\u3041-\u3096\u3099\u309a\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-\ua62b\ua640-\ua66f\ua674-\ua67d\ua67f-\ua697\ua69f-\ua6f1\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua827\ua840-\ua873\ua880-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f7\ua8fb\ua900-\ua92d\ua930-\ua953\ua960-\ua97c\ua980-\ua9c0\ua9cf-\ua9d9\uaa00-\uaa36\uaa40-\uaa4d\uaa50-\uaa59\uaa60-\uaa76\uaa7a\uaa7b\uaa80-\uaac2\uaadb-\uaadd\uaae0-\uaaef\uaaf2-\uaaf6\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabea\uabec\uabed\uabf0-\uabf9\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\ufe70-\ufe74\ufe76-\ufefc\uff10-\uff19\uff21-\uff3a\uff3f\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc]')
193
+ };
194
+
195
+ function getDefaultOptions() {
196
+ // default options
197
+ return {
198
+ indent: null,
199
+ base: null,
200
+ parse: null,
201
+ comment: false,
202
+ format: {
203
+ indent: {
204
+ style: ' ',
205
+ base: 0,
206
+ adjustMultilineComment: false
207
+ },
208
+ newline: '\n',
209
+ space: ' ',
210
+ json: false,
211
+ renumber: false,
212
+ hexadecimal: false,
213
+ quotes: 'single',
214
+ escapeless: false,
215
+ compact: false,
216
+ parentheses: true,
217
+ semicolons: true,
218
+ safeConcatenation: false
219
+ },
220
+ moz: {
221
+ starlessGenerator: false,
222
+ parenthesizedComprehensionBlock: false
223
+ },
224
+ sourceMap: null,
225
+ sourceMapRoot: null,
226
+ sourceMapWithCode: false,
227
+ directive: false,
228
+ verbatim: null
229
+ };
230
+ }
231
+
232
+ function stringToArray(str) {
233
+ var length = str.length,
234
+ result = [],
235
+ i;
236
+ for (i = 0; i < length; i += 1) {
237
+ result[i] = str.charAt(i);
238
+ }
239
+ return result;
240
+ }
241
+
242
+ function stringRepeat(str, num) {
243
+ var result = '';
244
+
245
+ for (num |= 0; num > 0; num >>>= 1, str += str) {
246
+ if (num & 1) {
247
+ result += str;
248
+ }
249
+ }
250
+
251
+ return result;
252
+ }
253
+
254
+ isArray = Array.isArray;
255
+ if (!isArray) {
256
+ isArray = function isArray(array) {
257
+ return Object.prototype.toString.call(array) === '[object Array]';
258
+ };
259
+ }
260
+
261
+ // Fallback for the non SourceMap environment
262
+ function SourceNodeMock(line, column, filename, chunk) {
263
+ var result = [];
264
+
265
+ function flatten(input) {
266
+ var i, iz;
267
+ if (isArray(input)) {
268
+ for (i = 0, iz = input.length; i < iz; ++i) {
269
+ flatten(input[i]);
270
+ }
271
+ } else if (input instanceof SourceNodeMock) {
272
+ result.push(input);
273
+ } else if (typeof input === 'string' && input) {
274
+ result.push(input);
275
+ }
276
+ }
277
+
278
+ flatten(chunk);
279
+ this.children = result;
280
+ }
281
+
282
+ SourceNodeMock.prototype.toString = function toString() {
283
+ var res = '', i, iz, node;
284
+ for (i = 0, iz = this.children.length; i < iz; ++i) {
285
+ node = this.children[i];
286
+ if (node instanceof SourceNodeMock) {
287
+ res += node.toString();
288
+ } else {
289
+ res += node;
290
+ }
291
+ }
292
+ return res;
293
+ };
294
+
295
+ SourceNodeMock.prototype.replaceRight = function replaceRight(pattern, replacement) {
296
+ var last = this.children[this.children.length - 1];
297
+ if (last instanceof SourceNodeMock) {
298
+ last.replaceRight(pattern, replacement);
299
+ } else if (typeof last === 'string') {
300
+ this.children[this.children.length - 1] = last.replace(pattern, replacement);
301
+ } else {
302
+ this.children.push(''.replace(pattern, replacement));
303
+ }
304
+ return this;
305
+ };
306
+
307
+ SourceNodeMock.prototype.join = function join(sep) {
308
+ var i, iz, result;
309
+ result = [];
310
+ iz = this.children.length;
311
+ if (iz > 0) {
312
+ for (i = 0, iz -= 1; i < iz; ++i) {
313
+ result.push(this.children[i], sep);
314
+ }
315
+ result.push(this.children[iz]);
316
+ this.children = result;
317
+ }
318
+ return this;
319
+ };
320
+
321
+ function hasLineTerminator(str) {
322
+ return (/[\r\n]/g).test(str);
323
+ }
324
+
325
+ function endsWithLineTerminator(str) {
326
+ var ch = str.charAt(str.length - 1);
327
+ return ch && isLineTerminator(ch);
328
+ }
329
+
330
+ function updateDeeply(target, override) {
331
+ var key, val;
332
+
333
+ function isHashObject(target) {
334
+ return typeof target === 'object' && target instanceof Object && !(target instanceof RegExp);
335
+ }
336
+
337
+ for (key in override) {
338
+ if (override.hasOwnProperty(key)) {
339
+ val = override[key];
340
+ if (isHashObject(val)) {
341
+ if (isHashObject(target[key])) {
342
+ updateDeeply(target[key], val);
343
+ } else {
344
+ target[key] = updateDeeply({}, val);
345
+ }
346
+ } else {
347
+ target[key] = val;
348
+ }
349
+ }
350
+ }
351
+ return target;
352
+ }
353
+
354
+ function generateNumber(value) {
355
+ var result, point, temp, exponent, pos;
356
+
357
+ if (value !== value) {
358
+ throw new Error('Numeric literal whose value is NaN');
359
+ }
360
+ if (value < 0 || (value === 0 && 1 / value < 0)) {
361
+ throw new Error('Numeric literal whose value is negative');
362
+ }
363
+
364
+ if (value === 1 / 0) {
365
+ return json ? 'null' : renumber ? '1e400' : '1e+400';
366
+ }
367
+
368
+ result = '' + value;
369
+ if (!renumber || result.length < 3) {
370
+ return result;
371
+ }
372
+
373
+ point = result.indexOf('.');
374
+ if (!json && result.charAt(0) === '0' && point === 1) {
375
+ point = 0;
376
+ result = result.slice(1);
377
+ }
378
+ temp = result;
379
+ result = result.replace('e+', 'e');
380
+ exponent = 0;
381
+ if ((pos = temp.indexOf('e')) > 0) {
382
+ exponent = +temp.slice(pos + 1);
383
+ temp = temp.slice(0, pos);
384
+ }
385
+ if (point >= 0) {
386
+ exponent -= temp.length - point - 1;
387
+ temp = +(temp.slice(0, point) + temp.slice(point + 1)) + '';
388
+ }
389
+ pos = 0;
390
+ while (temp.charAt(temp.length + pos - 1) === '0') {
391
+ pos -= 1;
392
+ }
393
+ if (pos !== 0) {
394
+ exponent -= pos;
395
+ temp = temp.slice(0, pos);
396
+ }
397
+ if (exponent !== 0) {
398
+ temp += 'e' + exponent;
399
+ }
400
+ if ((temp.length < result.length ||
401
+ (hexadecimal && value > 1e12 && Math.floor(value) === value && (temp = '0x' + value.toString(16)).length < result.length)) &&
402
+ +temp === value) {
403
+ result = temp;
404
+ }
405
+
406
+ return result;
407
+ }
408
+
409
+ // Generate valid RegExp expression.
410
+ // This function is based on https://github.com/Constellation/iv Engine
411
+
412
+ function escapeRegExpCharacter(ch, previousIsBackslash) {
413
+ // not handling '\' and handling \u2028 or \u2029 to unicode escape sequence
414
+ if ((ch & ~1) === 0x2028) {
415
+ return (previousIsBackslash ? 'u' : '\\u') + ((ch === 0x2028) ? '2028' : '2029');
416
+ } else if (ch === 10 || ch === 13) { // \n, \r
417
+ return (previousIsBackslash ? '' : '\\') + ((ch === 10) ? 'n' : 'r');
418
+ }
419
+ return String.fromCharCode(ch);
420
+ }
421
+
422
+ function generateRegExp(reg) {
423
+ var match, result, flags, i, iz, ch, characterInBrack, previousIsBackslash;
424
+
425
+ result = reg.toString();
426
+
427
+ if (reg.source) {
428
+ // extract flag from toString result
429
+ match = result.match(/\/([^/]*)$/);
430
+ if (!match) {
431
+ return result;
432
+ }
433
+
434
+ flags = match[1];
435
+ result = '';
436
+
437
+ characterInBrack = false;
438
+ previousIsBackslash = false;
439
+ for (i = 0, iz = reg.source.length; i < iz; ++i) {
440
+ ch = reg.source.charCodeAt(i);
441
+
442
+ if (!previousIsBackslash) {
443
+ if (characterInBrack) {
444
+ if (ch === 93) { // ]
445
+ characterInBrack = false;
446
+ }
447
+ } else {
448
+ if (ch === 47) { // /
449
+ result += '\\';
450
+ } else if (ch === 91) { // [
451
+ characterInBrack = true;
452
+ }
453
+ }
454
+ result += escapeRegExpCharacter(ch, previousIsBackslash);
455
+ previousIsBackslash = ch === 92; // \
456
+ } else {
457
+ // if new RegExp("\\\n') is provided, create /\n/
458
+ result += escapeRegExpCharacter(ch, previousIsBackslash);
459
+ // prevent like /\\[/]/
460
+ previousIsBackslash = false;
461
+ }
462
+ }
463
+
464
+ return '/' + result + '/' + flags;
465
+ }
466
+
467
+ return result;
468
+ }
469
+
470
+ function escapeAllowedCharacter(ch, next) {
471
+ var code = ch.charCodeAt(0), hex = code.toString(16), result = '\\';
472
+
473
+ switch (ch) {
474
+ case '\b':
475
+ result += 'b';
476
+ break;
477
+ case '\f':
478
+ result += 'f';
479
+ break;
480
+ case '\t':
481
+ result += 't';
482
+ break;
483
+ default:
484
+ if (json || code > 0xff) {
485
+ result += 'u' + '0000'.slice(hex.length) + hex;
486
+ } else if (ch === '\u0000' && '0123456789'.indexOf(next) < 0) {
487
+ result += '0';
488
+ } else if (ch === '\x0B') { // '\v'
489
+ result += 'x0B';
490
+ } else {
491
+ result += 'x' + '00'.slice(hex.length) + hex;
492
+ }
493
+ break;
494
+ }
495
+
496
+ return result;
497
+ }
498
+
499
+ function escapeDisallowedCharacter(ch) {
500
+ var result = '\\';
501
+ switch (ch) {
502
+ case '\\':
503
+ result += '\\';
504
+ break;
505
+ case '\n':
506
+ result += 'n';
507
+ break;
508
+ case '\r':
509
+ result += 'r';
510
+ break;
511
+ case '\u2028':
512
+ result += 'u2028';
513
+ break;
514
+ case '\u2029':
515
+ result += 'u2029';
516
+ break;
517
+ default:
518
+ throw new Error('Incorrectly classified character');
519
+ }
520
+
521
+ return result;
522
+ }
523
+
524
+ function escapeDirective(str) {
525
+ var i, iz, ch, buf, quote;
526
+
527
+ buf = str;
528
+ if (typeof buf[0] === 'undefined') {
529
+ buf = stringToArray(buf);
530
+ }
531
+
532
+ quote = quotes === 'double' ? '"' : '\'';
533
+ for (i = 0, iz = buf.length; i < iz; i += 1) {
534
+ ch = buf[i];
535
+ if (ch === '\'') {
536
+ quote = '"';
537
+ break;
538
+ } else if (ch === '"') {
539
+ quote = '\'';
540
+ break;
541
+ } else if (ch === '\\') {
542
+ i += 1;
543
+ }
544
+ }
545
+
546
+ return quote + str + quote;
547
+ }
548
+
549
+ function escapeString(str) {
550
+ var result = '', i, len, ch, singleQuotes = 0, doubleQuotes = 0, single;
551
+
552
+ if (typeof str[0] === 'undefined') {
553
+ str = stringToArray(str);
554
+ }
555
+
556
+ for (i = 0, len = str.length; i < len; i += 1) {
557
+ ch = str[i];
558
+ if (ch === '\'') {
559
+ singleQuotes += 1;
560
+ } else if (ch === '"') {
561
+ doubleQuotes += 1;
562
+ } else if (ch === '/' && json) {
563
+ result += '\\';
564
+ } else if ('\\\n\r\u2028\u2029'.indexOf(ch) >= 0) {
565
+ result += escapeDisallowedCharacter(ch);
566
+ continue;
567
+ } else if ((json && ch < ' ') || !(json || escapeless || (ch >= ' ' && ch <= '~'))) {
568
+ result += escapeAllowedCharacter(ch, str[i + 1]);
569
+ continue;
570
+ }
571
+ result += ch;
572
+ }
573
+
574
+ single = !(quotes === 'double' || (quotes === 'auto' && doubleQuotes < singleQuotes));
575
+ str = result;
576
+ result = single ? '\'' : '"';
577
+
578
+ if (typeof str[0] === 'undefined') {
579
+ str = stringToArray(str);
580
+ }
581
+
582
+ for (i = 0, len = str.length; i < len; i += 1) {
583
+ ch = str[i];
584
+ if ((ch === '\'' && single) || (ch === '"' && !single)) {
585
+ result += '\\';
586
+ }
587
+ result += ch;
588
+ }
589
+
590
+ return result + (single ? '\'' : '"');
591
+ }
592
+
593
+ function isWhiteSpace(ch) {
594
+ // Use `\x0B` instead of `\v` for IE < 9 compatibility
595
+ return '\t\x0B\f \xa0'.indexOf(ch) >= 0 || (ch.charCodeAt(0) >= 0x1680 && '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\ufeff'.indexOf(ch) >= 0);
596
+ }
597
+
598
+ function isLineTerminator(ch) {
599
+ return '\n\r\u2028\u2029'.indexOf(ch) >= 0;
600
+ }
601
+
602
+ function isIdentifierPart(ch) {
603
+ return (ch === '$') || (ch === '_') || (ch === '\\') ||
604
+ (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
605
+ ((ch >= '0') && (ch <= '9')) ||
606
+ ((ch.charCodeAt(0) >= 0x80) && Regex.NonAsciiIdentifierPart.test(ch));
607
+ }
608
+
609
+ // takes char code
610
+ function isDecimalDigit(ch) {
611
+ return (ch >= 48 && ch <= 57); // 0..9
612
+ }
613
+
614
+ function toSourceNode(generated, node) {
615
+ if (node == null) {
616
+ if (generated instanceof SourceNode) {
617
+ return generated;
618
+ } else {
619
+ node = {};
620
+ }
621
+ }
622
+ if (node.loc == null) {
623
+ return new SourceNode(null, null, sourceMap, generated, node.name || null);
624
+ }
625
+ return new SourceNode(node.loc.start.line, node.loc.start.column, (sourceMap === true ? node.loc.source || null : sourceMap), generated, node.name || null);
626
+ }
627
+
628
+ function noEmptySpace() {
629
+ return (space) ? space : ' ';
630
+ }
631
+
632
+ function join(left, right) {
633
+ var leftSource = toSourceNode(left).toString(),
634
+ rightSource = toSourceNode(right).toString(),
635
+ leftChar = leftSource.charAt(leftSource.length - 1),
636
+ rightChar = rightSource.charAt(0);
637
+
638
+ if ((leftChar === '+' || leftChar === '-') && leftChar === rightChar ||
639
+ isIdentifierPart(leftChar) && isIdentifierPart(rightChar) ||
640
+ leftChar === '/' && rightChar === 'i') { // infix word operators all start with `i`
641
+ return [left, noEmptySpace(), right];
642
+ } else if (isWhiteSpace(leftChar) || isLineTerminator(leftChar) || isWhiteSpace(rightChar) || isLineTerminator(rightChar)) {
643
+ return [left, right];
644
+ }
645
+ return [left, space, right];
646
+ }
647
+
648
+ function addIndent(stmt) {
649
+ return [base, stmt];
650
+ }
651
+
652
+ function withIndent(fn) {
653
+ var previousBase, result;
654
+ previousBase = base;
655
+ base += indent;
656
+ result = fn.call(this, base);
657
+ base = previousBase;
658
+ return result;
659
+ }
660
+
661
+ function calculateSpaces(str) {
662
+ var i;
663
+ for (i = str.length - 1; i >= 0; i -= 1) {
664
+ if (isLineTerminator(str.charAt(i))) {
665
+ break;
666
+ }
667
+ }
668
+ return (str.length - 1) - i;
669
+ }
670
+
671
+ function adjustMultilineComment(value, specialBase) {
672
+ var array, i, len, line, j, spaces, previousBase;
673
+
674
+ array = value.split(/\r\n|[\r\n]/);
675
+ spaces = Number.MAX_VALUE;
676
+
677
+ // first line doesn't have indentation
678
+ for (i = 1, len = array.length; i < len; i += 1) {
679
+ line = array[i];
680
+ j = 0;
681
+ while (j < line.length && isWhiteSpace(line[j])) {
682
+ j += 1;
683
+ }
684
+ if (spaces > j) {
685
+ spaces = j;
686
+ }
687
+ }
688
+
689
+ if (typeof specialBase !== 'undefined') {
690
+ // pattern like
691
+ // {
692
+ // var t = 20; /*
693
+ // * this is comment
694
+ // */
695
+ // }
696
+ previousBase = base;
697
+ if (array[1][spaces] === '*') {
698
+ specialBase += ' ';
699
+ }
700
+ base = specialBase;
701
+ } else {
702
+ if (spaces & 1) {
703
+ // /*
704
+ // *
705
+ // */
706
+ // If spaces are odd number, above pattern is considered.
707
+ // We waste 1 space.
708
+ spaces -= 1;
709
+ }
710
+ previousBase = base;
711
+ }
712
+
713
+ for (i = 1, len = array.length; i < len; i += 1) {
714
+ array[i] = toSourceNode(addIndent(array[i].slice(spaces))).join('');
715
+ }
716
+
717
+ base = previousBase;
718
+
719
+ return array.join('\n');
720
+ }
721
+
722
+ function generateComment(comment, specialBase) {
723
+ if (comment.type === 'Line') {
724
+ if (endsWithLineTerminator(comment.value)) {
725
+ return '//' + comment.value;
726
+ } else {
727
+ // Always use LineTerminator
728
+ return '//' + comment.value + '\n';
729
+ }
730
+ }
731
+ if (extra.format.indent.adjustMultilineComment && /[\n\r]/.test(comment.value)) {
732
+ return adjustMultilineComment('/*' + comment.value + '*/', specialBase);
733
+ }
734
+ return '/*' + comment.value + '*/';
735
+ }
736
+
737
+ function addCommentsToStatement(stmt, result) {
738
+ var i, len, comment, save, tailingToStatement, specialBase, fragment;
739
+
740
+ if (stmt.leadingComments && stmt.leadingComments.length > 0) {
741
+ save = result;
742
+
743
+ comment = stmt.leadingComments[0];
744
+ result = [];
745
+ if (safeConcatenation && stmt.type === Syntax.Program && stmt.body.length === 0) {
746
+ result.push('\n');
747
+ }
748
+ result.push(generateComment(comment));
749
+ if (!endsWithLineTerminator(toSourceNode(result).toString())) {
750
+ result.push('\n');
751
+ }
752
+
753
+ for (i = 1, len = stmt.leadingComments.length; i < len; i += 1) {
754
+ comment = stmt.leadingComments[i];
755
+ fragment = [generateComment(comment)];
756
+ if (!endsWithLineTerminator(toSourceNode(fragment).toString())) {
757
+ fragment.push('\n');
758
+ }
759
+ result.push(addIndent(fragment));
760
+ }
761
+
762
+ result.push(addIndent(save));
763
+ }
764
+
765
+ if (stmt.trailingComments) {
766
+ tailingToStatement = !endsWithLineTerminator(toSourceNode(result).toString());
767
+ specialBase = stringRepeat(' ', calculateSpaces(toSourceNode([base, result, indent]).toString()));
768
+ for (i = 0, len = stmt.trailingComments.length; i < len; i += 1) {
769
+ comment = stmt.trailingComments[i];
770
+ if (tailingToStatement) {
771
+ // We assume target like following script
772
+ //
773
+ // var t = 20; /**
774
+ // * This is comment of t
775
+ // */
776
+ if (i === 0) {
777
+ // first case
778
+ result = [result, indent];
779
+ } else {
780
+ result = [result, specialBase];
781
+ }
782
+ result.push(generateComment(comment, specialBase));
783
+ } else {
784
+ result = [result, addIndent(generateComment(comment))];
785
+ }
786
+ if (i !== len - 1 && !endsWithLineTerminator(toSourceNode(result).toString())) {
787
+ result = [result, '\n'];
788
+ }
789
+ }
790
+ }
791
+
792
+ return result;
793
+ }
794
+
795
+ function parenthesize(text, current, should) {
796
+ if (current < should) {
797
+ return ['(', text, ')'];
798
+ }
799
+ return text;
800
+ }
801
+
802
+ function maybeBlock(stmt, semicolonOptional, functionBody) {
803
+ var result, noLeadingComment;
804
+
805
+ noLeadingComment = !extra.comment || !stmt.leadingComments;
806
+
807
+ if (stmt.type === Syntax.BlockStatement && noLeadingComment) {
808
+ return [space, generateStatement(stmt, { functionBody: functionBody })];
809
+ }
810
+
811
+ if (stmt.type === Syntax.EmptyStatement && noLeadingComment) {
812
+ return ';';
813
+ }
814
+
815
+ withIndent(function () {
816
+ result = [newline, addIndent(generateStatement(stmt, { semicolonOptional: semicolonOptional, functionBody: functionBody }))];
817
+ });
818
+
819
+ return result;
820
+ }
821
+
822
+ function maybeBlockSuffix(stmt, result) {
823
+ var ends = endsWithLineTerminator(toSourceNode(result).toString());
824
+ if (stmt.type === Syntax.BlockStatement && (!extra.comment || !stmt.leadingComments) && !ends) {
825
+ return [result, space];
826
+ }
827
+ if (ends) {
828
+ return [result, base];
829
+ }
830
+ return [result, newline, base];
831
+ }
832
+
833
+ function generateVerbatim(expr, option) {
834
+ var i, result;
835
+ result = expr[extra.verbatim].split(/\r\n|\n/);
836
+ for (i = 1; i < result.length; i++) {
837
+ result[i] = newline + base + result[i];
838
+ }
839
+
840
+ result = parenthesize(result, Precedence.Sequence, option.precedence);
841
+ return toSourceNode(result, expr);
842
+ }
843
+
844
+ function generateIdentifier(node) {
845
+ return toSourceNode(node.name, node);
846
+ }
847
+
848
+ function generateFunctionBody(node) {
849
+ var result, i, len, expr, arrow;
850
+
851
+ arrow = node.type === Syntax.ArrowFunctionExpression;
852
+
853
+ if (arrow && node.params.length === 1 && node.params[0].type === Syntax.Identifier) {
854
+ // arg => { } case
855
+ result = [generateIdentifier(node.params[0])];
856
+ } else {
857
+ result = ['('];
858
+ for (i = 0, len = node.params.length; i < len; i += 1) {
859
+ result.push(generateIdentifier(node.params[i]));
860
+ if (i + 1 < len) {
861
+ result.push(',' + space);
862
+ }
863
+ }
864
+ result.push(')');
865
+ }
866
+
867
+ if (arrow) {
868
+ result.push(space, '=>');
869
+ }
870
+
871
+ if (node.expression) {
872
+ result.push(space);
873
+ expr = generateExpression(node.body, {
874
+ precedence: Precedence.Assignment,
875
+ allowIn: true,
876
+ allowCall: true
877
+ });
878
+ if (expr.toString().charAt(0) === '{') {
879
+ expr = ['(', expr, ')'];
880
+ }
881
+ result.push(expr);
882
+ } else {
883
+ result.push(maybeBlock(node.body, false, true));
884
+ }
885
+ return result;
886
+ }
887
+
888
+ function generateExpression(expr, option) {
889
+ var result,
890
+ precedence,
891
+ type,
892
+ currentPrecedence,
893
+ i,
894
+ len,
895
+ raw,
896
+ fragment,
897
+ multiline,
898
+ leftChar,
899
+ leftSource,
900
+ rightChar,
901
+ allowIn,
902
+ allowCall,
903
+ allowUnparenthesizedNew,
904
+ property;
905
+
906
+ precedence = option.precedence;
907
+ allowIn = option.allowIn;
908
+ allowCall = option.allowCall;
909
+ type = expr.type || option.type;
910
+
911
+ if (extra.verbatim && expr.hasOwnProperty(extra.verbatim)) {
912
+ return generateVerbatim(expr, option);
913
+ }
914
+
915
+ switch (type) {
916
+ case Syntax.SequenceExpression:
917
+ result = [];
918
+ allowIn |= (Precedence.Sequence < precedence);
919
+ for (i = 0, len = expr.expressions.length; i < len; i += 1) {
920
+ result.push(generateExpression(expr.expressions[i], {
921
+ precedence: Precedence.Assignment,
922
+ allowIn: allowIn,
923
+ allowCall: true
924
+ }));
925
+ if (i + 1 < len) {
926
+ result.push(',' + space);
927
+ }
928
+ }
929
+ result = parenthesize(result, Precedence.Sequence, precedence);
930
+ break;
931
+
932
+ case Syntax.AssignmentExpression:
933
+ allowIn |= (Precedence.Assignment < precedence);
934
+ result = parenthesize(
935
+ [
936
+ generateExpression(expr.left, {
937
+ precedence: Precedence.Call,
938
+ allowIn: allowIn,
939
+ allowCall: true
940
+ }),
941
+ space + expr.operator + space,
942
+ generateExpression(expr.right, {
943
+ precedence: Precedence.Assignment,
944
+ allowIn: allowIn,
945
+ allowCall: true
946
+ })
947
+ ],
948
+ Precedence.Assignment,
949
+ precedence
950
+ );
951
+ break;
952
+
953
+ case Syntax.ArrowFunctionExpression:
954
+ allowIn |= (Precedence.ArrowFunction < precedence);
955
+ result = parenthesize(generateFunctionBody(expr), Precedence.ArrowFunction, precedence);
956
+ break;
957
+
958
+ case Syntax.ConditionalExpression:
959
+ allowIn |= (Precedence.Conditional < precedence);
960
+ result = parenthesize(
961
+ [
962
+ generateExpression(expr.test, {
963
+ precedence: Precedence.LogicalOR,
964
+ allowIn: allowIn,
965
+ allowCall: true
966
+ }),
967
+ space + '?' + space,
968
+ generateExpression(expr.consequent, {
969
+ precedence: Precedence.Assignment,
970
+ allowIn: allowIn,
971
+ allowCall: true
972
+ }),
973
+ space + ':' + space,
974
+ generateExpression(expr.alternate, {
975
+ precedence: Precedence.Assignment,
976
+ allowIn: allowIn,
977
+ allowCall: true
978
+ })
979
+ ],
980
+ Precedence.Conditional,
981
+ precedence
982
+ );
983
+ break;
984
+
985
+ case Syntax.LogicalExpression:
986
+ case Syntax.BinaryExpression:
987
+ currentPrecedence = BinaryPrecedence[expr.operator];
988
+
989
+ allowIn |= (currentPrecedence < precedence);
990
+
991
+ fragment = generateExpression(expr.left, {
992
+ precedence: currentPrecedence,
993
+ allowIn: allowIn,
994
+ allowCall: true
995
+ });
996
+
997
+ leftSource = fragment.toString();
998
+
999
+ if (leftSource.charAt(leftSource.length - 1) === '/' && isIdentifierPart(expr.operator.charAt(0))) {
1000
+ result = [fragment, noEmptySpace(), expr.operator];
1001
+ } else {
1002
+ result = join(fragment, expr.operator);
1003
+ }
1004
+
1005
+ fragment = generateExpression(expr.right, {
1006
+ precedence: currentPrecedence + 1,
1007
+ allowIn: allowIn,
1008
+ allowCall: true
1009
+ });
1010
+
1011
+ if (expr.operator === '/' && fragment.toString().charAt(0) === '/' ||
1012
+ expr.operator.slice(-1) === '<' && fragment.toString().slice(0, 3) === '!--') {
1013
+ // If '/' concats with '/' or `<` concats with `!--`, it is interpreted as comment start
1014
+ result.push(noEmptySpace(), fragment);
1015
+ } else {
1016
+ result = join(result, fragment);
1017
+ }
1018
+
1019
+ if (expr.operator === 'in' && !allowIn) {
1020
+ result = ['(', result, ')'];
1021
+ } else {
1022
+ result = parenthesize(result, currentPrecedence, precedence);
1023
+ }
1024
+
1025
+ break;
1026
+
1027
+ case Syntax.CallExpression:
1028
+ result = [generateExpression(expr.callee, {
1029
+ precedence: Precedence.Call,
1030
+ allowIn: true,
1031
+ allowCall: true,
1032
+ allowUnparenthesizedNew: false
1033
+ })];
1034
+
1035
+ result.push('(');
1036
+ for (i = 0, len = expr['arguments'].length; i < len; i += 1) {
1037
+ result.push(generateExpression(expr['arguments'][i], {
1038
+ precedence: Precedence.Assignment,
1039
+ allowIn: true,
1040
+ allowCall: true
1041
+ }));
1042
+ if (i + 1 < len) {
1043
+ result.push(',' + space);
1044
+ }
1045
+ }
1046
+ result.push(')');
1047
+
1048
+ if (!allowCall) {
1049
+ result = ['(', result, ')'];
1050
+ } else {
1051
+ result = parenthesize(result, Precedence.Call, precedence);
1052
+ }
1053
+ break;
1054
+
1055
+ case Syntax.NewExpression:
1056
+ len = expr['arguments'].length;
1057
+ allowUnparenthesizedNew = option.allowUnparenthesizedNew === undefined || option.allowUnparenthesizedNew;
1058
+
1059
+ result = join(
1060
+ 'new',
1061
+ generateExpression(expr.callee, {
1062
+ precedence: Precedence.New,
1063
+ allowIn: true,
1064
+ allowCall: false,
1065
+ allowUnparenthesizedNew: allowUnparenthesizedNew && !parentheses && len === 0
1066
+ })
1067
+ );
1068
+
1069
+ if (!allowUnparenthesizedNew || parentheses || len > 0) {
1070
+ result.push('(');
1071
+ for (i = 0; i < len; i += 1) {
1072
+ result.push(generateExpression(expr['arguments'][i], {
1073
+ precedence: Precedence.Assignment,
1074
+ allowIn: true,
1075
+ allowCall: true
1076
+ }));
1077
+ if (i + 1 < len) {
1078
+ result.push(',' + space);
1079
+ }
1080
+ }
1081
+ result.push(')');
1082
+ }
1083
+
1084
+ result = parenthesize(result, Precedence.New, precedence);
1085
+ break;
1086
+
1087
+ case Syntax.MemberExpression:
1088
+ result = [generateExpression(expr.object, {
1089
+ precedence: Precedence.Call,
1090
+ allowIn: true,
1091
+ allowCall: allowCall,
1092
+ allowUnparenthesizedNew: false
1093
+ })];
1094
+
1095
+ if (expr.computed) {
1096
+ result.push('[', generateExpression(expr.property, {
1097
+ precedence: Precedence.Sequence,
1098
+ allowIn: true,
1099
+ allowCall: allowCall
1100
+ }), ']');
1101
+ } else {
1102
+ if (expr.object.type === Syntax.Literal && typeof expr.object.value === 'number') {
1103
+ fragment = toSourceNode(result).toString();
1104
+ // When the following conditions are all true,
1105
+ // 1. No floating point
1106
+ // 2. Don't have exponents
1107
+ // 3. The last character is a decimal digit
1108
+ // 4. Not hexadecimal OR octal number literal
1109
+ // we should add a floating point.
1110
+ if (
1111
+ fragment.indexOf('.') < 0 &&
1112
+ !/[eExX]/.test(fragment) &&
1113
+ isDecimalDigit(fragment.charCodeAt(fragment.length - 1)) &&
1114
+ !(fragment.length >= 2 && fragment.charCodeAt(0) === 48) // '0'
1115
+ ) {
1116
+ result.push('.');
1117
+ }
1118
+ }
1119
+ result.push('.', generateIdentifier(expr.property));
1120
+ }
1121
+
1122
+ result = parenthesize(result, Precedence.Member, precedence);
1123
+ break;
1124
+
1125
+ case Syntax.UnaryExpression:
1126
+ fragment = generateExpression(expr.argument, {
1127
+ precedence: Precedence.Unary,
1128
+ allowIn: true,
1129
+ allowCall: true
1130
+ });
1131
+
1132
+ if (space === '') {
1133
+ result = join(expr.operator, fragment);
1134
+ } else {
1135
+ result = [expr.operator];
1136
+ if (expr.operator.length > 2) {
1137
+ // delete, void, typeof
1138
+ // get `typeof []`, not `typeof[]`
1139
+ result = join(result, fragment);
1140
+ } else {
1141
+ // Prevent inserting spaces between operator and argument if it is unnecessary
1142
+ // like, `!cond`
1143
+ leftSource = toSourceNode(result).toString();
1144
+ leftChar = leftSource.charAt(leftSource.length - 1);
1145
+ rightChar = fragment.toString().charAt(0);
1146
+
1147
+ if (((leftChar === '+' || leftChar === '-') && leftChar === rightChar) || (isIdentifierPart(leftChar) && isIdentifierPart(rightChar))) {
1148
+ result.push(noEmptySpace(), fragment);
1149
+ } else {
1150
+ result.push(fragment);
1151
+ }
1152
+ }
1153
+ }
1154
+ result = parenthesize(result, Precedence.Unary, precedence);
1155
+ break;
1156
+
1157
+ case Syntax.AwaitExpression:
1158
+ // MambaScript: `waitForIt expr`. Same precedence as unary operators.
1159
+ fragment = generateExpression(expr.argument, {
1160
+ precedence: Precedence.Unary,
1161
+ allowIn: true,
1162
+ allowCall: true
1163
+ });
1164
+ result = parenthesize(join('await', fragment), Precedence.Await, precedence);
1165
+ break;
1166
+
1167
+ case Syntax.YieldExpression:
1168
+ if (expr.delegate) {
1169
+ result = 'yield*';
1170
+ } else {
1171
+ result = 'yield';
1172
+ }
1173
+ if (expr.argument) {
1174
+ result = join(
1175
+ result,
1176
+ generateExpression(expr.argument, {
1177
+ precedence: Precedence.Assignment,
1178
+ allowIn: true,
1179
+ allowCall: true
1180
+ })
1181
+ );
1182
+ }
1183
+ // MambaScript: `(yield x) + 1`, `f((yield x))` need the parentheses
1184
+ result = parenthesize(result, Precedence.Yield, precedence);
1185
+ break;
1186
+
1187
+ case Syntax.UpdateExpression:
1188
+ if (expr.prefix) {
1189
+ result = parenthesize(
1190
+ [
1191
+ expr.operator,
1192
+ generateExpression(expr.argument, {
1193
+ precedence: Precedence.Unary,
1194
+ allowIn: true,
1195
+ allowCall: true
1196
+ })
1197
+ ],
1198
+ Precedence.Unary,
1199
+ precedence
1200
+ );
1201
+ } else {
1202
+ result = parenthesize(
1203
+ [
1204
+ generateExpression(expr.argument, {
1205
+ precedence: Precedence.Postfix,
1206
+ allowIn: true,
1207
+ allowCall: true
1208
+ }),
1209
+ expr.operator
1210
+ ],
1211
+ Precedence.Postfix,
1212
+ precedence
1213
+ );
1214
+ }
1215
+ break;
1216
+
1217
+ case Syntax.FunctionExpression:
1218
+ // MambaScript: async functions (asyncify) and generators (generatorify)
1219
+ result = (expr.async ? 'async function' : 'function') + (expr.generator ? '*' : '');
1220
+
1221
+ if (expr.id) {
1222
+ result = [result, noEmptySpace(),
1223
+ generateIdentifier(expr.id),
1224
+ generateFunctionBody(expr)];
1225
+ } else {
1226
+ result = [result + space, generateFunctionBody(expr)];
1227
+ }
1228
+
1229
+ break;
1230
+
1231
+ case Syntax.ArrayPattern:
1232
+ case Syntax.ArrayExpression:
1233
+ if (!expr.elements.length) {
1234
+ result = '[]';
1235
+ break;
1236
+ }
1237
+ multiline = expr.elements.length > 1;
1238
+ result = ['[', multiline ? newline : ''];
1239
+ withIndent(function (indent) {
1240
+ for (i = 0, len = expr.elements.length; i < len; i += 1) {
1241
+ if (!expr.elements[i]) {
1242
+ if (multiline) {
1243
+ result.push(indent);
1244
+ }
1245
+ if (i + 1 === len) {
1246
+ result.push(',');
1247
+ }
1248
+ } else {
1249
+ result.push(multiline ? indent : '', generateExpression(expr.elements[i], {
1250
+ precedence: Precedence.Assignment,
1251
+ allowIn: true,
1252
+ allowCall: true
1253
+ }));
1254
+ }
1255
+ if (i + 1 < len) {
1256
+ result.push(',' + (multiline ? newline : space));
1257
+ }
1258
+ }
1259
+ });
1260
+ if (multiline && !endsWithLineTerminator(toSourceNode(result).toString())) {
1261
+ result.push(newline);
1262
+ }
1263
+ result.push(multiline ? base : '', ']');
1264
+ break;
1265
+
1266
+ case Syntax.Property:
1267
+ if (expr.kind === 'get' || expr.kind === 'set') {
1268
+ result = [
1269
+ expr.kind, noEmptySpace(),
1270
+ generateExpression(expr.key, {
1271
+ precedence: Precedence.Sequence,
1272
+ allowIn: true,
1273
+ allowCall: true
1274
+ }),
1275
+ generateFunctionBody(expr.value)
1276
+ ];
1277
+ } else {
1278
+ if (expr.shorthand) {
1279
+ result = generateExpression(expr.key, {
1280
+ precedence: Precedence.Sequence,
1281
+ allowIn: true,
1282
+ allowCall: true
1283
+ });
1284
+ } else if (expr.method) {
1285
+ result = [];
1286
+ if (expr.value.async) {
1287
+ result.push('async ');
1288
+ }
1289
+ if (expr.value.generator) {
1290
+ result.push('*');
1291
+ }
1292
+ result.push(generateExpression(expr.key, {
1293
+ precedence: Precedence.Sequence,
1294
+ allowIn: true,
1295
+ allowCall: true
1296
+ }), generateFunctionBody(expr.value));
1297
+ } else {
1298
+ result = [
1299
+ generateExpression(expr.key, {
1300
+ precedence: Precedence.Sequence,
1301
+ allowIn: true,
1302
+ allowCall: true
1303
+ }),
1304
+ ':' + space,
1305
+ generateExpression(expr.value, {
1306
+ precedence: Precedence.Assignment,
1307
+ allowIn: true,
1308
+ allowCall: true
1309
+ })
1310
+ ];
1311
+ }
1312
+ }
1313
+ break;
1314
+
1315
+ case Syntax.ObjectExpression:
1316
+ if (!expr.properties.length) {
1317
+ result = '{}';
1318
+ break;
1319
+ }
1320
+ multiline = expr.properties.length > 1;
1321
+
1322
+ withIndent(function () {
1323
+ fragment = generateExpression(expr.properties[0], {
1324
+ precedence: Precedence.Sequence,
1325
+ allowIn: true,
1326
+ allowCall: true,
1327
+ type: Syntax.Property
1328
+ });
1329
+ });
1330
+
1331
+ if (!multiline) {
1332
+ // issues 4
1333
+ // Do not transform from
1334
+ // dejavu.Class.declare({
1335
+ // method2: function () {}
1336
+ // });
1337
+ // to
1338
+ // dejavu.Class.declare({method2: function () {
1339
+ // }});
1340
+ if (!hasLineTerminator(toSourceNode(fragment).toString())) {
1341
+ result = [ '{', space, fragment, space, '}' ];
1342
+ break;
1343
+ }
1344
+ }
1345
+
1346
+ withIndent(function (indent) {
1347
+ result = [ '{', newline, indent, fragment ];
1348
+
1349
+ if (multiline) {
1350
+ result.push(',' + newline);
1351
+ for (i = 1, len = expr.properties.length; i < len; i += 1) {
1352
+ result.push(indent, generateExpression(expr.properties[i], {
1353
+ precedence: Precedence.Sequence,
1354
+ allowIn: true,
1355
+ allowCall: true,
1356
+ type: Syntax.Property
1357
+ }));
1358
+ if (i + 1 < len) {
1359
+ result.push(',' + newline);
1360
+ }
1361
+ }
1362
+ }
1363
+ });
1364
+
1365
+ if (!endsWithLineTerminator(toSourceNode(result).toString())) {
1366
+ result.push(newline);
1367
+ }
1368
+ result.push(base, '}');
1369
+ break;
1370
+
1371
+ case Syntax.ObjectPattern:
1372
+ if (!expr.properties.length) {
1373
+ result = '{}';
1374
+ break;
1375
+ }
1376
+
1377
+ multiline = false;
1378
+ if (expr.properties.length === 1) {
1379
+ property = expr.properties[0];
1380
+ if (property.value.type !== Syntax.Identifier) {
1381
+ multiline = true;
1382
+ }
1383
+ } else {
1384
+ for (i = 0, len = expr.properties.length; i < len; i += 1) {
1385
+ property = expr.properties[i];
1386
+ if (!property.shorthand) {
1387
+ multiline = true;
1388
+ break;
1389
+ }
1390
+ }
1391
+ }
1392
+ result = ['{', multiline ? newline : '' ];
1393
+
1394
+ withIndent(function (indent) {
1395
+ for (i = 0, len = expr.properties.length; i < len; i += 1) {
1396
+ result.push(multiline ? indent : '', generateExpression(expr.properties[i], {
1397
+ precedence: Precedence.Sequence,
1398
+ allowIn: true,
1399
+ allowCall: true
1400
+ }));
1401
+ if (i + 1 < len) {
1402
+ result.push(',' + (multiline ? newline : space));
1403
+ }
1404
+ }
1405
+ });
1406
+
1407
+ if (multiline && !endsWithLineTerminator(toSourceNode(result).toString())) {
1408
+ result.push(newline);
1409
+ }
1410
+ result.push(multiline ? base : '', '}');
1411
+ break;
1412
+
1413
+ case Syntax.ThisExpression:
1414
+ result = 'this';
1415
+ break;
1416
+
1417
+ case Syntax.Identifier:
1418
+ result = generateIdentifier(expr);
1419
+ break;
1420
+
1421
+ case Syntax.BigIntLiteral:
1422
+ result = expr.digits + 'n';
1423
+ break;
1424
+
1425
+ // MambaScript: tagged templates (tag"text #{value}")
1426
+ case Syntax.TemplateElement:
1427
+ result = expr.value.raw;
1428
+ break;
1429
+
1430
+ case Syntax.ImportExpression:
1431
+ // MambaScript: import('module')
1432
+ result = ['import(', generateExpression(expr.source, { precedence: Precedence.Sequence, allowIn: true, allowCall: true }), ')'];
1433
+ result = parenthesize(result, Precedence.Call, precedence);
1434
+ break;
1435
+
1436
+ case Syntax.TemplateLiteral:
1437
+ result = ['`'];
1438
+ for (i = 0, len = expr.quasis.length; i < len; ++i) {
1439
+ result.push(generateExpression(expr.quasis[i], {
1440
+ precedence: Precedence.Primary,
1441
+ allowIn: true,
1442
+ allowCall: true
1443
+ }));
1444
+ if (i + 1 < len) {
1445
+ result.push('${');
1446
+ result.push(generateExpression(expr.expressions[i], {
1447
+ precedence: Precedence.Sequence,
1448
+ allowIn: true,
1449
+ allowCall: true
1450
+ }));
1451
+ result.push('}');
1452
+ }
1453
+ }
1454
+ result.push('`');
1455
+ break;
1456
+
1457
+ case Syntax.TaggedTemplateExpression:
1458
+ result = [generateExpression(expr.tag, {
1459
+ precedence: Precedence.Call,
1460
+ allowIn: true,
1461
+ allowCall: allowCall
1462
+ }), generateExpression(expr.quasi, {
1463
+ precedence: Precedence.Primary,
1464
+ allowIn: true,
1465
+ allowCall: true
1466
+ })];
1467
+ result = parenthesize(result, Precedence.TaggedTemplate, precedence);
1468
+ break;
1469
+
1470
+ case Syntax.Literal:
1471
+ if (expr.hasOwnProperty('raw') && parse) {
1472
+ try {
1473
+ raw = parse(expr.raw).body[0].expression;
1474
+ if (raw.type === Syntax.Literal) {
1475
+ if (raw.value === expr.value) {
1476
+ result = expr.raw;
1477
+ break;
1478
+ }
1479
+ }
1480
+ } catch (e) {
1481
+ // not use raw property
1482
+ }
1483
+ }
1484
+
1485
+ if (expr.value === null) {
1486
+ result = 'null';
1487
+ break;
1488
+ }
1489
+
1490
+ if (typeof expr.value === 'string') {
1491
+ result = escapeString(expr.value);
1492
+ break;
1493
+ }
1494
+
1495
+ if (typeof expr.value === 'number') {
1496
+ result = generateNumber(expr.value);
1497
+ break;
1498
+ }
1499
+
1500
+ if (typeof expr.value === 'boolean') {
1501
+ result = expr.value ? 'true' : 'false';
1502
+ break;
1503
+ }
1504
+
1505
+ result = generateRegExp(expr.value);
1506
+ break;
1507
+
1508
+ case Syntax.ComprehensionExpression:
1509
+ result = [
1510
+ '[',
1511
+ generateExpression(expr.body, {
1512
+ precedence: Precedence.Assignment,
1513
+ allowIn: true,
1514
+ allowCall: true
1515
+ })
1516
+ ];
1517
+
1518
+ if (expr.blocks) {
1519
+ for (i = 0, len = expr.blocks.length; i < len; i += 1) {
1520
+ fragment = generateExpression(expr.blocks[i], {
1521
+ precedence: Precedence.Sequence,
1522
+ allowIn: true,
1523
+ allowCall: true
1524
+ });
1525
+ result = join(result, fragment);
1526
+ }
1527
+ }
1528
+
1529
+ if (expr.filter) {
1530
+ result = join(result, 'if' + space);
1531
+ fragment = generateExpression(expr.filter, {
1532
+ precedence: Precedence.Sequence,
1533
+ allowIn: true,
1534
+ allowCall: true
1535
+ });
1536
+ if (extra.moz.parenthesizedComprehensionBlock) {
1537
+ result = join(result, [ '(', fragment, ')' ]);
1538
+ } else {
1539
+ result = join(result, fragment);
1540
+ }
1541
+ }
1542
+ result.push(']');
1543
+ break;
1544
+
1545
+ case Syntax.ComprehensionBlock:
1546
+ if (expr.left.type === Syntax.VariableDeclaration) {
1547
+ fragment = [
1548
+ expr.left.kind, noEmptySpace(),
1549
+ generateStatement(expr.left.declarations[0], {
1550
+ allowIn: false
1551
+ })
1552
+ ];
1553
+ } else {
1554
+ fragment = generateExpression(expr.left, {
1555
+ precedence: Precedence.Call,
1556
+ allowIn: true,
1557
+ allowCall: true
1558
+ });
1559
+ }
1560
+
1561
+ fragment = join(fragment, expr.of ? 'of' : 'in');
1562
+ fragment = join(fragment, generateExpression(expr.right, {
1563
+ precedence: Precedence.Sequence,
1564
+ allowIn: true,
1565
+ allowCall: true
1566
+ }));
1567
+
1568
+ if (extra.moz.parenthesizedComprehensionBlock) {
1569
+ result = [ 'for' + space + '(', fragment, ')' ];
1570
+ } else {
1571
+ result = join('for' + space, fragment);
1572
+ }
1573
+ break;
1574
+
1575
+ default:
1576
+ throw new Error('Unknown expression type: ' + expr.type);
1577
+ }
1578
+
1579
+ return toSourceNode(result, expr);
1580
+ }
1581
+
1582
+ function generateStatement(stmt, option) {
1583
+ var i, len, result, node, allowIn, functionBody, directiveContext, fragment, semicolon;
1584
+
1585
+ allowIn = true;
1586
+ semicolon = ';';
1587
+ functionBody = false;
1588
+ directiveContext = false;
1589
+ if (option) {
1590
+ allowIn = option.allowIn === undefined || option.allowIn;
1591
+ if (!semicolons && option.semicolonOptional === true) {
1592
+ semicolon = '';
1593
+ }
1594
+ functionBody = option.functionBody;
1595
+ directiveContext = option.directiveContext;
1596
+ }
1597
+
1598
+ switch (stmt.type) {
1599
+ case Syntax.BlockStatement:
1600
+ result = ['{', newline];
1601
+
1602
+ withIndent(function () {
1603
+ for (i = 0, len = stmt.body.length; i < len; i += 1) {
1604
+ fragment = addIndent(generateStatement(stmt.body[i], {
1605
+ semicolonOptional: i === len - 1,
1606
+ directiveContext: functionBody
1607
+ }));
1608
+ result.push(fragment);
1609
+ if (!endsWithLineTerminator(toSourceNode(fragment).toString())) {
1610
+ result.push(newline);
1611
+ }
1612
+ }
1613
+ });
1614
+
1615
+ result.push(addIndent('}'));
1616
+ break;
1617
+
1618
+ case Syntax.BreakStatement:
1619
+ if (stmt.label) {
1620
+ result = 'break ' + stmt.label.name + semicolon;
1621
+ } else {
1622
+ result = 'break' + semicolon;
1623
+ }
1624
+ break;
1625
+
1626
+ case Syntax.ContinueStatement:
1627
+ if (stmt.label) {
1628
+ result = 'continue ' + stmt.label.name + semicolon;
1629
+ } else {
1630
+ result = 'continue' + semicolon;
1631
+ }
1632
+ break;
1633
+
1634
+ case Syntax.DirectiveStatement:
1635
+ if (stmt.raw) {
1636
+ result = stmt.raw + semicolon;
1637
+ } else {
1638
+ result = escapeDirective(stmt.directive) + semicolon;
1639
+ }
1640
+ break;
1641
+
1642
+ case Syntax.DoWhileStatement:
1643
+ // Because `do 42 while (cond)` is Syntax Error. We need semicolon.
1644
+ result = join('do', maybeBlock(stmt.body));
1645
+ result = maybeBlockSuffix(stmt.body, result);
1646
+ result = join(result, [
1647
+ 'while' + space + '(',
1648
+ generateExpression(stmt.test, {
1649
+ precedence: Precedence.Sequence,
1650
+ allowIn: true,
1651
+ allowCall: true
1652
+ }),
1653
+ ')' + semicolon
1654
+ ]);
1655
+ break;
1656
+
1657
+ case Syntax.CatchClause:
1658
+ withIndent(function () {
1659
+ result = [
1660
+ 'catch' + space + '(',
1661
+ generateExpression(stmt.param, {
1662
+ precedence: Precedence.Sequence,
1663
+ allowIn: true,
1664
+ allowCall: true
1665
+ }),
1666
+ ')'
1667
+ ];
1668
+ });
1669
+ result.push(maybeBlock(stmt.body));
1670
+ break;
1671
+
1672
+ case Syntax.DebuggerStatement:
1673
+ result = 'debugger' + semicolon;
1674
+ break;
1675
+
1676
+ case Syntax.EmptyStatement:
1677
+ result = ';';
1678
+ break;
1679
+
1680
+ case Syntax.ExpressionStatement:
1681
+ result = [generateExpression(stmt.expression, {
1682
+ precedence: Precedence.Sequence,
1683
+ allowIn: true,
1684
+ allowCall: true
1685
+ })];
1686
+ // 12.4 '{', 'function' is not allowed in this position.
1687
+ // wrap expression with parentheses
1688
+ fragment = toSourceNode(result).toString();
1689
+ // MambaScript: 'async function' is not allowed in this position either
1690
+ if (fragment.charAt(0) === '{' || (fragment.slice(0, 8) === 'function' && ' (*'.indexOf(fragment.charAt(8)) >= 0) || (fragment.slice(0, 14) === 'async function' && ' (*'.indexOf(fragment.charAt(14)) >= 0) || (directive && directiveContext && stmt.expression.type === Syntax.Literal && typeof stmt.expression.value === 'string')) {
1691
+ result = ['(', result, ')' + semicolon];
1692
+ } else {
1693
+ result.push(semicolon);
1694
+ }
1695
+ break;
1696
+
1697
+ case Syntax.VariableDeclarator:
1698
+ if (stmt.init) {
1699
+ result = [
1700
+ generateExpression(stmt.id, {
1701
+ precedence: Precedence.Assignment,
1702
+ allowIn: allowIn,
1703
+ allowCall: true
1704
+ }),
1705
+ space,
1706
+ '=',
1707
+ space,
1708
+ generateExpression(stmt.init, {
1709
+ precedence: Precedence.Assignment,
1710
+ allowIn: allowIn,
1711
+ allowCall: true
1712
+ })
1713
+ ];
1714
+ } else {
1715
+ result = generateIdentifier(stmt.id);
1716
+ }
1717
+ break;
1718
+
1719
+ case Syntax.VariableDeclaration:
1720
+ result = [stmt.kind];
1721
+ // special path for
1722
+ // var x = function () {
1723
+ // };
1724
+ if (stmt.declarations.length === 1 && stmt.declarations[0].init &&
1725
+ stmt.declarations[0].init.type === Syntax.FunctionExpression) {
1726
+ result.push(noEmptySpace(), generateStatement(stmt.declarations[0], {
1727
+ allowIn: allowIn
1728
+ }));
1729
+ } else {
1730
+ // VariableDeclarator is typed as Statement,
1731
+ // but joined with comma (not LineTerminator).
1732
+ // So if comment is attached to target node, we should specialize.
1733
+ withIndent(function () {
1734
+ node = stmt.declarations[0];
1735
+ if (extra.comment && node.leadingComments) {
1736
+ result.push('\n', addIndent(generateStatement(node, {
1737
+ allowIn: allowIn
1738
+ })));
1739
+ } else {
1740
+ result.push(noEmptySpace(), generateStatement(node, {
1741
+ allowIn: allowIn
1742
+ }));
1743
+ }
1744
+
1745
+ for (i = 1, len = stmt.declarations.length; i < len; i += 1) {
1746
+ node = stmt.declarations[i];
1747
+ if (extra.comment && node.leadingComments) {
1748
+ result.push(',' + newline, addIndent(generateStatement(node, {
1749
+ allowIn: allowIn
1750
+ })));
1751
+ } else {
1752
+ result.push(',' + space, generateStatement(node, {
1753
+ allowIn: allowIn
1754
+ }));
1755
+ }
1756
+ }
1757
+ });
1758
+ }
1759
+ result.push(semicolon);
1760
+ break;
1761
+
1762
+ case Syntax.ThrowStatement:
1763
+ result = [join(
1764
+ 'throw',
1765
+ generateExpression(stmt.argument, {
1766
+ precedence: Precedence.Sequence,
1767
+ allowIn: true,
1768
+ allowCall: true
1769
+ })
1770
+ ), semicolon];
1771
+ break;
1772
+
1773
+ case Syntax.TryStatement:
1774
+ result = ['try', maybeBlock(stmt.block)];
1775
+ result = maybeBlockSuffix(stmt.block, result);
1776
+ if (stmt.handlers) {
1777
+ // old interface
1778
+ for (i = 0, len = stmt.handlers.length; i < len; i += 1) {
1779
+ result = join(result, generateStatement(stmt.handlers[i]));
1780
+ if (stmt.finalizer || i + 1 !== len) {
1781
+ result = maybeBlockSuffix(stmt.handlers[i].body, result);
1782
+ }
1783
+ }
1784
+ } else {
1785
+ // new interface
1786
+ if (stmt.handler) {
1787
+ result = join(result, generateStatement(stmt.handler));
1788
+ if (stmt.finalizer || stmt.guardedHandlers.length > 0) {
1789
+ result = maybeBlockSuffix(stmt.handler.body, result);
1790
+ }
1791
+ }
1792
+
1793
+ for (i = 0, len = stmt.guardedHandlers.length; i < len; i += 1) {
1794
+ result = join(result, generateStatement(stmt.guardedHandlers[i]));
1795
+ if (stmt.finalizer || i + 1 !== len) {
1796
+ result = maybeBlockSuffix(stmt.guardedHandlers[i].body, result);
1797
+ }
1798
+ }
1799
+ }
1800
+ if (stmt.finalizer) {
1801
+ result = join(result, ['finally', maybeBlock(stmt.finalizer)]);
1802
+ }
1803
+ break;
1804
+
1805
+ case Syntax.SwitchStatement:
1806
+ withIndent(function () {
1807
+ result = [
1808
+ 'switch' + space + '(',
1809
+ generateExpression(stmt.discriminant, {
1810
+ precedence: Precedence.Sequence,
1811
+ allowIn: true,
1812
+ allowCall: true
1813
+ }),
1814
+ ')' + space + '{' + newline
1815
+ ];
1816
+ });
1817
+ if (stmt.cases) {
1818
+ for (i = 0, len = stmt.cases.length; i < len; i += 1) {
1819
+ fragment = addIndent(generateStatement(stmt.cases[i], {semicolonOptional: i === len - 1}));
1820
+ result.push(fragment);
1821
+ if (!endsWithLineTerminator(toSourceNode(fragment).toString())) {
1822
+ result.push(newline);
1823
+ }
1824
+ }
1825
+ }
1826
+ result.push(addIndent('}'));
1827
+ break;
1828
+
1829
+ case Syntax.SwitchCase:
1830
+ withIndent(function () {
1831
+ if (stmt.test) {
1832
+ result = [
1833
+ join('case', generateExpression(stmt.test, {
1834
+ precedence: Precedence.Sequence,
1835
+ allowIn: true,
1836
+ allowCall: true
1837
+ })),
1838
+ ':'
1839
+ ];
1840
+ } else {
1841
+ result = ['default:'];
1842
+ }
1843
+
1844
+ i = 0;
1845
+ len = stmt.consequent.length;
1846
+ if (len && stmt.consequent[0].type === Syntax.BlockStatement) {
1847
+ fragment = maybeBlock(stmt.consequent[0]);
1848
+ result.push(fragment);
1849
+ i = 1;
1850
+ }
1851
+
1852
+ if (i !== len && !endsWithLineTerminator(toSourceNode(result).toString())) {
1853
+ result.push(newline);
1854
+ }
1855
+
1856
+ for (; i < len; i += 1) {
1857
+ fragment = addIndent(generateStatement(stmt.consequent[i], {semicolonOptional: i === len - 1 && semicolon === ''}));
1858
+ result.push(fragment);
1859
+ if (i + 1 !== len && !endsWithLineTerminator(toSourceNode(fragment).toString())) {
1860
+ result.push(newline);
1861
+ }
1862
+ }
1863
+ });
1864
+ break;
1865
+
1866
+ case Syntax.IfStatement:
1867
+ withIndent(function () {
1868
+ result = [
1869
+ 'if' + space + '(',
1870
+ generateExpression(stmt.test, {
1871
+ precedence: Precedence.Sequence,
1872
+ allowIn: true,
1873
+ allowCall: true
1874
+ }),
1875
+ ')'
1876
+ ];
1877
+ });
1878
+ if (stmt.alternate) {
1879
+ result.push(maybeBlock(stmt.consequent));
1880
+ result = maybeBlockSuffix(stmt.consequent, result);
1881
+ if (stmt.alternate.type === Syntax.IfStatement) {
1882
+ result = join(result, ['else ', generateStatement(stmt.alternate, {semicolonOptional: semicolon === ''})]);
1883
+ } else {
1884
+ result = join(result, join('else', maybeBlock(stmt.alternate, semicolon === '')));
1885
+ }
1886
+ } else {
1887
+ result.push(maybeBlock(stmt.consequent, semicolon === ''));
1888
+ }
1889
+ break;
1890
+
1891
+ case Syntax.ForStatement:
1892
+ withIndent(function () {
1893
+ result = ['for' + space + '('];
1894
+ if (stmt.init) {
1895
+ if (stmt.init.type === Syntax.VariableDeclaration) {
1896
+ result.push(generateStatement(stmt.init, {allowIn: false}));
1897
+ } else {
1898
+ result.push(generateExpression(stmt.init, {
1899
+ precedence: Precedence.Sequence,
1900
+ allowIn: false,
1901
+ allowCall: true
1902
+ }), ';');
1903
+ }
1904
+ } else {
1905
+ result.push(';');
1906
+ }
1907
+
1908
+ if (stmt.test) {
1909
+ result.push(space, generateExpression(stmt.test, {
1910
+ precedence: Precedence.Sequence,
1911
+ allowIn: true,
1912
+ allowCall: true
1913
+ }), ';');
1914
+ } else {
1915
+ result.push(';');
1916
+ }
1917
+
1918
+ if (stmt.update) {
1919
+ result.push(space, generateExpression(stmt.update, {
1920
+ precedence: Precedence.Sequence,
1921
+ allowIn: true,
1922
+ allowCall: true
1923
+ }), ')');
1924
+ } else {
1925
+ result.push(')');
1926
+ }
1927
+ });
1928
+
1929
+ result.push(maybeBlock(stmt.body, semicolon === ''));
1930
+ break;
1931
+
1932
+ // MambaScript: ES module output (modules: 'esm')
1933
+ case Syntax.ImportDeclaration:
1934
+ if (stmt.specifiers.length === 0) {
1935
+ result = ['import', space, generateExpression(stmt.source, { precedence: Precedence.Sequence, allowIn: true, allowCall: true }), semicolon];
1936
+ break;
1937
+ }
1938
+ (function () {
1939
+ var parts = [], named = [], k, sp;
1940
+ for (k = 0; k < stmt.specifiers.length; ++k) {
1941
+ sp = stmt.specifiers[k];
1942
+ if (sp.type === Syntax.ImportDefaultSpecifier) {
1943
+ parts.push(generateIdentifier(sp.local));
1944
+ } else if (sp.type === Syntax.ImportNamespaceSpecifier) {
1945
+ parts.push('* as ' + generateIdentifier(sp.local));
1946
+ } else {
1947
+ named.push(sp.imported.name === sp.local.name ? generateIdentifier(sp.local) : generateIdentifier(sp.imported) + ' as ' + generateIdentifier(sp.local));
1948
+ }
1949
+ }
1950
+ if (named.length) {
1951
+ parts.push('{' + space + named.join(',' + space) + space + '}');
1952
+ }
1953
+ result = ['import ' + parts.join(',' + space) + ' from ', generateExpression(stmt.source, { precedence: Precedence.Sequence, allowIn: true, allowCall: true }), semicolon];
1954
+ }());
1955
+ break;
1956
+
1957
+ case Syntax.ExportNamedDeclaration:
1958
+ (function () {
1959
+ var named = [], k, sp;
1960
+ for (k = 0; k < stmt.specifiers.length; ++k) {
1961
+ sp = stmt.specifiers[k];
1962
+ named.push(sp.local.name === sp.exported.name ? generateIdentifier(sp.exported) : generateIdentifier(sp.local) + ' as ' + generateIdentifier(sp.exported));
1963
+ }
1964
+ result = ['export {' + space + named.join(',' + space) + space + '}'];
1965
+ if (stmt.source) {
1966
+ result.push(' from ', generateExpression(stmt.source, { precedence: Precedence.Sequence, allowIn: true, allowCall: true }));
1967
+ }
1968
+ result.push(semicolon);
1969
+ }());
1970
+ break;
1971
+
1972
+ case Syntax.ExportDefaultDeclaration:
1973
+ result = ['export default ', generateExpression(stmt.declaration, { precedence: Precedence.Assignment, allowIn: true, allowCall: true }), semicolon];
1974
+ break;
1975
+
1976
+ case Syntax.ExportAllDeclaration:
1977
+ result = ['export * from ', generateExpression(stmt.source, { precedence: Precedence.Sequence, allowIn: true, allowCall: true }), semicolon];
1978
+ break;
1979
+
1980
+ case Syntax.ForOfStatement:
1981
+ // MambaScript: `for x from iterable` / `for waitForIt x from asyncIterable`
1982
+ result = ['for' + (stmt.await ? ' await' : '') + space + '('];
1983
+ withIndent(function () {
1984
+ result.push(generateExpression(stmt.left, {
1985
+ precedence: Precedence.Call,
1986
+ allowIn: true,
1987
+ allowCall: true
1988
+ }));
1989
+ result = join(result, 'of');
1990
+ result = [join(
1991
+ result,
1992
+ generateExpression(stmt.right, {
1993
+ precedence: Precedence.Sequence,
1994
+ allowIn: true,
1995
+ allowCall: true
1996
+ })
1997
+ ), ')'];
1998
+ });
1999
+ result.push(maybeBlock(stmt.body, semicolon === ''));
2000
+ break;
2001
+
2002
+ case Syntax.ForInStatement:
2003
+ result = ['for' + space + '('];
2004
+ withIndent(function () {
2005
+ if (stmt.left.type === Syntax.VariableDeclaration) {
2006
+ withIndent(function () {
2007
+ result.push(stmt.left.kind + noEmptySpace(), generateStatement(stmt.left.declarations[0], {
2008
+ allowIn: false
2009
+ }));
2010
+ });
2011
+ } else {
2012
+ result.push(generateExpression(stmt.left, {
2013
+ precedence: Precedence.Call,
2014
+ allowIn: true,
2015
+ allowCall: true
2016
+ }));
2017
+ }
2018
+
2019
+ result = join(result, 'in');
2020
+ result = [join(
2021
+ result,
2022
+ generateExpression(stmt.right, {
2023
+ precedence: Precedence.Sequence,
2024
+ allowIn: true,
2025
+ allowCall: true
2026
+ })
2027
+ ), ')'];
2028
+ });
2029
+ result.push(maybeBlock(stmt.body, semicolon === ''));
2030
+ break;
2031
+
2032
+ case Syntax.LabeledStatement:
2033
+ result = [stmt.label.name + ':', maybeBlock(stmt.body, semicolon === '')];
2034
+ break;
2035
+
2036
+ case Syntax.Program:
2037
+ len = stmt.body.length;
2038
+ result = [safeConcatenation && len > 0 ? '\n' : ''];
2039
+ for (i = 0; i < len; i += 1) {
2040
+ fragment = addIndent(
2041
+ generateStatement(stmt.body[i], {
2042
+ semicolonOptional: !safeConcatenation && i === len - 1,
2043
+ directiveContext: true
2044
+ })
2045
+ );
2046
+ result.push(fragment);
2047
+ if (i + 1 < len && !endsWithLineTerminator(toSourceNode(fragment).toString())) {
2048
+ result.push(newline);
2049
+ }
2050
+ }
2051
+ break;
2052
+
2053
+ case Syntax.FunctionDeclaration:
2054
+ result = [(stmt.async ? 'async ' : '') + (stmt.generator && !extra.moz.starlessGenerator ? 'function* ' : 'function '),
2055
+ generateIdentifier(stmt.id),
2056
+ generateFunctionBody(stmt)];
2057
+ break;
2058
+
2059
+ case Syntax.ReturnStatement:
2060
+ if (stmt.argument) {
2061
+ result = [join(
2062
+ 'return',
2063
+ generateExpression(stmt.argument, {
2064
+ precedence: Precedence.Sequence,
2065
+ allowIn: true,
2066
+ allowCall: true
2067
+ })
2068
+ ), semicolon];
2069
+ } else {
2070
+ result = ['return' + semicolon];
2071
+ }
2072
+ break;
2073
+
2074
+ case Syntax.WhileStatement:
2075
+ withIndent(function () {
2076
+ result = [
2077
+ 'while' + space + '(',
2078
+ generateExpression(stmt.test, {
2079
+ precedence: Precedence.Sequence,
2080
+ allowIn: true,
2081
+ allowCall: true
2082
+ }),
2083
+ ')'
2084
+ ];
2085
+ });
2086
+ result.push(maybeBlock(stmt.body, semicolon === ''));
2087
+ break;
2088
+
2089
+ case Syntax.WithStatement:
2090
+ withIndent(function () {
2091
+ result = [
2092
+ 'with' + space + '(',
2093
+ generateExpression(stmt.object, {
2094
+ precedence: Precedence.Sequence,
2095
+ allowIn: true,
2096
+ allowCall: true
2097
+ }),
2098
+ ')'
2099
+ ];
2100
+ });
2101
+ result.push(maybeBlock(stmt.body, semicolon === ''));
2102
+ break;
2103
+
2104
+ default:
2105
+ throw new Error('Unknown statement type: ' + stmt.type);
2106
+ }
2107
+
2108
+ // Attach comments
2109
+
2110
+ if (extra.comment) {
2111
+ result = addCommentsToStatement(stmt, result);
2112
+ }
2113
+
2114
+ fragment = toSourceNode(result).toString();
2115
+ if (stmt.type === Syntax.Program && !safeConcatenation && newline === '' && fragment.charAt(fragment.length - 1) === '\n') {
2116
+ result = toSourceNode(result).replaceRight(/\s+$/, '');
2117
+ }
2118
+
2119
+ return toSourceNode(result, stmt);
2120
+ }
2121
+
2122
+ function generate(node, options) {
2123
+ var defaultOptions = getDefaultOptions(), result, pair;
2124
+
2125
+ if (options != null) {
2126
+ // Obsolete options
2127
+ //
2128
+ // `options.indent`
2129
+ // `options.base`
2130
+ //
2131
+ // Instead of them, we can use `option.format.indent`.
2132
+ if (typeof options.indent === 'string') {
2133
+ defaultOptions.format.indent.style = options.indent;
2134
+ }
2135
+ if (typeof options.base === 'number') {
2136
+ defaultOptions.format.indent.base = options.base;
2137
+ }
2138
+ options = updateDeeply(defaultOptions, options);
2139
+ indent = options.format.indent.style;
2140
+ if (typeof options.base === 'string') {
2141
+ base = options.base;
2142
+ } else {
2143
+ base = stringRepeat(indent, options.format.indent.base);
2144
+ }
2145
+ } else {
2146
+ options = defaultOptions;
2147
+ indent = options.format.indent.style;
2148
+ base = stringRepeat(indent, options.format.indent.base);
2149
+ }
2150
+ json = options.format.json;
2151
+ renumber = options.format.renumber;
2152
+ hexadecimal = json ? false : options.format.hexadecimal;
2153
+ quotes = json ? 'double' : options.format.quotes;
2154
+ escapeless = options.format.escapeless;
2155
+ newline = options.format.newline;
2156
+ space = options.format.space;
2157
+ if (options.format.compact) {
2158
+ newline = space = indent = base = '';
2159
+ }
2160
+ parentheses = options.format.parentheses;
2161
+ semicolons = options.format.semicolons;
2162
+ safeConcatenation = options.format.safeConcatenation;
2163
+ directive = options.directive;
2164
+ // MambaScript: the esprima-based `options.parse` re-parsing path is removed (zero dependencies).
2165
+ parse = null;
2166
+ sourceMap = options.sourceMap;
2167
+ extra = options;
2168
+
2169
+ if (sourceMap) {
2170
+ if (!exports.browser) {
2171
+ // We assume environment is node.js
2172
+ // And prevent from including source-map by browserify
2173
+ SourceNode = require('../source-map/lib/source-map').SourceNode;
2174
+ } else {
2175
+ SourceNode = global.sourceMap.SourceNode;
2176
+ }
2177
+ } else {
2178
+ SourceNode = SourceNodeMock;
2179
+ }
2180
+
2181
+ switch (node.type) {
2182
+ case Syntax.BlockStatement:
2183
+ case Syntax.BreakStatement:
2184
+ case Syntax.CatchClause:
2185
+ case Syntax.ContinueStatement:
2186
+ case Syntax.DirectiveStatement:
2187
+ case Syntax.DoWhileStatement:
2188
+ case Syntax.DebuggerStatement:
2189
+ case Syntax.EmptyStatement:
2190
+ case Syntax.ExpressionStatement:
2191
+ case Syntax.ForStatement:
2192
+ case Syntax.ImportDeclaration:
2193
+ case Syntax.ExportNamedDeclaration:
2194
+ case Syntax.ExportDefaultDeclaration:
2195
+ case Syntax.ExportAllDeclaration:
2196
+ case Syntax.ForOfStatement:
2197
+ case Syntax.ForInStatement:
2198
+ case Syntax.FunctionDeclaration:
2199
+ case Syntax.IfStatement:
2200
+ case Syntax.LabeledStatement:
2201
+ case Syntax.Program:
2202
+ case Syntax.ReturnStatement:
2203
+ case Syntax.SwitchStatement:
2204
+ case Syntax.SwitchCase:
2205
+ case Syntax.ThrowStatement:
2206
+ case Syntax.TryStatement:
2207
+ case Syntax.VariableDeclaration:
2208
+ case Syntax.VariableDeclarator:
2209
+ case Syntax.WhileStatement:
2210
+ case Syntax.WithStatement:
2211
+ result = generateStatement(node);
2212
+ break;
2213
+
2214
+ case Syntax.AssignmentExpression:
2215
+ case Syntax.ArrayExpression:
2216
+ case Syntax.ArrayPattern:
2217
+ case Syntax.AwaitExpression:
2218
+ case Syntax.BinaryExpression:
2219
+ case Syntax.CallExpression:
2220
+ case Syntax.ConditionalExpression:
2221
+ case Syntax.FunctionExpression:
2222
+ case Syntax.Identifier:
2223
+ case Syntax.Literal:
2224
+ case Syntax.BigIntLiteral:
2225
+ case Syntax.ImportExpression:
2226
+ case Syntax.TaggedTemplateExpression:
2227
+ case Syntax.TemplateLiteral:
2228
+ case Syntax.LogicalExpression:
2229
+ case Syntax.MemberExpression:
2230
+ case Syntax.NewExpression:
2231
+ case Syntax.ObjectExpression:
2232
+ case Syntax.ObjectPattern:
2233
+ case Syntax.Property:
2234
+ case Syntax.SequenceExpression:
2235
+ case Syntax.ThisExpression:
2236
+ case Syntax.UnaryExpression:
2237
+ case Syntax.UpdateExpression:
2238
+ case Syntax.YieldExpression:
2239
+
2240
+ result = generateExpression(node, {
2241
+ precedence: Precedence.Sequence,
2242
+ allowIn: true,
2243
+ allowCall: true
2244
+ });
2245
+ break;
2246
+
2247
+ default:
2248
+ throw new Error('Unknown node type: ' + node.type);
2249
+ }
2250
+
2251
+ if (!sourceMap) {
2252
+ return result.toString();
2253
+ }
2254
+
2255
+ pair = result.toStringWithSourceMap({
2256
+ file: options.file,
2257
+ sourceRoot: options.sourceMapRoot
2258
+ });
2259
+
2260
+ if (options.sourceMapWithCode) {
2261
+ return pair;
2262
+ }
2263
+ return pair.map.toString();
2264
+ }
2265
+
2266
+ FORMAT_MINIFY = {
2267
+ indent: {
2268
+ style: '',
2269
+ base: 0
2270
+ },
2271
+ renumber: true,
2272
+ hexadecimal: true,
2273
+ quotes: 'auto',
2274
+ escapeless: true,
2275
+ compact: true,
2276
+ parentheses: false,
2277
+ semicolons: false
2278
+ };
2279
+
2280
+ FORMAT_DEFAULTS = getDefaultOptions().format;
2281
+
2282
+ exports.version = '0.0.28-mambascript';
2283
+ exports.generate = generate;
2284
+ exports.attachComments = estraverse.attachComments;
2285
+ exports.browser = false;
2286
+ exports.FORMAT_MINIFY = FORMAT_MINIFY;
2287
+ exports.FORMAT_DEFAULTS = FORMAT_DEFAULTS;
2288
+ }());
2289
+ /* vim: set sw=4 ts=4 et tw=80 : */