tsc-ts 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +1 -1
  2. package/dist/api/compiler/ast.d.ts +10 -9
  3. package/dist/api/compiler/ast.js +22 -16
  4. package/dist/api/compiler/binder-utilities.js +2 -1
  5. package/dist/api/compiler/binder.js +9 -8
  6. package/dist/api/compiler/checker-calls.js +3 -2
  7. package/dist/api/compiler/checker-declaration-order.js +2 -1
  8. package/dist/api/compiler/checker-declarations.js +14 -14
  9. package/dist/api/compiler/checker-declared-types.d.ts +1 -1
  10. package/dist/api/compiler/checker-declared-types.js +12 -11
  11. package/dist/api/compiler/checker-decorators.js +3 -3
  12. package/dist/api/compiler/checker-deprecation.js +17 -18
  13. package/dist/api/compiler/checker-destructuring.d.ts +1 -1
  14. package/dist/api/compiler/checker-destructuring.js +3 -3
  15. package/dist/api/compiler/checker-elaboration.js +8 -7
  16. package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
  17. package/dist/api/compiler/checker-emit-resolver.js +5 -4
  18. package/dist/api/compiler/checker-grammar.js +18 -4
  19. package/dist/api/compiler/checker-heritage.d.ts +1 -1
  20. package/dist/api/compiler/checker-heritage.js +14 -13
  21. package/dist/api/compiler/checker-inference.d.ts +1 -1
  22. package/dist/api/compiler/checker-inference.js +9 -9
  23. package/dist/api/compiler/checker-javascript.d.ts +1 -1
  24. package/dist/api/compiler/checker-javascript.js +5 -4
  25. package/dist/api/compiler/checker-jsx.d.ts +1 -1
  26. package/dist/api/compiler/checker-jsx.js +4 -4
  27. package/dist/api/compiler/checker-literals.js +2 -2
  28. package/dist/api/compiler/checker-members.d.ts +5 -3
  29. package/dist/api/compiler/checker-members.js +75 -53
  30. package/dist/api/compiler/checker-modules.d.ts +1 -1
  31. package/dist/api/compiler/checker-modules.js +13 -13
  32. package/dist/api/compiler/checker-object-literals.d.ts +1 -1
  33. package/dist/api/compiler/checker-object-literals.js +11 -7
  34. package/dist/api/compiler/checker-overloads.d.ts +1 -1
  35. package/dist/api/compiler/checker-overloads.js +4 -3
  36. package/dist/api/compiler/checker-property-access.d.ts +1 -1
  37. package/dist/api/compiler/checker-property-access.js +2 -2
  38. package/dist/api/compiler/checker-services.js +2 -2
  39. package/dist/api/compiler/checker-signatures.d.ts +1 -1
  40. package/dist/api/compiler/checker-signatures.js +9 -8
  41. package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
  42. package/dist/api/compiler/checker-symbol-types.js +22 -952
  43. package/dist/api/compiler/checker-symbols.d.ts +2 -2
  44. package/dist/api/compiler/checker-symbols.js +29 -27
  45. package/dist/api/compiler/checker-type-factory.d.ts +2 -2
  46. package/dist/api/compiler/checker-type-factory.js +57 -16
  47. package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
  48. package/dist/api/compiler/checker-type-nodes.js +2 -2
  49. package/dist/api/compiler/checker-type-operators.d.ts +1 -1
  50. package/dist/api/compiler/checker-type-operators.js +5 -5
  51. package/dist/api/compiler/checker-types.d.ts +73 -7
  52. package/dist/api/compiler/checker-types.js +220 -43
  53. package/dist/api/compiler/checker-unused.d.ts +1 -1
  54. package/dist/api/compiler/checker-unused.js +3 -3
  55. package/dist/api/compiler/checker.d.ts +29 -8
  56. package/dist/api/compiler/checker.js +29 -9
  57. package/dist/api/compiler/diagnostics.d.ts +2 -8
  58. package/dist/api/compiler/diagnostics.js +4 -40
  59. package/dist/api/compiler/file-include.d.ts +35 -8
  60. package/dist/api/compiler/file-include.js +81 -18
  61. package/dist/api/compiler/file-loader.d.ts +33 -4
  62. package/dist/api/compiler/file-loader.js +90 -24
  63. package/dist/api/compiler/instantiation.d.ts +1 -1
  64. package/dist/api/compiler/instantiation.js +86 -50
  65. package/dist/api/compiler/link-tables.d.ts +69 -0
  66. package/dist/api/compiler/link-tables.js +236 -0
  67. package/dist/api/compiler/name-resolver.js +3 -3
  68. package/dist/api/compiler/node-builder-names.d.ts +1 -1
  69. package/dist/api/compiler/node-builder-names.js +12 -12
  70. package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
  71. package/dist/api/compiler/node-builder-pseudo.js +2 -1
  72. package/dist/api/compiler/node-builder.d.ts +1 -1
  73. package/dist/api/compiler/node-builder.js +16 -16
  74. package/dist/api/compiler/parallel-parse.d.ts +2 -0
  75. package/dist/api/compiler/parallel-parse.js +4 -0
  76. package/dist/api/compiler/parser.d.ts +33 -16
  77. package/dist/api/compiler/parser.js +95 -76
  78. package/dist/api/compiler/printer/emit-context.d.ts +5 -2
  79. package/dist/api/compiler/printer/emit-context.js +19 -13
  80. package/dist/api/compiler/program-checker.js +3 -0
  81. package/dist/api/compiler/program.js +9 -1
  82. package/dist/api/compiler/relations.d.ts +1 -1
  83. package/dist/api/compiler/relations.js +10 -10
  84. package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
  85. package/dist/api/compiler/symbol-accessibility.js +123 -26
  86. package/dist/api/compiler/symbol.d.ts +45 -3
  87. package/dist/api/compiler/symbol.js +121 -10
  88. package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
  89. package/dist/api/compiler/transformers/alias-references.js +2 -1
  90. package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
  91. package/dist/api/compiler/transformers/declarations-pseudo.js +4 -2
  92. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
  93. package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
  94. package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
  95. package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
  96. package/dist/api/compiler/transformers/declarations.js +6 -5
  97. package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
  98. package/dist/api/compiler/transformers/reference-resolver.js +26 -24
  99. package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
  100. package/dist/api/compiler/transformers/subtree-facts.js +7 -5
  101. package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
  102. package/dist/api/compiler/transformers/syntax-facts.js +9 -5
  103. package/dist/api/compiler/transformers/type-serialization.js +12 -12
  104. package/package.json +9 -9
  105. package/src/compiler/ast.ts +27 -19
  106. package/src/compiler/binder-utilities.ts +2 -2
  107. package/src/compiler/binder.ts +15 -11
  108. package/src/compiler/checker-calls.ts +3 -3
  109. package/src/compiler/checker-declaration-order.ts +2 -2
  110. package/src/compiler/checker-declarations.ts +21 -14
  111. package/src/compiler/checker-declared-types.ts +12 -12
  112. package/src/compiler/checker-decorators.ts +3 -3
  113. package/src/compiler/checker-deprecation.ts +17 -21
  114. package/src/compiler/checker-destructuring.ts +3 -3
  115. package/src/compiler/checker-elaboration.ts +8 -8
  116. package/src/compiler/checker-emit-resolver.ts +5 -5
  117. package/src/compiler/checker-grammar.ts +17 -5
  118. package/src/compiler/checker-heritage.ts +21 -14
  119. package/src/compiler/checker-inference.ts +17 -9
  120. package/src/compiler/checker-javascript.ts +5 -5
  121. package/src/compiler/checker-jsx.ts +12 -8
  122. package/src/compiler/checker-literals.ts +2 -2
  123. package/src/compiler/checker-members.ts +91 -47
  124. package/src/compiler/checker-modules.ts +23 -13
  125. package/src/compiler/checker-object-literals.ts +22 -6
  126. package/src/compiler/checker-overloads.ts +6 -6
  127. package/src/compiler/checker-property-access.ts +2 -2
  128. package/src/compiler/checker-services.ts +2 -2
  129. package/src/compiler/checker-signatures.ts +9 -9
  130. package/src/compiler/checker-symbol-types.ts +20 -940
  131. package/src/compiler/checker-symbols.ts +42 -35
  132. package/src/compiler/checker-type-factory.ts +53 -16
  133. package/src/compiler/checker-type-nodes.ts +2 -2
  134. package/src/compiler/checker-type-operators.ts +13 -5
  135. package/src/compiler/checker-types.ts +223 -43
  136. package/src/compiler/checker-unused.ts +3 -3
  137. package/src/compiler/checker.ts +31 -9
  138. package/src/compiler/diagnostics.ts +5 -44
  139. package/src/compiler/file-include.ts +85 -17
  140. package/src/compiler/file-loader.ts +104 -35
  141. package/src/compiler/incremental.ts +39 -5
  142. package/src/compiler/instantiation.ts +99 -55
  143. package/src/compiler/link-tables.ts +245 -0
  144. package/src/compiler/name-resolver.ts +3 -3
  145. package/src/compiler/node-builder-names.ts +21 -19
  146. package/src/compiler/node-builder-pseudo.ts +2 -2
  147. package/src/compiler/node-builder.ts +24 -16
  148. package/src/compiler/parallel-check.ts +11 -8
  149. package/src/compiler/parallel-parse.ts +5 -0
  150. package/src/compiler/parse-thread.ts +0 -4
  151. package/src/compiler/parser.ts +120 -70
  152. package/src/compiler/printer/emit-context.ts +20 -15
  153. package/src/compiler/program-checker.ts +2 -0
  154. package/src/compiler/program.ts +8 -1
  155. package/src/compiler/relations.ts +10 -10
  156. package/src/compiler/symbol-accessibility.ts +120 -25
  157. package/src/compiler/symbol.ts +127 -9
  158. package/src/compiler/transformers/alias-references.ts +2 -2
  159. package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
  160. package/src/compiler/transformers/declarations-pseudo.ts +7 -4
  161. package/src/compiler/transformers/declarations-syntactic.ts +17 -9
  162. package/src/compiler/transformers/declarations-tracker.ts +3 -3
  163. package/src/compiler/transformers/declarations.ts +6 -6
  164. package/src/compiler/transformers/reference-resolver.ts +37 -25
  165. package/src/compiler/transformers/subtree-facts.ts +13 -5
  166. package/src/compiler/transformers/syntax-facts.ts +10 -5
  167. package/src/compiler/transformers/type-serialization.ts +12 -12
  168. package/src/compiler/tsc-build.ts +17 -13
  169. package/src/compiler/tsc-cli.ts +9 -6
  170. package/src/compiler/tsc-compile.ts +16 -7
  171. package/src/compiler/tsc-watch.ts +94 -26
@@ -5,7 +5,7 @@
5
5
  // const file = parseSourceFile('/src/main.ts', text);
6
6
  // for (const statement of file.statements.nodes) console.log(statement.kind);
7
7
  // ```
8
- import { ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntLiteral, BinaryExpression, BindingElement, BindingPattern, Block, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseOrDefaultClause, CatchClause, CheckJsDirective, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DeleteExpression, DoStatement, ElementAccessExpression, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleIndicatorOptions, ExternalModuleReference, FileReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, JSDocAllType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, KeywordExpression, KeywordTypeNode, LabeledStatement, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignatureDeclaration, MissingDeclaration, MissingNodeList, ModifierList, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NewExpression, NoSubstitutionTemplateLiteral, NodeList, NodeVisitor, NonNullExpression, NumericLiteral, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PostfixUnaryExpression, Pragma, PragmaArgument, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisTypeNode, ThrowStatement, Token, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression, getBody, getIsTypeOnly, getModifiers, getName, getPostfixToken, getQuestionToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, } from './ast.js';
8
+ import { ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntLiteral, BinaryExpression, BindingElement, BindingPattern, Block, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseOrDefaultClause, CatchClause, CheckJsDirective, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DeleteExpression, DoStatement, ElementAccessExpression, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleIndicatorOptions, ExternalModuleReference, FileReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, JSDocAllType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, KeywordExpression, KeywordTypeNode, LabeledStatement, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignatureDeclaration, MissingDeclaration, MissingNodeList, ModifierList, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NewExpression, NoSubstitutionTemplateLiteral, NodeList, NodeVisitor, NonNullExpression, NumericLiteral, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PostfixUnaryExpression, Pragma, PragmaArgument, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, ReferenceIdentifier, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisTypeNode, ThrowStatement, Token, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression, getBody, getIsTypeOnly, getModifiers, getName, getPostfixToken, getQuestionToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, } from './ast.js';
9
9
  import { canHaveDecorators, canHaveIllegalDecorators, compareNodePositions, getBinaryOperatorPrecedence, getExternalModuleName, getImportTypeNodeLiteral, getTextOfNodeFromSourceText, isAmbientModule, isAnyImportOrReExport, isAssignmentOperator, isClassMemberModifier, isFunctionLike, isImportCall, isImportMeta, isInJSFile, isKeyword, isKeywordOrPunctuation, isLeftHandSideExpression, isModifierKind, isRequireCall, isReservedWord, isStringLiteralLike, modifierToFlag, modifiersToFlags, nodeIsMissing, nodeIsPresent, tagNamesAreEquivalent, tokenIsIdentifierOrKeyword, tokenIsIdentifierOrKeywordOrGreaterThan, } from './ast-utilities.js';
10
10
  import { isLineBreak } from './character-codes.js';
11
11
  import { Diagnostic, messageCode } from './diagnostics.js';
@@ -211,12 +211,15 @@ export class Parser extends ScannerErrorReporter {
211
211
  this.scanner.setLanguageVariant(this.languageVariant);
212
212
  }
213
213
  /**
214
- * Frees the scanner's copy of the text once the parser is done. The parser and its scanner and
215
- * JSDoc parser refer to each other, so natively they're freed only by a cycle collection, which may
216
- * come much later.
214
+ * Frees the scanner's copy of the text once the parser is done, and drops the references back to
215
+ * this parser from its scanner and JSDoc parser. Natively, the parser is then freed as soon as its
216
+ * caller lets go of it, instead of at a cycle collection, which may come much later (on a parse
217
+ * thread, not before the thread exits).
217
218
  */
218
219
  release() {
219
220
  this.scanner.setText('');
221
+ this.scanner.setOnError(undefined);
222
+ this.jsdoc = releasedParser().jsdoc;
220
223
  }
221
224
  token() {
222
225
  return this.currentToken;
@@ -421,16 +424,10 @@ export class Parser extends ScannerErrorReporter {
421
424
  collectExternalModuleReferences(result);
422
425
  if (result.isJS())
423
426
  result.jsDiagnostics = attachFileToDiagnostics(this.jsDiagnostics, result);
424
- // Declaration files get their caches on first use (in a thread's copy once they may be shared,
425
- // `useThreadTextCaches`); the file's DiagnosticFile exists from here on, so reading it never
426
- // writes to the file. The scanner holds the text's code units unless a nested parse cut its text short.
427
- const scanner = this.scanner;
428
- if (result.isDeclarationFile)
429
- result.diagnosticFile();
430
- else if (scanner.text === result.text && scanner.end === result.text.length)
431
- result.computeCachesFromUnits(scanner.chars);
432
- else
433
- result.computeCaches();
427
+ // Files get their line starts on first use (in a thread's copy once they may be shared,
428
+ // `useThreadTextCaches`): most files are never pointed into by a diagnostic. The file's
429
+ // DiagnosticFile exists from here on, so reading it never writes to the file.
430
+ result.diagnosticFile();
434
431
  return result;
435
432
  }
436
433
  newSourceFile(statements, eof) {
@@ -1315,7 +1312,7 @@ export class Parser extends ScannerErrorReporter {
1315
1312
  return this.finishWithJSDoc(new ContinueStatement(label), pos, jsdoc);
1316
1313
  }
1317
1314
  parseIdentifierUnlessAtSemicolon() {
1318
- return this.canParseSemicolon() ? undefined : this.parseIdentifier();
1315
+ return this.canParseSemicolon() ? undefined : this.parseIdentifier(1 /* IdentifierUse.Name */);
1319
1316
  }
1320
1317
  parseReturnStatement() {
1321
1318
  const pos = this.nodePos();
@@ -1660,7 +1657,7 @@ export class Parser extends ScannerErrorReporter {
1660
1657
  // named `implements`.
1661
1658
  if (this.isBindingIdentifier() && !this.isImplementsClause()) {
1662
1659
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
1663
- const id = this.createIdentifier(this.isBindingIdentifier());
1660
+ const id = this.createIdentifier(this.isBindingIdentifier(), 1 /* IdentifierUse.Name */);
1664
1661
  this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
1665
1662
  return id;
1666
1663
  }
@@ -1888,7 +1885,7 @@ export class Parser extends ScannerErrorReporter {
1888
1885
  }
1889
1886
  parseInterfaceDeclaration(pos, jsdoc, modifiers) {
1890
1887
  this.parseExpected(119 /* SyntaxKind.InterfaceKeyword */);
1891
- const name = this.parseIdentifier();
1888
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
1892
1889
  const typeParameters = this.parseTypeParameters();
1893
1890
  const heritageClauses = this.parseHeritageClauses();
1894
1891
  const members = this.parseObjectTypeMembers();
@@ -1900,7 +1897,7 @@ export class Parser extends ScannerErrorReporter {
1900
1897
  this.parseExpected(156 /* SyntaxKind.TypeKeyword */);
1901
1898
  if (this.hasPrecedingLineBreak())
1902
1899
  this.parseErrorAtCurrentToken(108 /* Diagnostics.Line_break_not_permitted_here */);
1903
- const name = this.parseIdentifier();
1900
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
1904
1901
  const typeParameters = this.parseTypeParameters();
1905
1902
  this.parseExpected(63 /* SyntaxKind.EqualsToken */);
1906
1903
  const type = this.token() === 141 /* SyntaxKind.IntrinsicKeyword */ && this.lookAhead(nextIsNotDot)
@@ -1926,7 +1923,7 @@ export class Parser extends ScannerErrorReporter {
1926
1923
  parseEnumDeclaration(pos, jsdoc, modifiers) {
1927
1924
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
1928
1925
  this.parseExpected(93 /* SyntaxKind.EnumKeyword */);
1929
- const name = this.parseIdentifier();
1926
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
1930
1927
  let members;
1931
1928
  if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
1932
1929
  const saveContextFlags = this.contextFlags;
@@ -1965,7 +1962,7 @@ export class Parser extends ScannerErrorReporter {
1965
1962
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
1966
1963
  if (this.token() === 162 /* SyntaxKind.GlobalKeyword */) {
1967
1964
  // `global` names the global scope augmentation.
1968
- name = this.parseIdentifier();
1965
+ name = this.parseIdentifier(1 /* IdentifierUse.Name */);
1969
1966
  keyword = 162 /* SyntaxKind.GlobalKeyword */;
1970
1967
  }
1971
1968
  else {
@@ -1994,7 +1991,7 @@ export class Parser extends ScannerErrorReporter {
1994
1991
  }
1995
1992
  parseModuleOrNamespaceDeclaration(pos, jsdoc, modifiers, nested, keyword) {
1996
1993
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
1997
- const name = nested ? this.parseIdentifierName() : this.parseIdentifier();
1994
+ const name = nested ? this.parseIdentifierName(1 /* IdentifierUse.Name */) : this.parseIdentifier(1 /* IdentifierUse.Name */);
1998
1995
  let body;
1999
1996
  if (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
2000
1997
  const implicitExport = new Token(94 /* SyntaxKind.ExportKeyword */);
@@ -2017,7 +2014,7 @@ export class Parser extends ScannerErrorReporter {
2017
2014
  const afterImportPos = this.nodePos();
2018
2015
  // The identifier isn't parsed in an await context; the checker reports `await`.
2019
2016
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
2020
- let identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
2017
+ let identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
2021
2018
  let phaseModifier = 0 /* SyntaxKind.Unknown */;
2022
2019
  if (identifier !== undefined &&
2023
2020
  identifier.text === 'type' &&
@@ -2025,7 +2022,7 @@ export class Parser extends ScannerErrorReporter {
2025
2022
  (this.isIdentifier() && this.lookAhead(nextTokenIsFromKeywordOrEqualsToken))) &&
2026
2023
  (this.isIdentifier() || this.tokenAfterImportDefinitelyProducesImportDeclaration())) {
2027
2024
  phaseModifier = 156 /* SyntaxKind.TypeKeyword */;
2028
- identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
2025
+ identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
2029
2026
  }
2030
2027
  else if (identifier !== undefined && identifier.text === 'defer') {
2031
2028
  const shouldParseAsDeferModifier = this.token() === 161 /* SyntaxKind.FromKeyword */
@@ -2033,7 +2030,7 @@ export class Parser extends ScannerErrorReporter {
2033
2030
  : this.token() !== 27 /* SyntaxKind.CommaToken */ && this.token() !== 63 /* SyntaxKind.EqualsToken */;
2034
2031
  if (shouldParseAsDeferModifier) {
2035
2032
  phaseModifier = 166 /* SyntaxKind.DeferKeyword */;
2036
- identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
2033
+ identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
2037
2034
  }
2038
2035
  }
2039
2036
  if (identifier !== undefined &&
@@ -2124,7 +2121,7 @@ export class Parser extends ScannerErrorReporter {
2124
2121
  const pos = this.nodePos();
2125
2122
  this.parseExpected(41 /* SyntaxKind.AsteriskToken */);
2126
2123
  this.parseExpected(129 /* SyntaxKind.AsKeyword */);
2127
- const name = this.parseIdentifier();
2124
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
2128
2125
  return this.finishNode(new NamespaceImport(name), pos);
2129
2126
  }
2130
2127
  parseNamedImports() {
@@ -2156,9 +2153,9 @@ export class Parser extends ScannerErrorReporter {
2156
2153
  // import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
2157
2154
  // import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
2158
2155
  if (this.token() === 129 /* SyntaxKind.AsKeyword */) {
2159
- const firstAs = this.parseIdentifierName();
2156
+ const firstAs = this.parseIdentifierName(1 /* IdentifierUse.Name */);
2160
2157
  if (this.token() === 129 /* SyntaxKind.AsKeyword */) {
2161
- const secondAs = this.parseIdentifierName();
2158
+ const secondAs = this.parseIdentifierName(1 /* IdentifierUse.Name */);
2162
2159
  if (this.canParseModuleExportName()) {
2163
2160
  // { type as as something }
2164
2161
  isTypeOnly = true;
@@ -2229,7 +2226,7 @@ export class Parser extends ScannerErrorReporter {
2229
2226
  parseModuleExportName() {
2230
2227
  if (this.token() === 10 /* SyntaxKind.StringLiteral */)
2231
2228
  return this.parseLiteralExpression(false);
2232
- return this.parseIdentifierName();
2229
+ return this.parseIdentifierName(1 /* IdentifierUse.Name */);
2233
2230
  }
2234
2231
  tryParseImportAttributes() {
2235
2232
  if (this.token() === 117 /* SyntaxKind.WithKeyword */ ||
@@ -2261,7 +2258,7 @@ export class Parser extends ScannerErrorReporter {
2261
2258
  this.parseExpected(129 /* SyntaxKind.AsKeyword */);
2262
2259
  this.parseExpected(145 /* SyntaxKind.NamespaceKeyword */);
2263
2260
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
2264
- const name = this.parseIdentifier();
2261
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
2265
2262
  this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
2266
2263
  this.parseSemicolon();
2267
2264
  // Modifiers are kept so the grammar checker can report them.
@@ -2404,7 +2401,7 @@ export class Parser extends ScannerErrorReporter {
2404
2401
  }
2405
2402
  parseTypeParameterOfInferType() {
2406
2403
  const pos = this.nodePos();
2407
- const name = this.parseIdentifier();
2404
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
2408
2405
  const constraint = this.tryParseConstraintOfInferType();
2409
2406
  const result = new TypeParameterDeclaration(undefined, name, constraint, undefined, undefined);
2410
2407
  this.finishNode(result, pos);
@@ -2602,11 +2599,12 @@ export class Parser extends ScannerErrorReporter {
2602
2599
  parseEntityNameOfTypeReference() {
2603
2600
  return this.parseEntityName(true, 79 /* Diagnostics.Type_expected */);
2604
2601
  }
2605
- parseEntityName(allowReservedWords, diagnosticMessage) {
2602
+ /** An entity name; `use` is for its first identifier, the qualified names' right sides are names. */
2603
+ parseEntityName(allowReservedWords, diagnosticMessage, use = 1 /* IdentifierUse.Name */) {
2606
2604
  const pos = this.nodePos();
2607
2605
  let entity = allowReservedWords
2608
- ? this.parseIdentifierNameWithDiagnostic(diagnosticMessage)
2609
- : this.parseIdentifierWithDiagnostic(diagnosticMessage, undefined);
2606
+ ? this.parseIdentifierNameWithDiagnostic(diagnosticMessage, use)
2607
+ : this.parseIdentifierWithDiagnostic(diagnosticMessage, undefined, use);
2610
2608
  while (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
2611
2609
  // A JSDoc-style generic; the checker reports the gap between the name and the type arguments.
2612
2610
  if (this.token() === 29 /* SyntaxKind.LessThanToken */)
@@ -2631,20 +2629,20 @@ export class Parser extends ScannerErrorReporter {
2631
2629
  // after it). Report a missing identifier right after the dot rather than on the next token.
2632
2630
  if (this.isKeywordStartingNextLine()) {
2633
2631
  this.parseErrorAt(this.nodePos(), this.nodePos(), 1 /* Diagnostics.Identifier_expected */);
2634
- return this.createMissingIdentifier();
2632
+ return this.createMissingIdentifier(1 /* IdentifierUse.Name */);
2635
2633
  }
2636
2634
  if (this.token() === 80 /* SyntaxKind.PrivateIdentifier */) {
2637
2635
  this.parsePrivateIdentifier();
2638
2636
  this.parseErrorAt(this.nodePos(), this.nodePos(), 1 /* Diagnostics.Identifier_expected */);
2639
- return this.createMissingIdentifier();
2637
+ return this.createMissingIdentifier(1 /* IdentifierUse.Name */);
2640
2638
  }
2641
2639
  if (allowIdentifierNames) {
2642
2640
  if (allowUnicodeEscapeSequenceInIdentifierName)
2643
- return this.parseIdentifierName();
2644
- return this.parseIdentifierNameErrorOnUnicodeEscapeSequence();
2641
+ return this.parseIdentifierName(1 /* IdentifierUse.Name */);
2642
+ return this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */);
2645
2643
  }
2646
2644
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
2647
- const id = this.parseIdentifier();
2645
+ const id = this.parseIdentifier(1 /* IdentifierUse.Name */);
2648
2646
  this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
2649
2647
  return id;
2650
2648
  }
@@ -2654,14 +2652,25 @@ export class Parser extends ScannerErrorReporter {
2654
2652
  tokenIsIdentifierOrKeyword(this.token()) &&
2655
2653
  this.lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine));
2656
2654
  }
2657
- newIdentifier(text) {
2655
+ /**
2656
+ * A new identifier of the class `use` calls for. Callers create it after the identifier's token, so
2657
+ * for an element name the current token tells a shorthand property from an assignment or a method.
2658
+ */
2659
+ newIdentifier(text, use = 0 /* IdentifierUse.Reference */) {
2658
2660
  this.identifierCount++;
2659
2661
  if (text === 'await')
2660
2662
  this.statementHasAwaitIdentifier = true;
2661
- return new Identifier(text);
2663
+ if (use === 1 /* IdentifierUse.Name */ || (use === 2 /* IdentifierUse.ElementName */ && this.isElementNameEnd()))
2664
+ return new Identifier(text);
2665
+ return new ReferenceIdentifier(text);
2662
2666
  }
2663
- createMissingIdentifier() {
2664
- const result = this.newIdentifier('');
2667
+ /** Whether the current token ends an object literal element name that is not a shorthand property. */
2668
+ isElementNameEnd() {
2669
+ const token = this.token();
2670
+ return token === 58 /* SyntaxKind.ColonToken */ || token === 20 /* SyntaxKind.OpenParenToken */ || token === 29 /* SyntaxKind.LessThanToken */;
2671
+ }
2672
+ createMissingIdentifier(use = 0 /* IdentifierUse.Reference */) {
2673
+ const result = this.newIdentifier('', use);
2665
2674
  this.finishNode(result, this.nodePos());
2666
2675
  return result;
2667
2676
  }
@@ -2741,7 +2750,7 @@ export class Parser extends ScannerErrorReporter {
2741
2750
  const pos = this.nodePos();
2742
2751
  let name;
2743
2752
  if (tokenIsIdentifierOrKeyword(this.token()))
2744
- name = this.parseIdentifierName();
2753
+ name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
2745
2754
  else if (this.token() === 10 /* SyntaxKind.StringLiteral */)
2746
2755
  name = this.parseLiteralExpression(false);
2747
2756
  if (name !== undefined)
@@ -2774,7 +2783,7 @@ export class Parser extends ScannerErrorReporter {
2774
2783
  parseTypeQuery() {
2775
2784
  const pos = this.nodePos();
2776
2785
  this.parseExpected(113 /* SyntaxKind.TypeOfKeyword */);
2777
- const entityName = this.parseEntityName(true, undefined);
2786
+ const entityName = this.parseEntityName(true, undefined, 0 /* IdentifierUse.Reference */);
2778
2787
  // ASI: don't parse the next line's type arguments as part of an instantiation expression.
2779
2788
  const typeArguments = this.hasPrecedingLineBreak() ? undefined : this.parseTypeArguments();
2780
2789
  return this.finishNode(new TypeQueryNode(entityName, typeArguments), pos);
@@ -2810,7 +2819,7 @@ export class Parser extends ScannerErrorReporter {
2810
2819
  }
2811
2820
  parseMappedTypeParameter() {
2812
2821
  const pos = this.nodePos();
2813
- const name = this.parseIdentifierName();
2822
+ const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
2814
2823
  this.parseExpected(102 /* SyntaxKind.InKeyword */);
2815
2824
  const type = this.parseType();
2816
2825
  const result = new TypeParameterDeclaration(undefined, name, type, undefined, undefined);
@@ -2855,7 +2864,7 @@ export class Parser extends ScannerErrorReporter {
2855
2864
  parseTypeParameter() {
2856
2865
  const pos = this.nodePos();
2857
2866
  const modifiers = this.parseModifiersEx(false, true, false);
2858
- const name = this.parseIdentifier();
2867
+ const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
2859
2868
  let constraint;
2860
2869
  let expression;
2861
2870
  if (this.parseOptional(95 /* SyntaxKind.ExtendsKeyword */)) {
@@ -2909,7 +2918,7 @@ export class Parser extends ScannerErrorReporter {
2909
2918
  const modifiers = this.parseModifiersEx(true, false, false);
2910
2919
  this.contextFlags = saveContextFlags;
2911
2920
  if (this.token() === 109 /* SyntaxKind.ThisKeyword */) {
2912
- const result = new ParameterDeclaration(modifiers, undefined, this.createIdentifier(true), undefined, this.parseTypeAnnotation(), undefined);
2921
+ const result = new ParameterDeclaration(modifiers, undefined, this.createIdentifier(true, 1 /* IdentifierUse.Name */), undefined, this.parseTypeAnnotation(), undefined);
2913
2922
  if (modifiers !== undefined) {
2914
2923
  const first = modifiers.nodes[0];
2915
2924
  this.parseErrorAt(first.pos, first.end, 359 /* Diagnostics.Neither_decorators_nor_modifiers_may_be_applied_to_this_parameters */);
@@ -2970,7 +2979,7 @@ export class Parser extends ScannerErrorReporter {
2970
2979
  if (this.isIdentifier()) {
2971
2980
  const state = this.beginSpeculation();
2972
2981
  const pos = this.nodePos();
2973
- const id = this.parseIdentifier();
2982
+ const id = this.parseIdentifier(1 /* IdentifierUse.Name */);
2974
2983
  if (this.token() === 142 /* SyntaxKind.IsKeyword */ && !this.hasPrecedingLineBreak()) {
2975
2984
  this.endSpeculation(state);
2976
2985
  this.nextToken();
@@ -3000,13 +3009,13 @@ export class Parser extends ScannerErrorReporter {
3000
3009
  this.checkJSSyntax(result);
3001
3010
  return result;
3002
3011
  }
3003
- parsePropertyName() {
3012
+ parsePropertyName(use = 1 /* IdentifierUse.Name */) {
3004
3013
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
3005
- const prop = this.parsePropertyNameWorker(true);
3014
+ const prop = this.parsePropertyNameWorker(true, use);
3006
3015
  this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
3007
3016
  return prop;
3008
3017
  }
3009
- parsePropertyNameWorker(allowComputedPropertyNames) {
3018
+ parsePropertyNameWorker(allowComputedPropertyNames, use = 1 /* IdentifierUse.Name */) {
3010
3019
  const token = this.token();
3011
3020
  if (token === 10 /* SyntaxKind.StringLiteral */ || token === 8 /* SyntaxKind.NumericLiteral */ || token === 9 /* SyntaxKind.BigIntLiteral */)
3012
3021
  return this.parseLiteralExpression(true);
@@ -3014,7 +3023,7 @@ export class Parser extends ScannerErrorReporter {
3014
3023
  return this.parseComputedPropertyName();
3015
3024
  if (token === 80 /* SyntaxKind.PrivateIdentifier */)
3016
3025
  return this.parsePrivateIdentifier();
3017
- return this.parseIdentifierName();
3026
+ return this.parseIdentifierName(use);
3018
3027
  }
3019
3028
  parseComputedPropertyName() {
3020
3029
  const pos = this.nodePos();
@@ -3099,7 +3108,7 @@ export class Parser extends ScannerErrorReporter {
3099
3108
  const pos = this.nodePos();
3100
3109
  const jsdoc = this.jsdocScannerInfo();
3101
3110
  const dotDotDotToken = this.parseOptionalToken(25 /* SyntaxKind.DotDotDotToken */);
3102
- const name = this.parseIdentifierName();
3111
+ const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
3103
3112
  const questionToken = this.parseOptionalToken(57 /* SyntaxKind.QuestionToken */);
3104
3113
  this.parseExpected(58 /* SyntaxKind.ColonToken */);
3105
3114
  const type = this.parseTupleElementType();
@@ -3132,7 +3141,7 @@ export class Parser extends ScannerErrorReporter {
3132
3141
  parseAssertsTypePredicate() {
3133
3142
  const pos = this.nodePos();
3134
3143
  const assertsModifier = this.parseExpectedToken(130 /* SyntaxKind.AssertsKeyword */);
3135
- const parameterName = this.token() === 109 /* SyntaxKind.ThisKeyword */ ? this.parseThisTypeNode() : this.parseIdentifier();
3144
+ const parameterName = this.token() === 109 /* SyntaxKind.ThisKeyword */ ? this.parseThisTypeNode() : this.parseIdentifier(1 /* IdentifierUse.Name */);
3136
3145
  const type = this.parseOptional(142 /* SyntaxKind.IsKeyword */) ? this.parseType() : undefined;
3137
3146
  return this.finishNode(new TypePredicateNode(assertsModifier, parameterName, type), pos);
3138
3147
  }
@@ -4101,10 +4110,10 @@ export class Parser extends ScannerErrorReporter {
4101
4110
  parseJsxAttributeName() {
4102
4111
  const pos = this.nodePos();
4103
4112
  this.scanJsxIdentifier();
4104
- const attrName = this.parseIdentifierNameErrorOnUnicodeEscapeSequence();
4113
+ const attrName = this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */);
4105
4114
  if (this.parseOptional(58 /* SyntaxKind.ColonToken */)) {
4106
4115
  this.scanJsxIdentifier();
4107
- return this.finishNode(new JsxNamespacedName(attrName, this.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos);
4116
+ return this.finishNode(new JsxNamespacedName(attrName, this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */)), pos);
4108
4117
  }
4109
4118
  return attrName;
4110
4119
  }
@@ -4222,7 +4231,7 @@ export class Parser extends ScannerErrorReporter {
4222
4231
  // An `import.*` meta property, such as `import.meta`.
4223
4232
  this.nextToken();
4224
4233
  this.nextToken();
4225
- const name = this.parseIdentifierName();
4234
+ const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
4226
4235
  expression = this.finishNode(new MetaProperty(101 /* SyntaxKind.ImportKeyword */, name), pos);
4227
4236
  if (name.text === 'defer') {
4228
4237
  if (this.token() === 20 /* SyntaxKind.OpenParenToken */ || this.token() === 29 /* SyntaxKind.LessThanToken */)
@@ -4606,7 +4615,7 @@ export class Parser extends ScannerErrorReporter {
4606
4615
  return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 179 /* SyntaxKind.SetAccessor */, 0 /* ParseFlags.None */);
4607
4616
  const asteriskToken = this.parseOptionalToken(41 /* SyntaxKind.AsteriskToken */);
4608
4617
  const tokenIsIdentifier = this.isIdentifier();
4609
- const name = this.parsePropertyName();
4618
+ const name = this.parsePropertyName(2 /* IdentifierUse.ElementName */);
4610
4619
  // The grammar checker reports optional property assignments, definite assignment assertions,
4611
4620
  // decorators and modifiers.
4612
4621
  let postfixToken = this.parseOptionalToken(57 /* SyntaxKind.QuestionToken */);
@@ -4683,7 +4692,7 @@ export class Parser extends ScannerErrorReporter {
4683
4692
  const pos = this.nodePos();
4684
4693
  this.parseExpected(104 /* SyntaxKind.NewKeyword */);
4685
4694
  if (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
4686
- const name = this.parseIdentifierName();
4695
+ const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
4687
4696
  return this.finishNode(new MetaProperty(104 /* SyntaxKind.NewKeyword */, name), pos);
4688
4697
  }
4689
4698
  const expressionPos = this.nodePos();
@@ -4739,36 +4748,36 @@ export class Parser extends ScannerErrorReporter {
4739
4748
  return this.finishNode(result, pos);
4740
4749
  }
4741
4750
  // Identifiers
4742
- parseIdentifierNameErrorOnUnicodeEscapeSequence() {
4751
+ parseIdentifierNameErrorOnUnicodeEscapeSequence(use = 0 /* IdentifierUse.Reference */) {
4743
4752
  if (this.scanner.hasUnicodeEscape() || this.scanner.hasExtendedUnicodeEscape())
4744
4753
  this.parseErrorAtCurrentToken(1824 /* Diagnostics.Unicode_escape_sequence_cannot_appear_here */);
4745
- return this.createIdentifier(tokenIsIdentifierOrKeyword(this.token()));
4754
+ return this.createIdentifier(tokenIsIdentifierOrKeyword(this.token()), use);
4746
4755
  }
4747
4756
  parseBindingIdentifier() {
4748
4757
  return this.parseBindingIdentifierWithDiagnostic(undefined);
4749
4758
  }
4750
4759
  parseBindingIdentifierWithDiagnostic(privateIdentifierDiagnosticMessage) {
4751
4760
  const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
4752
- const id = this.createIdentifierWithDiagnostic(this.isBindingIdentifier(), undefined, privateIdentifierDiagnosticMessage);
4761
+ const id = this.createIdentifierWithDiagnostic(this.isBindingIdentifier(), undefined, privateIdentifierDiagnosticMessage, 1 /* IdentifierUse.Name */);
4753
4762
  this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
4754
4763
  return id;
4755
4764
  }
4756
- parseIdentifierName() {
4757
- return this.parseIdentifierNameWithDiagnostic(undefined);
4765
+ parseIdentifierName(use = 0 /* IdentifierUse.Reference */) {
4766
+ return this.parseIdentifierNameWithDiagnostic(undefined, use);
4758
4767
  }
4759
- parseIdentifierNameWithDiagnostic(diagnosticMessage) {
4760
- return this.createIdentifierWithDiagnostic(tokenIsIdentifierOrKeyword(this.token()), diagnosticMessage, undefined);
4768
+ parseIdentifierNameWithDiagnostic(diagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
4769
+ return this.createIdentifierWithDiagnostic(tokenIsIdentifierOrKeyword(this.token()), diagnosticMessage, undefined, use);
4761
4770
  }
4762
- parseIdentifier() {
4763
- return this.parseIdentifierWithDiagnostic(undefined, undefined);
4771
+ parseIdentifier(use = 0 /* IdentifierUse.Reference */) {
4772
+ return this.parseIdentifierWithDiagnostic(undefined, undefined, use);
4764
4773
  }
4765
- parseIdentifierWithDiagnostic(diagnosticMessage, privateIdentifierDiagnosticMessage) {
4766
- return this.createIdentifierWithDiagnostic(this.isIdentifier(), diagnosticMessage, privateIdentifierDiagnosticMessage);
4774
+ parseIdentifierWithDiagnostic(diagnosticMessage, privateIdentifierDiagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
4775
+ return this.createIdentifierWithDiagnostic(this.isIdentifier(), diagnosticMessage, privateIdentifierDiagnosticMessage, use);
4767
4776
  }
4768
- createIdentifier(isIdentifier) {
4769
- return this.createIdentifierWithDiagnostic(isIdentifier, undefined, undefined);
4777
+ createIdentifier(isIdentifier, use = 0 /* IdentifierUse.Reference */) {
4778
+ return this.createIdentifierWithDiagnostic(isIdentifier, undefined, undefined, use);
4770
4779
  }
4771
- createIdentifierWithDiagnostic(isIdentifier, diagnosticMessage, privateIdentifierDiagnosticMessage) {
4780
+ createIdentifierWithDiagnostic(isIdentifier, diagnosticMessage, privateIdentifierDiagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
4772
4781
  if (isIdentifier) {
4773
4782
  const pos = this.scanner.hasPrecedingJSDocLeadingAsterisks() ? this.scanner.getTokenStart() : this.nodePos();
4774
4783
  const text = this.scanner.getIdentifierValue();
@@ -4776,7 +4785,7 @@ export class Parser extends ScannerErrorReporter {
4776
4785
  this.nextTokenWithoutCheck();
4777
4786
  if (record)
4778
4787
  this.identifierTexts.push(text);
4779
- const result = this.newIdentifier(text);
4788
+ const result = this.newIdentifier(text, use);
4780
4789
  this.finishNode(result, pos);
4781
4790
  return result;
4782
4791
  }
@@ -4784,7 +4793,7 @@ export class Parser extends ScannerErrorReporter {
4784
4793
  this.parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage !== undefined
4785
4794
  ? privateIdentifierDiagnosticMessage
4786
4795
  : 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
4787
- return this.createIdentifier(true);
4796
+ return this.createIdentifier(true, use);
4788
4797
  }
4789
4798
  // Report at the current position only at the end of the file: elsewhere the error would land
4790
4799
  // incorrectly on embedded script tags.
@@ -4809,7 +4818,7 @@ export class Parser extends ScannerErrorReporter {
4809
4818
  else {
4810
4819
  this.parseErrorAtCurrentToken(1 /* Diagnostics.Identifier_expected */);
4811
4820
  }
4812
- return this.createMissingIdentifier();
4821
+ return this.createMissingIdentifier(use);
4813
4822
  }
4814
4823
  internIdentifier(text) {
4815
4824
  this.identifierTexts.push(text);
@@ -5698,6 +5707,16 @@ export function forgetLazyJSDocFile() {
5698
5707
  lazyJSDocFile = undefined;
5699
5708
  }
5700
5709
  const viableKeywordSuggestions = getViableKeywordSuggestions();
5710
+ // A parser whose JSDoc parser released parsers keep (`Parser.release`), created on first use.
5711
+ let releasedParserValue;
5712
+ function releasedParser() {
5713
+ let parser = releasedParserValue;
5714
+ if (parser === undefined) {
5715
+ parser = new Parser('/', '/', '', 3 /* ScriptKind.TS */, new ExternalModuleIndicatorOptions(false, false));
5716
+ releasedParserValue = parser;
5717
+ }
5718
+ return parser;
5719
+ }
5701
5720
  function getSpaceSuggestion(expressionText) {
5702
5721
  for (const keyword of viableKeywordSuggestions)
5703
5722
  if (expressionText.length > keyword.length + 2 && expressionText.startsWith(keyword))
@@ -1,4 +1,5 @@
1
1
  import { FunctionDeclaration, Identifier, type Node, NodeList, SourceFile } from '../ast.js';
2
+ import { ClusteredLinkTable } from '../link-tables.js';
2
3
  import { SyntaxKind } from '../syntax-kind.js';
3
4
  import { EmitFlags } from './emit-flags.js';
4
5
  import { AutoGenerateInfo } from './auto-generate.js';
@@ -54,8 +55,10 @@ export { AutoGenerateInfo, newAutoGenerateId } from './auto-generate.js';
54
55
  export declare class EmitContext extends NodeFactory {
55
56
  readonly autoGenerate: Map<Node, AutoGenerateInfo>;
56
57
  readonly textSource: Map<Node, Node>;
57
- readonly original: Map<Node, Node>;
58
- readonly emitNodes: Map<Node, EmitNode>;
58
+ /** The node each node was made from, by node id. */
59
+ readonly original: ClusteredLinkTable<Node>;
60
+ /** The emit data of nodes, by node id. */
61
+ readonly emitNodes: ClusteredLinkTable<EmitNode>;
59
62
  private lastLookup;
60
63
  private lastEmitNode;
61
64
  readonly assignedNames: Map<Node, Node>;
@@ -1,6 +1,7 @@
1
1
  // Side tables that transforms fill in and the printer reads: original nodes, emit flags,
2
2
  // comment and source map ranges, synthesized comments, generated names and emit helpers.
3
3
  import { ExpressionStatement, FunctionDeclaration, Identifier, NodeList, PrivateIdentifier, StringLiteral, VariableDeclaration, VariableStatement, } from '../ast.js';
4
+ import { ClusteredLinkTable } from '../link-tables.js';
4
5
  import { NodeFactory } from './factory.js';
5
6
  import { isParseTreeNode, isPrologueDirective } from './utilities.js';
6
7
  export { EmitHelper, compareEmitHelpers, noPriority } from './helpers.js';
@@ -90,7 +91,9 @@ export { AutoGenerateInfo, newAutoGenerateId } from './auto-generate.js';
90
91
  export class EmitContext extends NodeFactory {
91
92
  autoGenerate;
92
93
  textSource;
94
+ /** The node each node was made from, by node id. */
93
95
  original;
96
+ /** The emit data of nodes, by node id. */
94
97
  emitNodes;
95
98
  lastLookup;
96
99
  lastEmitNode;
@@ -104,8 +107,8 @@ export class EmitContext extends NodeFactory {
104
107
  super();
105
108
  this.autoGenerate = new Map();
106
109
  this.textSource = new Map();
107
- this.original = new Map();
108
- this.emitNodes = new Map();
110
+ this.original = new ClusteredLinkTable();
111
+ this.emitNodes = new ClusteredLinkTable();
109
112
  this.lastLookup = undefined;
110
113
  this.lastEmitNode = undefined;
111
114
  this.assignedNames = new Map();
@@ -138,7 +141,7 @@ export class EmitContext extends NodeFactory {
138
141
  let emitNode = this.lookup(node);
139
142
  if (emitNode === undefined) {
140
143
  emitNode = new EmitNode();
141
- this.emitNodes.set(node, emitNode);
144
+ this.emitNodes.set(node.id, emitNode);
142
145
  this.lastLookup = node;
143
146
  this.lastEmitNode = emitNode;
144
147
  }
@@ -148,7 +151,7 @@ export class EmitContext extends NodeFactory {
148
151
  lookup(node) {
149
152
  if (node === this.lastLookup)
150
153
  return this.lastEmitNode;
151
- const emitNode = this.emitNodes.get(node);
154
+ const emitNode = this.emitNodes.get(node.id);
152
155
  this.lastLookup = node;
153
156
  this.lastEmitNode = emitNode;
154
157
  return emitNode;
@@ -158,30 +161,33 @@ export class EmitContext extends NodeFactory {
158
161
  this.setOriginalEx(node, original, false);
159
162
  }
160
163
  setOriginalEx(node, original, allowOverwrite) {
161
- const existing = this.original.get(node);
164
+ const existing = this.original.get(node.id);
162
165
  if (existing === undefined) {
163
- this.original.set(node, original);
166
+ this.original.set(node.id, original);
164
167
  const emitNode = this.lookup(original);
165
168
  if (emitNode !== undefined)
166
169
  this.emitNode(node).copyFrom(emitNode);
167
170
  }
168
171
  else if (allowOverwrite)
169
- this.original.set(node, original);
172
+ this.original.set(node.id, original);
170
173
  else if (existing !== original)
171
174
  throw new Error('Original node already set.');
172
175
  }
173
176
  unsetOriginal(node) {
174
- return this.original.delete(node);
177
+ if (this.original.get(node.id) === undefined)
178
+ return false;
179
+ this.original.set(node.id, undefined);
180
+ return true;
175
181
  }
176
182
  getOriginal(node) {
177
- return this.original.get(node);
183
+ return this.original.get(node.id);
178
184
  }
179
185
  /** The node at the end of the chain of original nodes. */
180
186
  mostOriginal(node) {
181
- let original = this.original.get(node);
187
+ let original = this.original.get(node.id);
182
188
  while (original !== undefined) {
183
189
  node = original;
184
- original = this.original.get(node);
190
+ original = this.original.get(node.id);
185
191
  }
186
192
  return node;
187
193
  }
@@ -204,7 +210,7 @@ export class EmitContext extends NodeFactory {
204
210
  return name;
205
211
  let node = info.node;
206
212
  const id = info.id;
207
- let original = this.original.get(node);
213
+ let original = this.original.get(node.id);
208
214
  while (original !== undefined) {
209
215
  node = original;
210
216
  if (node instanceof Identifier || node instanceof PrivateIdentifier) {
@@ -217,7 +223,7 @@ export class EmitContext extends NodeFactory {
217
223
  continue;
218
224
  }
219
225
  }
220
- original = this.original.get(node);
226
+ original = this.original.get(node.id);
221
227
  }
222
228
  return node;
223
229
  }
@@ -357,6 +357,9 @@ class Directives {
357
357
  byLine = new Map();
358
358
  constructor(file) {
359
359
  this.file = file;
360
+ // Most files have no directives, and need no line starts.
361
+ if (file.commentDirectives.length === 0)
362
+ return;
360
363
  const lineStarts = file.diagnosticFile().getLineStarts();
361
364
  for (const directive of file.commentDirectives) {
362
365
  const line = computeLineOfPosition(lineStarts, directive.pos);