rb-document-form-constructor 0.8.76 → 0.8.77

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.
@@ -97,4702 +97,6 @@ const UtFormConfig = {
97
97
 
98
98
  };
99
99
 
100
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
101
-
102
- function createCommonjsModule(fn, basedir, module) {
103
- return module = {
104
- path: basedir,
105
- exports: {},
106
- require: function (path, base) {
107
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
108
- }
109
- }, fn(module, module.exports), module.exports;
110
- }
111
-
112
- function commonjsRequire () {
113
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
114
- }
115
-
116
- var esprima = createCommonjsModule(function (module, exports) {
117
- /*
118
- Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
119
- Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
120
- Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
121
- Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
122
- Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
123
- Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
124
- Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
125
-
126
- Redistribution and use in source and binary forms, with or without
127
- modification, are permitted provided that the following conditions are met:
128
-
129
- * Redistributions of source code must retain the above copyright
130
- notice, this list of conditions and the following disclaimer.
131
- * Redistributions in binary form must reproduce the above copyright
132
- notice, this list of conditions and the following disclaimer in the
133
- documentation and/or other materials provided with the distribution.
134
-
135
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
136
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
138
- ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
139
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
140
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
141
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
142
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
144
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145
- */
146
-
147
- /*jslint bitwise:true plusplus:true */
148
- /*global esprima:true, define:true, exports:true, window: true,
149
- throwError: true, createLiteral: true, generateStatement: true,
150
- parseAssignmentExpression: true, parseBlock: true, parseExpression: true,
151
- parseFunctionDeclaration: true, parseFunctionExpression: true,
152
- parseFunctionSourceElements: true, parseVariableIdentifier: true,
153
- parseLeftHandSideExpression: true,
154
- parseStatement: true, parseSourceElement: true */
155
-
156
- (function (root, factory) {
157
-
158
- // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
159
- // Rhino, and plain browser loading.
160
- {
161
- factory(exports);
162
- }
163
- }(commonjsGlobal, function (exports) {
164
-
165
- var Token,
166
- TokenName,
167
- Syntax,
168
- PropertyKind,
169
- Messages,
170
- Regex,
171
- source,
172
- strict,
173
- index,
174
- lineNumber,
175
- lineStart,
176
- length,
177
- buffer,
178
- state,
179
- extra;
180
-
181
- Token = {
182
- BooleanLiteral: 1,
183
- EOF: 2,
184
- Identifier: 3,
185
- Keyword: 4,
186
- NullLiteral: 5,
187
- NumericLiteral: 6,
188
- Punctuator: 7,
189
- StringLiteral: 8
190
- };
191
-
192
- TokenName = {};
193
- TokenName[Token.BooleanLiteral] = 'Boolean';
194
- TokenName[Token.EOF] = '<end>';
195
- TokenName[Token.Identifier] = 'Identifier';
196
- TokenName[Token.Keyword] = 'Keyword';
197
- TokenName[Token.NullLiteral] = 'Null';
198
- TokenName[Token.NumericLiteral] = 'Numeric';
199
- TokenName[Token.Punctuator] = 'Punctuator';
200
- TokenName[Token.StringLiteral] = 'String';
201
-
202
- Syntax = {
203
- AssignmentExpression: 'AssignmentExpression',
204
- ArrayExpression: 'ArrayExpression',
205
- BlockStatement: 'BlockStatement',
206
- BinaryExpression: 'BinaryExpression',
207
- BreakStatement: 'BreakStatement',
208
- CallExpression: 'CallExpression',
209
- CatchClause: 'CatchClause',
210
- ConditionalExpression: 'ConditionalExpression',
211
- ContinueStatement: 'ContinueStatement',
212
- DoWhileStatement: 'DoWhileStatement',
213
- DebuggerStatement: 'DebuggerStatement',
214
- EmptyStatement: 'EmptyStatement',
215
- ExpressionStatement: 'ExpressionStatement',
216
- ForStatement: 'ForStatement',
217
- ForInStatement: 'ForInStatement',
218
- FunctionDeclaration: 'FunctionDeclaration',
219
- FunctionExpression: 'FunctionExpression',
220
- Identifier: 'Identifier',
221
- IfStatement: 'IfStatement',
222
- Literal: 'Literal',
223
- LabeledStatement: 'LabeledStatement',
224
- LogicalExpression: 'LogicalExpression',
225
- MemberExpression: 'MemberExpression',
226
- NewExpression: 'NewExpression',
227
- ObjectExpression: 'ObjectExpression',
228
- Program: 'Program',
229
- Property: 'Property',
230
- ReturnStatement: 'ReturnStatement',
231
- SequenceExpression: 'SequenceExpression',
232
- SwitchStatement: 'SwitchStatement',
233
- SwitchCase: 'SwitchCase',
234
- ThisExpression: 'ThisExpression',
235
- ThrowStatement: 'ThrowStatement',
236
- TryStatement: 'TryStatement',
237
- UnaryExpression: 'UnaryExpression',
238
- UpdateExpression: 'UpdateExpression',
239
- VariableDeclaration: 'VariableDeclaration',
240
- VariableDeclarator: 'VariableDeclarator',
241
- WhileStatement: 'WhileStatement',
242
- WithStatement: 'WithStatement'
243
- };
244
-
245
- PropertyKind = {
246
- Data: 1,
247
- Get: 2,
248
- Set: 4
249
- };
250
-
251
- // Error messages should be identical to V8.
252
- Messages = {
253
- UnexpectedToken: 'Unexpected token %0',
254
- UnexpectedNumber: 'Unexpected number',
255
- UnexpectedString: 'Unexpected string',
256
- UnexpectedIdentifier: 'Unexpected identifier',
257
- UnexpectedReserved: 'Unexpected reserved word',
258
- UnexpectedEOS: 'Unexpected end of input',
259
- NewlineAfterThrow: 'Illegal newline after throw',
260
- InvalidRegExp: 'Invalid regular expression',
261
- UnterminatedRegExp: 'Invalid regular expression: missing /',
262
- InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
263
- InvalidLHSInForIn: 'Invalid left-hand side in for-in',
264
- MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
265
- NoCatchOrFinally: 'Missing catch or finally after try',
266
- UnknownLabel: 'Undefined label \'%0\'',
267
- Redeclaration: '%0 \'%1\' has already been declared',
268
- IllegalContinue: 'Illegal continue statement',
269
- IllegalBreak: 'Illegal break statement',
270
- IllegalReturn: 'Illegal return statement',
271
- StrictModeWith: 'Strict mode code may not include a with statement',
272
- StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
273
- StrictVarName: 'Variable name may not be eval or arguments in strict mode',
274
- StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
275
- StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
276
- StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
277
- StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
278
- StrictDelete: 'Delete of an unqualified identifier in strict mode.',
279
- StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',
280
- AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',
281
- AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',
282
- StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
283
- StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
284
- StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
285
- StrictReservedWord: 'Use of future reserved word in strict mode'
286
- };
287
-
288
- // See also tools/generate-unicode-regex.py.
289
- Regex = {
290
- NonAsciiIdentifierStart: new RegExp('[\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]'),
291
- 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]')
292
- };
293
-
294
- // Ensure the condition is true, otherwise throw an error.
295
- // This is only to have a better contract semantic, i.e. another safety net
296
- // to catch a logic error. The condition shall be fulfilled in normal case.
297
- // Do NOT use this to enforce a certain condition on any user input.
298
-
299
- function assert(condition, message) {
300
- if (!condition) {
301
- throw new Error('ASSERT: ' + message);
302
- }
303
- }
304
-
305
- function sliceSource(from, to) {
306
- return source.slice(from, to);
307
- }
308
-
309
- if (typeof 'esprima'[0] === 'undefined') {
310
- sliceSource = function sliceArraySource(from, to) {
311
- return source.slice(from, to).join('');
312
- };
313
- }
314
-
315
- function isDecimalDigit(ch) {
316
- return '0123456789'.indexOf(ch) >= 0;
317
- }
318
-
319
- function isHexDigit(ch) {
320
- return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
321
- }
322
-
323
- function isOctalDigit(ch) {
324
- return '01234567'.indexOf(ch) >= 0;
325
- }
326
-
327
-
328
- // 7.2 White Space
329
-
330
- function isWhiteSpace(ch) {
331
- return (ch === ' ') || (ch === '\u0009') || (ch === '\u000B') ||
332
- (ch === '\u000C') || (ch === '\u00A0') ||
333
- (ch.charCodeAt(0) >= 0x1680 &&
334
- '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(ch) >= 0);
335
- }
336
-
337
- // 7.3 Line Terminators
338
-
339
- function isLineTerminator(ch) {
340
- return (ch === '\n' || ch === '\r' || ch === '\u2028' || ch === '\u2029');
341
- }
342
-
343
- // 7.6 Identifier Names and Identifiers
344
-
345
- function isIdentifierStart(ch) {
346
- return (ch === '$') || (ch === '_') || (ch === '\\') ||
347
- (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
348
- ((ch.charCodeAt(0) >= 0x80) && Regex.NonAsciiIdentifierStart.test(ch));
349
- }
350
-
351
- function isIdentifierPart(ch) {
352
- return (ch === '$') || (ch === '_') || (ch === '\\') ||
353
- (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
354
- ((ch >= '0') && (ch <= '9')) ||
355
- ((ch.charCodeAt(0) >= 0x80) && Regex.NonAsciiIdentifierPart.test(ch));
356
- }
357
-
358
- // 7.6.1.2 Future Reserved Words
359
-
360
- function isFutureReservedWord(id) {
361
- switch (id) {
362
-
363
- // Future reserved words.
364
- case 'class':
365
- case 'enum':
366
- case 'export':
367
- case 'extends':
368
- case 'import':
369
- case 'super':
370
- return true;
371
- }
372
-
373
- return false;
374
- }
375
-
376
- function isStrictModeReservedWord(id) {
377
- switch (id) {
378
-
379
- // Strict Mode reserved words.
380
- case 'implements':
381
- case 'interface':
382
- case 'package':
383
- case 'private':
384
- case 'protected':
385
- case 'public':
386
- case 'static':
387
- case 'yield':
388
- case 'let':
389
- return true;
390
- }
391
-
392
- return false;
393
- }
394
-
395
- function isRestrictedWord(id) {
396
- return id === 'eval' || id === 'arguments';
397
- }
398
-
399
- // 7.6.1.1 Keywords
400
-
401
- function isKeyword(id) {
402
- var keyword = false;
403
- switch (id.length) {
404
- case 2:
405
- keyword = (id === 'if') || (id === 'in') || (id === 'do');
406
- break;
407
- case 3:
408
- keyword = (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
409
- break;
410
- case 4:
411
- keyword = (id === 'this') || (id === 'else') || (id === 'case') || (id === 'void') || (id === 'with');
412
- break;
413
- case 5:
414
- keyword = (id === 'while') || (id === 'break') || (id === 'catch') || (id === 'throw');
415
- break;
416
- case 6:
417
- keyword = (id === 'return') || (id === 'typeof') || (id === 'delete') || (id === 'switch');
418
- break;
419
- case 7:
420
- keyword = (id === 'default') || (id === 'finally');
421
- break;
422
- case 8:
423
- keyword = (id === 'function') || (id === 'continue') || (id === 'debugger');
424
- break;
425
- case 10:
426
- keyword = (id === 'instanceof');
427
- break;
428
- }
429
-
430
- if (keyword) {
431
- return true;
432
- }
433
-
434
- switch (id) {
435
- // Future reserved words.
436
- // 'const' is specialized as Keyword in V8.
437
- case 'const':
438
- return true;
439
-
440
- // For compatiblity to SpiderMonkey and ES.next
441
- case 'yield':
442
- case 'let':
443
- return true;
444
- }
445
-
446
- if (strict && isStrictModeReservedWord(id)) {
447
- return true;
448
- }
449
-
450
- return isFutureReservedWord(id);
451
- }
452
-
453
- // 7.4 Comments
454
-
455
- function skipComment() {
456
- var ch, blockComment, lineComment;
457
-
458
- blockComment = false;
459
- lineComment = false;
460
-
461
- while (index < length) {
462
- ch = source[index];
463
-
464
- if (lineComment) {
465
- ch = source[index++];
466
- if (isLineTerminator(ch)) {
467
- lineComment = false;
468
- if (ch === '\r' && source[index] === '\n') {
469
- ++index;
470
- }
471
- ++lineNumber;
472
- lineStart = index;
473
- }
474
- } else if (blockComment) {
475
- if (isLineTerminator(ch)) {
476
- if (ch === '\r' && source[index + 1] === '\n') {
477
- ++index;
478
- }
479
- ++lineNumber;
480
- ++index;
481
- lineStart = index;
482
- if (index >= length) {
483
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
484
- }
485
- } else {
486
- ch = source[index++];
487
- if (index >= length) {
488
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
489
- }
490
- if (ch === '*') {
491
- ch = source[index];
492
- if (ch === '/') {
493
- ++index;
494
- blockComment = false;
495
- }
496
- }
497
- }
498
- } else if (ch === '/') {
499
- ch = source[index + 1];
500
- if (ch === '/') {
501
- index += 2;
502
- lineComment = true;
503
- } else if (ch === '*') {
504
- index += 2;
505
- blockComment = true;
506
- if (index >= length) {
507
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
508
- }
509
- } else {
510
- break;
511
- }
512
- } else if (isWhiteSpace(ch)) {
513
- ++index;
514
- } else if (isLineTerminator(ch)) {
515
- ++index;
516
- if (ch === '\r' && source[index] === '\n') {
517
- ++index;
518
- }
519
- ++lineNumber;
520
- lineStart = index;
521
- } else {
522
- break;
523
- }
524
- }
525
- }
526
-
527
- function scanHexEscape(prefix) {
528
- var i, len, ch, code = 0;
529
-
530
- len = (prefix === 'u') ? 4 : 2;
531
- for (i = 0; i < len; ++i) {
532
- if (index < length && isHexDigit(source[index])) {
533
- ch = source[index++];
534
- code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
535
- } else {
536
- return '';
537
- }
538
- }
539
- return String.fromCharCode(code);
540
- }
541
-
542
- function scanIdentifier() {
543
- var ch, start, id, restore;
544
-
545
- ch = source[index];
546
- if (!isIdentifierStart(ch)) {
547
- return;
548
- }
549
-
550
- start = index;
551
- if (ch === '\\') {
552
- ++index;
553
- if (source[index] !== 'u') {
554
- return;
555
- }
556
- ++index;
557
- restore = index;
558
- ch = scanHexEscape('u');
559
- if (ch) {
560
- if (ch === '\\' || !isIdentifierStart(ch)) {
561
- return;
562
- }
563
- id = ch;
564
- } else {
565
- index = restore;
566
- id = 'u';
567
- }
568
- } else {
569
- id = source[index++];
570
- }
571
-
572
- while (index < length) {
573
- ch = source[index];
574
- if (!isIdentifierPart(ch)) {
575
- break;
576
- }
577
- if (ch === '\\') {
578
- ++index;
579
- if (source[index] !== 'u') {
580
- return;
581
- }
582
- ++index;
583
- restore = index;
584
- ch = scanHexEscape('u');
585
- if (ch) {
586
- if (ch === '\\' || !isIdentifierPart(ch)) {
587
- return;
588
- }
589
- id += ch;
590
- } else {
591
- index = restore;
592
- id += 'u';
593
- }
594
- } else {
595
- id += source[index++];
596
- }
597
- }
598
-
599
- // There is no keyword or literal with only one character.
600
- // Thus, it must be an identifier.
601
- if (id.length === 1) {
602
- return {
603
- type: Token.Identifier,
604
- value: id,
605
- lineNumber: lineNumber,
606
- lineStart: lineStart,
607
- range: [start, index]
608
- };
609
- }
610
-
611
- if (isKeyword(id)) {
612
- return {
613
- type: Token.Keyword,
614
- value: id,
615
- lineNumber: lineNumber,
616
- lineStart: lineStart,
617
- range: [start, index]
618
- };
619
- }
620
-
621
- // 7.8.1 Null Literals
622
-
623
- if (id === 'null') {
624
- return {
625
- type: Token.NullLiteral,
626
- value: id,
627
- lineNumber: lineNumber,
628
- lineStart: lineStart,
629
- range: [start, index]
630
- };
631
- }
632
-
633
- // 7.8.2 Boolean Literals
634
-
635
- if (id === 'true' || id === 'false') {
636
- return {
637
- type: Token.BooleanLiteral,
638
- value: id,
639
- lineNumber: lineNumber,
640
- lineStart: lineStart,
641
- range: [start, index]
642
- };
643
- }
644
-
645
- return {
646
- type: Token.Identifier,
647
- value: id,
648
- lineNumber: lineNumber,
649
- lineStart: lineStart,
650
- range: [start, index]
651
- };
652
- }
653
-
654
- // 7.7 Punctuators
655
-
656
- function scanPunctuator() {
657
- var start = index,
658
- ch1 = source[index],
659
- ch2,
660
- ch3,
661
- ch4;
662
-
663
- // Check for most common single-character punctuators.
664
-
665
- if (ch1 === ';' || ch1 === '{' || ch1 === '}') {
666
- ++index;
667
- return {
668
- type: Token.Punctuator,
669
- value: ch1,
670
- lineNumber: lineNumber,
671
- lineStart: lineStart,
672
- range: [start, index]
673
- };
674
- }
675
-
676
- if (ch1 === ',' || ch1 === '(' || ch1 === ')') {
677
- ++index;
678
- return {
679
- type: Token.Punctuator,
680
- value: ch1,
681
- lineNumber: lineNumber,
682
- lineStart: lineStart,
683
- range: [start, index]
684
- };
685
- }
686
-
687
- // Dot (.) can also start a floating-point number, hence the need
688
- // to check the next character.
689
-
690
- ch2 = source[index + 1];
691
- if (ch1 === '.' && !isDecimalDigit(ch2)) {
692
- return {
693
- type: Token.Punctuator,
694
- value: source[index++],
695
- lineNumber: lineNumber,
696
- lineStart: lineStart,
697
- range: [start, index]
698
- };
699
- }
700
-
701
- // Peek more characters.
702
-
703
- ch3 = source[index + 2];
704
- ch4 = source[index + 3];
705
-
706
- // 4-character punctuator: >>>=
707
-
708
- if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
709
- if (ch4 === '=') {
710
- index += 4;
711
- return {
712
- type: Token.Punctuator,
713
- value: '>>>=',
714
- lineNumber: lineNumber,
715
- lineStart: lineStart,
716
- range: [start, index]
717
- };
718
- }
719
- }
720
-
721
- // 3-character punctuators: === !== >>> <<= >>=
722
-
723
- if (ch1 === '=' && ch2 === '=' && ch3 === '=') {
724
- index += 3;
725
- return {
726
- type: Token.Punctuator,
727
- value: '===',
728
- lineNumber: lineNumber,
729
- lineStart: lineStart,
730
- range: [start, index]
731
- };
732
- }
733
-
734
- if (ch1 === '!' && ch2 === '=' && ch3 === '=') {
735
- index += 3;
736
- return {
737
- type: Token.Punctuator,
738
- value: '!==',
739
- lineNumber: lineNumber,
740
- lineStart: lineStart,
741
- range: [start, index]
742
- };
743
- }
744
-
745
- if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
746
- index += 3;
747
- return {
748
- type: Token.Punctuator,
749
- value: '>>>',
750
- lineNumber: lineNumber,
751
- lineStart: lineStart,
752
- range: [start, index]
753
- };
754
- }
755
-
756
- if (ch1 === '<' && ch2 === '<' && ch3 === '=') {
757
- index += 3;
758
- return {
759
- type: Token.Punctuator,
760
- value: '<<=',
761
- lineNumber: lineNumber,
762
- lineStart: lineStart,
763
- range: [start, index]
764
- };
765
- }
766
-
767
- if (ch1 === '>' && ch2 === '>' && ch3 === '=') {
768
- index += 3;
769
- return {
770
- type: Token.Punctuator,
771
- value: '>>=',
772
- lineNumber: lineNumber,
773
- lineStart: lineStart,
774
- range: [start, index]
775
- };
776
- }
777
-
778
- // 2-character punctuators: <= >= == != ++ -- << >> && ||
779
- // += -= *= %= &= |= ^= /=
780
-
781
- if (ch2 === '=') {
782
- if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
783
- index += 2;
784
- return {
785
- type: Token.Punctuator,
786
- value: ch1 + ch2,
787
- lineNumber: lineNumber,
788
- lineStart: lineStart,
789
- range: [start, index]
790
- };
791
- }
792
- }
793
-
794
- if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0)) {
795
- if ('+-<>&|'.indexOf(ch2) >= 0) {
796
- index += 2;
797
- return {
798
- type: Token.Punctuator,
799
- value: ch1 + ch2,
800
- lineNumber: lineNumber,
801
- lineStart: lineStart,
802
- range: [start, index]
803
- };
804
- }
805
- }
806
-
807
- // The remaining 1-character punctuators.
808
-
809
- if ('[]<>+-*%&|^!~?:=/'.indexOf(ch1) >= 0) {
810
- return {
811
- type: Token.Punctuator,
812
- value: source[index++],
813
- lineNumber: lineNumber,
814
- lineStart: lineStart,
815
- range: [start, index]
816
- };
817
- }
818
- }
819
-
820
- // 7.8.3 Numeric Literals
821
-
822
- function scanNumericLiteral() {
823
- var number, start, ch;
824
-
825
- ch = source[index];
826
- assert(isDecimalDigit(ch) || (ch === '.'),
827
- 'Numeric literal must start with a decimal digit or a decimal point');
828
-
829
- start = index;
830
- number = '';
831
- if (ch !== '.') {
832
- number = source[index++];
833
- ch = source[index];
834
-
835
- // Hex number starts with '0x'.
836
- // Octal number starts with '0'.
837
- if (number === '0') {
838
- if (ch === 'x' || ch === 'X') {
839
- number += source[index++];
840
- while (index < length) {
841
- ch = source[index];
842
- if (!isHexDigit(ch)) {
843
- break;
844
- }
845
- number += source[index++];
846
- }
847
-
848
- if (number.length <= 2) {
849
- // only 0x
850
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
851
- }
852
-
853
- if (index < length) {
854
- ch = source[index];
855
- if (isIdentifierStart(ch)) {
856
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
857
- }
858
- }
859
- return {
860
- type: Token.NumericLiteral,
861
- value: parseInt(number, 16),
862
- lineNumber: lineNumber,
863
- lineStart: lineStart,
864
- range: [start, index]
865
- };
866
- } else if (isOctalDigit(ch)) {
867
- number += source[index++];
868
- while (index < length) {
869
- ch = source[index];
870
- if (!isOctalDigit(ch)) {
871
- break;
872
- }
873
- number += source[index++];
874
- }
875
-
876
- if (index < length) {
877
- ch = source[index];
878
- if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
879
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
880
- }
881
- }
882
- return {
883
- type: Token.NumericLiteral,
884
- value: parseInt(number, 8),
885
- octal: true,
886
- lineNumber: lineNumber,
887
- lineStart: lineStart,
888
- range: [start, index]
889
- };
890
- }
891
-
892
- // decimal number starts with '0' such as '09' is illegal.
893
- if (isDecimalDigit(ch)) {
894
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
895
- }
896
- }
897
-
898
- while (index < length) {
899
- ch = source[index];
900
- if (!isDecimalDigit(ch)) {
901
- break;
902
- }
903
- number += source[index++];
904
- }
905
- }
906
-
907
- if (ch === '.') {
908
- number += source[index++];
909
- while (index < length) {
910
- ch = source[index];
911
- if (!isDecimalDigit(ch)) {
912
- break;
913
- }
914
- number += source[index++];
915
- }
916
- }
917
-
918
- if (ch === 'e' || ch === 'E') {
919
- number += source[index++];
920
-
921
- ch = source[index];
922
- if (ch === '+' || ch === '-') {
923
- number += source[index++];
924
- }
925
-
926
- ch = source[index];
927
- if (isDecimalDigit(ch)) {
928
- number += source[index++];
929
- while (index < length) {
930
- ch = source[index];
931
- if (!isDecimalDigit(ch)) {
932
- break;
933
- }
934
- number += source[index++];
935
- }
936
- } else {
937
- ch = 'character ' + ch;
938
- if (index >= length) {
939
- ch = '<end>';
940
- }
941
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
942
- }
943
- }
944
-
945
- if (index < length) {
946
- ch = source[index];
947
- if (isIdentifierStart(ch)) {
948
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
949
- }
950
- }
951
-
952
- return {
953
- type: Token.NumericLiteral,
954
- value: parseFloat(number),
955
- lineNumber: lineNumber,
956
- lineStart: lineStart,
957
- range: [start, index]
958
- };
959
- }
960
-
961
- // 7.8.4 String Literals
962
-
963
- function scanStringLiteral() {
964
- var str = '', quote, start, ch, code, unescaped, restore, octal = false;
965
-
966
- quote = source[index];
967
- assert((quote === '\'' || quote === '"'),
968
- 'String literal must starts with a quote');
969
-
970
- start = index;
971
- ++index;
972
-
973
- while (index < length) {
974
- ch = source[index++];
975
-
976
- if (ch === quote) {
977
- quote = '';
978
- break;
979
- } else if (ch === '\\') {
980
- ch = source[index++];
981
- if (!isLineTerminator(ch)) {
982
- switch (ch) {
983
- case 'n':
984
- str += '\n';
985
- break;
986
- case 'r':
987
- str += '\r';
988
- break;
989
- case 't':
990
- str += '\t';
991
- break;
992
- case 'u':
993
- case 'x':
994
- restore = index;
995
- unescaped = scanHexEscape(ch);
996
- if (unescaped) {
997
- str += unescaped;
998
- } else {
999
- index = restore;
1000
- str += ch;
1001
- }
1002
- break;
1003
- case 'b':
1004
- str += '\b';
1005
- break;
1006
- case 'f':
1007
- str += '\f';
1008
- break;
1009
- case 'v':
1010
- str += '\x0B';
1011
- break;
1012
-
1013
- default:
1014
- if (isOctalDigit(ch)) {
1015
- code = '01234567'.indexOf(ch);
1016
-
1017
- // \0 is not octal escape sequence
1018
- if (code !== 0) {
1019
- octal = true;
1020
- }
1021
-
1022
- if (index < length && isOctalDigit(source[index])) {
1023
- octal = true;
1024
- code = code * 8 + '01234567'.indexOf(source[index++]);
1025
-
1026
- // 3 digits are only allowed when string starts
1027
- // with 0, 1, 2, 3
1028
- if ('0123'.indexOf(ch) >= 0 &&
1029
- index < length &&
1030
- isOctalDigit(source[index])) {
1031
- code = code * 8 + '01234567'.indexOf(source[index++]);
1032
- }
1033
- }
1034
- str += String.fromCharCode(code);
1035
- } else {
1036
- str += ch;
1037
- }
1038
- break;
1039
- }
1040
- } else {
1041
- ++lineNumber;
1042
- if (ch === '\r' && source[index] === '\n') {
1043
- ++index;
1044
- }
1045
- }
1046
- } else if (isLineTerminator(ch)) {
1047
- break;
1048
- } else {
1049
- str += ch;
1050
- }
1051
- }
1052
-
1053
- if (quote !== '') {
1054
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
1055
- }
1056
-
1057
- return {
1058
- type: Token.StringLiteral,
1059
- value: str,
1060
- octal: octal,
1061
- lineNumber: lineNumber,
1062
- lineStart: lineStart,
1063
- range: [start, index]
1064
- };
1065
- }
1066
-
1067
- function scanRegExp() {
1068
- var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false;
1069
-
1070
- buffer = null;
1071
- skipComment();
1072
-
1073
- start = index;
1074
- ch = source[index];
1075
- assert(ch === '/', 'Regular expression literal must start with a slash');
1076
- str = source[index++];
1077
-
1078
- while (index < length) {
1079
- ch = source[index++];
1080
- str += ch;
1081
- if (ch === '\\') {
1082
- ch = source[index++];
1083
- // ECMA-262 7.8.5
1084
- if (isLineTerminator(ch)) {
1085
- throwError({}, Messages.UnterminatedRegExp);
1086
- }
1087
- str += ch;
1088
- } else if (classMarker) {
1089
- if (ch === ']') {
1090
- classMarker = false;
1091
- }
1092
- } else {
1093
- if (ch === '/') {
1094
- terminated = true;
1095
- break;
1096
- } else if (ch === '[') {
1097
- classMarker = true;
1098
- } else if (isLineTerminator(ch)) {
1099
- throwError({}, Messages.UnterminatedRegExp);
1100
- }
1101
- }
1102
- }
1103
-
1104
- if (!terminated) {
1105
- throwError({}, Messages.UnterminatedRegExp);
1106
- }
1107
-
1108
- // Exclude leading and trailing slash.
1109
- pattern = str.substr(1, str.length - 2);
1110
-
1111
- flags = '';
1112
- while (index < length) {
1113
- ch = source[index];
1114
- if (!isIdentifierPart(ch)) {
1115
- break;
1116
- }
1117
-
1118
- ++index;
1119
- if (ch === '\\' && index < length) {
1120
- ch = source[index];
1121
- if (ch === 'u') {
1122
- ++index;
1123
- restore = index;
1124
- ch = scanHexEscape('u');
1125
- if (ch) {
1126
- flags += ch;
1127
- str += '\\u';
1128
- for (; restore < index; ++restore) {
1129
- str += source[restore];
1130
- }
1131
- } else {
1132
- index = restore;
1133
- flags += 'u';
1134
- str += '\\u';
1135
- }
1136
- } else {
1137
- str += '\\';
1138
- }
1139
- } else {
1140
- flags += ch;
1141
- str += ch;
1142
- }
1143
- }
1144
-
1145
- try {
1146
- value = new RegExp(pattern, flags);
1147
- } catch (e) {
1148
- throwError({}, Messages.InvalidRegExp);
1149
- }
1150
-
1151
- return {
1152
- literal: str,
1153
- value: value,
1154
- range: [start, index]
1155
- };
1156
- }
1157
-
1158
- function isIdentifierName(token) {
1159
- return token.type === Token.Identifier ||
1160
- token.type === Token.Keyword ||
1161
- token.type === Token.BooleanLiteral ||
1162
- token.type === Token.NullLiteral;
1163
- }
1164
-
1165
- function advance() {
1166
- var ch, token;
1167
-
1168
- skipComment();
1169
-
1170
- if (index >= length) {
1171
- return {
1172
- type: Token.EOF,
1173
- lineNumber: lineNumber,
1174
- lineStart: lineStart,
1175
- range: [index, index]
1176
- };
1177
- }
1178
-
1179
- token = scanPunctuator();
1180
- if (typeof token !== 'undefined') {
1181
- return token;
1182
- }
1183
-
1184
- ch = source[index];
1185
-
1186
- if (ch === '\'' || ch === '"') {
1187
- return scanStringLiteral();
1188
- }
1189
-
1190
- if (ch === '.' || isDecimalDigit(ch)) {
1191
- return scanNumericLiteral();
1192
- }
1193
-
1194
- token = scanIdentifier();
1195
- if (typeof token !== 'undefined') {
1196
- return token;
1197
- }
1198
-
1199
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
1200
- }
1201
-
1202
- function lex() {
1203
- var token;
1204
-
1205
- if (buffer) {
1206
- index = buffer.range[1];
1207
- lineNumber = buffer.lineNumber;
1208
- lineStart = buffer.lineStart;
1209
- token = buffer;
1210
- buffer = null;
1211
- return token;
1212
- }
1213
-
1214
- buffer = null;
1215
- return advance();
1216
- }
1217
-
1218
- function lookahead() {
1219
- var pos, line, start;
1220
-
1221
- if (buffer !== null) {
1222
- return buffer;
1223
- }
1224
-
1225
- pos = index;
1226
- line = lineNumber;
1227
- start = lineStart;
1228
- buffer = advance();
1229
- index = pos;
1230
- lineNumber = line;
1231
- lineStart = start;
1232
-
1233
- return buffer;
1234
- }
1235
-
1236
- // Return true if there is a line terminator before the next token.
1237
-
1238
- function peekLineTerminator() {
1239
- var pos, line, start, found;
1240
-
1241
- pos = index;
1242
- line = lineNumber;
1243
- start = lineStart;
1244
- skipComment();
1245
- found = lineNumber !== line;
1246
- index = pos;
1247
- lineNumber = line;
1248
- lineStart = start;
1249
-
1250
- return found;
1251
- }
1252
-
1253
- // Throw an exception
1254
-
1255
- function throwError(token, messageFormat) {
1256
- var error,
1257
- args = Array.prototype.slice.call(arguments, 2),
1258
- msg = messageFormat.replace(
1259
- /%(\d)/g,
1260
- function (whole, index) {
1261
- return args[index] || '';
1262
- }
1263
- );
1264
-
1265
- if (typeof token.lineNumber === 'number') {
1266
- error = new Error('Line ' + token.lineNumber + ': ' + msg);
1267
- error.index = token.range[0];
1268
- error.lineNumber = token.lineNumber;
1269
- error.column = token.range[0] - lineStart + 1;
1270
- } else {
1271
- error = new Error('Line ' + lineNumber + ': ' + msg);
1272
- error.index = index;
1273
- error.lineNumber = lineNumber;
1274
- error.column = index - lineStart + 1;
1275
- }
1276
-
1277
- throw error;
1278
- }
1279
-
1280
- function throwErrorTolerant() {
1281
- try {
1282
- throwError.apply(null, arguments);
1283
- } catch (e) {
1284
- if (extra.errors) {
1285
- extra.errors.push(e);
1286
- } else {
1287
- throw e;
1288
- }
1289
- }
1290
- }
1291
-
1292
-
1293
- // Throw an exception because of the token.
1294
-
1295
- function throwUnexpected(token) {
1296
- if (token.type === Token.EOF) {
1297
- throwError(token, Messages.UnexpectedEOS);
1298
- }
1299
-
1300
- if (token.type === Token.NumericLiteral) {
1301
- throwError(token, Messages.UnexpectedNumber);
1302
- }
1303
-
1304
- if (token.type === Token.StringLiteral) {
1305
- throwError(token, Messages.UnexpectedString);
1306
- }
1307
-
1308
- if (token.type === Token.Identifier) {
1309
- throwError(token, Messages.UnexpectedIdentifier);
1310
- }
1311
-
1312
- if (token.type === Token.Keyword) {
1313
- if (isFutureReservedWord(token.value)) {
1314
- throwError(token, Messages.UnexpectedReserved);
1315
- } else if (strict && isStrictModeReservedWord(token.value)) {
1316
- throwErrorTolerant(token, Messages.StrictReservedWord);
1317
- return;
1318
- }
1319
- throwError(token, Messages.UnexpectedToken, token.value);
1320
- }
1321
-
1322
- // BooleanLiteral, NullLiteral, or Punctuator.
1323
- throwError(token, Messages.UnexpectedToken, token.value);
1324
- }
1325
-
1326
- // Expect the next token to match the specified punctuator.
1327
- // If not, an exception will be thrown.
1328
-
1329
- function expect(value) {
1330
- var token = lex();
1331
- if (token.type !== Token.Punctuator || token.value !== value) {
1332
- throwUnexpected(token);
1333
- }
1334
- }
1335
-
1336
- // Expect the next token to match the specified keyword.
1337
- // If not, an exception will be thrown.
1338
-
1339
- function expectKeyword(keyword) {
1340
- var token = lex();
1341
- if (token.type !== Token.Keyword || token.value !== keyword) {
1342
- throwUnexpected(token);
1343
- }
1344
- }
1345
-
1346
- // Return true if the next token matches the specified punctuator.
1347
-
1348
- function match(value) {
1349
- var token = lookahead();
1350
- return token.type === Token.Punctuator && token.value === value;
1351
- }
1352
-
1353
- // Return true if the next token matches the specified keyword
1354
-
1355
- function matchKeyword(keyword) {
1356
- var token = lookahead();
1357
- return token.type === Token.Keyword && token.value === keyword;
1358
- }
1359
-
1360
- // Return true if the next token is an assignment operator
1361
-
1362
- function matchAssign() {
1363
- var token = lookahead(),
1364
- op = token.value;
1365
-
1366
- if (token.type !== Token.Punctuator) {
1367
- return false;
1368
- }
1369
- return op === '=' ||
1370
- op === '*=' ||
1371
- op === '/=' ||
1372
- op === '%=' ||
1373
- op === '+=' ||
1374
- op === '-=' ||
1375
- op === '<<=' ||
1376
- op === '>>=' ||
1377
- op === '>>>=' ||
1378
- op === '&=' ||
1379
- op === '^=' ||
1380
- op === '|=';
1381
- }
1382
-
1383
- function consumeSemicolon() {
1384
- var token, line;
1385
-
1386
- // Catch the very common case first.
1387
- if (source[index] === ';') {
1388
- lex();
1389
- return;
1390
- }
1391
-
1392
- line = lineNumber;
1393
- skipComment();
1394
- if (lineNumber !== line) {
1395
- return;
1396
- }
1397
-
1398
- if (match(';')) {
1399
- lex();
1400
- return;
1401
- }
1402
-
1403
- token = lookahead();
1404
- if (token.type !== Token.EOF && !match('}')) {
1405
- throwUnexpected(token);
1406
- }
1407
- }
1408
-
1409
- // Return true if provided expression is LeftHandSideExpression
1410
-
1411
- function isLeftHandSide(expr) {
1412
- return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
1413
- }
1414
-
1415
- // 11.1.4 Array Initialiser
1416
-
1417
- function parseArrayInitialiser() {
1418
- var elements = [];
1419
-
1420
- expect('[');
1421
-
1422
- while (!match(']')) {
1423
- if (match(',')) {
1424
- lex();
1425
- elements.push(null);
1426
- } else {
1427
- elements.push(parseAssignmentExpression());
1428
-
1429
- if (!match(']')) {
1430
- expect(',');
1431
- }
1432
- }
1433
- }
1434
-
1435
- expect(']');
1436
-
1437
- return {
1438
- type: Syntax.ArrayExpression,
1439
- elements: elements
1440
- };
1441
- }
1442
-
1443
- // 11.1.5 Object Initialiser
1444
-
1445
- function parsePropertyFunction(param, first) {
1446
- var previousStrict, body;
1447
-
1448
- previousStrict = strict;
1449
- body = parseFunctionSourceElements();
1450
- if (first && strict && isRestrictedWord(param[0].name)) {
1451
- throwErrorTolerant(first, Messages.StrictParamName);
1452
- }
1453
- strict = previousStrict;
1454
-
1455
- return {
1456
- type: Syntax.FunctionExpression,
1457
- id: null,
1458
- params: param,
1459
- defaults: [],
1460
- body: body,
1461
- rest: null,
1462
- generator: false,
1463
- expression: false
1464
- };
1465
- }
1466
-
1467
- function parseObjectPropertyKey() {
1468
- var token = lex();
1469
-
1470
- // Note: This function is called only from parseObjectProperty(), where
1471
- // EOF and Punctuator tokens are already filtered out.
1472
-
1473
- if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {
1474
- if (strict && token.octal) {
1475
- throwErrorTolerant(token, Messages.StrictOctalLiteral);
1476
- }
1477
- return createLiteral(token);
1478
- }
1479
-
1480
- return {
1481
- type: Syntax.Identifier,
1482
- name: token.value
1483
- };
1484
- }
1485
-
1486
- function parseObjectProperty() {
1487
- var token, key, id, param;
1488
-
1489
- token = lookahead();
1490
-
1491
- if (token.type === Token.Identifier) {
1492
-
1493
- id = parseObjectPropertyKey();
1494
-
1495
- // Property Assignment: Getter and Setter.
1496
-
1497
- if (token.value === 'get' && !match(':')) {
1498
- key = parseObjectPropertyKey();
1499
- expect('(');
1500
- expect(')');
1501
- return {
1502
- type: Syntax.Property,
1503
- key: key,
1504
- value: parsePropertyFunction([]),
1505
- kind: 'get'
1506
- };
1507
- } else if (token.value === 'set' && !match(':')) {
1508
- key = parseObjectPropertyKey();
1509
- expect('(');
1510
- token = lookahead();
1511
- if (token.type !== Token.Identifier) {
1512
- expect(')');
1513
- throwErrorTolerant(token, Messages.UnexpectedToken, token.value);
1514
- return {
1515
- type: Syntax.Property,
1516
- key: key,
1517
- value: parsePropertyFunction([]),
1518
- kind: 'set'
1519
- };
1520
- } else {
1521
- param = [ parseVariableIdentifier() ];
1522
- expect(')');
1523
- return {
1524
- type: Syntax.Property,
1525
- key: key,
1526
- value: parsePropertyFunction(param, token),
1527
- kind: 'set'
1528
- };
1529
- }
1530
- } else {
1531
- expect(':');
1532
- return {
1533
- type: Syntax.Property,
1534
- key: id,
1535
- value: parseAssignmentExpression(),
1536
- kind: 'init'
1537
- };
1538
- }
1539
- } else if (token.type === Token.EOF || token.type === Token.Punctuator) {
1540
- throwUnexpected(token);
1541
- } else {
1542
- key = parseObjectPropertyKey();
1543
- expect(':');
1544
- return {
1545
- type: Syntax.Property,
1546
- key: key,
1547
- value: parseAssignmentExpression(),
1548
- kind: 'init'
1549
- };
1550
- }
1551
- }
1552
-
1553
- function parseObjectInitialiser() {
1554
- var properties = [], property, name, kind, map = {}, toString = String;
1555
-
1556
- expect('{');
1557
-
1558
- while (!match('}')) {
1559
- property = parseObjectProperty();
1560
-
1561
- if (property.key.type === Syntax.Identifier) {
1562
- name = property.key.name;
1563
- } else {
1564
- name = toString(property.key.value);
1565
- }
1566
- kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;
1567
- if (Object.prototype.hasOwnProperty.call(map, name)) {
1568
- if (map[name] === PropertyKind.Data) {
1569
- if (strict && kind === PropertyKind.Data) {
1570
- throwErrorTolerant({}, Messages.StrictDuplicateProperty);
1571
- } else if (kind !== PropertyKind.Data) {
1572
- throwErrorTolerant({}, Messages.AccessorDataProperty);
1573
- }
1574
- } else {
1575
- if (kind === PropertyKind.Data) {
1576
- throwErrorTolerant({}, Messages.AccessorDataProperty);
1577
- } else if (map[name] & kind) {
1578
- throwErrorTolerant({}, Messages.AccessorGetSet);
1579
- }
1580
- }
1581
- map[name] |= kind;
1582
- } else {
1583
- map[name] = kind;
1584
- }
1585
-
1586
- properties.push(property);
1587
-
1588
- if (!match('}')) {
1589
- expect(',');
1590
- }
1591
- }
1592
-
1593
- expect('}');
1594
-
1595
- return {
1596
- type: Syntax.ObjectExpression,
1597
- properties: properties
1598
- };
1599
- }
1600
-
1601
- // 11.1.6 The Grouping Operator
1602
-
1603
- function parseGroupExpression() {
1604
- var expr;
1605
-
1606
- expect('(');
1607
-
1608
- expr = parseExpression();
1609
-
1610
- expect(')');
1611
-
1612
- return expr;
1613
- }
1614
-
1615
-
1616
- // 11.1 Primary Expressions
1617
-
1618
- function parsePrimaryExpression() {
1619
- var token = lookahead(),
1620
- type = token.type;
1621
-
1622
- if (type === Token.Identifier) {
1623
- return {
1624
- type: Syntax.Identifier,
1625
- name: lex().value
1626
- };
1627
- }
1628
-
1629
- if (type === Token.StringLiteral || type === Token.NumericLiteral) {
1630
- if (strict && token.octal) {
1631
- throwErrorTolerant(token, Messages.StrictOctalLiteral);
1632
- }
1633
- return createLiteral(lex());
1634
- }
1635
-
1636
- if (type === Token.Keyword) {
1637
- if (matchKeyword('this')) {
1638
- lex();
1639
- return {
1640
- type: Syntax.ThisExpression
1641
- };
1642
- }
1643
-
1644
- if (matchKeyword('function')) {
1645
- return parseFunctionExpression();
1646
- }
1647
- }
1648
-
1649
- if (type === Token.BooleanLiteral) {
1650
- lex();
1651
- token.value = (token.value === 'true');
1652
- return createLiteral(token);
1653
- }
1654
-
1655
- if (type === Token.NullLiteral) {
1656
- lex();
1657
- token.value = null;
1658
- return createLiteral(token);
1659
- }
1660
-
1661
- if (match('[')) {
1662
- return parseArrayInitialiser();
1663
- }
1664
-
1665
- if (match('{')) {
1666
- return parseObjectInitialiser();
1667
- }
1668
-
1669
- if (match('(')) {
1670
- return parseGroupExpression();
1671
- }
1672
-
1673
- if (match('/') || match('/=')) {
1674
- return createLiteral(scanRegExp());
1675
- }
1676
-
1677
- return throwUnexpected(lex());
1678
- }
1679
-
1680
- // 11.2 Left-Hand-Side Expressions
1681
-
1682
- function parseArguments() {
1683
- var args = [];
1684
-
1685
- expect('(');
1686
-
1687
- if (!match(')')) {
1688
- while (index < length) {
1689
- args.push(parseAssignmentExpression());
1690
- if (match(')')) {
1691
- break;
1692
- }
1693
- expect(',');
1694
- }
1695
- }
1696
-
1697
- expect(')');
1698
-
1699
- return args;
1700
- }
1701
-
1702
- function parseNonComputedProperty() {
1703
- var token = lex();
1704
-
1705
- if (!isIdentifierName(token)) {
1706
- throwUnexpected(token);
1707
- }
1708
-
1709
- return {
1710
- type: Syntax.Identifier,
1711
- name: token.value
1712
- };
1713
- }
1714
-
1715
- function parseNonComputedMember() {
1716
- expect('.');
1717
-
1718
- return parseNonComputedProperty();
1719
- }
1720
-
1721
- function parseComputedMember() {
1722
- var expr;
1723
-
1724
- expect('[');
1725
-
1726
- expr = parseExpression();
1727
-
1728
- expect(']');
1729
-
1730
- return expr;
1731
- }
1732
-
1733
- function parseNewExpression() {
1734
- var expr;
1735
-
1736
- expectKeyword('new');
1737
-
1738
- expr = {
1739
- type: Syntax.NewExpression,
1740
- callee: parseLeftHandSideExpression(),
1741
- 'arguments': []
1742
- };
1743
-
1744
- if (match('(')) {
1745
- expr['arguments'] = parseArguments();
1746
- }
1747
-
1748
- return expr;
1749
- }
1750
-
1751
- function parseLeftHandSideExpressionAllowCall() {
1752
- var expr;
1753
-
1754
- expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
1755
-
1756
- while (match('.') || match('[') || match('(')) {
1757
- if (match('(')) {
1758
- expr = {
1759
- type: Syntax.CallExpression,
1760
- callee: expr,
1761
- 'arguments': parseArguments()
1762
- };
1763
- } else if (match('[')) {
1764
- expr = {
1765
- type: Syntax.MemberExpression,
1766
- computed: true,
1767
- object: expr,
1768
- property: parseComputedMember()
1769
- };
1770
- } else {
1771
- expr = {
1772
- type: Syntax.MemberExpression,
1773
- computed: false,
1774
- object: expr,
1775
- property: parseNonComputedMember()
1776
- };
1777
- }
1778
- }
1779
-
1780
- return expr;
1781
- }
1782
-
1783
-
1784
- function parseLeftHandSideExpression() {
1785
- var expr;
1786
-
1787
- expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
1788
-
1789
- while (match('.') || match('[')) {
1790
- if (match('[')) {
1791
- expr = {
1792
- type: Syntax.MemberExpression,
1793
- computed: true,
1794
- object: expr,
1795
- property: parseComputedMember()
1796
- };
1797
- } else {
1798
- expr = {
1799
- type: Syntax.MemberExpression,
1800
- computed: false,
1801
- object: expr,
1802
- property: parseNonComputedMember()
1803
- };
1804
- }
1805
- }
1806
-
1807
- return expr;
1808
- }
1809
-
1810
- // 11.3 Postfix Expressions
1811
-
1812
- function parsePostfixExpression() {
1813
- var expr = parseLeftHandSideExpressionAllowCall(), token;
1814
-
1815
- token = lookahead();
1816
- if (token.type !== Token.Punctuator) {
1817
- return expr;
1818
- }
1819
-
1820
- if ((match('++') || match('--')) && !peekLineTerminator()) {
1821
- // 11.3.1, 11.3.2
1822
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
1823
- throwErrorTolerant({}, Messages.StrictLHSPostfix);
1824
- }
1825
- if (!isLeftHandSide(expr)) {
1826
- throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
1827
- }
1828
-
1829
- expr = {
1830
- type: Syntax.UpdateExpression,
1831
- operator: lex().value,
1832
- argument: expr,
1833
- prefix: false
1834
- };
1835
- }
1836
-
1837
- return expr;
1838
- }
1839
-
1840
- // 11.4 Unary Operators
1841
-
1842
- function parseUnaryExpression() {
1843
- var token, expr;
1844
-
1845
- token = lookahead();
1846
- if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
1847
- return parsePostfixExpression();
1848
- }
1849
-
1850
- if (match('++') || match('--')) {
1851
- token = lex();
1852
- expr = parseUnaryExpression();
1853
- // 11.4.4, 11.4.5
1854
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
1855
- throwErrorTolerant({}, Messages.StrictLHSPrefix);
1856
- }
1857
-
1858
- if (!isLeftHandSide(expr)) {
1859
- throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
1860
- }
1861
-
1862
- expr = {
1863
- type: Syntax.UpdateExpression,
1864
- operator: token.value,
1865
- argument: expr,
1866
- prefix: true
1867
- };
1868
- return expr;
1869
- }
1870
-
1871
- if (match('+') || match('-') || match('~') || match('!')) {
1872
- expr = {
1873
- type: Syntax.UnaryExpression,
1874
- operator: lex().value,
1875
- argument: parseUnaryExpression(),
1876
- prefix: true
1877
- };
1878
- return expr;
1879
- }
1880
-
1881
- if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
1882
- expr = {
1883
- type: Syntax.UnaryExpression,
1884
- operator: lex().value,
1885
- argument: parseUnaryExpression(),
1886
- prefix: true
1887
- };
1888
- if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
1889
- throwErrorTolerant({}, Messages.StrictDelete);
1890
- }
1891
- return expr;
1892
- }
1893
-
1894
- return parsePostfixExpression();
1895
- }
1896
-
1897
- // 11.5 Multiplicative Operators
1898
-
1899
- function parseMultiplicativeExpression() {
1900
- var expr = parseUnaryExpression();
1901
-
1902
- while (match('*') || match('/') || match('%')) {
1903
- expr = {
1904
- type: Syntax.BinaryExpression,
1905
- operator: lex().value,
1906
- left: expr,
1907
- right: parseUnaryExpression()
1908
- };
1909
- }
1910
-
1911
- return expr;
1912
- }
1913
-
1914
- // 11.6 Additive Operators
1915
-
1916
- function parseAdditiveExpression() {
1917
- var expr = parseMultiplicativeExpression();
1918
-
1919
- while (match('+') || match('-')) {
1920
- expr = {
1921
- type: Syntax.BinaryExpression,
1922
- operator: lex().value,
1923
- left: expr,
1924
- right: parseMultiplicativeExpression()
1925
- };
1926
- }
1927
-
1928
- return expr;
1929
- }
1930
-
1931
- // 11.7 Bitwise Shift Operators
1932
-
1933
- function parseShiftExpression() {
1934
- var expr = parseAdditiveExpression();
1935
-
1936
- while (match('<<') || match('>>') || match('>>>')) {
1937
- expr = {
1938
- type: Syntax.BinaryExpression,
1939
- operator: lex().value,
1940
- left: expr,
1941
- right: parseAdditiveExpression()
1942
- };
1943
- }
1944
-
1945
- return expr;
1946
- }
1947
- // 11.8 Relational Operators
1948
-
1949
- function parseRelationalExpression() {
1950
- var expr, previousAllowIn;
1951
-
1952
- previousAllowIn = state.allowIn;
1953
- state.allowIn = true;
1954
-
1955
- expr = parseShiftExpression();
1956
-
1957
- while (match('<') || match('>') || match('<=') || match('>=') || (previousAllowIn && matchKeyword('in')) || matchKeyword('instanceof')) {
1958
- expr = {
1959
- type: Syntax.BinaryExpression,
1960
- operator: lex().value,
1961
- left: expr,
1962
- right: parseShiftExpression()
1963
- };
1964
- }
1965
-
1966
- state.allowIn = previousAllowIn;
1967
- return expr;
1968
- }
1969
-
1970
- // 11.9 Equality Operators
1971
-
1972
- function parseEqualityExpression() {
1973
- var expr = parseRelationalExpression();
1974
-
1975
- while (match('==') || match('!=') || match('===') || match('!==')) {
1976
- expr = {
1977
- type: Syntax.BinaryExpression,
1978
- operator: lex().value,
1979
- left: expr,
1980
- right: parseRelationalExpression()
1981
- };
1982
- }
1983
-
1984
- return expr;
1985
- }
1986
-
1987
- // 11.10 Binary Bitwise Operators
1988
-
1989
- function parseBitwiseANDExpression() {
1990
- var expr = parseEqualityExpression();
1991
-
1992
- while (match('&')) {
1993
- lex();
1994
- expr = {
1995
- type: Syntax.BinaryExpression,
1996
- operator: '&',
1997
- left: expr,
1998
- right: parseEqualityExpression()
1999
- };
2000
- }
2001
-
2002
- return expr;
2003
- }
2004
-
2005
- function parseBitwiseXORExpression() {
2006
- var expr = parseBitwiseANDExpression();
2007
-
2008
- while (match('^')) {
2009
- lex();
2010
- expr = {
2011
- type: Syntax.BinaryExpression,
2012
- operator: '^',
2013
- left: expr,
2014
- right: parseBitwiseANDExpression()
2015
- };
2016
- }
2017
-
2018
- return expr;
2019
- }
2020
-
2021
- function parseBitwiseORExpression() {
2022
- var expr = parseBitwiseXORExpression();
2023
-
2024
- while (match('|')) {
2025
- lex();
2026
- expr = {
2027
- type: Syntax.BinaryExpression,
2028
- operator: '|',
2029
- left: expr,
2030
- right: parseBitwiseXORExpression()
2031
- };
2032
- }
2033
-
2034
- return expr;
2035
- }
2036
-
2037
- // 11.11 Binary Logical Operators
2038
-
2039
- function parseLogicalANDExpression() {
2040
- var expr = parseBitwiseORExpression();
2041
-
2042
- while (match('&&')) {
2043
- lex();
2044
- expr = {
2045
- type: Syntax.LogicalExpression,
2046
- operator: '&&',
2047
- left: expr,
2048
- right: parseBitwiseORExpression()
2049
- };
2050
- }
2051
-
2052
- return expr;
2053
- }
2054
-
2055
- function parseLogicalORExpression() {
2056
- var expr = parseLogicalANDExpression();
2057
-
2058
- while (match('||')) {
2059
- lex();
2060
- expr = {
2061
- type: Syntax.LogicalExpression,
2062
- operator: '||',
2063
- left: expr,
2064
- right: parseLogicalANDExpression()
2065
- };
2066
- }
2067
-
2068
- return expr;
2069
- }
2070
-
2071
- // 11.12 Conditional Operator
2072
-
2073
- function parseConditionalExpression() {
2074
- var expr, previousAllowIn, consequent;
2075
-
2076
- expr = parseLogicalORExpression();
2077
-
2078
- if (match('?')) {
2079
- lex();
2080
- previousAllowIn = state.allowIn;
2081
- state.allowIn = true;
2082
- consequent = parseAssignmentExpression();
2083
- state.allowIn = previousAllowIn;
2084
- expect(':');
2085
-
2086
- expr = {
2087
- type: Syntax.ConditionalExpression,
2088
- test: expr,
2089
- consequent: consequent,
2090
- alternate: parseAssignmentExpression()
2091
- };
2092
- }
2093
-
2094
- return expr;
2095
- }
2096
-
2097
- // 11.13 Assignment Operators
2098
-
2099
- function parseAssignmentExpression() {
2100
- var token, expr;
2101
-
2102
- token = lookahead();
2103
- expr = parseConditionalExpression();
2104
-
2105
- if (matchAssign()) {
2106
- // LeftHandSideExpression
2107
- if (!isLeftHandSide(expr)) {
2108
- throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
2109
- }
2110
-
2111
- // 11.13.1
2112
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
2113
- throwErrorTolerant(token, Messages.StrictLHSAssignment);
2114
- }
2115
-
2116
- expr = {
2117
- type: Syntax.AssignmentExpression,
2118
- operator: lex().value,
2119
- left: expr,
2120
- right: parseAssignmentExpression()
2121
- };
2122
- }
2123
-
2124
- return expr;
2125
- }
2126
-
2127
- // 11.14 Comma Operator
2128
-
2129
- function parseExpression() {
2130
- var expr = parseAssignmentExpression();
2131
-
2132
- if (match(',')) {
2133
- expr = {
2134
- type: Syntax.SequenceExpression,
2135
- expressions: [ expr ]
2136
- };
2137
-
2138
- while (index < length) {
2139
- if (!match(',')) {
2140
- break;
2141
- }
2142
- lex();
2143
- expr.expressions.push(parseAssignmentExpression());
2144
- }
2145
-
2146
- }
2147
- return expr;
2148
- }
2149
-
2150
- // 12.1 Block
2151
-
2152
- function parseStatementList() {
2153
- var list = [],
2154
- statement;
2155
-
2156
- while (index < length) {
2157
- if (match('}')) {
2158
- break;
2159
- }
2160
- statement = parseSourceElement();
2161
- if (typeof statement === 'undefined') {
2162
- break;
2163
- }
2164
- list.push(statement);
2165
- }
2166
-
2167
- return list;
2168
- }
2169
-
2170
- function parseBlock() {
2171
- var block;
2172
-
2173
- expect('{');
2174
-
2175
- block = parseStatementList();
2176
-
2177
- expect('}');
2178
-
2179
- return {
2180
- type: Syntax.BlockStatement,
2181
- body: block
2182
- };
2183
- }
2184
-
2185
- // 12.2 Variable Statement
2186
-
2187
- function parseVariableIdentifier() {
2188
- var token = lex();
2189
-
2190
- if (token.type !== Token.Identifier) {
2191
- throwUnexpected(token);
2192
- }
2193
-
2194
- return {
2195
- type: Syntax.Identifier,
2196
- name: token.value
2197
- };
2198
- }
2199
-
2200
- function parseVariableDeclaration(kind) {
2201
- var id = parseVariableIdentifier(),
2202
- init = null;
2203
-
2204
- // 12.2.1
2205
- if (strict && isRestrictedWord(id.name)) {
2206
- throwErrorTolerant({}, Messages.StrictVarName);
2207
- }
2208
-
2209
- if (kind === 'const') {
2210
- expect('=');
2211
- init = parseAssignmentExpression();
2212
- } else if (match('=')) {
2213
- lex();
2214
- init = parseAssignmentExpression();
2215
- }
2216
-
2217
- return {
2218
- type: Syntax.VariableDeclarator,
2219
- id: id,
2220
- init: init
2221
- };
2222
- }
2223
-
2224
- function parseVariableDeclarationList(kind) {
2225
- var list = [];
2226
-
2227
- do {
2228
- list.push(parseVariableDeclaration(kind));
2229
- if (!match(',')) {
2230
- break;
2231
- }
2232
- lex();
2233
- } while (index < length);
2234
-
2235
- return list;
2236
- }
2237
-
2238
- function parseVariableStatement() {
2239
- var declarations;
2240
-
2241
- expectKeyword('var');
2242
-
2243
- declarations = parseVariableDeclarationList();
2244
-
2245
- consumeSemicolon();
2246
-
2247
- return {
2248
- type: Syntax.VariableDeclaration,
2249
- declarations: declarations,
2250
- kind: 'var'
2251
- };
2252
- }
2253
-
2254
- // kind may be `const` or `let`
2255
- // Both are experimental and not in the specification yet.
2256
- // see http://wiki.ecmascript.org/doku.php?id=harmony:const
2257
- // and http://wiki.ecmascript.org/doku.php?id=harmony:let
2258
- function parseConstLetDeclaration(kind) {
2259
- var declarations;
2260
-
2261
- expectKeyword(kind);
2262
-
2263
- declarations = parseVariableDeclarationList(kind);
2264
-
2265
- consumeSemicolon();
2266
-
2267
- return {
2268
- type: Syntax.VariableDeclaration,
2269
- declarations: declarations,
2270
- kind: kind
2271
- };
2272
- }
2273
-
2274
- // 12.3 Empty Statement
2275
-
2276
- function parseEmptyStatement() {
2277
- expect(';');
2278
-
2279
- return {
2280
- type: Syntax.EmptyStatement
2281
- };
2282
- }
2283
-
2284
- // 12.4 Expression Statement
2285
-
2286
- function parseExpressionStatement() {
2287
- var expr = parseExpression();
2288
-
2289
- consumeSemicolon();
2290
-
2291
- return {
2292
- type: Syntax.ExpressionStatement,
2293
- expression: expr
2294
- };
2295
- }
2296
-
2297
- // 12.5 If statement
2298
-
2299
- function parseIfStatement() {
2300
- var test, consequent, alternate;
2301
-
2302
- expectKeyword('if');
2303
-
2304
- expect('(');
2305
-
2306
- test = parseExpression();
2307
-
2308
- expect(')');
2309
-
2310
- consequent = parseStatement();
2311
-
2312
- if (matchKeyword('else')) {
2313
- lex();
2314
- alternate = parseStatement();
2315
- } else {
2316
- alternate = null;
2317
- }
2318
-
2319
- return {
2320
- type: Syntax.IfStatement,
2321
- test: test,
2322
- consequent: consequent,
2323
- alternate: alternate
2324
- };
2325
- }
2326
-
2327
- // 12.6 Iteration Statements
2328
-
2329
- function parseDoWhileStatement() {
2330
- var body, test, oldInIteration;
2331
-
2332
- expectKeyword('do');
2333
-
2334
- oldInIteration = state.inIteration;
2335
- state.inIteration = true;
2336
-
2337
- body = parseStatement();
2338
-
2339
- state.inIteration = oldInIteration;
2340
-
2341
- expectKeyword('while');
2342
-
2343
- expect('(');
2344
-
2345
- test = parseExpression();
2346
-
2347
- expect(')');
2348
-
2349
- if (match(';')) {
2350
- lex();
2351
- }
2352
-
2353
- return {
2354
- type: Syntax.DoWhileStatement,
2355
- body: body,
2356
- test: test
2357
- };
2358
- }
2359
-
2360
- function parseWhileStatement() {
2361
- var test, body, oldInIteration;
2362
-
2363
- expectKeyword('while');
2364
-
2365
- expect('(');
2366
-
2367
- test = parseExpression();
2368
-
2369
- expect(')');
2370
-
2371
- oldInIteration = state.inIteration;
2372
- state.inIteration = true;
2373
-
2374
- body = parseStatement();
2375
-
2376
- state.inIteration = oldInIteration;
2377
-
2378
- return {
2379
- type: Syntax.WhileStatement,
2380
- test: test,
2381
- body: body
2382
- };
2383
- }
2384
-
2385
- function parseForVariableDeclaration() {
2386
- var token = lex();
2387
-
2388
- return {
2389
- type: Syntax.VariableDeclaration,
2390
- declarations: parseVariableDeclarationList(),
2391
- kind: token.value
2392
- };
2393
- }
2394
-
2395
- function parseForStatement() {
2396
- var init, test, update, left, right, body, oldInIteration;
2397
-
2398
- init = test = update = null;
2399
-
2400
- expectKeyword('for');
2401
-
2402
- expect('(');
2403
-
2404
- if (match(';')) {
2405
- lex();
2406
- } else {
2407
- if (matchKeyword('var') || matchKeyword('let')) {
2408
- state.allowIn = false;
2409
- init = parseForVariableDeclaration();
2410
- state.allowIn = true;
2411
-
2412
- if (init.declarations.length === 1 && matchKeyword('in')) {
2413
- lex();
2414
- left = init;
2415
- right = parseExpression();
2416
- init = null;
2417
- }
2418
- } else {
2419
- state.allowIn = false;
2420
- init = parseExpression();
2421
- state.allowIn = true;
2422
-
2423
- if (matchKeyword('in')) {
2424
- // LeftHandSideExpression
2425
- if (!isLeftHandSide(init)) {
2426
- throwErrorTolerant({}, Messages.InvalidLHSInForIn);
2427
- }
2428
-
2429
- lex();
2430
- left = init;
2431
- right = parseExpression();
2432
- init = null;
2433
- }
2434
- }
2435
-
2436
- if (typeof left === 'undefined') {
2437
- expect(';');
2438
- }
2439
- }
2440
-
2441
- if (typeof left === 'undefined') {
2442
-
2443
- if (!match(';')) {
2444
- test = parseExpression();
2445
- }
2446
- expect(';');
2447
-
2448
- if (!match(')')) {
2449
- update = parseExpression();
2450
- }
2451
- }
2452
-
2453
- expect(')');
2454
-
2455
- oldInIteration = state.inIteration;
2456
- state.inIteration = true;
2457
-
2458
- body = parseStatement();
2459
-
2460
- state.inIteration = oldInIteration;
2461
-
2462
- if (typeof left === 'undefined') {
2463
- return {
2464
- type: Syntax.ForStatement,
2465
- init: init,
2466
- test: test,
2467
- update: update,
2468
- body: body
2469
- };
2470
- }
2471
-
2472
- return {
2473
- type: Syntax.ForInStatement,
2474
- left: left,
2475
- right: right,
2476
- body: body,
2477
- each: false
2478
- };
2479
- }
2480
-
2481
- // 12.7 The continue statement
2482
-
2483
- function parseContinueStatement() {
2484
- var token, label = null;
2485
-
2486
- expectKeyword('continue');
2487
-
2488
- // Optimize the most common form: 'continue;'.
2489
- if (source[index] === ';') {
2490
- lex();
2491
-
2492
- if (!state.inIteration) {
2493
- throwError({}, Messages.IllegalContinue);
2494
- }
2495
-
2496
- return {
2497
- type: Syntax.ContinueStatement,
2498
- label: null
2499
- };
2500
- }
2501
-
2502
- if (peekLineTerminator()) {
2503
- if (!state.inIteration) {
2504
- throwError({}, Messages.IllegalContinue);
2505
- }
2506
-
2507
- return {
2508
- type: Syntax.ContinueStatement,
2509
- label: null
2510
- };
2511
- }
2512
-
2513
- token = lookahead();
2514
- if (token.type === Token.Identifier) {
2515
- label = parseVariableIdentifier();
2516
-
2517
- if (!Object.prototype.hasOwnProperty.call(state.labelSet, label.name)) {
2518
- throwError({}, Messages.UnknownLabel, label.name);
2519
- }
2520
- }
2521
-
2522
- consumeSemicolon();
2523
-
2524
- if (label === null && !state.inIteration) {
2525
- throwError({}, Messages.IllegalContinue);
2526
- }
2527
-
2528
- return {
2529
- type: Syntax.ContinueStatement,
2530
- label: label
2531
- };
2532
- }
2533
-
2534
- // 12.8 The break statement
2535
-
2536
- function parseBreakStatement() {
2537
- var token, label = null;
2538
-
2539
- expectKeyword('break');
2540
-
2541
- // Optimize the most common form: 'break;'.
2542
- if (source[index] === ';') {
2543
- lex();
2544
-
2545
- if (!(state.inIteration || state.inSwitch)) {
2546
- throwError({}, Messages.IllegalBreak);
2547
- }
2548
-
2549
- return {
2550
- type: Syntax.BreakStatement,
2551
- label: null
2552
- };
2553
- }
2554
-
2555
- if (peekLineTerminator()) {
2556
- if (!(state.inIteration || state.inSwitch)) {
2557
- throwError({}, Messages.IllegalBreak);
2558
- }
2559
-
2560
- return {
2561
- type: Syntax.BreakStatement,
2562
- label: null
2563
- };
2564
- }
2565
-
2566
- token = lookahead();
2567
- if (token.type === Token.Identifier) {
2568
- label = parseVariableIdentifier();
2569
-
2570
- if (!Object.prototype.hasOwnProperty.call(state.labelSet, label.name)) {
2571
- throwError({}, Messages.UnknownLabel, label.name);
2572
- }
2573
- }
2574
-
2575
- consumeSemicolon();
2576
-
2577
- if (label === null && !(state.inIteration || state.inSwitch)) {
2578
- throwError({}, Messages.IllegalBreak);
2579
- }
2580
-
2581
- return {
2582
- type: Syntax.BreakStatement,
2583
- label: label
2584
- };
2585
- }
2586
-
2587
- // 12.9 The return statement
2588
-
2589
- function parseReturnStatement() {
2590
- var token, argument = null;
2591
-
2592
- expectKeyword('return');
2593
-
2594
- if (!state.inFunctionBody) {
2595
- throwErrorTolerant({}, Messages.IllegalReturn);
2596
- }
2597
-
2598
- // 'return' followed by a space and an identifier is very common.
2599
- if (source[index] === ' ') {
2600
- if (isIdentifierStart(source[index + 1])) {
2601
- argument = parseExpression();
2602
- consumeSemicolon();
2603
- return {
2604
- type: Syntax.ReturnStatement,
2605
- argument: argument
2606
- };
2607
- }
2608
- }
2609
-
2610
- if (peekLineTerminator()) {
2611
- return {
2612
- type: Syntax.ReturnStatement,
2613
- argument: null
2614
- };
2615
- }
2616
-
2617
- if (!match(';')) {
2618
- token = lookahead();
2619
- if (!match('}') && token.type !== Token.EOF) {
2620
- argument = parseExpression();
2621
- }
2622
- }
2623
-
2624
- consumeSemicolon();
2625
-
2626
- return {
2627
- type: Syntax.ReturnStatement,
2628
- argument: argument
2629
- };
2630
- }
2631
-
2632
- // 12.10 The with statement
2633
-
2634
- function parseWithStatement() {
2635
- var object, body;
2636
-
2637
- if (strict) {
2638
- throwErrorTolerant({}, Messages.StrictModeWith);
2639
- }
2640
-
2641
- expectKeyword('with');
2642
-
2643
- expect('(');
2644
-
2645
- object = parseExpression();
2646
-
2647
- expect(')');
2648
-
2649
- body = parseStatement();
2650
-
2651
- return {
2652
- type: Syntax.WithStatement,
2653
- object: object,
2654
- body: body
2655
- };
2656
- }
2657
-
2658
- // 12.10 The swith statement
2659
-
2660
- function parseSwitchCase() {
2661
- var test,
2662
- consequent = [],
2663
- statement;
2664
-
2665
- if (matchKeyword('default')) {
2666
- lex();
2667
- test = null;
2668
- } else {
2669
- expectKeyword('case');
2670
- test = parseExpression();
2671
- }
2672
- expect(':');
2673
-
2674
- while (index < length) {
2675
- if (match('}') || matchKeyword('default') || matchKeyword('case')) {
2676
- break;
2677
- }
2678
- statement = parseStatement();
2679
- if (typeof statement === 'undefined') {
2680
- break;
2681
- }
2682
- consequent.push(statement);
2683
- }
2684
-
2685
- return {
2686
- type: Syntax.SwitchCase,
2687
- test: test,
2688
- consequent: consequent
2689
- };
2690
- }
2691
-
2692
- function parseSwitchStatement() {
2693
- var discriminant, cases, clause, oldInSwitch, defaultFound;
2694
-
2695
- expectKeyword('switch');
2696
-
2697
- expect('(');
2698
-
2699
- discriminant = parseExpression();
2700
-
2701
- expect(')');
2702
-
2703
- expect('{');
2704
-
2705
- cases = [];
2706
-
2707
- if (match('}')) {
2708
- lex();
2709
- return {
2710
- type: Syntax.SwitchStatement,
2711
- discriminant: discriminant,
2712
- cases: cases
2713
- };
2714
- }
2715
-
2716
- oldInSwitch = state.inSwitch;
2717
- state.inSwitch = true;
2718
- defaultFound = false;
2719
-
2720
- while (index < length) {
2721
- if (match('}')) {
2722
- break;
2723
- }
2724
- clause = parseSwitchCase();
2725
- if (clause.test === null) {
2726
- if (defaultFound) {
2727
- throwError({}, Messages.MultipleDefaultsInSwitch);
2728
- }
2729
- defaultFound = true;
2730
- }
2731
- cases.push(clause);
2732
- }
2733
-
2734
- state.inSwitch = oldInSwitch;
2735
-
2736
- expect('}');
2737
-
2738
- return {
2739
- type: Syntax.SwitchStatement,
2740
- discriminant: discriminant,
2741
- cases: cases
2742
- };
2743
- }
2744
-
2745
- // 12.13 The throw statement
2746
-
2747
- function parseThrowStatement() {
2748
- var argument;
2749
-
2750
- expectKeyword('throw');
2751
-
2752
- if (peekLineTerminator()) {
2753
- throwError({}, Messages.NewlineAfterThrow);
2754
- }
2755
-
2756
- argument = parseExpression();
2757
-
2758
- consumeSemicolon();
2759
-
2760
- return {
2761
- type: Syntax.ThrowStatement,
2762
- argument: argument
2763
- };
2764
- }
2765
-
2766
- // 12.14 The try statement
2767
-
2768
- function parseCatchClause() {
2769
- var param;
2770
-
2771
- expectKeyword('catch');
2772
-
2773
- expect('(');
2774
- if (match(')')) {
2775
- throwUnexpected(lookahead());
2776
- }
2777
-
2778
- param = parseVariableIdentifier();
2779
- // 12.14.1
2780
- if (strict && isRestrictedWord(param.name)) {
2781
- throwErrorTolerant({}, Messages.StrictCatchVariable);
2782
- }
2783
-
2784
- expect(')');
2785
-
2786
- return {
2787
- type: Syntax.CatchClause,
2788
- param: param,
2789
- body: parseBlock()
2790
- };
2791
- }
2792
-
2793
- function parseTryStatement() {
2794
- var block, handlers = [], finalizer = null;
2795
-
2796
- expectKeyword('try');
2797
-
2798
- block = parseBlock();
2799
-
2800
- if (matchKeyword('catch')) {
2801
- handlers.push(parseCatchClause());
2802
- }
2803
-
2804
- if (matchKeyword('finally')) {
2805
- lex();
2806
- finalizer = parseBlock();
2807
- }
2808
-
2809
- if (handlers.length === 0 && !finalizer) {
2810
- throwError({}, Messages.NoCatchOrFinally);
2811
- }
2812
-
2813
- return {
2814
- type: Syntax.TryStatement,
2815
- block: block,
2816
- guardedHandlers: [],
2817
- handlers: handlers,
2818
- finalizer: finalizer
2819
- };
2820
- }
2821
-
2822
- // 12.15 The debugger statement
2823
-
2824
- function parseDebuggerStatement() {
2825
- expectKeyword('debugger');
2826
-
2827
- consumeSemicolon();
2828
-
2829
- return {
2830
- type: Syntax.DebuggerStatement
2831
- };
2832
- }
2833
-
2834
- // 12 Statements
2835
-
2836
- function parseStatement() {
2837
- var token = lookahead(),
2838
- expr,
2839
- labeledBody;
2840
-
2841
- if (token.type === Token.EOF) {
2842
- throwUnexpected(token);
2843
- }
2844
-
2845
- if (token.type === Token.Punctuator) {
2846
- switch (token.value) {
2847
- case ';':
2848
- return parseEmptyStatement();
2849
- case '{':
2850
- return parseBlock();
2851
- case '(':
2852
- return parseExpressionStatement();
2853
- }
2854
- }
2855
-
2856
- if (token.type === Token.Keyword) {
2857
- switch (token.value) {
2858
- case 'break':
2859
- return parseBreakStatement();
2860
- case 'continue':
2861
- return parseContinueStatement();
2862
- case 'debugger':
2863
- return parseDebuggerStatement();
2864
- case 'do':
2865
- return parseDoWhileStatement();
2866
- case 'for':
2867
- return parseForStatement();
2868
- case 'function':
2869
- return parseFunctionDeclaration();
2870
- case 'if':
2871
- return parseIfStatement();
2872
- case 'return':
2873
- return parseReturnStatement();
2874
- case 'switch':
2875
- return parseSwitchStatement();
2876
- case 'throw':
2877
- return parseThrowStatement();
2878
- case 'try':
2879
- return parseTryStatement();
2880
- case 'var':
2881
- return parseVariableStatement();
2882
- case 'while':
2883
- return parseWhileStatement();
2884
- case 'with':
2885
- return parseWithStatement();
2886
- }
2887
- }
2888
-
2889
- expr = parseExpression();
2890
-
2891
- // 12.12 Labelled Statements
2892
- if ((expr.type === Syntax.Identifier) && match(':')) {
2893
- lex();
2894
-
2895
- if (Object.prototype.hasOwnProperty.call(state.labelSet, expr.name)) {
2896
- throwError({}, Messages.Redeclaration, 'Label', expr.name);
2897
- }
2898
-
2899
- state.labelSet[expr.name] = true;
2900
- labeledBody = parseStatement();
2901
- delete state.labelSet[expr.name];
2902
-
2903
- return {
2904
- type: Syntax.LabeledStatement,
2905
- label: expr,
2906
- body: labeledBody
2907
- };
2908
- }
2909
-
2910
- consumeSemicolon();
2911
-
2912
- return {
2913
- type: Syntax.ExpressionStatement,
2914
- expression: expr
2915
- };
2916
- }
2917
-
2918
- // 13 Function Definition
2919
-
2920
- function parseFunctionSourceElements() {
2921
- var sourceElement, sourceElements = [], token, directive, firstRestricted,
2922
- oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody;
2923
-
2924
- expect('{');
2925
-
2926
- while (index < length) {
2927
- token = lookahead();
2928
- if (token.type !== Token.StringLiteral) {
2929
- break;
2930
- }
2931
-
2932
- sourceElement = parseSourceElement();
2933
- sourceElements.push(sourceElement);
2934
- if (sourceElement.expression.type !== Syntax.Literal) {
2935
- // this is not directive
2936
- break;
2937
- }
2938
- directive = sliceSource(token.range[0] + 1, token.range[1] - 1);
2939
- if (directive === 'use strict') {
2940
- strict = true;
2941
- if (firstRestricted) {
2942
- throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
2943
- }
2944
- } else {
2945
- if (!firstRestricted && token.octal) {
2946
- firstRestricted = token;
2947
- }
2948
- }
2949
- }
2950
-
2951
- oldLabelSet = state.labelSet;
2952
- oldInIteration = state.inIteration;
2953
- oldInSwitch = state.inSwitch;
2954
- oldInFunctionBody = state.inFunctionBody;
2955
-
2956
- state.labelSet = {};
2957
- state.inIteration = false;
2958
- state.inSwitch = false;
2959
- state.inFunctionBody = true;
2960
-
2961
- while (index < length) {
2962
- if (match('}')) {
2963
- break;
2964
- }
2965
- sourceElement = parseSourceElement();
2966
- if (typeof sourceElement === 'undefined') {
2967
- break;
2968
- }
2969
- sourceElements.push(sourceElement);
2970
- }
2971
-
2972
- expect('}');
2973
-
2974
- state.labelSet = oldLabelSet;
2975
- state.inIteration = oldInIteration;
2976
- state.inSwitch = oldInSwitch;
2977
- state.inFunctionBody = oldInFunctionBody;
2978
-
2979
- return {
2980
- type: Syntax.BlockStatement,
2981
- body: sourceElements
2982
- };
2983
- }
2984
-
2985
- function parseFunctionDeclaration() {
2986
- var id, param, params = [], body, token, stricted, firstRestricted, message, previousStrict, paramSet;
2987
-
2988
- expectKeyword('function');
2989
- token = lookahead();
2990
- id = parseVariableIdentifier();
2991
- if (strict) {
2992
- if (isRestrictedWord(token.value)) {
2993
- throwErrorTolerant(token, Messages.StrictFunctionName);
2994
- }
2995
- } else {
2996
- if (isRestrictedWord(token.value)) {
2997
- firstRestricted = token;
2998
- message = Messages.StrictFunctionName;
2999
- } else if (isStrictModeReservedWord(token.value)) {
3000
- firstRestricted = token;
3001
- message = Messages.StrictReservedWord;
3002
- }
3003
- }
3004
-
3005
- expect('(');
3006
-
3007
- if (!match(')')) {
3008
- paramSet = {};
3009
- while (index < length) {
3010
- token = lookahead();
3011
- param = parseVariableIdentifier();
3012
- if (strict) {
3013
- if (isRestrictedWord(token.value)) {
3014
- stricted = token;
3015
- message = Messages.StrictParamName;
3016
- }
3017
- if (Object.prototype.hasOwnProperty.call(paramSet, token.value)) {
3018
- stricted = token;
3019
- message = Messages.StrictParamDupe;
3020
- }
3021
- } else if (!firstRestricted) {
3022
- if (isRestrictedWord(token.value)) {
3023
- firstRestricted = token;
3024
- message = Messages.StrictParamName;
3025
- } else if (isStrictModeReservedWord(token.value)) {
3026
- firstRestricted = token;
3027
- message = Messages.StrictReservedWord;
3028
- } else if (Object.prototype.hasOwnProperty.call(paramSet, token.value)) {
3029
- firstRestricted = token;
3030
- message = Messages.StrictParamDupe;
3031
- }
3032
- }
3033
- params.push(param);
3034
- paramSet[param.name] = true;
3035
- if (match(')')) {
3036
- break;
3037
- }
3038
- expect(',');
3039
- }
3040
- }
3041
-
3042
- expect(')');
3043
-
3044
- previousStrict = strict;
3045
- body = parseFunctionSourceElements();
3046
- if (strict && firstRestricted) {
3047
- throwError(firstRestricted, message);
3048
- }
3049
- if (strict && stricted) {
3050
- throwErrorTolerant(stricted, message);
3051
- }
3052
- strict = previousStrict;
3053
-
3054
- return {
3055
- type: Syntax.FunctionDeclaration,
3056
- id: id,
3057
- params: params,
3058
- defaults: [],
3059
- body: body,
3060
- rest: null,
3061
- generator: false,
3062
- expression: false
3063
- };
3064
- }
3065
-
3066
- function parseFunctionExpression() {
3067
- var token, id = null, stricted, firstRestricted, message, param, params = [], body, previousStrict, paramSet;
3068
-
3069
- expectKeyword('function');
3070
-
3071
- if (!match('(')) {
3072
- token = lookahead();
3073
- id = parseVariableIdentifier();
3074
- if (strict) {
3075
- if (isRestrictedWord(token.value)) {
3076
- throwErrorTolerant(token, Messages.StrictFunctionName);
3077
- }
3078
- } else {
3079
- if (isRestrictedWord(token.value)) {
3080
- firstRestricted = token;
3081
- message = Messages.StrictFunctionName;
3082
- } else if (isStrictModeReservedWord(token.value)) {
3083
- firstRestricted = token;
3084
- message = Messages.StrictReservedWord;
3085
- }
3086
- }
3087
- }
3088
-
3089
- expect('(');
3090
-
3091
- if (!match(')')) {
3092
- paramSet = {};
3093
- while (index < length) {
3094
- token = lookahead();
3095
- param = parseVariableIdentifier();
3096
- if (strict) {
3097
- if (isRestrictedWord(token.value)) {
3098
- stricted = token;
3099
- message = Messages.StrictParamName;
3100
- }
3101
- if (Object.prototype.hasOwnProperty.call(paramSet, token.value)) {
3102
- stricted = token;
3103
- message = Messages.StrictParamDupe;
3104
- }
3105
- } else if (!firstRestricted) {
3106
- if (isRestrictedWord(token.value)) {
3107
- firstRestricted = token;
3108
- message = Messages.StrictParamName;
3109
- } else if (isStrictModeReservedWord(token.value)) {
3110
- firstRestricted = token;
3111
- message = Messages.StrictReservedWord;
3112
- } else if (Object.prototype.hasOwnProperty.call(paramSet, token.value)) {
3113
- firstRestricted = token;
3114
- message = Messages.StrictParamDupe;
3115
- }
3116
- }
3117
- params.push(param);
3118
- paramSet[param.name] = true;
3119
- if (match(')')) {
3120
- break;
3121
- }
3122
- expect(',');
3123
- }
3124
- }
3125
-
3126
- expect(')');
3127
-
3128
- previousStrict = strict;
3129
- body = parseFunctionSourceElements();
3130
- if (strict && firstRestricted) {
3131
- throwError(firstRestricted, message);
3132
- }
3133
- if (strict && stricted) {
3134
- throwErrorTolerant(stricted, message);
3135
- }
3136
- strict = previousStrict;
3137
-
3138
- return {
3139
- type: Syntax.FunctionExpression,
3140
- id: id,
3141
- params: params,
3142
- defaults: [],
3143
- body: body,
3144
- rest: null,
3145
- generator: false,
3146
- expression: false
3147
- };
3148
- }
3149
-
3150
- // 14 Program
3151
-
3152
- function parseSourceElement() {
3153
- var token = lookahead();
3154
-
3155
- if (token.type === Token.Keyword) {
3156
- switch (token.value) {
3157
- case 'const':
3158
- case 'let':
3159
- return parseConstLetDeclaration(token.value);
3160
- case 'function':
3161
- return parseFunctionDeclaration();
3162
- default:
3163
- return parseStatement();
3164
- }
3165
- }
3166
-
3167
- if (token.type !== Token.EOF) {
3168
- return parseStatement();
3169
- }
3170
- }
3171
-
3172
- function parseSourceElements() {
3173
- var sourceElement, sourceElements = [], token, directive, firstRestricted;
3174
-
3175
- while (index < length) {
3176
- token = lookahead();
3177
- if (token.type !== Token.StringLiteral) {
3178
- break;
3179
- }
3180
-
3181
- sourceElement = parseSourceElement();
3182
- sourceElements.push(sourceElement);
3183
- if (sourceElement.expression.type !== Syntax.Literal) {
3184
- // this is not directive
3185
- break;
3186
- }
3187
- directive = sliceSource(token.range[0] + 1, token.range[1] - 1);
3188
- if (directive === 'use strict') {
3189
- strict = true;
3190
- if (firstRestricted) {
3191
- throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
3192
- }
3193
- } else {
3194
- if (!firstRestricted && token.octal) {
3195
- firstRestricted = token;
3196
- }
3197
- }
3198
- }
3199
-
3200
- while (index < length) {
3201
- sourceElement = parseSourceElement();
3202
- if (typeof sourceElement === 'undefined') {
3203
- break;
3204
- }
3205
- sourceElements.push(sourceElement);
3206
- }
3207
- return sourceElements;
3208
- }
3209
-
3210
- function parseProgram() {
3211
- var program;
3212
- strict = false;
3213
- program = {
3214
- type: Syntax.Program,
3215
- body: parseSourceElements()
3216
- };
3217
- return program;
3218
- }
3219
-
3220
- // The following functions are needed only when the option to preserve
3221
- // the comments is active.
3222
-
3223
- function addComment(type, value, start, end, loc) {
3224
- assert(typeof start === 'number', 'Comment must have valid position');
3225
-
3226
- // Because the way the actual token is scanned, often the comments
3227
- // (if any) are skipped twice during the lexical analysis.
3228
- // Thus, we need to skip adding a comment if the comment array already
3229
- // handled it.
3230
- if (extra.comments.length > 0) {
3231
- if (extra.comments[extra.comments.length - 1].range[1] > start) {
3232
- return;
3233
- }
3234
- }
3235
-
3236
- extra.comments.push({
3237
- type: type,
3238
- value: value,
3239
- range: [start, end],
3240
- loc: loc
3241
- });
3242
- }
3243
-
3244
- function scanComment() {
3245
- var comment, ch, loc, start, blockComment, lineComment;
3246
-
3247
- comment = '';
3248
- blockComment = false;
3249
- lineComment = false;
3250
-
3251
- while (index < length) {
3252
- ch = source[index];
3253
-
3254
- if (lineComment) {
3255
- ch = source[index++];
3256
- if (isLineTerminator(ch)) {
3257
- loc.end = {
3258
- line: lineNumber,
3259
- column: index - lineStart - 1
3260
- };
3261
- lineComment = false;
3262
- addComment('Line', comment, start, index - 1, loc);
3263
- if (ch === '\r' && source[index] === '\n') {
3264
- ++index;
3265
- }
3266
- ++lineNumber;
3267
- lineStart = index;
3268
- comment = '';
3269
- } else if (index >= length) {
3270
- lineComment = false;
3271
- comment += ch;
3272
- loc.end = {
3273
- line: lineNumber,
3274
- column: length - lineStart
3275
- };
3276
- addComment('Line', comment, start, length, loc);
3277
- } else {
3278
- comment += ch;
3279
- }
3280
- } else if (blockComment) {
3281
- if (isLineTerminator(ch)) {
3282
- if (ch === '\r' && source[index + 1] === '\n') {
3283
- ++index;
3284
- comment += '\r\n';
3285
- } else {
3286
- comment += ch;
3287
- }
3288
- ++lineNumber;
3289
- ++index;
3290
- lineStart = index;
3291
- if (index >= length) {
3292
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
3293
- }
3294
- } else {
3295
- ch = source[index++];
3296
- if (index >= length) {
3297
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
3298
- }
3299
- comment += ch;
3300
- if (ch === '*') {
3301
- ch = source[index];
3302
- if (ch === '/') {
3303
- comment = comment.substr(0, comment.length - 1);
3304
- blockComment = false;
3305
- ++index;
3306
- loc.end = {
3307
- line: lineNumber,
3308
- column: index - lineStart
3309
- };
3310
- addComment('Block', comment, start, index, loc);
3311
- comment = '';
3312
- }
3313
- }
3314
- }
3315
- } else if (ch === '/') {
3316
- ch = source[index + 1];
3317
- if (ch === '/') {
3318
- loc = {
3319
- start: {
3320
- line: lineNumber,
3321
- column: index - lineStart
3322
- }
3323
- };
3324
- start = index;
3325
- index += 2;
3326
- lineComment = true;
3327
- if (index >= length) {
3328
- loc.end = {
3329
- line: lineNumber,
3330
- column: index - lineStart
3331
- };
3332
- lineComment = false;
3333
- addComment('Line', comment, start, index, loc);
3334
- }
3335
- } else if (ch === '*') {
3336
- start = index;
3337
- index += 2;
3338
- blockComment = true;
3339
- loc = {
3340
- start: {
3341
- line: lineNumber,
3342
- column: index - lineStart - 2
3343
- }
3344
- };
3345
- if (index >= length) {
3346
- throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
3347
- }
3348
- } else {
3349
- break;
3350
- }
3351
- } else if (isWhiteSpace(ch)) {
3352
- ++index;
3353
- } else if (isLineTerminator(ch)) {
3354
- ++index;
3355
- if (ch === '\r' && source[index] === '\n') {
3356
- ++index;
3357
- }
3358
- ++lineNumber;
3359
- lineStart = index;
3360
- } else {
3361
- break;
3362
- }
3363
- }
3364
- }
3365
-
3366
- function filterCommentLocation() {
3367
- var i, entry, comment, comments = [];
3368
-
3369
- for (i = 0; i < extra.comments.length; ++i) {
3370
- entry = extra.comments[i];
3371
- comment = {
3372
- type: entry.type,
3373
- value: entry.value
3374
- };
3375
- if (extra.range) {
3376
- comment.range = entry.range;
3377
- }
3378
- if (extra.loc) {
3379
- comment.loc = entry.loc;
3380
- }
3381
- comments.push(comment);
3382
- }
3383
-
3384
- extra.comments = comments;
3385
- }
3386
-
3387
- function collectToken() {
3388
- var loc, token, range, value;
3389
-
3390
- skipComment();
3391
- loc = {
3392
- start: {
3393
- line: lineNumber,
3394
- column: index - lineStart
3395
- }
3396
- };
3397
-
3398
- token = extra.advance();
3399
- loc.end = {
3400
- line: lineNumber,
3401
- column: index - lineStart
3402
- };
3403
-
3404
- if (token.type !== Token.EOF) {
3405
- range = [token.range[0], token.range[1]];
3406
- value = sliceSource(token.range[0], token.range[1]);
3407
- extra.tokens.push({
3408
- type: TokenName[token.type],
3409
- value: value,
3410
- range: range,
3411
- loc: loc
3412
- });
3413
- }
3414
-
3415
- return token;
3416
- }
3417
-
3418
- function collectRegex() {
3419
- var pos, loc, regex, token;
3420
-
3421
- skipComment();
3422
-
3423
- pos = index;
3424
- loc = {
3425
- start: {
3426
- line: lineNumber,
3427
- column: index - lineStart
3428
- }
3429
- };
3430
-
3431
- regex = extra.scanRegExp();
3432
- loc.end = {
3433
- line: lineNumber,
3434
- column: index - lineStart
3435
- };
3436
-
3437
- // Pop the previous token, which is likely '/' or '/='
3438
- if (extra.tokens.length > 0) {
3439
- token = extra.tokens[extra.tokens.length - 1];
3440
- if (token.range[0] === pos && token.type === 'Punctuator') {
3441
- if (token.value === '/' || token.value === '/=') {
3442
- extra.tokens.pop();
3443
- }
3444
- }
3445
- }
3446
-
3447
- extra.tokens.push({
3448
- type: 'RegularExpression',
3449
- value: regex.literal,
3450
- range: [pos, index],
3451
- loc: loc
3452
- });
3453
-
3454
- return regex;
3455
- }
3456
-
3457
- function filterTokenLocation() {
3458
- var i, entry, token, tokens = [];
3459
-
3460
- for (i = 0; i < extra.tokens.length; ++i) {
3461
- entry = extra.tokens[i];
3462
- token = {
3463
- type: entry.type,
3464
- value: entry.value
3465
- };
3466
- if (extra.range) {
3467
- token.range = entry.range;
3468
- }
3469
- if (extra.loc) {
3470
- token.loc = entry.loc;
3471
- }
3472
- tokens.push(token);
3473
- }
3474
-
3475
- extra.tokens = tokens;
3476
- }
3477
-
3478
- function createLiteral(token) {
3479
- return {
3480
- type: Syntax.Literal,
3481
- value: token.value
3482
- };
3483
- }
3484
-
3485
- function createRawLiteral(token) {
3486
- return {
3487
- type: Syntax.Literal,
3488
- value: token.value,
3489
- raw: sliceSource(token.range[0], token.range[1])
3490
- };
3491
- }
3492
-
3493
- function createLocationMarker() {
3494
- var marker = {};
3495
-
3496
- marker.range = [index, index];
3497
- marker.loc = {
3498
- start: {
3499
- line: lineNumber,
3500
- column: index - lineStart
3501
- },
3502
- end: {
3503
- line: lineNumber,
3504
- column: index - lineStart
3505
- }
3506
- };
3507
-
3508
- marker.end = function () {
3509
- this.range[1] = index;
3510
- this.loc.end.line = lineNumber;
3511
- this.loc.end.column = index - lineStart;
3512
- };
3513
-
3514
- marker.applyGroup = function (node) {
3515
- if (extra.range) {
3516
- node.groupRange = [this.range[0], this.range[1]];
3517
- }
3518
- if (extra.loc) {
3519
- node.groupLoc = {
3520
- start: {
3521
- line: this.loc.start.line,
3522
- column: this.loc.start.column
3523
- },
3524
- end: {
3525
- line: this.loc.end.line,
3526
- column: this.loc.end.column
3527
- }
3528
- };
3529
- }
3530
- };
3531
-
3532
- marker.apply = function (node) {
3533
- if (extra.range) {
3534
- node.range = [this.range[0], this.range[1]];
3535
- }
3536
- if (extra.loc) {
3537
- node.loc = {
3538
- start: {
3539
- line: this.loc.start.line,
3540
- column: this.loc.start.column
3541
- },
3542
- end: {
3543
- line: this.loc.end.line,
3544
- column: this.loc.end.column
3545
- }
3546
- };
3547
- }
3548
- };
3549
-
3550
- return marker;
3551
- }
3552
-
3553
- function trackGroupExpression() {
3554
- var marker, expr;
3555
-
3556
- skipComment();
3557
- marker = createLocationMarker();
3558
- expect('(');
3559
-
3560
- expr = parseExpression();
3561
-
3562
- expect(')');
3563
-
3564
- marker.end();
3565
- marker.applyGroup(expr);
3566
-
3567
- return expr;
3568
- }
3569
-
3570
- function trackLeftHandSideExpression() {
3571
- var marker, expr;
3572
-
3573
- skipComment();
3574
- marker = createLocationMarker();
3575
-
3576
- expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
3577
-
3578
- while (match('.') || match('[')) {
3579
- if (match('[')) {
3580
- expr = {
3581
- type: Syntax.MemberExpression,
3582
- computed: true,
3583
- object: expr,
3584
- property: parseComputedMember()
3585
- };
3586
- marker.end();
3587
- marker.apply(expr);
3588
- } else {
3589
- expr = {
3590
- type: Syntax.MemberExpression,
3591
- computed: false,
3592
- object: expr,
3593
- property: parseNonComputedMember()
3594
- };
3595
- marker.end();
3596
- marker.apply(expr);
3597
- }
3598
- }
3599
-
3600
- return expr;
3601
- }
3602
-
3603
- function trackLeftHandSideExpressionAllowCall() {
3604
- var marker, expr;
3605
-
3606
- skipComment();
3607
- marker = createLocationMarker();
3608
-
3609
- expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
3610
-
3611
- while (match('.') || match('[') || match('(')) {
3612
- if (match('(')) {
3613
- expr = {
3614
- type: Syntax.CallExpression,
3615
- callee: expr,
3616
- 'arguments': parseArguments()
3617
- };
3618
- marker.end();
3619
- marker.apply(expr);
3620
- } else if (match('[')) {
3621
- expr = {
3622
- type: Syntax.MemberExpression,
3623
- computed: true,
3624
- object: expr,
3625
- property: parseComputedMember()
3626
- };
3627
- marker.end();
3628
- marker.apply(expr);
3629
- } else {
3630
- expr = {
3631
- type: Syntax.MemberExpression,
3632
- computed: false,
3633
- object: expr,
3634
- property: parseNonComputedMember()
3635
- };
3636
- marker.end();
3637
- marker.apply(expr);
3638
- }
3639
- }
3640
-
3641
- return expr;
3642
- }
3643
-
3644
- function filterGroup(node) {
3645
- var n, i, entry;
3646
-
3647
- n = (Object.prototype.toString.apply(node) === '[object Array]') ? [] : {};
3648
- for (i in node) {
3649
- if (node.hasOwnProperty(i) && i !== 'groupRange' && i !== 'groupLoc') {
3650
- entry = node[i];
3651
- if (entry === null || typeof entry !== 'object' || entry instanceof RegExp) {
3652
- n[i] = entry;
3653
- } else {
3654
- n[i] = filterGroup(entry);
3655
- }
3656
- }
3657
- }
3658
- return n;
3659
- }
3660
-
3661
- function wrapTrackingFunction(range, loc) {
3662
-
3663
- return function (parseFunction) {
3664
-
3665
- function isBinary(node) {
3666
- return node.type === Syntax.LogicalExpression ||
3667
- node.type === Syntax.BinaryExpression;
3668
- }
3669
-
3670
- function visit(node) {
3671
- var start, end;
3672
-
3673
- if (isBinary(node.left)) {
3674
- visit(node.left);
3675
- }
3676
- if (isBinary(node.right)) {
3677
- visit(node.right);
3678
- }
3679
-
3680
- if (range) {
3681
- if (node.left.groupRange || node.right.groupRange) {
3682
- start = node.left.groupRange ? node.left.groupRange[0] : node.left.range[0];
3683
- end = node.right.groupRange ? node.right.groupRange[1] : node.right.range[1];
3684
- node.range = [start, end];
3685
- } else if (typeof node.range === 'undefined') {
3686
- start = node.left.range[0];
3687
- end = node.right.range[1];
3688
- node.range = [start, end];
3689
- }
3690
- }
3691
- if (loc) {
3692
- if (node.left.groupLoc || node.right.groupLoc) {
3693
- start = node.left.groupLoc ? node.left.groupLoc.start : node.left.loc.start;
3694
- end = node.right.groupLoc ? node.right.groupLoc.end : node.right.loc.end;
3695
- node.loc = {
3696
- start: start,
3697
- end: end
3698
- };
3699
- } else if (typeof node.loc === 'undefined') {
3700
- node.loc = {
3701
- start: node.left.loc.start,
3702
- end: node.right.loc.end
3703
- };
3704
- }
3705
- }
3706
- }
3707
-
3708
- return function () {
3709
- var marker, node;
3710
-
3711
- skipComment();
3712
-
3713
- marker = createLocationMarker();
3714
- node = parseFunction.apply(null, arguments);
3715
- marker.end();
3716
-
3717
- if (range && typeof node.range === 'undefined') {
3718
- marker.apply(node);
3719
- }
3720
-
3721
- if (loc && typeof node.loc === 'undefined') {
3722
- marker.apply(node);
3723
- }
3724
-
3725
- if (isBinary(node)) {
3726
- visit(node);
3727
- }
3728
-
3729
- return node;
3730
- };
3731
- };
3732
- }
3733
-
3734
- function patch() {
3735
-
3736
- var wrapTracking;
3737
-
3738
- if (extra.comments) {
3739
- extra.skipComment = skipComment;
3740
- skipComment = scanComment;
3741
- }
3742
-
3743
- if (extra.raw) {
3744
- extra.createLiteral = createLiteral;
3745
- createLiteral = createRawLiteral;
3746
- }
3747
-
3748
- if (extra.range || extra.loc) {
3749
-
3750
- extra.parseGroupExpression = parseGroupExpression;
3751
- extra.parseLeftHandSideExpression = parseLeftHandSideExpression;
3752
- extra.parseLeftHandSideExpressionAllowCall = parseLeftHandSideExpressionAllowCall;
3753
- parseGroupExpression = trackGroupExpression;
3754
- parseLeftHandSideExpression = trackLeftHandSideExpression;
3755
- parseLeftHandSideExpressionAllowCall = trackLeftHandSideExpressionAllowCall;
3756
-
3757
- wrapTracking = wrapTrackingFunction(extra.range, extra.loc);
3758
-
3759
- extra.parseAdditiveExpression = parseAdditiveExpression;
3760
- extra.parseAssignmentExpression = parseAssignmentExpression;
3761
- extra.parseBitwiseANDExpression = parseBitwiseANDExpression;
3762
- extra.parseBitwiseORExpression = parseBitwiseORExpression;
3763
- extra.parseBitwiseXORExpression = parseBitwiseXORExpression;
3764
- extra.parseBlock = parseBlock;
3765
- extra.parseFunctionSourceElements = parseFunctionSourceElements;
3766
- extra.parseCatchClause = parseCatchClause;
3767
- extra.parseComputedMember = parseComputedMember;
3768
- extra.parseConditionalExpression = parseConditionalExpression;
3769
- extra.parseConstLetDeclaration = parseConstLetDeclaration;
3770
- extra.parseEqualityExpression = parseEqualityExpression;
3771
- extra.parseExpression = parseExpression;
3772
- extra.parseForVariableDeclaration = parseForVariableDeclaration;
3773
- extra.parseFunctionDeclaration = parseFunctionDeclaration;
3774
- extra.parseFunctionExpression = parseFunctionExpression;
3775
- extra.parseLogicalANDExpression = parseLogicalANDExpression;
3776
- extra.parseLogicalORExpression = parseLogicalORExpression;
3777
- extra.parseMultiplicativeExpression = parseMultiplicativeExpression;
3778
- extra.parseNewExpression = parseNewExpression;
3779
- extra.parseNonComputedProperty = parseNonComputedProperty;
3780
- extra.parseObjectProperty = parseObjectProperty;
3781
- extra.parseObjectPropertyKey = parseObjectPropertyKey;
3782
- extra.parsePostfixExpression = parsePostfixExpression;
3783
- extra.parsePrimaryExpression = parsePrimaryExpression;
3784
- extra.parseProgram = parseProgram;
3785
- extra.parsePropertyFunction = parsePropertyFunction;
3786
- extra.parseRelationalExpression = parseRelationalExpression;
3787
- extra.parseStatement = parseStatement;
3788
- extra.parseShiftExpression = parseShiftExpression;
3789
- extra.parseSwitchCase = parseSwitchCase;
3790
- extra.parseUnaryExpression = parseUnaryExpression;
3791
- extra.parseVariableDeclaration = parseVariableDeclaration;
3792
- extra.parseVariableIdentifier = parseVariableIdentifier;
3793
-
3794
- parseAdditiveExpression = wrapTracking(extra.parseAdditiveExpression);
3795
- parseAssignmentExpression = wrapTracking(extra.parseAssignmentExpression);
3796
- parseBitwiseANDExpression = wrapTracking(extra.parseBitwiseANDExpression);
3797
- parseBitwiseORExpression = wrapTracking(extra.parseBitwiseORExpression);
3798
- parseBitwiseXORExpression = wrapTracking(extra.parseBitwiseXORExpression);
3799
- parseBlock = wrapTracking(extra.parseBlock);
3800
- parseFunctionSourceElements = wrapTracking(extra.parseFunctionSourceElements);
3801
- parseCatchClause = wrapTracking(extra.parseCatchClause);
3802
- parseComputedMember = wrapTracking(extra.parseComputedMember);
3803
- parseConditionalExpression = wrapTracking(extra.parseConditionalExpression);
3804
- parseConstLetDeclaration = wrapTracking(extra.parseConstLetDeclaration);
3805
- parseEqualityExpression = wrapTracking(extra.parseEqualityExpression);
3806
- parseExpression = wrapTracking(extra.parseExpression);
3807
- parseForVariableDeclaration = wrapTracking(extra.parseForVariableDeclaration);
3808
- parseFunctionDeclaration = wrapTracking(extra.parseFunctionDeclaration);
3809
- parseFunctionExpression = wrapTracking(extra.parseFunctionExpression);
3810
- parseLeftHandSideExpression = wrapTracking(parseLeftHandSideExpression);
3811
- parseLogicalANDExpression = wrapTracking(extra.parseLogicalANDExpression);
3812
- parseLogicalORExpression = wrapTracking(extra.parseLogicalORExpression);
3813
- parseMultiplicativeExpression = wrapTracking(extra.parseMultiplicativeExpression);
3814
- parseNewExpression = wrapTracking(extra.parseNewExpression);
3815
- parseNonComputedProperty = wrapTracking(extra.parseNonComputedProperty);
3816
- parseObjectProperty = wrapTracking(extra.parseObjectProperty);
3817
- parseObjectPropertyKey = wrapTracking(extra.parseObjectPropertyKey);
3818
- parsePostfixExpression = wrapTracking(extra.parsePostfixExpression);
3819
- parsePrimaryExpression = wrapTracking(extra.parsePrimaryExpression);
3820
- parseProgram = wrapTracking(extra.parseProgram);
3821
- parsePropertyFunction = wrapTracking(extra.parsePropertyFunction);
3822
- parseRelationalExpression = wrapTracking(extra.parseRelationalExpression);
3823
- parseStatement = wrapTracking(extra.parseStatement);
3824
- parseShiftExpression = wrapTracking(extra.parseShiftExpression);
3825
- parseSwitchCase = wrapTracking(extra.parseSwitchCase);
3826
- parseUnaryExpression = wrapTracking(extra.parseUnaryExpression);
3827
- parseVariableDeclaration = wrapTracking(extra.parseVariableDeclaration);
3828
- parseVariableIdentifier = wrapTracking(extra.parseVariableIdentifier);
3829
- }
3830
-
3831
- if (typeof extra.tokens !== 'undefined') {
3832
- extra.advance = advance;
3833
- extra.scanRegExp = scanRegExp;
3834
-
3835
- advance = collectToken;
3836
- scanRegExp = collectRegex;
3837
- }
3838
- }
3839
-
3840
- function unpatch() {
3841
- if (typeof extra.skipComment === 'function') {
3842
- skipComment = extra.skipComment;
3843
- }
3844
-
3845
- if (extra.raw) {
3846
- createLiteral = extra.createLiteral;
3847
- }
3848
-
3849
- if (extra.range || extra.loc) {
3850
- parseAdditiveExpression = extra.parseAdditiveExpression;
3851
- parseAssignmentExpression = extra.parseAssignmentExpression;
3852
- parseBitwiseANDExpression = extra.parseBitwiseANDExpression;
3853
- parseBitwiseORExpression = extra.parseBitwiseORExpression;
3854
- parseBitwiseXORExpression = extra.parseBitwiseXORExpression;
3855
- parseBlock = extra.parseBlock;
3856
- parseFunctionSourceElements = extra.parseFunctionSourceElements;
3857
- parseCatchClause = extra.parseCatchClause;
3858
- parseComputedMember = extra.parseComputedMember;
3859
- parseConditionalExpression = extra.parseConditionalExpression;
3860
- parseConstLetDeclaration = extra.parseConstLetDeclaration;
3861
- parseEqualityExpression = extra.parseEqualityExpression;
3862
- parseExpression = extra.parseExpression;
3863
- parseForVariableDeclaration = extra.parseForVariableDeclaration;
3864
- parseFunctionDeclaration = extra.parseFunctionDeclaration;
3865
- parseFunctionExpression = extra.parseFunctionExpression;
3866
- parseGroupExpression = extra.parseGroupExpression;
3867
- parseLeftHandSideExpression = extra.parseLeftHandSideExpression;
3868
- parseLeftHandSideExpressionAllowCall = extra.parseLeftHandSideExpressionAllowCall;
3869
- parseLogicalANDExpression = extra.parseLogicalANDExpression;
3870
- parseLogicalORExpression = extra.parseLogicalORExpression;
3871
- parseMultiplicativeExpression = extra.parseMultiplicativeExpression;
3872
- parseNewExpression = extra.parseNewExpression;
3873
- parseNonComputedProperty = extra.parseNonComputedProperty;
3874
- parseObjectProperty = extra.parseObjectProperty;
3875
- parseObjectPropertyKey = extra.parseObjectPropertyKey;
3876
- parsePrimaryExpression = extra.parsePrimaryExpression;
3877
- parsePostfixExpression = extra.parsePostfixExpression;
3878
- parseProgram = extra.parseProgram;
3879
- parsePropertyFunction = extra.parsePropertyFunction;
3880
- parseRelationalExpression = extra.parseRelationalExpression;
3881
- parseStatement = extra.parseStatement;
3882
- parseShiftExpression = extra.parseShiftExpression;
3883
- parseSwitchCase = extra.parseSwitchCase;
3884
- parseUnaryExpression = extra.parseUnaryExpression;
3885
- parseVariableDeclaration = extra.parseVariableDeclaration;
3886
- parseVariableIdentifier = extra.parseVariableIdentifier;
3887
- }
3888
-
3889
- if (typeof extra.scanRegExp === 'function') {
3890
- advance = extra.advance;
3891
- scanRegExp = extra.scanRegExp;
3892
- }
3893
- }
3894
-
3895
- function stringToArray(str) {
3896
- var length = str.length,
3897
- result = [],
3898
- i;
3899
- for (i = 0; i < length; ++i) {
3900
- result[i] = str.charAt(i);
3901
- }
3902
- return result;
3903
- }
3904
-
3905
- function parse(code, options) {
3906
- var program, toString;
3907
-
3908
- toString = String;
3909
- if (typeof code !== 'string' && !(code instanceof String)) {
3910
- code = toString(code);
3911
- }
3912
-
3913
- source = code;
3914
- index = 0;
3915
- lineNumber = (source.length > 0) ? 1 : 0;
3916
- lineStart = 0;
3917
- length = source.length;
3918
- buffer = null;
3919
- state = {
3920
- allowIn: true,
3921
- labelSet: {},
3922
- inFunctionBody: false,
3923
- inIteration: false,
3924
- inSwitch: false
3925
- };
3926
-
3927
- extra = {};
3928
- if (typeof options !== 'undefined') {
3929
- extra.range = (typeof options.range === 'boolean') && options.range;
3930
- extra.loc = (typeof options.loc === 'boolean') && options.loc;
3931
- extra.raw = (typeof options.raw === 'boolean') && options.raw;
3932
- if (typeof options.tokens === 'boolean' && options.tokens) {
3933
- extra.tokens = [];
3934
- }
3935
- if (typeof options.comment === 'boolean' && options.comment) {
3936
- extra.comments = [];
3937
- }
3938
- if (typeof options.tolerant === 'boolean' && options.tolerant) {
3939
- extra.errors = [];
3940
- }
3941
- }
3942
-
3943
- if (length > 0) {
3944
- if (typeof source[0] === 'undefined') {
3945
- // Try first to convert to a string. This is good as fast path
3946
- // for old IE which understands string indexing for string
3947
- // literals only and not for string object.
3948
- if (code instanceof String) {
3949
- source = code.valueOf();
3950
- }
3951
-
3952
- // Force accessing the characters via an array.
3953
- if (typeof source[0] === 'undefined') {
3954
- source = stringToArray(code);
3955
- }
3956
- }
3957
- }
3958
-
3959
- patch();
3960
- try {
3961
- program = parseProgram();
3962
- if (typeof extra.comments !== 'undefined') {
3963
- filterCommentLocation();
3964
- program.comments = extra.comments;
3965
- }
3966
- if (typeof extra.tokens !== 'undefined') {
3967
- filterTokenLocation();
3968
- program.tokens = extra.tokens;
3969
- }
3970
- if (typeof extra.errors !== 'undefined') {
3971
- program.errors = extra.errors;
3972
- }
3973
- if (extra.range || extra.loc) {
3974
- program.body = filterGroup(program.body);
3975
- }
3976
- } catch (e) {
3977
- throw e;
3978
- } finally {
3979
- unpatch();
3980
- extra = {};
3981
- }
3982
-
3983
- return program;
3984
- }
3985
-
3986
- // Sync with package.json.
3987
- exports.version = '1.0.4';
3988
-
3989
- exports.parse = parse;
3990
-
3991
- // Deep copy.
3992
- exports.Syntax = (function () {
3993
- var name, types = {};
3994
-
3995
- if (typeof Object.create === 'function') {
3996
- types = Object.create(null);
3997
- }
3998
-
3999
- for (name in Syntax) {
4000
- if (Syntax.hasOwnProperty(name)) {
4001
- types[name] = Syntax[name];
4002
- }
4003
- }
4004
-
4005
- if (typeof Object.freeze === 'function') {
4006
- Object.freeze(types);
4007
- }
4008
-
4009
- return types;
4010
- }());
4011
-
4012
- }));
4013
- /* vim: set sw=4 ts=4 et tw=80 : */
4014
- });
4015
-
4016
- var hoister = hoist;
4017
-
4018
- function hoist(ast){
4019
-
4020
- var parentStack = [];
4021
- var variables = [];
4022
- var functions = [];
4023
-
4024
- if (Array.isArray(ast)){
4025
-
4026
- walkAll(ast);
4027
- prependScope(ast, variables, functions);
4028
-
4029
- } else {
4030
- walk(ast);
4031
- }
4032
-
4033
- return ast
4034
-
4035
- // walk through each node of a program of block statement
4036
- function walkAll(nodes){
4037
- var result = null;
4038
- for (var i=0;i<nodes.length;i++){
4039
- var childNode = nodes[i];
4040
- if (childNode.type === 'EmptyStatement') continue
4041
- var result = walk(childNode);
4042
- if (result === 'remove'){
4043
- nodes.splice(i--, 1);
4044
- }
4045
- }
4046
- }
4047
-
4048
- function walk(node){
4049
- var parent = parentStack[parentStack.length-1];
4050
- var remove = false;
4051
- parentStack.push(node);
4052
-
4053
- var excludeBody = false;
4054
- if (shouldScope(node, parent)){
4055
- hoist(node.body);
4056
- excludeBody = true;
4057
- }
4058
-
4059
- if (node.type === 'VariableDeclarator'){
4060
- variables.push(node);
4061
- }
4062
-
4063
- if (node.type === 'FunctionDeclaration'){
4064
- functions.push(node);
4065
- remove = true;
4066
- }
4067
-
4068
- for (var key in node){
4069
- if (key === 'type' || (excludeBody && key === 'body')) continue
4070
- if (key in node && node[key] && typeof node[key] == 'object'){
4071
- if (node[key].type){
4072
- walk(node[key]);
4073
- } else if (Array.isArray(node[key])){
4074
- walkAll(node[key]);
4075
- }
4076
- }
4077
- }
4078
-
4079
- parentStack.pop();
4080
- if (remove){
4081
- return 'remove'
4082
- }
4083
- }
4084
- }
4085
-
4086
- function shouldScope(node, parent){
4087
- if (node.type === 'Program'){
4088
- return true
4089
- } else if (node.type === 'BlockStatement'){
4090
- if (parent && (parent.type === 'FunctionExpression' || parent.type === 'FunctionDeclaration')){
4091
- return true
4092
- }
4093
- }
4094
- }
4095
-
4096
- function prependScope(nodes, variables, functions){
4097
- if (variables && variables.length){
4098
- var declarations = [];
4099
- for (var i=0;i<variables.length;i++){
4100
- declarations.push({
4101
- type: 'VariableDeclarator',
4102
- id: variables[i].id,
4103
- init: null
4104
- });
4105
- }
4106
-
4107
- nodes.unshift({
4108
- type: 'VariableDeclaration',
4109
- kind: 'var',
4110
- declarations: declarations
4111
- });
4112
-
4113
- }
4114
-
4115
- if (functions && functions.length){
4116
- for (var i=0;i<functions.length;i++){
4117
- nodes.unshift(functions[i]);
4118
- }
4119
- }
4120
- }
4121
-
4122
- var infiniteChecker = InfiniteChecker;
4123
-
4124
- function InfiniteChecker(maxIterations){
4125
- if (this instanceof InfiniteChecker){
4126
- this.maxIterations = maxIterations;
4127
- this.count = 0;
4128
- } else {
4129
- return new InfiniteChecker(maxIterations)
4130
- }
4131
- }
4132
-
4133
- InfiniteChecker.prototype.check = function(){
4134
- this.count += 1;
4135
- if (this.count > this.maxIterations){
4136
- throw new Error('Infinite loop detected - reached max iterations')
4137
- }
4138
- };
4139
-
4140
- var names = ['Object', 'String', 'Boolean', 'Number', 'RegExp', 'Date', 'Array', 'Function'];
4141
- var immutable = {string: 'String', boolean: 'Boolean', number: 'Number' };
4142
-
4143
- var primitives = names.map(getGlobal);
4144
- var protos = primitives.map(getProto);
4145
-
4146
- var primitives_1 = Primitives;
4147
-
4148
- function Primitives(context){
4149
- if (this instanceof Primitives){
4150
- this.context = context;
4151
- for (var i=0;i<names.length;i++){
4152
- if (!this.context[names[i]]){
4153
- this.context[names[i]] = wrap(primitives[i]);
4154
- }
4155
- }
4156
- } else {
4157
- return new Primitives(context)
4158
- }
4159
- }
4160
-
4161
- Primitives.prototype.replace = function(value){
4162
- var primIndex = primitives.indexOf(value);
4163
- var protoIndex = protos.indexOf(value);
4164
-
4165
- if (~primIndex){
4166
- var name = names[primIndex];
4167
- return this.context[name]
4168
- } else if (~protoIndex) {
4169
- var name = names[protoIndex];
4170
- return this.context[name].prototype
4171
- } else {
4172
- return value
4173
- }
4174
- };
4175
-
4176
- Primitives.prototype.getPropertyObject = function(object, property){
4177
- if (immutable[typeof object]){
4178
- return this.getPrototypeOf(object)
4179
- }
4180
- return object
4181
- };
4182
-
4183
- Primitives.prototype.isPrimitive = function(value){
4184
- return !!~primitives.indexOf(value) || !!~protos.indexOf(value)
4185
- };
4186
-
4187
- Primitives.prototype.getPrototypeOf = function(value){
4188
- if (value == null){ // handle null and undefined
4189
- return value
4190
- }
4191
-
4192
- var immutableType = immutable[typeof value];
4193
- if (immutableType){
4194
- var proto = this.context[immutableType].prototype;
4195
- } else {
4196
- var proto = Object.getPrototypeOf(value);
4197
- }
4198
-
4199
- if (!proto || proto === Object.prototype){
4200
- return null
4201
- } else {
4202
- var replacement = this.replace(proto);
4203
- if (replacement === value){
4204
- replacement = this.replace(Object.prototype);
4205
- }
4206
- return replacement
4207
- }
4208
- };
4209
-
4210
- Primitives.prototype.applyNew = function(func, args){
4211
- if (func.wrapped){
4212
- var prim = Object.getPrototypeOf(func);
4213
- var instance = new (Function.prototype.bind.apply(prim, arguments));
4214
- setProto(instance, func.prototype);
4215
- return instance
4216
- } else {
4217
- return new (Function.prototype.bind.apply(func, arguments))
4218
- }
4219
- };
4220
-
4221
- function getProto(func){
4222
- return func.prototype
4223
- }
4224
-
4225
- function getGlobal(str){
4226
- return commonjsGlobal[str]
4227
- }
4228
-
4229
- function setProto(obj, proto){
4230
- obj.__proto__ = proto;
4231
- }
4232
-
4233
- function wrap(prim){
4234
- var proto = Object.create(prim.prototype);
4235
-
4236
- var result = function() {
4237
- if (this instanceof result){
4238
- prim.apply(this, arguments);
4239
- } else {
4240
- var instance = prim.apply(null, arguments);
4241
- setProto(instance, proto);
4242
- return instance
4243
- }
4244
- };
4245
- setProto(result, prim);
4246
- result.prototype = proto;
4247
- result.wrapped = true;
4248
- return result
4249
- }
4250
-
4251
- var parse$2 = esprima.parse;
4252
-
4253
-
4254
-
4255
-
4256
-
4257
- var notevil = safeEval;
4258
- var _eval = safeEval;
4259
- var FunctionFactory_1 = FunctionFactory;
4260
- var _Function = FunctionFactory();
4261
-
4262
- var maxIterations = 1000000;
4263
-
4264
- // 'eval' with a controlled environment
4265
- function safeEval(src, parentContext){
4266
- var tree = prepareAst(src);
4267
- var context = Object.create(parentContext || {});
4268
- return finalValue(evaluateAst(tree, context))
4269
- }
4270
-
4271
- // create a 'Function' constructor for a controlled environment
4272
- function FunctionFactory(parentContext){
4273
- var context = Object.create(parentContext || {});
4274
- return function Function() {
4275
- // normalize arguments array
4276
- var args = Array.prototype.slice.call(arguments);
4277
- var src = args.slice(-1)[0];
4278
- args = args.slice(0,-1);
4279
- if (typeof src === 'string'){
4280
- //HACK: esprima doesn't like returns outside functions
4281
- src = parse$2('function a(){' + src + '}').body[0].body;
4282
- }
4283
- var tree = prepareAst(src);
4284
- return getFunction(tree, args, context)
4285
- }
4286
- }
4287
-
4288
- // takes an AST or js source and returns an AST
4289
- function prepareAst(src){
4290
- var tree = (typeof src === 'string') ? parse$2(src, {loc: true}) : src;
4291
- return hoister(tree)
4292
- }
4293
-
4294
- // evaluate an AST in the given context
4295
- function evaluateAst(tree, context){
4296
-
4297
- var safeFunction = FunctionFactory(context);
4298
- var primitives = primitives_1(context);
4299
-
4300
- // block scoped context for catch (ex) and 'let'
4301
- var blockContext = context;
4302
-
4303
- return walk(tree)
4304
-
4305
- // recursively walk every node in an array
4306
- function walkAll(nodes){
4307
- var result = undefined;
4308
- for (var i=0;i<nodes.length;i++){
4309
- var childNode = nodes[i];
4310
- if (childNode.type === 'EmptyStatement') continue
4311
- result = walk(childNode);
4312
- if (result instanceof ReturnValue){
4313
- return result
4314
- }
4315
- }
4316
- return result
4317
- }
4318
-
4319
- // recursively evalutate the node of an AST
4320
- function walk(node, traceNode){
4321
- try {
4322
- if (!node) return
4323
- switch (node.type) {
4324
-
4325
- case 'Program':
4326
- return walkAll(node.body)
4327
-
4328
- case 'BlockStatement':
4329
- enterBlock();
4330
- var result = walkAll(node.body);
4331
- leaveBlock();
4332
- return result
4333
-
4334
- case 'FunctionDeclaration':
4335
- var params = node.params.map(getName);
4336
- var value = getFunction(node.body, params, blockContext, node);
4337
- return context[node.id.name] = value
4338
-
4339
- case 'FunctionExpression':
4340
- var params = node.params.map(getName);
4341
-
4342
- // HACK: trace the function name for stack traces
4343
- if (!node.id && traceNode && traceNode.key && traceNode.key.type === 'Identifier') {
4344
- node.id = traceNode.key;
4345
- }
4346
-
4347
- return getFunction(node.body, params, blockContext, node)
4348
-
4349
- case 'ReturnStatement':
4350
- var value = walk(node.argument);
4351
- return new ReturnValue('return', value)
4352
-
4353
- case 'BreakStatement':
4354
- return new ReturnValue('break')
4355
-
4356
- case 'ContinueStatement':
4357
- return new ReturnValue('continue')
4358
-
4359
- case 'ExpressionStatement':
4360
- return walk(node.expression)
4361
-
4362
- case 'AssignmentExpression':
4363
- return setValue(blockContext, node.left, node.right, node.operator)
4364
-
4365
- case 'UpdateExpression':
4366
- return setValue(blockContext, node.argument, null, node.operator)
4367
-
4368
- case 'VariableDeclaration':
4369
- node.declarations.forEach(function(declaration){
4370
- var target = node.kind === 'let' ? blockContext : context;
4371
- if (declaration.init){
4372
- target[declaration.id.name] = walk(declaration.init);
4373
- } else {
4374
- target[declaration.id.name] = undefined;
4375
- }
4376
- });
4377
- break
4378
-
4379
- case 'SwitchStatement':
4380
- var defaultHandler = null;
4381
- var matched = false;
4382
- var value = walk(node.discriminant);
4383
- var result = undefined;
4384
-
4385
- enterBlock();
4386
-
4387
- var i = 0;
4388
- while (result == null){
4389
- if (i<node.cases.length){
4390
- if (node.cases[i].test){ // check or fall through
4391
- matched = matched || (walk(node.cases[i].test) === value);
4392
- } else if (defaultHandler == null) {
4393
- defaultHandler = i;
4394
- }
4395
- if (matched){
4396
- var r = walkAll(node.cases[i].consequent);
4397
- if (r instanceof ReturnValue){ // break out
4398
- if (r.type == 'break') break
4399
- result = r;
4400
- }
4401
- }
4402
- i += 1; // continue
4403
- } else if (!matched && defaultHandler != null){
4404
- // go back and do the default handler
4405
- i = defaultHandler;
4406
- matched = true;
4407
- } else {
4408
- // nothing we can do
4409
- break
4410
- }
4411
- }
4412
-
4413
- leaveBlock();
4414
- return result
4415
-
4416
- case 'IfStatement':
4417
- if (walk(node.test)){
4418
- return walk(node.consequent)
4419
- } else if (node.alternate) {
4420
- return walk(node.alternate)
4421
- }
4422
-
4423
- case 'ForStatement':
4424
- var infinite = infiniteChecker(maxIterations);
4425
- var result = undefined;
4426
-
4427
- enterBlock(); // allow lets on delarations
4428
- for (walk(node.init); walk(node.test); walk(node.update)){
4429
- var r = walk(node.body);
4430
-
4431
- // handle early return, continue and break
4432
- if (r instanceof ReturnValue){
4433
- if (r.type == 'continue') continue
4434
- if (r.type == 'break') break
4435
- result = r;
4436
- break
4437
- }
4438
-
4439
- infinite.check();
4440
- }
4441
- leaveBlock();
4442
- return result
4443
-
4444
- case 'ForInStatement':
4445
- var infinite = infiniteChecker(maxIterations);
4446
- var result = undefined;
4447
-
4448
- var value = walk(node.right);
4449
- var property = node.left;
4450
-
4451
- var target = context;
4452
- enterBlock();
4453
-
4454
- if (property.type == 'VariableDeclaration'){
4455
- walk(property);
4456
- property = property.declarations[0].id;
4457
- if (property.kind === 'let'){
4458
- target = blockContext;
4459
- }
4460
- }
4461
-
4462
- for (var key in value){
4463
- setValue(target, property, {type: 'Literal', value: key});
4464
- var r = walk(node.body);
4465
-
4466
- // handle early return, continue and break
4467
- if (r instanceof ReturnValue){
4468
- if (r.type == 'continue') continue
4469
- if (r.type == 'break') break
4470
- result = r;
4471
- break
4472
- }
4473
-
4474
- infinite.check();
4475
- }
4476
- leaveBlock();
4477
-
4478
- return result
4479
-
4480
- case 'WhileStatement':
4481
- var infinite = infiniteChecker(maxIterations);
4482
- while (walk(node.test)){
4483
- walk(node.body);
4484
- infinite.check();
4485
- }
4486
- break
4487
-
4488
- case 'TryStatement':
4489
- try {
4490
- walk(node.block);
4491
- } catch (error) {
4492
- enterBlock();
4493
- var catchClause = node.handlers[0];
4494
- if (catchClause) {
4495
- blockContext[catchClause.param.name] = error;
4496
- walk(catchClause.body);
4497
- }
4498
- leaveBlock();
4499
- } finally {
4500
- if (node.finalizer) {
4501
- walk(node.finalizer);
4502
- }
4503
- }
4504
- break
4505
-
4506
- case 'Literal':
4507
- return node.value
4508
-
4509
- case 'UnaryExpression':
4510
- if (node.operator === 'delete' && node.argument.type === 'MemberExpression') {
4511
- var arg = node.argument;
4512
- var parent = walk(arg.object);
4513
- var prop = arg.computed ? walk(arg.property) : arg.property.name;
4514
- delete parent[prop];
4515
- return true
4516
- } else {
4517
- var val = walk(node.argument);
4518
- switch(node.operator) {
4519
- case '+': return +val
4520
- case '-': return -val
4521
- case '~': return ~val
4522
- case '!': return !val
4523
- case 'typeof': return typeof val
4524
- default: return unsupportedExpression(node)
4525
- }
4526
- }
4527
-
4528
- case 'ArrayExpression':
4529
- var obj = blockContext['Array']();
4530
- for (var i=0;i<node.elements.length;i++){
4531
- obj.push(walk(node.elements[i]));
4532
- }
4533
- return obj
4534
-
4535
- case 'ObjectExpression':
4536
- var obj = blockContext['Object']();
4537
- for (var i = 0; i < node.properties.length; i++) {
4538
- var prop = node.properties[i];
4539
- var value = (prop.value === null) ? prop.value : walk(prop.value, prop);
4540
- obj[prop.key.value || prop.key.name] = value;
4541
- }
4542
- return obj
4543
-
4544
- case 'NewExpression':
4545
- var args = node.arguments.map(function(arg){
4546
- return walk(arg)
4547
- });
4548
- var target = walk(node.callee);
4549
- return primitives.applyNew(target, args)
4550
-
4551
-
4552
- case 'BinaryExpression':
4553
- var l = walk(node.left);
4554
- var r = walk(node.right);
4555
- switch(node.operator) {
4556
- case '==': return l == r
4557
- case '===': return l === r
4558
- case '!=': return l != r
4559
- case '!==': return l !== r
4560
- case '+': return l + r
4561
- case '-': return l - r
4562
- case '*': return l * r
4563
- case '/': return l / r
4564
- case '%': return l % r
4565
- case '<': return l < r
4566
- case '<=': return l <= r
4567
- case '>': return l > r
4568
- case '>=': return l >= r
4569
- case '|': return l | r
4570
- case '&': return l & r
4571
- case '^': return l ^ r
4572
- case 'instanceof': return l instanceof r
4573
- default: return unsupportedExpression(node)
4574
- }
4575
-
4576
- case 'LogicalExpression':
4577
- switch(node.operator) {
4578
- case '&&': return walk(node.left) && walk(node.right)
4579
- case '||': return walk(node.left) || walk(node.right)
4580
- default: return unsupportedExpression(node)
4581
- }
4582
-
4583
- case 'ThisExpression':
4584
- return blockContext['this']
4585
-
4586
- case 'Identifier':
4587
- if (node.name === 'undefined'){
4588
- return undefined
4589
- } else if (hasProperty(blockContext, node.name, primitives)){
4590
- return checkValue(blockContext[node.name])
4591
- } else {
4592
- throw new ReferenceError(node.name + ' is not defined')
4593
- }
4594
-
4595
- case 'CallExpression':
4596
- var args = node.arguments.map(function(arg){
4597
- return walk(arg)
4598
- });
4599
- var object = null;
4600
- var target = walk(node.callee);
4601
-
4602
- if (node.callee.type === 'MemberExpression'){
4603
- object = walk(node.callee.object);
4604
- }
4605
- return checkValue(target.apply(object, args))
4606
-
4607
- case 'MemberExpression':
4608
- var obj = walk(node.object);
4609
- if (node.computed){
4610
- var prop = walk(node.property);
4611
- } else {
4612
- var prop = node.property.name;
4613
- }
4614
- obj = primitives.getPropertyObject(obj, prop);
4615
- return checkValue(obj[prop]);
4616
-
4617
- case 'ConditionalExpression':
4618
- var val = walk(node.test);
4619
- return val ? walk(node.consequent) : walk(node.alternate)
4620
-
4621
- case 'EmptyStatement':
4622
- return
4623
-
4624
- default:
4625
- return unsupportedExpression(node)
4626
- }
4627
- } catch (ex) {
4628
- ex.trace = ex.trace || [];
4629
- ex.trace.push(node);
4630
- throw ex
4631
- }
4632
- }
4633
-
4634
- // safely retrieve a value
4635
- function checkValue(value){
4636
- if (value === Function){
4637
- value = safeFunction;
4638
- }
4639
- return finalValue(value)
4640
- }
4641
-
4642
- // block scope context control
4643
- function enterBlock(){
4644
- blockContext = Object.create(blockContext);
4645
- }
4646
- function leaveBlock(){
4647
- blockContext = Object.getPrototypeOf(blockContext);
4648
- }
4649
-
4650
- // set a value in the specified context if allowed
4651
- function setValue(object, left, right, operator){
4652
- var name = null;
4653
-
4654
- if (left.type === 'Identifier'){
4655
- name = left.name;
4656
- // handle parent context shadowing
4657
- object = objectForKey(object, name, primitives);
4658
- } else if (left.type === 'MemberExpression'){
4659
- if (left.computed){
4660
- name = walk(left.property);
4661
- } else {
4662
- name = left.property.name;
4663
- }
4664
- object = walk(left.object);
4665
- }
4666
-
4667
- // stop built in properties from being able to be changed
4668
- if (canSetProperty(object, name, primitives)){
4669
- switch(operator) {
4670
- case undefined: return object[name] = walk(right)
4671
- case '=': return object[name] = walk(right)
4672
- case '+=': return object[name] += walk(right)
4673
- case '-=': return object[name] -= walk(right)
4674
- case '++': return object[name]++
4675
- case '--': return object[name]--
4676
- }
4677
- }
4678
-
4679
- }
4680
-
4681
- }
4682
-
4683
- // when an unsupported expression is encountered, throw an error
4684
- function unsupportedExpression(node){
4685
- console.error(node);
4686
- var err = new Error('Unsupported expression: ' + node.type);
4687
- err.node = node;
4688
- throw err
4689
- }
4690
-
4691
- // walk a provided object's prototypal hierarchy to retrieve an inherited object
4692
- function objectForKey(object, key, primitives){
4693
- var proto = primitives.getPrototypeOf(object);
4694
- if (!proto || hasOwnProperty$1(object, key)){
4695
- return object
4696
- } else {
4697
- return objectForKey(proto, key, primitives)
4698
- }
4699
- }
4700
-
4701
- function hasProperty(object, key, primitives){
4702
- var proto = primitives.getPrototypeOf(object);
4703
- var hasOwn = hasOwnProperty$1(object, key);
4704
- if (object[key] !== undefined){
4705
- return true
4706
- } else if (!proto || hasOwn){
4707
- return hasOwn
4708
- } else {
4709
- return hasProperty(proto, key, primitives)
4710
- }
4711
- }
4712
-
4713
- function hasOwnProperty$1(object, key){
4714
- return Object.prototype.hasOwnProperty.call(object, key)
4715
- }
4716
-
4717
- function propertyIsEnumerable(object, key){
4718
- return Object.prototype.propertyIsEnumerable.call(object, key)
4719
- }
4720
-
4721
-
4722
- // determine if we have write access to a property
4723
- function canSetProperty(object, property, primitives){
4724
- if (property === '__proto__' || primitives.isPrimitive(object)){
4725
- return false
4726
- } else if (object != null){
4727
-
4728
- if (hasOwnProperty$1(object, property)){
4729
- if (propertyIsEnumerable(object, property)){
4730
- return true
4731
- } else {
4732
- return false
4733
- }
4734
- } else {
4735
- return canSetProperty(primitives.getPrototypeOf(object), property, primitives)
4736
- }
4737
-
4738
- } else {
4739
- return true
4740
- }
4741
- }
4742
-
4743
- // generate a function with specified context
4744
- function getFunction(body, params, parentContext, traceNode){
4745
- return function(){
4746
- try {
4747
- var context = Object.create(parentContext);
4748
- if (this == commonjsGlobal){
4749
- context['this'] = null;
4750
- } else {
4751
- context['this'] = this;
4752
- }
4753
- // normalize arguments array
4754
- var args = Array.prototype.slice.call(arguments);
4755
- context['arguments'] = arguments;
4756
- args.forEach(function(arg,idx){
4757
- var param = params[idx];
4758
- if (param){
4759
- context[param] = arg;
4760
- }
4761
- });
4762
- var result = evaluateAst(body, context);
4763
-
4764
- if (result instanceof ReturnValue){
4765
- return result.value
4766
- }
4767
- } catch (ex) {
4768
- ex.trace = ex.trace || [];
4769
- ex.trace.push(traceNode);
4770
- throw ex
4771
- }
4772
- }
4773
- }
4774
-
4775
- function finalValue(value){
4776
- if (value instanceof ReturnValue){
4777
- return value.value
4778
- }
4779
- return value
4780
- }
4781
-
4782
- // get the name of an identifier
4783
- function getName(identifier){
4784
- return identifier.name
4785
- }
4786
-
4787
- // a ReturnValue struct for differentiating between expression result and return statement
4788
- function ReturnValue(type, value){
4789
- this.type = type;
4790
- this.value = value;
4791
- }
4792
- notevil.eval = _eval;
4793
- notevil.FunctionFactory = FunctionFactory_1;
4794
- notevil.Function = _Function;
4795
-
4796
100
  let __clone = function (data) {
4797
101
  return JSON.parse(JSON.stringify(data));
4798
102
  };
@@ -5204,12 +508,19 @@ const UtFormConstructor = {
5204
508
  context['console'] = console;
5205
509
  context['Date'] = Date;
5206
510
  context['Math'] = Math;
511
+ let appendScript = '';
512
+
513
+ for (let v in context) {
514
+ appendScript = appendScript + `var ${v} = this.${v};\n`;
515
+ }
516
+
517
+ appendScript = appendScript ? appendScript + '\n' : '';
5207
518
 
5208
519
  let func = function (script) {
5209
- return notevil(script, context);
520
+ return eval(script);
5210
521
  };
5211
522
 
5212
- func.call(context, script);
523
+ func.call(context, appendScript + script);
5213
524
  }
5214
525
 
5215
526
  };
@@ -7685,6 +2996,22 @@ const __vue_component__$6 = /*#__PURE__*/normalizeComponent({
7685
2996
 
7686
2997
  var DocTemplateSectionModal = __vue_component__$6;
7687
2998
 
2999
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3000
+
3001
+ function createCommonjsModule(fn, basedir, module) {
3002
+ return module = {
3003
+ path: basedir,
3004
+ exports: {},
3005
+ require: function (path, base) {
3006
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
3007
+ }
3008
+ }, fn(module, module.exports), module.exports;
3009
+ }
3010
+
3011
+ function commonjsRequire () {
3012
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
3013
+ }
3014
+
7688
3015
  /**!
7689
3016
  * Sortable 1.10.2
7690
3017
  * @author RubaXa <trash@rubaxa.org>
@@ -13283,7 +8610,6 @@ var _typeof = function(object) {
13283
8610
  };
13284
8611
 
13285
8612
  //
13286
-
13287
8613
  var script$3 = {
13288
8614
  name: 'DocForm',
13289
8615
  props: {