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
@@ -388,23 +388,6 @@ export class TypeAlias {
388
388
  }
389
389
  }
390
390
 
391
- /** One entry of a `TypeListCache`: the parts of its key, its value, and the next entry with the same hash. */
392
- class TypeListEntry<V> {
393
- readonly types: readonly Type[];
394
- readonly alias: TypeAlias | undefined;
395
- readonly tag: number;
396
- value: V;
397
- next: TypeListEntry<V> | undefined;
398
-
399
- constructor(types: readonly Type[], alias: TypeAlias | undefined, tag: number, value: V) {
400
- this.types = types;
401
- this.alias = alias;
402
- this.tag = tag;
403
- this.value = value;
404
- this.next = undefined;
405
- }
406
- }
407
-
408
391
  function sameTypeListParts(a: readonly Type[], b: readonly Type[]): boolean {
409
392
  if (a.length !== b.length) return false;
410
393
  for (let i = 0; i < a.length; i++) if (a[i]! !== b[i]!) return false;
@@ -421,34 +404,149 @@ function sameAliasParts(a: TypeAlias | undefined, b: TypeAlias | undefined): boo
421
404
  * aliasKey(alias)` plus a suffix spelled, without building them. A lookup takes a number hashing the
422
405
  * parts (`typeListHash`); entries keep their parts, so a match is exact and keys sharing a hash chain.
423
406
  * Like tsgo's hashed type list keys. A list must not change after it keys an entry.
407
+ *
408
+ * Entries are numbered in the order they are added: `heads` maps a hash to its first entry, and the
409
+ * lists and values of the entries are kept in arrays by number. Aliases, tags and the chains of
410
+ * entries that share a hash get arrays once an entry needs them.
424
411
  */
425
412
  export class TypeListCache<V> {
426
- private readonly entries = new Map<number, TypeListEntry<V>>();
413
+ private heads: Map<number, number>;
414
+ private lists: (readonly Type[])[];
415
+ private values: V[];
416
+ private aliases: (TypeAlias | undefined)[] | undefined;
417
+ private tags: number[] | undefined;
418
+ /** The next entry with the same hash, or -1. */
419
+ private nexts: number[] | undefined;
420
+
421
+ constructor() {
422
+ this.heads = new Map<number, number>();
423
+ this.lists = [];
424
+ this.values = [];
425
+ this.aliases = undefined;
426
+ this.tags = undefined;
427
+ this.nexts = undefined;
428
+ }
427
429
 
428
430
  get(hash: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number): V | undefined {
429
- for (let e = this.entries.get(hash); e !== undefined; e = e.next)
430
- if (e.tag === tag && sameTypeListParts(e.types, types) && sameAliasParts(e.alias, alias)) return e.value;
431
- return undefined;
431
+ const entry = this.find(hash, types, alias, tag);
432
+ return entry >= 0 ? this.values[entry] : undefined;
432
433
  }
433
434
 
434
435
  set(hash: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number, value: V): void {
435
- const head = this.entries.get(hash);
436
+ const head = this.heads.get(hash);
437
+ if (head !== undefined) {
438
+ const entry = this.findFrom(head, types, alias, tag);
439
+ if (entry >= 0) {
440
+ this.values[entry] = value;
441
+ return;
442
+ }
443
+ }
444
+ const entry = this.lists.length;
445
+ this.lists.push(types);
446
+ this.values.push(value);
447
+ const aliases = this.aliases;
448
+ if (aliases !== undefined) aliases.push(alias);
449
+ else if (alias !== undefined) {
450
+ const created: (TypeAlias | undefined)[] = [];
451
+ for (let i = 0; i < entry; i++) created.push(undefined);
452
+ created.push(alias);
453
+ this.aliases = created;
454
+ }
455
+ const tags = this.tags;
456
+ if (tags !== undefined) tags.push(tag);
457
+ else if (tag !== 0) {
458
+ const created: number[] = [];
459
+ for (let i = 0; i < entry; i++) created.push(0);
460
+ created.push(tag);
461
+ this.tags = created;
462
+ }
463
+ let nexts = this.nexts;
464
+ if (nexts !== undefined) nexts.push(-1);
436
465
  if (head === undefined) {
437
- this.entries.set(hash, new TypeListEntry(types, alias, tag, value));
466
+ this.heads.set(hash, entry);
438
467
  return;
439
468
  }
440
- for (let e: TypeListEntry<V> | undefined = head; e !== undefined; e = e.next)
441
- if (e.tag === tag && sameTypeListParts(e.types, types) && sameAliasParts(e.alias, alias)) {
442
- e.value = value;
443
- return;
444
- }
445
- const entry = new TypeListEntry(types, alias, tag, value);
446
- entry.next = head.next;
447
- head.next = entry;
469
+ // A second entry with this hash: chain it after the first.
470
+ if (nexts === undefined) {
471
+ nexts = [];
472
+ for (let i = 0; i <= entry; i++) nexts.push(-1);
473
+ this.nexts = nexts;
474
+ }
475
+ nexts[entry] = nexts[head]!;
476
+ nexts[head] = entry;
448
477
  }
449
478
 
450
479
  clear(): void {
451
- this.entries.clear();
480
+ this.heads = new Map<number, number>();
481
+ this.lists = [];
482
+ this.values = [];
483
+ this.aliases = undefined;
484
+ this.tags = undefined;
485
+ this.nexts = undefined;
486
+ }
487
+
488
+ /** The number of the entry with these parts, or -1. */
489
+ private find(hash: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number): number {
490
+ const head = this.heads.get(hash);
491
+ return head !== undefined ? this.findFrom(head, types, alias, tag) : -1;
492
+ }
493
+
494
+ private findFrom(head: number, types: readonly Type[], alias: TypeAlias | undefined, tag: number): number {
495
+ const tags = this.tags;
496
+ const aliases = this.aliases;
497
+ const nexts = this.nexts;
498
+ for (let entry = head; entry >= 0; entry = nexts !== undefined ? nexts[entry]! : -1)
499
+ if (
500
+ (tags !== undefined ? tags[entry]! : 0) === tag &&
501
+ sameTypeListParts(this.lists[entry]!, types) &&
502
+ sameAliasParts(aliases !== undefined ? aliases[entry] : undefined, alias)
503
+ )
504
+ return entry;
505
+ return -1;
506
+ }
507
+ }
508
+
509
+ /**
510
+ * One list for each sequence of types that a checker keeps (`Checker.typeLists`): references and
511
+ * instantiation caches hold the same type arguments in many places, mostly lists of one or two types,
512
+ * and share one list for them. A list must not change once it is in the table.
513
+ */
514
+ export class TypeListTable {
515
+ private readonly heads = new Map<number, number>();
516
+ private readonly lists: Type[][] = [];
517
+ /** The next list with the same hash, or -1, once two lists share one. */
518
+ private nexts: number[] | undefined = undefined;
519
+
520
+ /**
521
+ * The list in the table with the types of `types`, in order, or `types` itself, which joins the
522
+ * table. `hash` is `typeListHash(types, undefined, 0)`.
523
+ */
524
+ intern(hash: number, types: Type[]): Type[] {
525
+ if (types.length === 0) return types;
526
+ const head = this.heads.get(hash);
527
+ const nexts = this.nexts;
528
+ if (head !== undefined)
529
+ for (let entry = head; entry >= 0; entry = nexts !== undefined ? nexts[entry]! : -1) {
530
+ const list = this.lists[entry]!;
531
+ if (sameTypeListParts(list, types)) return list;
532
+ }
533
+ const entry = this.lists.length;
534
+ this.lists.push(types);
535
+ if (nexts !== undefined) nexts.push(-1);
536
+ if (head === undefined) {
537
+ this.heads.set(hash, entry);
538
+ return types;
539
+ }
540
+ // A second list with this hash: chain it after the first.
541
+ let chain = nexts;
542
+ if (chain === undefined) {
543
+ chain = [];
544
+ for (let i = 0; i <= entry; i++) chain.push(-1);
545
+ this.nexts = chain;
546
+ }
547
+ chain[entry] = chain[head]!;
548
+ chain[head] = entry;
549
+ return types;
452
550
  }
453
551
  }
454
552
 
@@ -505,7 +603,7 @@ export class TypeExtra implements ProgramLifetime {
505
603
  origin: Type | undefined;
506
604
  keyPropertyName: string;
507
605
  constituentMap: Map<Type, Type> | undefined;
508
- constituentSet: Set<Type> | undefined;
606
+ constituentIds: Int32Array | undefined;
509
607
  membershipTests: number;
510
608
  // IntersectionType
511
609
  uniqueLiteralFilledInstantiation: Type | undefined;
@@ -519,7 +617,7 @@ export class TypeExtra implements ProgramLifetime {
519
617
  this.origin = undefined;
520
618
  this.keyPropertyName = '';
521
619
  this.constituentMap = undefined;
522
- this.constituentSet = undefined;
620
+ this.constituentIds = undefined;
523
621
  this.membershipTests = 0;
524
622
  this.uniqueLiteralFilledInstantiation = undefined;
525
623
  }
@@ -1105,21 +1203,48 @@ export class EvolvingArrayType extends ObjectType {
1105
1203
  }
1106
1204
  }
1107
1205
 
1108
- export class UnionOrIntersectionType extends StructuredType {
1206
+ /**
1207
+ * A union or intersection. Few have their members resolved or their properties cached, so those
1208
+ * live in `membersOf` (`UnionOrIntersectionMembers`), which is created when they are first written.
1209
+ */
1210
+ export class UnionOrIntersectionType extends Type {
1109
1211
  readonly types: Type[];
1110
- propertyCache: SymbolTable | undefined;
1111
- propertyCacheWithoutFunctionPropertyAugment: SymbolTable | undefined;
1112
- resolvedProperties: Symbol[] | undefined;
1212
+ membersOf: UnionOrIntersectionMembers | undefined;
1113
1213
 
1114
1214
  constructor(flags: TypeFlags, objectFlags: ObjectFlags, id: number, types: Type[]) {
1115
1215
  super(flags, objectFlags, id, undefined);
1116
1216
  this.types = types;
1217
+ this.membersOf = undefined;
1218
+ }
1219
+ }
1220
+
1221
+ /**
1222
+ * The resolved members of a union or intersection (`membersHolder`) and the caches of its
1223
+ * properties, created on first use.
1224
+ */
1225
+ export class UnionOrIntersectionMembers extends StructuredType {
1226
+ propertyCache: SymbolTable | undefined;
1227
+ propertyCacheWithoutFunctionPropertyAugment: SymbolTable | undefined;
1228
+ resolvedProperties: Symbol[] | undefined;
1229
+
1230
+ constructor(flags: TypeFlags, id: number) {
1231
+ super(flags, ObjectFlags.None, id, undefined);
1117
1232
  this.propertyCache = undefined;
1118
1233
  this.propertyCacheWithoutFunctionPropertyAugment = undefined;
1119
1234
  this.resolvedProperties = undefined;
1120
1235
  }
1121
1236
  }
1122
1237
 
1238
+ /** The members holder of a union or intersection, created if it has none yet. */
1239
+ export function unionOrIntersectionMembers(t: UnionOrIntersectionType): UnionOrIntersectionMembers {
1240
+ let members = t.membersOf;
1241
+ if (members === undefined) {
1242
+ members = new UnionOrIntersectionMembers(t.flags, t.id);
1243
+ t.membersOf = members;
1244
+ }
1245
+ return members;
1246
+ }
1247
+
1123
1248
  /** A union; all of its own fields are rarely set and live in `extra`. */
1124
1249
  export class UnionType extends UnionOrIntersectionType {
1125
1250
  constructor(objectFlags: ObjectFlags, id: number, types: Type[]) {
@@ -1173,14 +1298,18 @@ export class UnionType extends UnionOrIntersectionType {
1173
1298
  if (map !== undefined || this.extra !== undefined) typeExtra(this).constituentMap = map;
1174
1299
  }
1175
1300
 
1176
- /** The constituents of a large union, for membership tests; created on the second test. */
1177
- get constituentSet(): Set<Type> | undefined {
1301
+ /**
1302
+ * A hash table of the ids of a large union's constituents, for membership tests; created on the
1303
+ * second test (`constituentTable`). About eight bytes a constituent, where a set of them took
1304
+ * about five times that.
1305
+ */
1306
+ get constituentIds(): Int32Array | undefined {
1178
1307
  const extra = this.extra;
1179
- return extra !== undefined ? extra.constituentSet : undefined;
1308
+ return extra !== undefined ? extra.constituentIds : undefined;
1180
1309
  }
1181
1310
 
1182
- set constituentSet(set: Set<Type> | undefined) {
1183
- if (set !== undefined || this.extra !== undefined) typeExtra(this).constituentSet = set;
1311
+ set constituentIds(ids: Int32Array | undefined) {
1312
+ if (ids !== undefined || this.extra !== undefined) typeExtra(this).constituentIds = ids;
1184
1313
  }
1185
1314
 
1186
1315
  get membershipTests(): number {
@@ -1694,6 +1823,45 @@ export class ArrayTypeMapper extends TypeMapper {
1694
1823
  mapsThisOnly(): boolean {
1695
1824
  return this.sources.length === 1 && isThisTypeParameter(this.sources[0]!);
1696
1825
  }
1826
+
1827
+ /** The number of targets, one per source. */
1828
+ targetCount(): number {
1829
+ return this.targets.length;
1830
+ }
1831
+
1832
+ /** The target of the source at `index`. */
1833
+ targetAt(index: number): Type {
1834
+ return this.targets[index]!;
1835
+ }
1836
+ }
1837
+
1838
+ /**
1839
+ * The mapper of a type reference's members: its type arguments, then the reference itself for the
1840
+ * last source, the class or interface's `this` type. `targets` holds the type arguments only, so the
1841
+ * reference's own list serves without a copy that adds the reference.
1842
+ */
1843
+ export class ThisArgumentTypeMapper extends ArrayTypeMapper {
1844
+ readonly thisTarget: Type;
1845
+
1846
+ constructor(sources: Type[], typeArguments: Type[], thisTarget: Type) {
1847
+ super(sources, typeArguments);
1848
+ this.thisTarget = thisTarget;
1849
+ }
1850
+
1851
+ map(type: Type): Type {
1852
+ const sources = this.sources;
1853
+ const last = sources.length - 1;
1854
+ for (let i = 0; i < last; i++) if (type === sources[i]!) return this.targets[i]!;
1855
+ return type === sources[last]! ? this.thisTarget : type;
1856
+ }
1857
+
1858
+ targetCount(): number {
1859
+ return this.targets.length + 1;
1860
+ }
1861
+
1862
+ targetAt(index: number): Type {
1863
+ return index < this.targets.length ? this.targets[index]! : this.thisTarget;
1864
+ }
1697
1865
  }
1698
1866
 
1699
1867
  /**
@@ -1771,6 +1939,18 @@ export function newTypeMapper(sources: Type[], targets: Type[]): TypeMapper {
1771
1939
  : new ArrayTypeMapper(sources, targets);
1772
1940
  }
1773
1941
 
1942
+ /** `newTypeMapper(sources, [...typeArguments, thisTarget])`, without building that list where it can. */
1943
+ export function newThisArgumentTypeMapper(sources: Type[], typeArguments: Type[], thisTarget: Type): TypeMapper {
1944
+ if (sources.length === 1) return new SimpleTypeMapper(sources[0]!, thisTarget);
1945
+ if (sources.length >= indexedTypeMapperThreshold) {
1946
+ const targets: Type[] = [];
1947
+ for (const t of typeArguments) targets.push(t);
1948
+ targets.push(thisTarget);
1949
+ return new IndexedArrayTypeMapper(sources, targets);
1950
+ }
1951
+ return new ThisArgumentTypeMapper(sources, typeArguments, thisTarget);
1952
+ }
1953
+
1774
1954
  export function mergeTypeMappers(m1: TypeMapper | undefined, m2: TypeMapper): TypeMapper {
1775
1955
  return m1 !== undefined ? new MergedTypeMapper(m1, m2) : m2;
1776
1956
  }
@@ -49,7 +49,6 @@ import {
49
49
  } from './binder-utilities.js';
50
50
  import { type Checker, createDiagnosticForNode } from './checker.js';
51
51
  import { Diagnostic, DiagnosticCategory, Diagnostics } from './diagnostics.js';
52
- import { CheckFlags, type Symbol, SymbolFlags, getSymbolId } from './symbol.js';
53
52
  import { SyntaxKind } from './syntax-kind.js';
54
53
  import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
55
54
  import { getResolvedSymbol } from './checker-expressions.js';
@@ -61,6 +60,7 @@ import type { Type } from './checker-types.js';
61
60
  import { getLiteralTypeFromPropertyName } from './checker-type-operators.js';
62
61
  import { getPropertyOfType } from './checker-members.js';
63
62
  import { getPropertyNameFromType, isTypeUsableAsPropertyName } from './checker-utilities.js';
63
+ import { CheckFlags, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
64
64
 
65
65
  // ---- References
66
66
 
@@ -438,7 +438,7 @@ function checkUnusedLocalsAndParameters(c: Checker, node: Node): void {
438
438
  (local.flags & SymbolFlags.ModuleExports) !== 0
439
439
  )
440
440
  continue;
441
- for (const declaration of local.declarations) {
441
+ for (const declaration of getDeclarations(local)) {
442
442
  switch (declaration.kind) {
443
443
  case SyntaxKind.VariableDeclaration:
444
444
  case SyntaxKind.Parameter:
@@ -634,7 +634,7 @@ function isUnreferencedTypeParameter(c: Checker, typeParameter: Node): boolean {
634
634
  }
635
635
 
636
636
  function allDeclarationsInSameSourceFile(symbol: Symbol): boolean {
637
- const declarations = symbol.declarations;
637
+ const declarations = getDeclarations(symbol);
638
638
  if (declarations.length <= 1) return true;
639
639
  const file = getSourceFileOfNode(declarations[0]!);
640
640
  for (let i = 1; i < declarations.length; i++) if (getSourceFileOfNode(declarations[i]!) !== file) return false;
@@ -33,7 +33,7 @@ import type { DeferredCollisionCheck } from './checker-generated-code.js';
33
33
  import type { EmitHelperFileLinks } from './checker-emit-helpers.js';
34
34
  import { sideOf } from './side-state.js';
35
35
  import type { Node, PatternAmbientModule, SourceFile } from './ast.js';
36
- import { IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
36
+ import { CompactSymbolLinkTable, IntLinkTable, LinkTable, SparseLinkTable } from './link-tables.js';
37
37
  import { getErrorRangeForNode, getSourceFileOfNode } from './binder-utilities.js';
38
38
  import { Diagnostic, type DiagnosticMessage, Diagnostics, compareDiagnostics } from './diagnostics.js';
39
39
  import {
@@ -66,11 +66,13 @@ import {
66
66
  emptyTypes,
67
67
  VarianceFlags,
68
68
  TypeListCache,
69
+ TypeListTable,
69
70
  type ConditionalType,
70
71
  type InterfaceType,
71
72
  type TypeChecking,
72
73
  } from './checker-types.js';
73
74
  import { getBaseTypes } from './checker-declared-types.js';
75
+ import type { ModuleResolution } from './checker-modules.js';
74
76
  import { getFalseTypeFromConditionalType, getTrueTypeFromConditionalType } from './checker-type-operators.js';
75
77
  import {
76
78
  createArrayType,
@@ -107,11 +109,11 @@ import type { FlowNode, FlowReduceLabel } from './flow.js';
107
109
  import { JsxState } from './checker-jsx.js';
108
110
  import type { DeferredIterationError, IterationTypes } from './checker-iteration.js';
109
111
  import type { SpreadIndices } from './checker-contextual.js';
110
- import type { SlotSiblingProperties } from './checker-symbol-types.js';
111
112
  import { SourceFileMetadata, getEmitModuleFormatOfFile } from './program-utilities.js';
112
113
  import type { GrammarChecker } from './checker-grammar.js';
113
114
  import type { ResolvedModule } from './module-resolution-types.js';
114
115
  import type { ModuleSpecifierHost } from './module-specifiers.js';
116
+ import type { PropertyListIndex } from './checker-members.js';
115
117
 
116
118
  /** What the checker needs from a program. */
117
119
  export abstract class CheckerHost {
@@ -264,6 +266,23 @@ function stableSort(list: Diagnostic[]): void {
264
266
  /** Maximum depth of nested `typeToString` calls before diagnostics are discarded. */
265
267
  export const maxSerializationLevel = 2;
266
268
 
269
+ /**
270
+ * File positions per symbol id in `ExternalModuleContainerIndex.keys`. Symbol ids are int32, so the
271
+ * keys stay exact.
272
+ */
273
+ export const fileIndexScale = 2 ** 21;
274
+
275
+ /** The modules that export each symbol, built once from every module's exports. */
276
+ export class ExternalModuleContainerIndex {
277
+ complete = false;
278
+ /**
279
+ * One key per symbol and module that exports it, ascending: the id of the symbol the export
280
+ * resolves to times `fileIndexScale`, plus the module's file position in `Checker.files`. The
281
+ * keys of one symbol are contiguous and in program order.
282
+ */
283
+ keys: number[] = [];
284
+ }
285
+
267
286
  /** The checker's caches for symbol accessibility. */
268
287
  export class SymbolAccessibilityCaches {
269
288
  /** Accessible chains by symbol id, then by `chainCacheKey`. */
@@ -274,6 +293,8 @@ export class SymbolAccessibilityCaches {
274
293
  readonly containersByFile = new Map<number, Map<number, Symbol[]>>();
275
294
  /** All modules that export a symbol, by symbol id. */
276
295
  readonly containers = new Map<number, Symbol[]>();
296
+ /** The modules each symbol is exported from, built on the first search of all modules. */
297
+ externalModuleContainers: ExternalModuleContainerIndex | undefined = undefined;
277
298
  /** The name tables of named class expressions, by node id. */
278
299
  readonly classExpressionNames = new Map<number, SymbolTable>();
279
300
  /** Computed declaration visibility by node id (see isDeclarationVisible), 0 if not computed. */
@@ -326,6 +347,15 @@ export class Checker implements TypeChecking {
326
347
 
327
348
  readonly diagnostics = new DiagnosticCollection();
328
349
  readonly suggestionDiagnostics = new DiagnosticCollection();
350
+ /** Diagnostics and suggestions reported so far, whether kept or not (`resolveExternalModule`'s cache). */
351
+ reports = 0;
352
+ /** `resolveExternalModule` results that reported nothing, by module specifier (checker-modules.ts). */
353
+ readonly moduleResolutions = new Map<Node, ModuleResolution>();
354
+ /**
355
+ * Whether ambient modules and module augmentations are merged. Merging can give a module a new
356
+ * merged symbol, so `resolveExternalModule` keeps results only from then on.
357
+ */
358
+ modulesMerged = false;
329
359
  /** Module specifiers of `import("…")` types, by module symbol id, importing file path and resolution mode. */
330
360
  readonly moduleSpecifiers = new Map<string, string>();
331
361
  /** Specifier generation for hosts without a program. */
@@ -340,6 +370,11 @@ export class Checker implements TypeChecking {
340
370
  readonly sideHolders = new LinkTable<Type>();
341
371
  /** The same for signatures with side state (`signatureSideOf`), by signature id. */
342
372
  readonly signatureSideHolders = new LinkTable<Signature>();
373
+ /**
374
+ * The indexes of long property lists that `propertiesRelatedTo` walks; before a list is indexed, its uses
375
+ * so far; null where a list repeats a name.
376
+ */
377
+ readonly propertyListIndexes = new Map<Symbol[], PropertyListIndex | number | null>();
343
378
  /** The type of a value symbol. */
344
379
  readonly symbolTypes = new LinkTable<Type>();
345
380
  /** For instantiated and synthetic symbols, the symbol they come from. */
@@ -360,7 +395,7 @@ export class Checker implements TypeChecking {
360
395
  /** Bits of SymbolFlags for the meanings in which a symbol was referenced. */
361
396
  readonly symbolReferenceKinds = new IntLinkTable();
362
397
  /** The resolved symbol of an identifier, entity name or call. */
363
- readonly resolvedSymbols = new SparseLinkTable<Symbol>();
398
+ readonly resolvedSymbols = new CompactSymbolLinkTable();
364
399
  /** The resolved type of a type node or expression. */
365
400
  readonly resolvedTypes = new SparseLinkTable<Type>();
366
401
  /** The resolved signature of a call-like node or a signature declaration. */
@@ -398,10 +433,6 @@ export class Checker implements TypeChecking {
398
433
  readonly unresolvedSymbols = new Map<string, Symbol>();
399
434
  /** Widening's optional `undefined` properties by the id of the property each is created from. */
400
435
  readonly undefinedProperties = new Map<number, Symbol>();
401
- /** By file and name, the property that widening's optional `undefined` properties are created from. */
402
- readonly firstSiblingProperties = new Map<SourceFile, Map<string, Node>>();
403
- /** By tsgo checker, the first sibling properties of its files (firstSiblingProperty). */
404
- readonly slotSiblingProperties = new Map<number, SlotSiblingProperties>();
405
436
 
406
437
  // Interning tables.
407
438
  readonly stringLiteralTypes = new Map<string, LiteralType>();
@@ -421,6 +452,8 @@ export class Checker implements TypeChecking {
421
452
  readonly templateLiteralTypes = new Map<string, Type>();
422
453
  /** Instantiations of template literal types: the instantiated types, tagged with the template's id. */
423
454
  readonly templateLiteralInstantiations = new TypeListCache<Type>();
455
+ /** The type argument lists that references and instantiations keep, one of each (`TypeListTable`). */
456
+ readonly typeLists = new TypeListTable();
424
457
  readonly stringMappingTypes = new Map<string, Type>();
425
458
  readonly substitutionTypes = new Map<string, Type>();
426
459
  readonly subtypeReductionCache = new TypeListCache<Type[]>();
@@ -558,6 +591,13 @@ export class Checker implements TypeChecking {
558
591
  */
559
592
  readonly freeMapperCaches: Map<number, Type>[] = [];
560
593
  freeMapperCacheCount = 0;
594
+ /** Empty lists for type arguments that are compared with cached instantiations before any is kept. */
595
+ readonly freeTypeLists: Type[][] = [];
596
+ /**
597
+ * 1 by type id for the anonymous and mapped types whose declaration has no outer type parameters
598
+ * to instantiate (`getObjectTypeInstantiation`).
599
+ */
600
+ readonly withoutOuterTypeParameters = new IntLinkTable();
561
601
  conditionalConstraintDepth = 0;
562
602
 
563
603
  readonly suggestionResolver: SuggestionNameResolver;
@@ -870,6 +910,7 @@ export class Checker implements TypeChecking {
870
910
  this.diagnostics.startLog();
871
911
  this.suggestionDiagnostics.startLog();
872
912
  mergeAmbientModulesAndAugmentations(this);
913
+ this.modulesMerged = true;
873
914
  this.mergeDiagnostics.push(this.diagnostics.takeLog(), this.suggestionDiagnostics.takeLog());
874
915
  }
875
916
 
@@ -1002,11 +1043,13 @@ export class Checker implements TypeChecking {
1002
1043
  }
1003
1044
 
1004
1045
  addDiagnostic(diagnostic: Diagnostic): void {
1046
+ this.reports++;
1005
1047
  // Discard diagnostics created while at the maximum number of nested typeToString calls.
1006
1048
  if (this.serializationLevel < maxSerializationLevel) this.diagnostics.add(diagnostic);
1007
1049
  }
1008
1050
 
1009
1051
  addSuggestion(diagnostic: Diagnostic): void {
1052
+ this.reports++;
1010
1053
  this.suggestionDiagnostics.add(diagnostic);
1011
1054
  }
1012
1055
 
@@ -1051,8 +1094,6 @@ export function disposeChecker(c: Checker): void {
1051
1094
  c.symbolAccessibilityCaches = undefined;
1052
1095
  c.unresolvedSymbols.clear();
1053
1096
  c.undefinedProperties.clear();
1054
- c.firstSiblingProperties.clear();
1055
- c.slotSiblingProperties.clear();
1056
1097
  c.stringLiteralTypes.clear();
1057
1098
  c.numberLiteralTypes.clear();
1058
1099
  c.bigintLiteralTypes.clear();
@@ -13,7 +13,6 @@ import {
13
13
  BindingPattern,
14
14
  Block,
15
15
  BreakStatement,
16
- CallExpression,
17
16
  CallSignatureDeclaration,
18
17
  CaseBlock,
19
18
  CaseOrDefaultClause,
@@ -149,7 +148,6 @@ import {
149
148
  PrefixUnaryExpression,
150
149
  PrivateIdentifier,
151
150
  PropertyAccessExpression,
152
- PropertyAssignment,
153
151
  PropertyDeclaration,
154
152
  PropertySignatureDeclaration,
155
153
  QualifiedName,
@@ -197,6 +195,8 @@ import {
197
195
  WhileStatement,
198
196
  WithStatement,
199
197
  YieldExpression,
198
+ newCallExpression,
199
+ newPropertyAssignment,
200
200
  } from './ast.js';
201
201
  import { modifiersToFlags } from './ast-utilities.js';
202
202
  import { protocolVersion } from './encoder.js';
@@ -883,7 +883,7 @@ class Decoder {
883
883
  case SyntaxKind.ElementAccessExpression:
884
884
  return new ElementAccessExpression(this.required(0), this.token(1), this.required(2), 0);
885
885
  case SyntaxKind.CallExpression:
886
- return new CallExpression(this.required(0), this.token(1), this.list(2), this.requiredList(3), 0);
886
+ return newCallExpression(this.required(0), this.token(1), this.list(2), this.requiredList(3), 0, false);
887
887
  case SyntaxKind.NewExpression:
888
888
  return new NewExpression(this.required(0), this.list(1), this.list(2));
889
889
  case SyntaxKind.MetaProperty:
@@ -910,12 +910,13 @@ class Decoder {
910
910
  case SyntaxKind.SpreadAssignment:
911
911
  return new SpreadAssignment(this.required(0));
912
912
  case SyntaxKind.PropertyAssignment:
913
- return new PropertyAssignment(
913
+ return newPropertyAssignment(
914
914
  this.modifiers(0),
915
915
  this.required(1),
916
916
  this.token(2),
917
917
  this.node(3),
918
918
  this.required(4),
919
+ false,
919
920
  );
920
921
  case SyntaxKind.ShorthandPropertyAssignment:
921
922
  return new ShorthandPropertyAssignment(