@ibyar/expressions 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +0 -3
  2. package/api/abstract.d.ts +6 -2
  3. package/api/abstract.js +15 -8
  4. package/api/abstract.js.map +1 -1
  5. package/api/class/class.d.ts +15 -18
  6. package/api/class/class.js +49 -61
  7. package/api/class/class.js.map +1 -1
  8. package/api/class/decorator.d.ts +2 -2
  9. package/api/class/decorator.js +6 -6
  10. package/api/class/decorator.js.map +1 -1
  11. package/api/computing/call.d.ts +2 -2
  12. package/api/computing/call.js +8 -8
  13. package/api/computing/call.js.map +1 -1
  14. package/api/computing/debugger.d.ts +1 -2
  15. package/api/computing/debugger.js +2 -3
  16. package/api/computing/debugger.js.map +1 -1
  17. package/api/computing/new.d.ts +2 -2
  18. package/api/computing/new.js +7 -7
  19. package/api/computing/new.js.map +1 -1
  20. package/api/computing/rest.d.ts +2 -2
  21. package/api/computing/rest.js +6 -6
  22. package/api/computing/rest.js.map +1 -1
  23. package/api/computing/return.d.ts +2 -2
  24. package/api/computing/return.js +6 -6
  25. package/api/computing/return.js.map +1 -1
  26. package/api/computing/spread.d.ts +2 -2
  27. package/api/computing/spread.js +6 -6
  28. package/api/computing/spread.js.map +1 -1
  29. package/api/computing/throw.d.ts +4 -4
  30. package/api/computing/throw.js +18 -18
  31. package/api/computing/throw.js.map +1 -1
  32. package/api/computing/yield.d.ts +2 -2
  33. package/api/computing/yield.js +7 -7
  34. package/api/computing/yield.js.map +1 -1
  35. package/api/definition/array.d.ts +3 -3
  36. package/api/definition/array.js +14 -14
  37. package/api/definition/array.js.map +1 -1
  38. package/api/definition/bind.d.ts +2 -2
  39. package/api/definition/bind.js +9 -9
  40. package/api/definition/bind.js.map +1 -1
  41. package/api/definition/comment.d.ts +3 -3
  42. package/api/definition/comment.js +6 -6
  43. package/api/definition/comment.js.map +1 -1
  44. package/api/definition/function.d.ts +17 -16
  45. package/api/definition/function.js +60 -55
  46. package/api/definition/function.js.map +1 -1
  47. package/api/definition/member.d.ts +2 -2
  48. package/api/definition/member.js +13 -9
  49. package/api/definition/member.js.map +1 -1
  50. package/api/definition/object.d.ts +4 -4
  51. package/api/definition/object.js +22 -22
  52. package/api/definition/object.js.map +1 -1
  53. package/api/definition/statement.d.ts +2 -2
  54. package/api/definition/statement.js +6 -6
  55. package/api/definition/statement.js.map +1 -1
  56. package/api/definition/values.d.ts +15 -37
  57. package/api/definition/values.js +49 -74
  58. package/api/definition/values.js.map +1 -1
  59. package/api/expression.d.ts +42 -8
  60. package/api/expression.js.map +1 -1
  61. package/api/index.d.ts +1 -0
  62. package/api/index.js +1 -0
  63. package/api/index.js.map +1 -1
  64. package/api/module/common.d.ts +3 -3
  65. package/api/module/common.js +9 -9
  66. package/api/module/common.js.map +1 -1
  67. package/api/module/export.d.ts +5 -5
  68. package/api/module/export.js +30 -29
  69. package/api/module/export.js.map +1 -1
  70. package/api/module/import.d.ts +4 -4
  71. package/api/module/import.js +24 -23
  72. package/api/module/import.js.map +1 -1
  73. package/api/operators/assignment.d.ts +3 -3
  74. package/api/operators/assignment.js +5 -5
  75. package/api/operators/assignment.js.map +1 -1
  76. package/api/operators/await.d.ts +3 -3
  77. package/api/operators/await.js +7 -7
  78. package/api/operators/await.js.map +1 -1
  79. package/api/operators/binary.d.ts +1 -1
  80. package/api/operators/binary.js +1 -1
  81. package/api/operators/binary.js.map +1 -1
  82. package/api/operators/chaining.d.ts +2 -2
  83. package/api/operators/chaining.js +6 -6
  84. package/api/operators/chaining.js.map +1 -1
  85. package/api/operators/comma.d.ts +2 -2
  86. package/api/operators/comma.js +6 -6
  87. package/api/operators/comma.js.map +1 -1
  88. package/api/operators/grouping.d.ts +2 -2
  89. package/api/operators/grouping.js +6 -6
  90. package/api/operators/grouping.js.map +1 -1
  91. package/api/operators/logical.d.ts +1 -1
  92. package/api/operators/logical.js +1 -1
  93. package/api/operators/logical.js.map +1 -1
  94. package/api/operators/pipeline.d.ts +3 -3
  95. package/api/operators/pipeline.js +8 -8
  96. package/api/operators/pipeline.js.map +1 -1
  97. package/api/operators/ternary.d.ts +2 -2
  98. package/api/operators/ternary.js +8 -8
  99. package/api/operators/ternary.js.map +1 -1
  100. package/api/operators/types.d.ts +1 -1
  101. package/api/operators/unary.d.ts +3 -3
  102. package/api/operators/unary.js +7 -7
  103. package/api/operators/unary.js.map +1 -1
  104. package/api/operators/update.d.ts +3 -3
  105. package/api/operators/update.js +8 -8
  106. package/api/operators/update.js.map +1 -1
  107. package/api/program.d.ts +3 -3
  108. package/api/program.js +7 -7
  109. package/api/program.js.map +1 -1
  110. package/api/statement/control/block.d.ts +2 -2
  111. package/api/statement/control/block.js +6 -6
  112. package/api/statement/control/block.js.map +1 -1
  113. package/api/statement/control/empty.d.ts +2 -3
  114. package/api/statement/control/empty.js +6 -7
  115. package/api/statement/control/empty.js.map +1 -1
  116. package/api/statement/control/if.d.ts +2 -2
  117. package/api/statement/control/if.js +8 -8
  118. package/api/statement/control/if.js.map +1 -1
  119. package/api/statement/control/switch.d.ts +4 -6
  120. package/api/statement/control/switch.js +19 -20
  121. package/api/statement/control/switch.js.map +1 -1
  122. package/api/statement/control/terminate.d.ts +4 -4
  123. package/api/statement/control/terminate.js +11 -15
  124. package/api/statement/control/terminate.js.map +1 -1
  125. package/api/statement/control/with.d.ts +21 -0
  126. package/api/statement/control/with.js +67 -0
  127. package/api/statement/control/with.js.map +1 -0
  128. package/api/statement/declarations/declares.d.ts +4 -4
  129. package/api/statement/declarations/declares.js +14 -14
  130. package/api/statement/declarations/declares.js.map +1 -1
  131. package/api/statement/iterations/for.d.ts +7 -7
  132. package/api/statement/iterations/for.js +35 -35
  133. package/api/statement/iterations/for.js.map +1 -1
  134. package/api/statement/iterations/while.d.ts +3 -3
  135. package/api/statement/iterations/while.js +14 -14
  136. package/api/statement/iterations/while.js.map +1 -1
  137. package/package.json +14 -4
  138. package/scope/finalizer.d.ts +1 -1
  139. package/scope/pool.d.ts +1 -1
  140. package/scope/proxy.d.ts +1 -1
  141. package/scope/proxy.js +1 -0
  142. package/scope/proxy.js.map +1 -1
  143. package/scope/scope.d.ts +2 -2
  144. package/scope/scope.js +13 -16
  145. package/scope/scope.js.map +1 -1
  146. package/scope/stack.js +23 -23
  147. package/scope/stack.js.map +1 -1
  148. package/v8/enums.d.ts +4 -2
  149. package/v8/enums.js.map +1 -1
  150. package/v8/factory.d.ts +148 -0
  151. package/v8/factory.js +499 -0
  152. package/v8/factory.js.map +1 -0
  153. package/v8/inline.d.ts +49 -49
  154. package/v8/inline.js +317 -307
  155. package/v8/inline.js.map +1 -1
  156. package/v8/node.d.ts +141 -0
  157. package/v8/node.js +2 -0
  158. package/v8/node.js.map +1 -0
  159. package/v8/nodes.d.ts +0 -14
  160. package/v8/nodes.js +1 -152
  161. package/v8/nodes.js.map +1 -1
  162. package/v8/parser.d.ts +21 -18
  163. package/v8/parser.js +97 -84
  164. package/v8/parser.js.map +1 -1
  165. package/v8/stream.d.ts +2 -1
  166. package/v8/stream.js +221 -311
  167. package/v8/stream.js.map +1 -1
  168. package/v8/token.d.ts +3 -1
  169. package/v8/token.js +7 -5
  170. package/v8/token.js.map +1 -1
  171. package/visit/visitor.d.ts +1 -1
package/v8/parser.js CHANGED
@@ -1,27 +1,26 @@
1
+ import { Class } from '../api/class/class.js';
2
+ import { Literal } from '../api/definition/values.js';
3
+ import { ClassLiteralProperty, ClassLiteralPropertyKind, classPropertyKindFor, createClassInfo, FunctionKind, FunctionSyntaxKind, isAccessor, ParseFunctionFlag, PropertyKind, PropertyKindInfo, PropertyPosition, VariableDeclarationContext } from './enums.js';
1
4
  import { JavaScriptInlineParser } from './inline.js';
2
- import { Token } from './token.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';
5
- import { AssignmentExpression } from '../api/operators/assignment.js';
6
- import { VariableDeclarationNode, VariableDeclarator } from '../api/statement/declarations/declares.js';
7
5
  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, ParseFunctionFlag, PropertyKind, PropertyKindInfo, PropertyPosition, VariableDeclarationContext } from './enums.js';
13
- import { isStrict, LanguageMode, } from './language.js';
6
+ import { Token } from './token.js';
7
+ import { ExpressionNodeFactory, ExpressionNodeSourcePosition } from './factory.js';
8
+ import { isStrict, LanguageMode } from './language.js';
14
9
  export class JavaScriptParser extends JavaScriptInlineParser {
15
10
  /**
16
11
  * parser js with
17
12
  * @param source
18
13
  * @returns
19
14
  */
20
- static parse(source, { mode } = {}) {
15
+ static parse(source, { mode, factory, addLocation } = {}) {
21
16
  mode ?? (mode = LanguageMode.Strict);
22
17
  const stream = (typeof source === 'string') || Array.isArray(source)
23
18
  ? TokenStream.getTokenStream(source, mode) : source;
24
- const parser = new JavaScriptParser(stream);
19
+ if (factory == undefined) {
20
+ const sourcePositionFactory = addLocation && typeof source === 'string' ? new ExpressionNodeSourcePosition(source) : undefined;
21
+ factory = new ExpressionNodeFactory(sourcePositionFactory);
22
+ }
23
+ const parser = new JavaScriptParser(stream, factory, false);
25
24
  return parser.scan();
26
25
  }
27
26
  /**
@@ -31,20 +30,22 @@ export class JavaScriptParser extends JavaScriptInlineParser {
31
30
  return JavaScriptInlineParser.parse(source, options);
32
31
  }
33
32
  scan() {
33
+ const range = this.createStartPosition();
34
34
  const isModule = isStrict(this.languageMode);
35
35
  if (isModule) {
36
36
  this.setFunctionKind(FunctionKind.Module);
37
37
  }
38
38
  const body = isModule ? this.parseModuleItemList() : this.parseStatementList(Token.EOS);
39
- return new Program(isModule ? 'module' : 'script', body);
39
+ this.updateRangeEnd(range);
40
+ return this.factory.createProgram(isModule ? 'module' : 'script', body, range);
40
41
  }
41
- parseNewTargetExpression() {
42
+ parseNewTargetExpression(start) {
42
43
  this.consume(Token.PERIOD);
43
44
  const target = this.parsePropertyOrPrivatePropertyName();
44
45
  if (target.toString() !== 'target') {
45
46
  throw new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));
46
47
  }
47
- return MetaProperty.NewTarget;
48
+ return this.factory.createMetaProperty(this.factory.createIdentifier('new', start?.range), this.factory.createIdentifier('target', target.range), this.createRange(start));
48
49
  }
49
50
  parseClassExpression() {
50
51
  this.consume(Token.CLASS);
@@ -55,9 +56,9 @@ export class JavaScriptParser extends JavaScriptInlineParser {
55
56
  isStrictReserved = Token.isStrictReservedWord(this.current().token);
56
57
  }
57
58
  const classLiteral = this.parseClassLiteral(name, isStrictReserved);
58
- return new ClassExpression(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass());
59
+ return this.factory.createClassExpression(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass());
59
60
  }
60
- parseClassDeclaration(names, defaultExport) {
61
+ parseClassDeclaration(names, defaultExport, start) {
61
62
  // ClassDeclaration ::
62
63
  // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
63
64
  // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
@@ -89,7 +90,8 @@ export class JavaScriptParser extends JavaScriptInlineParser {
89
90
  name = identifier;
90
91
  }
91
92
  const classLiteral = this.parseClassLiteral(name, isStrictReserved);
92
- return new ClassDeclaration(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass());
93
+ const range = this.createRange(start);
94
+ return this.factory.createClassDeclaration(classLiteral.getBody(), classLiteral.getDecorators(), classLiteral.getId(), classLiteral.getSuperClass(), range);
93
95
  }
94
96
  parseClassLiteral(name, nameIsStrictReserved) {
95
97
  const isAnonymous = !!!name;
@@ -107,7 +109,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
107
109
  if (this.check(Token.EXTENDS)) {
108
110
  classInfo.extends = this.parseLeftHandSideExpression();
109
111
  }
110
- this.expect(Token.LBRACE);
112
+ const bodyStart = this.expect(Token.LBRACE);
111
113
  const hasExtends = !!classInfo.extends;
112
114
  while (this.peek().isNotType(Token.RBRACE)) {
113
115
  if (this.check(Token.SEMICOLON))
@@ -153,8 +155,8 @@ export class JavaScriptParser extends JavaScriptInlineParser {
153
155
  }
154
156
  this.declarePublicClassMethod(name, property, isConstructor, classInfo);
155
157
  }
156
- this.expect(Token.RBRACE);
157
- const classBody = this.rewriteClassLiteral(classInfo, name);
158
+ const bodyEnd = this.expect(Token.RBRACE);
159
+ const classBody = this.rewriteClassLiteral(classInfo, name, [bodyStart.range[0], bodyEnd.range[1]]);
158
160
  return new Class(classBody, [], name, classInfo.extends);
159
161
  }
160
162
  declarePublicClassMethod(name, property, isConstructor, classInfo) {
@@ -237,7 +239,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
237
239
  // }
238
240
  const initializer = this.parseMemberInitializer(classInfo, propInfo.isStatic);
239
241
  this.expectSemicolon();
240
- const result = this.newClassLiteralProperty(nameExpression, initializer, ClassLiteralPropertyKind.FIELD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
242
+ const result = this.newClassLiteralProperty(nameExpression, initializer, ClassLiteralPropertyKind.FIELD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate, propInfo.rangeStart);
241
243
  this.setFunctionNameFromPropertyName(result, propInfo.name);
242
244
  return result;
243
245
  }
@@ -257,8 +259,8 @@ export class JavaScriptParser extends JavaScriptInlineParser {
257
259
  classInfo.hasSeenConstructor = true;
258
260
  kind = hasExtends ? FunctionKind.DerivedConstructor : FunctionKind.BaseConstructor;
259
261
  }
260
- const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression);
261
- const result = this.newClassLiteralProperty(nameExpression, value, ClassLiteralProperty.Kind.METHOD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
262
+ const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression, propInfo.rangeStart);
263
+ const result = this.newClassLiteralProperty(nameExpression, value, ClassLiteralProperty.Kind.METHOD, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate, propInfo.rangeStart);
262
264
  this.setFunctionNameFromPropertyName(result, propInfo.name);
263
265
  return result;
264
266
  }
@@ -284,9 +286,9 @@ export class JavaScriptParser extends JavaScriptInlineParser {
284
286
  kind = isGet ? FunctionKind.GetterFunction
285
287
  : FunctionKind.SetterFunction;
286
288
  }
287
- const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression);
289
+ const value = this.parseFunctionLiteral(kind, FunctionSyntaxKind.AccessorOrMethod, nameExpression, propInfo.rangeStart);
288
290
  const propertyKind = isGet ? ClassLiteralProperty.Kind.GETTER : ClassLiteralProperty.Kind.SETTER;
289
- const result = this.newClassLiteralProperty(nameExpression, value, propertyKind, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate);
291
+ const result = this.newClassLiteralProperty(nameExpression, value, propertyKind, propInfo.isStatic, propInfo.isComputedName, propInfo.isPrivate, propInfo.rangeStart);
290
292
  const prefix = isGet ? 'get ' : 'set ';
291
293
  this.setFunctionNameFromPropertyName(result, propInfo.name, prefix);
292
294
  return result;
@@ -295,7 +297,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
295
297
  case PropertyKind.Shorthand:
296
298
  case PropertyKind.Spread:
297
299
  // throw new Error(this.errorMessage('Report Unexpected Token'));
298
- return NullNode;
300
+ return this.factory.createNull(propInfo.rangeStart?.range);
299
301
  }
300
302
  throw new Error(this.errorMessage('UNREACHABLE'));
301
303
  }
@@ -333,29 +335,22 @@ export class JavaScriptParser extends JavaScriptInlineParser {
333
335
  const block = this.parseBlock();
334
336
  this.restoreStatue();
335
337
  classInfo.hasStaticElements = true;
336
- return new StaticBlock(block.getBody());
337
- }
338
- declareClass(variableName, value, names) {
339
- names?.push(variableName);
340
- const proxy = this.declareVariable(variableName, 'let');
341
- return new AssignmentExpression('=', proxy, value);
342
- }
343
- declareVariable(name, mode) {
344
- return new VariableDeclarationNode([new VariableDeclarator(new Identifier(name))], mode);
338
+ return this.factory.createClassStaticBlockDeclaration(block.getBody(), block.range);
345
339
  }
346
- newClassLiteralProperty(nameExpression, initializer, kind, isStatic, isComputedName, isPrivate) {
340
+ newClassLiteralProperty(nameExpression, initializer, kind, isStatic, isComputedName, isPrivate, start) {
341
+ const range = this.createRange(start);
347
342
  switch (kind) {
348
343
  case ClassLiteralPropertyKind.METHOD:
349
344
  if (nameExpression.toString() === 'constructor') {
350
- return new MethodDefinition('constructor', nameExpression, initializer, [], isComputedName, isStatic);
345
+ return this.factory.createMethodSignature('constructor', nameExpression, initializer, [], isComputedName, isStatic, range);
351
346
  }
352
- return new MethodDefinition('method', nameExpression, initializer, [], isComputedName, isStatic);
347
+ return this.factory.createMethodSignature('method', nameExpression, initializer, [], isComputedName, isStatic, range);
353
348
  case ClassLiteralPropertyKind.GETTER:
354
- return new MethodDefinition('get', nameExpression, initializer, [], isComputedName, isStatic);
349
+ return this.factory.createMethodSignature('get', nameExpression, initializer, [], isComputedName, isStatic, range);
355
350
  case ClassLiteralPropertyKind.SETTER:
356
- return new MethodDefinition('set', nameExpression, initializer, [], isComputedName, isStatic);
351
+ return this.factory.createMethodSignature('set', nameExpression, initializer, [], isComputedName, isStatic, range);
357
352
  case ClassLiteralPropertyKind.FIELD:
358
- return new PropertyDefinition(nameExpression, [], isComputedName, isStatic, initializer);
353
+ return this.factory.createPropertySignature(nameExpression, [], isComputedName, isStatic, initializer, range);
359
354
  default:
360
355
  break;
361
356
  }
@@ -385,7 +380,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
385
380
  // the ClassExpression* handle this
386
381
  }
387
382
  parseSuperExpression() {
388
- this.consume(Token.SUPER);
383
+ const superToken = this.consume(Token.SUPER);
389
384
  if (Token.isProperty(this.peek().token)) {
390
385
  if (this.peek().isType(Token.PERIOD) && this.peekAhead().isType(Token.PRIVATE_NAME)) {
391
386
  this.consume(Token.PERIOD);
@@ -396,11 +391,11 @@ export class JavaScriptParser extends JavaScriptInlineParser {
396
391
  this.consume(Token.QUESTION_PERIOD);
397
392
  throw new Error(this.errorMessage('Optional Chaining No Super'));
398
393
  }
399
- return Super.INSTANCE;
394
+ return this.factory.createSuper(superToken.range);
400
395
  }
401
396
  throw new Error(this.errorMessage('Unexpected Super'));
402
397
  }
403
- rewriteClassLiteral(classInfo, name) {
398
+ rewriteClassLiteral(classInfo, name, range) {
404
399
  const body = [];
405
400
  if (classInfo.hasSeenConstructor) {
406
401
  body.push(classInfo.constructor);
@@ -409,7 +404,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
409
404
  body.push(...classInfo.instanceFields);
410
405
  body.push(...classInfo.publicMembers);
411
406
  body.push(...classInfo.privateMembers);
412
- return new ClassBody(body);
407
+ return this.factory.createClassBody(body, range);
413
408
  }
414
409
  parseModuleItemList() {
415
410
  // ecma262/#prod-Module
@@ -425,7 +420,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
425
420
  if (!stat) {
426
421
  break;
427
422
  }
428
- if (this.isEmptyStatement(stat)) {
423
+ if (this.factory.isEmptyStatement(stat)) {
429
424
  continue;
430
425
  }
431
426
  body.push(stat);
@@ -473,7 +468,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
473
468
  //
474
469
  // ModuleExportName :
475
470
  // StringLiteral
476
- this.expect(Token.EXPORT);
471
+ const start = this.expect(Token.EXPORT);
477
472
  let result;
478
473
  const names = [];
479
474
  // Statement * result = nullptr;
@@ -481,9 +476,9 @@ export class JavaScriptParser extends JavaScriptInlineParser {
481
476
  // Scanner::Location loc = scanner() -> peek_location();
482
477
  switch (this.peek().token) {
483
478
  case Token.DEFAULT:
484
- return this.parseExportDefault();
479
+ return this.parseExportDefault(start);
485
480
  case Token.MUL:
486
- return this.parseExportStar();
481
+ return this.parseExportStar(start);
487
482
  case Token.LBRACE: {
488
483
  // There are two cases here:
489
484
  //
@@ -535,20 +530,22 @@ export class JavaScriptParser extends JavaScriptInlineParser {
535
530
  // zone());
536
531
  // }
537
532
  }
538
- return new ExportNamedDeclaration(exportData, undefined, moduleSpecifier, importAssertions);
533
+ return this.factory.createNamespaceExportDeclaration(exportData, undefined, moduleSpecifier, importAssertions, this.createRange(start));
539
534
  // return factory() -> EmptyStatement();
540
535
  }
541
536
  case Token.FUNCTION: {
542
537
  const declaration = this.parseFunctionDeclaration();
543
538
  const identifier = declaration.getId();
544
- result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
539
+ const specifier = this.factory.createExportSpecifier(identifier, identifier, identifier.range);
540
+ result = this.factory.createNamespaceExportDeclaration([specifier], declaration, undefined, undefined, this.createRange(start));
545
541
  break;
546
542
  }
547
543
  case Token.CLASS: {
548
- this.consume(Token.CLASS);
549
- const declaration = this.parseClassDeclaration(names, false);
544
+ const classToken = this.consume(Token.CLASS);
545
+ const declaration = this.parseClassDeclaration(names, false, classToken);
550
546
  const identifier = declaration.getId();
551
- result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
547
+ const specifier = this.factory.createExportSpecifier(identifier, identifier, identifier.range);
548
+ result = this.factory.createNamespaceExportDeclaration([specifier], declaration, undefined, undefined, this.createRange(start));
552
549
  break;
553
550
  }
554
551
  case Token.VAR:
@@ -556,15 +553,16 @@ export class JavaScriptParser extends JavaScriptInlineParser {
556
553
  case Token.CONST:
557
554
  const declaration = this.parseVariableStatement(VariableDeclarationContext.StatementListItem, names);
558
555
  const specifiers = declaration.getDeclarations()
559
- .map(node => new ExportSpecifier(node.getId(), node.getId()));
560
- result = new ExportNamedDeclaration(specifiers, declaration);
556
+ .map(node => this.factory.createExportSpecifier(node.getId(), node.getId(), node.getId().range));
557
+ result = this.factory.createNamespaceExportDeclaration(specifiers, declaration, undefined, undefined, this.createRange(start));
561
558
  break;
562
559
  case Token.ASYNC:
563
- this.consume(Token.ASYNC);
560
+ const asyncToken = this.consume(Token.ASYNC);
564
561
  if (this.peek().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorBeforeNext()) {
565
- const declaration = this.parseAsyncFunctionDeclaration(names, false);
562
+ const declaration = this.parseAsyncFunctionDeclaration(names, false, asyncToken);
566
563
  const identifier = declaration.getId();
567
- result = new ExportNamedDeclaration([new ExportSpecifier(identifier, identifier)], declaration);
564
+ const specifier = this.factory.createExportSpecifier(identifier, identifier, identifier.range);
565
+ result = this.factory.createNamespaceExportDeclaration([specifier], declaration, undefined, undefined, this.createRange(start));
568
566
  break;
569
567
  }
570
568
  default:
@@ -594,7 +592,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
594
592
  //
595
593
  // NameSpaceImport :
596
594
  // '*' 'as' ImportedBinding
597
- this.expect(Token.IMPORT);
595
+ const start = this.expect(Token.IMPORT);
598
596
  const tok = this.peek();
599
597
  // 'import' ModuleSpecifier ';'
600
598
  if (tok.isType(Token.STRING)) {
@@ -603,7 +601,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
603
601
  const importAssertions = this.parseImportAssertClause();
604
602
  this.expectSemicolon();
605
603
  // module() -> AddEmptyImport(module_specifier, import_assertions, specifier_loc,zone());
606
- return new ImportDeclaration(moduleSpecifier, undefined, importAssertions);
604
+ return this.factory.createImportDeclaration(moduleSpecifier, undefined, importAssertions, this.createRange(start));
607
605
  }
608
606
  // Parse ImportedDefaultBinding if present.
609
607
  let importDefaultBinding;
@@ -650,21 +648,22 @@ export class JavaScriptParser extends JavaScriptInlineParser {
650
648
  // Declare that takes a location?
651
649
  const specifiers = [];
652
650
  if (moduleNamespaceBinding) {
653
- specifiers.push(new ImportNamespaceSpecifier(moduleNamespaceBinding));
651
+ specifiers.push(this.factory.createImportNamespaceSpecifier(moduleNamespaceBinding, moduleNamespaceBinding.range));
654
652
  }
655
653
  if (importDefaultBinding) {
656
- specifiers.push(new ImportDefaultSpecifier(importDefaultBinding));
654
+ specifiers.push(this.factory.createImportDefaultSpecifier(importDefaultBinding, importDefaultBinding.range));
657
655
  }
658
656
  if (namedImports?.length) {
659
657
  specifiers.push(...namedImports);
660
658
  }
661
- return new ImportDeclaration(moduleSpecifier, specifiers.length ? specifiers : undefined, importAssertions);
659
+ return this.factory.createImportDeclaration(moduleSpecifier, specifiers.length ? specifiers : undefined, importAssertions, this.createRange(start));
662
660
  }
663
661
  parseImportExpressions() {
664
- this.consume(Token.IMPORT);
662
+ const start = this.consume(Token.IMPORT);
665
663
  if (this.check(Token.PERIOD)) {
664
+ const peek = this.peek();
666
665
  this.expectContextualKeyword('meta');
667
- return MetaProperty.ImportMeta;
666
+ return this.factory.createMetaProperty(this.factory.createIdentifier('import', start.range), this.factory.createIdentifier('meta', peek.range), this.createRange(start));
668
667
  }
669
668
  if (this.peek().isNotType(Token.LPAREN)) {
670
669
  throw new SyntaxError(this.errorMessage('Unexpected Token'));
@@ -678,19 +677,19 @@ export class JavaScriptParser extends JavaScriptInlineParser {
678
677
  if (this.check(Token.COMMA)) {
679
678
  if (this.check(Token.RPAREN)) {
680
679
  // A trailing comma allowed after the specifier.
681
- return new ImportExpression(specifier);
680
+ return this.factory.createImportExpression(specifier, undefined, this.createRange(start));
682
681
  }
683
682
  else {
684
683
  const importAssertions = this.parseAssignmentExpressionCoverGrammar();
685
684
  this.check(Token.COMMA); // A trailing comma is allowed after the import
686
685
  // assertions.
687
686
  this.expect(Token.RPAREN);
688
- return new ImportExpression(specifier, importAssertions);
687
+ return this.factory.createImportExpression(specifier, importAssertions, this.createRange(start));
689
688
  }
690
689
  }
691
690
  this.expect(Token.RPAREN);
692
691
  this.restoreAcceptIN();
693
- return new ImportExpression(specifier);
692
+ return this.factory.createImportExpression(specifier, undefined, this.createRange(start));
694
693
  }
695
694
  parseVariableStatement(varContext, names) {
696
695
  // VariableStatement ::
@@ -739,7 +738,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
739
738
  }
740
739
  this.expect(Token.COLON);
741
740
  const attributeValue = this.expectAndGetValue(Token.STRING);
742
- importAssertions.push(new ImportAttribute(attributeKey, attributeValue));
741
+ importAssertions.push(this.factory.createAssertEntry(attributeKey, attributeValue, this.createRange(attributeKey)));
743
742
  counts[attributeKey.toString()] = (counts[attributeKey.toString()] ?? 0) + 1;
744
743
  if (counts[attributeKey.toString()] > 1) {
745
744
  // // It is a syntax error if two AssertEntries have the same key.
@@ -791,7 +790,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
791
790
  else {
792
791
  exportName = localName;
793
792
  }
794
- exportData.push(new ExportSpecifier(exportName, localName));
793
+ exportData.push(this.factory.createExportSpecifier(exportName, localName));
795
794
  if (this.peek().isType(Token.RBRACE))
796
795
  break;
797
796
  if (!this.check(Token.COMMA)) {
@@ -846,7 +845,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
846
845
  else if (this.isEvalOrArguments(localName)) {
847
846
  throw new SyntaxError(this.errorMessage('Strict Eval Arguments'));
848
847
  }
849
- result.push(new ImportSpecifier(localName, importName));
848
+ result.push(this.factory.createImportSpecifier(localName, importName, this.createRange(importName)));
850
849
  // DeclareUnboundVariable(localName, VariableMode:: kConst, kNeedsInitialization, position());
851
850
  // NamedImport * import = zone() -> New<NamedImport>(import_name, local_name, location);
852
851
  // result-> Add(import, zone());
@@ -857,7 +856,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
857
856
  this.expect(Token.RBRACE);
858
857
  return result;
859
858
  }
860
- parseExportDefault() {
859
+ parseExportDefault(start) {
861
860
  // Supports the following productions, starting after the 'default' token:
862
861
  // 'export' 'default' HoistableDeclaration
863
862
  // 'export' 'default' ClassDeclaration
@@ -869,16 +868,16 @@ export class JavaScriptParser extends JavaScriptInlineParser {
869
868
  let result;
870
869
  switch (this.peek().token) {
871
870
  case Token.FUNCTION:
872
- result = this.parseHoistableDeclaration(localNames, true);
871
+ result = this.parseHoistableDeclaration(localNames, true, this.peek());
873
872
  break;
874
873
  case Token.CLASS:
875
- this.consume(Token.CLASS);
876
- result = this.parseClassDeclaration(localNames, true);
874
+ const classToken = this.consume(Token.CLASS);
875
+ result = this.parseClassDeclaration(localNames, true, classToken);
877
876
  break;
878
877
  case Token.ASYNC:
879
878
  if (this.peekAhead().isType(Token.FUNCTION) && !this.scanner.hasLineTerminatorBeforeNext()) {
880
- this.consume(Token.ASYNC);
881
- result = this.parseHoistableDeclaration(localNames, true);
879
+ const asyncStart = this.consume(Token.ASYNC);
880
+ result = this.parseHoistableDeclaration(localNames, true, asyncStart);
882
881
  break;
883
882
  }
884
883
  default: {
@@ -904,9 +903,9 @@ export class JavaScriptParser extends JavaScriptInlineParser {
904
903
  // DCHECK_EQ(localNames.length(), 1);
905
904
  // module() -> AddExport(localNames.first(), ast_value_factory() -> default_string(), default_loc, zone());
906
905
  // }
907
- return new ExportDefaultDeclaration(result);
906
+ return this.factory.createExportDefault(result, this.createRange(start));
908
907
  }
909
- parseExportStar() {
908
+ parseExportStar(start) {
910
909
  this.consume(Token.MUL);
911
910
  if (!this.peekContextualKeyword('as')) {
912
911
  // 'export' '*' 'from' ModuleSpecifier ';'
@@ -917,7 +916,7 @@ export class JavaScriptParser extends JavaScriptInlineParser {
917
916
  const importAssertions = this.parseImportAssertClause();
918
917
  this.expectSemicolon();
919
918
  // module() -> AddStarExport(module_specifier, import_assertions, loc,specifier_loc, zone());
920
- return new ExportAllDeclaration(moduleSpecifier, undefined, importAssertions);
919
+ return this.factory.createExportAllDeclaration(moduleSpecifier, undefined, importAssertions, this.createRange(start));
921
920
  }
922
921
  // 'export' '*' 'as' IdentifierName 'from' ModuleSpecifier ';'
923
922
  //
@@ -943,7 +942,21 @@ export class JavaScriptParser extends JavaScriptInlineParser {
943
942
  // const specifiers = [new ExportSpecifier(exportName as Identifier, exportName as Identifier)];
944
943
  // module() -> AddStarImport(local_name, module_specifier, import_assertions,local_name_loc, specifier_loc, zone());
945
944
  // module() -> AddExport(local_name, export_name, export_name_loc, zone());
946
- return new ExportAllDeclaration(moduleSpecifier, exportName, importAssertions);
945
+ return this.factory.createExportAllDeclaration(moduleSpecifier, exportName, importAssertions, this.createRange(start));
946
+ }
947
+ parseWithStatement() {
948
+ // WithStatement ::
949
+ // 'with' '(' Expression ')' Statement
950
+ const start = this.consume(Token.WITH);
951
+ if (isStrict(this.languageMode)) {
952
+ throw new SyntaxError(this.errorMessage('With is not allowed in Strict mode.'));
953
+ }
954
+ this.expect(Token.LPAREN);
955
+ const object = this.parseExpression();
956
+ this.expect(Token.RPAREN);
957
+ const body = this.parseStatement();
958
+ const range = this.createRange(start);
959
+ return this.factory.createWithStatement(object, body, range);
947
960
  }
948
961
  }
949
962
  //# sourceMappingURL=parser.js.map