@ibyar/expressions 0.5.1 → 0.5.6
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.
- package/LICENSE +1 -1
- package/README.md +5 -4
- package/api/abstract.d.ts +5 -6
- package/api/abstract.js +3 -3
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +202 -0
- package/api/class/class.js +635 -0
- package/api/class/class.js.map +1 -0
- package/api/class/decorator.d.ts +20 -0
- package/api/class/decorator.js +48 -0
- package/api/class/decorator.js.map +1 -0
- package/api/computing/call.d.ts +3 -1
- package/api/computing/call.js +16 -4
- package/api/computing/call.js.map +1 -1
- package/api/computing/debugger.d.ts +15 -0
- package/api/computing/debugger.js +35 -0
- package/api/computing/debugger.js.map +1 -0
- package/api/computing/new.d.ts +2 -1
- package/api/computing/new.js +4 -0
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +6 -6
- package/api/computing/rest.js +5 -2
- package/api/computing/rest.js.map +1 -1
- package/api/computing/return.d.ts +2 -1
- package/api/computing/return.js +3 -0
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +2 -1
- package/api/computing/spread.js +5 -2
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +2 -1
- package/api/computing/throw.js +3 -0
- package/api/computing/throw.js.map +1 -1
- package/api/computing/yield.d.ts +2 -1
- package/api/computing/yield.js +3 -0
- package/api/computing/yield.js.map +1 -1
- package/api/definition/array.d.ts +12 -12
- package/api/definition/array.js +31 -25
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +2 -2
- package/api/definition/bind.js +1 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +40 -51
- package/api/definition/function.js +291 -309
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +2 -2
- package/api/definition/member.js +1 -1
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +15 -12
- package/api/definition/object.js +43 -13
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -2
- package/api/definition/statement.js +7 -3
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +35 -50
- package/api/definition/values.js +66 -149
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +2 -1
- package/api/deserialize/deserialize.js +4 -1
- package/api/deserialize/deserialize.js.map +1 -1
- package/api/deserialize/type-store.d.ts +2 -2
- package/api/deserialize/type-store.js.map +1 -1
- package/api/expression.d.ts +13 -18
- package/api/expression.js.map +1 -1
- package/api/index.d.ts +2 -0
- package/api/index.js +2 -0
- package/api/index.js.map +1 -1
- package/api/module/common.d.ts +29 -0
- package/api/module/common.js +71 -0
- package/api/module/common.js.map +1 -0
- package/api/module/export.d.ts +66 -25
- package/api/module/export.js +270 -58
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +61 -25
- package/api/module/import.js +226 -68
- package/api/module/import.js.map +1 -1
- package/api/operators/assignment.d.ts +2 -2
- package/api/operators/assignment.js +1 -1
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +2 -2
- package/api/operators/await.js +1 -1
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.d.ts +2 -2
- package/api/operators/binary.js +1 -1
- package/api/operators/binary.js.map +1 -1
- package/api/operators/chaining.d.ts +2 -2
- package/api/operators/chaining.js +1 -1
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +2 -2
- package/api/operators/comma.js +2 -2
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +2 -2
- package/api/operators/grouping.js +1 -1
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.d.ts +2 -2
- package/api/operators/logical.js +1 -1
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +2 -2
- package/api/operators/pipeline.js +1 -1
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +2 -2
- package/api/operators/ternary.js +1 -1
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +3 -3
- package/api/operators/unary.js +4 -3
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +2 -2
- package/api/operators/update.js +1 -1
- package/api/operators/update.js.map +1 -1
- package/api/{app/program.d.ts → program.d.ts} +8 -9
- package/api/program.js +45 -0
- package/api/program.js.map +1 -0
- package/api/statement/control/block.d.ts +4 -5
- package/api/statement/control/block.js +22 -23
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +1 -1
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +2 -2
- package/api/statement/control/if.js +1 -1
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +4 -5
- package/api/statement/control/switch.js +13 -9
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +38 -13
- package/api/statement/control/terminate.js +81 -20
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +17 -16
- package/api/statement/declarations/declares.js +24 -19
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +5 -5
- package/api/statement/iterations/for.js +29 -23
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -3
- package/api/statement/iterations/while.js +17 -13
- package/api/statement/iterations/while.js.map +1 -1
- package/api/utils.d.ts +5 -0
- package/api/utils.js +4 -0
- package/api/utils.js.map +1 -0
- package/package.json +5 -5
- package/scope/event.d.ts +2 -2
- package/scope/event.js +8 -14
- package/scope/event.js.map +1 -1
- package/scope/finalizer.d.ts +4 -0
- package/scope/finalizer.js +11 -0
- package/scope/finalizer.js.map +1 -0
- package/scope/proxy.d.ts +2 -3
- package/scope/proxy.js +22 -26
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +42 -53
- package/scope/scope.js +73 -143
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +43 -26
- package/scope/stack.js +148 -102
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +204 -0
- package/v8/enums.js +375 -0
- package/v8/enums.js.map +1 -0
- package/v8/index.d.ts +2 -1
- package/v8/index.js +2 -1
- package/v8/index.js.map +1 -1
- package/v8/inline.d.ts +177 -0
- package/v8/inline.js +1973 -0
- package/v8/inline.js.map +1 -0
- package/v8/nodes.d.ts +8 -7
- package/v8/nodes.js +37 -63
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +41 -151
- package/v8/parser.js +507 -1578
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +35 -3
- package/v8/stream.js +616 -164
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +15 -9
- package/v8/token.js +79 -46
- package/v8/token.js.map +1 -1
- package/visit/visitor.js +4 -7
- package/visit/visitor.js.map +1 -1
- package/api/app/class.d.ts +0 -117
- package/api/app/class.js +0 -292
- package/api/app/class.js.map +0 -1
- package/api/app/program.js +0 -39
- package/api/app/program.js.map +0 -1
- package/api/module/module.d.ts +0 -26
- package/api/module/module.js +0 -63
- package/api/module/module.js.map +0 -1
- package/v8/app.d.ts +0 -0
- package/v8/app.js +0 -2
- package/v8/app.js.map +0 -1
package/v8/inline.js
ADDED
|
@@ -0,0 +1,1973 @@
|
|
|
1
|
+
import { Token } from './token.js';
|
|
2
|
+
import { TokenStream } from './stream.js';
|
|
3
|
+
import { OfNode, Identifier, ThisNode, GetIdentifier, SetIdentifier, AsyncIdentifier, NullNode, AwaitIdentifier, ConstructorIdentifier, NameIdentifier, EvalIdentifier, ArgumentsIdentifier, TaggedTemplateExpression, TemplateLiteral, SuperIdentifier } from '../api/definition/values.js';
|
|
4
|
+
import { EmptyStatement } from '../api/statement/control/empty.js';
|
|
5
|
+
import { BlockStatement } from '../api/statement/control/block.js';
|
|
6
|
+
import { ArrowFunctionExpression, Param, FunctionExpression, FunctionDeclaration } from '../api/definition/function.js';
|
|
7
|
+
import { IfStatement } from '../api/statement/control/if.js';
|
|
8
|
+
import { NewExpression } from '../api/computing/new.js';
|
|
9
|
+
import { SpreadElement } from '../api/computing/spread.js';
|
|
10
|
+
import { RestElement } from '../api/computing/rest.js';
|
|
11
|
+
import { AssignmentExpression } from '../api/operators/assignment.js';
|
|
12
|
+
import { GroupingExpression } from '../api/operators/grouping.js';
|
|
13
|
+
import { MemberExpression } from '../api/definition/member.js';
|
|
14
|
+
import { BindExpression } from '../api/definition/bind.js';
|
|
15
|
+
import { ObjectExpression, Property, ObjectPattern } from '../api/definition/object.js';
|
|
16
|
+
import { ArrayExpression, ArrayPattern } from '../api/definition/array.js';
|
|
17
|
+
import { CallExpression } from '../api/computing/call.js';
|
|
18
|
+
import { DoWhileNode, WhileNode } from '../api/statement/iterations/while.js';
|
|
19
|
+
import { CatchClauseNode, ThrowStatement, TryCatchNode } from '../api/computing/throw.js';
|
|
20
|
+
import { SwitchCase, DefaultExpression, SwitchStatement } from '../api/statement/control/switch.js';
|
|
21
|
+
import { BreakStatement, ContinueStatement, LabeledStatement } from '../api/statement/control/terminate.js';
|
|
22
|
+
import { ReturnStatement } from '../api/computing/return.js';
|
|
23
|
+
import { YieldExpression } from '../api/computing/yield.js';
|
|
24
|
+
import { VariableDeclarator, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
|
|
25
|
+
import { ForNode, ForOfNode, ForInNode, ForAwaitOfNode } from '../api/statement/iterations/for.js';
|
|
26
|
+
import { ConditionalExpression } from '../api/operators/ternary.js';
|
|
27
|
+
import { PipelineExpression } from '../api/operators/pipeline.js';
|
|
28
|
+
import { LogicalExpression } from '../api/operators/logical.js';
|
|
29
|
+
import { SequenceExpression } from '../api/operators/comma.js';
|
|
30
|
+
import { ChainExpression } from '../api/operators/chaining.js';
|
|
31
|
+
import { ExpressionStatement } from '../api/definition/statement.js';
|
|
32
|
+
import { buildPostfixExpression, buildUnaryExpression, expressionFromLiteral, shortcutNumericLiteralBinaryExpression } from './nodes.js';
|
|
33
|
+
import { AllowLabelledFunctionStatement, FunctionBodyType, FunctionKind, functionKindForImpl, FunctionSyntaxKind, isAsyncFunction, isAsyncGeneratorFunction, isAwaitAsIdentifierDisallowed, isClassMembersInitializerFunction, isGeneratorFunction, isModule, isResumableFunction, isSloppy, isStrict, LanguageMode, ParseFunctionFlag, ParsingArrowHeadFlag, PropertyKind, PropertyKindInfo, PropertyPosition, SubFunctionKind, VariableDeclarationContext } from './enums.js';
|
|
34
|
+
import { DebuggerStatement } from '../api/computing/debugger.js';
|
|
35
|
+
export class AbstractParser {
|
|
36
|
+
constructor(scanner, acceptIN) {
|
|
37
|
+
this.scanner = scanner;
|
|
38
|
+
this.previousAcceptIN = [];
|
|
39
|
+
this.previousFunctionKind = [];
|
|
40
|
+
this.previousAcceptIN.push(this.acceptIN = acceptIN ?? false);
|
|
41
|
+
this.previousFunctionKind.push(this.functionKind = FunctionKind.NormalFunction);
|
|
42
|
+
}
|
|
43
|
+
get languageMode() {
|
|
44
|
+
return this.scanner.getLanguageMode();
|
|
45
|
+
}
|
|
46
|
+
set languageMode(mode) {
|
|
47
|
+
this.scanner.setLanguageMode(mode);
|
|
48
|
+
}
|
|
49
|
+
position() {
|
|
50
|
+
return this.scanner.getPos();
|
|
51
|
+
}
|
|
52
|
+
setAcceptIN(acceptIN) {
|
|
53
|
+
this.previousAcceptIN.push(this.acceptIN);
|
|
54
|
+
this.acceptIN = acceptIN;
|
|
55
|
+
}
|
|
56
|
+
restoreAcceptIN() {
|
|
57
|
+
this.acceptIN = this.previousAcceptIN.pop() ?? false;
|
|
58
|
+
}
|
|
59
|
+
getLastFunctionKind() {
|
|
60
|
+
return this.previousFunctionKind.at(-2) ?? FunctionKind.NormalFunction;
|
|
61
|
+
}
|
|
62
|
+
setFunctionKind(functionKind) {
|
|
63
|
+
this.previousFunctionKind.push(this.functionKind);
|
|
64
|
+
this.functionKind = functionKind;
|
|
65
|
+
}
|
|
66
|
+
restoreFunctionKind() {
|
|
67
|
+
this.functionKind = this.previousFunctionKind.pop() ?? FunctionKind.NormalFunction;
|
|
68
|
+
}
|
|
69
|
+
setStatue(acceptIN, functionKind) {
|
|
70
|
+
this.setFunctionKind(functionKind);
|
|
71
|
+
this.setAcceptIN(acceptIN);
|
|
72
|
+
}
|
|
73
|
+
restoreStatue() {
|
|
74
|
+
this.restoreFunctionKind();
|
|
75
|
+
this.restoreAcceptIN();
|
|
76
|
+
}
|
|
77
|
+
current() {
|
|
78
|
+
return this.scanner.currentToken();
|
|
79
|
+
}
|
|
80
|
+
next() {
|
|
81
|
+
return this.scanner.next();
|
|
82
|
+
}
|
|
83
|
+
peek() {
|
|
84
|
+
return this.scanner.peek();
|
|
85
|
+
}
|
|
86
|
+
peekAhead() {
|
|
87
|
+
return this.scanner.peekAhead();
|
|
88
|
+
}
|
|
89
|
+
peekAheadPosition() {
|
|
90
|
+
return this.scanner.peekAheadPosition();
|
|
91
|
+
}
|
|
92
|
+
peekPosition() {
|
|
93
|
+
return this.scanner.peekPosition();
|
|
94
|
+
}
|
|
95
|
+
consume(token) {
|
|
96
|
+
if (this.scanner.next().isNotType(token)) {
|
|
97
|
+
throw new Error(this.errorMessage(`Parsing ${JSON.stringify(token)}`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
check(token) {
|
|
101
|
+
const next = this.scanner.peek();
|
|
102
|
+
if (next.isType(token)) {
|
|
103
|
+
this.scanner.next();
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
checkAndGetValue(token) {
|
|
109
|
+
const next = this.scanner.peek();
|
|
110
|
+
if (next.isType(token)) {
|
|
111
|
+
this.scanner.next();
|
|
112
|
+
return next.value;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
checkValue(value) {
|
|
117
|
+
const next = this.scanner.peek();
|
|
118
|
+
if (next.value == value) {
|
|
119
|
+
this.scanner.next();
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
expect(token) {
|
|
125
|
+
const current = this.scanner.next();
|
|
126
|
+
if (current.isNotType(token)) {
|
|
127
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(token)}, current is ${JSON.stringify(current)}`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
expectAndGetValue(token) {
|
|
131
|
+
const current = this.scanner.next();
|
|
132
|
+
if (current.isNotType(token)) {
|
|
133
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(token)}, current is ${JSON.stringify(current)}`));
|
|
134
|
+
}
|
|
135
|
+
return current.getValue();
|
|
136
|
+
}
|
|
137
|
+
checkInOrOf() {
|
|
138
|
+
if (this.check(Token.IN)) {
|
|
139
|
+
return 'IN';
|
|
140
|
+
}
|
|
141
|
+
else if (this.checkValue(OfNode)) {
|
|
142
|
+
return 'OF';
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
peekInOrOf() {
|
|
147
|
+
var next = this.peek();
|
|
148
|
+
if (next.isType(Token.IN)) {
|
|
149
|
+
return 'IN';
|
|
150
|
+
}
|
|
151
|
+
else if (next.value === OfNode) {
|
|
152
|
+
return 'OF';
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
isArguments(name) {
|
|
157
|
+
return name instanceof Identifier && name.getName() === 'arguments';
|
|
158
|
+
}
|
|
159
|
+
isEval(name) {
|
|
160
|
+
return name instanceof Identifier && name.getName() === 'eval';
|
|
161
|
+
}
|
|
162
|
+
isEvalOrArguments(name) {
|
|
163
|
+
return name instanceof Identifier && (name.getName() === 'eval' || name.getName() === 'arguments');
|
|
164
|
+
}
|
|
165
|
+
isNextLetKeyword() {
|
|
166
|
+
if (this.peek().isNotType(Token.LET)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const nextNextToken = this.peekAhead().token;
|
|
170
|
+
switch (nextNextToken) {
|
|
171
|
+
case Token.LBRACE:
|
|
172
|
+
case Token.LBRACK:
|
|
173
|
+
case Token.IDENTIFIER:
|
|
174
|
+
case Token.STATIC:
|
|
175
|
+
case Token.LET:
|
|
176
|
+
case Token.YIELD:
|
|
177
|
+
case Token.AWAIT:
|
|
178
|
+
case Token.GET:
|
|
179
|
+
case Token.SET:
|
|
180
|
+
case Token.ASYNC:
|
|
181
|
+
return true;
|
|
182
|
+
default:
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
isIdentifier(expression) {
|
|
187
|
+
return expression instanceof Identifier;
|
|
188
|
+
}
|
|
189
|
+
markParenthesized(expression) {
|
|
190
|
+
Reflect.set(expression, 'parenthesized', true);
|
|
191
|
+
}
|
|
192
|
+
clearParenthesized(expression) {
|
|
193
|
+
Reflect.deleteProperty(expression, 'parenthesized');
|
|
194
|
+
}
|
|
195
|
+
isParenthesized(expression) {
|
|
196
|
+
return Reflect.get(expression, 'parenthesized') === true;
|
|
197
|
+
}
|
|
198
|
+
isAssignableIdentifier(expression) {
|
|
199
|
+
if (!(expression instanceof Identifier)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (isStrict(this.languageMode) && this.isEvalOrArguments(expression)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
isPattern(expression) {
|
|
208
|
+
return expression instanceof ObjectExpression || expression instanceof ArrayExpression;
|
|
209
|
+
}
|
|
210
|
+
isProperty(expression) {
|
|
211
|
+
return expression instanceof Property || expression instanceof MemberExpression;
|
|
212
|
+
}
|
|
213
|
+
isCallNew(expression) {
|
|
214
|
+
return expression instanceof NewExpression;
|
|
215
|
+
}
|
|
216
|
+
isCall(expression) {
|
|
217
|
+
return expression instanceof CallExpression;
|
|
218
|
+
}
|
|
219
|
+
isEmptyStatement(expression) {
|
|
220
|
+
return expression instanceof EmptyStatement;
|
|
221
|
+
}
|
|
222
|
+
isValidReferenceExpression(expression) {
|
|
223
|
+
return this.isAssignableIdentifier(expression) || this.isProperty(expression);
|
|
224
|
+
}
|
|
225
|
+
expectSemicolon() {
|
|
226
|
+
const tok = this.peek();
|
|
227
|
+
if (tok.isType(Token.SEMICOLON)) {
|
|
228
|
+
this.next();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (this.scanner.hasLineTerminatorBeforeNext() || Token.isAutoSemicolon(tok.token)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (this.scanner.currentToken().isType(Token.AWAIT) && !isAsyncFunction(this.functionKind)) {
|
|
235
|
+
throw new Error(this.errorMessage(`Await Not In Async Context/Function`));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
peekAnyIdentifier() {
|
|
239
|
+
return Token.isAnyIdentifier(this.peek().token);
|
|
240
|
+
}
|
|
241
|
+
expectContextualKeyword(keyword) {
|
|
242
|
+
const current = this.scanner.next();
|
|
243
|
+
if (!current.test((token, value) => Token.IDENTIFIER.equal(token) && keyword === value?.toString())) {
|
|
244
|
+
throw new Error(this.errorMessage(`Unexpected Token: current Token is ${JSON.stringify(current)}`));
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
checkContextualKeyword(keyword) {
|
|
249
|
+
const next = this.scanner.peek();
|
|
250
|
+
if (next.test((token, value) => Token.IDENTIFIER.equal(token) && keyword === value?.toString())) {
|
|
251
|
+
this.scanner.next();
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
peekContextualKeyword(keyword) {
|
|
257
|
+
const next = this.scanner.peek();
|
|
258
|
+
return next.test((token, value) => Token.IDENTIFIER.equal(token) && keyword === value?.toString());
|
|
259
|
+
}
|
|
260
|
+
methodKindFor(isStatic, flag) {
|
|
261
|
+
return functionKindForImpl(isStatic ? SubFunctionKind.StaticMethod : SubFunctionKind.NonStaticMethod, flag);
|
|
262
|
+
}
|
|
263
|
+
isGenerator() {
|
|
264
|
+
return isGeneratorFunction(this.functionKind);
|
|
265
|
+
}
|
|
266
|
+
isAsyncFunction() {
|
|
267
|
+
return isAsyncFunction(this.functionKind);
|
|
268
|
+
}
|
|
269
|
+
is_async_function() {
|
|
270
|
+
return isAsyncFunction(this.functionKind);
|
|
271
|
+
}
|
|
272
|
+
is_async_generator() {
|
|
273
|
+
return isAsyncGeneratorFunction(this.functionKind);
|
|
274
|
+
}
|
|
275
|
+
is_resumable() {
|
|
276
|
+
return isResumableFunction(this.functionKind);
|
|
277
|
+
}
|
|
278
|
+
isAwaitAllowed() {
|
|
279
|
+
return this.isAsyncFunction() || isModule(this.functionKind);
|
|
280
|
+
}
|
|
281
|
+
isAwaitAsIdentifierDisallowed() {
|
|
282
|
+
return isStrict(this.languageMode) ||
|
|
283
|
+
isAwaitAsIdentifierDisallowed(this.functionKind);
|
|
284
|
+
}
|
|
285
|
+
shouldBanArguments() {
|
|
286
|
+
return isClassMembersInitializerFunction(this.functionKind);
|
|
287
|
+
}
|
|
288
|
+
errorMessage(message) {
|
|
289
|
+
return this.scanner.createError(message);
|
|
290
|
+
}
|
|
291
|
+
reportErrorMessage(message) {
|
|
292
|
+
console.error(this.scanner.createError(message));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export class JavaScriptInlineParser extends AbstractParser {
|
|
296
|
+
static parse(source, { mode, acceptIN } = {}) {
|
|
297
|
+
mode ?? (mode = LanguageMode.Strict);
|
|
298
|
+
const stream = (typeof source === 'string')
|
|
299
|
+
? TokenStream.getTokenStream(source, mode)
|
|
300
|
+
: Array.isArray(source) ? TokenStream.getTokenStream(source) : source;
|
|
301
|
+
acceptIN ?? (acceptIN = false);
|
|
302
|
+
const parser = new JavaScriptInlineParser(stream, acceptIN);
|
|
303
|
+
return parser.scan();
|
|
304
|
+
}
|
|
305
|
+
constructor(scanner, acceptIN) {
|
|
306
|
+
super(scanner, acceptIN);
|
|
307
|
+
}
|
|
308
|
+
scan() {
|
|
309
|
+
const list = this.parseStatementList(Token.EOS);
|
|
310
|
+
if (list.length === 1) {
|
|
311
|
+
return list[0];
|
|
312
|
+
}
|
|
313
|
+
return new ExpressionStatement(list);
|
|
314
|
+
}
|
|
315
|
+
parseStatement(allowFunction = AllowLabelledFunctionStatement.DisallowLabelledFunctionStatement) {
|
|
316
|
+
switch (this.peek().token) {
|
|
317
|
+
case Token.LBRACE:
|
|
318
|
+
return this.parseBlock();
|
|
319
|
+
case Token.SEMICOLON:
|
|
320
|
+
this.consume(Token.SEMICOLON);
|
|
321
|
+
return EmptyStatement.INSTANCE;
|
|
322
|
+
case Token.IF:
|
|
323
|
+
return this.parseIfStatement();
|
|
324
|
+
case Token.DO:
|
|
325
|
+
return this.parseDoWhileStatement();
|
|
326
|
+
case Token.WHILE:
|
|
327
|
+
return this.parseWhileStatement();
|
|
328
|
+
case Token.FOR:
|
|
329
|
+
if (this.isAwaitAllowed() && this.peekAhead().isType(Token.AWAIT)) {
|
|
330
|
+
return this.parseForAwaitStatement();
|
|
331
|
+
}
|
|
332
|
+
return this.parseForStatement();
|
|
333
|
+
case Token.CONTINUE:
|
|
334
|
+
return this.parseContinueStatement();
|
|
335
|
+
case Token.BREAK:
|
|
336
|
+
return this.parseBreakStatement();
|
|
337
|
+
case Token.RETURN:
|
|
338
|
+
return this.parseReturnStatement();
|
|
339
|
+
case Token.THROW:
|
|
340
|
+
return this.parseThrowStatement();
|
|
341
|
+
case Token.TRY:
|
|
342
|
+
return this.parseTryStatement();
|
|
343
|
+
case Token.SWITCH:
|
|
344
|
+
return this.parseSwitchStatement();
|
|
345
|
+
case Token.FUNCTION:
|
|
346
|
+
throw new SyntaxError(this.errorMessage(`FunctionDeclaration only allowed as a StatementListItem not in an arbitrary Statement position.`));
|
|
347
|
+
case Token.DEBUGGER:
|
|
348
|
+
return this.parseDebuggerStatement();
|
|
349
|
+
case Token.VAR:
|
|
350
|
+
return this.parseVariableDeclarations(VariableDeclarationContext.Statement);
|
|
351
|
+
case Token.ASYNC:
|
|
352
|
+
if (!this.scanner.hasLineTerminatorAfterNext() && this.peekAhead().isType(Token.FUNCTION)) {
|
|
353
|
+
throw new SyntaxError(this.errorMessage(`async function in single statement context.`));
|
|
354
|
+
}
|
|
355
|
+
default:
|
|
356
|
+
return this.parseExpressionOrLabelledStatement(allowFunction);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
parseDebuggerStatement() {
|
|
360
|
+
this.consume(Token.DEBUGGER);
|
|
361
|
+
this.expectSemicolon();
|
|
362
|
+
return DebuggerStatement.INSTANCE;
|
|
363
|
+
}
|
|
364
|
+
parseTryStatement() {
|
|
365
|
+
this.consume(Token.TRY);
|
|
366
|
+
const tryBlock = this.parseBlock();
|
|
367
|
+
let peek = this.peek();
|
|
368
|
+
if (peek.isNotType(Token.CATCH) && peek.isNotType(Token.FINALLY)) {
|
|
369
|
+
throw new Error(this.errorMessage(`Uncaught SyntaxError: Missing catch or finally after try`));
|
|
370
|
+
}
|
|
371
|
+
let catchBlock;
|
|
372
|
+
if (this.check(Token.CATCH)) {
|
|
373
|
+
let identifier;
|
|
374
|
+
const hasBinding = this.check(Token.LPAREN);
|
|
375
|
+
if (hasBinding) {
|
|
376
|
+
if (this.peekAnyIdentifier()) {
|
|
377
|
+
identifier = this.parseNonRestrictedIdentifier();
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
identifier = this.parseBindingPattern(true);
|
|
381
|
+
}
|
|
382
|
+
this.expect(Token.RPAREN);
|
|
383
|
+
}
|
|
384
|
+
const block = this.parseBlock();
|
|
385
|
+
catchBlock = new CatchClauseNode(block, identifier);
|
|
386
|
+
}
|
|
387
|
+
let finallyBlock;
|
|
388
|
+
if (this.check(Token.FINALLY)) {
|
|
389
|
+
finallyBlock = this.parseBlock();
|
|
390
|
+
}
|
|
391
|
+
return new TryCatchNode(tryBlock, catchBlock, finallyBlock);
|
|
392
|
+
}
|
|
393
|
+
parseNonRestrictedIdentifier() {
|
|
394
|
+
const result = this.parseIdentifier();
|
|
395
|
+
if (isStrict(this.languageMode) && this.isEvalOrArguments(result)) {
|
|
396
|
+
throw new SyntaxError(this.errorMessage('Strict Eval/Arguments '));
|
|
397
|
+
}
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
parseBlock() {
|
|
401
|
+
this.expect(Token.LBRACE);
|
|
402
|
+
const statements = [];
|
|
403
|
+
const block = new BlockStatement(statements);
|
|
404
|
+
while (this.peek().isNotType(Token.RBRACE)) {
|
|
405
|
+
const stat = this.parseStatementListItem();
|
|
406
|
+
if (!stat) {
|
|
407
|
+
return block;
|
|
408
|
+
}
|
|
409
|
+
else if (stat instanceof EmptyStatement) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
statements.push(stat);
|
|
413
|
+
}
|
|
414
|
+
this.expect(Token.RBRACE);
|
|
415
|
+
return block;
|
|
416
|
+
}
|
|
417
|
+
parseStatementListItem() {
|
|
418
|
+
switch (this.peek().token) {
|
|
419
|
+
case Token.FUNCTION:
|
|
420
|
+
return this.parseHoistableDeclaration(undefined, false);
|
|
421
|
+
case Token.CLASS:
|
|
422
|
+
this.consume(Token.CLASS);
|
|
423
|
+
return this.parseClassDeclaration(undefined, false);
|
|
424
|
+
case Token.VAR:
|
|
425
|
+
case Token.CONST:
|
|
426
|
+
return this.parseVariableDeclarations(VariableDeclarationContext.StatementListItem);
|
|
427
|
+
case Token.LET:
|
|
428
|
+
if (this.isNextLetKeyword()) {
|
|
429
|
+
return this.parseVariableDeclarations(VariableDeclarationContext.StatementListItem);
|
|
430
|
+
}
|
|
431
|
+
break;
|
|
432
|
+
case Token.ASYNC:
|
|
433
|
+
if (this.peekAhead().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorAfterNext()) {
|
|
434
|
+
this.consume(Token.ASYNC);
|
|
435
|
+
return this.parseAsyncFunctionDeclaration(undefined, false);
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
438
|
+
default:
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
return this.parseStatement(AllowLabelledFunctionStatement.AllowLabelledFunctionStatement);
|
|
442
|
+
}
|
|
443
|
+
parseFunctionExpression() {
|
|
444
|
+
this.consume(Token.FUNCTION);
|
|
445
|
+
const functionKind = this.check(Token.MUL) ? FunctionKind.GeneratorFunction : FunctionKind.NormalFunction;
|
|
446
|
+
let name;
|
|
447
|
+
let functionSyntaxKind = FunctionSyntaxKind.AnonymousExpression;
|
|
448
|
+
const peek = this.peek();
|
|
449
|
+
if (peek.isNotType(Token.LPAREN)) {
|
|
450
|
+
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
451
|
+
functionSyntaxKind = FunctionSyntaxKind.NamedExpression;
|
|
452
|
+
}
|
|
453
|
+
return this.parseFunctionLiteral(functionKind, functionSyntaxKind, name);
|
|
454
|
+
}
|
|
455
|
+
parseAsyncFunctionDeclaration(names, defaultExport) {
|
|
456
|
+
if (this.scanner.hasLineTerminatorBeforeNext()) {
|
|
457
|
+
throw new SyntaxError(this.errorMessage('Line Terminator Before `function` parsing `async function`.'));
|
|
458
|
+
}
|
|
459
|
+
this.consume(Token.FUNCTION);
|
|
460
|
+
return this.parseHoistableDeclaration01(FunctionKind.AsyncFunction, names, defaultExport);
|
|
461
|
+
}
|
|
462
|
+
parseIfStatement() {
|
|
463
|
+
this.consume(Token.IF);
|
|
464
|
+
this.consume(Token.LPAREN);
|
|
465
|
+
const condition = this.parseExpression();
|
|
466
|
+
this.consume(Token.RPAREN);
|
|
467
|
+
const thenStatement = this.parseScopedStatement();
|
|
468
|
+
let elseStatement;
|
|
469
|
+
if (this.peek().isType(Token.ELSE)) {
|
|
470
|
+
this.consume(Token.ELSE);
|
|
471
|
+
elseStatement = this.parseScopedStatement();
|
|
472
|
+
}
|
|
473
|
+
return new IfStatement(condition, thenStatement, elseStatement);
|
|
474
|
+
}
|
|
475
|
+
parseScopedStatement() {
|
|
476
|
+
if (isStrict(this.languageMode) || this.peek().isNotType(Token.FUNCTION)) {
|
|
477
|
+
return this.parseStatement();
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
return this.parseFunctionDeclaration();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
parseDoWhileStatement() {
|
|
484
|
+
this.consume(Token.DO);
|
|
485
|
+
const body = this.parseStatement();
|
|
486
|
+
this.expect(Token.WHILE);
|
|
487
|
+
this.expect(Token.LPAREN);
|
|
488
|
+
const condition = this.parseExpression();
|
|
489
|
+
this.expect(Token.RPAREN);
|
|
490
|
+
this.check(Token.SEMICOLON);
|
|
491
|
+
return new DoWhileNode(condition, body);
|
|
492
|
+
}
|
|
493
|
+
parseWhileStatement() {
|
|
494
|
+
this.consume(Token.WHILE);
|
|
495
|
+
this.expect(Token.LPAREN);
|
|
496
|
+
const condition = this.parseExpression();
|
|
497
|
+
this.expect(Token.RPAREN);
|
|
498
|
+
const body = this.parseStatement();
|
|
499
|
+
return new WhileNode(condition, body);
|
|
500
|
+
}
|
|
501
|
+
parseThrowStatement() {
|
|
502
|
+
this.consume(Token.THROW);
|
|
503
|
+
if (this.scanner.hasLineTerminatorBeforeNext()) {
|
|
504
|
+
throw new Error(this.scanner.createError(`New line After Throw`));
|
|
505
|
+
}
|
|
506
|
+
const exception = this.parseExpression();
|
|
507
|
+
this.expectSemicolon();
|
|
508
|
+
return new ThrowStatement(exception);
|
|
509
|
+
}
|
|
510
|
+
parseSwitchStatement() {
|
|
511
|
+
this.consume(Token.SWITCH);
|
|
512
|
+
this.expect(Token.LPAREN);
|
|
513
|
+
const tag = this.parseExpression();
|
|
514
|
+
this.expect(Token.RPAREN);
|
|
515
|
+
const cases = [];
|
|
516
|
+
const switchStatement = new SwitchStatement(tag, cases);
|
|
517
|
+
let defaultSeen = false;
|
|
518
|
+
this.expect(Token.LBRACE);
|
|
519
|
+
while (this.peek().isNotType(Token.RBRACE)) {
|
|
520
|
+
const statements = [];
|
|
521
|
+
let label;
|
|
522
|
+
if (this.check(Token.CASE)) {
|
|
523
|
+
label = this.parseExpression();
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
this.expect(Token.DEFAULT);
|
|
527
|
+
if (defaultSeen) {
|
|
528
|
+
throw new Error(this.errorMessage(`Multiple Defaults In Switch`));
|
|
529
|
+
}
|
|
530
|
+
defaultSeen = true;
|
|
531
|
+
}
|
|
532
|
+
this.expect(Token.COLON);
|
|
533
|
+
while (this.peek().isNotType(Token.CASE)
|
|
534
|
+
&& this.peek().isNotType(Token.DEFAULT)
|
|
535
|
+
&& this.peek().isNotType(Token.RBRACE)) {
|
|
536
|
+
const statement = this.parseStatementListItem();
|
|
537
|
+
if (!statement || this.isEmptyStatement(statement)) {
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
statements.push(statement);
|
|
541
|
+
}
|
|
542
|
+
const block = new BlockStatement(statements);
|
|
543
|
+
const clause = defaultSeen ? new DefaultExpression(block) : new SwitchCase(label, block);
|
|
544
|
+
cases.push(clause);
|
|
545
|
+
}
|
|
546
|
+
this.expect(Token.RBRACE);
|
|
547
|
+
return switchStatement;
|
|
548
|
+
}
|
|
549
|
+
parseForStatement() {
|
|
550
|
+
this.consume(Token.FOR);
|
|
551
|
+
this.expect(Token.LPAREN);
|
|
552
|
+
const peek = this.peek();
|
|
553
|
+
const starts_with_let = peek.isType(Token.LET);
|
|
554
|
+
if (peek.isType(Token.CONST) || (starts_with_let && this.isNextLetKeyword())) {
|
|
555
|
+
const initializer = this.parseVariableDeclarations(VariableDeclarationContext.ForStatement);
|
|
556
|
+
const forMode = this.checkInOrOf();
|
|
557
|
+
if (forMode) {
|
|
558
|
+
return this.parseForEachStatementWithDeclarations(initializer, forMode);
|
|
559
|
+
}
|
|
560
|
+
this.expect(Token.SEMICOLON);
|
|
561
|
+
return this.parseStandardForLoopWithLexicalDeclarations(initializer);
|
|
562
|
+
}
|
|
563
|
+
let initializer;
|
|
564
|
+
if (peek.isType(Token.VAR)) {
|
|
565
|
+
initializer = this.parseVariableDeclarations(VariableDeclarationContext.ForStatement);
|
|
566
|
+
const forMode = this.checkInOrOf();
|
|
567
|
+
if (forMode) {
|
|
568
|
+
return this.parseForEachStatementWithDeclarations(initializer, forMode);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else if (this.peek().isNotType(Token.SEMICOLON)) {
|
|
572
|
+
this.setAcceptIN(false);
|
|
573
|
+
initializer = this.parseExpressionCoverGrammar();
|
|
574
|
+
this.restoreAcceptIN();
|
|
575
|
+
const expression_is_async = this.current().isType(Token.ASYNC);
|
|
576
|
+
const forMode = this.checkInOrOf();
|
|
577
|
+
if (forMode) {
|
|
578
|
+
if (forMode === 'OF' && starts_with_let || expression_is_async) {
|
|
579
|
+
throw new SyntaxError(this.errorMessage(starts_with_let ? 'For Of Let' : 'For Of Async'));
|
|
580
|
+
}
|
|
581
|
+
return this.parseForEachStatementWithoutDeclarations(initializer, forMode);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
this.expect(Token.SEMICOLON);
|
|
585
|
+
return this.parseStandardForLoop(initializer);
|
|
586
|
+
}
|
|
587
|
+
parseStandardForLoopWithLexicalDeclarations(initializer) {
|
|
588
|
+
return this.parseStandardForLoop(initializer);
|
|
589
|
+
}
|
|
590
|
+
parseForEachStatementWithDeclarations(initializer, forMode) {
|
|
591
|
+
if (initializer.getDeclarations().length != 1) {
|
|
592
|
+
throw new SyntaxError(this.errorMessage('For In/Of loop Multi Bindings'));
|
|
593
|
+
}
|
|
594
|
+
return this.parseForEachStatementWithoutDeclarations(initializer, forMode);
|
|
595
|
+
}
|
|
596
|
+
parseForEachStatementWithoutDeclarations(initializer, forMode) {
|
|
597
|
+
let enumerable;
|
|
598
|
+
if (forMode == 'OF') {
|
|
599
|
+
this.setAcceptIN(true);
|
|
600
|
+
enumerable = this.parseAssignmentExpression();
|
|
601
|
+
this.restoreAcceptIN();
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
enumerable = this.parseExpression();
|
|
605
|
+
}
|
|
606
|
+
this.expect(Token.RPAREN);
|
|
607
|
+
const body = this.parseStatement();
|
|
608
|
+
if (forMode === 'OF') {
|
|
609
|
+
return new ForOfNode(initializer, enumerable, body);
|
|
610
|
+
}
|
|
611
|
+
else if (forMode === 'IN') {
|
|
612
|
+
return new ForInNode(initializer, enumerable, body);
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
throw new Error(this.errorMessage(`parsing for loop: ${this.position()}`));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
parseStandardForLoop(initializer) {
|
|
619
|
+
let cond = new EmptyStatement();
|
|
620
|
+
if (this.peek().isNotType(Token.SEMICOLON)) {
|
|
621
|
+
cond = this.parseExpression();
|
|
622
|
+
}
|
|
623
|
+
this.expect(Token.SEMICOLON);
|
|
624
|
+
let next = new EmptyStatement();
|
|
625
|
+
if (this.peek().isNotType(Token.RPAREN)) {
|
|
626
|
+
next = this.parseExpression();
|
|
627
|
+
}
|
|
628
|
+
this.expect(Token.RPAREN);
|
|
629
|
+
const body = this.parseStatement();
|
|
630
|
+
return new ForNode(body, initializer, cond, next);
|
|
631
|
+
}
|
|
632
|
+
parseForAwaitStatement() {
|
|
633
|
+
if (!this.isAwaitAllowed()) {
|
|
634
|
+
throw new SyntaxError(this.errorMessage('"await" is not allowed'));
|
|
635
|
+
}
|
|
636
|
+
this.expect(Token.FOR);
|
|
637
|
+
this.expect(Token.AWAIT);
|
|
638
|
+
this.expect(Token.LPAREN);
|
|
639
|
+
let hasDeclarations = false;
|
|
640
|
+
let eachVariable;
|
|
641
|
+
let peek = this.peek();
|
|
642
|
+
let startsWithLet = peek.isType(Token.LET);
|
|
643
|
+
if (peek.isType(Token.VAR) || peek.isType(Token.CONST)
|
|
644
|
+
|| (startsWithLet && this.isNextLetKeyword())) {
|
|
645
|
+
hasDeclarations = true;
|
|
646
|
+
const initializer = this.parseVariableDeclarations(VariableDeclarationContext.ForStatement);
|
|
647
|
+
if (initializer.getDeclarations().length != 1) {
|
|
648
|
+
throw new SyntaxError(this.errorMessage('For In/Of Loop MultiBindings, "for-await-of"'));
|
|
649
|
+
}
|
|
650
|
+
eachVariable = initializer;
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
if (startsWithLet) {
|
|
654
|
+
throw new SyntaxError(this.errorMessage('The initializer does not contain declarations, For Of Let, "for-await-of"'));
|
|
655
|
+
}
|
|
656
|
+
eachVariable = this.parseLeftHandSideExpression();
|
|
657
|
+
}
|
|
658
|
+
this.expectContextualKeyword('of');
|
|
659
|
+
this.setAcceptIN(true);
|
|
660
|
+
const iterable = this.parseAssignmentExpression();
|
|
661
|
+
this.restoreAcceptIN();
|
|
662
|
+
this.expect(Token.RPAREN);
|
|
663
|
+
const body = this.parseStatement();
|
|
664
|
+
return new ForAwaitOfNode(eachVariable, iterable, body);
|
|
665
|
+
}
|
|
666
|
+
parseVariableDeclarations(varContext) {
|
|
667
|
+
let mode;
|
|
668
|
+
const token = this.peek().token;
|
|
669
|
+
switch (token) {
|
|
670
|
+
case Token.CONST:
|
|
671
|
+
this.consume(token);
|
|
672
|
+
mode = 'const';
|
|
673
|
+
break;
|
|
674
|
+
case Token.VAR:
|
|
675
|
+
this.consume(token);
|
|
676
|
+
mode = 'var';
|
|
677
|
+
break;
|
|
678
|
+
case Token.LET:
|
|
679
|
+
default:
|
|
680
|
+
this.consume(token);
|
|
681
|
+
mode = 'let';
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
const variables = [];
|
|
685
|
+
do {
|
|
686
|
+
let name;
|
|
687
|
+
let value;
|
|
688
|
+
if (Token.isAnyIdentifier(this.peek().token)) {
|
|
689
|
+
name = this.parseAndClassifyIdentifier(this.next());
|
|
690
|
+
if (isStrict(this.languageMode) && this.isEvalOrArguments(name)) {
|
|
691
|
+
throw new Error(this.errorMessage(`Strict Eval Arguments`));
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
name = this.parseBindingPattern(true);
|
|
696
|
+
}
|
|
697
|
+
if (this.check(Token.ASSIGN)) {
|
|
698
|
+
this.setAcceptIN(varContext !== VariableDeclarationContext.ForStatement);
|
|
699
|
+
value = this.parseAssignmentExpression();
|
|
700
|
+
this.restoreAcceptIN();
|
|
701
|
+
}
|
|
702
|
+
else if (!this.peekInOrOf()) {
|
|
703
|
+
if (mode === 'const' && (name === undefined || value === undefined)) {
|
|
704
|
+
throw new Error(this.errorMessage(`Declaration Missing Initializer`));
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
variables.push(new VariableDeclarator(name, value));
|
|
708
|
+
} while (this.check(Token.COMMA));
|
|
709
|
+
return new VariableDeclarationNode(variables, mode);
|
|
710
|
+
}
|
|
711
|
+
parseBindingPattern(isPattern) {
|
|
712
|
+
const token = this.peek().token;
|
|
713
|
+
if (Token.isAnyIdentifier(token)) {
|
|
714
|
+
const name = this.parseAndClassifyIdentifier(this.next());
|
|
715
|
+
if (isStrict(this.languageMode) && this.isEvalOrArguments(name)) {
|
|
716
|
+
throw new Error(this.errorMessage(`Strict Eval Arguments`));
|
|
717
|
+
}
|
|
718
|
+
return name;
|
|
719
|
+
}
|
|
720
|
+
if (token == Token.LBRACK) {
|
|
721
|
+
return this.parseArrayLiteral(isPattern);
|
|
722
|
+
}
|
|
723
|
+
else if (token == Token.LBRACE) {
|
|
724
|
+
return this.parseObjectLiteral(isPattern);
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${this.next().getValue()}`));
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
parseAndClassifyIdentifier(next) {
|
|
731
|
+
if (Token.isInRangeIdentifierAndAsync(next.token)) {
|
|
732
|
+
const name = next.getValue();
|
|
733
|
+
if (this.isArguments(name) && this.shouldBanArguments()) {
|
|
734
|
+
throw new SyntaxError(this.errorMessage('Arguments Disallowed In Initializer And Static Block'));
|
|
735
|
+
}
|
|
736
|
+
return name;
|
|
737
|
+
}
|
|
738
|
+
if (!Token.isValidIdentifier(next.token, this.languageMode, this.isGenerator(), this.isAwaitAsIdentifierDisallowed())) {
|
|
739
|
+
throw new SyntaxError(this.errorMessage('Invalid Identifier'));
|
|
740
|
+
}
|
|
741
|
+
if (next.isType(Token.AWAIT)) {
|
|
742
|
+
return next.getValue();
|
|
743
|
+
}
|
|
744
|
+
return next.getValue();
|
|
745
|
+
}
|
|
746
|
+
parseContinueStatement() {
|
|
747
|
+
this.consume(Token.CONTINUE);
|
|
748
|
+
let label;
|
|
749
|
+
if (!this.scanner.hasLineTerminatorBeforeNext() &&
|
|
750
|
+
!Token.isAutoSemicolon(this.peek().token)) {
|
|
751
|
+
label = this.parseIdentifier();
|
|
752
|
+
}
|
|
753
|
+
this.expectSemicolon();
|
|
754
|
+
return label ? new ContinueStatement(label) : ContinueStatement.CONTINUE_INSTANCE;
|
|
755
|
+
}
|
|
756
|
+
parseBreakStatement() {
|
|
757
|
+
this.consume(Token.BREAK);
|
|
758
|
+
let label;
|
|
759
|
+
if (!this.scanner.hasLineTerminatorBeforeNext() &&
|
|
760
|
+
!Token.isAutoSemicolon(this.peek().token)) {
|
|
761
|
+
label = this.parseIdentifier();
|
|
762
|
+
}
|
|
763
|
+
this.expectSemicolon();
|
|
764
|
+
return label ? new BreakStatement(label) : BreakStatement.BREAK_INSTANCE;
|
|
765
|
+
}
|
|
766
|
+
parseReturnStatement() {
|
|
767
|
+
this.consume(Token.RETURN);
|
|
768
|
+
const tokenExp = this.peek();
|
|
769
|
+
let returnValue;
|
|
770
|
+
if (this.scanner.hasLineTerminatorBeforeNext() || Token.isAutoSemicolon(tokenExp.token)) {
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
returnValue = this.parseExpression();
|
|
774
|
+
}
|
|
775
|
+
this.expectSemicolon();
|
|
776
|
+
return new ReturnStatement(returnValue);
|
|
777
|
+
}
|
|
778
|
+
parseExpressionOrLabelledStatement(allowFunction) {
|
|
779
|
+
switch (this.peek().token) {
|
|
780
|
+
case Token.FUNCTION:
|
|
781
|
+
case Token.LBRACE:
|
|
782
|
+
throw new Error(this.errorMessage(`Unreachable state`));
|
|
783
|
+
case Token.CLASS:
|
|
784
|
+
throw new Error(this.errorMessage(`Unexpected Token ${this.next().getValue().toString()}`));
|
|
785
|
+
case Token.LET: {
|
|
786
|
+
const nextNext = this.peekAhead();
|
|
787
|
+
if (nextNext.isNotType(Token.LBRACK) &&
|
|
788
|
+
((nextNext.isNotType(Token.LBRACE) && nextNext.isNotType(Token.IDENTIFIER)))) {
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
throw new Error(this.errorMessage(`Unexpected Lexical Declaration ${this.position()}`));
|
|
792
|
+
}
|
|
793
|
+
default:
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
const startsWithIdentifier = Token.isAnyIdentifier(this.peek().token);
|
|
797
|
+
this.setAcceptIN(true);
|
|
798
|
+
const expression = this.parseExpressionCoverGrammar();
|
|
799
|
+
if (this.peek().isType(Token.COLON) && startsWithIdentifier && this.isIdentifier(expression)) {
|
|
800
|
+
this.consume(Token.COLON);
|
|
801
|
+
if (this.peek().isType(Token.FUNCTION)
|
|
802
|
+
&& isSloppy(this.languageMode)
|
|
803
|
+
&& allowFunction == AllowLabelledFunctionStatement.AllowLabelledFunctionStatement) {
|
|
804
|
+
const result = this.parseFunctionDeclaration();
|
|
805
|
+
this.restoreAcceptIN();
|
|
806
|
+
return new LabeledStatement(expression, result);
|
|
807
|
+
}
|
|
808
|
+
const result = this.parseStatement(allowFunction);
|
|
809
|
+
this.restoreAcceptIN();
|
|
810
|
+
return new LabeledStatement(expression, result);
|
|
811
|
+
}
|
|
812
|
+
this.restoreAcceptIN();
|
|
813
|
+
this.expectSemicolon();
|
|
814
|
+
return expression;
|
|
815
|
+
}
|
|
816
|
+
parseExpression() {
|
|
817
|
+
this.setAcceptIN(true);
|
|
818
|
+
const result = this.parseExpressionCoverGrammar();
|
|
819
|
+
this.restoreAcceptIN();
|
|
820
|
+
return result;
|
|
821
|
+
}
|
|
822
|
+
parseFunctionDeclaration() {
|
|
823
|
+
this.consume(Token.FUNCTION);
|
|
824
|
+
if (this.check(Token.MUL)) {
|
|
825
|
+
throw new Error(this.errorMessage(`Error Generator In Single Statement Context`));
|
|
826
|
+
}
|
|
827
|
+
return this.parseHoistableDeclaration01(FunctionKind.NormalFunction, undefined, false);
|
|
828
|
+
}
|
|
829
|
+
parseAsyncFunctionLiteral() {
|
|
830
|
+
if (this.current().isNotType(Token.ASYNC)) {
|
|
831
|
+
throw new SyntaxError(this.errorMessage('invalid token'));
|
|
832
|
+
}
|
|
833
|
+
this.consume(Token.FUNCTION);
|
|
834
|
+
let name;
|
|
835
|
+
let syntaxKind = FunctionSyntaxKind.AnonymousExpression;
|
|
836
|
+
let flags = FunctionKind.AsyncFunction;
|
|
837
|
+
if (this.check(Token.MUL)) {
|
|
838
|
+
flags = FunctionKind.AsyncGeneratorFunction;
|
|
839
|
+
}
|
|
840
|
+
if (this.peekAnyIdentifier()) {
|
|
841
|
+
syntaxKind = FunctionSyntaxKind.NamedExpression;
|
|
842
|
+
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
843
|
+
}
|
|
844
|
+
return this.parseFunctionLiteral(flags, syntaxKind, name);
|
|
845
|
+
}
|
|
846
|
+
parseHoistableDeclaration(names, defaultExport) {
|
|
847
|
+
this.consume(Token.FUNCTION);
|
|
848
|
+
let flags = FunctionKind.NormalFunction;
|
|
849
|
+
if (this.check(Token.MUL)) {
|
|
850
|
+
flags = FunctionKind.GeneratorFunction;
|
|
851
|
+
}
|
|
852
|
+
return this.parseHoistableDeclaration01(flags, names, defaultExport);
|
|
853
|
+
}
|
|
854
|
+
parseHoistableDeclaration01(flag, names, defaultExport) {
|
|
855
|
+
if ((flag & ParseFunctionFlag.IsAsync) != 0 && this.check(Token.MUL)) {
|
|
856
|
+
flag |= ParseFunctionFlag.IsGenerator;
|
|
857
|
+
}
|
|
858
|
+
let name;
|
|
859
|
+
if (this.peek().isType(Token.LPAREN)) {
|
|
860
|
+
if (defaultExport) {
|
|
861
|
+
name = new Identifier('default');
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
throw new SyntaxError(this.errorMessage('Missing Function Name'));
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
869
|
+
}
|
|
870
|
+
names?.push(name.toString());
|
|
871
|
+
return this.parseFunctionLiteral(flag, FunctionSyntaxKind.Declaration, name);
|
|
872
|
+
}
|
|
873
|
+
parseIdentifier(kind) {
|
|
874
|
+
kind ?? (kind = this.functionKind);
|
|
875
|
+
const next = this.next();
|
|
876
|
+
if (!Token.isValidIdentifier(next.token, this.languageMode, isGeneratorFunction(kind), isAwaitAsIdentifierDisallowed(kind))) {
|
|
877
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${next.getValue()}`));
|
|
878
|
+
}
|
|
879
|
+
if (next.isType(Token.IDENTIFIER)) {
|
|
880
|
+
return next.getValue();
|
|
881
|
+
}
|
|
882
|
+
return this.getIdentifier();
|
|
883
|
+
}
|
|
884
|
+
getIdentifier() {
|
|
885
|
+
const current = this.current();
|
|
886
|
+
switch (current.token) {
|
|
887
|
+
case Token.AWAIT:
|
|
888
|
+
return AwaitIdentifier;
|
|
889
|
+
case Token.ASYNC:
|
|
890
|
+
return AsyncIdentifier;
|
|
891
|
+
case Token.IDENTIFIER:
|
|
892
|
+
case Token.PRIVATE_NAME:
|
|
893
|
+
return current.getValue();
|
|
894
|
+
default:
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
const name = current.getValue().toString();
|
|
898
|
+
if (name == 'constructor') {
|
|
899
|
+
return ConstructorIdentifier;
|
|
900
|
+
}
|
|
901
|
+
if (name == 'name') {
|
|
902
|
+
return NameIdentifier;
|
|
903
|
+
}
|
|
904
|
+
if (name == 'eval') {
|
|
905
|
+
return EvalIdentifier;
|
|
906
|
+
}
|
|
907
|
+
else if (name == 'arguments') {
|
|
908
|
+
return ArgumentsIdentifier;
|
|
909
|
+
}
|
|
910
|
+
return current.getValue();
|
|
911
|
+
}
|
|
912
|
+
parseFunctionLiteral(flag, functionSyntaxKind, name) {
|
|
913
|
+
this.setFunctionKind(flag);
|
|
914
|
+
const functionInfo = {};
|
|
915
|
+
this.expect(Token.LPAREN);
|
|
916
|
+
const formals = this.parseFormalParameterList(functionInfo);
|
|
917
|
+
this.expect(Token.RPAREN);
|
|
918
|
+
this.expect(Token.LBRACE);
|
|
919
|
+
this.setAcceptIN(true);
|
|
920
|
+
const body = this.parseFunctionBody(flag, FunctionBodyType.BLOCK, functionSyntaxKind);
|
|
921
|
+
this.restoreAcceptIN();
|
|
922
|
+
this.restoreFunctionKind();
|
|
923
|
+
const bodyBlock = new BlockStatement(body);
|
|
924
|
+
if (name) {
|
|
925
|
+
return new FunctionDeclaration(formals, bodyBlock, isAsyncFunction(flag), isGeneratorFunction(flag), name);
|
|
926
|
+
}
|
|
927
|
+
return new FunctionExpression(formals, bodyBlock, isAsyncFunction(flag), isGeneratorFunction(flag));
|
|
928
|
+
}
|
|
929
|
+
parseFunctionBody(kind, bodyType, functionSyntaxKind) {
|
|
930
|
+
let innerBody;
|
|
931
|
+
if (bodyType == FunctionBodyType.EXPRESSION) {
|
|
932
|
+
innerBody = this.parseAssignmentExpression();
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
const closing_token = functionSyntaxKind == FunctionSyntaxKind.Wrapped ? Token.EOS : Token.RBRACE;
|
|
936
|
+
if (isAsyncGeneratorFunction(kind)) {
|
|
937
|
+
innerBody = this.parseAndRewriteAsyncGeneratorFunctionBody(kind);
|
|
938
|
+
}
|
|
939
|
+
else if (isGeneratorFunction(kind)) {
|
|
940
|
+
innerBody = this.parseAndRewriteGeneratorFunctionBody(kind);
|
|
941
|
+
}
|
|
942
|
+
else if (isAsyncFunction(kind)) {
|
|
943
|
+
innerBody = this.parseAsyncFunctionBody();
|
|
944
|
+
}
|
|
945
|
+
else {
|
|
946
|
+
innerBody = this.parseStatementList(closing_token);
|
|
947
|
+
}
|
|
948
|
+
this.expect(closing_token);
|
|
949
|
+
}
|
|
950
|
+
return innerBody;
|
|
951
|
+
}
|
|
952
|
+
parseAndRewriteAsyncGeneratorFunctionBody(kind) {
|
|
953
|
+
return this.parseStatementList(Token.RBRACE);
|
|
954
|
+
}
|
|
955
|
+
parseAndRewriteGeneratorFunctionBody(kind) {
|
|
956
|
+
return this.parseStatementList(Token.RBRACE);
|
|
957
|
+
}
|
|
958
|
+
parseAsyncFunctionBody() {
|
|
959
|
+
return this.parseStatementList(Token.RBRACE);
|
|
960
|
+
}
|
|
961
|
+
parseStatementList(endToken) {
|
|
962
|
+
if (this.peek().test((token, value) => Token.STRING === token && 'use strict' === value.getValue())) {
|
|
963
|
+
this.languageMode = LanguageMode.Strict;
|
|
964
|
+
}
|
|
965
|
+
const list = [];
|
|
966
|
+
while (this.peek().isNotType(endToken)) {
|
|
967
|
+
const stat = this.parseStatementListItem();
|
|
968
|
+
if (!stat) {
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
if (this.isEmptyStatement(stat)) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
list.push(stat);
|
|
975
|
+
}
|
|
976
|
+
return list;
|
|
977
|
+
}
|
|
978
|
+
parseFormalParameterList(functionInfo) {
|
|
979
|
+
const parameters = [];
|
|
980
|
+
if (this.peek().isNotType(Token.RPAREN)) {
|
|
981
|
+
while (true) {
|
|
982
|
+
const param = this.parseFormalParameter(functionInfo);
|
|
983
|
+
parameters.push(param);
|
|
984
|
+
if (functionInfo.rest) {
|
|
985
|
+
if (this.peek().isType(Token.COMMA)) {
|
|
986
|
+
throw new Error(this.errorMessage(`Param After Rest`));
|
|
987
|
+
}
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
if (!this.check(Token.COMMA))
|
|
991
|
+
break;
|
|
992
|
+
if (this.peek().isType(Token.RPAREN)) {
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return parameters;
|
|
998
|
+
}
|
|
999
|
+
parseFormalParameter(functionInfo) {
|
|
1000
|
+
functionInfo.rest = this.check(Token.ELLIPSIS);
|
|
1001
|
+
let pattern = this.parseBindingPattern(true);
|
|
1002
|
+
let initializer;
|
|
1003
|
+
if (this.check(Token.ASSIGN)) {
|
|
1004
|
+
if (functionInfo.rest) {
|
|
1005
|
+
throw new Error(this.errorMessage(`Rest Default Initializer`));
|
|
1006
|
+
}
|
|
1007
|
+
this.setAcceptIN(true);
|
|
1008
|
+
const value = this.parseAssignmentExpression();
|
|
1009
|
+
this.restoreAcceptIN();
|
|
1010
|
+
initializer = new Param(pattern, value);
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
initializer = new Param(pattern);
|
|
1014
|
+
}
|
|
1015
|
+
return initializer;
|
|
1016
|
+
}
|
|
1017
|
+
parseExpressionCoverGrammar() {
|
|
1018
|
+
const list = [];
|
|
1019
|
+
let expression;
|
|
1020
|
+
while (true) {
|
|
1021
|
+
if (this.peek().isType(Token.ELLIPSIS)) {
|
|
1022
|
+
return this.parseArrowParametersWithRest(list);
|
|
1023
|
+
}
|
|
1024
|
+
expression = this.parseAssignmentExpressionCoverGrammar();
|
|
1025
|
+
list.push(expression);
|
|
1026
|
+
if (!this.check(Token.COMMA))
|
|
1027
|
+
break;
|
|
1028
|
+
if (this.peek().isType(Token.RPAREN) && this.peekAhead().isType(Token.ARROW)) {
|
|
1029
|
+
break;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
if (list.length == 1)
|
|
1033
|
+
return expression;
|
|
1034
|
+
return this.expressionListToExpression(list);
|
|
1035
|
+
}
|
|
1036
|
+
parseArrowParametersWithRest(list) {
|
|
1037
|
+
this.consume(Token.ELLIPSIS);
|
|
1038
|
+
const pattern = this.parseBindingPattern(true);
|
|
1039
|
+
if (this.peek().isType(Token.ASSIGN)) {
|
|
1040
|
+
throw new Error(this.errorMessage(`Error A rest parameter cannot have an initializer`));
|
|
1041
|
+
}
|
|
1042
|
+
if (this.peek().isType(Token.COMMA)) {
|
|
1043
|
+
throw new Error(this.errorMessage(`Error A rest parameter or binding pattern may not have a trailing comma`));
|
|
1044
|
+
}
|
|
1045
|
+
if (this.peek().isNotType(Token.RPAREN) || this.peekAhead().isNotType(Token.ARROW)) {
|
|
1046
|
+
throw new Error(this.errorMessage(`Error Unexpected Token At ${this.position()}`));
|
|
1047
|
+
}
|
|
1048
|
+
list.push(new SpreadElement(pattern));
|
|
1049
|
+
return this.expressionListToExpression(list);
|
|
1050
|
+
}
|
|
1051
|
+
expressionListToExpression(list) {
|
|
1052
|
+
const first = list[0];
|
|
1053
|
+
if (list.length === 1) {
|
|
1054
|
+
return first;
|
|
1055
|
+
}
|
|
1056
|
+
if (first instanceof SequenceExpression) {
|
|
1057
|
+
first.getExpressions().push(...list.slice(1));
|
|
1058
|
+
return first;
|
|
1059
|
+
}
|
|
1060
|
+
return new SequenceExpression(list);
|
|
1061
|
+
}
|
|
1062
|
+
parseMemberExpression() {
|
|
1063
|
+
const result = this.parsePrimaryExpression();
|
|
1064
|
+
return this.parseMemberExpressionContinuation(result);
|
|
1065
|
+
}
|
|
1066
|
+
toParamNode(expression) {
|
|
1067
|
+
if (expression instanceof AssignmentExpression) {
|
|
1068
|
+
return new Param(expression.getLeft(), expression.getRight());
|
|
1069
|
+
}
|
|
1070
|
+
if (expression instanceof GroupingExpression) {
|
|
1071
|
+
return new Param(expression.getNode());
|
|
1072
|
+
}
|
|
1073
|
+
return new Param(expression);
|
|
1074
|
+
}
|
|
1075
|
+
parsePrimaryExpression() {
|
|
1076
|
+
let token = this.peek();
|
|
1077
|
+
if (Token.isAnyIdentifier(token.token)) {
|
|
1078
|
+
this.consume(token.token);
|
|
1079
|
+
let kind = FunctionKind.NormalFunction;
|
|
1080
|
+
if (token.isType(Token.ASYNC) && !this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1081
|
+
if (this.peek().isType(Token.FUNCTION)) {
|
|
1082
|
+
return this.parseAsyncFunctionLiteral();
|
|
1083
|
+
}
|
|
1084
|
+
;
|
|
1085
|
+
if (Token.isAnyIdentifier(this.peek().token) && this.peekAhead().isType(Token.ARROW)) {
|
|
1086
|
+
token = this.next();
|
|
1087
|
+
kind = FunctionKind.AsyncFunction;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (this.peek().isType(Token.ARROW)) {
|
|
1091
|
+
this.setFunctionKind(kind);
|
|
1092
|
+
const name = this.parseAndClassifyIdentifier(token);
|
|
1093
|
+
const params = [];
|
|
1094
|
+
if (name instanceof SequenceExpression) {
|
|
1095
|
+
params.push(...name.getExpressions().map(this.toParamNode));
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
params.push(this.toParamNode(name));
|
|
1099
|
+
}
|
|
1100
|
+
const arrow = this.parseArrowFunctionLiteral(params, kind);
|
|
1101
|
+
this.restoreFunctionKind();
|
|
1102
|
+
return arrow;
|
|
1103
|
+
}
|
|
1104
|
+
return this.parseAndClassifyIdentifier(token);
|
|
1105
|
+
}
|
|
1106
|
+
if (Token.isLiteral(token.token)) {
|
|
1107
|
+
return expressionFromLiteral(this.next());
|
|
1108
|
+
}
|
|
1109
|
+
switch (token.token) {
|
|
1110
|
+
case Token.NEW:
|
|
1111
|
+
return this.parseMemberWithPresentNewPrefixesExpression();
|
|
1112
|
+
case Token.THIS:
|
|
1113
|
+
this.consume(Token.THIS);
|
|
1114
|
+
return ThisNode;
|
|
1115
|
+
case Token.DIV:
|
|
1116
|
+
case Token.DIV_ASSIGN:
|
|
1117
|
+
return this.parseRegExpLiteral();
|
|
1118
|
+
case Token.FUNCTION:
|
|
1119
|
+
return this.parseFunctionExpression();
|
|
1120
|
+
case Token.SUPER: {
|
|
1121
|
+
return this.parseSuperExpression();
|
|
1122
|
+
}
|
|
1123
|
+
case Token.IMPORT:
|
|
1124
|
+
return this.parseImportExpressions();
|
|
1125
|
+
case Token.LBRACK:
|
|
1126
|
+
return this.parseArrayLiteral(false);
|
|
1127
|
+
case Token.LBRACE:
|
|
1128
|
+
return this.parseObjectLiteral(false);
|
|
1129
|
+
case Token.LPAREN: {
|
|
1130
|
+
this.consume(Token.LPAREN);
|
|
1131
|
+
if (this.check(Token.RPAREN)) {
|
|
1132
|
+
if (!this.peek().isType(Token.ARROW)) {
|
|
1133
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${Token.RPAREN.getName()}`));
|
|
1134
|
+
}
|
|
1135
|
+
const result = new SequenceExpression([]);
|
|
1136
|
+
this.markParenthesized(result);
|
|
1137
|
+
return result;
|
|
1138
|
+
}
|
|
1139
|
+
this.setAcceptIN(true);
|
|
1140
|
+
const expression = this.parseExpressionCoverGrammar();
|
|
1141
|
+
this.markParenthesized(expression);
|
|
1142
|
+
this.expect(Token.RPAREN);
|
|
1143
|
+
this.restoreAcceptIN();
|
|
1144
|
+
return expression;
|
|
1145
|
+
}
|
|
1146
|
+
case Token.CLASS: {
|
|
1147
|
+
return this.parseClassExpression();
|
|
1148
|
+
}
|
|
1149
|
+
case Token.TEMPLATE_SPAN:
|
|
1150
|
+
case Token.TEMPLATE_TAIL:
|
|
1151
|
+
return this.parseTemplateLiteral();
|
|
1152
|
+
default:
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(this.next())}`));
|
|
1156
|
+
}
|
|
1157
|
+
parseTemplateLiteral(tag) {
|
|
1158
|
+
let next = this.peek();
|
|
1159
|
+
if (!Token.isTemplate(next.token)) {
|
|
1160
|
+
throw new SyntaxError(this.errorMessage(`Unexpected Token: ${JSON.stringify(this.next())}`));
|
|
1161
|
+
}
|
|
1162
|
+
if (next.isType(Token.TEMPLATE_TAIL)) {
|
|
1163
|
+
this.consume(Token.TEMPLATE_TAIL);
|
|
1164
|
+
const string = next.getValue().string;
|
|
1165
|
+
return this.createTemplateLiteralExpressionNode([string], [], tag);
|
|
1166
|
+
}
|
|
1167
|
+
this.consume(Token.TEMPLATE_SPAN);
|
|
1168
|
+
const expressions = [];
|
|
1169
|
+
const strings = [];
|
|
1170
|
+
strings.push(next.getValue().string);
|
|
1171
|
+
do {
|
|
1172
|
+
this.setAcceptIN(true);
|
|
1173
|
+
const expression = this.parseExpressionCoverGrammar();
|
|
1174
|
+
expressions.push(expression);
|
|
1175
|
+
next = this.next();
|
|
1176
|
+
if (next.isNotType(Token.RBRACE)) {
|
|
1177
|
+
this.restoreAcceptIN();
|
|
1178
|
+
throw new SyntaxError(this.errorMessage('Unterminated Template Expr'));
|
|
1179
|
+
}
|
|
1180
|
+
next = this.scanner.scanTemplateContinuation();
|
|
1181
|
+
strings.push(next.getValue().string);
|
|
1182
|
+
this.restoreAcceptIN();
|
|
1183
|
+
} while (next.isType(Token.TEMPLATE_SPAN));
|
|
1184
|
+
if (next.isNotType(Token.TEMPLATE_TAIL)) {
|
|
1185
|
+
throw new SyntaxError(this.errorMessage(`Unexpected Token: ${JSON.stringify(next)}`));
|
|
1186
|
+
}
|
|
1187
|
+
return this.createTemplateLiteralExpressionNode(strings, expressions, tag);
|
|
1188
|
+
}
|
|
1189
|
+
createTemplateLiteralExpressionNode(strings, expressions, tag) {
|
|
1190
|
+
if (tag) {
|
|
1191
|
+
return new TaggedTemplateExpression(tag, strings, expressions);
|
|
1192
|
+
}
|
|
1193
|
+
else {
|
|
1194
|
+
return new TemplateLiteral(strings, expressions);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
parseMemberWithPresentNewPrefixesExpression() {
|
|
1198
|
+
this.consume(Token.NEW);
|
|
1199
|
+
let result;
|
|
1200
|
+
if (this.peek().isType(Token.IMPORT) && this.peekAhead().isType(Token.LPAREN)) {
|
|
1201
|
+
throw new SyntaxError(this.errorMessage(`Import Call Not New Expression`));
|
|
1202
|
+
}
|
|
1203
|
+
else if (this.peek().isType(Token.PERIOD)) {
|
|
1204
|
+
result = this.parseNewTargetExpression();
|
|
1205
|
+
return this.parseMemberExpressionContinuation(result);
|
|
1206
|
+
}
|
|
1207
|
+
else {
|
|
1208
|
+
result = this.parseMemberExpression();
|
|
1209
|
+
if (result === SuperIdentifier) {
|
|
1210
|
+
throw new SyntaxError(this.errorMessage(`Unexpected Super, new super() is never allowed`));
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
if (this.peek().isType(Token.LPAREN)) {
|
|
1214
|
+
const args = this.parseArguments();
|
|
1215
|
+
result = new NewExpression(result, args);
|
|
1216
|
+
return this.parseMemberExpressionContinuation(result);
|
|
1217
|
+
}
|
|
1218
|
+
if (this.peek().isType(Token.QUESTION_PERIOD)) {
|
|
1219
|
+
throw new SyntaxError(this.errorMessage(`Optional Chaining with New not allowed, new x?.y()`));
|
|
1220
|
+
}
|
|
1221
|
+
return new NewExpression(result);
|
|
1222
|
+
}
|
|
1223
|
+
parseArguments(maybeArrow) {
|
|
1224
|
+
this.consume(Token.LPAREN);
|
|
1225
|
+
const args = [];
|
|
1226
|
+
while (this.peek().isNotType(Token.RPAREN)) {
|
|
1227
|
+
const isSpread = this.check(Token.ELLIPSIS);
|
|
1228
|
+
this.setAcceptIN(true);
|
|
1229
|
+
let argument = this.parseAssignmentExpressionCoverGrammar();
|
|
1230
|
+
if (ParsingArrowHeadFlag.MaybeArrowHead === maybeArrow) {
|
|
1231
|
+
if (isSpread) {
|
|
1232
|
+
if (argument instanceof AssignmentExpression) {
|
|
1233
|
+
this.restoreAcceptIN();
|
|
1234
|
+
throw new Error(this.errorMessage(` Rest parameter may not have a default initializer'`));
|
|
1235
|
+
}
|
|
1236
|
+
if (this.peek().isType(Token.COMMA)) {
|
|
1237
|
+
this.restoreAcceptIN();
|
|
1238
|
+
throw new Error(this.errorMessage(`parsing '...spread,arg =>'`));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (isSpread) {
|
|
1243
|
+
argument = new SpreadElement(argument);
|
|
1244
|
+
}
|
|
1245
|
+
args.push(argument);
|
|
1246
|
+
this.restoreAcceptIN();
|
|
1247
|
+
if (!this.check(Token.COMMA))
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
if (!this.check(Token.RPAREN)) {
|
|
1251
|
+
throw new Error(this.errorMessage(`parsing arguments call, expecting ')'`));
|
|
1252
|
+
}
|
|
1253
|
+
return args;
|
|
1254
|
+
}
|
|
1255
|
+
parseAssignmentExpressionCoverGrammar() {
|
|
1256
|
+
if (this.peek().isType(Token.YIELD) && isGeneratorFunction(this.functionKind)) {
|
|
1257
|
+
return this.parseYieldExpression();
|
|
1258
|
+
}
|
|
1259
|
+
let expression = this.parseConditionalExpression();
|
|
1260
|
+
const op = this.peek().token;
|
|
1261
|
+
if (!Token.isArrowOrAssignmentOp(op)) {
|
|
1262
|
+
this.clearParenthesized(expression);
|
|
1263
|
+
return expression;
|
|
1264
|
+
}
|
|
1265
|
+
;
|
|
1266
|
+
if (op === Token.ARROW) {
|
|
1267
|
+
if (!this.isIdentifier(expression) && !this.isParenthesized(expression)) {
|
|
1268
|
+
throw new Error(this.errorMessage(`Malformed Arrow Fun Param List`));
|
|
1269
|
+
}
|
|
1270
|
+
const kind = FunctionKind.NormalFunction;
|
|
1271
|
+
this.setFunctionKind(kind);
|
|
1272
|
+
let arrow;
|
|
1273
|
+
if (expression instanceof SequenceExpression) {
|
|
1274
|
+
const params = expression.getExpressions().map(expr => new Param(expr));
|
|
1275
|
+
const last = params.at(-1)?.getIdentifier();
|
|
1276
|
+
if (last instanceof SpreadElement) {
|
|
1277
|
+
const arg = last.getArgument();
|
|
1278
|
+
let param = arg;
|
|
1279
|
+
if (arg instanceof ArrayExpression) {
|
|
1280
|
+
param = new ArrayPattern(arg.getElements());
|
|
1281
|
+
}
|
|
1282
|
+
else if (arg instanceof ObjectExpression) {
|
|
1283
|
+
param = new ObjectPattern(arg.getProperties());
|
|
1284
|
+
}
|
|
1285
|
+
params[params.length - 1] = new Param(new RestElement(param));
|
|
1286
|
+
}
|
|
1287
|
+
arrow = this.parseArrowFunctionLiteral(params, FunctionKind.NormalFunction);
|
|
1288
|
+
}
|
|
1289
|
+
else if (expression instanceof GroupingExpression) {
|
|
1290
|
+
arrow = this.parseArrowFunctionLiteral([new Param(expression.getNode())], FunctionKind.NormalFunction);
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
this.clearParenthesized(expression);
|
|
1294
|
+
arrow = this.parseArrowFunctionLiteral([new Param(expression)], FunctionKind.NormalFunction);
|
|
1295
|
+
}
|
|
1296
|
+
this.restoreFunctionKind();
|
|
1297
|
+
return arrow;
|
|
1298
|
+
}
|
|
1299
|
+
if (this.isAssignableIdentifier(expression)) {
|
|
1300
|
+
}
|
|
1301
|
+
else if (this.isProperty(expression)) {
|
|
1302
|
+
}
|
|
1303
|
+
else if (this.isPattern(expression) && Token.isAssignment(op)) {
|
|
1304
|
+
expression = expression instanceof ObjectExpression
|
|
1305
|
+
? new ObjectPattern(expression.getProperties())
|
|
1306
|
+
: new ArrayPattern(expression.getElements());
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
if (!this.isValidReferenceExpression(expression)) {
|
|
1310
|
+
throw new Error(this.errorMessage(`Invalid Reference Expression`));
|
|
1311
|
+
}
|
|
1312
|
+
if (Token.isLogicalAssignmentOp(op)) {
|
|
1313
|
+
throw new Error(this.errorMessage(`Invalid Lhs In Assignment`));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
this.consume(op);
|
|
1317
|
+
const right = this.parseAssignmentExpression();
|
|
1318
|
+
if (!Token.isAssignment(op)) {
|
|
1319
|
+
throw new Error(this.errorMessage(`Invalid Destructuring Target`));
|
|
1320
|
+
}
|
|
1321
|
+
return new AssignmentExpression(op.getName(), expression, right);
|
|
1322
|
+
}
|
|
1323
|
+
parseAssignmentExpression() {
|
|
1324
|
+
return this.parseAssignmentExpressionCoverGrammar();
|
|
1325
|
+
}
|
|
1326
|
+
parseArrowFunctionLiteral(parameters, kind) {
|
|
1327
|
+
if (this.peek().isNotType(Token.ARROW)) {
|
|
1328
|
+
throw new SyntaxError(this.errorMessage('SyntaxError Expecting Arrow Token'));
|
|
1329
|
+
}
|
|
1330
|
+
if (this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1331
|
+
throw new SyntaxError(this.errorMessage('Unexpected Token "\n" a line terminator after arrow token"'));
|
|
1332
|
+
}
|
|
1333
|
+
let body;
|
|
1334
|
+
let has_braces = true;
|
|
1335
|
+
this.consume(Token.ARROW);
|
|
1336
|
+
if (this.peek().isType(Token.LBRACE)) {
|
|
1337
|
+
this.consume(Token.LBRACE);
|
|
1338
|
+
this.setStatue(true, kind);
|
|
1339
|
+
body = this.parseFunctionBody(kind, FunctionBodyType.BLOCK, FunctionSyntaxKind.AnonymousExpression);
|
|
1340
|
+
this.restoreStatue();
|
|
1341
|
+
}
|
|
1342
|
+
else {
|
|
1343
|
+
has_braces = false;
|
|
1344
|
+
body = this.parseFunctionBody(kind, FunctionBodyType.EXPRESSION, FunctionSyntaxKind.AnonymousExpression);
|
|
1345
|
+
}
|
|
1346
|
+
return new ArrowFunctionExpression(parameters, body, !has_braces, isAsyncFunction(kind));
|
|
1347
|
+
}
|
|
1348
|
+
parseRegExpLiteral() {
|
|
1349
|
+
if (!this.scanner.scanRegExpPattern()) {
|
|
1350
|
+
throw new Error('Unterminated RegExp');
|
|
1351
|
+
}
|
|
1352
|
+
return this.scanner.currentToken().getValue();
|
|
1353
|
+
}
|
|
1354
|
+
parseArrayLiteral(isPattern) {
|
|
1355
|
+
this.consume(Token.LBRACK);
|
|
1356
|
+
let first_spread_index = -1;
|
|
1357
|
+
const values = [];
|
|
1358
|
+
while (!this.check(Token.RBRACK)) {
|
|
1359
|
+
let elem;
|
|
1360
|
+
if (this.peek().isType(Token.COMMA)) {
|
|
1361
|
+
elem = null;
|
|
1362
|
+
}
|
|
1363
|
+
else if (this.check(Token.ELLIPSIS)) {
|
|
1364
|
+
this.setAcceptIN(true);
|
|
1365
|
+
const argument = this.parsePossibleDestructuringSubPattern();
|
|
1366
|
+
this.restoreAcceptIN();
|
|
1367
|
+
elem = new SpreadElement(argument);
|
|
1368
|
+
if (first_spread_index < 0) {
|
|
1369
|
+
first_spread_index = values.length;
|
|
1370
|
+
}
|
|
1371
|
+
if (argument instanceof AssignmentExpression && isPattern) {
|
|
1372
|
+
throw new SyntaxError(this.errorMessage('Invalid Destructuring Target'));
|
|
1373
|
+
}
|
|
1374
|
+
if (this.peek().isType(Token.COMMA)) {
|
|
1375
|
+
throw new SyntaxError(this.errorMessage('Element After Rest'));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
this.setAcceptIN(true);
|
|
1380
|
+
elem = this.parsePossibleDestructuringSubPattern();
|
|
1381
|
+
this.restoreAcceptIN();
|
|
1382
|
+
}
|
|
1383
|
+
values.push(elem);
|
|
1384
|
+
if (this.peek().isNotType(Token.RBRACK)) {
|
|
1385
|
+
this.expect(Token.COMMA);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return new (isPattern ? ArrayPattern : ArrayExpression)(values);
|
|
1389
|
+
}
|
|
1390
|
+
parsePossibleDestructuringSubPattern() {
|
|
1391
|
+
return this.parseAssignmentExpressionCoverGrammar();
|
|
1392
|
+
}
|
|
1393
|
+
parseObjectLiteral(isPattern) {
|
|
1394
|
+
this.consume(Token.LBRACE);
|
|
1395
|
+
const properties = [];
|
|
1396
|
+
while (!this.check(Token.RBRACE)) {
|
|
1397
|
+
const property = this.parseObjectPropertyDefinition(isPattern);
|
|
1398
|
+
properties.push(property);
|
|
1399
|
+
if (this.peek().isNotType(Token.RBRACE)) {
|
|
1400
|
+
this.expect(Token.COMMA);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (isPattern) {
|
|
1404
|
+
return new ObjectPattern(properties);
|
|
1405
|
+
}
|
|
1406
|
+
return new ObjectExpression(properties);
|
|
1407
|
+
}
|
|
1408
|
+
parseObjectPropertyDefinition(isPattern) {
|
|
1409
|
+
const propInfo = new PropertyKindInfo();
|
|
1410
|
+
const nameExpression = this.parseProperty(propInfo);
|
|
1411
|
+
switch (propInfo.kind) {
|
|
1412
|
+
case PropertyKind.Spread:
|
|
1413
|
+
let value = nameExpression;
|
|
1414
|
+
if (isPattern) {
|
|
1415
|
+
value = new RestElement(value.getArgument());
|
|
1416
|
+
}
|
|
1417
|
+
return new Property(value.getArgument(), value, 'init', false, false, propInfo.isComputedName);
|
|
1418
|
+
case PropertyKind.Value: {
|
|
1419
|
+
this.consume(Token.COLON);
|
|
1420
|
+
this.setAcceptIN(true);
|
|
1421
|
+
const value = this.parsePossibleDestructuringSubPattern();
|
|
1422
|
+
this.restoreAcceptIN();
|
|
1423
|
+
return new Property(nameExpression, value, 'init', false, false, propInfo.isComputedName);
|
|
1424
|
+
}
|
|
1425
|
+
case PropertyKind.Assign:
|
|
1426
|
+
case PropertyKind.ShorthandOrClassField:
|
|
1427
|
+
case PropertyKind.Shorthand: {
|
|
1428
|
+
const lhs = new Identifier(propInfo.name);
|
|
1429
|
+
if (!this.isAssignableIdentifier(lhs)) {
|
|
1430
|
+
throw new Error(this.errorMessage('Strict Eval Arguments'));
|
|
1431
|
+
}
|
|
1432
|
+
let value;
|
|
1433
|
+
if (this.peek().isType(Token.ASSIGN)) {
|
|
1434
|
+
this.consume(Token.ASSIGN);
|
|
1435
|
+
this.setAcceptIN(true);
|
|
1436
|
+
const rhs = this.parseAssignmentExpression();
|
|
1437
|
+
this.restoreAcceptIN();
|
|
1438
|
+
value = new AssignmentExpression(Token.ASSIGN.getName(), lhs, rhs);
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
value = lhs;
|
|
1442
|
+
}
|
|
1443
|
+
return new Property(nameExpression, value, 'init', false, propInfo.kind !== PropertyKind.Assign, propInfo.isComputedName);
|
|
1444
|
+
}
|
|
1445
|
+
case PropertyKind.Method: {
|
|
1446
|
+
const kind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);
|
|
1447
|
+
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ? new Identifier(propInfo.name) : undefined);
|
|
1448
|
+
return new Property(nameExpression, value, 'init', true, false, propInfo.isComputedName);
|
|
1449
|
+
}
|
|
1450
|
+
case PropertyKind.AccessorGetter:
|
|
1451
|
+
case PropertyKind.AccessorSetter: {
|
|
1452
|
+
const isGet = propInfo.kind == PropertyKind.AccessorGetter;
|
|
1453
|
+
const kind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);
|
|
1454
|
+
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ? new Identifier(propInfo.name) : undefined);
|
|
1455
|
+
return new Property(nameExpression, value, isGet ? 'get' : 'set', false, false, propInfo.isComputedName);
|
|
1456
|
+
}
|
|
1457
|
+
case PropertyKind.ClassField:
|
|
1458
|
+
case PropertyKind.NotSet:
|
|
1459
|
+
return NullNode;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
parseProperty(propInfo) {
|
|
1463
|
+
let nextToken = this.peek();
|
|
1464
|
+
if (this.check(Token.ASYNC)) {
|
|
1465
|
+
nextToken = this.peek();
|
|
1466
|
+
if (nextToken.isNotType(Token.MUL)
|
|
1467
|
+
&& propInfo.parsePropertyKindFromToken(nextToken.token)
|
|
1468
|
+
|| this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1469
|
+
return AsyncIdentifier;
|
|
1470
|
+
}
|
|
1471
|
+
propInfo.kind = PropertyKind.Method;
|
|
1472
|
+
propInfo.funcFlag = ParseFunctionFlag.IsAsync;
|
|
1473
|
+
}
|
|
1474
|
+
if (this.check(Token.MUL)) {
|
|
1475
|
+
propInfo.kind = PropertyKind.Method;
|
|
1476
|
+
propInfo.funcFlag = ParseFunctionFlag.IsGenerator;
|
|
1477
|
+
}
|
|
1478
|
+
nextToken = this.peek();
|
|
1479
|
+
if (propInfo.kind == PropertyKind.NotSet && nextToken.isType(Token.GET) || nextToken.isType(Token.SET)) {
|
|
1480
|
+
const token = this.next();
|
|
1481
|
+
if (propInfo.parsePropertyKindFromToken(this.peek().token)) {
|
|
1482
|
+
return nextToken.isType(Token.GET) ? GetIdentifier : SetIdentifier;
|
|
1483
|
+
}
|
|
1484
|
+
if (token.isType(Token.GET)) {
|
|
1485
|
+
propInfo.kind = PropertyKind.AccessorGetter;
|
|
1486
|
+
}
|
|
1487
|
+
else if (token.isType(Token.SET)) {
|
|
1488
|
+
propInfo.kind = PropertyKind.AccessorSetter;
|
|
1489
|
+
}
|
|
1490
|
+
nextToken = this.peek();
|
|
1491
|
+
}
|
|
1492
|
+
let propertyName;
|
|
1493
|
+
switch (nextToken.token) {
|
|
1494
|
+
case Token.PRIVATE_NAME:
|
|
1495
|
+
propInfo.isPrivate = true;
|
|
1496
|
+
this.consume(Token.PRIVATE_NAME);
|
|
1497
|
+
if (propInfo.kind == PropertyKind.NotSet) {
|
|
1498
|
+
propInfo.parsePropertyKindFromToken(this.peek().token);
|
|
1499
|
+
}
|
|
1500
|
+
propertyName = this.getIdentifier();
|
|
1501
|
+
propInfo.name = propertyName.getName();
|
|
1502
|
+
if (propInfo.position == PropertyPosition.ObjectLiteral) {
|
|
1503
|
+
throw new TypeError(this.errorMessage('UnexpectedToken PRIVATE_NAME'));
|
|
1504
|
+
}
|
|
1505
|
+
break;
|
|
1506
|
+
case Token.STRING:
|
|
1507
|
+
case Token.NUMBER:
|
|
1508
|
+
case Token.BIGINT:
|
|
1509
|
+
this.consume(nextToken.token);
|
|
1510
|
+
propertyName = nextToken.getValue();
|
|
1511
|
+
propInfo.name = propertyName.getValue();
|
|
1512
|
+
break;
|
|
1513
|
+
case Token.LBRACK:
|
|
1514
|
+
this.consume(Token.LBRACK);
|
|
1515
|
+
this.setAcceptIN(true);
|
|
1516
|
+
propertyName = this.parseAssignmentExpression();
|
|
1517
|
+
this.expect(Token.RBRACK);
|
|
1518
|
+
if (propInfo.kind === PropertyKind.NotSet) {
|
|
1519
|
+
propInfo.parsePropertyKindFromToken(this.peek().token);
|
|
1520
|
+
}
|
|
1521
|
+
propInfo.name = propertyName.toString();
|
|
1522
|
+
this.restoreAcceptIN();
|
|
1523
|
+
return propertyName;
|
|
1524
|
+
case Token.ELLIPSIS:
|
|
1525
|
+
if (propInfo.kind == PropertyKind.NotSet) {
|
|
1526
|
+
this.consume(Token.ELLIPSIS);
|
|
1527
|
+
this.setAcceptIN(true);
|
|
1528
|
+
propertyName = this.parsePossibleDestructuringSubPattern();
|
|
1529
|
+
propInfo.kind = PropertyKind.Spread;
|
|
1530
|
+
if (!this.isValidReferenceExpression(propertyName)) {
|
|
1531
|
+
throw new Error(this.errorMessage('Invalid Rest Binding/Assignment Pattern'));
|
|
1532
|
+
}
|
|
1533
|
+
if (this.peek().isNotType(Token.RBRACE)) {
|
|
1534
|
+
throw new Error(this.errorMessage('Element After Rest'));
|
|
1535
|
+
}
|
|
1536
|
+
propInfo.name = propertyName.toString();
|
|
1537
|
+
this.restoreAcceptIN();
|
|
1538
|
+
return new SpreadElement(propertyName);
|
|
1539
|
+
}
|
|
1540
|
+
default:
|
|
1541
|
+
propertyName = this.parsePropertyOrPrivatePropertyName();
|
|
1542
|
+
propInfo.name = propertyName.toString();
|
|
1543
|
+
break;
|
|
1544
|
+
}
|
|
1545
|
+
if (propInfo.kind === PropertyKind.NotSet) {
|
|
1546
|
+
propInfo.parsePropertyKindFromToken(this.peek().token);
|
|
1547
|
+
}
|
|
1548
|
+
return propertyName;
|
|
1549
|
+
}
|
|
1550
|
+
parseMemberExpressionContinuation(expression) {
|
|
1551
|
+
if (!Token.isMember(this.peek().token))
|
|
1552
|
+
return expression;
|
|
1553
|
+
return this.doParseMemberExpressionContinuation(expression);
|
|
1554
|
+
}
|
|
1555
|
+
doParseMemberExpressionContinuation(expression) {
|
|
1556
|
+
if (!Token.isMember(this.peek().token)) {
|
|
1557
|
+
throw new Error(this.errorMessage(`Parsing member expression`));
|
|
1558
|
+
}
|
|
1559
|
+
do {
|
|
1560
|
+
switch (this.peek().token) {
|
|
1561
|
+
case Token.LBRACK: {
|
|
1562
|
+
this.consume(Token.LBRACK);
|
|
1563
|
+
this.setAcceptIN(true);
|
|
1564
|
+
const index = this.parseExpressionCoverGrammar();
|
|
1565
|
+
expression = new MemberExpression(expression, index, true);
|
|
1566
|
+
this.expect(Token.RBRACK);
|
|
1567
|
+
this.restoreAcceptIN();
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
case Token.PERIOD: {
|
|
1571
|
+
this.consume(Token.PERIOD);
|
|
1572
|
+
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1573
|
+
expression = new MemberExpression(expression, key, false);
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
case Token.TEMPLATE_SPAN:
|
|
1577
|
+
case Token.TEMPLATE_TAIL: {
|
|
1578
|
+
expression = this.parseTemplateLiteral(expression);
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
default:
|
|
1582
|
+
throw new SyntaxError(this.errorMessage('unknown token position'));
|
|
1583
|
+
}
|
|
1584
|
+
} while (Token.isMember(this.peek().token));
|
|
1585
|
+
return expression;
|
|
1586
|
+
}
|
|
1587
|
+
parsePropertyOrPrivatePropertyName() {
|
|
1588
|
+
const next = this.next();
|
|
1589
|
+
if (next.isType(Token.IDENTIFIER) || next.isType(Token.PRIVATE_NAME)) {
|
|
1590
|
+
return next.getValue();
|
|
1591
|
+
}
|
|
1592
|
+
if (Token.isPropertyName(next.token) && next.isNotType(Token.EOS)) {
|
|
1593
|
+
return new Identifier(next.token.getName());
|
|
1594
|
+
}
|
|
1595
|
+
throw new SyntaxError(this.errorMessage(`Parsing property expression: Unexpected Token`));
|
|
1596
|
+
}
|
|
1597
|
+
parsePipelineExpression(expression) {
|
|
1598
|
+
let token;
|
|
1599
|
+
while (Token.isPipelineOperator(token = this.peek().token)) {
|
|
1600
|
+
this.consume(token);
|
|
1601
|
+
expression = this.parsePipelineBody(expression);
|
|
1602
|
+
}
|
|
1603
|
+
return expression;
|
|
1604
|
+
}
|
|
1605
|
+
parsePipelineBody(lhs) {
|
|
1606
|
+
let body;
|
|
1607
|
+
let token = this.peek();
|
|
1608
|
+
switch (token.token) {
|
|
1609
|
+
case Token.FUNCTION:
|
|
1610
|
+
body = this.parseFunctionExpression();
|
|
1611
|
+
break;
|
|
1612
|
+
case Token.ASYNC:
|
|
1613
|
+
this.consume(Token.ASYNC);
|
|
1614
|
+
body = this.parseAsyncFunctionLiteral();
|
|
1615
|
+
break;
|
|
1616
|
+
default:
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
if (body) {
|
|
1620
|
+
return new PipelineExpression(lhs, body);
|
|
1621
|
+
}
|
|
1622
|
+
if (token.isType(Token.LPAREN)) {
|
|
1623
|
+
body = this.parsePrimaryExpression();
|
|
1624
|
+
return new PipelineExpression(lhs, body);
|
|
1625
|
+
}
|
|
1626
|
+
const func = this.parseMemberExpression();
|
|
1627
|
+
let args = [];
|
|
1628
|
+
switch (this.peek().token) {
|
|
1629
|
+
case Token.COLON:
|
|
1630
|
+
do {
|
|
1631
|
+
this.consume(Token.COLON);
|
|
1632
|
+
const isSpread = this.check(Token.ELLIPSIS);
|
|
1633
|
+
if (this.peek().isType(Token.CONDITIONAL)) {
|
|
1634
|
+
this.consume(Token.CONDITIONAL);
|
|
1635
|
+
if (isSpread) {
|
|
1636
|
+
args.push('...?');
|
|
1637
|
+
}
|
|
1638
|
+
else {
|
|
1639
|
+
args.push('?');
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
else {
|
|
1643
|
+
const arg = this.parseAssignmentExpressionCoverGrammar();
|
|
1644
|
+
if (isSpread) {
|
|
1645
|
+
args.push(new SpreadElement(arg));
|
|
1646
|
+
}
|
|
1647
|
+
else {
|
|
1648
|
+
args.push(arg);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
} while (this.peek().isType(Token.COLON));
|
|
1652
|
+
break;
|
|
1653
|
+
case Token.LPAREN:
|
|
1654
|
+
this.consume(Token.LPAREN);
|
|
1655
|
+
let indexed = false;
|
|
1656
|
+
while (this.peek().isNotType(Token.RPAREN)) {
|
|
1657
|
+
const isSpread = this.check(Token.ELLIPSIS);
|
|
1658
|
+
if (this.peek().isType(Token.CONDITIONAL)) {
|
|
1659
|
+
this.consume(Token.CONDITIONAL);
|
|
1660
|
+
indexed = true;
|
|
1661
|
+
if (isSpread) {
|
|
1662
|
+
args.push('...?');
|
|
1663
|
+
}
|
|
1664
|
+
else {
|
|
1665
|
+
args.push('?');
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
else {
|
|
1669
|
+
const arg = this.parseAssignmentExpressionCoverGrammar();
|
|
1670
|
+
if (isSpread) {
|
|
1671
|
+
args.push(new SpreadElement(arg));
|
|
1672
|
+
}
|
|
1673
|
+
else {
|
|
1674
|
+
args.push(arg);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
this.check(Token.COMMA);
|
|
1678
|
+
}
|
|
1679
|
+
this.expect(Token.RPAREN);
|
|
1680
|
+
if (!indexed) {
|
|
1681
|
+
body = new CallExpression(func, args);
|
|
1682
|
+
return new PipelineExpression(lhs, body);
|
|
1683
|
+
}
|
|
1684
|
+
break;
|
|
1685
|
+
default:
|
|
1686
|
+
break;
|
|
1687
|
+
}
|
|
1688
|
+
return new PipelineExpression(lhs, func, args);
|
|
1689
|
+
}
|
|
1690
|
+
parseConditionalExpression() {
|
|
1691
|
+
let expression = this.parseLogicalExpression();
|
|
1692
|
+
expression = this.parsePipelineExpression(expression);
|
|
1693
|
+
return this.peek().isType(Token.CONDITIONAL) ? this.parseConditionalContinuation(expression) : expression;
|
|
1694
|
+
}
|
|
1695
|
+
parseLogicalExpression() {
|
|
1696
|
+
let expression = this.parseBinaryExpression(6);
|
|
1697
|
+
const peek = this.peek();
|
|
1698
|
+
if (peek.isType(Token.AND) || peek.isType(Token.OR)) {
|
|
1699
|
+
const precedence = Token.precedence(peek.token, this.acceptIN);
|
|
1700
|
+
expression = this.parseBinaryContinuation(expression, 4, precedence);
|
|
1701
|
+
}
|
|
1702
|
+
else if (peek.isType(Token.NULLISH)) {
|
|
1703
|
+
expression = this.parseNullishExpression(expression);
|
|
1704
|
+
}
|
|
1705
|
+
return expression;
|
|
1706
|
+
}
|
|
1707
|
+
parseBinaryContinuation(x, prec, prec1) {
|
|
1708
|
+
do {
|
|
1709
|
+
while (Token.precedence(this.peek().token, this.acceptIN) === prec1) {
|
|
1710
|
+
let y;
|
|
1711
|
+
let op = this.next();
|
|
1712
|
+
const is_right_associative = op.isType(Token.EXP);
|
|
1713
|
+
const next_prec = is_right_associative ? prec1 : prec1 + 1;
|
|
1714
|
+
y = this.parseBinaryExpression(next_prec);
|
|
1715
|
+
if (Token.isCompare(op.token)) {
|
|
1716
|
+
let cmp = op.token;
|
|
1717
|
+
switch (op.token) {
|
|
1718
|
+
case Token.NE:
|
|
1719
|
+
cmp = Token.EQ;
|
|
1720
|
+
break;
|
|
1721
|
+
case Token.NE_STRICT:
|
|
1722
|
+
cmp = Token.EQ_STRICT;
|
|
1723
|
+
break;
|
|
1724
|
+
default: break;
|
|
1725
|
+
}
|
|
1726
|
+
x = shortcutNumericLiteralBinaryExpression(x, y, cmp);
|
|
1727
|
+
if (op.isNotType(cmp)) {
|
|
1728
|
+
x = buildUnaryExpression(x, Token.NOT);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
else {
|
|
1732
|
+
x = shortcutNumericLiteralBinaryExpression(x, y, op.token);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
--prec1;
|
|
1736
|
+
} while (prec1 >= prec);
|
|
1737
|
+
return x;
|
|
1738
|
+
}
|
|
1739
|
+
parseBinaryExpression(precedence) {
|
|
1740
|
+
if (this.peek().isType(Token.PRIVATE_NAME)) {
|
|
1741
|
+
const x = this.parsePropertyOrPrivatePropertyName();
|
|
1742
|
+
const precedence1 = Token.precedence(this.peek().token, this.acceptIN);
|
|
1743
|
+
if (this.peek().isNotType(Token.IN) || precedence1 < precedence) {
|
|
1744
|
+
throw new SyntaxError(this.errorMessage('Unexpected Token Token.PRIVATE_NAME "#name"'));
|
|
1745
|
+
}
|
|
1746
|
+
return this.parseBinaryContinuation(x, precedence, precedence1);
|
|
1747
|
+
}
|
|
1748
|
+
const x = this.parseUnaryExpression();
|
|
1749
|
+
const precedence1 = Token.precedence(this.peek().token, this.acceptIN);
|
|
1750
|
+
if (precedence1 >= precedence) {
|
|
1751
|
+
return this.parseBinaryContinuation(x, precedence, precedence1);
|
|
1752
|
+
}
|
|
1753
|
+
return x;
|
|
1754
|
+
}
|
|
1755
|
+
parseUnaryExpression() {
|
|
1756
|
+
const op = this.peek();
|
|
1757
|
+
if (Token.isUnaryOrCount(op.token)) {
|
|
1758
|
+
return this.parseUnaryOrPrefixExpression();
|
|
1759
|
+
}
|
|
1760
|
+
if (op.isType(Token.AWAIT) && this.isAwaitAllowed()) {
|
|
1761
|
+
return this.parseAwaitExpression();
|
|
1762
|
+
}
|
|
1763
|
+
return this.parsePostfixExpression();
|
|
1764
|
+
}
|
|
1765
|
+
parseUnaryOrPrefixExpression() {
|
|
1766
|
+
const op = this.next();
|
|
1767
|
+
const expression = this.parseUnaryExpression();
|
|
1768
|
+
if (Token.isUnary(op.token)) {
|
|
1769
|
+
if (op.isType(Token.DELETE)) {
|
|
1770
|
+
if (this.isIdentifier(expression) && isStrict(this.languageMode)) {
|
|
1771
|
+
throw new Error(this.errorMessage(`"delete identifier" is a syntax error in strict mode`));
|
|
1772
|
+
}
|
|
1773
|
+
if (expression instanceof MemberExpression && expression.getProperty().toString().startsWith('#')) {
|
|
1774
|
+
throw new Error(this.errorMessage(`"Delete Private Field" is a syntax error`));
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
if (this.peek().isType(Token.EXP)) {
|
|
1778
|
+
throw new Error(this.errorMessage(`Unexpected Token Unary Exponentiation`));
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (Token.isCount(op.token) || Token.isUnary(op.token)) {
|
|
1782
|
+
return buildUnaryExpression(expression, op.token);
|
|
1783
|
+
}
|
|
1784
|
+
throw new Error(this.errorMessage(`while rewrite unary operation`));
|
|
1785
|
+
}
|
|
1786
|
+
parsePostfixExpression() {
|
|
1787
|
+
const expression = this.parseLeftHandSideExpression();
|
|
1788
|
+
if (!Token.isCount(this.peek().token) || this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1789
|
+
return expression;
|
|
1790
|
+
}
|
|
1791
|
+
return this.parsePostfixContinuation(expression);
|
|
1792
|
+
}
|
|
1793
|
+
parsePostfixContinuation(expression) {
|
|
1794
|
+
if (!this.isValidReferenceExpression(expression)) {
|
|
1795
|
+
throw new Error(this.errorMessage(`Invalid LHS In Postfix Op.`));
|
|
1796
|
+
}
|
|
1797
|
+
const op = this.next();
|
|
1798
|
+
return buildPostfixExpression(expression, op.token);
|
|
1799
|
+
}
|
|
1800
|
+
parseLeftHandSideExpression() {
|
|
1801
|
+
const result = this.parseMemberExpression();
|
|
1802
|
+
if (!Token.isPropertyOrCall(this.peek().token))
|
|
1803
|
+
return result;
|
|
1804
|
+
return this.parseLeftHandSideContinuation(result);
|
|
1805
|
+
}
|
|
1806
|
+
parseLeftHandSideContinuation(result) {
|
|
1807
|
+
if (this.peek().isType(Token.LPAREN)
|
|
1808
|
+
&& this.isIdentifier(result)
|
|
1809
|
+
&& this.scanner.currentToken().isType(Token.ASYNC)
|
|
1810
|
+
&& !this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1811
|
+
const args = this.parseArguments(ParsingArrowHeadFlag.AsyncArrowFunction);
|
|
1812
|
+
if (this.peek().isType(Token.ARROW)) {
|
|
1813
|
+
if (!args.length)
|
|
1814
|
+
return new EmptyStatement;
|
|
1815
|
+
return this.expressionListToExpression(args);
|
|
1816
|
+
}
|
|
1817
|
+
result = new CallExpression(result, args);
|
|
1818
|
+
if (!Token.isPropertyOrCall(this.peek().token))
|
|
1819
|
+
return result;
|
|
1820
|
+
}
|
|
1821
|
+
let optionalChaining = false;
|
|
1822
|
+
let isOptional = false;
|
|
1823
|
+
do {
|
|
1824
|
+
switch (this.peek().token) {
|
|
1825
|
+
case Token.QUESTION_PERIOD: {
|
|
1826
|
+
if (isOptional) {
|
|
1827
|
+
throw new Error(this.errorMessage(`Failure Expression`));
|
|
1828
|
+
}
|
|
1829
|
+
this.consume(Token.QUESTION_PERIOD);
|
|
1830
|
+
isOptional = true;
|
|
1831
|
+
optionalChaining = true;
|
|
1832
|
+
if (Token.isPropertyOrCall(this.peek().token))
|
|
1833
|
+
continue;
|
|
1834
|
+
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1835
|
+
result = new MemberExpression(result, key, false, isOptional);
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
case Token.LBRACK: {
|
|
1839
|
+
this.consume(Token.LBRACK);
|
|
1840
|
+
this.setAcceptIN(true);
|
|
1841
|
+
const index = this.parseExpressionCoverGrammar();
|
|
1842
|
+
this.restoreAcceptIN();
|
|
1843
|
+
result = new MemberExpression(result, index, true, isOptional);
|
|
1844
|
+
this.expect(Token.RBRACK);
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
case Token.PERIOD: {
|
|
1848
|
+
if (isOptional) {
|
|
1849
|
+
throw new Error(this.errorMessage(`Unexpected Token:${this.position()}`));
|
|
1850
|
+
}
|
|
1851
|
+
this.consume(Token.PERIOD);
|
|
1852
|
+
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1853
|
+
result = new MemberExpression(result, key, false, isOptional);
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
case Token.LPAREN: {
|
|
1857
|
+
const args = this.parseArguments();
|
|
1858
|
+
result = new CallExpression(result, args, isOptional);
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
case Token.BIND: {
|
|
1862
|
+
if (isOptional) {
|
|
1863
|
+
throw new Error(this.errorMessage(`Unexpected Token:${this.position()}`));
|
|
1864
|
+
}
|
|
1865
|
+
this.consume(Token.BIND);
|
|
1866
|
+
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1867
|
+
result = new BindExpression(result, key, false, isOptional);
|
|
1868
|
+
break;
|
|
1869
|
+
}
|
|
1870
|
+
case Token.QUESTION_BIND: {
|
|
1871
|
+
if (isOptional) {
|
|
1872
|
+
throw new Error(this.errorMessage(`Failure Expression`));
|
|
1873
|
+
}
|
|
1874
|
+
this.consume(Token.QUESTION_BIND);
|
|
1875
|
+
isOptional = true;
|
|
1876
|
+
optionalChaining = true;
|
|
1877
|
+
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1878
|
+
result = new BindExpression(result, key, true, isOptional);
|
|
1879
|
+
break;
|
|
1880
|
+
}
|
|
1881
|
+
default:
|
|
1882
|
+
if (optionalChaining) {
|
|
1883
|
+
throw new Error(this.errorMessage(`Optional Chaining No Template support`));
|
|
1884
|
+
}
|
|
1885
|
+
result = this.parseTemplateLiteral(result);
|
|
1886
|
+
break;
|
|
1887
|
+
}
|
|
1888
|
+
if (isOptional) {
|
|
1889
|
+
isOptional = false;
|
|
1890
|
+
}
|
|
1891
|
+
} while (Token.isPropertyOrCall(this.peek().token));
|
|
1892
|
+
if (optionalChaining) {
|
|
1893
|
+
result = new ChainExpression(result);
|
|
1894
|
+
}
|
|
1895
|
+
return result;
|
|
1896
|
+
}
|
|
1897
|
+
parseAwaitExpression() {
|
|
1898
|
+
this.consume(Token.AWAIT);
|
|
1899
|
+
const value = this.parseUnaryExpression();
|
|
1900
|
+
if (this.peek().isType(Token.EXP)) {
|
|
1901
|
+
throw new Error(this.scanner.createError(`Unexpected Token Unary Exponentiation`));
|
|
1902
|
+
}
|
|
1903
|
+
return buildUnaryExpression(value, Token.AWAIT);
|
|
1904
|
+
}
|
|
1905
|
+
parseNullishExpression(expression) {
|
|
1906
|
+
const list = [];
|
|
1907
|
+
list.push(expression);
|
|
1908
|
+
while (this.peek().isType(Token.NULLISH)) {
|
|
1909
|
+
this.consume(Token.NULLISH);
|
|
1910
|
+
expression = this.parseBinaryExpression(6);
|
|
1911
|
+
list.push(expression);
|
|
1912
|
+
}
|
|
1913
|
+
expression = list.pop();
|
|
1914
|
+
expression = list.reverse()
|
|
1915
|
+
.reduce((previous, current) => new LogicalExpression(Token.NULLISH.getName(), current, previous), expression);
|
|
1916
|
+
return expression;
|
|
1917
|
+
}
|
|
1918
|
+
parseConditionalContinuation(expression) {
|
|
1919
|
+
this.consume(Token.CONDITIONAL);
|
|
1920
|
+
this.setAcceptIN(true);
|
|
1921
|
+
const left = this.parseAssignmentExpression();
|
|
1922
|
+
this.restoreAcceptIN();
|
|
1923
|
+
this.expect(Token.COLON);
|
|
1924
|
+
const right = this.parseAssignmentExpression();
|
|
1925
|
+
return new ConditionalExpression(expression, left, right);
|
|
1926
|
+
}
|
|
1927
|
+
parseYieldExpression() {
|
|
1928
|
+
this.consume(Token.YIELD);
|
|
1929
|
+
let delegating = false;
|
|
1930
|
+
let expression;
|
|
1931
|
+
if (!this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1932
|
+
if (this.check(Token.MUL)) {
|
|
1933
|
+
delegating = true;
|
|
1934
|
+
}
|
|
1935
|
+
switch (this.peek().token) {
|
|
1936
|
+
case Token.EOS:
|
|
1937
|
+
case Token.SEMICOLON:
|
|
1938
|
+
case Token.RBRACE:
|
|
1939
|
+
case Token.RBRACK:
|
|
1940
|
+
case Token.RPAREN:
|
|
1941
|
+
case Token.COLON:
|
|
1942
|
+
case Token.COMMA:
|
|
1943
|
+
case Token.IN:
|
|
1944
|
+
if (!delegating)
|
|
1945
|
+
break;
|
|
1946
|
+
throw new Error(this.errorMessage(`Delegating yields require an RHS`));
|
|
1947
|
+
default:
|
|
1948
|
+
expression = this.parseAssignmentExpressionCoverGrammar();
|
|
1949
|
+
break;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
return new YieldExpression(delegating, expression);
|
|
1953
|
+
}
|
|
1954
|
+
parseNewTargetExpression() {
|
|
1955
|
+
throw new Error(this.errorMessage('Expression (new.target) not supported.'));
|
|
1956
|
+
}
|
|
1957
|
+
parseClassExpression() {
|
|
1958
|
+
throw new Error(this.errorMessage(`Expression (class) not supported.`));
|
|
1959
|
+
}
|
|
1960
|
+
parseClassDeclaration(names, defaultExport) {
|
|
1961
|
+
throw new Error(this.errorMessage(`Expression (class) not supported.`));
|
|
1962
|
+
}
|
|
1963
|
+
parseClassLiteral(name, isStrictReserved) {
|
|
1964
|
+
throw new Error(this.errorMessage(`Expression (class) not supported.`));
|
|
1965
|
+
}
|
|
1966
|
+
parseSuperExpression() {
|
|
1967
|
+
throw new Error(this.errorMessage('Expression (supper) not supported.'));
|
|
1968
|
+
}
|
|
1969
|
+
parseImportExpressions() {
|
|
1970
|
+
throw new Error(this.errorMessage('Expression (import) not supported.'));
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
//# sourceMappingURL=inline.js.map
|