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