tsc-ts 0.0.5 → 0.0.7

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 (203) hide show
  1. package/README.md +1 -1
  2. package/dist/api/compiler/ast.d.ts +67 -27
  3. package/dist/api/compiler/ast.js +156 -55
  4. package/dist/api/compiler/binder-utilities.js +4 -3
  5. package/dist/api/compiler/binder.js +14 -13
  6. package/dist/api/compiler/checker-calls.js +7 -6
  7. package/dist/api/compiler/checker-contextual.js +1 -1
  8. package/dist/api/compiler/checker-declaration-order.js +2 -1
  9. package/dist/api/compiler/checker-declarations.js +14 -14
  10. package/dist/api/compiler/checker-declared-types.d.ts +1 -1
  11. package/dist/api/compiler/checker-declared-types.js +12 -11
  12. package/dist/api/compiler/checker-decorators.js +3 -3
  13. package/dist/api/compiler/checker-deprecation.js +17 -18
  14. package/dist/api/compiler/checker-destructuring.d.ts +1 -1
  15. package/dist/api/compiler/checker-destructuring.js +3 -3
  16. package/dist/api/compiler/checker-elaboration.js +8 -7
  17. package/dist/api/compiler/checker-emit-helpers.d.ts +2 -1
  18. package/dist/api/compiler/checker-emit-helpers.js +5 -4
  19. package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
  20. package/dist/api/compiler/checker-emit-resolver.js +5 -4
  21. package/dist/api/compiler/checker-grammar.js +23 -9
  22. package/dist/api/compiler/checker-heritage.d.ts +1 -1
  23. package/dist/api/compiler/checker-heritage.js +14 -13
  24. package/dist/api/compiler/checker-inference.d.ts +21 -11
  25. package/dist/api/compiler/checker-inference.js +57 -34
  26. package/dist/api/compiler/checker-javascript.d.ts +1 -1
  27. package/dist/api/compiler/checker-javascript.js +5 -4
  28. package/dist/api/compiler/checker-jsx.d.ts +1 -1
  29. package/dist/api/compiler/checker-jsx.js +4 -4
  30. package/dist/api/compiler/checker-literals.js +2 -2
  31. package/dist/api/compiler/checker-members.d.ts +32 -3
  32. package/dist/api/compiler/checker-members.js +240 -53
  33. package/dist/api/compiler/checker-modules.d.ts +15 -1
  34. package/dist/api/compiler/checker-modules.js +86 -14
  35. package/dist/api/compiler/checker-object-literals.d.ts +1 -1
  36. package/dist/api/compiler/checker-object-literals.js +11 -7
  37. package/dist/api/compiler/checker-overloads.d.ts +1 -1
  38. package/dist/api/compiler/checker-overloads.js +4 -3
  39. package/dist/api/compiler/checker-property-access.d.ts +1 -1
  40. package/dist/api/compiler/checker-property-access.js +2 -2
  41. package/dist/api/compiler/checker-services.js +2 -2
  42. package/dist/api/compiler/checker-signatures.d.ts +1 -1
  43. package/dist/api/compiler/checker-signatures.js +9 -8
  44. package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
  45. package/dist/api/compiler/checker-symbol-types.js +22 -952
  46. package/dist/api/compiler/checker-symbols.d.ts +2 -2
  47. package/dist/api/compiler/checker-symbols.js +29 -27
  48. package/dist/api/compiler/checker-type-factory.d.ts +2 -2
  49. package/dist/api/compiler/checker-type-factory.js +57 -16
  50. package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
  51. package/dist/api/compiler/checker-type-nodes.js +2 -2
  52. package/dist/api/compiler/checker-type-operators.d.ts +1 -1
  53. package/dist/api/compiler/checker-type-operators.js +5 -5
  54. package/dist/api/compiler/checker-types.d.ts +73 -7
  55. package/dist/api/compiler/checker-types.js +220 -43
  56. package/dist/api/compiler/checker-unused.d.ts +1 -1
  57. package/dist/api/compiler/checker-unused.js +3 -3
  58. package/dist/api/compiler/checker.d.ts +45 -8
  59. package/dist/api/compiler/checker.js +46 -9
  60. package/dist/api/compiler/diagnostics.d.ts +2 -8
  61. package/dist/api/compiler/diagnostics.js +13 -45
  62. package/dist/api/compiler/file-include.d.ts +35 -8
  63. package/dist/api/compiler/file-include.js +81 -18
  64. package/dist/api/compiler/file-loader.d.ts +33 -4
  65. package/dist/api/compiler/file-loader.js +90 -24
  66. package/dist/api/compiler/instantiation.d.ts +1 -1
  67. package/dist/api/compiler/instantiation.js +86 -50
  68. package/dist/api/compiler/link-tables.d.ts +69 -0
  69. package/dist/api/compiler/link-tables.js +236 -0
  70. package/dist/api/compiler/name-resolver.js +3 -3
  71. package/dist/api/compiler/node-builder-names.d.ts +1 -1
  72. package/dist/api/compiler/node-builder-names.js +12 -12
  73. package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
  74. package/dist/api/compiler/node-builder-pseudo.js +2 -1
  75. package/dist/api/compiler/node-builder.d.ts +1 -1
  76. package/dist/api/compiler/node-builder.js +16 -16
  77. package/dist/api/compiler/parallel-parse.d.ts +2 -0
  78. package/dist/api/compiler/parallel-parse.js +7 -1
  79. package/dist/api/compiler/parser.d.ts +33 -16
  80. package/dist/api/compiler/parser.js +127 -98
  81. package/dist/api/compiler/printer/emit-context.d.ts +5 -2
  82. package/dist/api/compiler/printer/emit-context.js +19 -13
  83. package/dist/api/compiler/printer/factory-base.js +8 -8
  84. package/dist/api/compiler/printer/factory.js +4 -4
  85. package/dist/api/compiler/printer/printer.js +6 -6
  86. package/dist/api/compiler/program-checker.d.ts +5 -0
  87. package/dist/api/compiler/program-checker.js +14 -1
  88. package/dist/api/compiler/program.js +9 -1
  89. package/dist/api/compiler/relations.d.ts +1 -1
  90. package/dist/api/compiler/relations.js +18 -13
  91. package/dist/api/compiler/reparser.js +13 -5
  92. package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
  93. package/dist/api/compiler/symbol-accessibility.js +123 -26
  94. package/dist/api/compiler/symbol.d.ts +45 -3
  95. package/dist/api/compiler/symbol.js +121 -10
  96. package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
  97. package/dist/api/compiler/transformers/alias-references.js +2 -1
  98. package/dist/api/compiler/transformers/class-fields.js +3 -3
  99. package/dist/api/compiler/transformers/commonjs-module.js +3 -3
  100. package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
  101. package/dist/api/compiler/transformers/declarations-pseudo.js +6 -4
  102. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
  103. package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
  104. package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
  105. package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
  106. package/dist/api/compiler/transformers/declarations.js +6 -5
  107. package/dist/api/compiler/transformers/module.js +2 -2
  108. package/dist/api/compiler/transformers/optional-chain.js +3 -3
  109. package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
  110. package/dist/api/compiler/transformers/reference-resolver.js +26 -24
  111. package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
  112. package/dist/api/compiler/transformers/subtree-facts.js +9 -7
  113. package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
  114. package/dist/api/compiler/transformers/syntax-facts.js +9 -5
  115. package/dist/api/compiler/transformers/tagged-template.js +2 -2
  116. package/dist/api/compiler/transformers/type-eraser.js +2 -2
  117. package/dist/api/compiler/transformers/type-serialization.js +12 -12
  118. package/dist/api/compiler/transformers/visitor-base.js +3 -3
  119. package/dist/api/compiler/tsconfig.js +2 -2
  120. package/package.json +9 -9
  121. package/src/compiler/ast.ts +211 -78
  122. package/src/compiler/binder-utilities.ts +4 -3
  123. package/src/compiler/binder.ts +26 -16
  124. package/src/compiler/checker-calls.ts +8 -6
  125. package/src/compiler/checker-contextual.ts +1 -1
  126. package/src/compiler/checker-declaration-order.ts +2 -2
  127. package/src/compiler/checker-declarations.ts +21 -14
  128. package/src/compiler/checker-declared-types.ts +12 -12
  129. package/src/compiler/checker-decorators.ts +3 -3
  130. package/src/compiler/checker-deprecation.ts +17 -21
  131. package/src/compiler/checker-destructuring.ts +3 -3
  132. package/src/compiler/checker-elaboration.ts +8 -8
  133. package/src/compiler/checker-emit-helpers.ts +5 -4
  134. package/src/compiler/checker-emit-resolver.ts +5 -5
  135. package/src/compiler/checker-grammar.ts +22 -8
  136. package/src/compiler/checker-heritage.ts +21 -14
  137. package/src/compiler/checker-inference.ts +66 -34
  138. package/src/compiler/checker-javascript.ts +5 -5
  139. package/src/compiler/checker-jsx.ts +12 -8
  140. package/src/compiler/checker-literals.ts +2 -2
  141. package/src/compiler/checker-members.ts +255 -47
  142. package/src/compiler/checker-modules.ts +115 -14
  143. package/src/compiler/checker-object-literals.ts +22 -6
  144. package/src/compiler/checker-overloads.ts +6 -6
  145. package/src/compiler/checker-property-access.ts +2 -2
  146. package/src/compiler/checker-services.ts +2 -2
  147. package/src/compiler/checker-signatures.ts +9 -9
  148. package/src/compiler/checker-symbol-types.ts +20 -940
  149. package/src/compiler/checker-symbols.ts +42 -35
  150. package/src/compiler/checker-type-factory.ts +53 -16
  151. package/src/compiler/checker-type-nodes.ts +2 -2
  152. package/src/compiler/checker-type-operators.ts +13 -5
  153. package/src/compiler/checker-types.ts +223 -43
  154. package/src/compiler/checker-unused.ts +3 -3
  155. package/src/compiler/checker.ts +50 -9
  156. package/src/compiler/decoder.ts +5 -4
  157. package/src/compiler/diagnostics.ts +14 -48
  158. package/src/compiler/encoder.ts +10 -5
  159. package/src/compiler/file-include.ts +85 -17
  160. package/src/compiler/file-loader.ts +104 -35
  161. package/src/compiler/incremental.ts +39 -5
  162. package/src/compiler/instantiation.ts +99 -55
  163. package/src/compiler/link-tables.ts +245 -0
  164. package/src/compiler/name-resolver.ts +3 -3
  165. package/src/compiler/node-builder-names.ts +21 -19
  166. package/src/compiler/node-builder-pseudo.ts +2 -2
  167. package/src/compiler/node-builder.ts +24 -16
  168. package/src/compiler/parallel-check.ts +11 -8
  169. package/src/compiler/parallel-parse.ts +8 -1
  170. package/src/compiler/parse-thread.ts +0 -4
  171. package/src/compiler/parser.ts +173 -93
  172. package/src/compiler/printer/emit-context.ts +20 -15
  173. package/src/compiler/printer/factory-base.ts +14 -7
  174. package/src/compiler/printer/factory.ts +5 -3
  175. package/src/compiler/printer/printer.ts +8 -6
  176. package/src/compiler/program-checker.ts +12 -1
  177. package/src/compiler/program.ts +8 -1
  178. package/src/compiler/relations.ts +20 -12
  179. package/src/compiler/reparser.ts +14 -4
  180. package/src/compiler/symbol-accessibility.ts +120 -25
  181. package/src/compiler/symbol.ts +127 -9
  182. package/src/compiler/transformers/alias-references.ts +2 -2
  183. package/src/compiler/transformers/class-fields.ts +12 -2
  184. package/src/compiler/transformers/commonjs-module.ts +3 -2
  185. package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
  186. package/src/compiler/transformers/declarations-pseudo.ts +9 -5
  187. package/src/compiler/transformers/declarations-syntactic.ts +17 -9
  188. package/src/compiler/transformers/declarations-tracker.ts +3 -3
  189. package/src/compiler/transformers/declarations.ts +7 -7
  190. package/src/compiler/transformers/module.ts +2 -1
  191. package/src/compiler/transformers/optional-chain.ts +5 -2
  192. package/src/compiler/transformers/reference-resolver.ts +37 -25
  193. package/src/compiler/transformers/subtree-facts.ts +15 -6
  194. package/src/compiler/transformers/syntax-facts.ts +10 -5
  195. package/src/compiler/transformers/tagged-template.ts +2 -2
  196. package/src/compiler/transformers/type-eraser.ts +2 -1
  197. package/src/compiler/transformers/type-serialization.ts +12 -12
  198. package/src/compiler/transformers/visitor-base.ts +10 -5
  199. package/src/compiler/tsc-build.ts +17 -13
  200. package/src/compiler/tsc-cli.ts +9 -6
  201. package/src/compiler/tsc-compile.ts +16 -7
  202. package/src/compiler/tsc-watch.ts +94 -26
  203. package/src/compiler/tsconfig.ts +2 -1
@@ -15,7 +15,6 @@ import {
15
15
  TypeQueryNode,
16
16
  } from './ast.js';
17
17
  import { Diagnostics } from './diagnostics.js';
18
- import { CheckFlags, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
19
18
  import { SyntaxKind } from './syntax-kind.js';
20
19
  import type { Checker, VarianceReporting } from './checker.js';
21
20
  import {
@@ -79,6 +78,15 @@ import {
79
78
  import { getConstraintDeclaration } from './checker-declared-types.js';
80
79
  import { isTypeAssignableTo } from './relations.js';
81
80
  import { getFirstIdentifier } from './checker-symbols.js';
81
+ import {
82
+ CheckFlags,
83
+ copyDeclarations,
84
+ declarationCount,
85
+ getDeclarations,
86
+ getSymbolId,
87
+ type Symbol,
88
+ SymbolFlags,
89
+ } from './symbol.js';
82
90
 
83
91
  // ---- Mappers that need the checker
84
92
 
@@ -181,8 +189,18 @@ export function instantiateTypeWithAlias(
181
189
  alias: TypeAlias | undefined,
182
190
  ): Type {
183
191
  if (mapper === undefined) return type;
184
- // Aliases with type arguments may be copied with new arguments even when the type itself has no type variables.
185
- if (!couldContainTypeVariables(c, type) && !aliasCouldContainTypeVariables(c, type)) return type;
192
+ // `couldContainTypeVariables`, answered here when the type's own flags decide it. Aliases with type
193
+ // arguments may be copied with new arguments even when the type itself has no type variables.
194
+ let could: boolean;
195
+ if ((type.flags & TypeFlags.StructuredOrInstantiable) === 0) could = false;
196
+ else {
197
+ const objectFlags = type.objectFlags;
198
+ could =
199
+ (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) !== 0
200
+ ? (objectFlags & ObjectFlags.CouldContainTypeVariables) !== 0
201
+ : couldContainTypeVariables(c, type);
202
+ }
203
+ if (!could && (type.alias === undefined || !aliasCouldContainTypeVariables(c, type))) return type;
186
204
  if (c.instantiationDepth === 100 || c.instantiationCount >= 5000000) {
187
205
  // Probably infinitely expanding generic types; stop with the error type.
188
206
  c.error(c.currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
@@ -292,7 +310,7 @@ export function couldContainTypeVariables(c: Checker, type: Type): boolean {
292
310
  SymbolFlags.Class |
293
311
  SymbolFlags.TypeLiteral |
294
312
  SymbolFlags.ObjectLiteral)) !==
295
- 0 && type.symbol.declarations.length !== 0;
313
+ 0 && declarationCount(type.symbol) !== 0;
296
314
  }
297
315
  if (!result)
298
316
  result =
@@ -324,7 +342,7 @@ function isNonGenericTopLevelType(type: Type): boolean {
324
342
  const alias = type.alias;
325
343
  if (alias === undefined || alias.typeArguments.length !== 0) return false;
326
344
  let declaration: Node | undefined;
327
- for (const d of alias.symbol.declarations)
345
+ for (const d of getDeclarations(alias.symbol))
328
346
  if (d.kind === SyntaxKind.TypeAliasDeclaration || d.kind === SyntaxKind.JSTypeAliasDeclaration) {
329
347
  declaration = d;
330
348
  break;
@@ -429,11 +447,12 @@ function getObjectTypeInstantiation(
429
447
  mapper: TypeMapper,
430
448
  alias: TypeAlias | undefined,
431
449
  ): Type {
450
+ if ((type.objectFlags & ObjectFlags.Reference) === 0 && c.withoutOuterTypeParameters.get(type.id) !== 0) return type;
432
451
  let declaration: Node;
433
452
  if ((type.objectFlags & ObjectFlags.Reference) !== 0) declaration = (type as TypeReference).node!;
434
453
  else if ((type.objectFlags & ObjectFlags.InstantiationExpressionType) !== 0)
435
454
  declaration = (type as InstantiationExpressionType).node!;
436
- else declaration = type.symbol!.declarations[0]!;
455
+ else declaration = type.symbol!.declaration!;
437
456
  const links = c.nodeLinks(declaration);
438
457
  let target: ObjectType;
439
458
  if ((type.objectFlags & ObjectFlags.Reference) !== 0) target = c.resolvedTypes.get(declaration.id) as ObjectType;
@@ -451,7 +470,7 @@ function getObjectTypeInstantiation(
451
470
  } else if ((target.symbol!.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral)) !== 0) {
452
471
  const referenced: Type[] = [];
453
472
  for (const tp of typeParameters) {
454
- for (const d of type.symbol!.declarations) {
473
+ for (const d of getDeclarations(type.symbol!)) {
455
474
  if (isTypeParameterPossiblyReferenced(c, tp, d)) {
456
475
  referenced.push(tp);
457
476
  break;
@@ -463,14 +482,25 @@ function getObjectTypeInstantiation(
463
482
  }
464
483
  links.outerTypeParameters = typeParameters;
465
484
  }
466
- if (typeParameters.length === 0) return type;
467
- const combinedMapper = combineTypeMappers(c, type.mapper, mapper);
468
- const typeArguments: Type[] = [];
469
- for (const tp of typeParameters) typeArguments.push(combinedMapper.map(tp));
485
+ if (typeParameters.length === 0) {
486
+ if ((type.objectFlags & ObjectFlags.Reference) === 0) c.withoutOuterTypeParameters.set(type.id, 1);
487
+ return type;
488
+ }
489
+ // The type arguments, mapped as `combineTypeMappers(c, type.mapper, mapper)` maps them, into a
490
+ // list of the checker's that is copied only when the instantiation is new.
491
+ const typeMapper = type.mapper;
492
+ const mapped = c.freeTypeLists.pop() ?? [];
493
+ for (const tp of typeParameters) {
494
+ if (typeMapper === undefined) mapped.push(mapper.map(tp));
495
+ else {
496
+ const t1 = typeMapper.map(tp);
497
+ mapped.push(t1 !== tp ? instantiateType(c, t1, mapper) : mapper.map(tp));
498
+ }
499
+ }
470
500
  const newAlias = alias ?? instantiateTypeAlias(c, type.alias, mapper);
471
501
  const singleSignature = (type.objectFlags & ObjectFlags.SingleSignatureType) !== 0;
472
502
  const tag = singleSignature ? 1 : 0;
473
- const hash = typeListHash(typeArguments, newAlias, tag);
503
+ const hash = typeListHash(mapped, newAlias, tag);
474
504
  const generic = sideOf(c, target);
475
505
  let instantiations = generic.instantiations;
476
506
  if (instantiations === undefined) {
@@ -478,39 +508,47 @@ function getObjectTypeInstantiation(
478
508
  instantiations.set(typeListHash(typeParameters, target.alias, 0), typeParameters, target.alias, 0, target);
479
509
  generic.instantiations = instantiations;
480
510
  }
481
- let result = instantiations.get(hash, typeArguments, newAlias, tag);
482
- if (result === undefined) {
483
- let newMapper = newTypeMapper(typeParameters, typeArguments);
484
- if ((target.objectFlags & ObjectFlags.SingleSignatureType) !== 0)
485
- newMapper = combineTypeMappers(c, newMapper, mapper);
486
- if ((target.objectFlags & ObjectFlags.Reference) !== 0)
487
- result = createDeferredTypeReference(
488
- c,
489
- (type as TypeReference).target!,
490
- (type as TypeReference).node!,
491
- newMapper,
492
- newAlias,
493
- );
494
- else if ((target.objectFlags & ObjectFlags.Mapped) !== 0)
495
- result = instantiateMappedType(c, target as MappedType, newMapper, newAlias);
496
- else result = instantiateAnonymousType(c, target, newMapper, newAlias);
497
- instantiations.set(hash, typeArguments, newAlias, tag, result);
498
- if (
499
- (result.flags & TypeFlags.ObjectFlagsType) !== 0 &&
500
- (lazyObjectFlags(c, result) & ObjectFlags.CouldContainTypeVariablesComputed) === 0
501
- ) {
502
- // Type variable containment follows from the type arguments.
503
- let couldContain = false;
504
- for (const t of typeArguments)
505
- if (couldContainTypeVariables(c, t)) {
506
- couldContain = true;
507
- break;
508
- }
509
- if ((result.objectFlags & (ObjectFlags.Mapped | ObjectFlags.Anonymous | ObjectFlags.Reference)) !== 0)
510
- sideOf(c, result).objectFlags |=
511
- ObjectFlags.CouldContainTypeVariablesComputed | (couldContain ? ObjectFlags.CouldContainTypeVariables : 0);
512
- else if (!couldContain) sideOf(c, result).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed;
513
- }
511
+ const cached = instantiations.get(hash, mapped, newAlias, tag);
512
+ if (cached !== undefined) {
513
+ mapped.length = 0;
514
+ c.freeTypeLists.push(mapped);
515
+ return cached;
516
+ }
517
+ // The cache and the instantiation's mapper keep the type arguments.
518
+ const typeArguments = c.typeLists.intern(typeListHash(mapped, undefined, 0), mapped.slice());
519
+ mapped.length = 0;
520
+ c.freeTypeLists.push(mapped);
521
+ let result: Type;
522
+ let newMapper = newTypeMapper(typeParameters, typeArguments);
523
+ if ((target.objectFlags & ObjectFlags.SingleSignatureType) !== 0)
524
+ newMapper = combineTypeMappers(c, newMapper, mapper);
525
+ if ((target.objectFlags & ObjectFlags.Reference) !== 0)
526
+ result = createDeferredTypeReference(
527
+ c,
528
+ (type as TypeReference).target!,
529
+ (type as TypeReference).node!,
530
+ newMapper,
531
+ newAlias,
532
+ );
533
+ else if ((target.objectFlags & ObjectFlags.Mapped) !== 0)
534
+ result = instantiateMappedType(c, target as MappedType, newMapper, newAlias);
535
+ else result = instantiateAnonymousType(c, target, newMapper, newAlias);
536
+ instantiations.set(hash, typeArguments, newAlias, tag, result);
537
+ if (
538
+ (result.flags & TypeFlags.ObjectFlagsType) !== 0 &&
539
+ (lazyObjectFlags(c, result) & ObjectFlags.CouldContainTypeVariablesComputed) === 0
540
+ ) {
541
+ // Type variable containment follows from the type arguments.
542
+ let couldContain = false;
543
+ for (const t of typeArguments)
544
+ if (couldContainTypeVariables(c, t)) {
545
+ couldContain = true;
546
+ break;
547
+ }
548
+ if ((result.objectFlags & (ObjectFlags.Mapped | ObjectFlags.Anonymous | ObjectFlags.Reference)) !== 0)
549
+ sideOf(c, result).objectFlags |=
550
+ ObjectFlags.CouldContainTypeVariablesComputed | (couldContain ? ObjectFlags.CouldContainTypeVariables : 0);
551
+ else if (!couldContain) sideOf(c, result).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed;
514
552
  }
515
553
  return result;
516
554
  }
@@ -551,12 +589,12 @@ class ReferenceFinder extends NodeVisitor {
551
589
  !(firstIdentifier.kind === SyntaxKind.Identifier && firstIdentifier.text === 'this')
552
590
  ) {
553
591
  const symbol = getResolvedSymbolOfIdentifier(this.c, firstIdentifier);
554
- const tpDeclaration = tp.symbol!.declarations[0]!;
592
+ const tpDeclaration = tp.symbol!.declaration!;
555
593
  let scope: Node | undefined;
556
594
  if (tpDeclaration.kind === SyntaxKind.TypeParameter) scope = tpDeclaration.parent;
557
595
  else if (tp.isThisType) scope = tpDeclaration;
558
596
  if (scope !== undefined) {
559
- for (const d of symbol.declarations) if (isNodeDescendantOf(d, scope)) return true;
597
+ for (const d of getDeclarations(symbol)) if (isNodeDescendantOf(d, scope)) return true;
560
598
  const args = getTypeArgumentNodes(node);
561
599
  if (args !== undefined) for (const a of args.nodes) if (this.containsReference(a)) return true;
562
600
  return false;
@@ -596,9 +634,9 @@ export function isNodeDescendantOf(node: Node, ancestor: Node): boolean {
596
634
  */
597
635
  export function isTypeParameterPossiblyReferenced(c: Checker, tp: Type, node: Node): boolean {
598
636
  const typeParameter = tp as TypeParameter;
599
- if (tp.symbol === undefined || tp.symbol.declarations.length !== 1) return true;
637
+ if (tp.symbol === undefined || declarationCount(tp.symbol) !== 1) return true;
600
638
  const finder = new ReferenceFinder(c, typeParameter);
601
- const container = tp.symbol.declarations[0]!.parent;
639
+ const container = tp.symbol.declaration!.parent;
602
640
  for (let n: Node | undefined = node; n !== container; n = n.parent) {
603
641
  if (n === undefined || n.kind === SyntaxKind.Block) return true;
604
642
  if (n.kind === SyntaxKind.ConditionalType && finder.containsReference((n as ConditionalTypeNode).extendsType))
@@ -650,9 +688,15 @@ export function instantiateTypeAlias(
650
688
  alias: TypeAlias | undefined,
651
689
  mapper: TypeMapper,
652
690
  ): TypeAlias | undefined {
653
- return alias === undefined
654
- ? undefined
655
- : new TypeAlias(alias.symbol, instantiateTypes(c, alias.typeArguments, mapper));
691
+ if (alias === undefined) return undefined;
692
+ const typeArguments = instantiateTypes(c, alias.typeArguments, mapper);
693
+ // The alias's type keeps its type arguments.
694
+ return new TypeAlias(
695
+ alias.symbol,
696
+ typeArguments === alias.typeArguments
697
+ ? typeArguments
698
+ : c.typeLists.intern(typeListHash(typeArguments, undefined, 0), typeArguments),
699
+ );
656
700
  }
657
701
 
658
702
  /** Instantiates each type; returns `types` itself when nothing changed. */
@@ -785,7 +829,7 @@ export function newInstantiatedSymbol(c: Checker, symbol: Symbol, mapper: TypeMa
785
829
  CheckFlags.Instantiated |
786
830
  (symbol.checkFlags &
787
831
  (CheckFlags.Readonly | CheckFlags.Late | CheckFlags.OptionalParameter | CheckFlags.RestParameter));
788
- result.declarations = symbol.declarations;
832
+ copyDeclarations(result, symbol);
789
833
  result.parent = symbol.parent;
790
834
  result.valueDeclaration = symbol.valueDeclaration;
791
835
  const id = getSymbolId(result);
@@ -797,8 +841,8 @@ export function newInstantiatedSymbol(c: Checker, symbol: Symbol, mapper: TypeMa
797
841
 
798
842
  /** Conservatively, whether a parameter or member's type can't reference `this`. */
799
843
  export function isThisless(symbol: Symbol): boolean {
800
- if (symbol.declarations.length !== 1) return false;
801
- const declaration = symbol.declarations[0]!;
844
+ if (declarationCount(symbol) !== 1) return false;
845
+ const declaration = symbol.declaration!;
802
846
  switch (declaration.kind) {
803
847
  case SyntaxKind.Parameter:
804
848
  case SyntaxKind.PropertyDeclaration:
@@ -7,6 +7,8 @@
7
7
  // checker that touches part of a program (as each of several parallel checkers does) stores only
8
8
  // the pages it touches.
9
9
 
10
+ import type { Symbol } from './symbol.js';
11
+
10
12
  /** Links are stored in pages of 256 ids. */
11
13
  export const enum LinkPaging {
12
14
  Bits = 8,
@@ -96,3 +98,246 @@ export class SparseLinkTable<T> {
96
98
  this.values.clear();
97
99
  }
98
100
  }
101
+
102
+ /**
103
+ * Values by id for ids in a few clusters, as one file's emit uses them: the file's nodes and the
104
+ * nodes the emit synthesizes, far above them. Pages of `LinkPaging.Size` ids are found through a
105
+ * map from the page index, so the ids between clusters cost nothing, and the page of the last
106
+ * lookup is kept, since lookups come in runs of nearby ids.
107
+ */
108
+ export class ClusteredLinkTable<T> {
109
+ private readonly pages = new Map<number, (T | undefined)[]>();
110
+ private lastIndex = -1;
111
+ private lastPage: (T | undefined)[] | undefined = undefined;
112
+
113
+ get(id: number): T | undefined {
114
+ const page = this.pageOf(id >> LinkPaging.Bits);
115
+ return page !== undefined ? page[id & LinkPaging.Mask] : undefined;
116
+ }
117
+
118
+ set(id: number, value: T | undefined): void {
119
+ const index = id >> LinkPaging.Bits;
120
+ const page = this.pageOf(index);
121
+ if (page !== undefined) page[id & LinkPaging.Mask] = value;
122
+ else if (value !== undefined) {
123
+ const created: (T | undefined)[] = [];
124
+ for (let i = 0; i < LinkPaging.Size; i++) created.push(undefined);
125
+ created[id & LinkPaging.Mask] = value;
126
+ this.pages.set(index, created);
127
+ this.lastPage = created;
128
+ }
129
+ }
130
+
131
+ private pageOf(index: number): (T | undefined)[] | undefined {
132
+ if (index !== this.lastIndex) {
133
+ this.lastIndex = index;
134
+ this.lastPage = this.pages.get(index);
135
+ }
136
+ return this.lastPage;
137
+ }
138
+ }
139
+
140
+ /** Int32 values by id, zero where none is stored, for ids in a few clusters (`ClusteredLinkTable`). */
141
+ export class ClusteredIntLinkTable {
142
+ private readonly pages = new Map<number, Int32Array>();
143
+ private lastIndex = -1;
144
+ private lastPage: Int32Array | undefined = undefined;
145
+
146
+ get(id: number): number {
147
+ const page = this.pageOf(id >> LinkPaging.Bits);
148
+ return page !== undefined ? page[id & LinkPaging.Mask]! : 0;
149
+ }
150
+
151
+ set(id: number, value: number): void {
152
+ const index = id >> LinkPaging.Bits;
153
+ const page = this.pageOf(index);
154
+ if (page !== undefined) page[id & LinkPaging.Mask] = value;
155
+ else if (value !== 0) {
156
+ const created = new Int32Array(LinkPaging.Size);
157
+ created[id & LinkPaging.Mask] = value;
158
+ this.pages.set(index, created);
159
+ this.lastPage = created;
160
+ }
161
+ }
162
+
163
+ private pageOf(index: number): Int32Array | undefined {
164
+ if (index !== this.lastIndex) {
165
+ this.lastIndex = index;
166
+ this.lastPage = this.pages.get(index);
167
+ }
168
+ return this.lastPage;
169
+ }
170
+ }
171
+
172
+ /** The number of set bits of a 32-bit value. */
173
+ function bitCount(x: number): number {
174
+ x = x - ((x >>> 1) & 0x55555555);
175
+ x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
176
+ x = (x + (x >>> 4)) & 0x0f0f0f0f;
177
+ return Math.imul(x, 0x01010101) >>> 24;
178
+ }
179
+
180
+ /**
181
+ * A page of a `CompactSymbolLinkTable`: one bit per id of the page in eight 32-id words, the number
182
+ * of symbols stored before each word, and the symbols in id order. The words are fields, so a
183
+ * lookup reads one object before the symbols. The class isn't generic, so natively the words are
184
+ * 32-bit fields: every write stores an int32.
185
+ */
186
+ class CompactLinkPage {
187
+ readonly values: Symbol[];
188
+ private w0: number;
189
+ private w1: number;
190
+ private w2: number;
191
+ private w3: number;
192
+ private w4: number;
193
+ private w5: number;
194
+ private w6: number;
195
+ private w7: number;
196
+ /** Byte `w & 3` of `before0` (words 1 to 3) or of `before1` (words 4 to 7): the values before word `w`. */
197
+ private before0: number;
198
+ private before1: number;
199
+
200
+ constructor() {
201
+ this.values = [];
202
+ this.w0 = 0;
203
+ this.w1 = 0;
204
+ this.w2 = 0;
205
+ this.w3 = 0;
206
+ this.w4 = 0;
207
+ this.w5 = 0;
208
+ this.w6 = 0;
209
+ this.w7 = 0;
210
+ this.before0 = 0;
211
+ this.before1 = 0;
212
+ }
213
+
214
+ /** The presence bits of ids `32 * word` to `32 * word + 31`. */
215
+ word(word: number): number {
216
+ switch (word) {
217
+ case 0:
218
+ return this.w0;
219
+ case 1:
220
+ return this.w1;
221
+ case 2:
222
+ return this.w2;
223
+ case 3:
224
+ return this.w3;
225
+ case 4:
226
+ return this.w4;
227
+ case 5:
228
+ return this.w5;
229
+ case 6:
230
+ return this.w6;
231
+ default:
232
+ return this.w7;
233
+ }
234
+ }
235
+
236
+ setWord(word: number, bits: number): void {
237
+ switch (word) {
238
+ case 0:
239
+ this.w0 = bits | 0;
240
+ break;
241
+ case 1:
242
+ this.w1 = bits | 0;
243
+ break;
244
+ case 2:
245
+ this.w2 = bits | 0;
246
+ break;
247
+ case 3:
248
+ this.w3 = bits | 0;
249
+ break;
250
+ case 4:
251
+ this.w4 = bits | 0;
252
+ break;
253
+ case 5:
254
+ this.w5 = bits | 0;
255
+ break;
256
+ case 6:
257
+ this.w6 = bits | 0;
258
+ break;
259
+ default:
260
+ this.w7 = bits | 0;
261
+ }
262
+ }
263
+
264
+ /** The index in `values` of the value of `slot` (an id's low bits), or of where it goes. */
265
+ rank(slot: number, bits: number): number {
266
+ const word = slot >> 5;
267
+ const before = ((word < 4 ? this.before0 : this.before1) >>> ((word & 3) << 3)) & 0xff;
268
+ return before + bitCount(bits & ((1 << (slot & 31)) - 1));
269
+ }
270
+
271
+ /** Adds `delta` to the counts of the words after `word`. */
272
+ shiftCounts(word: number, delta: number): void {
273
+ for (let w = word + 1; w < 8; w++) {
274
+ const step = delta << ((w & 3) << 3);
275
+ if (w < 4) this.before0 = (this.before0 + step) | 0;
276
+ else this.before1 = (this.before1 + step) | 0;
277
+ }
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Symbols by node id, for ids a checker resolves in one in four to one in eight of the ids of the
283
+ * pages it touches, as it resolves the identifiers and names of the files it checks. Pages of
284
+ * `LinkPaging.Size` ids keep a presence bit per id and only the symbols stored, so a symbol costs
285
+ * about one array slot. A `LinkTable` page costs a slot for every id, and a `Map` entry also
286
+ * stores its key and a share of the hash buckets. At fewer values per page than that, the page's
287
+ * own allocations outweigh what it saves, and a `SparseLinkTable` costs less.
288
+ */
289
+ export class CompactSymbolLinkTable {
290
+ readonly pages: (CompactLinkPage | undefined)[] = [];
291
+ /** The number of symbols stored. */
292
+ size = 0;
293
+
294
+ get(id: number): Symbol | undefined {
295
+ const page = this.pages[id >> LinkPaging.Bits];
296
+ if (page === undefined) return undefined;
297
+ const slot = id & LinkPaging.Mask;
298
+ const bits = page.word(slot >> 5);
299
+ if ((bits & (1 << (slot & 31))) === 0) return undefined;
300
+ return page.values[page.rank(slot, bits)];
301
+ }
302
+
303
+ set(id: number, value: Symbol | undefined): void {
304
+ const index = id >> LinkPaging.Bits;
305
+ let page = this.pages[index];
306
+ if (page === undefined) {
307
+ if (value === undefined) return;
308
+ while (this.pages.length <= index) this.pages.push(undefined);
309
+ page = new CompactLinkPage();
310
+ this.pages[index] = page;
311
+ }
312
+ const slot = id & LinkPaging.Mask;
313
+ const word = slot >> 5;
314
+ const bit = 1 << (slot & 31);
315
+ const bits = page.word(word);
316
+ const at = page.rank(slot, bits);
317
+ const values = page.values;
318
+ if ((bits & bit) !== 0) {
319
+ if (value !== undefined) {
320
+ values[at] = value;
321
+ return;
322
+ }
323
+ for (let i = at; i < values.length - 1; i++) values[i] = values[i + 1]!;
324
+ values.pop();
325
+ page.setWord(word, bits & ~bit);
326
+ page.shiftCounts(word, -1);
327
+ this.size--;
328
+ return;
329
+ }
330
+ if (value === undefined) return;
331
+ values.push(value);
332
+ for (let i = values.length - 1; i > at; i--) values[i] = values[i - 1]!;
333
+ values[at] = value;
334
+ page.setWord(word, bits | bit);
335
+ page.shiftCounts(word, 1);
336
+ this.size++;
337
+ }
338
+
339
+ clear(): void {
340
+ this.pages.length = 0;
341
+ this.size = 0;
342
+ }
343
+ }
@@ -55,9 +55,9 @@ import {
55
55
  getIsolatedModules,
56
56
  getUseDefineForClassFields,
57
57
  } from './options.js';
58
- import { InternalSymbolName, Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
59
58
  import { SyntaxKind } from './syntax-kind.js';
60
59
  import { ScriptTarget } from './types.js';
60
+ import { getDeclarations, InternalSymbolName, Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
61
61
 
62
62
  export class NameResolver {
63
63
  readonly compilerOptions: CompilerOptions;
@@ -596,7 +596,7 @@ function isInParameter(declaration: Node | undefined): boolean {
596
596
 
597
597
  /** The local symbol of an `export default` declaration. */
598
598
  export function getLocalSymbolForExportDefault(symbol: Symbol): Symbol | undefined {
599
- const declarations = symbol.declarations;
599
+ const declarations = getDeclarations(symbol);
600
600
  if (declarations.length === 0 || !hasSyntacticModifier(declarations[0]!, ModifierFlags.Default)) return undefined;
601
601
  for (const declaration of declarations) {
602
602
  const localSymbol = getLocalSymbol(declaration);
@@ -623,7 +623,7 @@ function isDeferredContext(location: Node, lastLocation: Node | undefined): bool
623
623
  }
624
624
 
625
625
  function isTypeParameterSymbolDeclaredInContainer(symbol: Symbol, container: Node): boolean {
626
- for (const declaration of symbol.declarations)
626
+ for (const declaration of getDeclarations(symbol))
627
627
  if (declaration.kind === SyntaxKind.TypeParameter && declaration.parent === container) return true;
628
628
  return false;
629
629
  }
@@ -59,14 +59,6 @@ import type { KnownSymlinks } from './symlinks.js';
59
59
  import { isExternalModuleAugmentation } from './transformers/declarations-syntactic.js';
60
60
  import { EmitFlags } from './printer/emit-flags.js';
61
61
  import { isIdentifierText } from './scanner.js';
62
- import {
63
- CheckFlags,
64
- InternalSymbolName,
65
- type Symbol,
66
- SymbolFlags,
67
- escapeInternalSymbolName,
68
- getSymbolId,
69
- } from './symbol.js';
70
62
  import {
71
63
  getAccessibleSymbolChain,
72
64
  getAliasForSymbolInContainer,
@@ -81,6 +73,16 @@ import { SyntaxKind } from './syntax-kind.js';
81
73
  import { NodeBuilderFlags, NodeBuilderInternalFlags } from './transformers/declarations-resolver.js';
82
74
  import { TokenFlags } from './types.js';
83
75
  import { type NodeBuilder, classifyPropertyName, isNumericLiteralName } from './node-builder.js';
76
+ import {
77
+ CheckFlags,
78
+ declarationCount,
79
+ escapeInternalSymbolName,
80
+ getDeclarations,
81
+ getSymbolId,
82
+ InternalSymbolName,
83
+ type Symbol,
84
+ SymbolFlags,
85
+ } from './symbol.js';
84
86
 
85
87
  // ---- Symbol chains
86
88
 
@@ -325,7 +327,7 @@ function createAccessFromSymbolChain(
325
327
  }
326
328
  if (symbolName.length === 0) {
327
329
  let name: Node | undefined = undefined;
328
- for (const d of symbol.declarations) {
330
+ for (const d of getDeclarations(symbol)) {
329
331
  name = getNameOfDeclaration(d);
330
332
  if (name !== undefined) break;
331
333
  }
@@ -658,14 +660,14 @@ export function getNameOfSymbolAsWritten(b: NodeBuilder, symbol: Symbol): string
658
660
  (b.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope) === 0 &&
659
661
  // Not the first part of an entity name, synthesized, or from another binding context.
660
662
  ((b.flags & NodeBuilderFlags.InInitialEntityName) === 0 ||
661
- symbol.declarations.length === 0 ||
663
+ declarationCount(symbol) === 0 ||
662
664
  (b.enclosingDeclaration !== undefined &&
663
- findDefaultBindingContext(symbol.declarations[0]!) !== findDefaultBindingContext(b.enclosingDeclaration)))
665
+ findDefaultBindingContext(symbol.declaration!) !== findDefaultBindingContext(b.enclosingDeclaration)))
664
666
  )
665
667
  return 'default';
666
- if (symbol.declarations.length > 0) {
668
+ if (declarationCount(symbol) > 0) {
667
669
  let name: Node | undefined = undefined;
668
- for (const d of symbol.declarations) {
670
+ for (const d of getDeclarations(symbol)) {
669
671
  name = getNameOfDeclaration(d);
670
672
  if (name !== undefined) break;
671
673
  }
@@ -679,7 +681,7 @@ export function getNameOfSymbolAsWritten(b: NodeBuilder, symbol: Symbol): string
679
681
  }
680
682
  return declarationNameToString(getSourceFileOfNode(name), name);
681
683
  }
682
- const declaration = symbol.declarations[0]!;
684
+ const declaration = symbol.declaration!;
683
685
  const parent = declaration.parent;
684
686
  if (parent !== undefined && parent.kind === SyntaxKind.VariableDeclaration) {
685
687
  const parentName = getName(parent)!;
@@ -725,7 +727,7 @@ export function getPropertyNameNodeForSymbol(b: NodeBuilder, symbol: Symbol): No
725
727
  if (declarationName !== undefined && declarationName.kind === SyntaxKind.PrivateIdentifier)
726
728
  return b.cloneSynthesized(declarationName);
727
729
  }
728
- const declarations = symbol.declarations;
730
+ const declarations = getDeclarations(symbol);
729
731
  let stringNamed = declarations.length !== 0;
730
732
  for (const d of declarations)
731
733
  if (!isStringNamed(b, d)) {
@@ -810,7 +812,7 @@ export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, over
810
812
  const c = b.c;
811
813
  let file = asSourceFile(getDeclarationOfKind(symbol, SyntaxKind.SourceFile));
812
814
  if (file === undefined)
813
- for (const d of symbol.declarations) {
815
+ for (const d of getDeclarations(symbol)) {
814
816
  const equivalent = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, symbol);
815
817
  if (equivalent !== undefined) {
816
818
  file = asSourceFile(getDeclarationOfKind(equivalent, SyntaxKind.SourceFile));
@@ -890,14 +892,14 @@ function getModuleSpecifierHost(c: Checker): ModuleSpecifierHost {
890
892
 
891
893
  /** The name of an ambient module declaring `moduleSymbol`, or of the one whose `export =` it is, else `''`. */
892
894
  function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): string {
893
- for (const d of moduleSymbol.declarations) {
895
+ for (const d of getDeclarations(moduleSymbol)) {
894
896
  const name = isModuleWithStringLiteralName(d) ? getName(d)! : undefined;
895
897
  if (name !== undefined && (!isModuleAugmentationExternal(d) || !isExternalModuleNameRelative(getText(name))))
896
898
  return getText(name);
897
899
  }
898
900
  // A namespace exported with `export =` from an ambient module: `import { c } from "m"` names
899
901
  // `ns.c` for `declare module "m" { namespace ns { class c {} } export = ns; }`.
900
- for (const d of moduleSymbol.declarations) {
902
+ for (const d of getDeclarations(moduleSymbol)) {
901
903
  if (d.kind !== SyntaxKind.ModuleDeclaration) continue;
902
904
  let container: Node | undefined = d;
903
905
  while (container !== undefined && !isModuleWithStringLiteralName(container)) container = container.parent;
@@ -1060,7 +1062,7 @@ function asSourceFile(node: Node | undefined): SourceFile | undefined {
1060
1062
  function getSourceFileOfModule(symbol: Symbol): SourceFile | undefined {
1061
1063
  let d = symbol.valueDeclaration;
1062
1064
  if (d === undefined)
1063
- for (const declaration of symbol.declarations)
1065
+ for (const declaration of getDeclarations(symbol))
1064
1066
  if (!isExternalModuleAugmentation(declaration) && !isGlobalScopeAugmentation(declaration)) {
1065
1067
  d = declaration;
1066
1068
  break;