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
@@ -62,13 +62,21 @@ export class Program {
62
62
  this.programDiagnosticsList.push(diagnostic);
63
63
  for (const path of previous.emitBlockingPaths)
64
64
  this.emitBlockingPaths.add(path);
65
- this.symlinks = previous.symlinks;
65
+ // The files and include reasons it takes from a program shared with checker threads are immutable, and
66
+ // so is that program's symlink cache: this one computes its own then (`getSymlinkCache`).
67
+ this.shared = previous.shared;
68
+ if (!previous.shared)
69
+ this.symlinks = previous.symlinks;
70
+ // The same files are emitted, so the common source directory is the same. Its diagnostics are those
71
+ // `previous` was created with (`IncludeProcessor.copy`).
72
+ this.commonSourceDirectoryValue = previous.commonSourceDirectoryValue;
66
73
  }
67
74
  else {
68
75
  this.processed = (loader ?? new FileLoader(host, commandLine)).load();
69
76
  this.includeProcessor = this.processed.includeProcessor;
70
77
  this.verifyCompilerOptions();
71
78
  }
79
+ this.includeProcessor.noteProgramCreated();
72
80
  }
73
81
  /**
74
82
  * The program with the file at `path` read again from `host` and everything else taken from this program,
@@ -1,12 +1,12 @@
1
1
  import { ModifierFlags, type Node } from './ast.js';
2
2
  import { Diagnostic, type DiagnosticMessage } from './diagnostics.js';
3
- import { type Symbol } from './symbol.js';
4
3
  import { type Checker } from './checker.js';
5
4
  import { type IndexInfo, type MappedType, type Signature, SignatureKind, Ternary, type Type, type UnionType, VarianceFlags } from './checker-types.js';
6
5
  import { typeListKey } from './checker-type-factory.js';
7
6
  import { findApplicableIndexInfo } from './checker-members.js';
8
7
  import { getMergedSymbol } from './checker-symbols.js';
9
8
  import { getPropertyNameFromType } from './checker-utilities.js';
9
+ import { type Symbol } from './symbol.js';
10
10
  export declare const enum RelationComparisonResult {
11
11
  None = 0,
12
12
  Succeeded = 1,
@@ -5,7 +5,6 @@ import { getExpression, getName, getNodeId, getText, } from './ast.js';
5
5
  import { getSymbolNameForPrivateIdentifier } from './binder.js';
6
6
  import { getCombinedModifierFlags } from './binder-utilities.js';
7
7
  import { Diagnostic, messageElidedInCompatibilityPyramid } from './diagnostics.js';
8
- import { getSymbolId } from './symbol.js';
9
8
  import { isContextSensitive } from './checker-functions.js';
10
9
  import { createDiagnosticForNode } from './checker.js';
11
10
  import { cachedTypeKey, emptyTypes, newTypeMapper, SimpleTypeMapper, } from './checker-types.js';
@@ -23,6 +22,7 @@ import { getConstraintOfDistributiveConditionalType, getDefaultConstraintOfCondi
23
22
  import { getCanonicalSignature, getErasedSignature, getMinArgumentCount, getNonArrayRestType, getNonCircularReturnTypeOfSignature, getParameterCount, getParameterNameAtPosition, getRestOrAnyTypeAtPosition, getReturnTypeOfSignature, getSingleCallSignature, getThisTypeOfSignature, getTypeAtPosition, getTypePredicateOfSignature, hasEffectiveRestParameter, instantiateSignatureInContextOf, isTopSignature, tryGetTypeAtPosition, } from './checker-signatures.js';
24
23
  import { getNonNullableType, getTypeFacts } from './checker-flow.js';
25
24
  import { getPropertyNameFromType, isLateBoundName, isNumericLiteralName, maybeTypeOfKind, } from './checker-utilities.js';
25
+ import { declarationCount, getDeclarations, getSymbolId } from './symbol.js';
26
26
  /**
27
27
  * Cached results of one relation by numeric relation key (see getRelationKey): an open-addressing
28
28
  * table of keys and one-byte results. Keys are never 0 (packed keys are positive, interned ones
@@ -430,8 +430,8 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
430
430
  c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
431
431
  return false;
432
432
  }
433
- const sourceDecl = sourceProperty.declarations.find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
434
- const targetDecl = targetProperty.declarations.find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
433
+ const sourceDecl = getDeclarations(sourceProperty).find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
434
+ const targetDecl = getDeclarations(targetProperty).find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
435
435
  if (sourceDecl === undefined || targetDecl === undefined)
436
436
  continue;
437
437
  computeEnumMemberValues(c, sourceDecl.parent);
@@ -933,8 +933,8 @@ export class Relater extends TypeComparer {
933
933
  ]);
934
934
  return true;
935
935
  }
936
- const objectLiteralDeclaration = source.symbol !== undefined && source.symbol.declarations.length !== 0
937
- ? source.symbol.declarations[0]
936
+ const objectLiteralDeclaration = source.symbol !== undefined && declarationCount(source.symbol) !== 0
937
+ ? source.symbol.declaration
938
938
  : undefined;
939
939
  const valueDeclaration = prop.valueDeclaration;
940
940
  let suggestion = undefined;
@@ -2202,8 +2202,8 @@ export class Relater extends TypeComparer {
2202
2202
  names[0],
2203
2203
  names[1],
2204
2204
  ]);
2205
- if (unmatchedProperty.declarations.length !== 0)
2206
- this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declarations[0], 860 /* Diagnostics.X_0_is_declared_here */, [propName]));
2205
+ if (declarationCount(unmatchedProperty) !== 0)
2206
+ this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declaration, 860 /* Diagnostics.X_0_is_declared_here */, [propName]));
2207
2207
  }
2208
2208
  else if (this.tryElaborateArrayLikeErrors(source, target, false)) {
2209
2209
  const names = getTypeNamesForErrorDisplay(c, source, target);
@@ -2547,12 +2547,12 @@ export class Relater extends TypeComparer {
2547
2547
  this.reportRelationError(headMessage, source, target);
2548
2548
  if ((source.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 &&
2549
2549
  source.symbol !== undefined &&
2550
- source.symbol.declarations.length !== 0 &&
2550
+ declarationCount(source.symbol) !== 0 &&
2551
2551
  getConstraintOfType(c, source) === undefined) {
2552
2552
  const syntheticParam = cloneTypeParameter(c, source);
2553
2553
  syntheticParam.constraint = instantiateType(c, target, new SimpleTypeMapper(source, syntheticParam));
2554
2554
  if (hasNonCircularBaseConstraint(c, syntheticParam)) {
2555
- this.relatedInfo.push(createDiagnosticForNode(source.symbol.declarations[0], 473 /* Diagnostics.This_type_parameter_might_need_an_extends_0_constraint */, [typeToString(c, target)]));
2555
+ this.relatedInfo.push(createDiagnosticForNode(source.symbol.declaration, 473 /* Diagnostics.This_type_parameter_might_need_an_extends_0_constraint */, [typeToString(c, target)]));
2556
2556
  }
2557
2557
  }
2558
2558
  }
@@ -3476,7 +3476,7 @@ import { getTypeAliasInstantiation } from './checker-type-nodes.js';
3476
3476
  export function getTypeParameterModifiers(tp) {
3477
3477
  let flags = 0;
3478
3478
  if (tp.symbol !== undefined)
3479
- for (const d of tp.symbol.declarations)
3479
+ for (const d of getDeclarations(tp.symbol))
3480
3480
  flags |= getCombinedModifierFlags(d);
3481
3481
  return flags & (8192 /* ModifierFlags.In */ | 16384 /* ModifierFlags.Out */ | 4096 /* ModifierFlags.Const */);
3482
3482
  }
@@ -1,7 +1,7 @@
1
1
  import { type Node, type SourceFile } from './ast.js';
2
2
  import { type Checker } from './checker.js';
3
- import { type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
4
3
  import { SymbolAccessibilityResult } from './transformers/declarations-resolver.js';
4
+ import { type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
5
5
  export declare function isTypeSymbolAccessible(c: Checker, symbol: Symbol, enclosingDeclaration: Node | undefined): boolean;
6
6
  export declare function isValueSymbolAccessible(c: Checker, symbol: Symbol, enclosingDeclaration: Node | undefined): boolean;
7
7
  export declare function isSymbolAccessibleByFlags(c: Checker, symbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags): boolean;
@@ -4,7 +4,7 @@
4
4
  import { BinaryExpression, BindingElement, BindingPattern, ClassExpression, ExportDeclaration, ImportEqualsDeclaration, VariableDeclaration, getExpression, getInitializer, getLocals, getName, getNodeId, getText, getType, } from './ast.js';
5
5
  import { isAmbientModule, isInJSFile } from './ast-utilities.js';
6
6
  import { getCombinedModifierFlags, getRootDeclaration, getSourceFileOfNode, hasSyntacticModifier, isAccessExpression, isEntityNameExpression, isExportsIdentifier, isExternalModule, isExternalOrCommonJSModule, isGlobalSourceFile, isModuleExportsAccessExpression, } from './binder-utilities.js';
7
- import { SymbolAccessibilityCaches } from './checker.js';
7
+ import { ExternalModuleContainerIndex, SymbolAccessibilityCaches, fileIndexScale } from './checker.js';
8
8
  import { getEffectiveDeclarationFlags } from './checker-declarations.js';
9
9
  import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
10
10
  import { checkExpressionCached } from './checker-expressions.js';
@@ -12,11 +12,11 @@ import { resolveExternalModuleName, resolveExternalModuleSymbol } from './checke
12
12
  import { getExportsOfSymbol, getMergedSymbol, getParentOfSymbol, getSymbolFlags, getSymbolOfDeclaration, resolveAlias, resolveSymbol, } from './checker-symbols.js';
13
13
  import { getTypeOfSymbol } from './checker-symbol-types.js';
14
14
  import { compareSymbols } from './checker-type-factory.js';
15
- import { getSymbolId } from './symbol.js';
16
15
  import { SymbolAccessibilityResult, accessible } from './transformers/declarations-resolver.js';
17
16
  import { getAnyImportSyntax, getDeclarationContainer, isExternalModuleAugmentation, isLateVisibilityPaintedStatement, } from './transformers/declarations-syntactic.js';
18
17
  import { isImplicitlyExportedJSDocDeclaration } from './binder-utilities.js';
19
18
  import { symbolToString } from './type-printer.js';
19
+ import { declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
20
20
  const tableKindScale = 2 ** 44;
21
21
  function tableId(kind, id) {
22
22
  return kind * tableKindScale + id;
@@ -61,7 +61,7 @@ function isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, meaning, shou
61
61
  return result;
62
62
  // A symbol not exported from its module, or from another module without an alias, can't be named.
63
63
  let symbolExternalModule = undefined;
64
- for (const d of symbol.declarations) {
64
+ for (const d of getDeclarations(symbol)) {
65
65
  symbolExternalModule = getExternalModuleContainer(c, d);
66
66
  if (symbolExternalModule !== undefined)
67
67
  break;
@@ -109,7 +109,7 @@ function isAnySymbolAccessible(c, symbols, enclosingDeclaration, initialSymbol,
109
109
  return undefined;
110
110
  }
111
111
  export function hasNonGlobalAugmentationExternalModuleDeclaration(symbol) {
112
- for (const d of symbol.declarations)
112
+ for (const d of getDeclarations(symbol))
113
113
  if (hasNonGlobalAugmentationExternalModuleSymbol(d))
114
114
  return true;
115
115
  return false;
@@ -128,18 +128,22 @@ function isModuleWithStringLiteralName(node) {
128
128
  export function getQualifiedLeftMeaning(rightMeaning) {
129
129
  return rightMeaning === 111551 /* SymbolFlags.Value */ ? 111551 /* SymbolFlags.Value */ : 1920 /* SymbolFlags.Namespace */;
130
130
  }
131
+ /** The merged symbol `symbol` resolves to through aliases. */
132
+ function getResolvedTarget(c, symbol) {
133
+ const resolved = resolveSymbol(c, getMergedSymbol(c, symbol));
134
+ return resolved !== undefined ? getMergedSymbol(c, resolved) : undefined;
135
+ }
131
136
  /** `s1` if both symbols resolve to the same symbol, else undefined. */
132
137
  export function getSymbolIfSameReference(c, s1, s2) {
133
- const r1 = resolveSymbol(c, getMergedSymbol(c, s1));
134
- const r2 = resolveSymbol(c, getMergedSymbol(c, s2));
135
- if (r1 !== undefined && r2 !== undefined && getMergedSymbol(c, r1) === getMergedSymbol(c, r2))
138
+ const r1 = getResolvedTarget(c, s1);
139
+ if (r1 !== undefined && r1 === getResolvedTarget(c, s2))
136
140
  return s1;
137
141
  return undefined;
138
142
  }
139
143
  // ---- Containers
140
144
  function getWithAlternativeContainers(c, container, symbol, enclosingDeclaration, meaning) {
141
145
  const additionalContainers = [];
142
- for (const d of container.declarations) {
146
+ for (const d of getDeclarations(container)) {
143
147
  const fileSymbol = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, container);
144
148
  if (fileSymbol !== undefined)
145
149
  additionalContainers.push(fileSymbol);
@@ -225,24 +229,117 @@ function getAlternativeContainingModules(c, symbol, enclosingDeclaration) {
225
229
  const cached = cache.containers.get(symbolId);
226
230
  if (cached !== undefined)
227
231
  return cached;
228
- // Search every module; expensive, but independent of the location.
232
+ // Search every module; independent of the location.
233
+ const containers = getExternalModuleContainers(c, symbol);
234
+ cache.containers.set(symbolId, containers);
235
+ return containers;
236
+ }
237
+ /** The modules that export `symbol`, and its parent module, in program order. */
238
+ function getExternalModuleContainers(c, symbol) {
239
+ const cache = caches(c);
240
+ if (cache.externalModuleContainers === undefined)
241
+ buildExternalModuleContainerIndex(c);
242
+ const index = cache.externalModuleContainers;
243
+ // Re-entered from an alias resolved while building the index, or too many files to index.
244
+ if (!index.complete)
245
+ return scanExternalModuleContainers(c, symbol);
246
+ // The parent module contains the symbol even when the symbol is absent from its exports.
247
+ const parent = getParentOfSymbol(c, symbol);
248
+ let parentIndex = externalModuleFileIndex(c, parent);
249
+ const result = [];
250
+ const target = getResolvedTarget(c, symbol);
251
+ if (target !== undefined) {
252
+ const keys = index.keys;
253
+ const first = getSymbolId(target) * fileIndexScale;
254
+ let low = 0;
255
+ let high = keys.length;
256
+ while (low < high) {
257
+ const mid = (low + high) >>> 1;
258
+ if (keys[mid] < first)
259
+ low = mid + 1;
260
+ else
261
+ high = mid;
262
+ }
263
+ for (let i = low; i < keys.length && keys[i] < first + fileIndexScale; i++) {
264
+ const fileIndex = keys[i] - first;
265
+ if (parentIndex >= 0 && parentIndex <= fileIndex) {
266
+ if (parentIndex < fileIndex)
267
+ result.push(parent);
268
+ parentIndex = -1;
269
+ }
270
+ // `as`: scriptc passes an element of a subclass array only as that class.
271
+ result.push(getSymbolOfDeclaration(c, c.files[fileIndex]));
272
+ }
273
+ }
274
+ if (parentIndex >= 0)
275
+ result.push(parent);
276
+ return result;
277
+ }
278
+ /** The position in `Checker.files` of the external module `symbol`, or -1 for any other symbol. */
279
+ function externalModuleFileIndex(c, symbol) {
280
+ if (symbol === undefined || (symbol.flags & 512 /* SymbolFlags.ValueModule */) === 0)
281
+ return -1;
282
+ for (const declaration of getDeclarations(symbol)) {
283
+ if (declaration.kind !== 307 /* SyntaxKind.SourceFile */)
284
+ continue;
285
+ const file = declaration;
286
+ if (isExternalModule(file) && getSymbolOfDeclaration(c, declaration) === symbol)
287
+ return c.fileIndex.get(file) ?? -1;
288
+ }
289
+ return -1;
290
+ }
291
+ function buildExternalModuleContainerIndex(c) {
292
+ const index = new ExternalModuleContainerIndex();
293
+ caches(c).externalModuleContainers = index;
294
+ if (c.files.length > fileIndexScale)
295
+ return;
296
+ const keys = [];
297
+ for (let fileIndex = 0; fileIndex < c.files.length; fileIndex++) {
298
+ const file = c.files[fileIndex];
299
+ if (!isExternalModule(file))
300
+ continue;
301
+ // `as`: scriptc passes an element of a subclass array only as that class.
302
+ const container = getSymbolOfDeclaration(c, file);
303
+ if (container === undefined)
304
+ continue;
305
+ for (const exported of getExportsOfSymbol(c, container).values()) {
306
+ const target = getResolvedTarget(c, exported);
307
+ if (target !== undefined)
308
+ keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
309
+ }
310
+ const exportEquals = container.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
311
+ const target = exportEquals !== undefined ? getResolvedTarget(c, exportEquals) : undefined;
312
+ if (target !== undefined)
313
+ keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
314
+ }
315
+ keys.sort((a, b) => a - b);
316
+ // A module that exports a symbol under several names gives it one key.
317
+ let kept = 0;
318
+ for (let i = 0; i < keys.length; i++)
319
+ if (kept === 0 || keys[i] !== keys[kept - 1])
320
+ keys[kept++] = keys[i];
321
+ // An exact-size copy: each checker keeps its own index for the rest of the compilation.
322
+ index.keys = keys.slice(0, kept);
323
+ index.complete = true;
324
+ }
325
+ /** The modules that export `symbol`, found by checking every module. */
326
+ function scanExternalModuleContainers(c, symbol) {
327
+ const containers = [];
229
328
  for (const file of c.host.getSourceFiles()) {
230
329
  if (!isExternalModule(file))
231
330
  continue;
232
331
  // `as`: scriptc passes a for-of element of a subclass array only as that class.
233
- const fileSymbol = getSymbolOfDeclaration(c, file);
234
- if (fileSymbol === undefined || getAliasForSymbolInContainer(c, fileSymbol, symbol) === undefined)
235
- continue;
236
- results.push(fileSymbol);
332
+ const container = getSymbolOfDeclaration(c, file);
333
+ if (container !== undefined && getAliasForSymbolInContainer(c, container, symbol) !== undefined)
334
+ containers.push(container);
237
335
  }
238
- cache.containers.set(symbolId, results);
239
- return results;
336
+ return containers;
240
337
  }
241
338
  /** The variable `var a = { x: 1 }` declares, for the anonymous `__object` symbol of its literal. */
242
339
  function getVariableDeclarationOfObjectLiteral(c, symbol, meaning) {
243
- if ((meaning & 111551 /* SymbolFlags.Value */) === 0 || symbol.declarations.length === 0)
340
+ if ((meaning & 111551 /* SymbolFlags.Value */) === 0 || declarationCount(symbol) === 0)
244
341
  return undefined;
245
- const firstDecl = symbol.declarations[0];
342
+ const firstDecl = symbol.declaration;
246
343
  const parent = firstDecl.parent;
247
344
  if (parent === undefined || !(parent instanceof VariableDeclaration))
248
345
  return undefined;
@@ -282,7 +379,7 @@ export function getContainersOfSymbol(c, symbol, enclosingDeclaration, meaning)
282
379
  if (s !== undefined && candidates.indexOf(s) < 0)
283
380
  candidates.push(s);
284
381
  };
285
- for (const d of symbol.declarations) {
382
+ for (const d of getDeclarations(symbol)) {
286
383
  const parent = d.parent;
287
384
  if (!isAmbientModule(d) && parent !== undefined) {
288
385
  // A direct child of a module.
@@ -448,7 +545,7 @@ class ChainSearch {
448
545
  (this.useOnlyExternalAliasing && !hasExternalModuleImportEqualsDeclaration(fromTable)) ||
449
546
  (isLocalNameLookup && hasNamespaceReexportDeclaration(fromTable)) ||
450
547
  // Exports are in scope, but export specifiers aren't.
451
- (!ignoreQualification && fromTable.declarations.some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */)))
548
+ (!ignoreQualification && getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */)))
452
549
  continue;
453
550
  const resolved = resolveAlias(c, fromTable);
454
551
  const candidate = this.candidateListForSymbol(fromTable, resolved, ignoreQualification);
@@ -542,10 +639,10 @@ function compareSymbolChains(c, a, b) {
542
639
  return 0;
543
640
  }
544
641
  function isUMDExportSymbol(symbol) {
545
- return symbol.declarations.length > 0 && symbol.declarations[0].kind === 271 /* SyntaxKind.NamespaceExportDeclaration */;
642
+ return declarationCount(symbol) > 0 && symbol.declaration.kind === 271 /* SyntaxKind.NamespaceExportDeclaration */;
546
643
  }
547
644
  function hasNamespaceReexportDeclaration(symbol) {
548
- for (const d of symbol.declarations)
645
+ for (const d of getDeclarations(symbol))
549
646
  if (isNamespaceReexportDeclaration(d))
550
647
  return true;
551
648
  return false;
@@ -556,7 +653,7 @@ function isNamespaceReexportDeclaration(node) {
556
653
  node.parent.moduleSpecifier !== undefined);
557
654
  }
558
655
  function hasExternalModuleImportEqualsDeclaration(symbol) {
559
- for (const d of symbol.declarations)
656
+ for (const d of getDeclarations(symbol))
560
657
  if (isExternalModuleImportEqualsDeclaration(d))
561
658
  return true;
562
659
  return false;
@@ -576,7 +673,7 @@ export function needsQualification(c, symbol, enclosingDeclaration, meaning) {
576
673
  return true;
577
674
  // Qualify if the symbol of this name has the meaning sought.
578
675
  const shouldResolveAlias = (fromTable.flags & 2097152 /* SymbolFlags.Alias */) !== 0 &&
579
- !fromTable.declarations.some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */);
676
+ !getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */);
580
677
  if (shouldResolveAlias)
581
678
  fromTable = resolveAlias(c, fromTable);
582
679
  const flags = shouldResolveAlias ? getSymbolFlags(c, fromTable) : fromTable.flags;
@@ -589,9 +686,9 @@ export function needsQualification(c, symbol, enclosingDeclaration, meaning) {
589
686
  return qualify;
590
687
  }
591
688
  function isPropertyOrMethodDeclarationSymbol(symbol) {
592
- if (symbol.declarations.length === 0)
689
+ if (declarationCount(symbol) === 0)
593
690
  return false;
594
- for (const declaration of symbol.declarations) {
691
+ for (const declaration of getDeclarations(symbol)) {
595
692
  switch (declaration.kind) {
596
693
  case 173 /* SyntaxKind.PropertyDeclaration */:
597
694
  case 175 /* SyntaxKind.MethodDeclaration */:
@@ -834,7 +931,7 @@ export function hasVisibleDeclarations(c, symbol, shouldComputeAliasesToMakeVisi
834
931
  if (aliases.indexOf(statement) < 0)
835
932
  aliases.push(statement);
836
933
  };
837
- for (const declaration of symbol.declarations) {
934
+ for (const declaration of getDeclarations(symbol)) {
838
935
  if (declaration.kind === 79 /* SyntaxKind.Identifier */ || isDeclarationVisible(c, declaration))
839
936
  continue;
840
937
  // Unexported imports can name types if their parent is visible.
@@ -132,19 +132,46 @@ export declare class SymbolRareFields implements ProgramLifetime {
132
132
  members: SymbolTable | undefined;
133
133
  exports: SymbolTable | undefined;
134
134
  exportSymbol: Symbol | undefined;
135
+ /** All declarations of a symbol that has more than one (`getDeclarations`). */
136
+ declarations: Node[] | undefined;
137
+ /** The value declaration where it is not the first declaration (`Symbol.valueDeclaration`). */
138
+ valueDeclaration: Node | undefined;
135
139
  }
136
140
  export declare class Symbol implements ProgramLifetime {
137
141
  flags: SymbolFlags;
138
- checkFlags: CheckFlags;
142
+ /** The check flags, and `valueDeclarationIsFirst`. */
143
+ private bits;
139
144
  readonly name: string;
140
- declarations: Node[];
141
- valueDeclaration: Node | undefined;
145
+ /**
146
+ * The first declaration. A symbol with more keeps all of them in its rare fields; read them with
147
+ * `declarationCount`, `declarationAt` and `getDeclarations`. Written only through `setFirst`,
148
+ * which keeps the value declaration.
149
+ */
150
+ declaration: Node | undefined;
142
151
  parent: Symbol | undefined;
143
152
  private rareFields;
144
153
  /** Assigned on first use by `getSymbolId`, or at creation while threads share the program; 0 until then. */
145
154
  id: number;
146
155
  constructor(flags: SymbolFlags, name: string);
156
+ get checkFlags(): CheckFlags;
157
+ set checkFlags(flags: CheckFlags);
158
+ /** Makes `node` the first declaration, keeping the value declaration. */
159
+ setFirst(node: Node | undefined): void;
160
+ /**
161
+ * The declaration of the symbol's value. Almost always the first declaration, which a bit of `bits`
162
+ * says; any other is kept in the rare fields.
163
+ */
164
+ get valueDeclaration(): Node | undefined;
165
+ set valueDeclaration(node: Node | undefined);
147
166
  private rareFieldsOrNew;
167
+ /**
168
+ * The declarations, for tsc-ts/api's `Symbol.declarations`. The compiler reads `declaration`,
169
+ * `declarationCount` and `declarationAt`: for a single declaration this builds a list on each read.
170
+ */
171
+ get declarations(): readonly Node[];
172
+ /** All declarations where there are more than one, else undefined. */
173
+ get moreDeclarations(): Node[] | undefined;
174
+ set moreDeclarations(value: Node[] | undefined);
148
175
  get members(): SymbolTable | undefined;
149
176
  set members(value: SymbolTable | undefined);
150
177
  get exports(): SymbolTable | undefined;
@@ -182,6 +209,21 @@ export declare function lastSymbolIdValue(): number;
182
209
  export declare function reserveSymbolIds(last: number): void;
183
210
  /** Appends `node` to the declarations of `symbol`. */
184
211
  export declare function addDeclaration(symbol: Symbol, node: Node): void;
212
+ /** The number of declarations of `symbol`. */
213
+ export declare function declarationCount(symbol: Symbol): number;
214
+ /** The declaration of `symbol` at `index`, which is below `declarationCount(symbol)`. */
215
+ export declare function declarationAt(symbol: Symbol, index: number): Node;
216
+ /**
217
+ * The declarations of `symbol`, in order. A symbol with one declaration gets a new list each call;
218
+ * hot paths read `declaration`, `declarationCount` and `declarationAt` instead.
219
+ */
220
+ export declare function getDeclarations(symbol: Symbol): readonly Node[];
221
+ /** Whether `node` is a declaration of `symbol`. */
222
+ export declare function hasDeclaration(symbol: Symbol, node: Node): boolean;
223
+ /** Gives `target` the declarations of `source`; a list of several is shared, as the list was before. */
224
+ export declare function copyDeclarations(target: Symbol, source: Symbol): void;
225
+ /** Replaces the declarations of `symbol` with `declarations`, which it keeps when they are more than one. */
226
+ export declare function setDeclarations(symbol: Symbol, declarations: readonly Node[]): void;
185
227
  /** A program-wide id, assigned to each symbol when first requested. */
186
228
  export declare function getSymbolId(symbol: Symbol): number;
187
229
  /** The exports table of `symbol`, created if missing. */
@@ -3,27 +3,74 @@ export class SymbolRareFields {
3
3
  members = undefined;
4
4
  exports = undefined;
5
5
  exportSymbol = undefined;
6
+ /** All declarations of a symbol that has more than one (`getDeclarations`). */
7
+ declarations = undefined;
8
+ /** The value declaration where it is not the first declaration (`Symbol.valueDeclaration`). */
9
+ valueDeclaration = undefined;
6
10
  }
11
+ /** In `Symbol.bits`, above the check flags: the value declaration is the first declaration. */
12
+ const valueDeclarationIsFirst = 1 << 30;
7
13
  export class Symbol {
8
14
  flags;
9
- checkFlags;
15
+ /** The check flags, and `valueDeclarationIsFirst`. */
16
+ bits;
10
17
  name;
11
- declarations;
12
- valueDeclaration;
18
+ /**
19
+ * The first declaration. A symbol with more keeps all of them in its rare fields; read them with
20
+ * `declarationCount`, `declarationAt` and `getDeclarations`. Written only through `setFirst`,
21
+ * which keeps the value declaration.
22
+ */
23
+ declaration;
13
24
  parent;
14
25
  rareFields;
15
26
  /** Assigned on first use by `getSymbolId`, or at creation while threads share the program; 0 until then. */
16
27
  id;
17
28
  constructor(flags, name) {
18
29
  this.flags = flags;
19
- this.checkFlags = 0 /* CheckFlags.None */;
30
+ this.bits = 0;
20
31
  this.name = name;
21
- this.declarations = noDeclarations;
22
- this.valueDeclaration = undefined;
32
+ this.declaration = undefined;
23
33
  this.parent = undefined;
24
34
  this.rareFields = undefined;
25
35
  this.id = idsAtCreation ? takeSymbolId() : 0;
26
36
  }
37
+ get checkFlags() {
38
+ return (this.bits & ~valueDeclarationIsFirst);
39
+ }
40
+ set checkFlags(flags) {
41
+ this.bits = (this.bits & valueDeclarationIsFirst) | flags;
42
+ }
43
+ /** Makes `node` the first declaration, keeping the value declaration. */
44
+ setFirst(node) {
45
+ if ((this.bits & valueDeclarationIsFirst) !== 0 && node !== this.declaration) {
46
+ // The value declaration stays what it was.
47
+ this.rareFieldsOrNew().valueDeclaration = this.declaration;
48
+ this.bits &= ~valueDeclarationIsFirst;
49
+ }
50
+ this.declaration = node;
51
+ }
52
+ /**
53
+ * The declaration of the symbol's value. Almost always the first declaration, which a bit of `bits`
54
+ * says; any other is kept in the rare fields.
55
+ */
56
+ get valueDeclaration() {
57
+ if ((this.bits & valueDeclarationIsFirst) !== 0)
58
+ return this.declaration;
59
+ const group = this.rareFields;
60
+ return group === undefined ? undefined : group.valueDeclaration;
61
+ }
62
+ set valueDeclaration(node) {
63
+ const group = this.rareFields;
64
+ if (node !== undefined && node === this.declaration) {
65
+ this.bits |= valueDeclarationIsFirst;
66
+ if (group !== undefined)
67
+ group.valueDeclaration = undefined;
68
+ return;
69
+ }
70
+ this.bits &= ~valueDeclarationIsFirst;
71
+ if (node !== undefined || group !== undefined)
72
+ this.rareFieldsOrNew().valueDeclaration = node;
73
+ }
27
74
  rareFieldsOrNew() {
28
75
  let group = this.rareFields;
29
76
  if (group === undefined) {
@@ -32,6 +79,23 @@ export class Symbol {
32
79
  }
33
80
  return group;
34
81
  }
82
+ /**
83
+ * The declarations, for tsc-ts/api's `Symbol.declarations`. The compiler reads `declaration`,
84
+ * `declarationCount` and `declarationAt`: for a single declaration this builds a list on each read.
85
+ */
86
+ get declarations() {
87
+ return getDeclarations(this);
88
+ }
89
+ /** All declarations where there are more than one, else undefined. */
90
+ get moreDeclarations() {
91
+ const group = this.rareFields;
92
+ return group === undefined ? undefined : group.declarations;
93
+ }
94
+ set moreDeclarations(value) {
95
+ if (value === undefined && this.rareFields === undefined)
96
+ return;
97
+ this.rareFieldsOrNew().declarations = value;
98
+ }
35
99
  get members() {
36
100
  const group = this.rareFields;
37
101
  return group === undefined ? undefined : group.members;
@@ -156,11 +220,58 @@ export function reserveSymbolIds(last) {
156
220
  const noDeclarations = [];
157
221
  /** Appends `node` to the declarations of `symbol`. */
158
222
  export function addDeclaration(symbol, node) {
159
- const declarations = symbol.declarations;
160
- if (declarations.length === 0)
161
- symbol.declarations = [node];
223
+ const first = symbol.declaration;
224
+ if (first === undefined) {
225
+ symbol.setFirst(node);
226
+ return;
227
+ }
228
+ const more = symbol.moreDeclarations;
229
+ if (more !== undefined)
230
+ more.push(node);
162
231
  else
163
- declarations.push(node);
232
+ symbol.moreDeclarations = [first, node];
233
+ }
234
+ /** The number of declarations of `symbol`. */
235
+ export function declarationCount(symbol) {
236
+ if (symbol.declaration === undefined)
237
+ return 0;
238
+ const more = symbol.moreDeclarations;
239
+ return more !== undefined ? more.length : 1;
240
+ }
241
+ /** The declaration of `symbol` at `index`, which is below `declarationCount(symbol)`. */
242
+ export function declarationAt(symbol, index) {
243
+ return index === 0 ? symbol.declaration : symbol.moreDeclarations[index];
244
+ }
245
+ /**
246
+ * The declarations of `symbol`, in order. A symbol with one declaration gets a new list each call;
247
+ * hot paths read `declaration`, `declarationCount` and `declarationAt` instead.
248
+ */
249
+ export function getDeclarations(symbol) {
250
+ const first = symbol.declaration;
251
+ if (first === undefined)
252
+ return noDeclarations;
253
+ const more = symbol.moreDeclarations;
254
+ return more !== undefined ? more : [first];
255
+ }
256
+ /** Whether `node` is a declaration of `symbol`. */
257
+ export function hasDeclaration(symbol, node) {
258
+ const first = symbol.declaration;
259
+ if (first === undefined)
260
+ return false;
261
+ if (first === node)
262
+ return true;
263
+ const more = symbol.moreDeclarations;
264
+ return more !== undefined && more.indexOf(node) >= 0;
265
+ }
266
+ /** Gives `target` the declarations of `source`; a list of several is shared, as the list was before. */
267
+ export function copyDeclarations(target, source) {
268
+ target.setFirst(source.declaration);
269
+ target.moreDeclarations = source.moreDeclarations;
270
+ }
271
+ /** Replaces the declarations of `symbol` with `declarations`, which it keeps when they are more than one. */
272
+ export function setDeclarations(symbol, declarations) {
273
+ symbol.setFirst(declarations.length !== 0 ? declarations[0] : undefined);
274
+ symbol.moreDeclarations = declarations.length > 1 ? declarations : undefined;
164
275
  }
165
276
  /**
166
277
  * The symbols of `table` by escaped name, with their ids assigned, as tsc-ts's public API types them: the map's
@@ -1,7 +1,7 @@
1
1
  import { type Node, NodeVisitor, type SourceFile } from '../ast.js';
2
2
  import { type CompilerOptions } from '../options.js';
3
- import { type Symbol } from '../symbol.js';
4
3
  import { type ReferenceResolver } from './reference-resolver.js';
4
+ import { type Symbol } from '../symbol.js';
5
5
  export declare class AliasReferences extends NodeVisitor {
6
6
  readonly options: CompilerOptions;
7
7
  readonly resolver: ReferenceResolver;
@@ -9,6 +9,7 @@ import { JsxEmit, getIsolatedModules, getStrictOptionValue, shouldPreserveConstE
9
9
  import { getDeclarationOfAliasSymbol } from './reference-resolver.js';
10
10
  import { getFirstConstructorWithBody, getRestParameterElementType, getSetAccessorValueParameter, nodeCanBeDecorated, } from './decorator-utilities.js';
11
11
  import { hasDecorators, hasSyntacticModifier } from './utilities.js';
12
+ import { getDeclarations } from '../symbol.js';
12
13
  export class AliasReferences extends NodeVisitor {
13
14
  options;
14
15
  resolver;
@@ -149,7 +150,7 @@ export class AliasReferences extends NodeVisitor {
149
150
  if (symbol === undefined)
150
151
  return undefined;
151
152
  const kind = node.kind === 179 /* SyntaxKind.SetAccessor */ ? 178 /* SyntaxKind.GetAccessor */ : 179 /* SyntaxKind.SetAccessor */;
152
- for (const declaration of symbol.declarations)
153
+ for (const declaration of getDeclarations(symbol))
153
154
  if (declaration.kind === kind)
154
155
  return declaration;
155
156
  return undefined;