rb-document-form-constructor 0.8.71 → 0.8.73

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