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
@@ -1,7 +1,7 @@
1
1
  import { type Node } from './ast.js';
2
- import { type Symbol } from './symbol.js';
3
2
  import type { Checker, VarianceReporting } from './checker.js';
4
3
  import { IndexInfo, type ObjectType, Signature, type Type, TypeAlias, TypeMapper, TypeParameter } from './checker-types.js';
4
+ import { type Symbol } from './symbol.js';
5
5
  /** Applies `m1`, then instantiates its result with `m2`, or applies `m2` when `m1` doesn't map. */
6
6
  export declare class CompositeTypeMapper extends TypeMapper {
7
7
  readonly c: Checker;
@@ -1,7 +1,6 @@
1
1
  // Instantiation: mappers that need the checker, and `instantiateType` for every kind of type.
2
2
  import { lazyObjectFlags, sideOf, sideOfIfAny } from './side-state.js';
3
3
  import { NodeVisitor, getBody, getInitializer, getParameters, getType, getTypeArguments as getTypeArgumentNodes, getTypeParameters as getTypeParameterNodes, } from './ast.js';
4
- import { getSymbolId } from './symbol.js';
5
4
  import { cachedTypeKey, IndexInfo, Signature, TypeAlias, TypeMapper, emptyTypes, newTypeMapper, SimpleTypeMapper, TypeListCache, } from './checker-types.js';
6
5
  import { createDeferredTypeReference, createNormalizedTypeReference, getIntersectionType, getIntersectionTypeEx, getPropagatingFlagsOfTypes, getTemplateLiteralType, getTypeArguments, getUnionTypeEx, newObjectType, aliasKey, typesOf, typeListHash, } from './checker-type-factory.js';
7
6
  import { getOuterTypeParameters } from './checker-declared-types.js';
@@ -10,6 +9,7 @@ import { getConditionalTypeInstantiation, getIndexType, getIndexedAccessTypeEx,
10
9
  import { getConstraintDeclaration } from './checker-declared-types.js';
11
10
  import { isTypeAssignableTo } from './relations.js';
12
11
  import { getFirstIdentifier } from './checker-symbols.js';
12
+ import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
13
13
  // ---- Mappers that need the checker
14
14
  /** Applies `m1`, then instantiates its result with `m2`, or applies `m2` when `m1` doesn't map. */
15
15
  export class CompositeTypeMapper extends TypeMapper {
@@ -88,8 +88,19 @@ export function instantiateType(c, type, mapper) {
88
88
  export function instantiateTypeWithAlias(c, type, mapper, alias) {
89
89
  if (mapper === undefined)
90
90
  return type;
91
- // Aliases with type arguments may be copied with new arguments even when the type itself has no type variables.
92
- if (!couldContainTypeVariables(c, type) && !aliasCouldContainTypeVariables(c, type))
91
+ // `couldContainTypeVariables`, answered here when the type's own flags decide it. Aliases with type
92
+ // arguments may be copied with new arguments even when the type itself has no type variables.
93
+ let could;
94
+ if ((type.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) === 0)
95
+ could = false;
96
+ else {
97
+ const objectFlags = type.objectFlags;
98
+ could =
99
+ (objectFlags & 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */) !== 0
100
+ ? (objectFlags & 1048576 /* ObjectFlags.CouldContainTypeVariables */) !== 0
101
+ : couldContainTypeVariables(c, type);
102
+ }
103
+ if (!could && (type.alias === undefined || !aliasCouldContainTypeVariables(c, type)))
93
104
  return type;
94
105
  if (c.instantiationDepth === 100 || c.instantiationCount >= 5000000) {
95
106
  // Probably infinitely expanding generic types; stop with the error type.
@@ -218,7 +229,7 @@ export function couldContainTypeVariables(c, type) {
218
229
  32 /* SymbolFlags.Class */ |
219
230
  2048 /* SymbolFlags.TypeLiteral */ |
220
231
  4096 /* SymbolFlags.ObjectLiteral */)) !==
221
- 0 && type.symbol.declarations.length !== 0;
232
+ 0 && declarationCount(type.symbol) !== 0;
222
233
  }
223
234
  if (!result)
224
235
  result =
@@ -249,7 +260,7 @@ function isNonGenericTopLevelType(type) {
249
260
  if (alias === undefined || alias.typeArguments.length !== 0)
250
261
  return false;
251
262
  let declaration;
252
- for (const d of alias.symbol.declarations)
263
+ for (const d of getDeclarations(alias.symbol))
253
264
  if (d.kind === 266 /* SyntaxKind.TypeAliasDeclaration */ || d.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */) {
254
265
  declaration = d;
255
266
  break;
@@ -346,13 +357,15 @@ function instantiateTypeWorker(c, type, mapper, alias) {
346
357
  }
347
358
  /** Instantiates anonymous types, deferred references, instantiation expressions and mapped types. */
348
359
  function getObjectTypeInstantiation(c, type, mapper, alias) {
360
+ if ((type.objectFlags & 4 /* ObjectFlags.Reference */) === 0 && c.withoutOuterTypeParameters.get(type.id) !== 0)
361
+ return type;
349
362
  let declaration;
350
363
  if ((type.objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
351
364
  declaration = type.node;
352
365
  else if ((type.objectFlags & 16777216 /* ObjectFlags.InstantiationExpressionType */) !== 0)
353
366
  declaration = type.node;
354
367
  else
355
- declaration = type.symbol.declarations[0];
368
+ declaration = type.symbol.declaration;
356
369
  const links = c.nodeLinks(declaration);
357
370
  let target;
358
371
  if ((type.objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
@@ -376,7 +389,7 @@ function getObjectTypeInstantiation(c, type, mapper, alias) {
376
389
  else if ((target.symbol.flags & (8192 /* SymbolFlags.Method */ | 2048 /* SymbolFlags.TypeLiteral */)) !== 0) {
377
390
  const referenced = [];
378
391
  for (const tp of typeParameters) {
379
- for (const d of type.symbol.declarations) {
392
+ for (const d of getDeclarations(type.symbol)) {
380
393
  if (isTypeParameterPossiblyReferenced(c, tp, d)) {
381
394
  referenced.push(tp);
382
395
  break;
@@ -388,16 +401,27 @@ function getObjectTypeInstantiation(c, type, mapper, alias) {
388
401
  }
389
402
  links.outerTypeParameters = typeParameters;
390
403
  }
391
- if (typeParameters.length === 0)
404
+ if (typeParameters.length === 0) {
405
+ if ((type.objectFlags & 4 /* ObjectFlags.Reference */) === 0)
406
+ c.withoutOuterTypeParameters.set(type.id, 1);
392
407
  return type;
393
- const combinedMapper = combineTypeMappers(c, type.mapper, mapper);
394
- const typeArguments = [];
395
- for (const tp of typeParameters)
396
- typeArguments.push(combinedMapper.map(tp));
408
+ }
409
+ // The type arguments, mapped as `combineTypeMappers(c, type.mapper, mapper)` maps them, into a
410
+ // list of the checker's that is copied only when the instantiation is new.
411
+ const typeMapper = type.mapper;
412
+ const mapped = c.freeTypeLists.pop() ?? [];
413
+ for (const tp of typeParameters) {
414
+ if (typeMapper === undefined)
415
+ mapped.push(mapper.map(tp));
416
+ else {
417
+ const t1 = typeMapper.map(tp);
418
+ mapped.push(t1 !== tp ? instantiateType(c, t1, mapper) : mapper.map(tp));
419
+ }
420
+ }
397
421
  const newAlias = alias ?? instantiateTypeAlias(c, type.alias, mapper);
398
422
  const singleSignature = (type.objectFlags & 33554432 /* ObjectFlags.SingleSignatureType */) !== 0;
399
423
  const tag = singleSignature ? 1 : 0;
400
- const hash = typeListHash(typeArguments, newAlias, tag);
424
+ const hash = typeListHash(mapped, newAlias, tag);
401
425
  const generic = sideOf(c, target);
402
426
  let instantiations = generic.instantiations;
403
427
  if (instantiations === undefined) {
@@ -405,33 +429,41 @@ function getObjectTypeInstantiation(c, type, mapper, alias) {
405
429
  instantiations.set(typeListHash(typeParameters, target.alias, 0), typeParameters, target.alias, 0, target);
406
430
  generic.instantiations = instantiations;
407
431
  }
408
- let result = instantiations.get(hash, typeArguments, newAlias, tag);
409
- if (result === undefined) {
410
- let newMapper = newTypeMapper(typeParameters, typeArguments);
411
- if ((target.objectFlags & 33554432 /* ObjectFlags.SingleSignatureType */) !== 0)
412
- newMapper = combineTypeMappers(c, newMapper, mapper);
413
- if ((target.objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
414
- result = createDeferredTypeReference(c, type.target, type.node, newMapper, newAlias);
415
- else if ((target.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0)
416
- result = instantiateMappedType(c, target, newMapper, newAlias);
417
- else
418
- result = instantiateAnonymousType(c, target, newMapper, newAlias);
419
- instantiations.set(hash, typeArguments, newAlias, tag, result);
420
- if ((result.flags & 403963917 /* TypeFlags.ObjectFlagsType */) !== 0 &&
421
- (lazyObjectFlags(c, result) & 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */) === 0) {
422
- // Type variable containment follows from the type arguments.
423
- let couldContain = false;
424
- for (const t of typeArguments)
425
- if (couldContainTypeVariables(c, t)) {
426
- couldContain = true;
427
- break;
428
- }
429
- if ((result.objectFlags & (32 /* ObjectFlags.Mapped */ | 16 /* ObjectFlags.Anonymous */ | 4 /* ObjectFlags.Reference */)) !== 0)
430
- sideOf(c, result).objectFlags |=
431
- 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */ | (couldContain ? 1048576 /* ObjectFlags.CouldContainTypeVariables */ : 0);
432
- else if (!couldContain)
433
- sideOf(c, result).objectFlags |= 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */;
434
- }
432
+ const cached = instantiations.get(hash, mapped, newAlias, tag);
433
+ if (cached !== undefined) {
434
+ mapped.length = 0;
435
+ c.freeTypeLists.push(mapped);
436
+ return cached;
437
+ }
438
+ // The cache and the instantiation's mapper keep the type arguments.
439
+ const typeArguments = c.typeLists.intern(typeListHash(mapped, undefined, 0), mapped.slice());
440
+ mapped.length = 0;
441
+ c.freeTypeLists.push(mapped);
442
+ let result;
443
+ let newMapper = newTypeMapper(typeParameters, typeArguments);
444
+ if ((target.objectFlags & 33554432 /* ObjectFlags.SingleSignatureType */) !== 0)
445
+ newMapper = combineTypeMappers(c, newMapper, mapper);
446
+ if ((target.objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
447
+ result = createDeferredTypeReference(c, type.target, type.node, newMapper, newAlias);
448
+ else if ((target.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0)
449
+ result = instantiateMappedType(c, target, newMapper, newAlias);
450
+ else
451
+ result = instantiateAnonymousType(c, target, newMapper, newAlias);
452
+ instantiations.set(hash, typeArguments, newAlias, tag, result);
453
+ if ((result.flags & 403963917 /* TypeFlags.ObjectFlagsType */) !== 0 &&
454
+ (lazyObjectFlags(c, result) & 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */) === 0) {
455
+ // Type variable containment follows from the type arguments.
456
+ let couldContain = false;
457
+ for (const t of typeArguments)
458
+ if (couldContainTypeVariables(c, t)) {
459
+ couldContain = true;
460
+ break;
461
+ }
462
+ if ((result.objectFlags & (32 /* ObjectFlags.Mapped */ | 16 /* ObjectFlags.Anonymous */ | 4 /* ObjectFlags.Reference */)) !== 0)
463
+ sideOf(c, result).objectFlags |=
464
+ 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */ | (couldContain ? 1048576 /* ObjectFlags.CouldContainTypeVariables */ : 0);
465
+ else if (!couldContain)
466
+ sideOf(c, result).objectFlags |= 524288 /* ObjectFlags.CouldContainTypeVariablesComputed */;
435
467
  }
436
468
  return result;
437
469
  }
@@ -464,14 +496,14 @@ class ReferenceFinder extends NodeVisitor {
464
496
  if (firstIdentifier.kind !== 109 /* SyntaxKind.ThisKeyword */ &&
465
497
  !(firstIdentifier.kind === 79 /* SyntaxKind.Identifier */ && firstIdentifier.text === 'this')) {
466
498
  const symbol = getResolvedSymbolOfIdentifier(this.c, firstIdentifier);
467
- const tpDeclaration = tp.symbol.declarations[0];
499
+ const tpDeclaration = tp.symbol.declaration;
468
500
  let scope;
469
501
  if (tpDeclaration.kind === 169 /* SyntaxKind.TypeParameter */)
470
502
  scope = tpDeclaration.parent;
471
503
  else if (tp.isThisType)
472
504
  scope = tpDeclaration;
473
505
  if (scope !== undefined) {
474
- for (const d of symbol.declarations)
506
+ for (const d of getDeclarations(symbol))
475
507
  if (isNodeDescendantOf(d, scope))
476
508
  return true;
477
509
  const args = getTypeArgumentNodes(node);
@@ -521,10 +553,10 @@ export function isNodeDescendantOf(node, ancestor) {
521
553
  */
522
554
  export function isTypeParameterPossiblyReferenced(c, tp, node) {
523
555
  const typeParameter = tp;
524
- if (tp.symbol === undefined || tp.symbol.declarations.length !== 1)
556
+ if (tp.symbol === undefined || declarationCount(tp.symbol) !== 1)
525
557
  return true;
526
558
  const finder = new ReferenceFinder(c, typeParameter);
527
- const container = tp.symbol.declarations[0].parent;
559
+ const container = tp.symbol.declaration.parent;
528
560
  for (let n = node; n !== container; n = n.parent) {
529
561
  if (n === undefined || n.kind === 242 /* SyntaxKind.Block */)
530
562
  return true;
@@ -562,9 +594,13 @@ export function cloneTypeParameter(c, tp) {
562
594
  return result;
563
595
  }
564
596
  export function instantiateTypeAlias(c, alias, mapper) {
565
- return alias === undefined
566
- ? undefined
567
- : new TypeAlias(alias.symbol, instantiateTypes(c, alias.typeArguments, mapper));
597
+ if (alias === undefined)
598
+ return undefined;
599
+ const typeArguments = instantiateTypes(c, alias.typeArguments, mapper);
600
+ // The alias's type keeps its type arguments.
601
+ return new TypeAlias(alias.symbol, typeArguments === alias.typeArguments
602
+ ? typeArguments
603
+ : c.typeLists.intern(typeListHash(typeArguments, undefined, 0), typeArguments));
568
604
  }
569
605
  /** Instantiates each type; returns `types` itself when nothing changed. */
570
606
  export function instantiateTypes(c, types, mapper) {
@@ -688,7 +724,7 @@ export function newInstantiatedSymbol(c, symbol, mapper) {
688
724
  1 /* CheckFlags.Instantiated */ |
689
725
  (symbol.checkFlags &
690
726
  (8 /* CheckFlags.Readonly */ | 4096 /* CheckFlags.Late */ | 16384 /* CheckFlags.OptionalParameter */ | 32768 /* CheckFlags.RestParameter */));
691
- result.declarations = symbol.declarations;
727
+ copyDeclarations(result, symbol);
692
728
  result.parent = symbol.parent;
693
729
  result.valueDeclaration = symbol.valueDeclaration;
694
730
  const id = getSymbolId(result);
@@ -699,9 +735,9 @@ export function newInstantiatedSymbol(c, symbol, mapper) {
699
735
  }
700
736
  /** Conservatively, whether a parameter or member's type can't reference `this`. */
701
737
  export function isThisless(symbol) {
702
- if (symbol.declarations.length !== 1)
738
+ if (declarationCount(symbol) !== 1)
703
739
  return false;
704
- const declaration = symbol.declarations[0];
740
+ const declaration = symbol.declaration;
705
741
  switch (declaration.kind) {
706
742
  case 170 /* SyntaxKind.Parameter */:
707
743
  case 173 /* SyntaxKind.PropertyDeclaration */:
@@ -1,3 +1,4 @@
1
+ import type { Symbol } from './symbol.js';
1
2
  /** Links are stored in pages of 256 ids. */
2
3
  export declare const enum LinkPaging {
3
4
  Bits = 8,
@@ -34,3 +35,71 @@ export declare class SparseLinkTable<T> {
34
35
  set(id: number, value: T | undefined): void;
35
36
  clear(): void;
36
37
  }
38
+ /**
39
+ * Values by id for ids in a few clusters, as one file's emit uses them: the file's nodes and the
40
+ * nodes the emit synthesizes, far above them. Pages of `LinkPaging.Size` ids are found through a
41
+ * map from the page index, so the ids between clusters cost nothing, and the page of the last
42
+ * lookup is kept, since lookups come in runs of nearby ids.
43
+ */
44
+ export declare class ClusteredLinkTable<T> {
45
+ private readonly pages;
46
+ private lastIndex;
47
+ private lastPage;
48
+ get(id: number): T | undefined;
49
+ set(id: number, value: T | undefined): void;
50
+ private pageOf;
51
+ }
52
+ /** Int32 values by id, zero where none is stored, for ids in a few clusters (`ClusteredLinkTable`). */
53
+ export declare class ClusteredIntLinkTable {
54
+ private readonly pages;
55
+ private lastIndex;
56
+ private lastPage;
57
+ get(id: number): number;
58
+ set(id: number, value: number): void;
59
+ private pageOf;
60
+ }
61
+ /**
62
+ * A page of a `CompactSymbolLinkTable`: one bit per id of the page in eight 32-id words, the number
63
+ * of symbols stored before each word, and the symbols in id order. The words are fields, so a
64
+ * lookup reads one object before the symbols. The class isn't generic, so natively the words are
65
+ * 32-bit fields: every write stores an int32.
66
+ */
67
+ declare class CompactLinkPage {
68
+ readonly values: Symbol[];
69
+ private w0;
70
+ private w1;
71
+ private w2;
72
+ private w3;
73
+ private w4;
74
+ private w5;
75
+ private w6;
76
+ private w7;
77
+ /** Byte `w & 3` of `before0` (words 1 to 3) or of `before1` (words 4 to 7): the values before word `w`. */
78
+ private before0;
79
+ private before1;
80
+ constructor();
81
+ /** The presence bits of ids `32 * word` to `32 * word + 31`. */
82
+ word(word: number): number;
83
+ setWord(word: number, bits: number): void;
84
+ /** The index in `values` of the value of `slot` (an id's low bits), or of where it goes. */
85
+ rank(slot: number, bits: number): number;
86
+ /** Adds `delta` to the counts of the words after `word`. */
87
+ shiftCounts(word: number, delta: number): void;
88
+ }
89
+ /**
90
+ * Symbols by node id, for ids a checker resolves in one in four to one in eight of the ids of the
91
+ * pages it touches, as it resolves the identifiers and names of the files it checks. Pages of
92
+ * `LinkPaging.Size` ids keep a presence bit per id and only the symbols stored, so a symbol costs
93
+ * about one array slot. A `LinkTable` page costs a slot for every id, and a `Map` entry also
94
+ * stores its key and a share of the hash buckets. At fewer values per page than that, the page's
95
+ * own allocations outweigh what it saves, and a `SparseLinkTable` costs less.
96
+ */
97
+ export declare class CompactSymbolLinkTable {
98
+ readonly pages: (CompactLinkPage | undefined)[];
99
+ /** The number of symbols stored. */
100
+ size: number;
101
+ get(id: number): Symbol | undefined;
102
+ set(id: number, value: Symbol | undefined): void;
103
+ clear(): void;
104
+ }
105
+ export {};
@@ -81,3 +81,239 @@ export class SparseLinkTable {
81
81
  this.values.clear();
82
82
  }
83
83
  }
84
+ /**
85
+ * Values by id for ids in a few clusters, as one file's emit uses them: the file's nodes and the
86
+ * nodes the emit synthesizes, far above them. Pages of `LinkPaging.Size` ids are found through a
87
+ * map from the page index, so the ids between clusters cost nothing, and the page of the last
88
+ * lookup is kept, since lookups come in runs of nearby ids.
89
+ */
90
+ export class ClusteredLinkTable {
91
+ pages = new Map();
92
+ lastIndex = -1;
93
+ lastPage = undefined;
94
+ get(id) {
95
+ const page = this.pageOf(id >> 8 /* LinkPaging.Bits */);
96
+ return page !== undefined ? page[id & 255 /* LinkPaging.Mask */] : undefined;
97
+ }
98
+ set(id, value) {
99
+ const index = id >> 8 /* LinkPaging.Bits */;
100
+ const page = this.pageOf(index);
101
+ if (page !== undefined)
102
+ page[id & 255 /* LinkPaging.Mask */] = value;
103
+ else if (value !== undefined) {
104
+ const created = [];
105
+ for (let i = 0; i < 256 /* LinkPaging.Size */; i++)
106
+ created.push(undefined);
107
+ created[id & 255 /* LinkPaging.Mask */] = value;
108
+ this.pages.set(index, created);
109
+ this.lastPage = created;
110
+ }
111
+ }
112
+ pageOf(index) {
113
+ if (index !== this.lastIndex) {
114
+ this.lastIndex = index;
115
+ this.lastPage = this.pages.get(index);
116
+ }
117
+ return this.lastPage;
118
+ }
119
+ }
120
+ /** Int32 values by id, zero where none is stored, for ids in a few clusters (`ClusteredLinkTable`). */
121
+ export class ClusteredIntLinkTable {
122
+ pages = new Map();
123
+ lastIndex = -1;
124
+ lastPage = undefined;
125
+ get(id) {
126
+ const page = this.pageOf(id >> 8 /* LinkPaging.Bits */);
127
+ return page !== undefined ? page[id & 255 /* LinkPaging.Mask */] : 0;
128
+ }
129
+ set(id, value) {
130
+ const index = id >> 8 /* LinkPaging.Bits */;
131
+ const page = this.pageOf(index);
132
+ if (page !== undefined)
133
+ page[id & 255 /* LinkPaging.Mask */] = value;
134
+ else if (value !== 0) {
135
+ const created = new Int32Array(256 /* LinkPaging.Size */);
136
+ created[id & 255 /* LinkPaging.Mask */] = value;
137
+ this.pages.set(index, created);
138
+ this.lastPage = created;
139
+ }
140
+ }
141
+ pageOf(index) {
142
+ if (index !== this.lastIndex) {
143
+ this.lastIndex = index;
144
+ this.lastPage = this.pages.get(index);
145
+ }
146
+ return this.lastPage;
147
+ }
148
+ }
149
+ /** The number of set bits of a 32-bit value. */
150
+ function bitCount(x) {
151
+ x = x - ((x >>> 1) & 0x55555555);
152
+ x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
153
+ x = (x + (x >>> 4)) & 0x0f0f0f0f;
154
+ return Math.imul(x, 0x01010101) >>> 24;
155
+ }
156
+ /**
157
+ * A page of a `CompactSymbolLinkTable`: one bit per id of the page in eight 32-id words, the number
158
+ * of symbols stored before each word, and the symbols in id order. The words are fields, so a
159
+ * lookup reads one object before the symbols. The class isn't generic, so natively the words are
160
+ * 32-bit fields: every write stores an int32.
161
+ */
162
+ class CompactLinkPage {
163
+ values;
164
+ w0;
165
+ w1;
166
+ w2;
167
+ w3;
168
+ w4;
169
+ w5;
170
+ w6;
171
+ w7;
172
+ /** Byte `w & 3` of `before0` (words 1 to 3) or of `before1` (words 4 to 7): the values before word `w`. */
173
+ before0;
174
+ before1;
175
+ constructor() {
176
+ this.values = [];
177
+ this.w0 = 0;
178
+ this.w1 = 0;
179
+ this.w2 = 0;
180
+ this.w3 = 0;
181
+ this.w4 = 0;
182
+ this.w5 = 0;
183
+ this.w6 = 0;
184
+ this.w7 = 0;
185
+ this.before0 = 0;
186
+ this.before1 = 0;
187
+ }
188
+ /** The presence bits of ids `32 * word` to `32 * word + 31`. */
189
+ word(word) {
190
+ switch (word) {
191
+ case 0:
192
+ return this.w0;
193
+ case 1:
194
+ return this.w1;
195
+ case 2:
196
+ return this.w2;
197
+ case 3:
198
+ return this.w3;
199
+ case 4:
200
+ return this.w4;
201
+ case 5:
202
+ return this.w5;
203
+ case 6:
204
+ return this.w6;
205
+ default:
206
+ return this.w7;
207
+ }
208
+ }
209
+ setWord(word, bits) {
210
+ switch (word) {
211
+ case 0:
212
+ this.w0 = bits | 0;
213
+ break;
214
+ case 1:
215
+ this.w1 = bits | 0;
216
+ break;
217
+ case 2:
218
+ this.w2 = bits | 0;
219
+ break;
220
+ case 3:
221
+ this.w3 = bits | 0;
222
+ break;
223
+ case 4:
224
+ this.w4 = bits | 0;
225
+ break;
226
+ case 5:
227
+ this.w5 = bits | 0;
228
+ break;
229
+ case 6:
230
+ this.w6 = bits | 0;
231
+ break;
232
+ default:
233
+ this.w7 = bits | 0;
234
+ }
235
+ }
236
+ /** The index in `values` of the value of `slot` (an id's low bits), or of where it goes. */
237
+ rank(slot, bits) {
238
+ const word = slot >> 5;
239
+ const before = ((word < 4 ? this.before0 : this.before1) >>> ((word & 3) << 3)) & 0xff;
240
+ return before + bitCount(bits & ((1 << (slot & 31)) - 1));
241
+ }
242
+ /** Adds `delta` to the counts of the words after `word`. */
243
+ shiftCounts(word, delta) {
244
+ for (let w = word + 1; w < 8; w++) {
245
+ const step = delta << ((w & 3) << 3);
246
+ if (w < 4)
247
+ this.before0 = (this.before0 + step) | 0;
248
+ else
249
+ this.before1 = (this.before1 + step) | 0;
250
+ }
251
+ }
252
+ }
253
+ /**
254
+ * Symbols by node id, for ids a checker resolves in one in four to one in eight of the ids of the
255
+ * pages it touches, as it resolves the identifiers and names of the files it checks. Pages of
256
+ * `LinkPaging.Size` ids keep a presence bit per id and only the symbols stored, so a symbol costs
257
+ * about one array slot. A `LinkTable` page costs a slot for every id, and a `Map` entry also
258
+ * stores its key and a share of the hash buckets. At fewer values per page than that, the page's
259
+ * own allocations outweigh what it saves, and a `SparseLinkTable` costs less.
260
+ */
261
+ export class CompactSymbolLinkTable {
262
+ pages = [];
263
+ /** The number of symbols stored. */
264
+ size = 0;
265
+ get(id) {
266
+ const page = this.pages[id >> 8 /* LinkPaging.Bits */];
267
+ if (page === undefined)
268
+ return undefined;
269
+ const slot = id & 255 /* LinkPaging.Mask */;
270
+ const bits = page.word(slot >> 5);
271
+ if ((bits & (1 << (slot & 31))) === 0)
272
+ return undefined;
273
+ return page.values[page.rank(slot, bits)];
274
+ }
275
+ set(id, value) {
276
+ const index = id >> 8 /* LinkPaging.Bits */;
277
+ let page = this.pages[index];
278
+ if (page === undefined) {
279
+ if (value === undefined)
280
+ return;
281
+ while (this.pages.length <= index)
282
+ this.pages.push(undefined);
283
+ page = new CompactLinkPage();
284
+ this.pages[index] = page;
285
+ }
286
+ const slot = id & 255 /* LinkPaging.Mask */;
287
+ const word = slot >> 5;
288
+ const bit = 1 << (slot & 31);
289
+ const bits = page.word(word);
290
+ const at = page.rank(slot, bits);
291
+ const values = page.values;
292
+ if ((bits & bit) !== 0) {
293
+ if (value !== undefined) {
294
+ values[at] = value;
295
+ return;
296
+ }
297
+ for (let i = at; i < values.length - 1; i++)
298
+ values[i] = values[i + 1];
299
+ values.pop();
300
+ page.setWord(word, bits & ~bit);
301
+ page.shiftCounts(word, -1);
302
+ this.size--;
303
+ return;
304
+ }
305
+ if (value === undefined)
306
+ return;
307
+ values.push(value);
308
+ for (let i = values.length - 1; i > at; i--)
309
+ values[i] = values[i - 1];
310
+ values[at] = value;
311
+ page.setWord(word, bits | bit);
312
+ page.shiftCounts(word, 1);
313
+ this.size++;
314
+ }
315
+ clear() {
316
+ this.pages.length = 0;
317
+ this.size = 0;
318
+ }
319
+ }
@@ -6,7 +6,7 @@ import { BindingElement, ConditionalTypeNode, HeritageClause, ModuleDeclaration,
6
6
  import { isFunctionLike, isFunctionLikeDeclarationKind, isInJSFile, isRequireCall } from './ast-utilities.js';
7
7
  import { findConstructorDeclaration, getDeclarationOfKind, getImmediatelyInvokedFunctionExpression, getSourceFileOfNode, hasSyntacticModifier, hasStaticModifier, isClassElement, isClassLike, isConstAssertion, isExternalOrCommonJSModule, isGlobalSourceFile, isNullishCoalesce, isOptionalChain, isPartOfParameterDeclaration, isStatic, isTypeNodeKind, } from './binder-utilities.js';
8
8
  import { getEmitScriptTarget, getIsolatedModules, getUseDefineForClassFields, } from './options.js';
9
- import { Symbol } from './symbol.js';
9
+ import { getDeclarations, Symbol } from './symbol.js';
10
10
  export class NameResolver {
11
11
  compilerOptions;
12
12
  /** The global symbol table; empty unless the checker sets it. */
@@ -459,7 +459,7 @@ function isInParameter(declaration) {
459
459
  }
460
460
  /** The local symbol of an `export default` declaration. */
461
461
  export function getLocalSymbolForExportDefault(symbol) {
462
- const declarations = symbol.declarations;
462
+ const declarations = getDeclarations(symbol);
463
463
  if (declarations.length === 0 || !hasSyntacticModifier(declarations[0], 2048 /* ModifierFlags.Default */))
464
464
  return undefined;
465
465
  for (const declaration of declarations) {
@@ -486,7 +486,7 @@ function isDeferredContext(location, lastLocation) {
486
486
  return getImmediatelyInvokedFunctionExpression(location) === undefined;
487
487
  }
488
488
  function isTypeParameterSymbolDeclaredInContainer(symbol, container) {
489
- for (const declaration of symbol.declarations)
489
+ for (const declaration of getDeclarations(symbol))
490
490
  if (declaration.kind === 169 /* SyntaxKind.TypeParameter */ && declaration.parent === container)
491
491
  return true;
492
492
  return false;
@@ -2,8 +2,8 @@ import { type Node, type NodeList, SourceFile } from './ast.js';
2
2
  import type { Checker } from './checker.js';
3
3
  import { ModuleSpecifierPreferences } from './module-specifiers.js';
4
4
  import { ModuleKind } from './options.js';
5
- import { type Symbol, SymbolFlags } from './symbol.js';
6
5
  import { type NodeBuilder } from './node-builder.js';
6
+ import { type Symbol, SymbolFlags } from './symbol.js';
7
7
  /** The chain of symbols naming `symbol`, reported to the tracker. */
8
8
  export declare function lookupSymbolChain(b: NodeBuilder, symbol: Symbol, meaning: SymbolFlags, yieldModuleSymbol: boolean): Symbol[];
9
9
  /** A type node naming `symbol` with `mask`: a type reference, `typeof`, indexed access or `import("…")`. */