@ibyar/expressions 0.8.3 → 0.8.5
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/README.md +0 -3
- package/api/abstract.d.ts +6 -2
- package/api/abstract.js +15 -8
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +15 -18
- package/api/class/class.js +49 -61
- package/api/class/class.js.map +1 -1
- package/api/class/decorator.d.ts +2 -2
- package/api/class/decorator.js +6 -6
- package/api/class/decorator.js.map +1 -1
- package/api/computing/call.d.ts +2 -2
- package/api/computing/call.js +8 -8
- package/api/computing/call.js.map +1 -1
- package/api/computing/debugger.d.ts +1 -2
- package/api/computing/debugger.js +2 -3
- package/api/computing/debugger.js.map +1 -1
- package/api/computing/new.d.ts +2 -2
- package/api/computing/new.js +7 -7
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +2 -2
- package/api/computing/rest.js +6 -6
- package/api/computing/rest.js.map +1 -1
- package/api/computing/return.d.ts +2 -2
- package/api/computing/return.js +6 -6
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +2 -2
- package/api/computing/spread.js +6 -6
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +4 -4
- package/api/computing/throw.js +18 -18
- package/api/computing/throw.js.map +1 -1
- package/api/computing/yield.d.ts +2 -2
- package/api/computing/yield.js +7 -7
- package/api/computing/yield.js.map +1 -1
- package/api/definition/array.d.ts +3 -3
- package/api/definition/array.js +14 -14
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +2 -2
- package/api/definition/bind.js +9 -9
- package/api/definition/bind.js.map +1 -1
- package/api/definition/comment.d.ts +3 -3
- package/api/definition/comment.js +6 -6
- package/api/definition/comment.js.map +1 -1
- package/api/definition/function.d.ts +17 -16
- package/api/definition/function.js +60 -55
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +2 -2
- package/api/definition/member.js +13 -9
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +4 -4
- package/api/definition/object.js +22 -22
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -2
- package/api/definition/statement.js +6 -6
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +15 -37
- package/api/definition/values.js +49 -74
- package/api/definition/values.js.map +1 -1
- package/api/expression.d.ts +42 -8
- package/api/expression.js.map +1 -1
- package/api/index.d.ts +1 -0
- package/api/index.js +1 -0
- package/api/index.js.map +1 -1
- package/api/module/common.d.ts +3 -3
- package/api/module/common.js +9 -9
- package/api/module/common.js.map +1 -1
- package/api/module/export.d.ts +5 -5
- package/api/module/export.js +30 -29
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +4 -4
- package/api/module/import.js +24 -23
- package/api/module/import.js.map +1 -1
- package/api/operators/assignment.d.ts +3 -3
- package/api/operators/assignment.js +5 -5
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +3 -3
- package/api/operators/await.js +7 -7
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.d.ts +1 -1
- 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 +6 -6
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +2 -2
- package/api/operators/comma.js +6 -6
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +2 -2
- package/api/operators/grouping.js +6 -6
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.d.ts +1 -1
- package/api/operators/logical.js +1 -1
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +3 -3
- package/api/operators/pipeline.js +8 -8
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +2 -2
- package/api/operators/ternary.js +8 -8
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/types.d.ts +1 -1
- package/api/operators/unary.d.ts +3 -3
- package/api/operators/unary.js +7 -7
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +3 -3
- package/api/operators/update.js +8 -8
- package/api/operators/update.js.map +1 -1
- package/api/program.d.ts +3 -3
- package/api/program.js +7 -7
- package/api/program.js.map +1 -1
- package/api/statement/control/block.d.ts +2 -2
- package/api/statement/control/block.js +6 -6
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +2 -3
- package/api/statement/control/empty.js +6 -7
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +2 -2
- package/api/statement/control/if.js +8 -8
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +4 -6
- package/api/statement/control/switch.js +19 -20
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +4 -4
- package/api/statement/control/terminate.js +11 -15
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/control/with.d.ts +21 -0
- package/api/statement/control/with.js +67 -0
- package/api/statement/control/with.js.map +1 -0
- package/api/statement/declarations/declares.d.ts +4 -4
- package/api/statement/declarations/declares.js +14 -14
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +7 -7
- package/api/statement/iterations/for.js +35 -35
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -3
- package/api/statement/iterations/while.js +14 -14
- package/api/statement/iterations/while.js.map +1 -1
- package/package.json +14 -4
- package/scope/finalizer.d.ts +1 -1
- package/scope/pool.d.ts +1 -1
- package/scope/proxy.d.ts +1 -1
- package/scope/proxy.js +1 -0
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +2 -2
- package/scope/scope.js +13 -16
- package/scope/scope.js.map +1 -1
- package/scope/stack.js +23 -23
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +4 -2
- package/v8/enums.js.map +1 -1
- package/v8/factory.d.ts +148 -0
- package/v8/factory.js +499 -0
- package/v8/factory.js.map +1 -0
- package/v8/inline.d.ts +49 -49
- package/v8/inline.js +317 -307
- package/v8/inline.js.map +1 -1
- package/v8/node.d.ts +141 -0
- package/v8/node.js +2 -0
- package/v8/node.js.map +1 -0
- package/v8/nodes.d.ts +0 -14
- package/v8/nodes.js +1 -152
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +21 -18
- package/v8/parser.js +97 -84
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +2 -1
- package/v8/stream.js +221 -311
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +3 -1
- package/v8/token.js +7 -5
- package/v8/token.js.map +1 -1
- package/visit/visitor.d.ts +1 -1
package/v8/inline.js
CHANGED
|
@@ -1,52 +1,24 @@
|
|
|
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
1
|
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
2
|
import { AllowLabelledFunctionStatement, FunctionBodyType, FunctionKind, functionKindForImpl, FunctionSyntaxKind, isAsyncFunction, isAsyncGeneratorFunction, isAwaitAsIdentifierDisallowed, isClassMembersInitializerFunction, isGeneratorFunction, isModule, isResumableFunction, ParseFunctionFlag, ParsingArrowHeadFlag, PropertyKind, PropertyKindInfo, PropertyPosition, SubFunctionKind, VariableDeclarationContext } from './enums.js';
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
3
|
+
import { TokenStream } from './stream.js';
|
|
4
|
+
import { Token } from './token.js';
|
|
5
|
+
import { ExpressionNodeFactory, ExpressionNodeSourcePosition } from './factory.js';
|
|
6
|
+
import { isSloppy, isStrict, LanguageMode } from './language.js';
|
|
36
7
|
export class AbstractParser {
|
|
37
|
-
constructor(scanner, acceptIN) {
|
|
38
|
-
this.scanner = scanner;
|
|
39
|
-
this.previousAcceptIN = [];
|
|
40
|
-
this.previousFunctionKind = [];
|
|
41
|
-
this.previousAcceptIN.push(this.acceptIN = acceptIN ?? false);
|
|
42
|
-
this.previousFunctionKind.push(this.functionKind = FunctionKind.NormalFunction);
|
|
43
|
-
}
|
|
44
8
|
get languageMode() {
|
|
45
9
|
return this.scanner.getLanguageMode();
|
|
46
10
|
}
|
|
47
11
|
set languageMode(mode) {
|
|
48
12
|
this.scanner.setLanguageMode(mode);
|
|
49
13
|
}
|
|
14
|
+
constructor(scanner, factory, acceptIN) {
|
|
15
|
+
this.scanner = scanner;
|
|
16
|
+
this.factory = factory;
|
|
17
|
+
this.previousAcceptIN = [];
|
|
18
|
+
this.previousFunctionKind = [];
|
|
19
|
+
this.previousAcceptIN.push(this.acceptIN = acceptIN ?? false);
|
|
20
|
+
this.previousFunctionKind.push(this.functionKind = FunctionKind.NormalFunction);
|
|
21
|
+
}
|
|
50
22
|
position() {
|
|
51
23
|
return this.scanner.getPos();
|
|
52
24
|
}
|
|
@@ -93,10 +65,27 @@ export class AbstractParser {
|
|
|
93
65
|
peekPosition() {
|
|
94
66
|
return this.scanner.peekPosition();
|
|
95
67
|
}
|
|
68
|
+
createRange(start) {
|
|
69
|
+
if (Number.isNaN(start?.range?.[0])) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return [start.range[0], this.scanner.getPos()];
|
|
73
|
+
}
|
|
74
|
+
createRangeByStart(start) {
|
|
75
|
+
return [start.range[0], this.scanner.getPos()];
|
|
76
|
+
}
|
|
77
|
+
createStartPosition() {
|
|
78
|
+
return [this.scanner.getPos(), -1];
|
|
79
|
+
}
|
|
80
|
+
updateRangeEnd(range) {
|
|
81
|
+
range[1] = this.scanner.getPos();
|
|
82
|
+
}
|
|
96
83
|
consume(token) {
|
|
97
|
-
|
|
84
|
+
const next = this.scanner.next();
|
|
85
|
+
if (next.isNotType(token)) {
|
|
98
86
|
throw new Error(this.errorMessage(`Parsing ${JSON.stringify(token)}`));
|
|
99
87
|
}
|
|
88
|
+
return next;
|
|
100
89
|
}
|
|
101
90
|
check(token) {
|
|
102
91
|
const next = this.scanner.peek();
|
|
@@ -127,6 +116,7 @@ export class AbstractParser {
|
|
|
127
116
|
if (current.isNotType(token)) {
|
|
128
117
|
throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(token)}, current is ${JSON.stringify(current)}`));
|
|
129
118
|
}
|
|
119
|
+
return current;
|
|
130
120
|
}
|
|
131
121
|
expectAndGetValue(token) {
|
|
132
122
|
const current = this.scanner.next();
|
|
@@ -136,32 +126,30 @@ export class AbstractParser {
|
|
|
136
126
|
return current.getValue();
|
|
137
127
|
}
|
|
138
128
|
checkInOrOf() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
else if (this.checkValue(OfNode)) {
|
|
143
|
-
return 'OF';
|
|
129
|
+
const result = this.peekInOrOf();
|
|
130
|
+
if (result) {
|
|
131
|
+
this.scanner.next();
|
|
144
132
|
}
|
|
145
|
-
return
|
|
133
|
+
return result;
|
|
146
134
|
}
|
|
147
135
|
peekInOrOf() {
|
|
148
136
|
var next = this.peek();
|
|
149
137
|
if (next.isType(Token.IN)) {
|
|
150
138
|
return 'IN';
|
|
151
139
|
}
|
|
152
|
-
else if (next.value ===
|
|
140
|
+
else if (this.factory.isIdentifier(next.value) && next.value.getName() === 'of') {
|
|
153
141
|
return 'OF';
|
|
154
142
|
}
|
|
155
143
|
return false;
|
|
156
144
|
}
|
|
157
|
-
isArguments(
|
|
158
|
-
return
|
|
145
|
+
isArguments(node) {
|
|
146
|
+
return this.factory.isIdentifier(node) && node.getName() === 'arguments';
|
|
159
147
|
}
|
|
160
|
-
isEval(
|
|
161
|
-
return
|
|
148
|
+
isEval(node) {
|
|
149
|
+
return this.factory.isIdentifier(node) && node.getName() === 'eval';
|
|
162
150
|
}
|
|
163
|
-
isEvalOrArguments(
|
|
164
|
-
return
|
|
151
|
+
isEvalOrArguments(node) {
|
|
152
|
+
return this.factory.isIdentifier(node) && (node.getName() === 'eval' || node.getName() === 'arguments');
|
|
165
153
|
}
|
|
166
154
|
isNextLetKeyword() {
|
|
167
155
|
if (this.peek().isNotType(Token.LET)) {
|
|
@@ -188,9 +176,6 @@ export class AbstractParser {
|
|
|
188
176
|
return false;
|
|
189
177
|
}
|
|
190
178
|
}
|
|
191
|
-
isIdentifier(expression) {
|
|
192
|
-
return expression instanceof Identifier;
|
|
193
|
-
}
|
|
194
179
|
markParenthesized(expression) {
|
|
195
180
|
Reflect.set(expression, 'parenthesized', true);
|
|
196
181
|
}
|
|
@@ -202,7 +187,7 @@ export class AbstractParser {
|
|
|
202
187
|
}
|
|
203
188
|
isAssignableIdentifier(expression) {
|
|
204
189
|
// return expression instanceof AssignmentNode;
|
|
205
|
-
if (!(expression
|
|
190
|
+
if (!(this.factory.isIdentifier(expression))) {
|
|
206
191
|
return false;
|
|
207
192
|
}
|
|
208
193
|
if (isStrict(this.languageMode) && this.isEvalOrArguments(expression)) {
|
|
@@ -210,23 +195,8 @@ export class AbstractParser {
|
|
|
210
195
|
}
|
|
211
196
|
return true;
|
|
212
197
|
}
|
|
213
|
-
isPattern(expression) {
|
|
214
|
-
return expression instanceof ObjectExpression || expression instanceof ArrayExpression;
|
|
215
|
-
}
|
|
216
|
-
isProperty(expression) {
|
|
217
|
-
return expression instanceof Property || expression instanceof MemberExpression;
|
|
218
|
-
}
|
|
219
|
-
isCallNew(expression) {
|
|
220
|
-
return expression instanceof NewExpression;
|
|
221
|
-
}
|
|
222
|
-
isCall(expression) {
|
|
223
|
-
return expression instanceof CallExpression;
|
|
224
|
-
}
|
|
225
|
-
isEmptyStatement(expression) {
|
|
226
|
-
return expression instanceof EmptyStatement;
|
|
227
|
-
}
|
|
228
198
|
isValidReferenceExpression(expression) {
|
|
229
|
-
return this.isAssignableIdentifier(expression) || this.
|
|
199
|
+
return this.isAssignableIdentifier(expression) || this.factory.isPropertyOrMemberExpression(expression);
|
|
230
200
|
}
|
|
231
201
|
expectSemicolon() {
|
|
232
202
|
const tok = this.peek();
|
|
@@ -299,24 +269,29 @@ export class AbstractParser {
|
|
|
299
269
|
}
|
|
300
270
|
}
|
|
301
271
|
export class JavaScriptInlineParser extends AbstractParser {
|
|
302
|
-
static parse(source, { mode, acceptIN } = {}) {
|
|
272
|
+
static parse(source, { mode, acceptIN, factory, addLocation } = {}) {
|
|
303
273
|
mode ?? (mode = LanguageMode.Strict);
|
|
304
274
|
const stream = (typeof source === 'string')
|
|
305
275
|
? TokenStream.getTokenStream(source, mode)
|
|
306
276
|
: Array.isArray(source) ? TokenStream.getTokenStream(source) : source;
|
|
307
277
|
acceptIN ?? (acceptIN = false);
|
|
308
|
-
|
|
278
|
+
if (factory == undefined) {
|
|
279
|
+
const sourcePositionFactory = addLocation && typeof source === 'string' ? new ExpressionNodeSourcePosition(source) : undefined;
|
|
280
|
+
factory = new ExpressionNodeFactory(sourcePositionFactory);
|
|
281
|
+
}
|
|
282
|
+
const parser = new JavaScriptInlineParser(stream, factory, acceptIN);
|
|
309
283
|
return parser.scan();
|
|
310
284
|
}
|
|
311
|
-
constructor(scanner, acceptIN) {
|
|
312
|
-
super(scanner, acceptIN);
|
|
285
|
+
constructor(scanner, factory, acceptIN) {
|
|
286
|
+
super(scanner, factory, acceptIN);
|
|
313
287
|
}
|
|
314
288
|
scan() {
|
|
289
|
+
const start = this.scanner.getPos();
|
|
315
290
|
const list = this.parseStatementList(Token.EOS);
|
|
316
291
|
if (list.length === 1) {
|
|
317
292
|
return list[0];
|
|
318
293
|
}
|
|
319
|
-
return
|
|
294
|
+
return this.factory.createExpressionStatement(list, [start, this.scanner.getPos()]);
|
|
320
295
|
}
|
|
321
296
|
/**
|
|
322
297
|
* Statement ::
|
|
@@ -341,8 +316,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
341
316
|
case Token.LBRACE:
|
|
342
317
|
return this.parseBlock();
|
|
343
318
|
case Token.SEMICOLON:
|
|
344
|
-
this.consume(Token.SEMICOLON);
|
|
345
|
-
return
|
|
319
|
+
const semicolon = this.consume(Token.SEMICOLON);
|
|
320
|
+
return this.factory.createEmptyStatement(semicolon.range);
|
|
346
321
|
case Token.IF:
|
|
347
322
|
return this.parseIfStatement();
|
|
348
323
|
case Token.DO:
|
|
@@ -366,6 +341,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
366
341
|
return this.parseTryStatement();
|
|
367
342
|
case Token.SWITCH:
|
|
368
343
|
return this.parseSwitchStatement();
|
|
344
|
+
case Token.WITH:
|
|
345
|
+
return this.parseWithStatement();
|
|
369
346
|
case Token.FUNCTION:
|
|
370
347
|
throw new SyntaxError(this.errorMessage(`FunctionDeclaration only allowed as a StatementListItem not in an arbitrary Statement position.`));
|
|
371
348
|
case Token.DEBUGGER:
|
|
@@ -381,9 +358,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
381
358
|
}
|
|
382
359
|
}
|
|
383
360
|
parseDebuggerStatement() {
|
|
384
|
-
this.consume(Token.DEBUGGER);
|
|
361
|
+
const token = this.consume(Token.DEBUGGER);
|
|
385
362
|
this.expectSemicolon();
|
|
386
|
-
return
|
|
363
|
+
return this.factory.createDebuggerStatement(token.range);
|
|
387
364
|
}
|
|
388
365
|
parseTryStatement() {
|
|
389
366
|
// TryStatement ::
|
|
@@ -396,8 +373,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
396
373
|
//
|
|
397
374
|
// Finally ::
|
|
398
375
|
// 'finally' Block
|
|
399
|
-
this.consume(Token.TRY);
|
|
376
|
+
const tryToken = this.consume(Token.TRY);
|
|
400
377
|
const tryBlock = this.parseBlock();
|
|
378
|
+
let range;
|
|
401
379
|
let peek = this.peek();
|
|
402
380
|
if (peek.isNotType(Token.CATCH) && peek.isNotType(Token.FINALLY)) {
|
|
403
381
|
throw new Error(this.errorMessage(`Uncaught SyntaxError: Missing catch or finally after try`));
|
|
@@ -416,13 +394,15 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
416
394
|
this.expect(Token.RPAREN);
|
|
417
395
|
}
|
|
418
396
|
const block = this.parseBlock();
|
|
419
|
-
catchBlock =
|
|
397
|
+
catchBlock = this.factory.createCatchClause(block, identifier, this.createRange(peek));
|
|
398
|
+
range = this.createRange(tryToken);
|
|
420
399
|
}
|
|
421
400
|
let finallyBlock;
|
|
422
401
|
if (this.check(Token.FINALLY)) {
|
|
423
402
|
finallyBlock = this.parseBlock();
|
|
403
|
+
range = this.createRange(tryToken);
|
|
424
404
|
}
|
|
425
|
-
return
|
|
405
|
+
return this.factory.createTryStatement(tryBlock, catchBlock, finallyBlock, range);
|
|
426
406
|
}
|
|
427
407
|
parseNonRestrictedIdentifier() {
|
|
428
408
|
const result = this.parseIdentifier();
|
|
@@ -432,20 +412,22 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
432
412
|
return result;
|
|
433
413
|
}
|
|
434
414
|
parseBlock() {
|
|
435
|
-
this.expect(Token.LBRACE);
|
|
415
|
+
const start = this.expect(Token.LBRACE);
|
|
436
416
|
const statements = [];
|
|
437
|
-
const
|
|
417
|
+
const range = this.createRangeByStart(start);
|
|
418
|
+
const block = this.factory.createBlock(statements, range);
|
|
438
419
|
while (this.peek().isNotType(Token.RBRACE)) {
|
|
439
420
|
const stat = this.parseStatementListItem();
|
|
440
421
|
if (!stat) {
|
|
441
422
|
return block;
|
|
442
423
|
}
|
|
443
|
-
else if (stat
|
|
424
|
+
else if (this.factory.isEmptyStatement(stat)) {
|
|
444
425
|
continue;
|
|
445
426
|
}
|
|
446
427
|
statements.push(stat);
|
|
447
428
|
}
|
|
448
429
|
this.expect(Token.RBRACE);
|
|
430
|
+
this.updateRangeEnd(range);
|
|
449
431
|
return block;
|
|
450
432
|
}
|
|
451
433
|
/**
|
|
@@ -469,10 +451,10 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
469
451
|
parseStatementListItem() {
|
|
470
452
|
switch (this.peek().token) {
|
|
471
453
|
case Token.FUNCTION:
|
|
472
|
-
return this.parseHoistableDeclaration(undefined, false);
|
|
454
|
+
return this.parseHoistableDeclaration(undefined, false, this.peek());
|
|
473
455
|
case Token.CLASS:
|
|
474
|
-
this.consume(Token.CLASS);
|
|
475
|
-
return this.parseClassDeclaration(undefined, false);
|
|
456
|
+
const classToken = this.consume(Token.CLASS);
|
|
457
|
+
return this.parseClassDeclaration(undefined, false, classToken);
|
|
476
458
|
case Token.VAR:
|
|
477
459
|
case Token.CONST:
|
|
478
460
|
return this.parseVariableDeclarations(VariableDeclarationContext.StatementListItem);
|
|
@@ -483,8 +465,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
483
465
|
break;
|
|
484
466
|
case Token.ASYNC:
|
|
485
467
|
if (this.peekAhead().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorAfterNext()) {
|
|
486
|
-
this.consume(Token.ASYNC);
|
|
487
|
-
return this.parseAsyncFunctionDeclaration(undefined, false);
|
|
468
|
+
const start = this.consume(Token.ASYNC);
|
|
469
|
+
return this.parseAsyncFunctionDeclaration(undefined, false, start);
|
|
488
470
|
}
|
|
489
471
|
break;
|
|
490
472
|
default:
|
|
@@ -493,7 +475,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
493
475
|
return this.parseStatement(AllowLabelledFunctionStatement.AllowLabelledFunctionStatement);
|
|
494
476
|
}
|
|
495
477
|
parseFunctionExpression() {
|
|
496
|
-
this.consume(Token.FUNCTION);
|
|
478
|
+
const start = this.consume(Token.FUNCTION);
|
|
497
479
|
const functionKind = this.check(Token.MUL) ? FunctionKind.GeneratorFunction : FunctionKind.NormalFunction;
|
|
498
480
|
let name;
|
|
499
481
|
let functionSyntaxKind = FunctionSyntaxKind.AnonymousExpression;
|
|
@@ -502,9 +484,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
502
484
|
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
503
485
|
functionSyntaxKind = FunctionSyntaxKind.NamedExpression;
|
|
504
486
|
}
|
|
505
|
-
return this.parseFunctionLiteral(functionKind, functionSyntaxKind, name);
|
|
487
|
+
return this.parseFunctionLiteral(functionKind, functionSyntaxKind, name, start);
|
|
506
488
|
}
|
|
507
|
-
parseAsyncFunctionDeclaration(names, defaultExport) {
|
|
489
|
+
parseAsyncFunctionDeclaration(names, defaultExport, start) {
|
|
508
490
|
// AsyncFunctionDeclaration ::
|
|
509
491
|
// async [no LineTerminator here] function BindingIdentifier[Await]
|
|
510
492
|
// ( FormalParameters[Await] ) { AsyncFunctionBody }
|
|
@@ -512,20 +494,22 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
512
494
|
throw new SyntaxError(this.errorMessage('Line Terminator Before `function` parsing `async function`.'));
|
|
513
495
|
}
|
|
514
496
|
this.consume(Token.FUNCTION);
|
|
515
|
-
return this.parseHoistableDeclaration01(FunctionKind.AsyncFunction, names, defaultExport);
|
|
497
|
+
return this.parseHoistableDeclaration01(FunctionKind.AsyncFunction, names, defaultExport, start);
|
|
516
498
|
}
|
|
517
499
|
parseIfStatement() {
|
|
518
|
-
this.consume(Token.IF);
|
|
500
|
+
const ifToken = this.consume(Token.IF);
|
|
519
501
|
this.consume(Token.LPAREN);
|
|
520
502
|
const condition = this.parseExpression();
|
|
521
503
|
this.consume(Token.RPAREN);
|
|
522
504
|
const thenStatement = this.parseScopedStatement();
|
|
505
|
+
let range;
|
|
523
506
|
let elseStatement;
|
|
524
507
|
if (this.peek().isType(Token.ELSE)) {
|
|
525
508
|
this.consume(Token.ELSE);
|
|
526
509
|
elseStatement = this.parseScopedStatement();
|
|
527
510
|
}
|
|
528
|
-
|
|
511
|
+
range = this.createRange(ifToken);
|
|
512
|
+
return this.factory.createIfStatement(condition, thenStatement, elseStatement, range);
|
|
529
513
|
}
|
|
530
514
|
parseScopedStatement() {
|
|
531
515
|
if (isStrict(this.languageMode) || this.peek().isNotType(Token.FUNCTION)) {
|
|
@@ -538,35 +522,36 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
538
522
|
parseDoWhileStatement() {
|
|
539
523
|
// DoStatement ::
|
|
540
524
|
// 'do' Statement 'while' '(' Expression ')' ';'
|
|
541
|
-
this.consume(Token.DO);
|
|
525
|
+
const start = this.consume(Token.DO);
|
|
542
526
|
const body = this.parseStatement();
|
|
543
527
|
this.expect(Token.WHILE);
|
|
544
528
|
this.expect(Token.LPAREN);
|
|
545
529
|
const condition = this.parseExpression();
|
|
546
530
|
this.expect(Token.RPAREN);
|
|
547
531
|
this.check(Token.SEMICOLON);
|
|
548
|
-
return
|
|
532
|
+
return this.factory.createDoStatement(condition, body, this.createRange(start));
|
|
549
533
|
}
|
|
550
534
|
parseWhileStatement() {
|
|
551
535
|
// WhileStatement ::
|
|
552
536
|
// 'while' '(' Expression ')' Statement
|
|
553
|
-
this.consume(Token.WHILE);
|
|
537
|
+
const start = this.consume(Token.WHILE);
|
|
554
538
|
this.expect(Token.LPAREN);
|
|
555
539
|
const condition = this.parseExpression();
|
|
556
540
|
this.expect(Token.RPAREN);
|
|
557
541
|
const body = this.parseStatement();
|
|
558
|
-
return
|
|
542
|
+
return this.factory.createWhileStatement(condition, body, this.createRange(start));
|
|
559
543
|
}
|
|
560
544
|
parseThrowStatement() {
|
|
561
545
|
// ThrowStatement ::
|
|
562
546
|
// 'throw' Expression ';'
|
|
563
|
-
this.consume(Token.THROW);
|
|
547
|
+
const throwToken = this.consume(Token.THROW);
|
|
564
548
|
if (this.scanner.hasLineTerminatorBeforeNext()) {
|
|
565
549
|
throw new Error(this.scanner.createError(`New line After Throw`));
|
|
566
550
|
}
|
|
567
551
|
const exception = this.parseExpression();
|
|
552
|
+
const range = this.createRange(throwToken);
|
|
568
553
|
this.expectSemicolon();
|
|
569
|
-
return
|
|
554
|
+
return this.factory.createThrowStatement(exception, range);
|
|
570
555
|
}
|
|
571
556
|
parseSwitchStatement() {
|
|
572
557
|
// SwitchStatement ::
|
|
@@ -574,19 +559,21 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
574
559
|
// CaseClause ::
|
|
575
560
|
// 'case' Expression ':' StatementList
|
|
576
561
|
// 'default' ':' StatementList
|
|
577
|
-
this.consume(Token.SWITCH);
|
|
562
|
+
const start = this.consume(Token.SWITCH);
|
|
563
|
+
const range = this.createRangeByStart(start);
|
|
578
564
|
this.expect(Token.LPAREN);
|
|
579
565
|
const tag = this.parseExpression();
|
|
580
566
|
this.expect(Token.RPAREN);
|
|
581
567
|
const cases = [];
|
|
582
|
-
const switchStatement =
|
|
568
|
+
const switchStatement = this.factory.createSwitchStatement(tag, cases, range);
|
|
583
569
|
let defaultSeen = false;
|
|
584
570
|
this.expect(Token.LBRACE);
|
|
585
571
|
while (this.peek().isNotType(Token.RBRACE)) {
|
|
586
572
|
const statements = [];
|
|
587
|
-
let
|
|
573
|
+
let test;
|
|
574
|
+
const caseStart = this.scanner.peek();
|
|
588
575
|
if (this.check(Token.CASE)) {
|
|
589
|
-
|
|
576
|
+
test = this.parseExpression();
|
|
590
577
|
}
|
|
591
578
|
else {
|
|
592
579
|
this.expect(Token.DEFAULT);
|
|
@@ -595,21 +582,25 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
595
582
|
}
|
|
596
583
|
defaultSeen = true;
|
|
597
584
|
}
|
|
598
|
-
this.expect(Token.COLON);
|
|
585
|
+
const blockStart = this.expect(Token.COLON);
|
|
599
586
|
while (this.peek().isNotType(Token.CASE)
|
|
600
587
|
&& this.peek().isNotType(Token.DEFAULT)
|
|
601
588
|
&& this.peek().isNotType(Token.RBRACE)) {
|
|
602
589
|
const statement = this.parseStatementListItem();
|
|
603
|
-
if (!statement || this.isEmptyStatement(statement)) {
|
|
590
|
+
if (!statement || this.factory.isEmptyStatement(statement)) {
|
|
604
591
|
continue;
|
|
605
592
|
}
|
|
606
593
|
statements.push(statement);
|
|
607
594
|
}
|
|
608
|
-
const block =
|
|
609
|
-
const
|
|
595
|
+
const block = this.factory.createBlock(statements, this.createRange(blockStart));
|
|
596
|
+
const caseRange = this.createRange(caseStart);
|
|
597
|
+
const clause = defaultSeen
|
|
598
|
+
? this.factory.createDefaultClause(block, caseRange)
|
|
599
|
+
: this.factory.createCaseBlock(test, block, caseRange);
|
|
610
600
|
cases.push(clause);
|
|
611
601
|
}
|
|
612
602
|
this.expect(Token.RBRACE);
|
|
603
|
+
this.updateRangeEnd(range);
|
|
613
604
|
return switchStatement;
|
|
614
605
|
}
|
|
615
606
|
parseForStatement() {
|
|
@@ -621,7 +612,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
621
612
|
// We parse a declaration/expression after the 'for (' and then read the first
|
|
622
613
|
// expression/declaration before we know if this is a for or a for-each.
|
|
623
614
|
// typename FunctionState::LoopScope loop_scope(function_state_);
|
|
624
|
-
this.consume(Token.FOR);
|
|
615
|
+
const start = this.consume(Token.FOR);
|
|
625
616
|
this.expect(Token.LPAREN);
|
|
626
617
|
const peek = this.peek();
|
|
627
618
|
const starts_with_let = peek.isType(Token.LET);
|
|
@@ -635,13 +626,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
635
626
|
const initializer = this.parseVariableDeclarations(VariableDeclarationContext.ForStatement);
|
|
636
627
|
const forMode = this.checkInOrOf();
|
|
637
628
|
if (forMode) {
|
|
638
|
-
return this.parseForEachStatementWithDeclarations(initializer, forMode);
|
|
629
|
+
return this.parseForEachStatementWithDeclarations(initializer, forMode, start);
|
|
639
630
|
}
|
|
640
631
|
this.expect(Token.SEMICOLON);
|
|
641
632
|
// Parse the remaining code in the inner block scope since the declaration
|
|
642
633
|
// above was parsed there. We'll finalize the unnecessary outer block scope
|
|
643
634
|
// after parsing the rest of the loop.
|
|
644
|
-
return this.parseStandardForLoopWithLexicalDeclarations(initializer);
|
|
635
|
+
return this.parseStandardForLoopWithLexicalDeclarations(initializer, start);
|
|
645
636
|
}
|
|
646
637
|
let initializer;
|
|
647
638
|
if (peek.isType(Token.VAR)) {
|
|
@@ -651,7 +642,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
651
642
|
// for_info.position = scanner() -> location().beg_pos;
|
|
652
643
|
const forMode = this.checkInOrOf();
|
|
653
644
|
if (forMode) {
|
|
654
|
-
return this.parseForEachStatementWithDeclarations(initializer, forMode);
|
|
645
|
+
return this.parseForEachStatementWithDeclarations(initializer, forMode, start);
|
|
655
646
|
}
|
|
656
647
|
// init = impl() -> BuildInitializationBlock(& for_info.parsing_result);
|
|
657
648
|
}
|
|
@@ -671,25 +662,25 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
671
662
|
if (forMode === 'OF' && starts_with_let || expression_is_async) {
|
|
672
663
|
throw new SyntaxError(this.errorMessage(starts_with_let ? 'For Of Let' : 'For Of Async'));
|
|
673
664
|
}
|
|
674
|
-
return this.parseForEachStatementWithoutDeclarations(initializer, forMode);
|
|
665
|
+
return this.parseForEachStatementWithoutDeclarations(initializer, forMode, start);
|
|
675
666
|
}
|
|
676
667
|
}
|
|
677
668
|
this.expect(Token.SEMICOLON);
|
|
678
|
-
return this.parseStandardForLoop(initializer);
|
|
669
|
+
return this.parseStandardForLoop(initializer, start);
|
|
679
670
|
}
|
|
680
|
-
parseStandardForLoopWithLexicalDeclarations(initializer) {
|
|
671
|
+
parseStandardForLoopWithLexicalDeclarations(initializer, start) {
|
|
681
672
|
// The condition and the next statement of the for loop must be parsed
|
|
682
673
|
// in a new scope.
|
|
683
|
-
return this.parseStandardForLoop(initializer);
|
|
674
|
+
return this.parseStandardForLoop(initializer, start);
|
|
684
675
|
}
|
|
685
|
-
parseForEachStatementWithDeclarations(initializer, forMode) {
|
|
676
|
+
parseForEachStatementWithDeclarations(initializer, forMode, start) {
|
|
686
677
|
// Just one declaration followed by in/of.
|
|
687
678
|
if (initializer.getDeclarations().length != 1) {
|
|
688
679
|
throw new SyntaxError(this.errorMessage('For In/Of loop Multi Bindings'));
|
|
689
680
|
}
|
|
690
|
-
return this.parseForEachStatementWithoutDeclarations(initializer, forMode);
|
|
681
|
+
return this.parseForEachStatementWithoutDeclarations(initializer, forMode, start);
|
|
691
682
|
}
|
|
692
|
-
parseForEachStatementWithoutDeclarations(initializer, forMode) {
|
|
683
|
+
parseForEachStatementWithoutDeclarations(initializer, forMode, start) {
|
|
693
684
|
let enumerable;
|
|
694
685
|
if (forMode == 'OF') {
|
|
695
686
|
this.setAcceptIN(true);
|
|
@@ -701,32 +692,31 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
701
692
|
}
|
|
702
693
|
this.expect(Token.RPAREN);
|
|
703
694
|
const body = this.parseStatement();
|
|
695
|
+
const range = this.createRange(start);
|
|
704
696
|
if (forMode === 'OF') {
|
|
705
|
-
return
|
|
697
|
+
return this.factory.createForOfStatement(initializer, enumerable, body, range);
|
|
706
698
|
}
|
|
707
699
|
else if (forMode === 'IN') {
|
|
708
|
-
return
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
throw new Error(this.errorMessage(`parsing for loop: ${this.position()}`));
|
|
700
|
+
return this.factory.createForInStatement(initializer, enumerable, body, range);
|
|
712
701
|
}
|
|
702
|
+
throw new Error(this.errorMessage(`parsing for loop: ${this.position()}`));
|
|
713
703
|
}
|
|
714
|
-
parseStandardForLoop(initializer) {
|
|
704
|
+
parseStandardForLoop(initializer, start) {
|
|
715
705
|
// CheckStackOverflow();
|
|
716
706
|
// ForStatementT loop = factory() -> NewForStatement(stmt_pos);
|
|
717
707
|
// Target target(this, loop, labels, own_labels, Target:: TARGET_FOR_ANONYMOUS);
|
|
718
|
-
let cond =
|
|
708
|
+
let cond = this.factory.createEmptyStatement();
|
|
719
709
|
if (this.peek().isNotType(Token.SEMICOLON)) {
|
|
720
710
|
cond = this.parseExpression();
|
|
721
711
|
}
|
|
722
712
|
this.expect(Token.SEMICOLON);
|
|
723
|
-
let next =
|
|
713
|
+
let next = this.factory.createEmptyStatement();
|
|
724
714
|
if (this.peek().isNotType(Token.RPAREN)) {
|
|
725
715
|
next = this.parseExpression();
|
|
726
716
|
}
|
|
727
717
|
this.expect(Token.RPAREN);
|
|
728
718
|
const body = this.parseStatement();
|
|
729
|
-
return
|
|
719
|
+
return this.factory.createForStatement(body, initializer, cond, next, this.createRange(start));
|
|
730
720
|
}
|
|
731
721
|
parseForAwaitStatement() {
|
|
732
722
|
// for await '(' ForDeclaration of AssignmentExpression ')'
|
|
@@ -735,7 +725,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
735
725
|
if (!this.isAwaitAllowed()) {
|
|
736
726
|
throw new SyntaxError(this.errorMessage('"await" is not allowed'));
|
|
737
727
|
}
|
|
738
|
-
this.expect(Token.FOR);
|
|
728
|
+
const start = this.expect(Token.FOR);
|
|
739
729
|
this.expect(Token.AWAIT);
|
|
740
730
|
this.expect(Token.LPAREN);
|
|
741
731
|
let hasDeclarations = false;
|
|
@@ -772,14 +762,16 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
772
762
|
this.restoreAcceptIN();
|
|
773
763
|
this.expect(Token.RPAREN);
|
|
774
764
|
const body = this.parseStatement();
|
|
775
|
-
|
|
765
|
+
const range = this.createRange(start);
|
|
766
|
+
return this.factory.createForAwaitOfStatement(eachVariable, iterable, body, range);
|
|
776
767
|
}
|
|
777
768
|
parseVariableDeclarations(varContext) {
|
|
778
769
|
// VariableDeclarations ::
|
|
779
770
|
// ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[',']
|
|
780
771
|
// var converted into ==> 'let' by parser
|
|
781
772
|
let mode;
|
|
782
|
-
const
|
|
773
|
+
const start = this.peek();
|
|
774
|
+
const token = start.token;
|
|
783
775
|
switch (token) {
|
|
784
776
|
case Token.CONST:
|
|
785
777
|
this.consume(token);
|
|
@@ -799,6 +791,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
799
791
|
do {
|
|
800
792
|
let name;
|
|
801
793
|
let value;
|
|
794
|
+
const range = this.createStartPosition();
|
|
802
795
|
// Check for an identifier first, so that we can elide the pattern in cases
|
|
803
796
|
// where there is no initializer (and so no proxy needs to be created).
|
|
804
797
|
if (Token.isAnyIdentifier(this.peek().token)) {
|
|
@@ -826,9 +819,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
826
819
|
}
|
|
827
820
|
// value = undefined;
|
|
828
821
|
}
|
|
829
|
-
|
|
822
|
+
this.updateRangeEnd(range);
|
|
823
|
+
variables.push(this.factory.createVariableDeclaration(name, value, range));
|
|
830
824
|
} while (this.check(Token.COMMA));
|
|
831
|
-
|
|
825
|
+
const range = this.createRange(start);
|
|
826
|
+
return this.factory.createVariableStatement(variables, mode, range);
|
|
832
827
|
}
|
|
833
828
|
parseBindingPattern(isPattern) {
|
|
834
829
|
// Pattern ::
|
|
@@ -849,9 +844,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
849
844
|
else if (token == Token.LBRACE) {
|
|
850
845
|
return this.parseObjectLiteral(isPattern);
|
|
851
846
|
}
|
|
852
|
-
|
|
853
|
-
throw new Error(this.errorMessage(`Unexpected Token: ${this.next().getValue()}`));
|
|
854
|
-
}
|
|
847
|
+
throw new Error(this.errorMessage(`Unexpected Token: ${this.next().getValue()}`));
|
|
855
848
|
}
|
|
856
849
|
parseAndClassifyIdentifier(next) {
|
|
857
850
|
// Updates made here must be reflected on ClassifyPropertyIdentifier.
|
|
@@ -874,29 +867,31 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
874
867
|
// ContinueStatement ::
|
|
875
868
|
// 'continue' ';'
|
|
876
869
|
// Identifier? is not supported
|
|
877
|
-
this.consume(Token.CONTINUE);
|
|
870
|
+
const start = this.consume(Token.CONTINUE);
|
|
878
871
|
let label;
|
|
879
872
|
if (!this.scanner.hasLineTerminatorBeforeNext() &&
|
|
880
873
|
!Token.isAutoSemicolon(this.peek().token)) {
|
|
881
874
|
// ECMA allows "eval" or "arguments" as labels even in strict mode.
|
|
882
875
|
label = this.parseIdentifier();
|
|
883
876
|
}
|
|
877
|
+
const range = this.createRange(start);
|
|
884
878
|
this.expectSemicolon();
|
|
885
|
-
return label
|
|
879
|
+
return this.factory.createContinueStatement(label, range);
|
|
886
880
|
}
|
|
887
881
|
parseBreakStatement() {
|
|
888
882
|
// BreakStatement ::
|
|
889
883
|
// 'break' ';'
|
|
890
884
|
// Identifier? is not supported
|
|
891
|
-
this.consume(Token.BREAK);
|
|
885
|
+
const start = this.consume(Token.BREAK);
|
|
892
886
|
let label;
|
|
893
887
|
if (!this.scanner.hasLineTerminatorBeforeNext() &&
|
|
894
888
|
!Token.isAutoSemicolon(this.peek().token)) {
|
|
895
889
|
// ECMA allows "eval" or "arguments" as labels even in strict mode.
|
|
896
890
|
label = this.parseIdentifier();
|
|
897
891
|
}
|
|
892
|
+
const range = this.createRange(start);
|
|
898
893
|
this.expectSemicolon();
|
|
899
|
-
return label
|
|
894
|
+
return this.factory.createBreakStatement(label, range);
|
|
900
895
|
}
|
|
901
896
|
parseReturnStatement() {
|
|
902
897
|
// ReturnStatement ::
|
|
@@ -904,7 +899,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
904
899
|
// Consume the return token. It is necessary to do that before
|
|
905
900
|
// reporting any errors on it, because of the way errors are
|
|
906
901
|
// reported (underlining).
|
|
907
|
-
this.consume(Token.RETURN);
|
|
902
|
+
const start = this.consume(Token.RETURN);
|
|
908
903
|
const tokenExp = this.peek();
|
|
909
904
|
let returnValue;
|
|
910
905
|
// ExpressionT return_value = impl() -> NullExpression();
|
|
@@ -917,8 +912,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
917
912
|
else {
|
|
918
913
|
returnValue = this.parseExpression();
|
|
919
914
|
}
|
|
915
|
+
const range = this.createRange(start);
|
|
920
916
|
this.expectSemicolon();
|
|
921
|
-
return
|
|
917
|
+
return this.factory.createReturnStatement(returnValue, range);
|
|
922
918
|
}
|
|
923
919
|
parseExpressionOrLabelledStatement(allowFunction) {
|
|
924
920
|
// ExpressionStatement | LabelledStatement ::
|
|
@@ -947,10 +943,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
947
943
|
default:
|
|
948
944
|
break;
|
|
949
945
|
}
|
|
946
|
+
const range = this.createStartPosition();
|
|
950
947
|
const startsWithIdentifier = Token.isAnyIdentifier(this.peek().token);
|
|
951
948
|
this.setAcceptIN(true);
|
|
952
949
|
const expression = this.parseExpressionCoverGrammar();
|
|
953
|
-
if (this.peek().isType(Token.COLON) && startsWithIdentifier && this.isIdentifier(expression)) {
|
|
950
|
+
if (this.peek().isType(Token.COLON) && startsWithIdentifier && this.factory.isIdentifier(expression)) {
|
|
954
951
|
// The whole expression was a single identifier, and not, e.g.,
|
|
955
952
|
// something starting with an identifier or a parenthesized identifier.
|
|
956
953
|
// Remove the "ghost" variable that turned out to be a label from the top
|
|
@@ -963,11 +960,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
963
960
|
&& allowFunction == AllowLabelledFunctionStatement.AllowLabelledFunctionStatement) {
|
|
964
961
|
const result = this.parseFunctionDeclaration();
|
|
965
962
|
this.restoreAcceptIN();
|
|
966
|
-
|
|
963
|
+
this.updateRangeEnd(range);
|
|
964
|
+
return this.factory.createLabeledStatement(expression, result, range);
|
|
967
965
|
}
|
|
968
966
|
const result = this.parseStatement(allowFunction);
|
|
969
967
|
this.restoreAcceptIN();
|
|
970
|
-
|
|
968
|
+
this.updateRangeEnd(range);
|
|
969
|
+
return this.factory.createLabeledStatement(expression, result, range);
|
|
971
970
|
}
|
|
972
971
|
this.restoreAcceptIN();
|
|
973
972
|
// Parsed expression statement, followed by semicolon.
|
|
@@ -981,11 +980,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
981
980
|
return result;
|
|
982
981
|
}
|
|
983
982
|
parseFunctionDeclaration() {
|
|
984
|
-
this.consume(Token.FUNCTION);
|
|
983
|
+
const start = this.consume(Token.FUNCTION);
|
|
985
984
|
if (this.check(Token.MUL)) {
|
|
986
985
|
throw new Error(this.errorMessage(`Error Generator In Single Statement Context`));
|
|
987
986
|
}
|
|
988
|
-
return this.parseHoistableDeclaration01(FunctionKind.NormalFunction, undefined, false);
|
|
987
|
+
return this.parseHoistableDeclaration01(FunctionKind.NormalFunction, undefined, false, start);
|
|
989
988
|
}
|
|
990
989
|
parseAsyncFunctionLiteral() {
|
|
991
990
|
// AsyncFunctionLiteral ::
|
|
@@ -997,7 +996,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
997
996
|
if (this.current().isNotType(Token.ASYNC)) {
|
|
998
997
|
throw new SyntaxError(this.errorMessage('invalid token'));
|
|
999
998
|
}
|
|
1000
|
-
this.consume(Token.FUNCTION);
|
|
999
|
+
const start = this.consume(Token.FUNCTION);
|
|
1001
1000
|
let name;
|
|
1002
1001
|
let syntaxKind = FunctionSyntaxKind.AnonymousExpression;
|
|
1003
1002
|
let flags = FunctionKind.AsyncFunction;
|
|
@@ -1008,17 +1007,17 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1008
1007
|
syntaxKind = FunctionSyntaxKind.NamedExpression;
|
|
1009
1008
|
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
1010
1009
|
}
|
|
1011
|
-
return this.parseFunctionLiteral(flags, syntaxKind, name);
|
|
1010
|
+
return this.parseFunctionLiteral(flags, syntaxKind, name, start);
|
|
1012
1011
|
}
|
|
1013
|
-
parseHoistableDeclaration(names, defaultExport) {
|
|
1012
|
+
parseHoistableDeclaration(names, defaultExport, start) {
|
|
1014
1013
|
this.consume(Token.FUNCTION);
|
|
1015
1014
|
let flags = FunctionKind.NormalFunction;
|
|
1016
1015
|
if (this.check(Token.MUL)) {
|
|
1017
1016
|
flags = FunctionKind.GeneratorFunction;
|
|
1018
1017
|
}
|
|
1019
|
-
return this.parseHoistableDeclaration01(flags, names, defaultExport);
|
|
1018
|
+
return this.parseHoistableDeclaration01(flags, names, defaultExport, start);
|
|
1020
1019
|
}
|
|
1021
|
-
parseHoistableDeclaration01(flag, names, defaultExport) {
|
|
1020
|
+
parseHoistableDeclaration01(flag, names, defaultExport, start) {
|
|
1022
1021
|
// FunctionDeclaration ::
|
|
1023
1022
|
// 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}'
|
|
1024
1023
|
// 'function' '(' FormalParameters ')' '{' FunctionBody '}'
|
|
@@ -1037,7 +1036,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1037
1036
|
let name;
|
|
1038
1037
|
if (this.peek().isType(Token.LPAREN)) {
|
|
1039
1038
|
if (defaultExport) {
|
|
1040
|
-
name =
|
|
1039
|
+
name = this.factory.createIdentifier('default', this.createRange(start));
|
|
1041
1040
|
}
|
|
1042
1041
|
else {
|
|
1043
1042
|
throw new SyntaxError(this.errorMessage('Missing Function Name'));
|
|
@@ -1047,7 +1046,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1047
1046
|
name = this.parseIdentifier(this.getLastFunctionKind());
|
|
1048
1047
|
}
|
|
1049
1048
|
names?.push(name.toString());
|
|
1050
|
-
return this.parseFunctionLiteral(flag, FunctionSyntaxKind.Declaration, name);
|
|
1049
|
+
return this.parseFunctionLiteral(flag, FunctionSyntaxKind.Declaration, name, start);
|
|
1051
1050
|
}
|
|
1052
1051
|
parseIdentifier(kind) {
|
|
1053
1052
|
kind ?? (kind = this.functionKind);
|
|
@@ -1064,9 +1063,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1064
1063
|
const current = this.current();
|
|
1065
1064
|
switch (current.token) {
|
|
1066
1065
|
case Token.AWAIT:
|
|
1067
|
-
return
|
|
1066
|
+
return this.factory.createIdentifier('await', current.range);
|
|
1068
1067
|
case Token.ASYNC:
|
|
1069
|
-
return
|
|
1068
|
+
return this.factory.createIdentifier('async', current.range);
|
|
1070
1069
|
case Token.IDENTIFIER:
|
|
1071
1070
|
case Token.PRIVATE_NAME:
|
|
1072
1071
|
return current.getValue();
|
|
@@ -1075,20 +1074,20 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1075
1074
|
}
|
|
1076
1075
|
const name = current.getValue().toString();
|
|
1077
1076
|
if (name == 'constructor') {
|
|
1078
|
-
return
|
|
1077
|
+
return this.factory.createIdentifier('constructor', current.range);
|
|
1079
1078
|
}
|
|
1080
1079
|
if (name == 'name') {
|
|
1081
|
-
return
|
|
1080
|
+
return this.factory.createIdentifier('name', current.range);
|
|
1082
1081
|
}
|
|
1083
1082
|
if (name == 'eval') {
|
|
1084
|
-
return
|
|
1083
|
+
return this.factory.createIdentifier('eval', current.range);
|
|
1085
1084
|
}
|
|
1086
1085
|
else if (name == 'arguments') {
|
|
1087
|
-
return
|
|
1086
|
+
return this.factory.createIdentifier('arguments', current.range);
|
|
1088
1087
|
}
|
|
1089
1088
|
return current.getValue();
|
|
1090
1089
|
}
|
|
1091
|
-
parseFunctionLiteral(flag, functionSyntaxKind, name) {
|
|
1090
|
+
parseFunctionLiteral(flag, functionSyntaxKind, name, start) {
|
|
1092
1091
|
// Function ::
|
|
1093
1092
|
// '(' FormalParameterList? ')' '{' FunctionBody '}'
|
|
1094
1093
|
this.setFunctionKind(flag);
|
|
@@ -1096,16 +1095,18 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1096
1095
|
this.expect(Token.LPAREN);
|
|
1097
1096
|
const formals = this.parseFormalParameterList(functionInfo);
|
|
1098
1097
|
this.expect(Token.RPAREN);
|
|
1099
|
-
this.expect(Token.LBRACE);
|
|
1098
|
+
const bodyStart = this.expect(Token.LBRACE);
|
|
1100
1099
|
this.setAcceptIN(true);
|
|
1101
1100
|
const body = this.parseFunctionBody(flag, FunctionBodyType.BLOCK, functionSyntaxKind);
|
|
1102
1101
|
this.restoreAcceptIN();
|
|
1103
1102
|
this.restoreFunctionKind();
|
|
1104
|
-
const
|
|
1103
|
+
const bodyRange = this.createRange(bodyStart);
|
|
1104
|
+
const funcRange = this.createRange(start);
|
|
1105
|
+
const bodyBlock = this.factory.createBlock(body, bodyRange);
|
|
1105
1106
|
if (name) {
|
|
1106
|
-
return
|
|
1107
|
+
return this.factory.createFunctionDeclaration(formals, bodyBlock, isAsyncFunction(flag), isGeneratorFunction(flag), name, funcRange);
|
|
1107
1108
|
}
|
|
1108
|
-
return
|
|
1109
|
+
return this.factory.createFunctionExpression(formals, bodyBlock, isAsyncFunction(flag), isGeneratorFunction(flag), funcRange);
|
|
1109
1110
|
}
|
|
1110
1111
|
parseFunctionBody(kind, bodyType, functionSyntaxKind) {
|
|
1111
1112
|
// Building the parameter initialization block declares the parameters.
|
|
@@ -1157,7 +1158,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1157
1158
|
if (!stat) {
|
|
1158
1159
|
break;
|
|
1159
1160
|
}
|
|
1160
|
-
if (this.isEmptyStatement(stat)) {
|
|
1161
|
+
if (this.factory.isEmptyStatement(stat)) {
|
|
1161
1162
|
continue;
|
|
1162
1163
|
}
|
|
1163
1164
|
list.push(stat);
|
|
@@ -1199,6 +1200,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1199
1200
|
parseFormalParameter(functionInfo) {
|
|
1200
1201
|
// FormalParameter[Yield,GeneratorParameter] :
|
|
1201
1202
|
// BindingElement[?Yield, ?GeneratorParameter]
|
|
1203
|
+
const range = this.createStartPosition();
|
|
1202
1204
|
functionInfo.rest = this.check(Token.ELLIPSIS);
|
|
1203
1205
|
const pattern = this.parseBindingPattern(true);
|
|
1204
1206
|
let initializer;
|
|
@@ -1207,12 +1209,16 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1207
1209
|
throw new Error(this.errorMessage(`Rest Default Initializer`));
|
|
1208
1210
|
}
|
|
1209
1211
|
this.setAcceptIN(true);
|
|
1210
|
-
const
|
|
1212
|
+
const right = this.parseAssignmentExpression();
|
|
1211
1213
|
this.restoreAcceptIN();
|
|
1212
|
-
|
|
1214
|
+
this.updateRangeEnd(range);
|
|
1215
|
+
const left = this.checkParamType(pattern);
|
|
1216
|
+
initializer = this.factory.createAssignmentPattern(left, right, range);
|
|
1213
1217
|
}
|
|
1214
1218
|
else {
|
|
1215
|
-
|
|
1219
|
+
this.updateRangeEnd(range);
|
|
1220
|
+
const param = this.checkParamType(pattern);
|
|
1221
|
+
initializer = functionInfo.rest ? this.factory.createRestElement(param, param.range && [range[0], param.range[1]]) : param;
|
|
1216
1222
|
}
|
|
1217
1223
|
return initializer;
|
|
1218
1224
|
}
|
|
@@ -1240,8 +1246,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1240
1246
|
return this.expressionListToExpression(list);
|
|
1241
1247
|
}
|
|
1242
1248
|
parseArrowParametersWithRest(list) {
|
|
1243
|
-
this.consume(Token.ELLIPSIS);
|
|
1249
|
+
const start = this.consume(Token.ELLIPSIS);
|
|
1244
1250
|
const pattern = this.parseBindingPattern(true);
|
|
1251
|
+
const range = this.createRange(start);
|
|
1245
1252
|
if (this.peek().isType(Token.ASSIGN)) {
|
|
1246
1253
|
throw new Error(this.errorMessage(`Error A rest parameter cannot have an initializer`));
|
|
1247
1254
|
}
|
|
@@ -1254,7 +1261,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1254
1261
|
if (this.peek().isNotType(Token.RPAREN) || this.peekAhead().isNotType(Token.ARROW)) {
|
|
1255
1262
|
throw new Error(this.errorMessage(`Error Unexpected Token At ${this.position()}`));
|
|
1256
1263
|
}
|
|
1257
|
-
list.push(
|
|
1264
|
+
list.push(this.factory.createSpreadElement(pattern, range));
|
|
1258
1265
|
return this.expressionListToExpression(list);
|
|
1259
1266
|
}
|
|
1260
1267
|
expressionListToExpression(list) {
|
|
@@ -1262,11 +1269,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1262
1269
|
if (list.length === 1) {
|
|
1263
1270
|
return first;
|
|
1264
1271
|
}
|
|
1265
|
-
if (first
|
|
1272
|
+
if (this.factory.isSequenceExpression(first)) {
|
|
1266
1273
|
first.getExpressions().push(...list.slice(1));
|
|
1267
1274
|
return first;
|
|
1268
1275
|
}
|
|
1269
|
-
|
|
1276
|
+
const range = this.createRange(list.at(0));
|
|
1277
|
+
range && this.updateRangeEnd(range);
|
|
1278
|
+
return this.factory.createCommaListExpression(list, range);
|
|
1270
1279
|
}
|
|
1271
1280
|
parseMemberExpression() {
|
|
1272
1281
|
// MemberExpression ::
|
|
@@ -1284,15 +1293,6 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1284
1293
|
const result = this.parsePrimaryExpression();
|
|
1285
1294
|
return this.parseMemberExpressionContinuation(result);
|
|
1286
1295
|
}
|
|
1287
|
-
toParamNode(expression) {
|
|
1288
|
-
if (expression instanceof AssignmentExpression) {
|
|
1289
|
-
return new Param(expression.getLeft(), expression.getRight());
|
|
1290
|
-
}
|
|
1291
|
-
if (expression instanceof GroupingExpression) {
|
|
1292
|
-
return new Param(expression.getNode());
|
|
1293
|
-
}
|
|
1294
|
-
return new Param(expression);
|
|
1295
|
-
}
|
|
1296
1296
|
parsePrimaryExpression() {
|
|
1297
1297
|
// PrimaryExpression ::
|
|
1298
1298
|
// 'this'
|
|
@@ -1327,28 +1327,22 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1327
1327
|
if (this.peek().isType(Token.ARROW)) {
|
|
1328
1328
|
this.setFunctionKind(kind);
|
|
1329
1329
|
const name = this.parseAndClassifyIdentifier(token);
|
|
1330
|
-
const params = [];
|
|
1331
|
-
|
|
1332
|
-
params.push(...name.getExpressions().map(this.toParamNode));
|
|
1333
|
-
}
|
|
1334
|
-
else {
|
|
1335
|
-
params.push(this.toParamNode(name));
|
|
1336
|
-
}
|
|
1337
|
-
const arrow = this.parseArrowFunctionLiteral(params, kind);
|
|
1330
|
+
const params = this.factory.isSequenceExpression(name) ? name.getExpressions() : [name];
|
|
1331
|
+
const arrow = this.parseArrowFunctionLiteral(params, kind, this.createRange(token));
|
|
1338
1332
|
this.restoreFunctionKind();
|
|
1339
1333
|
return arrow;
|
|
1340
1334
|
}
|
|
1341
1335
|
return this.parseAndClassifyIdentifier(token);
|
|
1342
1336
|
}
|
|
1343
1337
|
if (Token.isLiteral(token.token)) {
|
|
1344
|
-
return
|
|
1338
|
+
return this.next().getValue();
|
|
1345
1339
|
}
|
|
1346
1340
|
switch (token.token) {
|
|
1347
1341
|
case Token.NEW:
|
|
1348
1342
|
return this.parseMemberWithPresentNewPrefixesExpression();
|
|
1349
1343
|
case Token.THIS:
|
|
1350
1344
|
this.consume(Token.THIS);
|
|
1351
|
-
return
|
|
1345
|
+
return this.factory.createThis(token.range);
|
|
1352
1346
|
case Token.DIV:
|
|
1353
1347
|
case Token.DIV_ASSIGN:
|
|
1354
1348
|
// case Token.REGEXP_LITERAL:
|
|
@@ -1374,7 +1368,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1374
1368
|
if (!this.peek().isType(Token.ARROW)) {
|
|
1375
1369
|
throw new Error(this.errorMessage(`Unexpected Token: ${Token.RPAREN.getName()}`));
|
|
1376
1370
|
}
|
|
1377
|
-
const result =
|
|
1371
|
+
const result = this.factory.createCommaListExpression([], this.createRange(token));
|
|
1378
1372
|
this.markParenthesized(result);
|
|
1379
1373
|
return result;
|
|
1380
1374
|
}
|
|
@@ -1418,10 +1412,10 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1418
1412
|
// single TEMPLATE_SPAN and no expressions.
|
|
1419
1413
|
if (next.isType(Token.TEMPLATE_TAIL)) {
|
|
1420
1414
|
this.consume(Token.TEMPLATE_TAIL);
|
|
1421
|
-
const
|
|
1422
|
-
return this.createTemplateLiteralExpressionNode([string], [], tag);
|
|
1415
|
+
const template = next.getValue();
|
|
1416
|
+
return this.createTemplateLiteralExpressionNode([template.string], [], tag, template.range);
|
|
1423
1417
|
}
|
|
1424
|
-
this.consume(Token.TEMPLATE_SPAN);
|
|
1418
|
+
const start = this.consume(Token.TEMPLATE_SPAN);
|
|
1425
1419
|
const expressions = [];
|
|
1426
1420
|
const strings = [];
|
|
1427
1421
|
strings.push(next.getValue().string);
|
|
@@ -1446,16 +1440,15 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1446
1440
|
if (next.isNotType(Token.TEMPLATE_TAIL)) {
|
|
1447
1441
|
throw new SyntaxError(this.errorMessage(`Unexpected Token: ${JSON.stringify(next)}`));
|
|
1448
1442
|
}
|
|
1443
|
+
const range = this.createRange(start);
|
|
1449
1444
|
// Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
|
|
1450
|
-
return this.createTemplateLiteralExpressionNode(strings, expressions, tag);
|
|
1445
|
+
return this.createTemplateLiteralExpressionNode(strings, expressions, tag, range);
|
|
1451
1446
|
}
|
|
1452
|
-
createTemplateLiteralExpressionNode(strings, expressions, tag) {
|
|
1447
|
+
createTemplateLiteralExpressionNode(strings, expressions, tag, range) {
|
|
1453
1448
|
if (tag) {
|
|
1454
|
-
return
|
|
1455
|
-
}
|
|
1456
|
-
else {
|
|
1457
|
-
return new TemplateLiteral(strings, expressions);
|
|
1449
|
+
return this.factory.createTaggedTemplateExpression(tag, strings, expressions, range);
|
|
1458
1450
|
}
|
|
1451
|
+
return this.factory.createTemplateExpression(strings, expressions, range);
|
|
1459
1452
|
}
|
|
1460
1453
|
parseMemberWithPresentNewPrefixesExpression() {
|
|
1461
1454
|
// NewExpression ::
|
|
@@ -1476,19 +1469,19 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1476
1469
|
// new new foo() means new (new foo())
|
|
1477
1470
|
// new new foo().bar().baz means (new (new foo()).bar()).baz
|
|
1478
1471
|
// new super.x means new (super.x)
|
|
1479
|
-
this.consume(Token.NEW);
|
|
1472
|
+
const start = this.consume(Token.NEW);
|
|
1480
1473
|
let result;
|
|
1481
1474
|
// CheckStackOverflow();
|
|
1482
1475
|
if (this.peek().isType(Token.IMPORT) && this.peekAhead().isType(Token.LPAREN)) {
|
|
1483
1476
|
throw new SyntaxError(this.errorMessage(`Import Call Not New Expression`));
|
|
1484
1477
|
}
|
|
1485
1478
|
else if (this.peek().isType(Token.PERIOD)) {
|
|
1486
|
-
result = this.parseNewTargetExpression();
|
|
1479
|
+
result = this.parseNewTargetExpression(start);
|
|
1487
1480
|
return this.parseMemberExpressionContinuation(result);
|
|
1488
1481
|
}
|
|
1489
1482
|
else {
|
|
1490
1483
|
result = this.parseMemberExpression();
|
|
1491
|
-
if (result
|
|
1484
|
+
if (this.factory.isSuper(result)) {
|
|
1492
1485
|
// new super() is never allowed
|
|
1493
1486
|
throw new SyntaxError(this.errorMessage(`Unexpected Super, new super() is never allowed`));
|
|
1494
1487
|
}
|
|
@@ -1496,14 +1489,14 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1496
1489
|
if (this.peek().isType(Token.LPAREN)) {
|
|
1497
1490
|
// NewExpression with arguments.
|
|
1498
1491
|
const args = this.parseArguments();
|
|
1499
|
-
result =
|
|
1492
|
+
result = this.factory.createNewExpression(result, args, this.createRange(start));
|
|
1500
1493
|
// The expression can still continue with . or [ after the arguments.
|
|
1501
1494
|
return this.parseMemberExpressionContinuation(result);
|
|
1502
1495
|
}
|
|
1503
1496
|
if (this.peek().isType(Token.QUESTION_PERIOD)) {
|
|
1504
1497
|
throw new SyntaxError(this.errorMessage(`Optional Chaining with New not allowed, new x?.y()`));
|
|
1505
1498
|
}
|
|
1506
|
-
return
|
|
1499
|
+
return this.factory.createNewExpression(result, undefined, this.createRange(start));
|
|
1507
1500
|
}
|
|
1508
1501
|
parseArguments(maybeArrow) {
|
|
1509
1502
|
// Arguments ::
|
|
@@ -1511,12 +1504,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1511
1504
|
this.consume(Token.LPAREN);
|
|
1512
1505
|
const args = [];
|
|
1513
1506
|
while (this.peek().isNotType(Token.RPAREN)) {
|
|
1507
|
+
const range = this.createStartPosition();
|
|
1514
1508
|
const isSpread = this.check(Token.ELLIPSIS);
|
|
1515
1509
|
this.setAcceptIN(true);
|
|
1516
1510
|
let argument = this.parseAssignmentExpressionCoverGrammar();
|
|
1517
1511
|
if (ParsingArrowHeadFlag.MaybeArrowHead === maybeArrow) {
|
|
1518
1512
|
if (isSpread) {
|
|
1519
|
-
if (argument
|
|
1513
|
+
if (this.factory.isAssignmentExpression(argument)) {
|
|
1520
1514
|
this.restoreAcceptIN();
|
|
1521
1515
|
throw new Error(this.errorMessage(` Rest parameter may not have a default initializer'`));
|
|
1522
1516
|
}
|
|
@@ -1527,7 +1521,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1527
1521
|
}
|
|
1528
1522
|
}
|
|
1529
1523
|
if (isSpread) {
|
|
1530
|
-
|
|
1524
|
+
this.updateRangeEnd(range);
|
|
1525
|
+
argument = this.factory.createSpreadElement(argument, range);
|
|
1531
1526
|
}
|
|
1532
1527
|
args.push(argument);
|
|
1533
1528
|
this.restoreAcceptIN();
|
|
@@ -1545,6 +1540,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1545
1540
|
// ArrowFunction
|
|
1546
1541
|
// YieldExpression
|
|
1547
1542
|
// LeftHandSideExpression AssignmentOperator AssignmentExpression
|
|
1543
|
+
const range = this.createStartPosition();
|
|
1548
1544
|
if (this.peek().isType(Token.YIELD) && isGeneratorFunction(this.functionKind)) {
|
|
1549
1545
|
return this.parseYieldExpression();
|
|
1550
1546
|
}
|
|
@@ -1557,37 +1553,34 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1557
1553
|
;
|
|
1558
1554
|
// Arrow functions.
|
|
1559
1555
|
if (op === Token.ARROW) {
|
|
1560
|
-
if (!this.isIdentifier(expression) && !this.isParenthesized(expression)) {
|
|
1556
|
+
if (!this.factory.isIdentifier(expression) && !this.isParenthesized(expression)) {
|
|
1561
1557
|
throw new Error(this.errorMessage(`Malformed Arrow Fun Param List`));
|
|
1562
1558
|
}
|
|
1563
1559
|
const kind = FunctionKind.NormalFunction;
|
|
1564
1560
|
this.setFunctionKind(kind);
|
|
1565
1561
|
let arrow;
|
|
1566
|
-
if (expression
|
|
1567
|
-
|
|
1568
|
-
.map(expr => new Param(expr));
|
|
1569
|
-
arrow = this.parseArrowFunctionLiteral(params, FunctionKind.NormalFunction);
|
|
1562
|
+
if (this.factory.isSequenceExpression(expression)) {
|
|
1563
|
+
arrow = this.parseArrowFunctionLiteral(expression.getExpressions(), FunctionKind.NormalFunction, range);
|
|
1570
1564
|
}
|
|
1571
|
-
else if (expression
|
|
1572
|
-
arrow = this.parseArrowFunctionLiteral([
|
|
1565
|
+
else if (this.factory.isGroupingExpression(expression)) {
|
|
1566
|
+
arrow = this.parseArrowFunctionLiteral([expression.getNode()], FunctionKind.NormalFunction, range);
|
|
1573
1567
|
}
|
|
1574
1568
|
else {
|
|
1575
1569
|
this.clearParenthesized(expression);
|
|
1576
|
-
arrow = this.parseArrowFunctionLiteral([
|
|
1570
|
+
arrow = this.parseArrowFunctionLiteral([expression], FunctionKind.NormalFunction, range);
|
|
1577
1571
|
}
|
|
1578
1572
|
this.restoreFunctionKind();
|
|
1579
1573
|
return arrow;
|
|
1580
1574
|
}
|
|
1581
1575
|
if (this.isAssignableIdentifier(expression)) {
|
|
1582
1576
|
}
|
|
1583
|
-
else if (this.
|
|
1577
|
+
else if (this.factory.isPropertyOrMemberExpression(expression)) {
|
|
1584
1578
|
}
|
|
1585
|
-
else if (this.
|
|
1579
|
+
else if (this.factory.canBePattern(expression) && Token.isAssignment(op)) {
|
|
1586
1580
|
// Destructuring assignment.
|
|
1587
|
-
expression = expression
|
|
1588
|
-
?
|
|
1589
|
-
:
|
|
1590
|
-
// expression_scope() -> ValidateAsPattern(expression, lhs_beg_pos, end_position());
|
|
1581
|
+
expression = this.factory.isObjectExpression(expression)
|
|
1582
|
+
? this.factory.createObjectBindingPattern(expression.getProperties(), expression.range)
|
|
1583
|
+
: this.factory.createArrayBindingPattern(expression.getElements(), expression.range);
|
|
1591
1584
|
}
|
|
1592
1585
|
else {
|
|
1593
1586
|
if (!this.isValidReferenceExpression(expression)) {
|
|
@@ -1604,36 +1597,34 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1604
1597
|
if (!Token.isAssignment(op)) {
|
|
1605
1598
|
throw new Error(this.errorMessage(`Invalid Destructuring Target`));
|
|
1606
1599
|
}
|
|
1607
|
-
|
|
1600
|
+
this.updateRangeEnd(range);
|
|
1601
|
+
return this.factory.createAssignment(op.getName(), expression, right, range);
|
|
1608
1602
|
}
|
|
1609
1603
|
parseAssignmentExpression() {
|
|
1610
1604
|
return this.parseAssignmentExpressionCoverGrammar();
|
|
1611
1605
|
}
|
|
1612
|
-
checkParamType(
|
|
1613
|
-
if (
|
|
1614
|
-
return
|
|
1606
|
+
checkParamType(node) {
|
|
1607
|
+
if (this.factory.isArrayExpression(node)) {
|
|
1608
|
+
return this.factory.createArrayBindingPattern(node.getElements(), node.range);
|
|
1615
1609
|
}
|
|
1616
|
-
else if (
|
|
1617
|
-
return
|
|
1610
|
+
else if (this.factory.isObjectExpression(node)) {
|
|
1611
|
+
return this.factory.createObjectBindingPattern(node.getProperties(), node.range);
|
|
1618
1612
|
}
|
|
1619
|
-
else if (
|
|
1620
|
-
let arg =
|
|
1613
|
+
else if (this.factory.isSpreadElement(node)) {
|
|
1614
|
+
let arg = node.getArgument();
|
|
1621
1615
|
// let param = arg;
|
|
1622
|
-
if (arg
|
|
1623
|
-
arg =
|
|
1616
|
+
if (this.factory.isArrayExpression(arg)) {
|
|
1617
|
+
arg = this.factory.createArrayBindingPattern(arg.getElements(), arg.range);
|
|
1624
1618
|
}
|
|
1625
|
-
else if (arg
|
|
1626
|
-
arg =
|
|
1619
|
+
else if (this.factory.isObjectExpression(arg)) {
|
|
1620
|
+
arg = this.factory.createObjectBindingPattern(arg.getProperties(), arg.range);
|
|
1627
1621
|
}
|
|
1628
|
-
return
|
|
1622
|
+
return this.factory.createRestElement(arg, node.range);
|
|
1629
1623
|
}
|
|
1630
|
-
return
|
|
1624
|
+
return node;
|
|
1631
1625
|
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
parseArrowFunctionLiteral(parameters, kind) {
|
|
1636
|
-
parameters = this.mapParams(parameters);
|
|
1626
|
+
parseArrowFunctionLiteral(parameters, kind, range) {
|
|
1627
|
+
parameters = parameters.map(node => this.checkParamType(node));
|
|
1637
1628
|
if (this.peek().isNotType(Token.ARROW)) {
|
|
1638
1629
|
throw new SyntaxError(this.errorMessage('SyntaxError Expecting Arrow Token'));
|
|
1639
1630
|
}
|
|
@@ -1653,7 +1644,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1653
1644
|
has_braces = false;
|
|
1654
1645
|
body = this.parseFunctionBody(kind, FunctionBodyType.EXPRESSION, FunctionSyntaxKind.AnonymousExpression);
|
|
1655
1646
|
}
|
|
1656
|
-
|
|
1647
|
+
this.updateRangeEnd(range);
|
|
1648
|
+
return this.factory.createArrowFunction(parameters, body, !has_braces, isAsyncFunction(kind), range);
|
|
1657
1649
|
}
|
|
1658
1650
|
parseRegExpLiteral() {
|
|
1659
1651
|
if (!this.scanner.scanRegExpPattern()) {
|
|
@@ -1664,23 +1656,24 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1664
1656
|
parseArrayLiteral(isPattern) {
|
|
1665
1657
|
// ArrayLiteral ::
|
|
1666
1658
|
// '[' Expression? (',' Expression?)* ']'
|
|
1667
|
-
this.consume(Token.LBRACK);
|
|
1659
|
+
const start = this.consume(Token.LBRACK);
|
|
1668
1660
|
let first_spread_index = -1;
|
|
1669
1661
|
const values = [];
|
|
1670
1662
|
while (!this.check(Token.RBRACK)) {
|
|
1671
1663
|
let elem;
|
|
1672
|
-
|
|
1664
|
+
const peek = this.peek();
|
|
1665
|
+
if (peek.isType(Token.COMMA)) {
|
|
1673
1666
|
elem = null;
|
|
1674
1667
|
}
|
|
1675
1668
|
else if (this.check(Token.ELLIPSIS)) {
|
|
1676
1669
|
this.setAcceptIN(true);
|
|
1677
1670
|
const argument = this.parsePossibleDestructuringSubPattern();
|
|
1678
1671
|
this.restoreAcceptIN();
|
|
1679
|
-
elem =
|
|
1672
|
+
elem = this.factory.createSpreadElement(argument, this.createRange(peek));
|
|
1680
1673
|
if (first_spread_index < 0) {
|
|
1681
1674
|
first_spread_index = values.length;
|
|
1682
1675
|
}
|
|
1683
|
-
if (argument
|
|
1676
|
+
if (this.factory.isAssignmentExpression(argument) && isPattern) {
|
|
1684
1677
|
throw new SyntaxError(this.errorMessage('Invalid Destructuring Target'));
|
|
1685
1678
|
}
|
|
1686
1679
|
if (this.peek().isType(Token.COMMA)) {
|
|
@@ -1697,7 +1690,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1697
1690
|
this.expect(Token.COMMA);
|
|
1698
1691
|
}
|
|
1699
1692
|
}
|
|
1700
|
-
|
|
1693
|
+
const range = this.createRange(start);
|
|
1694
|
+
if (isPattern) {
|
|
1695
|
+
return this.factory.createArrayBindingPattern(values, range);
|
|
1696
|
+
}
|
|
1697
|
+
return this.factory.createArrayLiteralExpression(values, range);
|
|
1701
1698
|
}
|
|
1702
1699
|
parsePossibleDestructuringSubPattern() {
|
|
1703
1700
|
return this.parseAssignmentExpressionCoverGrammar();
|
|
@@ -1705,7 +1702,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1705
1702
|
parseObjectLiteral(isPattern) {
|
|
1706
1703
|
// ObjectLiteral ::
|
|
1707
1704
|
// '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
|
|
1708
|
-
this.consume(Token.LBRACE);
|
|
1705
|
+
const start = this.consume(Token.LBRACE);
|
|
1709
1706
|
const properties = [];
|
|
1710
1707
|
while (!this.check(Token.RBRACE)) {
|
|
1711
1708
|
const property = this.parseObjectPropertyDefinition(isPattern);
|
|
@@ -1714,10 +1711,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1714
1711
|
this.expect(Token.COMMA);
|
|
1715
1712
|
}
|
|
1716
1713
|
}
|
|
1714
|
+
const range = this.createRange(start);
|
|
1717
1715
|
if (isPattern) {
|
|
1718
|
-
return
|
|
1716
|
+
return this.factory.createObjectBindingPattern(properties, range);
|
|
1719
1717
|
}
|
|
1720
|
-
return
|
|
1718
|
+
return this.factory.createObjectLiteralExpression(properties, range);
|
|
1721
1719
|
}
|
|
1722
1720
|
parseObjectPropertyDefinition(isPattern) {
|
|
1723
1721
|
const propInfo = new PropertyKindInfo();
|
|
@@ -1726,15 +1724,17 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1726
1724
|
case PropertyKind.Spread:
|
|
1727
1725
|
let value = nameExpression;
|
|
1728
1726
|
if (isPattern) {
|
|
1729
|
-
value =
|
|
1727
|
+
value = this.factory.createRestElement(value.getArgument(), value.range);
|
|
1730
1728
|
}
|
|
1731
|
-
|
|
1729
|
+
const range = this.createRange(propInfo.rangeStart);
|
|
1730
|
+
return this.factory.createPropertyDeclaration(value.getArgument(), value, 'init', false, false, propInfo.isComputedName, range);
|
|
1732
1731
|
case PropertyKind.Value: {
|
|
1733
1732
|
this.consume(Token.COLON);
|
|
1734
1733
|
this.setAcceptIN(true);
|
|
1735
1734
|
const value = this.parsePossibleDestructuringSubPattern();
|
|
1736
1735
|
this.restoreAcceptIN();
|
|
1737
|
-
|
|
1736
|
+
const range = this.createRange(propInfo.rangeStart);
|
|
1737
|
+
return this.factory.createPropertyDeclaration(nameExpression, value, 'init', false, false, propInfo.isComputedName, range);
|
|
1738
1738
|
}
|
|
1739
1739
|
case PropertyKind.Assign:
|
|
1740
1740
|
case PropertyKind.ShorthandOrClassField:
|
|
@@ -1745,7 +1745,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1745
1745
|
//
|
|
1746
1746
|
// CoverInitializedName
|
|
1747
1747
|
// IdentifierReference Initializer?
|
|
1748
|
-
const lhs =
|
|
1748
|
+
const lhs = this.factory.createIdentifier(propInfo.name, this.createRange(propInfo.rangeStart));
|
|
1749
1749
|
if (!this.isAssignableIdentifier(lhs)) {
|
|
1750
1750
|
throw new Error(this.errorMessage('Strict Eval Arguments'));
|
|
1751
1751
|
}
|
|
@@ -1755,46 +1755,51 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1755
1755
|
this.setAcceptIN(true);
|
|
1756
1756
|
const rhs = this.parseAssignmentExpression();
|
|
1757
1757
|
this.restoreAcceptIN();
|
|
1758
|
-
value =
|
|
1758
|
+
value = this.factory.createAssignment(Token.ASSIGN.getName(), lhs, rhs, this.createRange(propInfo.rangeStart));
|
|
1759
1759
|
}
|
|
1760
1760
|
else {
|
|
1761
1761
|
value = lhs;
|
|
1762
1762
|
}
|
|
1763
|
-
|
|
1763
|
+
const range = this.createRange(propInfo.rangeStart);
|
|
1764
|
+
return this.factory.createPropertyDeclaration(nameExpression, value, 'init', false, propInfo.kind !== PropertyKind.Assign, propInfo.isComputedName, range);
|
|
1764
1765
|
}
|
|
1765
1766
|
case PropertyKind.Method: {
|
|
1766
1767
|
// MethodDefinition
|
|
1767
1768
|
// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
|
|
1768
1769
|
// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
|
|
1769
1770
|
const kind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);
|
|
1770
|
-
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ?
|
|
1771
|
-
|
|
1771
|
+
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ? this.factory.createIdentifier(propInfo.name) : undefined, propInfo.rangeStart);
|
|
1772
|
+
const range = this.createRange(propInfo.rangeStart);
|
|
1773
|
+
return this.factory.createPropertyDeclaration(nameExpression, value, 'init', true, false, propInfo.isComputedName, range);
|
|
1772
1774
|
}
|
|
1773
1775
|
case PropertyKind.AccessorGetter:
|
|
1774
1776
|
case PropertyKind.AccessorSetter: {
|
|
1775
1777
|
const isGet = propInfo.kind == PropertyKind.AccessorGetter;
|
|
1776
1778
|
const kind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);
|
|
1777
|
-
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ?
|
|
1778
|
-
|
|
1779
|
+
const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, propInfo.name ? this.factory.createIdentifier(propInfo.name, this.createRange(propInfo.rangeStart)) : undefined, propInfo.rangeStart);
|
|
1780
|
+
const range = this.createRange(propInfo.rangeStart);
|
|
1781
|
+
return this.factory.createPropertyDeclaration(nameExpression, value, isGet ? 'get' : 'set', false, false, propInfo.isComputedName, range);
|
|
1779
1782
|
}
|
|
1780
1783
|
case PropertyKind.ClassField:
|
|
1781
1784
|
case PropertyKind.NotSet:
|
|
1782
|
-
return
|
|
1785
|
+
return this.factory.createNull(this.createRange(propInfo.rangeStart));
|
|
1783
1786
|
}
|
|
1784
1787
|
}
|
|
1785
1788
|
parseProperty(propInfo) {
|
|
1786
1789
|
let nextToken = this.peek();
|
|
1790
|
+
propInfo.rangeStart = nextToken;
|
|
1787
1791
|
if (this.check(Token.ASYNC)) {
|
|
1788
1792
|
// async
|
|
1789
1793
|
nextToken = this.peek();
|
|
1790
1794
|
if (nextToken.isNotType(Token.MUL)
|
|
1791
1795
|
&& propInfo.parsePropertyKindFromToken(nextToken.token)
|
|
1792
1796
|
|| this.scanner.hasLineTerminatorBeforeNext()) {
|
|
1793
|
-
return
|
|
1797
|
+
return this.factory.createIdentifier('async', this.createRange(propInfo.rangeStart));
|
|
1794
1798
|
}
|
|
1795
1799
|
propInfo.kind = PropertyKind.Method;
|
|
1796
1800
|
propInfo.funcFlag = ParseFunctionFlag.IsAsync;
|
|
1797
1801
|
}
|
|
1802
|
+
nextToken = this.peek();
|
|
1798
1803
|
if (this.check(Token.MUL)) {
|
|
1799
1804
|
// async*
|
|
1800
1805
|
propInfo.kind = PropertyKind.Method;
|
|
@@ -1804,7 +1809,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1804
1809
|
if (propInfo.kind == PropertyKind.NotSet && nextToken.isType(Token.GET) || nextToken.isType(Token.SET)) {
|
|
1805
1810
|
const token = this.next();
|
|
1806
1811
|
if (propInfo.parsePropertyKindFromToken(this.peek().token)) {
|
|
1807
|
-
return nextToken.isType(Token.GET) ?
|
|
1812
|
+
return this.factory.createIdentifier(nextToken.isType(Token.GET) ? 'get' : 'set', this.createRange(propInfo.rangeStart));
|
|
1808
1813
|
}
|
|
1809
1814
|
if (token.isType(Token.GET)) {
|
|
1810
1815
|
propInfo.kind = PropertyKind.AccessorGetter;
|
|
@@ -1864,7 +1869,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1864
1869
|
}
|
|
1865
1870
|
propInfo.name = propertyName.toString();
|
|
1866
1871
|
this.restoreAcceptIN();
|
|
1867
|
-
return
|
|
1872
|
+
return this.factory.createSpreadElement(propertyName, this.createRange(nextToken));
|
|
1868
1873
|
}
|
|
1869
1874
|
default:
|
|
1870
1875
|
propertyName = this.parsePropertyOrPrivatePropertyName();
|
|
@@ -1893,7 +1898,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1893
1898
|
this.consume(Token.LBRACK);
|
|
1894
1899
|
this.setAcceptIN(true);
|
|
1895
1900
|
const index = this.parseExpressionCoverGrammar();
|
|
1896
|
-
expression =
|
|
1901
|
+
expression = this.factory.createPropertyAssignment(expression, index, true, false, this.createRange(expression));
|
|
1897
1902
|
this.expect(Token.RBRACK);
|
|
1898
1903
|
this.restoreAcceptIN();
|
|
1899
1904
|
break;
|
|
@@ -1901,7 +1906,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1901
1906
|
case Token.PERIOD: {
|
|
1902
1907
|
this.consume(Token.PERIOD);
|
|
1903
1908
|
const key = this.parsePropertyOrPrivatePropertyName();
|
|
1904
|
-
expression =
|
|
1909
|
+
expression = this.factory.createPropertyAssignment(expression, key, false, false, this.createRange(expression));
|
|
1905
1910
|
break;
|
|
1906
1911
|
}
|
|
1907
1912
|
case Token.TEMPLATE_SPAN:
|
|
@@ -1922,7 +1927,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1922
1927
|
}
|
|
1923
1928
|
// check keyword as identifier
|
|
1924
1929
|
if (Token.isPropertyName(next.token) && next.isNotType(Token.EOS)) {
|
|
1925
|
-
return
|
|
1930
|
+
return this.factory.createIdentifier(next.token.getName(), next.range);
|
|
1926
1931
|
}
|
|
1927
1932
|
throw new SyntaxError(this.errorMessage(`Parsing property expression: Unexpected Token`));
|
|
1928
1933
|
}
|
|
@@ -1962,13 +1967,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1962
1967
|
break;
|
|
1963
1968
|
}
|
|
1964
1969
|
if (body) {
|
|
1965
|
-
return
|
|
1970
|
+
return this.factory.createPipelineExpression(lhs, body, undefined, this.createRange(lhs));
|
|
1966
1971
|
}
|
|
1967
1972
|
if (token.isType(Token.LPAREN)) {
|
|
1968
1973
|
// parse arrow function
|
|
1969
1974
|
// x |> ( y => y+1 )
|
|
1970
1975
|
body = this.parsePrimaryExpression();
|
|
1971
|
-
return
|
|
1976
|
+
return this.factory.createPipelineExpression(lhs, body, undefined, this.createRange(lhs));
|
|
1972
1977
|
}
|
|
1973
1978
|
// parse angular-like and f# and partial operator syntax
|
|
1974
1979
|
const func = this.parseMemberExpression(); //this.parseLogicalExpression();
|
|
@@ -1978,6 +1983,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1978
1983
|
// support angular pipeline syntax
|
|
1979
1984
|
do {
|
|
1980
1985
|
this.consume(Token.COLON);
|
|
1986
|
+
const peek = this.peek();
|
|
1981
1987
|
const isSpread = this.check(Token.ELLIPSIS);
|
|
1982
1988
|
if (this.peek().isType(Token.CONDITIONAL)) {
|
|
1983
1989
|
this.consume(Token.CONDITIONAL);
|
|
@@ -1991,7 +1997,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
1991
1997
|
else {
|
|
1992
1998
|
const arg = this.parseAssignmentExpressionCoverGrammar();
|
|
1993
1999
|
if (isSpread) {
|
|
1994
|
-
args.push(
|
|
2000
|
+
args.push(this.factory.createSpreadElement(arg, this.createRange(peek)));
|
|
1995
2001
|
}
|
|
1996
2002
|
else {
|
|
1997
2003
|
args.push(arg);
|
|
@@ -2004,6 +2010,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2004
2010
|
this.consume(Token.LPAREN);
|
|
2005
2011
|
let indexed = false;
|
|
2006
2012
|
while (this.peek().isNotType(Token.RPAREN)) {
|
|
2013
|
+
const peek = this.peek();
|
|
2007
2014
|
const isSpread = this.check(Token.ELLIPSIS);
|
|
2008
2015
|
if (this.peek().isType(Token.CONDITIONAL)) {
|
|
2009
2016
|
this.consume(Token.CONDITIONAL);
|
|
@@ -2018,7 +2025,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2018
2025
|
else {
|
|
2019
2026
|
const arg = this.parseAssignmentExpressionCoverGrammar();
|
|
2020
2027
|
if (isSpread) {
|
|
2021
|
-
args.push(
|
|
2028
|
+
args.push(this.factory.createSpreadElement(arg, this.createRange(peek)));
|
|
2022
2029
|
}
|
|
2023
2030
|
else {
|
|
2024
2031
|
args.push(arg);
|
|
@@ -2030,14 +2037,14 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2030
2037
|
// should be indexed, has partial operator
|
|
2031
2038
|
if (!indexed) {
|
|
2032
2039
|
// z |> method(x, y) === method(x, y)(z)
|
|
2033
|
-
body =
|
|
2034
|
-
return
|
|
2040
|
+
body = this.factory.createCallExpression(func, args, false, this.createRange(func));
|
|
2041
|
+
return this.factory.createPipelineExpression(lhs, body, undefined, this.createRange(lhs));
|
|
2035
2042
|
}
|
|
2036
2043
|
break;
|
|
2037
2044
|
default:
|
|
2038
2045
|
break;
|
|
2039
2046
|
}
|
|
2040
|
-
return
|
|
2047
|
+
return this.factory.createPipelineExpression(lhs, func, args, this.createRange(lhs));
|
|
2041
2048
|
}
|
|
2042
2049
|
parseConditionalExpression() {
|
|
2043
2050
|
// ConditionalExpression ::
|
|
@@ -2072,9 +2079,9 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2072
2079
|
while (Token.precedence(this.peek().token, this.acceptIN) === prec1) {
|
|
2073
2080
|
let y;
|
|
2074
2081
|
let op = this.next();
|
|
2075
|
-
const
|
|
2076
|
-
const
|
|
2077
|
-
y = this.parseBinaryExpression(
|
|
2082
|
+
const isRightAssociative = op.isType(Token.EXP);
|
|
2083
|
+
const nextPrecedence = isRightAssociative ? prec1 : prec1 + 1;
|
|
2084
|
+
y = this.parseBinaryExpression(nextPrecedence);
|
|
2078
2085
|
// For now we distinguish between comparisons and other binary
|
|
2079
2086
|
// operations. (We could combine the two and get rid of this
|
|
2080
2087
|
// code and AST node eventually.)
|
|
@@ -2090,14 +2097,14 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2090
2097
|
break;
|
|
2091
2098
|
default: break;
|
|
2092
2099
|
}
|
|
2093
|
-
x =
|
|
2100
|
+
x = this.factory.createInfixExpression(cmp.getName(), x, y, this.createRange(x));
|
|
2094
2101
|
if (op.isNotType(cmp)) {
|
|
2095
2102
|
// The comparison was negated - add a NOT.
|
|
2096
|
-
x =
|
|
2103
|
+
x = this.factory.createUnaryExpression(Token.NOT.getName(), x, this.createRange(op));
|
|
2097
2104
|
}
|
|
2098
2105
|
}
|
|
2099
2106
|
else {
|
|
2100
|
-
x =
|
|
2107
|
+
x = this.factory.createInfixExpression(op.token.getName(), x, y, this.createRange(x));
|
|
2101
2108
|
}
|
|
2102
2109
|
}
|
|
2103
2110
|
--prec1;
|
|
@@ -2150,11 +2157,11 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2150
2157
|
const expression = this.parseUnaryExpression();
|
|
2151
2158
|
if (Token.isUnary(op.token)) {
|
|
2152
2159
|
if (op.isType(Token.DELETE)) {
|
|
2153
|
-
if (this.isIdentifier(expression) && isStrict(this.languageMode)) {
|
|
2160
|
+
if (this.factory.isIdentifier(expression) && isStrict(this.languageMode)) {
|
|
2154
2161
|
// "delete identifier" is a syntax error in strict mode.
|
|
2155
2162
|
throw new Error(this.errorMessage(`"delete identifier" is a syntax error in strict mode`));
|
|
2156
2163
|
}
|
|
2157
|
-
if (expression
|
|
2164
|
+
if (this.factory.isMemberExpression(expression) && expression.getProperty().toString().startsWith('#')) {
|
|
2158
2165
|
throw new Error(this.errorMessage(`"Delete Private Field" is a syntax error`));
|
|
2159
2166
|
}
|
|
2160
2167
|
}
|
|
@@ -2164,7 +2171,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2164
2171
|
}
|
|
2165
2172
|
if (Token.isCount(op.token) || Token.isUnary(op.token)) {
|
|
2166
2173
|
// Allow the parser to rewrite the expression.
|
|
2167
|
-
return
|
|
2174
|
+
return this.factory.createUnaryExpression(op.token.getName(), expression, op.range);
|
|
2168
2175
|
}
|
|
2169
2176
|
throw new Error(this.errorMessage(`while rewrite unary operation`));
|
|
2170
2177
|
}
|
|
@@ -2182,7 +2189,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2182
2189
|
throw new Error(this.errorMessage(`Invalid LHS In Postfix Op.`));
|
|
2183
2190
|
}
|
|
2184
2191
|
const op = this.next();
|
|
2185
|
-
return
|
|
2192
|
+
return this.factory.createUpdateExpression(op.token.getName(), expression, false, this.createRange(expression));
|
|
2186
2193
|
}
|
|
2187
2194
|
parseLeftHandSideExpression() {
|
|
2188
2195
|
// LeftHandSideExpression ::
|
|
@@ -2194,7 +2201,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2194
2201
|
}
|
|
2195
2202
|
parseLeftHandSideContinuation(result) {
|
|
2196
2203
|
if (this.peek().isType(Token.LPAREN)
|
|
2197
|
-
&& this.isIdentifier(result)
|
|
2204
|
+
&& this.factory.isIdentifier(result)
|
|
2198
2205
|
&& this.scanner.currentToken().isType(Token.ASYNC)
|
|
2199
2206
|
&& !this.scanner.hasLineTerminatorBeforeNext()) {
|
|
2200
2207
|
const args = this.parseArguments(ParsingArrowHeadFlag.AsyncArrowFunction);
|
|
@@ -2205,7 +2212,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2205
2212
|
// async ( Arguments ) => ...
|
|
2206
2213
|
return this.expressionListToExpression(args);
|
|
2207
2214
|
}
|
|
2208
|
-
result =
|
|
2215
|
+
result = this.factory.createCallExpression(result, args, false, this.createRange(result));
|
|
2209
2216
|
if (!Token.isPropertyOrCall(this.peek().token))
|
|
2210
2217
|
return result;
|
|
2211
2218
|
}
|
|
@@ -2224,7 +2231,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2224
2231
|
if (Token.isPropertyOrCall(this.peek().token))
|
|
2225
2232
|
continue;
|
|
2226
2233
|
const key = this.parsePropertyOrPrivatePropertyName();
|
|
2227
|
-
result =
|
|
2234
|
+
result = this.factory.createPropertyAssignment(result, key, false, isOptional, this.createRange(result));
|
|
2228
2235
|
break;
|
|
2229
2236
|
}
|
|
2230
2237
|
/* Property */
|
|
@@ -2233,7 +2240,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2233
2240
|
this.setAcceptIN(true);
|
|
2234
2241
|
const index = this.parseExpressionCoverGrammar();
|
|
2235
2242
|
this.restoreAcceptIN();
|
|
2236
|
-
result =
|
|
2243
|
+
result = this.factory.createPropertyAssignment(result, index, true, isOptional, this.createRange(result));
|
|
2237
2244
|
this.expect(Token.RBRACK);
|
|
2238
2245
|
break;
|
|
2239
2246
|
}
|
|
@@ -2244,13 +2251,13 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2244
2251
|
}
|
|
2245
2252
|
this.consume(Token.PERIOD);
|
|
2246
2253
|
const key = this.parsePropertyOrPrivatePropertyName();
|
|
2247
|
-
result =
|
|
2254
|
+
result = this.factory.createPropertyAssignment(result, key, false, isOptional, this.createRange(result));
|
|
2248
2255
|
break;
|
|
2249
2256
|
}
|
|
2250
2257
|
/* Call */
|
|
2251
2258
|
case Token.LPAREN: {
|
|
2252
2259
|
const args = this.parseArguments();
|
|
2253
|
-
result =
|
|
2260
|
+
result = this.factory.createCallExpression(result, args, isOptional, this.createRange(result));
|
|
2254
2261
|
break;
|
|
2255
2262
|
}
|
|
2256
2263
|
/* bind call */
|
|
@@ -2260,7 +2267,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2260
2267
|
}
|
|
2261
2268
|
this.consume(Token.BIND);
|
|
2262
2269
|
const key = this.parsePropertyOrPrivatePropertyName();
|
|
2263
|
-
result =
|
|
2270
|
+
result = this.factory.createBindExpression(result, key, false, isOptional, this.createRange(result));
|
|
2264
2271
|
break;
|
|
2265
2272
|
}
|
|
2266
2273
|
/* chain bind call */
|
|
@@ -2272,7 +2279,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2272
2279
|
isOptional = true;
|
|
2273
2280
|
optionalChaining = true;
|
|
2274
2281
|
const key = this.parsePropertyOrPrivatePropertyName();
|
|
2275
|
-
result =
|
|
2282
|
+
result = this.factory.createBindExpression(result, key, true, isOptional, this.createRange(result));
|
|
2276
2283
|
break;
|
|
2277
2284
|
}
|
|
2278
2285
|
default:
|
|
@@ -2289,17 +2296,17 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2289
2296
|
}
|
|
2290
2297
|
} while (Token.isPropertyOrCall(this.peek().token));
|
|
2291
2298
|
if (optionalChaining) {
|
|
2292
|
-
result =
|
|
2299
|
+
result = this.factory.createChainExpression(result, this.createRange(result));
|
|
2293
2300
|
}
|
|
2294
2301
|
return result;
|
|
2295
2302
|
}
|
|
2296
2303
|
parseAwaitExpression() {
|
|
2297
|
-
this.consume(Token.AWAIT);
|
|
2304
|
+
const start = this.consume(Token.AWAIT);
|
|
2298
2305
|
const value = this.parseUnaryExpression();
|
|
2299
2306
|
if (this.peek().isType(Token.EXP)) {
|
|
2300
2307
|
throw new Error(this.scanner.createError(`Unexpected Token Unary Exponentiation`));
|
|
2301
2308
|
}
|
|
2302
|
-
return
|
|
2309
|
+
return this.factory.createAwaitExpression(value, this.createRange(start));
|
|
2303
2310
|
}
|
|
2304
2311
|
parseNullishExpression(expression) {
|
|
2305
2312
|
// CoalesceExpression ::
|
|
@@ -2320,7 +2327,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2320
2327
|
}
|
|
2321
2328
|
expression = list.pop();
|
|
2322
2329
|
expression = list.reverse()
|
|
2323
|
-
.reduce((previous, current) =>
|
|
2330
|
+
.reduce((previous, current) => this.factory.createLogicalExpression(Token.NULLISH.getName(), current, previous), expression);
|
|
2324
2331
|
return expression;
|
|
2325
2332
|
}
|
|
2326
2333
|
parseConditionalContinuation(expression) {
|
|
@@ -2330,7 +2337,7 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2330
2337
|
this.restoreAcceptIN();
|
|
2331
2338
|
this.expect(Token.COLON);
|
|
2332
2339
|
const right = this.parseAssignmentExpression();
|
|
2333
|
-
return
|
|
2340
|
+
return this.factory.createConditionalExpression(expression, left, right);
|
|
2334
2341
|
}
|
|
2335
2342
|
parseYieldExpression() {
|
|
2336
2343
|
// YieldExpression ::
|
|
@@ -2365,15 +2372,15 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2365
2372
|
break;
|
|
2366
2373
|
}
|
|
2367
2374
|
}
|
|
2368
|
-
return
|
|
2375
|
+
return this.factory.createYieldExpression(delegating, expression);
|
|
2369
2376
|
}
|
|
2370
|
-
parseNewTargetExpression() {
|
|
2377
|
+
parseNewTargetExpression(start) {
|
|
2371
2378
|
throw new Error(this.errorMessage('Expression (new.target) not supported.'));
|
|
2372
2379
|
}
|
|
2373
2380
|
parseClassExpression() {
|
|
2374
2381
|
throw new Error(this.errorMessage(`Expression (class) not supported.`));
|
|
2375
2382
|
}
|
|
2376
|
-
parseClassDeclaration(names, defaultExport) {
|
|
2383
|
+
parseClassDeclaration(names, defaultExport, start) {
|
|
2377
2384
|
throw new Error(this.errorMessage(`Expression (class) not supported.`));
|
|
2378
2385
|
}
|
|
2379
2386
|
parseClassLiteral(name, isStrictReserved) {
|
|
@@ -2385,5 +2392,8 @@ export class JavaScriptInlineParser extends AbstractParser {
|
|
|
2385
2392
|
parseImportExpressions() {
|
|
2386
2393
|
throw new Error(this.errorMessage('Expression (import) not supported.'));
|
|
2387
2394
|
}
|
|
2395
|
+
parseWithStatement() {
|
|
2396
|
+
throw new Error(this.errorMessage('Expression (with) not supported.'));
|
|
2397
|
+
}
|
|
2388
2398
|
}
|
|
2389
2399
|
//# sourceMappingURL=inline.js.map
|