@ibyar/expressions 0.5.2 → 0.5.62

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.
Files changed (186) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -3
  3. package/api/abstract.d.ts +5 -6
  4. package/api/abstract.js +8 -3
  5. package/api/abstract.js.map +1 -1
  6. package/api/class/class.d.ts +227 -0
  7. package/api/class/class.js +662 -0
  8. package/api/class/class.js.map +1 -0
  9. package/api/class/decorator.d.ts +20 -0
  10. package/api/class/decorator.js +48 -0
  11. package/api/class/decorator.js.map +1 -0
  12. package/api/computing/call.d.ts +3 -1
  13. package/api/computing/call.js +16 -4
  14. package/api/computing/call.js.map +1 -1
  15. package/api/computing/debugger.d.ts +15 -0
  16. package/api/computing/debugger.js +35 -0
  17. package/api/computing/debugger.js.map +1 -0
  18. package/api/computing/new.d.ts +2 -1
  19. package/api/computing/new.js +4 -0
  20. package/api/computing/new.js.map +1 -1
  21. package/api/computing/rest.d.ts +6 -6
  22. package/api/computing/rest.js +5 -2
  23. package/api/computing/rest.js.map +1 -1
  24. package/api/computing/return.d.ts +6 -1
  25. package/api/computing/return.js +8 -0
  26. package/api/computing/return.js.map +1 -1
  27. package/api/computing/spread.d.ts +2 -1
  28. package/api/computing/spread.js +5 -2
  29. package/api/computing/spread.js.map +1 -1
  30. package/api/computing/throw.d.ts +6 -1
  31. package/api/computing/throw.js +7 -0
  32. package/api/computing/throw.js.map +1 -1
  33. package/api/computing/yield.d.ts +2 -1
  34. package/api/computing/yield.js +3 -0
  35. package/api/computing/yield.js.map +1 -1
  36. package/api/definition/array.d.ts +12 -12
  37. package/api/definition/array.js +31 -25
  38. package/api/definition/array.js.map +1 -1
  39. package/api/definition/bind.d.ts +8 -2
  40. package/api/definition/bind.js +7 -1
  41. package/api/definition/bind.js.map +1 -1
  42. package/api/definition/function.d.ts +40 -51
  43. package/api/definition/function.js +292 -309
  44. package/api/definition/function.js.map +1 -1
  45. package/api/definition/member.d.ts +2 -2
  46. package/api/definition/member.js +1 -1
  47. package/api/definition/member.js.map +1 -1
  48. package/api/definition/object.d.ts +15 -12
  49. package/api/definition/object.js +43 -13
  50. package/api/definition/object.js.map +1 -1
  51. package/api/definition/statement.d.ts +2 -2
  52. package/api/definition/statement.js +7 -3
  53. package/api/definition/statement.js.map +1 -1
  54. package/api/definition/values.d.ts +44 -50
  55. package/api/definition/values.js +87 -149
  56. package/api/definition/values.js.map +1 -1
  57. package/api/deserialize/deserialize.d.ts +7 -1
  58. package/api/deserialize/deserialize.js +9 -1
  59. package/api/deserialize/deserialize.js.map +1 -1
  60. package/api/deserialize/type-store.d.ts +2 -2
  61. package/api/deserialize/type-store.js.map +1 -1
  62. package/api/expression.d.ts +159 -18
  63. package/api/expression.js.map +1 -1
  64. package/api/index.d.ts +2 -0
  65. package/api/index.js +2 -0
  66. package/api/index.js.map +1 -1
  67. package/api/module/common.d.ts +29 -0
  68. package/api/module/common.js +71 -0
  69. package/api/module/common.js.map +1 -0
  70. package/api/module/export.d.ts +129 -25
  71. package/api/module/export.js +333 -58
  72. package/api/module/export.js.map +1 -1
  73. package/api/module/import.d.ts +114 -25
  74. package/api/module/import.js +279 -68
  75. package/api/module/import.js.map +1 -1
  76. package/api/operators/assignment.d.ts +2 -2
  77. package/api/operators/assignment.js +1 -1
  78. package/api/operators/assignment.js.map +1 -1
  79. package/api/operators/await.d.ts +2 -2
  80. package/api/operators/await.js +1 -1
  81. package/api/operators/await.js.map +1 -1
  82. package/api/operators/binary.d.ts +2 -2
  83. package/api/operators/binary.js +1 -1
  84. package/api/operators/binary.js.map +1 -1
  85. package/api/operators/chaining.d.ts +2 -2
  86. package/api/operators/chaining.js +1 -1
  87. package/api/operators/chaining.js.map +1 -1
  88. package/api/operators/comma.d.ts +2 -2
  89. package/api/operators/comma.js +2 -2
  90. package/api/operators/comma.js.map +1 -1
  91. package/api/operators/grouping.d.ts +9 -2
  92. package/api/operators/grouping.js +8 -1
  93. package/api/operators/grouping.js.map +1 -1
  94. package/api/operators/logical.d.ts +2 -2
  95. package/api/operators/logical.js +1 -1
  96. package/api/operators/logical.js.map +1 -1
  97. package/api/operators/pipeline.d.ts +14 -2
  98. package/api/operators/pipeline.js +13 -1
  99. package/api/operators/pipeline.js.map +1 -1
  100. package/api/operators/ternary.d.ts +2 -2
  101. package/api/operators/ternary.js +1 -1
  102. package/api/operators/ternary.js.map +1 -1
  103. package/api/operators/unary.d.ts +3 -3
  104. package/api/operators/unary.js +7 -3
  105. package/api/operators/unary.js.map +1 -1
  106. package/api/operators/update.d.ts +2 -2
  107. package/api/operators/update.js +1 -1
  108. package/api/operators/update.js.map +1 -1
  109. package/api/{app/program.d.ts → program.d.ts} +8 -9
  110. package/api/program.js +45 -0
  111. package/api/program.js.map +1 -0
  112. package/api/statement/control/block.d.ts +8 -5
  113. package/api/statement/control/block.js +26 -23
  114. package/api/statement/control/block.js.map +1 -1
  115. package/api/statement/control/empty.d.ts +8 -1
  116. package/api/statement/control/empty.js +7 -0
  117. package/api/statement/control/empty.js.map +1 -1
  118. package/api/statement/control/if.d.ts +7 -2
  119. package/api/statement/control/if.js +6 -1
  120. package/api/statement/control/if.js.map +1 -1
  121. package/api/statement/control/switch.d.ts +10 -5
  122. package/api/statement/control/switch.js +22 -9
  123. package/api/statement/control/switch.js.map +1 -1
  124. package/api/statement/control/terminate.d.ts +46 -13
  125. package/api/statement/control/terminate.js +89 -20
  126. package/api/statement/control/terminate.js.map +1 -1
  127. package/api/statement/declarations/declares.d.ts +17 -16
  128. package/api/statement/declarations/declares.js +24 -19
  129. package/api/statement/declarations/declares.js.map +1 -1
  130. package/api/statement/iterations/for.d.ts +10 -5
  131. package/api/statement/iterations/for.js +42 -23
  132. package/api/statement/iterations/for.js.map +1 -1
  133. package/api/statement/iterations/while.d.ts +9 -3
  134. package/api/statement/iterations/while.js +27 -13
  135. package/api/statement/iterations/while.js.map +1 -1
  136. package/api/utils.d.ts +5 -0
  137. package/api/utils.js +4 -0
  138. package/api/utils.js.map +1 -0
  139. package/package.json +5 -5
  140. package/scope/finalizer.d.ts +4 -0
  141. package/scope/finalizer.js +11 -0
  142. package/scope/finalizer.js.map +1 -0
  143. package/scope/proxy.d.ts +5 -3
  144. package/scope/proxy.js +26 -26
  145. package/scope/proxy.js.map +1 -1
  146. package/scope/scope.d.ts +108 -51
  147. package/scope/scope.js +72 -134
  148. package/scope/scope.js.map +1 -1
  149. package/scope/stack.d.ts +117 -26
  150. package/scope/stack.js +154 -102
  151. package/scope/stack.js.map +1 -1
  152. package/v8/enums.d.ts +204 -0
  153. package/v8/enums.js +406 -0
  154. package/v8/enums.js.map +1 -0
  155. package/v8/index.d.ts +2 -1
  156. package/v8/index.js +2 -1
  157. package/v8/index.js.map +1 -1
  158. package/v8/inline.d.ts +213 -0
  159. package/v8/inline.js +2375 -0
  160. package/v8/inline.js.map +1 -0
  161. package/v8/nodes.d.ts +8 -7
  162. package/v8/nodes.js +39 -64
  163. package/v8/nodes.js.map +1 -1
  164. package/v8/parser.d.ts +49 -151
  165. package/v8/parser.js +839 -1607
  166. package/v8/parser.js.map +1 -1
  167. package/v8/stream.d.ts +39 -3
  168. package/v8/stream.js +685 -171
  169. package/v8/stream.js.map +1 -1
  170. package/v8/token.d.ts +244 -9
  171. package/v8/token.js +315 -47
  172. package/v8/token.js.map +1 -1
  173. package/visit/visitor.d.ts +3 -0
  174. package/visit/visitor.js +4 -7
  175. package/visit/visitor.js.map +1 -1
  176. package/api/app/class.d.ts +0 -117
  177. package/api/app/class.js +0 -292
  178. package/api/app/class.js.map +0 -1
  179. package/api/app/program.js +0 -39
  180. package/api/app/program.js.map +0 -1
  181. package/api/module/module.d.ts +0 -26
  182. package/api/module/module.js +0 -63
  183. package/api/module/module.js.map +0 -1
  184. package/v8/app.d.ts +0 -0
  185. package/v8/app.js +0 -2
  186. package/v8/app.js.map +0 -1
package/v8/parser.js CHANGED
@@ -1,1716 +1,948 @@
1
+ import { JavaScriptInlineParser } from './inline.js';
1
2
  import { Token } from './token.js';
2
- import { TokenStream } from './stream.js';
3
- import { OfNode, Identifier, ThisNode, GetIdentifier, SetIdentifier, AsyncIdentifier, NullNode, StringLiteral, AwaitIdentifier, ConstructorIdentifier, NameIdentifier, EvalIdentifier, ArgumentsIdentifier, TaggedTemplateExpression, TemplateLiteral } 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, ArrowFunctionType, FunctionKind, 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';
3
+ import { Class, ClassBody, ClassDeclaration, ClassExpression, MetaProperty, MethodDefinition, PropertyDefinition, StaticBlock, Super } from '../api/class/class.js';
4
+ import { Identifier, Literal, NullNode } from '../api/definition/values.js';
11
5
  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 } from '../api/statement/control/terminate.js';
22
- import { ReturnStatement } from '../api/computing/return.js';
23
- import { YieldExpression } from '../api/computing/yield.js';
24
- import { VariableNode, 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 { BinaryExpression } from '../api/operators/binary.js';
34
- export var ParsingArrowHeadFlag;
35
- (function (ParsingArrowHeadFlag) {
36
- ParsingArrowHeadFlag[ParsingArrowHeadFlag["CertainlyNotArrowHead"] = 0] = "CertainlyNotArrowHead";
37
- ParsingArrowHeadFlag[ParsingArrowHeadFlag["MaybeArrowHead"] = 1] = "MaybeArrowHead";
38
- ParsingArrowHeadFlag[ParsingArrowHeadFlag["AsyncArrowFunction"] = 2] = "AsyncArrowFunction";
39
- })(ParsingArrowHeadFlag || (ParsingArrowHeadFlag = {}));
40
- export var PropertyKind;
41
- (function (PropertyKind) {
42
- PropertyKind[PropertyKind["Value"] = 0] = "Value";
43
- PropertyKind[PropertyKind["Shorthand"] = 1] = "Shorthand";
44
- PropertyKind[PropertyKind["ShorthandOrClassField"] = 2] = "ShorthandOrClassField";
45
- PropertyKind[PropertyKind["Assign"] = 3] = "Assign";
46
- PropertyKind[PropertyKind["Method"] = 4] = "Method";
47
- PropertyKind[PropertyKind["ClassField"] = 5] = "ClassField";
48
- PropertyKind[PropertyKind["AccessorGetter"] = 6] = "AccessorGetter";
49
- PropertyKind[PropertyKind["AccessorSetter"] = 7] = "AccessorSetter";
50
- PropertyKind[PropertyKind["Spread"] = 8] = "Spread";
51
- PropertyKind[PropertyKind["NotSet"] = 9] = "NotSet";
52
- })(PropertyKind || (PropertyKind = {}));
53
- export function parsePropertyKindFromToken(token, info) {
54
- switch (token) {
55
- case Token.COLON:
56
- info.kind = PropertyKind.Value;
57
- return true;
58
- case Token.COMMA:
59
- info.kind = PropertyKind.Shorthand;
60
- return true;
61
- case Token.R_CURLY:
62
- info.kind = PropertyKind.ShorthandOrClassField;
63
- return true;
64
- case Token.ASSIGN:
65
- info.kind = PropertyKind.Assign;
66
- return true;
67
- case Token.L_PARENTHESES:
68
- info.kind = PropertyKind.Method;
69
- return true;
70
- case Token.MUL:
71
- case Token.SEMICOLON:
72
- info.kind = PropertyKind.ClassField;
73
- return true;
74
- default:
75
- break;
76
- }
77
- return false;
78
- }
79
- export var PreParserIdentifierType;
80
- (function (PreParserIdentifierType) {
81
- PreParserIdentifierType["NullIdentifier"] = "NullIdentifier";
82
- PreParserIdentifierType["UnknownIdentifier"] = "UnknownIdentifier";
83
- PreParserIdentifierType["EvalIdentifier"] = "EvalIdentifier";
84
- PreParserIdentifierType["ArgumentsIdentifier"] = "ArgumentsIdentifier";
85
- PreParserIdentifierType["ConstructorIdentifier"] = "ConstructorIdentifier";
86
- PreParserIdentifierType["AwaitIdentifier"] = "AwaitIdentifier";
87
- PreParserIdentifierType["AsyncIdentifier"] = "AsyncIdentifier";
88
- PreParserIdentifierType["NameIdentifier"] = "NameIdentifier";
89
- PreParserIdentifierType["PrivateNameIdentifier"] = "PrivateNameIdentifier";
90
- })(PreParserIdentifierType || (PreParserIdentifierType = {}));
91
- export class AbstractParser {
92
- constructor(scanner) {
93
- this.scanner = scanner;
94
- }
95
- position() {
96
- return this.scanner.getPos();
97
- }
98
- current() {
99
- return this.scanner.currentToken();
100
- }
101
- next() {
102
- return this.scanner.next();
103
- }
104
- peek() {
105
- return this.scanner.peek();
106
- }
107
- peekAhead() {
108
- return this.scanner.peekAhead();
109
- }
110
- peekAheadPosition() {
111
- return this.scanner.peekAheadPosition();
112
- }
113
- peekPosition() {
114
- return this.scanner.peekPosition();
115
- }
116
- consume(token) {
117
- if (this.scanner.next().isNotType(token)) {
118
- throw new Error(this.errorMessage(`Parsing ${JSON.stringify(token)}`));
119
- }
120
- }
121
- check(token) {
122
- const next = this.scanner.peek();
123
- if (next.isType(token)) {
124
- this.scanner.next();
125
- return true;
126
- }
127
- return false;
128
- }
129
- checkValue(value) {
130
- const next = this.scanner.peek();
131
- if (next.value == value) {
132
- this.scanner.next();
133
- return true;
134
- }
135
- return false;
136
- }
137
- expect(token) {
138
- const current = this.scanner.next();
139
- if (current.isNotType(token)) {
140
- throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(token)}, current is ${JSON.stringify(current)}`));
141
- }
142
- }
143
- checkInOrOf() {
144
- if (this.check(Token.IN)) {
145
- return 'IN';
146
- }
147
- else if (this.checkValue(OfNode)) {
148
- return 'OF';
149
- }
150
- return false;
151
- }
152
- peekInOrOf() {
153
- var next = this.peek();
154
- if (next.isType(Token.IN)) {
155
- return 'IN';
156
- }
157
- else if (next.value === OfNode) {
158
- return 'OF';
159
- }
160
- return false;
161
- }
162
- isEvalOrArguments(name) {
163
- if (name.toString() === 'eval') {
164
- return true;
165
- }
166
- else if (name.toString() === 'arguments') {
167
- return true;
168
- }
169
- return false;
170
- }
171
- isNextLetKeyword() {
172
- if (this.peek().isNotType(Token.LET)) {
173
- return false;
174
- }
175
- const nextNextToken = this.peekAhead().token;
176
- switch (nextNextToken) {
177
- case Token.L_CURLY:
178
- case Token.L_BRACKETS:
179
- case Token.IDENTIFIER:
180
- case Token.STATIC:
181
- case Token.LET:
182
- case Token.YIELD:
183
- case Token.AWAIT:
184
- case Token.GET:
185
- case Token.SET:
186
- case Token.ASYNC:
187
- return true;
188
- default:
189
- return false;
190
- }
191
- }
192
- isIdentifier(expression) {
193
- return expression instanceof Identifier;
6
+ import { VariableDeclarationNode, VariableDeclarator } from '../api/statement/declarations/declares.js';
7
+ import { TokenStream } from './stream.js';
8
+ import { Program } from '../api/program.js';
9
+ import { ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier } from '../api/module/export.js';
10
+ import { ImportDeclaration, ImportDefaultSpecifier, ImportExpression, ImportNamespaceSpecifier, ImportSpecifier } from '../api/module/import.js';
11
+ import { ImportAttribute } from '../api/module/common.js';
12
+ import { ClassLiteralProperty, ClassLiteralPropertyKind, classPropertyKindFor, createClassInfo, FunctionKind, FunctionSyntaxKind, isAccessor, isStrict, LanguageMode, ParseFunctionFlag, PropertyKind, PropertyKindInfo, PropertyPosition, VariableDeclarationContext } from './enums.js';
13
+ export class JavaScriptParser extends JavaScriptInlineParser {
14
+ /**
15
+ * parser js with
16
+ * @param source
17
+ * @returns
18
+ */
19
+ static parse(source, { mode } = {}) {
20
+ mode ?? (mode = LanguageMode.Strict);
21
+ const stream = (typeof source === 'string') || Array.isArray(source)
22
+ ? TokenStream.getTokenStream(source, mode) : source;
23
+ const parser = new JavaScriptParser(stream);
24
+ return parser.scan();
194
25
  }
195
- isParenthesized(expression) {
196
- return expression instanceof GroupingExpression || expression instanceof SequenceExpression;
26
+ /**
27
+ * parse inline code like that used in html 2 or 1 way binding
28
+ */
29
+ static parseScript(source, options) {
30
+ return JavaScriptInlineParser.parse(source, options);
197
31
  }
198
- isAssignableIdentifier(expression) {
199
- if (!(expression instanceof Identifier)) {
200
- return false;
201
- }
202
- if (this.isEvalOrArguments(expression)) {
203
- return false;
32
+ scan() {
33
+ const isModule = isStrict(this.languageMode);
34
+ if (isModule) {
35
+ this.setFunctionKind(FunctionKind.Module);
204
36
  }
205
- return true;
206
- }
207
- isPattern(expression) {
208
- return expression instanceof ObjectPattern || expression instanceof ArrayPattern;
209
- }
210
- isProperty(expression) {
211
- return expression instanceof MemberExpression;
212
- }
213
- isCallNew(expression) {
214
- return expression instanceof NewExpression;
37
+ const body = isModule ? this.parseModuleItemList() : this.parseStatementList(Token.EOS);
38
+ return new Program(isModule ? 'module' : 'script', body);
215
39
  }
216
- isCall(expression) {
217
- return expression instanceof CallExpression;
218
- }
219
- isEmptyStatement(expression) {
220
- return expression instanceof EmptyStatement;
221
- }
222
- isThisProperty(expression) {
223
- if (this.isProperty(expression)) {
224
- if (expression.getObject() === ThisNode || expression.getObject().toString() === 'this') {
225
- return true;
226
- }
40
+ parseNewTargetExpression() {
41
+ this.consume(Token.PERIOD);
42
+ const target = this.parsePropertyOrPrivatePropertyName();
43
+ if (target.toString() !== 'target') {
44
+ throw new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));
227
45
  }
228
- return false;
229
- }
230
- isValidReferenceExpression(expression) {
231
- return this.isAssignableIdentifier(expression) || this.isProperty(expression);
46
+ return MetaProperty.NewTarget;
232
47
  }
233
- expectSemicolon() {
234
- const tok = this.peek();
235
- if (tok.isType(Token.SEMICOLON)) {
236
- this.next();
237
- return;
238
- }
239
- if (this.scanner.hasLineTerminatorBeforeNext() || Token.isAutoSemicolon(tok.token)) {
240
- return;
241
- }
242
- if (this.scanner.currentToken().isType(Token.AWAIT)) {
243
- throw new Error(this.errorMessage(`Await Not In Async Context/Function`));
48
+ parseClassExpression() {
49
+ this.consume(Token.CLASS);
50
+ let name;
51
+ let isStrictReserved = false;
52
+ if (this.peekAnyIdentifier()) {
53
+ name = this.parseAndClassifyIdentifier(this.next());
54
+ isStrictReserved = Token.isStrictReservedWord(this.current().token);
244
55
  }
56
+ const classLiteral = this.parseClassLiteral(name, isStrictReserved);
57
+ return new ClassExpression(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass());
245
58
  }
246
- peekAnyIdentifier() {
247
- return Token.isAnyIdentifier(this.peek().token);
248
- }
249
- errorMessage(message) {
250
- return this.scanner.createError(message);
251
- }
252
- }
253
- export class JavaScriptParser extends AbstractParser {
254
- static parse(source) {
255
- const stream = (typeof source === 'string' || Array.isArray(source))
256
- ? TokenStream.getTokenStream(source)
257
- : source;
258
- const parser = new JavaScriptParser(stream);
259
- return parser.scan();
260
- }
261
- scan() {
262
- const list = this.parseStatementList(Token.EOS);
263
- if (list.length === 1) {
264
- return list[0];
59
+ parseClassDeclaration(names, defaultExport) {
60
+ // ClassDeclaration ::
61
+ // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
62
+ // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
63
+ //
64
+ // The anonymous form is allowed iff [default_export] is true.
65
+ //
66
+ // 'class' is expected to be consumed by the caller.
67
+ //
68
+ // A ClassDeclaration
69
+ //
70
+ // class C { ... }
71
+ //
72
+ // has the same semantics as:
73
+ //
74
+ // let C = class C { ... };
75
+ //
76
+ // so rewrite it as such.
77
+ const nextToken = this.peek().token;
78
+ const isStrictReserved = Token.isStrictReservedWord(nextToken);
79
+ let name;
80
+ let variableName;
81
+ if (defaultExport && (nextToken == Token.EXTENDS || nextToken == Token.LBRACE)) {
82
+ name = new Literal('default');
83
+ variableName = '.default';
265
84
  }
266
- return new ExpressionStatement(list);
267
- }
268
- parseStatement() {
269
- switch (this.peek().token) {
270
- case Token.L_CURLY:
271
- return this.parseBlock();
272
- case Token.SEMICOLON:
273
- this.consume(Token.SEMICOLON);
274
- return EmptyStatement.INSTANCE;
275
- case Token.IF:
276
- return this.parseIfStatement();
277
- case Token.DO:
278
- return this.parseDoWhileStatement();
279
- case Token.WHILE:
280
- return this.parseWhileStatement();
281
- case Token.FOR:
282
- return this.parseForStatement();
283
- case Token.CONTINUE:
284
- return this.parseContinueStatement();
285
- case Token.BREAK:
286
- return this.parseBreakStatement();
287
- case Token.RETURN:
288
- return this.parseReturnStatement();
289
- case Token.THROW:
290
- return this.parseThrowStatement();
291
- case Token.TRY:
292
- return this.parseTryStatement();
293
- case Token.SWITCH:
294
- return this.parseSwitchStatement();
295
- case Token.VAR:
296
- case Token.LET:
297
- case Token.CONST:
298
- return this.parseVariableDeclarations();
299
- case Token.ASYNC:
300
- if (this.peekAhead().isType(Token.FUNCTION)) {
301
- this.consume(Token.ASYNC);
302
- this.consume(Token.FUNCTION);
303
- if (this.peek().isType(Token.MUL)) {
304
- return this.parseFunctionExpression(FunctionKind.ASYNC_GENERATOR);
305
- }
306
- return this.parseFunctionExpression(FunctionKind.ASYNC);
307
- }
308
- default:
309
- return this.parseExpressionOrLabelledStatement();
85
+ else {
86
+ const identifier = this.parseIdentifier();
87
+ variableName = identifier.getName();
88
+ name = identifier;
310
89
  }
90
+ const classLiteral = this.parseClassLiteral(name, isStrictReserved);
91
+ return new ClassDeclaration(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass());
311
92
  }
312
- parseTryStatement() {
313
- this.consume(Token.TRY);
314
- const tryBlock = this.parseBlock();
315
- if (tryBlock instanceof BlockStatement) {
316
- tryBlock.isStatement = true;
317
- }
318
- let peek = this.peek();
319
- if (peek.isNotType(Token.CATCH) && peek.isNotType(Token.FINALLY)) {
320
- throw new Error(this.errorMessage(`Uncaught SyntaxError: Missing catch or finally after try`));
321
- }
322
- let catchBlock;
323
- if (this.check(Token.CATCH)) {
324
- let catchVar;
325
- const hasBinding = this.check(Token.L_PARENTHESES);
326
- if (hasBinding) {
327
- catchVar = this.parseIdentifier();
328
- this.expect(Token.R_PARENTHESES);
93
+ parseClassLiteral(name, nameIsStrictReserved) {
94
+ const isAnonymous = !!!name;
95
+ // All parts of a ClassDeclaration and ClassExpression are strict code.
96
+ if (!isAnonymous) {
97
+ if (nameIsStrictReserved) {
98
+ throw new Error(this.errorMessage(`Unexpected Strict Reserved class name`));
329
99
  }
330
- const block = this.parseBlock();
331
- if (block instanceof BlockStatement) {
332
- block.isStatement = true;
100
+ if (this.isEvalOrArguments(name)) {
101
+ throw new Error(this.errorMessage(`Strict Eval Arguments not allowed for class name`));
333
102
  }
334
- catchBlock = new CatchClauseNode(block, catchVar);
335
103
  }
336
- let finallyBlock;
337
- if (this.check(Token.FINALLY)) {
338
- finallyBlock = this.parseBlock();
339
- if (finallyBlock instanceof BlockStatement) {
340
- finallyBlock.isStatement = true;
341
- }
104
+ const classInfo = createClassInfo();
105
+ classInfo.isAnonymous = isAnonymous;
106
+ if (this.check(Token.EXTENDS)) {
107
+ classInfo.extends = this.parseLeftHandSideExpression();
342
108
  }
343
- return new TryCatchNode(tryBlock, catchBlock, finallyBlock);
344
- }
345
- parseBlock() {
346
- this.expect(Token.L_CURLY);
347
- const statements = [];
348
- const block = new BlockStatement(statements, false);
349
- while (this.peek().isNotType(Token.R_CURLY)) {
350
- const stat = this.parseStatementListItem();
351
- if (!stat) {
352
- return block;
109
+ this.expect(Token.LBRACE);
110
+ const hasExtends = !!classInfo.extends;
111
+ while (this.peek().isNotType(Token.RBRACE)) {
112
+ if (this.check(Token.SEMICOLON))
113
+ continue;
114
+ // Either we're parsing a `static { }` initialization block or a property.
115
+ if (this.peek().isType(Token.STATIC) && this.peekAhead().isType(Token.LBRACE)) {
116
+ const staticBlock = this.parseClassStaticBlock(classInfo);
117
+ classInfo.staticElements.push(staticBlock);
118
+ classInfo.hasStaticBlocks = true;
119
+ continue;
353
120
  }
354
- else if (stat instanceof EmptyStatement) {
121
+ // FuncNameInferrerState fni_state(& fni_);
122
+ // If we haven't seen the constructor yet, it potentially is the next
123
+ // property.
124
+ let isConstructor = !classInfo.hasSeenConstructor;
125
+ const propInfo = new PropertyKindInfo();
126
+ propInfo.position = PropertyPosition.ClassLiteral;
127
+ const property = this.parseClassPropertyDefinition(classInfo, propInfo, hasExtends);
128
+ // if (has_error()) return impl() . FailureExpression();
129
+ const propertyKind = classPropertyKindFor(propInfo.kind);
130
+ if (!classInfo.hasStaticComputedNames && propInfo.isStatic && propInfo.isComputedName) {
131
+ classInfo.hasStaticComputedNames = true;
132
+ }
133
+ isConstructor && (isConstructor = classInfo.hasSeenConstructor);
134
+ const isField = propertyKind == ClassLiteralPropertyKind.FIELD;
135
+ if (propInfo.isPrivate) {
136
+ if (isConstructor) {
137
+ throw new Error(this.errorMessage('private constructor is not allowed'));
138
+ }
139
+ classInfo.requiresBrand || (classInfo.requiresBrand = !isField && !propInfo.isStatic);
140
+ const isMethod = propertyKind == ClassLiteralPropertyKind.METHOD;
141
+ classInfo.hasPrivateMethods || (classInfo.hasPrivateMethods = isMethod);
142
+ classInfo.hasStaticPrivateMethods || (classInfo.hasStaticPrivateMethods = isMethod && propInfo.isStatic);
143
+ this.declarePrivateClassMember(propInfo.name, property, propertyKind, propInfo.isStatic, classInfo);
355
144
  continue;
356
145
  }
357
- statements.push(stat);
358
- }
359
- this.expect(Token.R_CURLY);
360
- return block;
361
- }
362
- parseStatementListItem() {
363
- switch (this.peek().token) {
364
- case Token.FUNCTION:
365
- this.consume(Token.FUNCTION);
366
- if (this.peek().isType(Token.MUL)) {
367
- this.consume(Token.MUL);
368
- return this.parseFunctionExpression(FunctionKind.GENERATOR);
369
- }
370
- return this.parseFunctionExpression(FunctionKind.NORMAL);
371
- case Token.CLASS:
372
- this.consume(Token.CLASS);
373
- return this.parseClassDeclaration(undefined, false);
374
- case Token.VAR:
375
- case Token.LET:
376
- case Token.CONST:
377
- return this.parseVariableDeclarations();
378
- case Token.ASYNC:
379
- if (this.peekAhead().isType(Token.FUNCTION)) {
380
- this.consume(Token.ASYNC);
381
- this.consume(Token.FUNCTION);
382
- if (this.peek().isType(Token.MUL)) {
383
- this.consume(Token.MUL);
384
- return this.parseFunctionExpression(FunctionKind.ASYNC_GENERATOR);
385
- }
386
- return this.parseFunctionExpression(FunctionKind.ASYNC);
146
+ if (isField) {
147
+ if (propInfo.isComputedName) {
148
+ classInfo.computedFieldCount++;
387
149
  }
388
- break;
389
- default:
390
- break;
391
- }
392
- return this.parseStatement();
393
- }
394
- parseFunctionExpression(type) {
395
- let funcName;
396
- const peek = this.peek();
397
- if (peek.isNotType(Token.L_PARENTHESES)) {
398
- if (peek.isType(Token.L_BRACKETS)) {
399
- this.consume(Token.L_BRACKETS);
400
- funcName = this.parseMemberExpression();
401
- this.expect(Token.R_BRACKETS);
402
- }
403
- else {
404
- funcName = this.parseIdentifier();
150
+ this.declarePublicClassField(property, propInfo.isStatic, propInfo.isComputedName, classInfo);
151
+ continue;
405
152
  }
153
+ this.declarePublicClassMethod(name, property, isConstructor, classInfo);
406
154
  }
407
- return this.parseFunctionLiteral(type, funcName);
155
+ this.expect(Token.RBRACE);
156
+ const classBody = this.rewriteClassLiteral(classInfo, name);
157
+ return new Class(classBody, [], name, classInfo.extends);
408
158
  }
409
- parseIfStatement() {
410
- this.consume(Token.IF);
411
- this.consume(Token.L_PARENTHESES);
412
- const condition = this.parseExpression();
413
- this.consume(Token.R_PARENTHESES);
414
- const thenStatement = this.parseStatement();
415
- if (thenStatement instanceof BlockStatement) {
416
- thenStatement.isStatement = true;
417
- }
418
- let elseStatement;
419
- if (this.peek().isType(Token.ELSE)) {
420
- this.consume(Token.ELSE);
421
- elseStatement = this.parseStatement();
422
- }
423
- return new IfStatement(condition, thenStatement, elseStatement);
424
- }
425
- parseDoWhileStatement() {
426
- this.consume(Token.DO);
427
- const body = this.parseStatement();
428
- if (body instanceof BlockStatement) {
429
- body.isStatement = true;
430
- }
431
- this.expect(Token.WHILE);
432
- this.expect(Token.L_PARENTHESES);
433
- const condition = this.parseExpression();
434
- this.expect(Token.R_PARENTHESES);
435
- this.check(Token.SEMICOLON);
436
- return new DoWhileNode(condition, body);
437
- }
438
- parseWhileStatement() {
439
- this.consume(Token.WHILE);
440
- this.expect(Token.L_PARENTHESES);
441
- const condition = this.parseExpression();
442
- this.expect(Token.R_PARENTHESES);
443
- const body = this.parseStatement();
444
- if (body instanceof BlockStatement) {
445
- body.isStatement = true;
446
- }
447
- return new WhileNode(condition, body);
448
- }
449
- parseThrowStatement() {
450
- this.consume(Token.THROW);
451
- if (this.scanner.hasLineTerminatorBeforeNext()) {
452
- throw new Error(this.scanner.createError(`New line After Throw`));
453
- }
454
- const exception = this.parseExpression();
455
- this.expectSemicolon();
456
- return new ThrowStatement(exception);
457
- }
458
- parseSwitchStatement() {
459
- this.consume(Token.SWITCH);
460
- this.expect(Token.L_PARENTHESES);
461
- const tag = this.parseExpression();
462
- this.expect(Token.R_PARENTHESES);
463
- const cases = [];
464
- const switchStatement = new SwitchStatement(tag, cases);
465
- let defaultSeen = false;
466
- this.expect(Token.L_CURLY);
467
- while (this.peek().isNotType(Token.R_CURLY)) {
468
- const statements = [];
469
- let label;
470
- if (this.check(Token.CASE)) {
471
- label = this.parseExpression();
472
- }
473
- else {
474
- this.expect(Token.DEFAULT);
475
- if (defaultSeen) {
476
- throw new Error(this.errorMessage(`Multiple Defaults In Switch`));
477
- }
478
- defaultSeen = true;
479
- }
480
- this.expect(Token.COLON);
481
- while (this.peek().isNotType(Token.CASE)
482
- && this.peek().isNotType(Token.DEFAULT)
483
- && this.peek().isNotType(Token.R_CURLY)) {
484
- const statement = this.parseStatementListItem();
485
- if (!statement || this.isEmptyStatement(statement)) {
486
- continue;
487
- }
488
- statements.push(statement);
159
+ declarePublicClassMethod(name, property, isConstructor, classInfo) {
160
+ // throw new Error('Method not implemented.');
161
+ if (isConstructor) {
162
+ if (classInfo.constructor) {
163
+ throw new SyntaxError(this.errorMessage('A class may only have one constructor.'));
489
164
  }
490
- const block = new BlockStatement(statements, true);
491
- const clause = defaultSeen ? new DefaultExpression(block) : new SwitchCase(label, block);
492
- cases.push(clause);
165
+ classInfo.constructor = property;
166
+ // set the class name as the constructor name
167
+ Reflect.set(classInfo.constructor, 'id', name);
168
+ return;
493
169
  }
494
- this.expect(Token.R_CURLY);
495
- return switchStatement;
170
+ classInfo.publicMembers.push(property);
496
171
  }
497
- parseForStatement() {
498
- this.consume(Token.FOR);
499
- const isAwait = this.check(Token.AWAIT);
500
- this.expect(Token.L_PARENTHESES);
501
- const peek = this.peek();
502
- const startsWithLet = peek.isType(Token.LET) || peek.isType(Token.VAR);
503
- let initializer;
504
- if (peek.isType(Token.CONST) || (startsWithLet && this.isNextLetKeyword())) {
505
- initializer = this.parseVariableDeclarations();
506
- }
507
- else if (peek.isType(Token.SEMICOLON)) {
508
- initializer = EmptyStatement.INSTANCE;
172
+ declarePublicClassField(property, isStatic, isComputedName, classInfo) {
173
+ if (isStatic) {
174
+ classInfo.staticElements.push(property);
509
175
  }
510
176
  else {
511
- initializer = this.parseExpressionCoverGrammar();
512
- }
513
- if (initializer instanceof BinaryExpression) {
514
- const objectNode = initializer.getRight();
515
- initializer = initializer.getLeft();
516
- this.expect(Token.R_PARENTHESES);
517
- const statement = this.parseStatement();
518
- return new ForInNode(initializer, objectNode, statement);
519
- }
520
- const forMode = this.checkInOrOf();
521
- if (forMode) {
522
- const object = forMode === 'IN' ? this.parseAssignmentExpression() : this.parseExpression();
523
- this.expect(Token.R_PARENTHESES);
524
- const statement = this.parseStatement();
525
- if (statement instanceof BlockStatement) {
526
- statement.isStatement = true;
527
- }
528
- if (isAwait && forMode === 'OF') {
529
- return new ForAwaitOfNode(initializer, object, statement);
530
- }
531
- else if (forMode === 'OF') {
532
- return new ForOfNode(initializer, object, statement);
533
- }
534
- else if (forMode === 'IN') {
535
- return new ForInNode(initializer, object, statement);
177
+ classInfo.instanceFields.push(property);
178
+ }
179
+ // if (isComputedName) {
180
+ // classInfo.publicMembers.push(property);
181
+ // }
182
+ }
183
+ declarePrivateClassMember(propertyName, property, kind, isStatic, classInfo) {
184
+ classInfo.privateMembers.push(property);
185
+ }
186
+ // protected createPrivateNameVariable(mode: VariableMode, staticFlag: StaticFlag, propertyName: string) {
187
+ // throw new Error('Method not implemented.');
188
+ // }
189
+ parseClassPropertyDefinition(classInfo, propInfo, hasExtends) {
190
+ if (!classInfo) {
191
+ throw new Error(this.errorMessage('class info is undefined'));
192
+ }
193
+ if (propInfo.position !== PropertyPosition.ClassLiteral) {
194
+ throw new Error(this.errorMessage('expected property position ClassLiteral'));
195
+ }
196
+ const nameToken = this.peek();
197
+ let nameExpression;
198
+ if (nameToken.isType(Token.STATIC)) {
199
+ this.consume(Token.STATIC);
200
+ if (this.peek().isType(Token.LPAREN)) {
201
+ propInfo.kind = PropertyKind.Method;
202
+ nameExpression = this.parseIdentifier();
203
+ propInfo.name = nameExpression.getName();
204
+ }
205
+ else if (this.peek().isType(Token.ASSIGN)
206
+ || this.peek().isType(Token.SEMICOLON)
207
+ || this.peek().isType(Token.RBRACK)) {
208
+ nameExpression = this.parseIdentifier();
209
+ propInfo.name = nameExpression.getName();
536
210
  }
537
211
  else {
538
- throw new Error(this.errorMessage(`parsing for loop: ${this.position()}`));
212
+ propInfo.isStatic = true;
213
+ nameExpression = this.parseProperty(propInfo);
539
214
  }
540
215
  }
541
- this.expect(Token.SEMICOLON);
542
- let condition;
543
- if (!this.check(Token.SEMICOLON)) {
544
- condition = this.parseExpression();
545
- this.expect(Token.SEMICOLON);
546
- }
547
- let finalExpression;
548
- if (!this.check(Token.R_PARENTHESES)) {
549
- finalExpression = this.parseExpression();
550
- this.expect(Token.R_PARENTHESES);
551
- }
552
- const body = this.parseStatement();
553
- if (body instanceof BlockStatement) {
554
- body.isStatement = true;
555
- }
556
- return new ForNode(body, initializer, condition, finalExpression);
557
- }
558
- parseVariableDeclarations() {
559
- let mode;
560
- const token = this.peek().token;
561
- switch (token) {
562
- case Token.CONST:
563
- this.consume(token);
564
- mode = 'const';
565
- break;
566
- case Token.VAR:
567
- this.consume(token);
568
- mode = 'var';
569
- case Token.LET:
570
- default:
571
- this.consume(token);
572
- mode = 'let';
573
- break;
216
+ else {
217
+ nameExpression = this.parseProperty(propInfo);
574
218
  }
575
- const variables = [];
576
- do {
577
- let name;
578
- let value;
579
- if (Token.isAnyIdentifier(this.peek().token)) {
580
- name = this.parseAndClassifyIdentifier(this.next());
581
- if (this.isEvalOrArguments(name)) {
582
- throw new Error(this.errorMessage(`Strict Eval Arguments`));
583
- }
584
- }
585
- else {
586
- name = this.parseBindingPattern(true);
219
+ switch (propInfo.kind) {
220
+ case PropertyKind.Assign:
221
+ case PropertyKind.ClassField:
222
+ case PropertyKind.ShorthandOrClassField:
223
+ case PropertyKind.NotSet: {
224
+ // This case is a name followed by a
225
+ // name or other property. Here we have
226
+ // to assume that's an uninitialized
227
+ // field followed by a line break
228
+ // followed by a property, with ASI
229
+ // adding the semicolon. If not, there
230
+ // will be a syntax error after parsing
231
+ // the first name as an uninitialized
232
+ // field.
233
+ propInfo.kind = PropertyKind.ClassField;
234
+ // if (!propInfo.isComputedName) {
235
+ // this.checkClassFieldName(propInfo.name, propInfo.isStatic);
236
+ // }
237
+ const initializer = this.parseMemberInitializer(classInfo, propInfo.isStatic);
238
+ this.expectSemicolon();
239
+ const result = this.newClassLiteralProperty(nameExpression, initializer, ClassLiteralPropertyKind.FIELD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
240
+ this.setFunctionNameFromPropertyName(result, propInfo.name);
241
+ return result;
587
242
  }
588
- if (this.check(Token.ASSIGN)) {
589
- value = this.parseAssignmentExpression();
243
+ case PropertyKind.Method: {
244
+ // MethodDefinition
245
+ // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
246
+ // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
247
+ // async PropertyName '(' StrictFormalParameters ')'
248
+ // '{' FunctionBody '}'
249
+ // async '*' PropertyName '(' StrictFormalParameters ')'
250
+ // '{' FunctionBody '}'
251
+ if (!propInfo.isComputedName) {
252
+ this.checkClassMethodName(propInfo, classInfo);
253
+ }
254
+ let kind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);
255
+ if (!propInfo.isStatic && propInfo.name.toString() === 'constructor') {
256
+ classInfo.hasSeenConstructor = true;
257
+ kind = hasExtends ? FunctionKind.DerivedConstructor : FunctionKind.BaseConstructor;
258
+ }
259
+ const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression);
260
+ const result = this.newClassLiteralProperty(nameExpression, value, ClassLiteralProperty.Kind.METHOD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
261
+ this.setFunctionNameFromPropertyName(result, propInfo.name);
262
+ return result;
590
263
  }
591
- else if (!this.peekInOrOf()) {
592
- if (mode === 'const' && (name === undefined || value === undefined)) {
593
- throw new Error(this.errorMessage(`Declaration Missing Initializer : ${this.position()}`));
264
+ case PropertyKind.AccessorGetter:
265
+ case PropertyKind.AccessorSetter: {
266
+ if (propInfo.funcFlag !== ParseFunctionFlag.IsNormal) {
267
+ throw new Error(this.errorMessage('accessor is not normal function'));
594
268
  }
269
+ const isGet = propInfo.kind == PropertyKind.AccessorGetter;
270
+ if (!propInfo.isComputedName) {
271
+ this.checkClassMethodName(propInfo, classInfo);
272
+ // Make sure the name expression is a string since we need a Name for
273
+ // Runtime_DefineAccessorPropertyUnchecked and since we can determine
274
+ // this statically we can skip the extra runtime check.
275
+ nameExpression = new Literal(propInfo.name);
276
+ }
277
+ let kind;
278
+ if (propInfo.isStatic) {
279
+ kind = isGet ? FunctionKind.StaticGetterFunction
280
+ : FunctionKind.StaticSetterFunction;
281
+ }
282
+ else {
283
+ kind = isGet ? FunctionKind.GetterFunction
284
+ : FunctionKind.SetterFunction;
285
+ }
286
+ const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression);
287
+ const propertyKind = isGet ? ClassLiteralProperty.Kind.GETTER : ClassLiteralProperty.Kind.SETTER;
288
+ const result = this.newClassLiteralProperty(nameExpression, value, propertyKind, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
289
+ const prefix = isGet ? 'get ' : 'set ';
290
+ this.setFunctionNameFromPropertyName(result, propInfo.name, prefix);
291
+ return result;
595
292
  }
596
- variables.push(new VariableNode(name, value));
597
- } while (this.check(Token.COMMA));
598
- return new VariableDeclarationNode(variables, mode);
599
- }
600
- parseBindingPattern(isPattern) {
601
- const token = this.peek().token;
602
- if (Token.isAnyIdentifier(token)) {
603
- const name = this.parseAndClassifyIdentifier(this.next());
604
- if (this.isEvalOrArguments(name)) {
605
- throw new Error(this.errorMessage(`Strict Eval Arguments`));
606
- }
607
- return name;
608
- }
609
- if (token == Token.L_BRACKETS) {
610
- return this.parseArrayLiteral(isPattern);
611
- }
612
- else if (token == Token.L_CURLY) {
613
- return this.parseObjectLiteral(isPattern);
614
- }
615
- else {
616
- throw new Error(this.errorMessage(`Unexpected Token: ${this.next().getValue()}`));
293
+ case PropertyKind.Value:
294
+ case PropertyKind.Shorthand:
295
+ case PropertyKind.Spread:
296
+ // throw new Error(this.errorMessage('Report Unexpected Token'));
297
+ return NullNode;
617
298
  }
299
+ throw new Error(this.errorMessage('UNREACHABLE'));
618
300
  }
619
- parseAndClassifyIdentifier(next) {
620
- if (next.isType(Token.IDENTIFIER)) {
621
- return next.getValue();
301
+ checkClassMethodName(propInfo, classInfo) {
302
+ if (!(propInfo.kind == PropertyKind.Method || isAccessor(propInfo.kind))) {
303
+ throw new Error(this.errorMessage('not kind of method or setter or getter'));
622
304
  }
623
- else if (next.isType(Token.SET)) {
624
- const value = this.parseFunctionDeclaration();
625
- return new Property(next.getValue(), value, 'set');
305
+ if (propInfo.isPrivate && propInfo.name.toString() === 'constructor') {
306
+ throw new Error(this.errorMessage('constructor is private'));
626
307
  }
627
- else if (next.isType(Token.GET)) {
628
- const value = this.parseFunctionDeclaration();
629
- return new Property(next.getValue(), value, 'get');
308
+ else if (propInfo.isStatic && propInfo.name.toString() === 'prototype') {
309
+ throw new Error(this.errorMessage('static prototype'));
630
310
  }
631
- else if (next.isType(Token.AWAIT)) {
632
- throw new Error(this.errorMessage(`un supported expression (await)`));
633
- }
634
- return next.getValue();
635
- }
636
- parseContinueStatement() {
637
- this.consume(Token.CONTINUE);
638
- this.expectSemicolon();
639
- return ContinueStatement.CONTINUE_INSTANCE;
640
- }
641
- parseBreakStatement() {
642
- this.consume(Token.BREAK);
643
- this.expectSemicolon();
644
- return BreakStatement.BREAK_INSTANCE;
645
- }
646
- parseReturnStatement() {
647
- this.consume(Token.RETURN);
648
- const tokenExp = this.peek();
649
- let returnValue;
650
- if (this.scanner.hasLineTerminatorBeforeNext() || Token.isAutoSemicolon(tokenExp.token)) {
651
- }
652
- else {
653
- returnValue = this.parseExpression();
654
- }
655
- this.expectSemicolon();
656
- return new ReturnStatement(returnValue);
657
- }
658
- parseExpressionOrLabelledStatement() {
659
- switch (this.peek().token) {
660
- case Token.FUNCTION:
661
- case Token.L_CURLY:
662
- throw new Error(this.errorMessage(`Unreachable state`));
663
- case Token.CLASS:
664
- throw new Error(this.errorMessage(`Unexpected Token ${this.next().getValue().toString()}`));
665
- case Token.LET: {
666
- const nextNext = this.peekAhead();
667
- if (nextNext.isNotType(Token.L_BRACKETS) &&
668
- ((nextNext.isNotType(Token.L_CURLY) && nextNext.isNotType(Token.IDENTIFIER)))) {
669
- break;
311
+ else if (propInfo.name.toString() === 'constructor') {
312
+ if (propInfo.funcFlag !== ParseFunctionFlag.IsNormal || isAccessor(propInfo.kind)) {
313
+ if (propInfo.funcFlag === ParseFunctionFlag.IsGenerator) {
314
+ throw new Error(this.errorMessage('constructor is generator'));
315
+ }
316
+ else if (propInfo.funcFlag === ParseFunctionFlag.IsAsync) {
317
+ throw new Error(this.errorMessage('constructor is async'));
318
+ }
319
+ if (classInfo.hasSeenConstructor) {
320
+ throw new Error(this.errorMessage('duplicate constructor'));
670
321
  }
671
- throw new Error(this.errorMessage(`Unexpected Lexical Declaration ${this.position()}`));
672
- }
673
- default:
674
- break;
675
- }
676
- const startsWithIdentifier = Token.isAnyIdentifier(this.peek().token);
677
- const expression = this.parseExpressionCoverGrammar();
678
- if (this.peek().isType(Token.COLON) && startsWithIdentifier && this.isIdentifier(expression)) {
679
- this.consume(Token.COLON);
680
- if (this.peek().isType(Token.FUNCTION)) {
681
- return this.parseFunctionDeclaration();
682
322
  }
683
- return this.parseStatement();
323
+ classInfo.hasSeenConstructor = true;
684
324
  }
685
- this.expectSemicolon();
686
- return expression;
687
325
  }
688
- parseExpression() {
689
- return this.parseExpressionCoverGrammar();
326
+ parseClassStaticBlock(classInfo) {
327
+ this.consume(Token.STATIC);
328
+ // Each static block has its own var and lexical scope, so make a new var
329
+ // block scope instead of using the synthetic members initializer function
330
+ // scope.
331
+ this.setStatue(true, FunctionKind.ClassStaticInitializerFunction);
332
+ const block = this.parseBlock();
333
+ this.restoreStatue();
334
+ classInfo.hasStaticElements = true;
335
+ return new StaticBlock(block.getBody());
690
336
  }
691
- parseFunctionDeclaration() {
692
- this.consume(Token.FUNCTION);
693
- if (this.check(Token.MUL)) {
694
- throw new Error(this.errorMessage(`Error Generator In Single Statement Context`));
695
- }
696
- return this.parseHoistableDeclaration(FunctionKind.NORMAL);
337
+ declareClass(variableName, value, names) {
338
+ names?.push(variableName);
339
+ const proxy = this.declareVariable(variableName, 'let');
340
+ return new AssignmentExpression('=', proxy, value);
697
341
  }
698
- parseFunctionDeclarationAndGenerator() {
699
- this.consume(Token.FUNCTION);
700
- if (this.check(Token.MUL)) {
701
- return this.parseHoistableDeclaration(FunctionKind.GENERATOR);
702
- }
703
- return this.parseHoistableDeclaration(FunctionKind.NORMAL);
342
+ declareVariable(name, mode) {
343
+ return new VariableDeclarationNode([new VariableDeclarator(new Identifier(name))], mode);
704
344
  }
705
- parseHoistableDeclaration(flag) {
706
- if (FunctionKind.ASYNC === flag && this.check(Token.MUL)) {
707
- flag = FunctionKind.ASYNC_GENERATOR;
708
- }
709
- let name;
710
- if (this.peek().isNotType(Token.L_PARENTHESES)) {
711
- name = this.parseIdentifier();
712
- }
713
- return this.parseFunctionLiteral(flag, name);
714
- }
715
- parseIdentifier() {
716
- const next = this.next();
717
- if (!Token.isValidIdentifier(next.token)) {
718
- throw new Error(this.errorMessage(`Unexpected Token: ${next.getValue()}`));
719
- }
720
- if (next.isType(Token.IDENTIFIER)) {
721
- return next.getValue();
722
- }
723
- return this.getIdentifier();
724
- }
725
- getIdentifier() {
726
- const current = this.current();
727
- const string = current.getValue().toString();
728
- switch (current.token) {
729
- case Token.AWAIT:
730
- return AwaitIdentifier;
731
- case Token.ASYNC:
732
- return AsyncIdentifier;
733
- case Token.PRIVATE_NAME:
734
- return new Identifier(`#${string}`);
345
+ newClassLiteralProperty(nameExpression, initializer, kind, isStatic, isComputedName, isPrivate) {
346
+ switch (kind) {
347
+ case ClassLiteralPropertyKind.METHOD:
348
+ if (nameExpression.toString() === 'constructor') {
349
+ return new MethodDefinition('constructor', nameExpression, initializer, [], isComputedName, isStatic);
350
+ }
351
+ return new MethodDefinition('method', nameExpression, initializer, [], isComputedName, isStatic);
352
+ case ClassLiteralPropertyKind.GETTER:
353
+ return new MethodDefinition('get', nameExpression, initializer, [], isComputedName, isStatic);
354
+ case ClassLiteralPropertyKind.SETTER:
355
+ return new MethodDefinition('set', nameExpression, initializer, [], isComputedName, isStatic);
356
+ case ClassLiteralPropertyKind.FIELD:
357
+ return new PropertyDefinition(nameExpression, [], isComputedName, isStatic, initializer);
735
358
  default:
736
359
  break;
737
360
  }
738
- if (string == 'constructor') {
739
- return ConstructorIdentifier;
740
- }
741
- if (string == 'name') {
742
- return NameIdentifier;
743
- }
744
- if (string == 'eval') {
745
- return EvalIdentifier;
746
- }
747
- else if (string == 'arguments') {
748
- return ArgumentsIdentifier;
749
- }
750
- throw new Error(this.errorMessage(`can't identify token ${string}`));
361
+ throw new Error(this.errorMessage('UNREACHABLE'));
751
362
  }
752
- parseFunctionLiteral(flag, name) {
753
- const functionInfo = {};
754
- this.expect(Token.L_PARENTHESES);
755
- const formals = this.parseFormalParameterList(functionInfo);
756
- this.expect(Token.R_PARENTHESES);
757
- const body = this.parseFunctionBody();
758
- if (name) {
759
- return new FunctionDeclaration(formals, body, flag, name, functionInfo.rest);
363
+ parseMemberInitializer(classInfo, isStatic) {
364
+ const kind = isStatic
365
+ ? FunctionKind.ClassStaticInitializerFunction
366
+ : FunctionKind.ClassMembersInitializerFunction;
367
+ let initializer = undefined;
368
+ if (this.check(Token.ASSIGN)) {
369
+ this.setStatue(true, kind);
370
+ initializer = this.parseAssignmentExpression();
371
+ this.restoreStatue();
760
372
  }
761
- return new FunctionExpression(formals, body, flag, name, functionInfo.rest);
762
- }
763
- parseArrowFunctionBody() {
764
- const isExpression = this.peek().isNotType(Token.L_CURLY);
765
- if (isExpression) {
766
- const expression = this.parseAssignmentExpression();
767
- return expression;
373
+ if (isStatic) {
374
+ classInfo.hasStaticElements = true;
768
375
  }
769
376
  else {
770
- return this.parseFunctionBody();
377
+ classInfo.hasInstanceMembers = true;
771
378
  }
379
+ return initializer;
772
380
  }
773
- parseFunctionBody() {
774
- this.expect(Token.L_CURLY);
775
- const list = this.parseStatementList(Token.R_CURLY);
776
- this.expect(Token.R_CURLY);
777
- return list;
381
+ setFunctionNameFromPropertyName(property, name, prefix) {
382
+ // TODO: no need for this now
383
+ // check later when needed
384
+ // the ClassExpression* handle this
778
385
  }
779
- parseStatementList(endToken) {
780
- const list = [];
781
- while (this.peek().isNotType(endToken)) {
782
- const stat = this.parseStatementListItem();
386
+ parseSuperExpression() {
387
+ this.consume(Token.SUPER);
388
+ if (Token.isProperty(this.peek().token)) {
389
+ if (this.peek().isType(Token.PERIOD) && this.peekAhead().isType(Token.PRIVATE_NAME)) {
390
+ this.consume(Token.PERIOD);
391
+ this.consume(Token.PRIVATE_NAME);
392
+ throw new Error(this.errorMessage('Unexpected Private Field'));
393
+ }
394
+ if (this.peek().isType(Token.QUESTION_PERIOD)) {
395
+ this.consume(Token.QUESTION_PERIOD);
396
+ throw new Error(this.errorMessage('Optional Chaining No Super'));
397
+ }
398
+ return Super.INSTANCE;
399
+ }
400
+ throw new Error(this.errorMessage('Unexpected Super'));
401
+ }
402
+ rewriteClassLiteral(classInfo, name) {
403
+ const body = [];
404
+ if (classInfo.hasSeenConstructor) {
405
+ body.push(classInfo.constructor);
406
+ }
407
+ body.push(...classInfo.staticElements);
408
+ body.push(...classInfo.instanceFields);
409
+ body.push(...classInfo.publicMembers);
410
+ body.push(...classInfo.privateMembers);
411
+ return new ClassBody(body);
412
+ }
413
+ parseModuleItemList() {
414
+ // ecma262/#prod-Module
415
+ // Module :
416
+ // ModuleBody?
417
+ //
418
+ // ecma262/#prod-ModuleItemList
419
+ // ModuleBody :
420
+ // ModuleItem*
421
+ const body = [];
422
+ while (this.peek().isNotType(Token.EOS)) {
423
+ const stat = this.parseModuleItem();
783
424
  if (!stat) {
784
425
  break;
785
426
  }
786
427
  if (this.isEmptyStatement(stat)) {
787
428
  continue;
788
429
  }
789
- list.push(stat);
790
- }
791
- return list;
792
- }
793
- parseFormalParameterList(functionInfo) {
794
- const parameters = [];
795
- if (this.peek().isNotType(Token.R_PARENTHESES)) {
796
- while (true) {
797
- const param = this.parseFormalParameter(functionInfo);
798
- parameters.push(param);
799
- if (functionInfo.rest) {
800
- if (this.peek().isType(Token.COMMA)) {
801
- throw new Error(this.errorMessage(`Param After Rest`));
802
- }
803
- break;
804
- }
805
- if (!this.check(Token.COMMA))
806
- break;
807
- if (this.peek().isType(Token.R_PARENTHESES)) {
808
- break;
809
- }
810
- }
811
- }
812
- return parameters;
813
- }
814
- parseFormalParameter(functionInfo) {
815
- functionInfo.rest = this.check(Token.ELLIPSIS);
816
- let pattern = this.parseBindingPattern(true);
817
- let initializer;
818
- if (this.check(Token.ASSIGN)) {
819
- if (functionInfo.rest) {
820
- throw new Error(this.errorMessage(`Rest Default Initializer`));
821
- }
822
- const value = this.parseAssignmentExpression();
823
- initializer = new Param(pattern, value);
824
- }
825
- else {
826
- initializer = new Param(pattern);
827
- }
828
- return initializer;
829
- }
830
- parseExpressionCoverGrammar(info) {
831
- let variableIndex = 0;
832
- const list = [];
833
- let expression;
834
- while (true) {
835
- if (this.peek().isType(Token.ELLIPSIS)) {
836
- if (info) {
837
- info.rest = true;
838
- }
839
- return this.parseArrowParametersWithRest(list, variableIndex);
840
- }
841
- expression = this.parseAssignmentExpressionCoverGrammar();
842
- list.push(expression);
843
- if (!this.check(Token.COMMA))
844
- break;
845
- if (this.peek().isType(Token.R_PARENTHESES) && this.peekAhead().isType(Token.ARROW)) {
846
- break;
847
- }
848
- }
849
- if (list.length == 1)
850
- return expression;
851
- return this.expressionListToExpression(list);
852
- }
853
- parseArrowParametersWithRest(list, variableIndex) {
854
- this.consume(Token.ELLIPSIS);
855
- const pattern = this.parseBindingPattern(true);
856
- if (this.peek().isType(Token.ASSIGN)) {
857
- throw new Error(this.errorMessage(`Error A rest parameter cannot have an initializer`));
858
- }
859
- if (this.peek().isType(Token.COMMA)) {
860
- throw new Error(this.errorMessage(`Error A rest parameter or binding pattern may not have a trailing comma`));
861
- }
862
- if (this.peek().isNotType(Token.R_PARENTHESES) || this.peekAhead().isNotType(Token.ARROW)) {
863
- throw new Error(this.errorMessage(`Error Unexpected Token At ${this.position()}`));
864
- }
865
- list.push(pattern);
866
- return this.expressionListToExpression(list);
867
- }
868
- expressionListToExpression(list) {
869
- if (list.length === 1) {
870
- return list[0];
871
- }
872
- return new SequenceExpression(list);
873
- }
874
- parseMemberExpression() {
875
- const result = this.parsePrimaryExpression();
876
- return this.parseMemberExpressionContinuation(result);
877
- }
878
- toParamNode(expression) {
879
- if (expression instanceof AssignmentExpression) {
880
- return new Param(expression.getLeft(), expression.getRight());
881
- }
882
- if (expression instanceof GroupingExpression) {
883
- return new Param(expression.getNode());
884
- }
885
- return new Param(expression);
886
- }
887
- parsePrimaryExpression() {
888
- let token = this.peek();
889
- if (Token.isAnyIdentifier(token.token)) {
890
- this.consume(token.token);
891
- let kind = ArrowFunctionType.NORMAL;
892
- if (token.isType(Token.ASYNC) && !this.scanner.hasLineTerminatorBeforeNext()) {
893
- if (this.peek().isType(Token.FUNCTION)) {
894
- return this.parseFunctionDeclarationAndGenerator();
895
- }
896
- ;
897
- if (Token.isAnyIdentifier(this.peek().token) && this.peekAhead().isType(Token.ARROW)) {
898
- token = this.next();
899
- kind = ArrowFunctionType.ASYNC;
900
- }
901
- }
902
- if (this.peek().isType(Token.ARROW)) {
903
- const name = this.parseAndClassifyIdentifier(token);
904
- const params = [];
905
- if (name instanceof SequenceExpression) {
906
- params.push(...name.getExpressions().map(this.toParamNode));
907
- }
908
- else {
909
- params.push(this.toParamNode(name));
910
- }
911
- return this.parseArrowFunctionLiteral(params, kind);
912
- }
913
- return this.parseAndClassifyIdentifier(token);
914
- }
915
- if (Token.isLiteral(token.token)) {
916
- return expressionFromLiteral(this.next());
917
- }
918
- switch (token.token) {
919
- case Token.NEW:
920
- return this.parseMemberWithPresentNewPrefixesExpression();
921
- case Token.THIS:
922
- this.consume(Token.THIS);
923
- return ThisNode;
924
- case Token.DIV:
925
- case Token.DIV_ASSIGN:
926
- return this.parseRegExpLiteral();
927
- case Token.FUNCTION:
928
- this.consume(Token.FUNCTION);
929
- if (this.peek().isType(Token.MUL)) {
930
- this.consume(Token.MUL);
931
- return this.parseFunctionExpression(FunctionKind.GENERATOR);
932
- }
933
- return this.parseFunctionExpression(FunctionKind.NORMAL);
934
- case Token.SUPER: {
935
- return this.parseSuperExpression();
936
- }
937
- case Token.IMPORT:
938
- return this.parseImportExpressions();
939
- case Token.L_BRACKETS:
940
- return this.parseArrayLiteral(false);
941
- case Token.L_CURLY:
942
- return this.parseObjectLiteral(false);
943
- case Token.L_PARENTHESES: {
944
- this.consume(Token.L_PARENTHESES);
945
- if (this.check(Token.R_PARENTHESES)) {
946
- if (!this.peek().isType(Token.ARROW)) {
947
- throw new Error(this.errorMessage(`Unexpected Token: ${Token.R_PARENTHESES.getName()}`));
948
- }
949
- return this.parseArrowFunctionLiteral([], ArrowFunctionType.NORMAL);
950
- }
951
- const peekToken = this.peek();
952
- let expression;
953
- const info = {};
954
- if (peekToken.isType(Token.FUNCTION)) {
955
- this.consume(Token.FUNCTION);
956
- expression = this.parseFunctionLiteral(FunctionKind.NORMAL);
957
- }
958
- else if (peekToken.isType(Token.ASYNC) && this.peekAhead().isType(Token.FUNCTION)) {
959
- this.consume(Token.ASYNC);
960
- this.consume(Token.FUNCTION);
961
- expression = this.parseFunctionLiteral(FunctionKind.ASYNC);
430
+ body.push(stat);
431
+ }
432
+ return body;
433
+ }
434
+ parseModuleItem() {
435
+ // ecma262/#prod-ModuleItem
436
+ // ModuleItem :
437
+ // ImportDeclaration
438
+ // ExportDeclaration
439
+ // StatementListItem
440
+ const next = this.peek();
441
+ if (next.isType(Token.EXPORT)) {
442
+ return this.parseExportDeclaration();
443
+ }
444
+ if (next.isType(Token.IMPORT)) {
445
+ // We must be careful not to parse a dynamic import expression as an import
446
+ // declaration. Same for import.meta expressions.
447
+ const peekAhead = this.peekAhead();
448
+ if (peekAhead.isNotType(Token.LPAREN) && peekAhead.isNotType(Token.PERIOD)) {
449
+ return this.parseImportDeclaration();
450
+ // return factory() -> EmptyStatement();
451
+ }
452
+ }
453
+ return this.parseStatementListItem();
454
+ }
455
+ parseExportDeclaration() {
456
+ // ExportDeclaration:
457
+ // 'export' '*' 'from' ModuleSpecifier ';'
458
+ // 'export' '*' 'from' ModuleSpecifier [no LineTerminator here]
459
+ // AssertClause ';'
460
+ // 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier ';'
461
+ // 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier
462
+ // [no LineTerminator here] AssertClause ';'
463
+ // 'export' '*' 'as' ModuleExportName 'from' ModuleSpecifier ';'
464
+ // 'export' '*' 'as' ModuleExportName 'from' ModuleSpecifier ';'
465
+ // [no LineTerminator here] AssertClause ';'
466
+ // 'export' ExportClause ('from' ModuleSpecifier)? ';'
467
+ // 'export' ExportClause ('from' ModuleSpecifier [no LineTerminator here]
468
+ // AssertClause)? ';'
469
+ // 'export' VariableStatement
470
+ // 'export' Declaration
471
+ // 'export' 'default' ... (handled in ParseExportDefault)
472
+ //
473
+ // ModuleExportName :
474
+ // StringLiteral
475
+ this.expect(Token.EXPORT);
476
+ let result;
477
+ const names = [];
478
+ // Statement * result = nullptr;
479
+ // ZonePtrList <const AstRawString> names(1, zone());
480
+ // Scanner::Location loc = scanner() -> peek_location();
481
+ switch (this.peek().token) {
482
+ case Token.DEFAULT:
483
+ return this.parseExportDefault();
484
+ case Token.MUL:
485
+ return this.parseExportStar();
486
+ case Token.LBRACE: {
487
+ // There are two cases here:
488
+ //
489
+ // 'export' ExportClause ';'
490
+ // and
491
+ // 'export' ExportClause FromClause ';'
492
+ //
493
+ // In the first case, the exported identifiers in ExportClause must
494
+ // not be reserved words, while in the latter they may be. We
495
+ // pass in a location that gets filled with the first reserved word
496
+ // encountered, and then throw a SyntaxError if we are in the
497
+ // non-FromClause case.
498
+ // Scanner::Location reserved_loc = Scanner:: Location:: invalid();
499
+ // Scanner::Location string_literal_local_name_loc =
500
+ // Scanner:: Location:: invalid();
501
+ // ZoneChunkList < ExportClauseData >* export_data =
502
+ // ParseExportClause(& reserved_loc, & string_literal_local_name_loc);
503
+ const exportData = this.parseExportClause();
504
+ let moduleSpecifier;
505
+ let importAssertions;
506
+ if (this.checkContextualKeyword('from')) {
507
+ // Scanner::Location specifier_loc = scanner() -> peek_location();
508
+ moduleSpecifier = this.parseModuleSpecifier();
509
+ importAssertions = this.parseImportAssertClause();
510
+ this.expectSemicolon();
511
+ // if (exportData.isEmpty()) {
512
+ // // module() -> AddEmptyImport(module_specifier, import_assertions, specifier_loc, zone());
513
+ // } else {
514
+ // // for (const ExportClauseData& data : * export_data) {
515
+ // // module() -> AddExport(data.local_name, data.export_name,
516
+ // // module_specifier, import_assertions,
517
+ // // data.location, specifier_loc, zone());
518
+ // // }
519
+ // }
962
520
  }
963
521
  else {
964
- expression = this.parseExpressionCoverGrammar(info);
965
- }
966
- this.expect(Token.R_PARENTHESES);
967
- if (this.peek().isType(Token.ARROW)) {
968
- if (expression instanceof SequenceExpression) {
969
- expression = this.parseArrowFunctionLiteral(expression.getExpressions(), ArrowFunctionType.NORMAL, info.rest);
970
- }
971
- else {
972
- expression = this.parseArrowFunctionLiteral([expression], ArrowFunctionType.NORMAL, info.rest);
973
- }
974
- }
975
- return expression;
522
+ // if (reserved_loc.IsValid()) {
523
+ // // No FromClause, so reserved words are invalid in ExportClause.
524
+ // ReportMessageAt(reserved_loc, MessageTemplate:: kUnexpectedReserved);
525
+ // return nullptr;
526
+ // } else if (string_literal_local_name_loc.IsValid()) {
527
+ // ReportMessageAt(string_literal_local_name_loc,
528
+ // MessageTemplate:: kModuleExportNameWithoutFromClause);
529
+ // return nullptr;
530
+ // }
531
+ this.expectSemicolon();
532
+ // for (const ExportClauseData& data : * export_data) {
533
+ // module() -> AddExport(data.local_name, data.export_name, data.location,
534
+ // zone());
535
+ // }
536
+ }
537
+ return new ExportNamedDeclaration(exportData, undefined, moduleSpecifier, importAssertions);
538
+ // return factory() -> EmptyStatement();
539
+ }
540
+ case Token.FUNCTION: {
541
+ const declaration = this.parseFunctionDeclaration();
542
+ const identifier = declaration.getId();
543
+ result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
544
+ break;
976
545
  }
977
546
  case Token.CLASS: {
978
547
  this.consume(Token.CLASS);
979
- let name;
980
- let isStrictReserved = false;
981
- if (this.peekAnyIdentifier()) {
982
- name = this.parseAndClassifyIdentifier(this.next());
983
- isStrictReserved = Token.isStrictReservedWord(this.current().token);
984
- }
985
- return this.parseClassLiteral(name, isStrictReserved);
986
- }
987
- case Token.TEMPLATE_LITERALS:
988
- return this.parseTemplateLiteral();
989
- default:
548
+ const declaration = this.parseClassDeclaration(names, false);
549
+ const identifier = declaration.getId();
550
+ result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
990
551
  break;
991
- }
992
- throw new Error(this.errorMessage(`Unexpected Token: ${JSON.stringify(this.next())}`));
993
- }
994
- parseTemplateLiteral(tag) {
995
- const template = this.next().getValue();
996
- const exprs = template.expressions.map(expr => JavaScriptParser.parse(expr));
997
- if (tag) {
998
- return new TaggedTemplateExpression(tag, template.strings, exprs);
999
- }
1000
- else {
1001
- return new TemplateLiteral(template.strings, exprs);
1002
- }
1003
- }
1004
- parseMemberWithPresentNewPrefixesExpression() {
1005
- this.consume(Token.NEW);
1006
- let classRef;
1007
- if (this.peek().isType(Token.IMPORT) && this.peekAhead().isType(Token.L_PARENTHESES)) {
1008
- throw new Error(this.errorMessage(`parsing new import (`));
1009
- }
1010
- else if (this.peek().isType(Token.SUPER)) {
1011
- throw new Error(this.errorMessage(`parsing new super() is never allowed`));
1012
- }
1013
- else if (this.peek().isType(Token.PERIOD)) {
1014
- classRef = this.parseNewTargetExpression();
1015
- return this.parseMemberExpressionContinuation(classRef);
1016
- }
1017
- else {
1018
- classRef = this.parseMemberExpression();
1019
- }
1020
- if (this.peek().isType(Token.L_PARENTHESES)) {
1021
- const args = this.parseArguments();
1022
- classRef = new NewExpression(classRef, args);
1023
- return this.parseMemberExpressionContinuation(classRef);
1024
- }
1025
- if (this.peek().isType(Token.QUESTION_PERIOD)) {
1026
- throw new Error(this.errorMessage(`parsing new xxx?.yyy at position`));
1027
- }
1028
- return new NewExpression(classRef);
1029
- }
1030
- parseArguments(maybeArrow) {
1031
- this.consume(Token.L_PARENTHESES);
1032
- const args = [];
1033
- while (this.peek().isNotType(Token.R_PARENTHESES)) {
1034
- const isSpread = this.check(Token.ELLIPSIS);
1035
- let argument = this.parseAssignmentExpressionCoverGrammar();
1036
- if (ParsingArrowHeadFlag.MaybeArrowHead === maybeArrow) {
1037
- if (isSpread) {
1038
- if (argument instanceof AssignmentExpression) {
1039
- throw new Error(this.errorMessage(` Rest parameter may not have a default initializer'`));
1040
- }
1041
- if (this.peek().isType(Token.COMMA)) {
1042
- throw new Error(this.errorMessage(`parsing '...spread,arg =>'`));
1043
- }
1044
- }
1045
- }
1046
- if (isSpread) {
1047
- argument = new SpreadElement(argument);
1048
552
  }
1049
- args.push(argument);
1050
- if (!this.check(Token.COMMA))
1051
- break;
1052
- }
1053
- if (!this.check(Token.R_PARENTHESES)) {
1054
- throw new Error(this.errorMessage(`parsing arguments call, expecting ')'`));
1055
- }
1056
- return args;
1057
- }
1058
- parseAssignmentExpressionCoverGrammar() {
1059
- if (this.peek().isType(Token.YIELD)) {
1060
- return this.parseYieldExpression();
1061
- }
1062
- let expression = this.parseConditionalExpression();
1063
- const op = this.peek().token;
1064
- if (!Token.isArrowOrAssignmentOp(op))
1065
- return expression;
1066
- if (op === Token.ARROW) {
1067
- if (!this.isIdentifier(expression) && !this.isParenthesized(expression)) {
1068
- throw new Error(this.errorMessage(`Malformed Arrow Fun Param List`));
1069
- }
1070
- if (expression instanceof SequenceExpression) {
1071
- const params = expression.getExpressions().map(expr => new Param(expr));
1072
- return this.parseArrowFunctionLiteral(params, ArrowFunctionType.NORMAL);
1073
- }
1074
- if (expression instanceof GroupingExpression) {
1075
- return this.parseArrowFunctionLiteral([new Param(expression.getNode())], ArrowFunctionType.NORMAL);
1076
- }
1077
- return this.parseArrowFunctionLiteral([new Param(expression)], ArrowFunctionType.NORMAL);
1078
- }
1079
- if (this.isAssignableIdentifier(expression)) {
1080
- if (this.isParenthesized(expression)) {
1081
- throw new Error(this.errorMessage(`Invalid Destructuring Target`));
1082
- }
1083
- }
1084
- else if (this.isProperty(expression)) {
1085
- }
1086
- else if (this.isPattern(expression) && Token.isAssignment(op)) {
1087
- if (this.isParenthesized(expression)) {
1088
- }
1089
- }
1090
- else {
1091
- if (!this.isValidReferenceExpression(expression)) {
1092
- throw new Error(this.errorMessage(`Invalid Reference Expression`));
1093
- }
1094
- if (Token.isLogicalAssignmentOp(op)) {
1095
- throw new Error(this.errorMessage(`Invalid Lhs In Assignment`));
1096
- }
1097
- }
1098
- this.consume(op);
1099
- const right = this.parseAssignmentExpression();
1100
- if (!Token.isAssignment(op)) {
1101
- throw new Error(this.errorMessage(`Invalid Destructuring Target`));
1102
- }
1103
- return new AssignmentExpression(op.getName(), expression, right);
1104
- }
1105
- parseAssignmentExpression() {
1106
- return this.parseAssignmentExpressionCoverGrammar();
1107
- }
1108
- parseArrowFunctionLiteral(parameters, flag, rest) {
1109
- this.consume(Token.ARROW);
1110
- const body = this.parseArrowFunctionBody();
1111
- return new ArrowFunctionExpression(parameters, body, flag, rest);
1112
- }
1113
- parseRegExpLiteral() {
1114
- if (!this.scanner.scanRegExpPattern()) {
1115
- throw new Error('Unterminated RegExp');
1116
- }
1117
- return this.scanner.currentToken().getValue();
1118
- }
1119
- parseArrayLiteral(isPattern) {
1120
- this.consume(Token.L_BRACKETS);
1121
- const values = [];
1122
- let firstSpreadIndex = -1;
1123
- while (!this.check(Token.R_BRACKETS)) {
1124
- let elem;
1125
- if (this.peek().isType(Token.COMMA)) {
1126
- this.consume(Token.COMMA);
1127
- continue;
1128
- }
1129
- else if (this.check(Token.ELLIPSIS)) {
1130
- const argument = this.parsePossibleDestructuringSubPattern();
1131
- elem = isPattern
1132
- ? new RestElement(argument)
1133
- : new SpreadElement(argument);
1134
- if (firstSpreadIndex < 0) {
1135
- firstSpreadIndex = values.length;
1136
- }
1137
- if (this.peek().isType(Token.COMMA)) {
1138
- throw new Error(this.errorMessage(`Element After Rest @${this.position()}`));
1139
- }
1140
- }
1141
- else {
1142
- elem = this.parsePossibleDestructuringSubPattern();
1143
- }
1144
- values.push(elem);
1145
- }
1146
- if (isPattern) {
1147
- return new ArrayPattern(values);
1148
- }
1149
- return new ArrayExpression(values);
1150
- }
1151
- parsePossibleDestructuringSubPattern() {
1152
- return this.parseAssignmentExpressionCoverGrammar();
1153
- }
1154
- parseObjectLiteral(isPattern) {
1155
- this.consume(Token.L_CURLY);
1156
- const properties = [];
1157
- while (!this.check(Token.R_CURLY)) {
1158
- const property = this.parseObjectPropertyDefinition(isPattern);
1159
- properties.push(property);
1160
- if (this.peek().isNotType(Token.R_CURLY)) {
1161
- this.expect(Token.COMMA);
1162
- }
1163
- }
1164
- if (isPattern) {
1165
- return new ObjectPattern(properties);
1166
- }
1167
- return new ObjectExpression(properties);
1168
- }
1169
- parseObjectPropertyDefinition(isPattern) {
1170
- const propInfo = { kind: PropertyKind.NotSet };
1171
- const nameExpression = this.parseProperty(propInfo);
1172
- switch (propInfo.kind) {
1173
- case PropertyKind.Spread:
1174
- let value = nameExpression;
1175
- if (isPattern) {
1176
- value = new RestElement(value.getArgument());
1177
- }
1178
- return new Property(value.getArgument(), value, 'init');
1179
- case PropertyKind.Value: {
1180
- this.consume(Token.COLON);
1181
- const value = this.parsePossibleDestructuringSubPattern();
1182
- return new Property(nameExpression, value, 'init');
1183
- }
1184
- case PropertyKind.Assign:
1185
- case PropertyKind.ShorthandOrClassField:
1186
- case PropertyKind.Shorthand: {
1187
- const lhs = new Identifier(propInfo.name);
1188
- if (!this.isAssignableIdentifier(lhs)) {
1189
- throw new Error(this.errorMessage('Strict Eval Arguments'));
1190
- }
1191
- let value;
1192
- if (this.peek().isType(Token.ASSIGN)) {
1193
- this.consume(Token.ASSIGN);
1194
- const rhs = this.parseAssignmentExpression();
1195
- value = new AssignmentExpression(Token.ASSIGN.getName(), lhs, rhs);
1196
- }
1197
- else {
1198
- value = lhs;
1199
- }
1200
- return new Property(nameExpression, value, 'init');
1201
- }
1202
- case PropertyKind.Method: {
1203
- const value = this.parseFunctionLiteral(propInfo.funcFlag);
1204
- return new Property(nameExpression, value, 'init');
1205
- }
1206
- case PropertyKind.AccessorGetter:
1207
- case PropertyKind.AccessorSetter: {
1208
- const isGet = propInfo.kind == PropertyKind.AccessorGetter;
1209
- const value = this.parseFunctionLiteral(propInfo.funcFlag);
1210
- return new Property(nameExpression, value, isGet ? 'get' : 'set');
1211
- }
1212
- case PropertyKind.ClassField:
1213
- case PropertyKind.NotSet:
1214
- return NullNode;
1215
- }
1216
- }
1217
- parseProperty(propInfo) {
1218
- let nextToken = this.peek();
1219
- if (this.check(Token.ASYNC)) {
1220
- nextToken = this.peek();
1221
- if (nextToken.isNotType(Token.MUL)
1222
- && parsePropertyKindFromToken(nextToken.token, propInfo)
1223
- || this.scanner.hasLineTerminatorBeforeNext()) {
1224
- return AsyncIdentifier;
1225
- }
1226
- propInfo.kind = PropertyKind.Method;
1227
- propInfo.funcFlag = FunctionKind.ASYNC;
1228
- }
1229
- if (this.check(Token.MUL)) {
1230
- propInfo.kind = PropertyKind.Method;
1231
- propInfo.funcFlag = FunctionKind.ASYNC_GENERATOR;
1232
- }
1233
- nextToken = this.peek();
1234
- if (propInfo.kind == PropertyKind.NotSet && nextToken.isType(Token.GET) || nextToken.isType(Token.SET)) {
1235
- const token = this.next();
1236
- if (parsePropertyKindFromToken(this.peek().token, propInfo)) {
1237
- return nextToken.isType(Token.GET) ? GetIdentifier : SetIdentifier;
1238
- }
1239
- if (token.isType(Token.GET)) {
1240
- propInfo.kind = PropertyKind.AccessorGetter;
1241
- }
1242
- else if (token.isType(Token.SET)) {
1243
- propInfo.kind = PropertyKind.AccessorSetter;
1244
- }
1245
- }
1246
- let propertyName;
1247
- switch (nextToken.token) {
1248
- case Token.PRIVATE_NAME:
1249
- this.consume(Token.PRIVATE_NAME);
1250
- if (propInfo.kind == PropertyKind.NotSet) {
1251
- parsePropertyKindFromToken(this.peek().token, propInfo);
1252
- }
1253
- propertyName = this.getIdentifier();
1254
- break;
1255
- case Token.STRING:
1256
- case Token.NUMBER:
1257
- case Token.BIGINT:
1258
- this.consume(nextToken.token);
1259
- propertyName = nextToken.getValue();
1260
- propInfo.name = propertyName.getValue();
553
+ case Token.VAR:
554
+ case Token.LET:
555
+ case Token.CONST:
556
+ const declaration = this.parseVariableStatement(VariableDeclarationContext.StatementListItem, names);
557
+ const specifiers = declaration.getDeclarations()
558
+ .map(node => new ExportSpecifier(node.getId(), node.getId()));
559
+ result = new ExportNamedDeclaration(specifiers, declaration);
1261
560
  break;
1262
- case Token.L_BRACKETS:
1263
- this.consume(Token.L_BRACKETS);
1264
- propertyName = this.parseAssignmentExpression();
1265
- this.expect(Token.R_BRACKETS);
1266
- if (propInfo.kind === PropertyKind.NotSet) {
1267
- parsePropertyKindFromToken(this.peek().token, propInfo);
1268
- }
1269
- propInfo.name = propertyName.toString();
1270
- return propertyName;
1271
- case Token.ELLIPSIS:
1272
- if (propInfo.kind == PropertyKind.NotSet) {
1273
- this.consume(Token.ELLIPSIS);
1274
- propertyName = this.parsePossibleDestructuringSubPattern();
1275
- propInfo.kind = PropertyKind.Spread;
1276
- if (!this.isValidReferenceExpression(propertyName)) {
1277
- throw new Error(this.errorMessage('Invalid Rest Binding/Assignment Pattern'));
1278
- }
1279
- if (this.peek().isNotType(Token.R_CURLY)) {
1280
- throw new Error(this.errorMessage('Element After Rest'));
1281
- }
1282
- propInfo.name = propertyName.toString();
1283
- return propertyName;
561
+ case Token.ASYNC:
562
+ this.consume(Token.ASYNC);
563
+ if (this.peek().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorBeforeNext()) {
564
+ const declaration = this.parseAsyncFunctionDeclaration(names, false);
565
+ const identifier = declaration.getId();
566
+ result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
567
+ break;
1284
568
  }
1285
569
  default:
1286
- propertyName = new StringLiteral(this.parsePropertyName().toString());
1287
- propInfo.name = propertyName.toString();
1288
- break;
1289
- }
1290
- if (propInfo.kind === PropertyKind.NotSet) {
1291
- parsePropertyKindFromToken(this.peek().token, propInfo);
570
+ throw new SyntaxError(this.errorMessage('Unexpected Token'));
1292
571
  }
1293
- return propertyName;
1294
- }
1295
- parseMemberExpressionContinuation(expression) {
1296
- if (!Token.isMember(this.peek().token))
1297
- return expression;
1298
- return this.doParseMemberExpressionContinuation(expression);
572
+ // loc.end_pos = scanner() -> location().end_pos;
573
+ // SourceTextModuleDescriptor * descriptor = module();
574
+ // for (const AstRawString* name : names) {
575
+ // descriptor -> AddExport(name, name, loc, zone());
576
+ // }
577
+ return result;
1299
578
  }
1300
- doParseMemberExpressionContinuation(expression) {
1301
- if (!Token.isMember(this.peek().token)) {
1302
- throw new Error(this.errorMessage(`Parsing member expression`));
1303
- }
1304
- do {
579
+ parseImportDeclaration() {
580
+ // ImportDeclaration :
581
+ // 'import' ImportClause 'from' ModuleSpecifier ';'
582
+ // 'import' ModuleSpecifier ';'
583
+ // 'import' ImportClause 'from' ModuleSpecifier [no LineTerminator here]
584
+ // AssertClause ';'
585
+ // 'import' ModuleSpecifier [no LineTerminator here] AssertClause';'
586
+ //
587
+ // ImportClause :
588
+ // ImportedDefaultBinding
589
+ // NameSpaceImport
590
+ // NamedImports
591
+ // ImportedDefaultBinding ',' NameSpaceImport
592
+ // ImportedDefaultBinding ',' NamedImports
593
+ //
594
+ // NameSpaceImport :
595
+ // '*' 'as' ImportedBinding
596
+ this.expect(Token.IMPORT);
597
+ const tok = this.peek();
598
+ // 'import' ModuleSpecifier ';'
599
+ if (tok.isType(Token.STRING)) {
600
+ // Scanner::Location specifier_loc = scanner() -> peek_location();
601
+ const moduleSpecifier = this.parseModuleSpecifier();
602
+ const importAssertions = this.parseImportAssertClause();
603
+ this.expectSemicolon();
604
+ // module() -> AddEmptyImport(module_specifier, import_assertions, specifier_loc,zone());
605
+ return new ImportDeclaration(moduleSpecifier, undefined, importAssertions);
606
+ }
607
+ // Parse ImportedDefaultBinding if present.
608
+ let importDefaultBinding;
609
+ // Scanner::Location import_default_binding_loc;
610
+ if (tok.isNotType(Token.MUL) && tok.isNotType(Token.LBRACE)) {
611
+ importDefaultBinding = this.parseNonRestrictedIdentifier();
612
+ // DeclareUnboundVariable(import_default_binding, VariableMode:: kConst,kNeedsInitialization, pos);
613
+ }
614
+ // Parse NameSpaceImport or NamedImports if present.
615
+ let moduleNamespaceBinding;
616
+ let namedImports;
617
+ // Scanner::Location module_namespace_binding_loc;
618
+ // const ZonePtrList<const NamedImport >* named_imports = nullptr;
619
+ if (importDefaultBinding == undefined || this.check(Token.COMMA)) {
1305
620
  switch (this.peek().token) {
1306
- case Token.L_BRACKETS: {
1307
- this.consume(Token.L_BRACKETS);
1308
- const index = this.parseExpressionCoverGrammar();
1309
- expression = new MemberExpression(expression, index, true);
1310
- this.expect(Token.R_BRACKETS);
1311
- break;
1312
- }
1313
- case Token.PERIOD: {
1314
- this.consume(Token.PERIOD);
1315
- const key = this.parsePropertyName();
1316
- expression = new MemberExpression(expression, key, false);
621
+ case Token.MUL: {
622
+ this.consume(Token.MUL);
623
+ this.expectContextualKeyword('as');
624
+ moduleNamespaceBinding = this.parseNonRestrictedIdentifier();
625
+ // ExpectContextualKeyword(ast_value_factory() -> as_string());
626
+ // module_namespace_binding = ParseNonRestrictedIdentifier();
627
+ // module_namespace_binding_loc = scanner() -> location();
628
+ // DeclareUnboundVariable(module_namespace_binding, VariableMode:: kConst, kCreatedInitialized, pos);
1317
629
  break;
1318
630
  }
1319
- case Token.TEMPLATE_LITERALS: {
1320
- expression = this.parseTemplateLiteral(expression);
631
+ case Token.LBRACE:
632
+ namedImports = this.parseNamedImports();
1321
633
  break;
1322
- }
1323
634
  default:
1324
- break;
635
+ throw new SyntaxError(this.errorMessage('Unexpected Token'));
1325
636
  }
1326
- } while (Token.isMember(this.peek().token));
1327
- return expression;
1328
- }
1329
- parsePropertyName() {
1330
- const next = this.next();
1331
- if (next.getValue() instanceof Identifier) {
1332
- return next.getValue();
1333
- }
1334
- if (Token.isPropertyName(next.token)) {
1335
- return new Identifier(next.token.getName());
1336
- }
1337
- throw new Error(this.errorMessage(`Parsing property expression: Unexpected Token`));
1338
- }
1339
- parsePipelineExpression(expression) {
1340
- let token;
1341
- while (Token.isPipelineOperator(token = this.peek().token)) {
1342
- this.consume(token);
1343
- expression = this.parsePipelineBody(expression);
1344
- }
1345
- return expression;
1346
- }
1347
- parsePipelineBody(lhs) {
1348
- let body;
1349
- let token = this.peek();
1350
- switch (token.token) {
1351
- case Token.FUNCTION:
1352
- this.consume(Token.FUNCTION);
1353
- if (this.peek().isType(Token.MUL)) {
1354
- this.consume(Token.MUL);
1355
- body = this.parseFunctionExpression(FunctionKind.GENERATOR);
1356
- break;
1357
- }
1358
- body = this.parseFunctionExpression(FunctionKind.NORMAL);
1359
- break;
1360
- case Token.ASYNC:
1361
- if (this.peekAhead().isType(Token.FUNCTION)) {
1362
- this.consume(Token.ASYNC);
1363
- this.consume(Token.FUNCTION);
1364
- if (this.peek().isType(Token.MUL)) {
1365
- this.consume(Token.MUL);
1366
- body = this.parseFunctionExpression(FunctionKind.ASYNC_GENERATOR);
1367
- break;
1368
- }
1369
- body = this.parseFunctionExpression(FunctionKind.ASYNC);
1370
- break;
1371
- }
1372
- break;
1373
- default:
1374
- break;
1375
- }
1376
- if (body) {
1377
- return new PipelineExpression(lhs, body);
1378
- }
1379
- if (token.isType(Token.L_PARENTHESES)) {
1380
- body = this.parsePrimaryExpression();
1381
- return new PipelineExpression(lhs, body);
1382
637
  }
1383
- const func = this.parseMemberExpression();
1384
- let args = [];
1385
- switch (this.peek().token) {
1386
- case Token.COLON:
1387
- do {
1388
- this.consume(Token.COLON);
1389
- const isSpread = this.check(Token.ELLIPSIS);
1390
- if (this.peek().isType(Token.CONDITIONAL)) {
1391
- this.consume(Token.CONDITIONAL);
1392
- if (isSpread) {
1393
- args.push('...?');
1394
- }
1395
- else {
1396
- args.push('?');
1397
- }
1398
- }
1399
- else {
1400
- const arg = this.parseAssignmentExpressionCoverGrammar();
1401
- if (isSpread) {
1402
- args.push(new SpreadElement(arg));
1403
- }
1404
- else {
1405
- args.push(arg);
1406
- }
1407
- }
1408
- } while (this.peek().isType(Token.COLON));
1409
- break;
1410
- case Token.L_PARENTHESES:
1411
- this.consume(Token.L_PARENTHESES);
1412
- let indexed = false;
1413
- while (this.peek().isNotType(Token.R_PARENTHESES)) {
1414
- const isSpread = this.check(Token.ELLIPSIS);
1415
- if (this.peek().isType(Token.CONDITIONAL)) {
1416
- this.consume(Token.CONDITIONAL);
1417
- indexed = true;
1418
- if (isSpread) {
1419
- args.push('...?');
1420
- }
1421
- else {
1422
- args.push('?');
1423
- }
1424
- }
1425
- else {
1426
- const arg = this.parseAssignmentExpressionCoverGrammar();
1427
- if (isSpread) {
1428
- args.push(new SpreadElement(arg));
1429
- }
1430
- else {
1431
- args.push(arg);
1432
- }
1433
- }
1434
- this.check(Token.COMMA);
1435
- }
1436
- this.expect(Token.R_PARENTHESES);
1437
- if (!indexed) {
1438
- body = new CallExpression(func, args);
1439
- return new PipelineExpression(lhs, body);
1440
- }
1441
- break;
1442
- default:
1443
- break;
638
+ this.expectContextualKeyword('from');
639
+ // ExpectContextualKeyword(ast_value_factory() -> from_string());
640
+ // Scanner::Location specifier_loc = scanner() -> peek_location();
641
+ const moduleSpecifier = this.parseModuleSpecifier();
642
+ const importAssertions = this.parseImportAssertClause();
643
+ this.expectSemicolon();
644
+ // Now that we have all the information, we can make the appropriate
645
+ // declarations.
646
+ // TODO(neis): Would prefer to call DeclareVariable for each case below rather
647
+ // than above and in ParseNamedImports, but then a possible error message
648
+ // would point to the wrong location. Maybe have a DeclareAt version of
649
+ // Declare that takes a location?
650
+ const specifiers = [];
651
+ if (moduleNamespaceBinding) {
652
+ specifiers.push(new ImportNamespaceSpecifier(moduleNamespaceBinding));
1444
653
  }
1445
- return new PipelineExpression(lhs, func, args);
1446
- }
1447
- parseConditionalExpression() {
1448
- let expression = this.parseLogicalExpression();
1449
- expression = this.parsePipelineExpression(expression);
1450
- return this.peek().isType(Token.CONDITIONAL) ? this.parseConditionalContinuation(expression) : expression;
1451
- }
1452
- parseLogicalExpression() {
1453
- let expression = this.parseBinaryExpression(6);
1454
- const peek = this.peek();
1455
- if (peek.isType(Token.AND) || peek.isType(Token.OR)) {
1456
- const precedence = peek.token.getPrecedence();
1457
- expression = this.parseBinaryContinuation(expression, 4, precedence);
654
+ if (importDefaultBinding) {
655
+ specifiers.push(new ImportDefaultSpecifier(importDefaultBinding));
1458
656
  }
1459
- else if (peek.isType(Token.NULLISH)) {
1460
- expression = this.parseNullishExpression(expression);
657
+ if (namedImports?.length) {
658
+ specifiers.push(...namedImports);
1461
659
  }
1462
- return expression;
1463
- }
1464
- parseBinaryContinuation(x, prec, prec1) {
1465
- do {
1466
- while (this.peek().token.getPrecedence() === prec1) {
1467
- let y;
1468
- let op = this.next();
1469
- const is_right_associative = op.isType(Token.EXP);
1470
- const next_prec = is_right_associative ? prec1 : prec1 + 1;
1471
- y = this.parseBinaryExpression(next_prec);
1472
- if (Token.isCompare(op.token)) {
1473
- let cmp = op.token;
1474
- switch (op.token) {
1475
- case Token.NE:
1476
- cmp = Token.EQ;
1477
- break;
1478
- case Token.NE_STRICT:
1479
- cmp = Token.EQ_STRICT;
1480
- break;
1481
- default: break;
1482
- }
1483
- x = shortcutNumericLiteralBinaryExpression(x, y, cmp);
1484
- if (op.isNotType(cmp)) {
1485
- x = buildUnaryExpression(x, Token.NOT);
1486
- }
1487
- }
1488
- else {
1489
- x = shortcutNumericLiteralBinaryExpression(x, y, op.token);
1490
- }
1491
- }
1492
- --prec1;
1493
- } while (prec1 >= prec);
1494
- return x;
660
+ return new ImportDeclaration(moduleSpecifier, specifiers.length ? specifiers : undefined, importAssertions);
1495
661
  }
1496
- parseBinaryExpression(precedence) {
1497
- const x = this.parseUnaryExpression();
1498
- const precedence1 = this.peek().token.getPrecedence();
1499
- if (precedence1 >= precedence) {
1500
- return this.parseBinaryContinuation(x, precedence, precedence1);
662
+ parseImportExpressions() {
663
+ this.consume(Token.IMPORT);
664
+ if (this.check(Token.PERIOD)) {
665
+ this.expectContextualKeyword('meta');
666
+ return MetaProperty.ImportMeta;
1501
667
  }
1502
- return x;
1503
- }
1504
- parseUnaryExpression() {
1505
- const op = this.peek();
1506
- if (Token.isUnaryOrCount(op.token)) {
1507
- return this.parseUnaryOrPrefixExpression();
668
+ if (this.peek().isNotType(Token.LPAREN)) {
669
+ throw new SyntaxError(this.errorMessage('Unexpected Token'));
1508
670
  }
1509
- if (op.isType(Token.AWAIT)) {
1510
- return this.parseAwaitExpression();
671
+ this.consume(Token.LPAREN);
672
+ if (this.peek().isType(Token.RPAREN)) {
673
+ throw new SyntaxError(this.errorMessage('Import Missing Specifier'));
1511
674
  }
1512
- return this.parsePostfixExpression();
1513
- }
1514
- parseUnaryOrPrefixExpression() {
1515
- const op = this.next();
1516
- const expression = this.parseUnaryExpression();
1517
- if (Token.isUnary(op.token)) {
1518
- if (op.isType(Token.DELETE)) {
1519
- if (this.isIdentifier(expression)) {
1520
- throw new Error(this.errorMessage(`"delete identifier" is a syntax error in strict mode`));
1521
- }
1522
- if (expression instanceof MemberExpression && expression.getProperty().toString().startsWith('#')) {
1523
- throw new Error(this.errorMessage(`"Delete Private Field" is a syntax error`));
1524
- }
675
+ this.setAcceptIN(true);
676
+ const specifier = this.parseAssignmentExpressionCoverGrammar();
677
+ if (this.check(Token.COMMA)) {
678
+ if (this.check(Token.RPAREN)) {
679
+ // A trailing comma allowed after the specifier.
680
+ return new ImportExpression(specifier);
1525
681
  }
1526
- if (this.peek().isType(Token.EXP)) {
1527
- throw new Error(this.errorMessage(`Unexpected Token Unary Exponentiation`));
682
+ else {
683
+ const importAssertions = this.parseAssignmentExpressionCoverGrammar();
684
+ this.check(Token.COMMA); // A trailing comma is allowed after the import
685
+ // assertions.
686
+ this.expect(Token.RPAREN);
687
+ return new ImportExpression(specifier, importAssertions);
688
+ }
689
+ }
690
+ this.expect(Token.RPAREN);
691
+ this.restoreAcceptIN();
692
+ return new ImportExpression(specifier);
693
+ }
694
+ parseVariableStatement(varContext, names) {
695
+ // VariableStatement ::
696
+ // VariableDeclarations ';'
697
+ // The scope of a var declared variable anywhere inside a function
698
+ // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can
699
+ // transform a source-level var declaration into a (Function) Scope
700
+ // declaration, and rewrite the source-level initialization into an assignment
701
+ // statement. We use a block to collect multiple assignments.
702
+ //
703
+ // We mark the block as initializer block because we don't want the
704
+ // rewriter to add a '.result' assignment to such a block (to get compliant
705
+ // behavior for code such as print(eval('var x = 7')), and for cosmetic
706
+ // reasons when pretty-printing. Also, unless an assignment (initialization)
707
+ // is inside an initializer block, it is ignored.
708
+ const declarations = this.parseVariableDeclarations(varContext);
709
+ this.expectSemicolon();
710
+ names.push(...declarations.getDeclarations().map(d => d.getId().toString()));
711
+ return declarations;
712
+ }
713
+ parseImportAssertClause() {
714
+ // AssertClause :
715
+ // assert '{' '}'
716
+ // assert '{' AssertEntries '}'
717
+ // AssertEntries :
718
+ // IdentifierName: AssertionKey
719
+ // IdentifierName: AssertionKey , AssertEntries
720
+ // AssertionKey :
721
+ // IdentifierName
722
+ // StringLiteral
723
+ // auto import_assertions = zone() -> New<ImportAssertions>(zone());
724
+ // if (!FLAG_harmony_import_assertions) {
725
+ // return import_assertions;
726
+ // }
727
+ // Assert clause is optional, and cannot be preceded by a LineTerminator.
728
+ if (this.scanner.hasLineTerminatorBeforeNext() || !this.checkContextualKeyword('assert')) {
729
+ return undefined;
730
+ }
731
+ this.expect(Token.LBRACE);
732
+ const counts = {};
733
+ const importAssertions = [];
734
+ while (this.peek().isNotType(Token.RBRACE)) {
735
+ let attributeKey = this.checkAndGetValue(Token.STRING);
736
+ if (!attributeKey) {
737
+ attributeKey = this.parsePropertyOrPrivatePropertyName();
1528
738
  }
1529
- }
1530
- if (Token.isCount(op.token) || Token.isUnary(op.token)) {
1531
- return buildUnaryExpression(expression, op.token);
1532
- }
1533
- throw new Error(this.errorMessage(`while rewrite unary operation`));
1534
- }
1535
- parsePostfixExpression() {
1536
- const expression = this.parseLeftHandSideExpression();
1537
- if (!Token.isCount(this.peek().token) || this.scanner.hasLineTerminatorBeforeNext()) {
1538
- return expression;
1539
- }
1540
- return this.parsePostfixContinuation(expression);
1541
- }
1542
- parsePostfixContinuation(expression) {
1543
- if (!this.isValidReferenceExpression(expression)) {
1544
- throw new Error(this.errorMessage(`Invalid LHS In Postfix Op.`));
1545
- }
1546
- const op = this.next();
1547
- return buildPostfixExpression(expression, op.token);
1548
- }
1549
- parseLeftHandSideExpression() {
1550
- const result = this.parseMemberExpression();
1551
- if (!Token.isPropertyOrCall(this.peek().token))
1552
- return result;
1553
- return this.parseLeftHandSideContinuation(result);
1554
- }
1555
- parseLeftHandSideContinuation(result) {
1556
- if (this.peek().isType(Token.L_PARENTHESES)
1557
- && this.isIdentifier(result)
1558
- && this.scanner.currentToken().isType(Token.ASYNC)
1559
- && !this.scanner.hasLineTerminatorBeforeNext()) {
1560
- const args = this.parseArguments(ParsingArrowHeadFlag.AsyncArrowFunction);
1561
- if (this.peek().isType(Token.ARROW)) {
1562
- if (!args.length)
1563
- return new EmptyStatement;
1564
- return this.expressionListToExpression(args);
739
+ this.expect(Token.COLON);
740
+ const attributeValue = this.expectAndGetValue(Token.STRING);
741
+ importAssertions.push(new ImportAttribute(attributeKey, attributeValue));
742
+ counts[attributeKey.toString()] = (counts[attributeKey.toString()] ?? 0) + 1;
743
+ if (counts[attributeKey.toString()] > 1) {
744
+ // // It is a syntax error if two AssertEntries have the same key.
745
+ throw new SyntaxError(this.errorMessage('Import Assertion Duplicate Key'));
746
+ }
747
+ if (this.peek().isType(Token.RBRACE))
748
+ break;
749
+ if (!this.check(Token.COMMA)) {
750
+ throw new SyntaxError('Unexpected Token');
751
+ }
752
+ }
753
+ this.expect(Token.RBRACE);
754
+ return importAssertions;
755
+ }
756
+ parseModuleSpecifier() {
757
+ // ModuleSpecifier :
758
+ // StringLiteral
759
+ return this.expectAndGetValue(Token.STRING);
760
+ }
761
+ parseExportClause() {
762
+ // ExportClause :
763
+ // '{' '}'
764
+ // '{' ExportsList '}'
765
+ // '{' ExportsList ',' '}'
766
+ //
767
+ // ExportsList :
768
+ // ExportSpecifier
769
+ // ExportsList ',' ExportSpecifier
770
+ //
771
+ // ExportSpecifier :
772
+ // IdentifierName
773
+ // IdentifierName 'as' IdentifierName
774
+ // IdentifierName 'as' ModuleExportName
775
+ // ModuleExportName
776
+ // ModuleExportName 'as' ModuleExportName
777
+ //
778
+ // ModuleExportName :
779
+ // StringLiteral
780
+ // ZoneChunkList < ExportClauseData >* export_data = zone() -> New<ZoneChunkList<ExportClauseData>>(zone());
781
+ this.expect(Token.LBRACE);
782
+ const exportData = [];
783
+ let nameTok = this.peek();
784
+ while (nameTok.isNotType(Token.RBRACE)) {
785
+ const localName = this.parseExportSpecifierName();
786
+ let exportName;
787
+ if (this.checkContextualKeyword('as')) {
788
+ exportName = this.parseExportSpecifierName();
1565
789
  }
1566
- result = new CallExpression(result, args);
1567
- if (!Token.isPropertyOrCall(this.peek().token))
1568
- return result;
1569
- }
1570
- let optionalChaining = false;
1571
- let isOptional = false;
1572
- do {
1573
- switch (this.peek().token) {
1574
- case Token.QUESTION_PERIOD: {
1575
- if (isOptional) {
1576
- throw new Error(this.errorMessage(`Failure Expression`));
1577
- }
1578
- this.consume(Token.QUESTION_PERIOD);
1579
- isOptional = true;
1580
- optionalChaining = true;
1581
- if (Token.isPropertyOrCall(this.peek().token))
1582
- continue;
1583
- const key = this.parsePropertyName();
1584
- result = new MemberExpression(result, key, false, isOptional);
1585
- break;
1586
- }
1587
- case Token.L_BRACKETS: {
1588
- this.consume(Token.L_BRACKETS);
1589
- const index = this.parseExpressionCoverGrammar();
1590
- result = new MemberExpression(result, index, true, isOptional);
1591
- this.expect(Token.R_BRACKETS);
1592
- break;
1593
- }
1594
- case Token.PERIOD: {
1595
- if (isOptional) {
1596
- throw new Error(this.errorMessage(`Unexpected Token:${this.position()}`));
1597
- }
1598
- this.consume(Token.PERIOD);
1599
- const key = this.parsePropertyName();
1600
- result = new MemberExpression(result, key, false, isOptional);
1601
- break;
1602
- }
1603
- case Token.L_PARENTHESES: {
1604
- const args = this.parseArguments();
1605
- if (result.toString() === 'eval') {
1606
- throw new Error(this.errorMessage(`'eval(...)' is not supported.`));
1607
- }
1608
- result = new CallExpression(result, args, isOptional);
1609
- break;
1610
- }
1611
- case Token.BIND: {
1612
- if (isOptional) {
1613
- throw new Error(this.errorMessage(`Unexpected Token:${this.position()}`));
1614
- }
1615
- this.consume(Token.BIND);
1616
- const key = this.parsePropertyName();
1617
- result = new BindExpression(result, key, false, isOptional);
1618
- break;
1619
- }
1620
- case Token.QUESTION_BIND: {
1621
- if (isOptional) {
1622
- throw new Error(this.errorMessage(`Failure Expression`));
1623
- }
1624
- this.consume(Token.QUESTION_BIND);
1625
- isOptional = true;
1626
- optionalChaining = true;
1627
- const key = this.parsePropertyName();
1628
- result = new BindExpression(result, key, true, isOptional);
1629
- break;
1630
- }
1631
- default:
1632
- if (optionalChaining) {
1633
- throw new Error(this.errorMessage(`Optional Chaining No Template support`));
1634
- }
1635
- result = this.parseTemplateLiteral(result);
1636
- break;
790
+ else {
791
+ exportName = localName;
1637
792
  }
1638
- if (isOptional) {
1639
- isOptional = false;
793
+ exportData.push(new ExportSpecifier(exportName, localName));
794
+ if (this.peek().isType(Token.RBRACE))
795
+ break;
796
+ if (!this.check(Token.COMMA)) {
797
+ throw new SyntaxError('Unexpected Token');
1640
798
  }
1641
- } while (Token.isPropertyOrCall(this.peek().token));
1642
- if (optionalChaining) {
1643
- result = new ChainExpression(result);
1644
799
  }
1645
- return result;
800
+ this.expect(Token.RBRACE);
801
+ return exportData;
1646
802
  }
1647
- parseAwaitExpression() {
1648
- this.consume(Token.AWAIT);
1649
- const value = this.parseUnaryExpression();
1650
- if (this.peek().isType(Token.EXP)) {
1651
- throw new Error(this.scanner.createError(`Unexpected Token Unary Exponentiation`));
803
+ parseExportSpecifierName() {
804
+ const next = this.next();
805
+ // IdentifierName
806
+ if (next.isType(Token.IDENTIFIER) || Token.isPropertyName(next.token)) {
807
+ return next.getValue();
1652
808
  }
1653
- return buildUnaryExpression(value, Token.AWAIT);
1654
- }
1655
- parseNullishExpression(expression) {
1656
- const list = [];
1657
- list.push(expression);
1658
- while (this.peek().isType(Token.NULLISH)) {
1659
- this.consume(Token.NULLISH);
1660
- expression = this.parseBinaryExpression(6);
1661
- list.push(expression);
809
+ // ModuleExportName
810
+ if (next.isType(Token.STRING)) {
811
+ const exportName = next.getValue();
812
+ return exportName;
813
+ }
814
+ throw new SyntaxError(this.errorMessage('Unexpected Token'));
815
+ }
816
+ parseNamedImports() {
817
+ // NamedImports :
818
+ // '{' '}'
819
+ // '{' ImportsList '}'
820
+ // '{' ImportsList ',' '}'
821
+ //
822
+ // ImportsList :
823
+ // ImportSpecifier
824
+ // ImportsList ',' ImportSpecifier
825
+ //
826
+ // ImportSpecifier :
827
+ // BindingIdentifier
828
+ // IdentifierName 'as' BindingIdentifier
829
+ // ModuleExportName 'as' BindingIdentifier
830
+ this.expect(Token.LBRACE);
831
+ const result = [];
832
+ // auto result = zone() -> New < ZonePtrList <const NamedImport>> (1, zone());
833
+ while (this.peek().isNotType(Token.RBRACE)) {
834
+ const importName = this.parseExportSpecifierName();
835
+ let localName = importName;
836
+ // In the presence of 'as', the left-side of the 'as' can
837
+ // be any IdentifierName. But without 'as', it must be a valid
838
+ // BindingIdentifier.
839
+ if (this.checkContextualKeyword('as')) {
840
+ localName = this.parsePropertyOrPrivatePropertyName();
841
+ }
842
+ if (!Token.isValidIdentifier(this.current().token, LanguageMode.Strict, false, isStrict(this.languageMode))) {
843
+ throw new SyntaxError(this.errorMessage('Unexpected Reserved Keyword'));
844
+ }
845
+ else if (this.isEvalOrArguments(localName)) {
846
+ throw new SyntaxError(this.errorMessage('Strict Eval Arguments'));
847
+ }
848
+ result.push(new ImportSpecifier(localName, importName));
849
+ // DeclareUnboundVariable(localName, VariableMode:: kConst, kNeedsInitialization, position());
850
+ // NamedImport * import = zone() -> New<NamedImport>(import_name, local_name, location);
851
+ // result-> Add(import, zone());
852
+ if (this.peek().isType(Token.RBRACE))
853
+ break;
854
+ this.expect(Token.COMMA);
1662
855
  }
1663
- expression = list.pop();
1664
- expression = list.reverse()
1665
- .reduce((previous, current) => new LogicalExpression(Token.NULLISH.getName(), current, previous), expression);
1666
- return expression;
1667
- }
1668
- parseConditionalContinuation(expression) {
1669
- this.consume(Token.CONDITIONAL);
1670
- const left = this.parseAssignmentExpression();
1671
- this.expect(Token.COLON);
1672
- const right = this.parseAssignmentExpression();
1673
- return new ConditionalExpression(expression, left, right);
856
+ this.expect(Token.RBRACE);
857
+ return result;
1674
858
  }
1675
- parseYieldExpression() {
1676
- this.consume(Token.YIELD);
1677
- let delegating = false;
1678
- let expression;
1679
- if (this.check(Token.MUL)) {
1680
- delegating = true;
1681
- }
859
+ parseExportDefault() {
860
+ // Supports the following productions, starting after the 'default' token:
861
+ // 'export' 'default' HoistableDeclaration
862
+ // 'export' 'default' ClassDeclaration
863
+ // 'export' 'default' AssignmentExpression[In] ';'
864
+ this.expect(Token.DEFAULT);
865
+ // Scanner::Location default_loc = scanner() -> location();
866
+ // ZonePtrList <const AstRawString> localNames(1, zone());
867
+ const localNames = [];
868
+ let result;
1682
869
  switch (this.peek().token) {
1683
- case Token.EOS:
1684
- case Token.SEMICOLON:
1685
- case Token.R_CURLY:
1686
- case Token.R_BRACKETS:
1687
- case Token.R_PARENTHESES:
1688
- case Token.COLON:
1689
- case Token.COMMA:
1690
- case Token.IN:
1691
- if (!delegating)
870
+ case Token.FUNCTION:
871
+ result = this.parseHoistableDeclaration(localNames, true);
872
+ break;
873
+ case Token.CLASS:
874
+ this.consume(Token.CLASS);
875
+ result = this.parseClassDeclaration(localNames, true);
876
+ break;
877
+ case Token.ASYNC:
878
+ if (this.peekAhead().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorBeforeNext()) {
879
+ this.consume(Token.ASYNC);
880
+ result = this.parseHoistableDeclaration(localNames, true);
1692
881
  break;
1693
- throw new Error(this.errorMessage(`Delegating yields require an RHS`));
1694
- default:
1695
- expression = this.parseAssignmentExpressionCoverGrammar();
882
+ }
883
+ default: {
884
+ // int pos = position();
885
+ // AcceptINScope scope(this, true);
886
+ this.setAcceptIN(true);
887
+ result = this.parseAssignmentExpression();
888
+ // SetFunctionName(value, ast_value_factory() -> default_string());
889
+ // const AstRawString* local_name = ast_value_factory() -> dot_default_string();
890
+ // localNames.Add(local_name, zone());
891
+ // It's fine to declare this as VariableMode::kConst because the user has
892
+ // no way of writing to it.
893
+ // VariableProxy * proxy = DeclareBoundVariable(local_name, VariableMode:: kConst, pos);
894
+ // proxy ->var() -> set_initializer_position(position());
895
+ // Assignment * assignment = factory() -> NewAssignment(Token.INIT, proxy, value, kNoSourcePosition);
896
+ // result = IgnoreCompletion( factory() -> NewExpressionStatement(assignment, kNoSourcePosition));
897
+ this.expectSemicolon();
898
+ this.restoreAcceptIN();
1696
899
  break;
900
+ }
1697
901
  }
1698
- return new YieldExpression(delegating, expression);
1699
- }
1700
- parseNewTargetExpression() {
1701
- throw new Error(this.errorMessage('Expression (new.target) not supported.'));
1702
- }
1703
- parseClassDeclaration(names, defaultExport) {
1704
- throw new Error(this.errorMessage(`Expression (class) not supported.`));
1705
- }
1706
- parseClassLiteral(name, isStrictReserved) {
1707
- throw new Error(this.errorMessage(`Expression (class) not supported.`));
1708
- }
1709
- parseSuperExpression() {
1710
- throw new Error(this.errorMessage('Expression (supper) not supported.'));
1711
- }
1712
- parseImportExpressions() {
1713
- throw new Error(this.errorMessage('Expression (import) not supported.'));
902
+ // if (!result) {
903
+ // DCHECK_EQ(localNames.length(), 1);
904
+ // module() -> AddExport(localNames.first(), ast_value_factory() -> default_string(), default_loc, zone());
905
+ // }
906
+ return new ExportDefaultDeclaration(result);
907
+ }
908
+ parseExportStar() {
909
+ this.consume(Token.MUL);
910
+ if (!this.peekContextualKeyword('as')) {
911
+ // 'export' '*' 'from' ModuleSpecifier ';'
912
+ // Scanner::Location loc = scanner() -> location();
913
+ this.expectContextualKeyword('from');
914
+ // Scanner::Location specifier_loc = scanner() -> peek_location();
915
+ const moduleSpecifier = this.parseModuleSpecifier();
916
+ const importAssertions = this.parseImportAssertClause();
917
+ this.expectSemicolon();
918
+ // module() -> AddStarExport(module_specifier, import_assertions, loc,specifier_loc, zone());
919
+ return new ExportAllDeclaration(moduleSpecifier, undefined, importAssertions);
920
+ }
921
+ // 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier ';'
922
+ //
923
+ // Desugaring:
924
+ // export * as x from "...";
925
+ // ~>
926
+ // import * as .x from "..."; export {.x as x};
927
+ //
928
+ // Note that the desugared internal namespace export name (.x above) will
929
+ // never conflict with a string literal export name, as literal string export
930
+ // names in local name positions (i.e. left of 'as' or in a clause without
931
+ // 'as') are disallowed without a following 'from' clause.
932
+ this.expectContextualKeyword('as');
933
+ const exportName = this.parseExportSpecifierName();
934
+ // Scanner::Location export_name_loc = scanner() -> location();
935
+ // const localName = this.nextInternalNamespaceExportName();
936
+ // Scanner::Location local_name_loc = Scanner:: Location:: invalid();
937
+ // DeclareUnboundVariable(local_name, VariableMode:: kConst, kCreatedInitialized,pos);
938
+ this.expectContextualKeyword('from');
939
+ const moduleSpecifier = this.parseModuleSpecifier();
940
+ const importAssertions = this.parseImportAssertClause();
941
+ this.expectSemicolon();
942
+ // const specifiers = [new ExportSpecifier(exportName as Identifier, exportName as Identifier)];
943
+ // module() -> AddStarImport(local_name, module_specifier, import_assertions,local_name_loc, specifier_loc, zone());
944
+ // module() -> AddExport(local_name, export_name, export_name_loc, zone());
945
+ return new ExportAllDeclaration(moduleSpecifier, exportName, importAssertions);
1714
946
  }
1715
947
  }
1716
948
  //# sourceMappingURL=parser.js.map