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