rb-document-form-constructor 0.8.54 → 0.8.56

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