tsc-ts 0.0.6 → 0.0.8

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 (85) hide show
  1. package/README.md +1 -1
  2. package/dist/api/compiler/ast.d.ts +57 -18
  3. package/dist/api/compiler/ast.js +134 -39
  4. package/dist/api/compiler/binder-utilities.js +2 -2
  5. package/dist/api/compiler/binder.js +6 -6
  6. package/dist/api/compiler/checker-calls.js +4 -4
  7. package/dist/api/compiler/checker-contextual.js +1 -1
  8. package/dist/api/compiler/checker-declaration-order.js +3 -2
  9. package/dist/api/compiler/checker-declared-types.js +6 -3
  10. package/dist/api/compiler/checker-deprecation.js +14 -13
  11. package/dist/api/compiler/checker-destructuring.js +3 -2
  12. package/dist/api/compiler/checker-emit-helpers.d.ts +2 -1
  13. package/dist/api/compiler/checker-emit-helpers.js +5 -4
  14. package/dist/api/compiler/checker-grammar.js +5 -5
  15. package/dist/api/compiler/checker-inference.d.ts +20 -10
  16. package/dist/api/compiler/checker-inference.js +48 -25
  17. package/dist/api/compiler/checker-members.d.ts +27 -0
  18. package/dist/api/compiler/checker-members.js +165 -0
  19. package/dist/api/compiler/checker-modules.d.ts +14 -0
  20. package/dist/api/compiler/checker-modules.js +73 -1
  21. package/dist/api/compiler/checker-symbol-types.js +5 -5
  22. package/dist/api/compiler/checker-symbols.js +3 -1
  23. package/dist/api/compiler/checker.d.ts +16 -0
  24. package/dist/api/compiler/checker.js +17 -0
  25. package/dist/api/compiler/diagnostics.js +9 -5
  26. package/dist/api/compiler/parallel-parse.js +3 -1
  27. package/dist/api/compiler/parser.d.ts +7 -0
  28. package/dist/api/compiler/parser.js +73 -41
  29. package/dist/api/compiler/printer/factory-base.js +8 -8
  30. package/dist/api/compiler/printer/factory.js +4 -4
  31. package/dist/api/compiler/printer/printer.js +6 -6
  32. package/dist/api/compiler/program-checker.d.ts +5 -0
  33. package/dist/api/compiler/program-checker.js +11 -1
  34. package/dist/api/compiler/relations.js +8 -3
  35. package/dist/api/compiler/reparser.js +13 -5
  36. package/dist/api/compiler/transformers/class-fields.js +3 -3
  37. package/dist/api/compiler/transformers/commonjs-module.js +3 -3
  38. package/dist/api/compiler/transformers/declarations-pseudo.js +2 -2
  39. package/dist/api/compiler/transformers/module.js +2 -2
  40. package/dist/api/compiler/transformers/optional-chain.js +3 -3
  41. package/dist/api/compiler/transformers/subtree-facts.js +2 -2
  42. package/dist/api/compiler/transformers/tagged-template.js +2 -2
  43. package/dist/api/compiler/transformers/type-eraser.js +2 -2
  44. package/dist/api/compiler/transformers/visitor-base.js +3 -3
  45. package/dist/api/compiler/tsconfig.js +2 -2
  46. package/package.json +9 -9
  47. package/src/compiler/ast.ts +184 -59
  48. package/src/compiler/binder-utilities.ts +2 -1
  49. package/src/compiler/binder.ts +11 -5
  50. package/src/compiler/checker-calls.ts +5 -3
  51. package/src/compiler/checker-contextual.ts +1 -1
  52. package/src/compiler/checker-declaration-order.ts +3 -2
  53. package/src/compiler/checker-declared-types.ts +6 -3
  54. package/src/compiler/checker-deprecation.ts +13 -11
  55. package/src/compiler/checker-destructuring.ts +11 -2
  56. package/src/compiler/checker-emit-helpers.ts +5 -4
  57. package/src/compiler/checker-grammar.ts +5 -3
  58. package/src/compiler/checker-inference.ts +49 -25
  59. package/src/compiler/checker-members.ts +164 -0
  60. package/src/compiler/checker-modules.ts +92 -1
  61. package/src/compiler/checker-symbol-types.ts +14 -4
  62. package/src/compiler/checker-symbols.ts +4 -1
  63. package/src/compiler/checker.ts +19 -0
  64. package/src/compiler/decoder.ts +5 -4
  65. package/src/compiler/diagnostics.ts +10 -5
  66. package/src/compiler/encoder.ts +10 -5
  67. package/src/compiler/parallel-parse.ts +3 -1
  68. package/src/compiler/parser.ts +93 -39
  69. package/src/compiler/printer/factory-base.ts +14 -7
  70. package/src/compiler/printer/factory.ts +5 -3
  71. package/src/compiler/printer/printer.ts +8 -6
  72. package/src/compiler/program-checker.ts +10 -1
  73. package/src/compiler/relations.ts +10 -2
  74. package/src/compiler/reparser.ts +14 -4
  75. package/src/compiler/transformers/class-fields.ts +12 -2
  76. package/src/compiler/transformers/commonjs-module.ts +3 -2
  77. package/src/compiler/transformers/declarations-pseudo.ts +2 -1
  78. package/src/compiler/transformers/declarations.ts +1 -1
  79. package/src/compiler/transformers/module.ts +2 -1
  80. package/src/compiler/transformers/optional-chain.ts +5 -2
  81. package/src/compiler/transformers/subtree-facts.ts +2 -1
  82. package/src/compiler/transformers/tagged-template.ts +2 -2
  83. package/src/compiler/transformers/type-eraser.ts +2 -1
  84. package/src/compiler/transformers/visitor-base.ts +10 -5
  85. package/src/compiler/tsconfig.ts +2 -1
@@ -4075,9 +4075,45 @@ export class ElementAccessExpression extends Node {
4075
4075
 
4076
4076
  export class CallExpression extends Node {
4077
4077
  expression: Expression;
4078
+ arguments: NodeList;
4079
+
4080
+ constructor(expression: Expression, args: NodeList, flags: NodeFlags) {
4081
+ super(SyntaxKind.CallExpression);
4082
+ this.expression = expression;
4083
+ this.arguments = args;
4084
+ this.flags |= flags & NodeFlags.OptionalChain;
4085
+ }
4086
+
4087
+ forEachChild(v: NodeVisitor): boolean {
4088
+ if (v.visitNode(this.expression)) return true;
4089
+ return v.visitList(this.arguments);
4090
+ }
4091
+
4092
+ setParentOfChildren(): void {
4093
+ this.expression.parent = this;
4094
+ setParents(this.arguments.nodes, this);
4095
+ }
4096
+
4097
+ deepClone(): Node {
4098
+ return this.copy();
4099
+ }
4100
+
4101
+ copy(): CallExpression {
4102
+ const node = new CallExpression(this.expression.deepClone(), cloneList(this.arguments), this.flags);
4103
+ node.flags = this.flags;
4104
+ node.pos = this.pos;
4105
+ node.end = this.end;
4106
+ return node;
4107
+ }
4108
+ }
4109
+
4110
+ /**
4111
+ * A call with `?.` or type arguments, or in a JavaScript file, where the binder can declare a symbol
4112
+ * for it (`Object.defineProperty`). Other calls are a plain `CallExpression`, without these fields.
4113
+ */
4114
+ export class FullCallExpression extends CallExpression {
4078
4115
  questionDotToken: Token | undefined;
4079
4116
  typeArguments: NodeList | undefined;
4080
- arguments: NodeList;
4081
4117
  // Set by the binder.
4082
4118
  symbol: Symbol | undefined;
4083
4119
 
@@ -4088,12 +4124,9 @@ export class CallExpression extends Node {
4088
4124
  args: NodeList,
4089
4125
  flags: NodeFlags,
4090
4126
  ) {
4091
- super(SyntaxKind.CallExpression);
4092
- this.expression = expression;
4127
+ super(expression, args, flags);
4093
4128
  this.questionDotToken = questionDotToken;
4094
4129
  this.typeArguments = typeArguments;
4095
- this.arguments = args;
4096
- this.flags |= flags & NodeFlags.OptionalChain;
4097
4130
  this.symbol = undefined;
4098
4131
  }
4099
4132
 
@@ -4111,12 +4144,8 @@ export class CallExpression extends Node {
4111
4144
  setParents(this.arguments.nodes, this);
4112
4145
  }
4113
4146
 
4114
- deepClone(): Node {
4115
- return this.copy();
4116
- }
4117
-
4118
4147
  copy(): CallExpression {
4119
- const node = new CallExpression(
4148
+ const node = new FullCallExpression(
4120
4149
  this.expression.deepClone(),
4121
4150
  this.questionDotToken === undefined ? undefined : this.questionDotToken.copy(),
4122
4151
  this.typeArguments === undefined ? undefined : cloneList(this.typeArguments),
@@ -4130,6 +4159,28 @@ export class CallExpression extends Node {
4130
4159
  }
4131
4160
  }
4132
4161
 
4162
+ /** A `FullCallExpression` when one of its fields is set or `inJavaScript`, else a `CallExpression`. */
4163
+ export function newCallExpression(
4164
+ expression: Expression,
4165
+ questionDotToken: Token | undefined,
4166
+ typeArguments: NodeList | undefined,
4167
+ args: NodeList,
4168
+ flags: NodeFlags,
4169
+ inJavaScript: boolean,
4170
+ ): CallExpression {
4171
+ if (inJavaScript || questionDotToken !== undefined || typeArguments !== undefined)
4172
+ return new FullCallExpression(expression, questionDotToken, typeArguments, args, flags);
4173
+ return new CallExpression(expression, args, flags);
4174
+ }
4175
+
4176
+ export function callQuestionDotToken(node: CallExpression): Token | undefined {
4177
+ return node instanceof FullCallExpression ? node.questionDotToken : undefined;
4178
+ }
4179
+
4180
+ export function callTypeArguments(node: CallExpression): NodeList | undefined {
4181
+ return node instanceof FullCallExpression ? node.typeArguments : undefined;
4182
+ }
4183
+
4133
4184
  export class NewExpression extends Node {
4134
4185
  expression: Expression;
4135
4186
  typeArguments: NodeList | undefined;
@@ -4511,14 +4562,51 @@ export class SpreadAssignment extends Node {
4511
4562
  }
4512
4563
 
4513
4564
  export class PropertyAssignment extends Node {
4514
- modifiers: ModifierList | undefined;
4515
4565
  name: PropertyName;
4516
- postfixToken: Token | undefined;
4517
- type: TypeNode | undefined;
4518
4566
  initializer: Expression;
4519
4567
  // Set by the binder.
4520
4568
  symbol: Symbol | undefined;
4521
4569
 
4570
+ constructor(name: PropertyName, initializer: Expression) {
4571
+ super(SyntaxKind.PropertyAssignment);
4572
+ this.name = name;
4573
+ this.initializer = initializer;
4574
+ this.symbol = undefined;
4575
+ }
4576
+
4577
+ forEachChild(v: NodeVisitor): boolean {
4578
+ if (v.visitNode(this.name)) return true;
4579
+ return v.visitNode(this.initializer);
4580
+ }
4581
+
4582
+ setParentOfChildren(): void {
4583
+ this.name.parent = this;
4584
+ this.initializer.parent = this;
4585
+ }
4586
+
4587
+ deepClone(): Node {
4588
+ return this.copy();
4589
+ }
4590
+
4591
+ copy(): PropertyAssignment {
4592
+ const node = new PropertyAssignment(this.name.deepClone(), this.initializer.deepClone());
4593
+ node.flags = this.flags;
4594
+ node.pos = this.pos;
4595
+ node.end = this.end;
4596
+ return node;
4597
+ }
4598
+ }
4599
+
4600
+ /**
4601
+ * A property assignment with modifiers, a `?` or `!`, or a type annotation (which the grammar checker
4602
+ * reports), or in a JavaScript file, where JSDoc can give it a type or modifiers. Other property
4603
+ * assignments are a plain `PropertyAssignment`, without these fields.
4604
+ */
4605
+ export class FullPropertyAssignment extends PropertyAssignment {
4606
+ modifiers: ModifierList | undefined;
4607
+ postfixToken: Token | undefined;
4608
+ type: TypeNode | undefined;
4609
+
4522
4610
  constructor(
4523
4611
  modifiers: ModifierList | undefined,
4524
4612
  name: PropertyName,
@@ -4526,13 +4614,10 @@ export class PropertyAssignment extends Node {
4526
4614
  type: TypeNode | undefined,
4527
4615
  initializer: Expression,
4528
4616
  ) {
4529
- super(SyntaxKind.PropertyAssignment);
4617
+ super(name, initializer);
4530
4618
  this.modifiers = modifiers;
4531
- this.name = name;
4532
4619
  this.postfixToken = postfixToken;
4533
4620
  this.type = type;
4534
- this.initializer = initializer;
4535
- this.symbol = undefined;
4536
4621
  }
4537
4622
 
4538
4623
  forEachChild(v: NodeVisitor): boolean {
@@ -4551,12 +4636,8 @@ export class PropertyAssignment extends Node {
4551
4636
  this.initializer.parent = this;
4552
4637
  }
4553
4638
 
4554
- deepClone(): Node {
4555
- return this.copy();
4556
- }
4557
-
4558
4639
  copy(): PropertyAssignment {
4559
- const node = new PropertyAssignment(
4640
+ const node = new FullPropertyAssignment(
4560
4641
  this.modifiers === undefined ? undefined : cloneModifiers(this.modifiers),
4561
4642
  this.name.deepClone(),
4562
4643
  this.postfixToken === undefined ? undefined : this.postfixToken.copy(),
@@ -4570,6 +4651,32 @@ export class PropertyAssignment extends Node {
4570
4651
  }
4571
4652
  }
4572
4653
 
4654
+ /** A `FullPropertyAssignment` when one of its fields is set or `inJavaScript`, else a `PropertyAssignment`. */
4655
+ export function newPropertyAssignment(
4656
+ modifiers: ModifierList | undefined,
4657
+ name: PropertyName,
4658
+ postfixToken: Token | undefined,
4659
+ type: TypeNode | undefined,
4660
+ initializer: Expression,
4661
+ inJavaScript: boolean,
4662
+ ): PropertyAssignment {
4663
+ if (inJavaScript || modifiers !== undefined || postfixToken !== undefined || type !== undefined)
4664
+ return new FullPropertyAssignment(modifiers, name, postfixToken, type, initializer);
4665
+ return new PropertyAssignment(name, initializer);
4666
+ }
4667
+
4668
+ export function propertyAssignmentModifiers(node: PropertyAssignment): ModifierList | undefined {
4669
+ return node instanceof FullPropertyAssignment ? node.modifiers : undefined;
4670
+ }
4671
+
4672
+ export function propertyAssignmentPostfixToken(node: PropertyAssignment): Token | undefined {
4673
+ return node instanceof FullPropertyAssignment ? node.postfixToken : undefined;
4674
+ }
4675
+
4676
+ export function propertyAssignmentType(node: PropertyAssignment): TypeNode | undefined {
4677
+ return node instanceof FullPropertyAssignment ? node.type : undefined;
4678
+ }
4679
+
4573
4680
  export class ShorthandPropertyAssignment extends Node {
4574
4681
  modifiers: ModifierList | undefined;
4575
4682
  name: PropertyName;
@@ -8109,6 +8216,24 @@ export class JSDocParameterOrPropertyTag extends Node {
8109
8216
  }
8110
8217
  }
8111
8218
 
8219
+ // The lists of a source file that has none. Most files have no diagnostics, references, pragmas
8220
+ // or ambient modules, so they share these instead of holding empty arrays of their own. A list
8221
+ // that grows replaces an empty one rather than pushing to it (appendToList).
8222
+ export const emptyDiagnostics: readonly Diagnostic[] = [];
8223
+ export const emptyNodes: readonly Node[] = [];
8224
+ export const emptyStrings: readonly string[] = [];
8225
+ export const emptyCommentDirectives: readonly CommentDirective[] = [];
8226
+ export const emptyPragmas: readonly Pragma[] = [];
8227
+ export const emptyFileReferences: readonly FileReference[] = [];
8228
+ export const emptyPatternAmbientModules: readonly PatternAmbientModule[] = [];
8229
+
8230
+ /** `list` with `item` appended: a new array when `list` is empty (it may be shared), else `list` itself. */
8231
+ export function appendToList<T>(list: readonly T[], item: T): readonly T[] {
8232
+ if (list.length === 0) return [item];
8233
+ (list as T[]).push(item);
8234
+ return list;
8235
+ }
8236
+
8112
8237
  export class SourceFile extends Node {
8113
8238
  readonly fileName: string;
8114
8239
  readonly path: string;
@@ -8118,10 +8243,10 @@ export class SourceFile extends Node {
8118
8243
  endOfFileToken: Token;
8119
8244
 
8120
8245
  // Set by the parser.
8121
- diagnostics: Diagnostic[];
8246
+ diagnostics: readonly Diagnostic[];
8122
8247
  /** Diagnostics for TypeScript-only syntax in JavaScript files. */
8123
- jsDiagnostics: Diagnostic[];
8124
- jsDocDiagnostics: Diagnostic[];
8248
+ jsDiagnostics: readonly Diagnostic[];
8249
+ jsDocDiagnostics: readonly Diagnostic[];
8125
8250
  languageVariant: LanguageVariant;
8126
8251
  scriptKind: ScriptKind;
8127
8252
  isDeclarationFile: boolean;
@@ -8136,20 +8261,20 @@ export class SourceFile extends Node {
8136
8261
  /** Module specifiers of imports, exports, `require` calls and `import()` types, in source order. */
8137
8262
  imports: Node[];
8138
8263
  /** Names of `declare module "x"` augmentations and `declare global` blocks in modules. */
8139
- moduleAugmentations: Node[];
8140
- ambientModuleNames: string[];
8264
+ moduleAugmentations: readonly Node[];
8265
+ ambientModuleNames: readonly string[];
8141
8266
  commentDirectives: readonly CommentDirective[];
8142
- pragmas: Pragma[];
8143
- referencedFiles: FileReference[];
8144
- typeReferenceDirectives: FileReference[];
8145
- libReferenceDirectives: FileReference[];
8267
+ pragmas: readonly Pragma[];
8268
+ referencedFiles: readonly FileReference[];
8269
+ typeReferenceDirectives: readonly FileReference[];
8270
+ libReferenceDirectives: readonly FileReference[];
8146
8271
  checkJsDirective: CheckJsDirective | undefined;
8147
8272
  /** The first CommonJS `module.exports`/`exports.x` use in a JavaScript file. */
8148
8273
  commonJSModuleIndicator: Node | undefined;
8149
8274
  /** What makes this file a module: an import or export statement, `import.meta`, a JSX tag, or the file itself when forced. */
8150
8275
  externalModuleIndicator: Node | undefined;
8151
8276
  /** Nodes cloned by JSDoc reparsing, sorted by position. */
8152
- reparsedClones: Node[];
8277
+ reparsedClones: readonly Node[];
8153
8278
  /** Whether JSDoc of TypeScript files is parsed on first use. */
8154
8279
  hasLazyJSDoc: boolean;
8155
8280
  /**
@@ -8164,12 +8289,12 @@ export class SourceFile extends Node {
8164
8289
  locals: SymbolTable | undefined;
8165
8290
  nextContainer: Node | undefined;
8166
8291
  isBound: boolean;
8167
- bindDiagnostics: Diagnostic[];
8292
+ bindDiagnostics: readonly Diagnostic[];
8168
8293
  /** The flow at the end of the file. */
8169
8294
  endFlowNode: FlowNode | undefined;
8170
8295
  symbolCount: number;
8171
8296
  /** Ambient modules with a `*` in their name, like `declare module "*.css"`. */
8172
- patternAmbientModules: PatternAmbientModule[];
8297
+ patternAmbientModules: readonly PatternAmbientModule[];
8173
8298
  /** UMD exports from `export as namespace N`. */
8174
8299
  globalExports: SymbolTable | undefined;
8175
8300
 
@@ -8188,9 +8313,9 @@ export class SourceFile extends Node {
8188
8313
  this.externalModuleIndicatorOptions = externalModuleIndicatorOptions;
8189
8314
  this.statements = statements;
8190
8315
  this.endOfFileToken = endOfFileToken;
8191
- this.diagnostics = [];
8192
- this.jsDiagnostics = [];
8193
- this.jsDocDiagnostics = [];
8316
+ this.diagnostics = emptyDiagnostics;
8317
+ this.jsDiagnostics = emptyDiagnostics;
8318
+ this.jsDocDiagnostics = emptyDiagnostics;
8194
8319
  this.languageVariant = 0;
8195
8320
  this.scriptKind = ScriptKind.Unknown;
8196
8321
  this.isDeclarationFile = false;
@@ -8201,17 +8326,17 @@ export class SourceFile extends Node {
8201
8326
  this.nodeCount = 0;
8202
8327
  this.textCount = 0;
8203
8328
  this.imports = [];
8204
- this.moduleAugmentations = [];
8205
- this.ambientModuleNames = [];
8206
- this.commentDirectives = [];
8207
- this.pragmas = [];
8208
- this.referencedFiles = [];
8209
- this.typeReferenceDirectives = [];
8210
- this.libReferenceDirectives = [];
8329
+ this.moduleAugmentations = emptyNodes;
8330
+ this.ambientModuleNames = emptyStrings;
8331
+ this.commentDirectives = emptyCommentDirectives;
8332
+ this.pragmas = emptyPragmas;
8333
+ this.referencedFiles = emptyFileReferences;
8334
+ this.typeReferenceDirectives = emptyFileReferences;
8335
+ this.libReferenceDirectives = emptyFileReferences;
8211
8336
  this.checkJsDirective = undefined;
8212
8337
  this.commonJSModuleIndicator = undefined;
8213
8338
  this.externalModuleIndicator = undefined;
8214
- this.reparsedClones = [];
8339
+ this.reparsedClones = emptyNodes;
8215
8340
  this.hasLazyJSDoc = false;
8216
8341
  this.jsDocs = undefined;
8217
8342
  this.diagnosticFileCache = undefined;
@@ -8219,10 +8344,10 @@ export class SourceFile extends Node {
8219
8344
  this.locals = undefined;
8220
8345
  this.nextContainer = undefined;
8221
8346
  this.isBound = false;
8222
- this.bindDiagnostics = [];
8347
+ this.bindDiagnostics = emptyDiagnostics;
8223
8348
  this.endFlowNode = undefined;
8224
8349
  this.symbolCount = 0;
8225
- this.patternAmbientModules = [];
8350
+ this.patternAmbientModules = emptyPatternAmbientModules;
8226
8351
  this.globalExports = undefined;
8227
8352
  }
8228
8353
 
@@ -8703,8 +8828,8 @@ export function getModifiers(node: Node): ModifierList | undefined {
8703
8828
  }
8704
8829
  break;
8705
8830
  case SyntaxKind.PropertyAssignment:
8706
- if (node instanceof PropertyAssignment) {
8707
- const holder: PropertyAssignment = node;
8831
+ if (node instanceof FullPropertyAssignment) {
8832
+ const holder: FullPropertyAssignment = node;
8708
8833
  return holder.modifiers;
8709
8834
  }
8710
8835
  break;
@@ -9077,8 +9202,8 @@ export function getType(node: Node): Node | undefined {
9077
9202
  }
9078
9203
  break;
9079
9204
  case SyntaxKind.PropertyAssignment:
9080
- if (node instanceof PropertyAssignment) {
9081
- const holder: PropertyAssignment = node;
9205
+ if (node instanceof FullPropertyAssignment) {
9206
+ const holder: FullPropertyAssignment = node;
9082
9207
  return holder.type;
9083
9208
  }
9084
9209
  break;
@@ -9566,8 +9691,8 @@ export function getPostfixToken(node: Node): Node | undefined {
9566
9691
  }
9567
9692
  break;
9568
9693
  case SyntaxKind.PropertyAssignment:
9569
- if (node instanceof PropertyAssignment) {
9570
- const holder: PropertyAssignment = node;
9694
+ if (node instanceof FullPropertyAssignment) {
9695
+ const holder: FullPropertyAssignment = node;
9571
9696
  return holder.postfixToken;
9572
9697
  }
9573
9698
  break;
@@ -9584,8 +9709,8 @@ export function getPostfixToken(node: Node): Node | undefined {
9584
9709
  export function getTypeArguments(node: Node): NodeList | undefined {
9585
9710
  switch (node.kind) {
9586
9711
  case SyntaxKind.CallExpression:
9587
- if (node instanceof CallExpression) {
9588
- const holder: CallExpression = node;
9712
+ if (node instanceof FullCallExpression) {
9713
+ const holder: FullCallExpression = node;
9589
9714
  return holder.typeArguments;
9590
9715
  }
9591
9716
  break;
@@ -10839,8 +10964,8 @@ export function getSymbol(node: Node): Symbol | undefined {
10839
10964
  }
10840
10965
  break;
10841
10966
  case SyntaxKind.CallExpression:
10842
- if (node instanceof CallExpression) {
10843
- const holder: CallExpression = node;
10967
+ if (node instanceof FullCallExpression) {
10968
+ const holder: FullCallExpression = node;
10844
10969
  return holder.symbol;
10845
10970
  }
10846
10971
  break;
@@ -11171,8 +11296,8 @@ export function setSymbol(node: Node, value: Symbol | undefined): void {
11171
11296
  }
11172
11297
  break;
11173
11298
  case SyntaxKind.CallExpression:
11174
- if (node instanceof CallExpression) {
11175
- const target: CallExpression = node;
11299
+ if (node instanceof FullCallExpression) {
11300
+ const target: FullCallExpression = node;
11176
11301
  target.symbol = value;
11177
11302
  }
11178
11303
  break;
@@ -47,6 +47,7 @@ import {
47
47
  getTagName,
48
48
  getText,
49
49
  getType,
50
+ callQuestionDotToken,
50
51
  } from './ast.js';
51
52
  import { getJSDoc } from './parser.js';
52
53
  import { isAssignmentOperator, isLeftHandSideExpression, isStringLiteralLike, nodeIsMissing } from './ast-utilities.js';
@@ -343,7 +344,7 @@ export function skipParentheses(node: Node): Node {
343
344
  function getQuestionDotToken(node: Node): Node | undefined {
344
345
  if (node instanceof PropertyAccessExpression) return (node as PropertyAccessExpression).questionDotToken;
345
346
  if (node instanceof ElementAccessExpression) return (node as ElementAccessExpression).questionDotToken;
346
- if (node instanceof CallExpression) return (node as CallExpression).questionDotToken;
347
+ if (node instanceof CallExpression) return callQuestionDotToken(node as CallExpression);
347
348
  if (node instanceof TaggedTemplateExpression) return (node as TaggedTemplateExpression).questionDotToken;
348
349
  return undefined;
349
350
  }
@@ -4,6 +4,7 @@
4
4
  // Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
5
5
  // statically, but reads fields of a narrowed value dynamically.
6
6
  import {
7
+ appendToList,
7
8
  BinaryExpression,
8
9
  BindingElement,
9
10
  CallExpression,
@@ -72,6 +73,8 @@ import {
72
73
  setNextContainer,
73
74
  setReturnFlowNode,
74
75
  setSymbol,
76
+ callQuestionDotToken,
77
+ callTypeArguments,
75
78
  } from './ast.js';
76
79
  import {
77
80
  isAmbientModule,
@@ -795,7 +798,7 @@ class Binder extends NodeVisitor {
795
798
  }
796
799
 
797
800
  addDiagnostic(diagnostic: Diagnostic): void {
798
- this.file.bindDiagnostics.push(diagnostic);
801
+ this.file.bindDiagnostics = appendToList(this.file.bindDiagnostics, diagnostic);
799
802
  }
800
803
 
801
804
  // Traversal
@@ -1885,8 +1888,8 @@ class Binder extends NodeVisitor {
1885
1888
  this.bindOptional((node as ElementAccessExpression).questionDotToken);
1886
1889
  this.bind((node as ElementAccessExpression).argumentExpression);
1887
1890
  } else if (node instanceof CallExpression) {
1888
- this.bindOptional((node as CallExpression).questionDotToken);
1889
- this.bindNodes((node as CallExpression).typeArguments);
1891
+ this.bindOptional(callQuestionDotToken(node as CallExpression));
1892
+ this.bindNodes(callTypeArguments(node as CallExpression));
1890
1893
  this.bindNodes((node as CallExpression).arguments);
1891
1894
  }
1892
1895
  }
@@ -1897,7 +1900,7 @@ class Binder extends NodeVisitor {
1897
1900
  // An IIFE's flow node includes the evaluation of its arguments.
1898
1901
  const callee = skipParentheses(node.expression);
1899
1902
  if (callee.kind === SyntaxKind.FunctionExpression || callee.kind === SyntaxKind.ArrowFunction) {
1900
- this.bindNodes(node.typeArguments);
1903
+ this.bindNodes(callTypeArguments(node));
1901
1904
  this.bindNodes(node.arguments);
1902
1905
  this.bind(node.expression);
1903
1906
  } else {
@@ -1973,7 +1976,10 @@ class Binder extends NodeVisitor {
1973
1976
  if (starIndex >= 0 && text.indexOf('*', starIndex + 1) >= 0)
1974
1977
  this.errorOnFirstToken(name, Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, [text]);
1975
1978
  else if (starIndex >= 0)
1976
- this.file.patternAmbientModules.push(new PatternAmbientModule(text, starIndex, symbol));
1979
+ this.file.patternAmbientModules = appendToList(
1980
+ this.file.patternAmbientModules,
1981
+ new PatternAmbientModule(text, starIndex, symbol),
1982
+ );
1977
1983
  }
1978
1984
  return;
1979
1985
  }
@@ -25,6 +25,8 @@ import {
25
25
  getNodeId,
26
26
  getBody,
27
27
  getSymbol,
28
+ callQuestionDotToken,
29
+ callTypeArguments,
28
30
  } from './ast.js';
29
31
  import {
30
32
  canHaveDecorators,
@@ -238,7 +240,7 @@ export function checkCallExpression(c: Checker, node: Node, checkMode: CheckMode
238
240
  return getESSymbolLikeTypeForNode(c, walkUpParenthesizedExpressions(node.parent!));
239
241
  // An assertion call must name its target through explicitly typed declarations.
240
242
  if (
241
- call.questionDotToken === undefined &&
243
+ callQuestionDotToken(call) === undefined &&
242
244
  node.parent!.kind === SyntaxKind.ExpressionStatement &&
243
245
  (returnType.flags & TypeFlags.Void) !== 0 &&
244
246
  getTypePredicateOfSignature(c, signature) !== undefined
@@ -368,7 +370,7 @@ function resolveCallExpression(c: Checker, node: CallExpression, checkMode: Chec
368
370
  const callSignatures = getSignaturesOfType(c, apparentType, SignatureKind.Call);
369
371
  const numConstructSignatures = getSignaturesOfType(c, apparentType, SignatureKind.Construct).length;
370
372
  if (isUntypedFunctionCall(c, funcType, apparentType, callSignatures.length, numConstructSignatures)) {
371
- if (!isErrorType(c, funcType) && node.typeArguments !== undefined)
373
+ if (!isErrorType(c, funcType) && callTypeArguments(node) !== undefined)
372
374
  c.error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
373
375
  return resolveUntypedCall(c, node);
374
376
  }
@@ -382,7 +384,7 @@ function resolveCallExpression(c: Checker, node: CallExpression, checkMode: Chec
382
384
  // inferences can flow through function composition.
383
385
  if (
384
386
  (checkMode & CheckMode.SkipGenericFunctions) !== 0 &&
385
- node.typeArguments === undefined &&
387
+ callTypeArguments(node) === undefined &&
386
388
  someGenericFunctionReturningFunction(c, callSignatures)
387
389
  ) {
388
390
  skippedGenericFunction(c, node, checkMode);
@@ -277,7 +277,7 @@ export function checkExpressionWithContextualType(
277
277
  checkMode | CheckMode.Contextual | (inferenceContext !== undefined ? CheckMode.Inferential : 0),
278
278
  );
279
279
  // Intra-expression inference sites only matter during this check.
280
- if (inferenceContext !== undefined) inferenceContext.intraExpressionInferenceSites = [];
280
+ if (inferenceContext !== undefined) inferenceContext.intraExpressionInferenceSites = undefined;
281
281
  // Contextually typed literals keep their literal types rather than widening during inference.
282
282
  if (
283
283
  maybeTypeOfKind(t, TypeFlags.Literal) &&
@@ -37,7 +37,7 @@ import { getExportSymbolOfValueSymbolIfExported } from './checker-symbols.js';
37
37
  import { getBaseTypes, getDeclaredTypeOfSymbol } from './checker-declared-types.js';
38
38
  import { getPropertyOfType } from './checker-members.js';
39
39
  import { FunctionFlags, getFunctionFlags } from './checker-utilities.js';
40
- import { getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
40
+ import { declarationAt, declarationCount, type Symbol, SymbolFlags } from './symbol.js';
41
41
 
42
42
  /** Reports a block-scoped variable, class or enum resolved at `errorLocation` before its declaration. */
43
43
  export function checkResolvedBlockScopedVariable(c: Checker, resolved: Symbol, errorLocation: Node): void {
@@ -50,7 +50,8 @@ export function checkResolvedBlockScopedVariable(c: Checker, resolved: Symbol, e
50
50
  )
51
51
  return;
52
52
  let declaration: Node | undefined;
53
- for (const d of getDeclarations(result)) {
53
+ for (let i = 0; i < declarationCount(result); i++) {
54
+ const d = declarationAt(result, i);
54
55
  if (isBlockOrCatchScoped(d) || isClassLike(d) || d.kind === SyntaxKind.EnumDeclaration) {
55
56
  declaration = d;
56
57
  break;
@@ -87,7 +87,7 @@ import { getIndexedAccessType, isGenericMappedType } from './checker-type-operat
87
87
  import { getSignatureInstantiation } from './checker-signatures.js';
88
88
  import { evaluateEnumMember, EvaluatedFlags, EvaluatedKind } from './checker-evaluator.js';
89
89
  import { checkTypeAssignableTo, isTypeIdenticalTo } from './relations.js';
90
- import { getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
90
+ import { declarationAt, declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
91
91
 
92
92
  export { getParentOfSymbol };
93
93
 
@@ -877,9 +877,12 @@ export function getMinTypeArgumentCount(c: Checker, typeParameters: readonly Typ
877
877
 
878
878
  /** Whether a type parameter is declared with a default, without resolving it. */
879
879
  function hasTypeParameterDefault(t: Type): boolean {
880
- if (t.symbol === undefined) return false;
881
- for (const d of getDeclarations(t.symbol))
880
+ const symbol = t.symbol;
881
+ if (symbol === undefined) return false;
882
+ for (let i = 0; i < declarationCount(symbol); i++) {
883
+ const d = declarationAt(symbol, i);
882
884
  if (d.kind === SyntaxKind.TypeParameter && (d as TypeParameterDeclaration).defaultType !== undefined) return true;
885
+ }
883
886
  return false;
884
887
  }
885
888
 
@@ -32,7 +32,7 @@ import { entityNameToString } from './checker-expressions.js';
32
32
  import { isErrorType } from './checker-type-factory.js';
33
33
  import { getPropertyOfType } from './checker-members.js';
34
34
  import { signatureToString } from './type-printer.js';
35
- import { declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
35
+ import { declarationAt, declarationCount, getDeclarations, type Symbol, SymbolFlags } from './symbol.js';
36
36
 
37
37
  /** Whether `declaration`, or the statement it belongs to, has a `@deprecated` JSDoc tag. */
38
38
  export function isDeprecatedDeclaration(declaration: Node): boolean {
@@ -56,25 +56,26 @@ function getJSDocDeprecatedTag(node: Node): Node | undefined {
56
56
  * members when all are.
57
57
  */
58
58
  export function isDeprecatedSymbol(c: Checker, symbol: Symbol): boolean {
59
- const declarations = getDeclarations(symbol);
59
+ const count = declarationCount(symbol);
60
60
  const parentSymbol = getParentOfSymbol(c, symbol);
61
- if (parentSymbol !== undefined && declarations.length > 1)
61
+ if (parentSymbol !== undefined && count > 1)
62
62
  return (parentSymbol.flags & SymbolFlags.Interface) !== 0
63
- ? someDeprecatedDeclaration(declarations)
64
- : everyDeprecatedDeclaration(declarations);
63
+ ? someDeprecatedDeclaration(symbol)
64
+ : everyDeprecatedDeclaration(symbol);
65
65
  return (
66
66
  (symbol.valueDeclaration !== undefined && isDeprecatedDeclaration(symbol.valueDeclaration)) ||
67
- (declarations.length !== 0 && everyDeprecatedDeclaration(declarations))
67
+ (count !== 0 && everyDeprecatedDeclaration(symbol))
68
68
  );
69
69
  }
70
70
 
71
- function someDeprecatedDeclaration(declarations: readonly Node[]): boolean {
72
- for (const d of declarations) if (isDeprecatedDeclaration(d)) return true;
71
+ function someDeprecatedDeclaration(symbol: Symbol): boolean {
72
+ for (let i = 0; i < declarationCount(symbol); i++) if (isDeprecatedDeclaration(declarationAt(symbol, i))) return true;
73
73
  return false;
74
74
  }
75
75
 
76
- function everyDeprecatedDeclaration(declarations: readonly Node[]): boolean {
77
- for (const d of declarations) if (!isDeprecatedDeclaration(d)) return false;
76
+ function everyDeprecatedDeclaration(symbol: Symbol): boolean {
77
+ for (let i = 0; i < declarationCount(symbol); i++)
78
+ if (!isDeprecatedDeclaration(declarationAt(symbol, i))) return false;
78
79
  return true;
79
80
  }
80
81
 
@@ -330,7 +331,8 @@ export function checkDeprecatedTypeReference(c: Checker, node: Node, type: Type)
330
331
  if (isErrorType(c, type)) return;
331
332
  const symbol = c.resolvedSymbols.get(node.id);
332
333
  if (symbol === undefined) return;
333
- for (const d of getDeclarations(symbol)) {
334
+ for (let i = 0; i < declarationCount(symbol); i++) {
335
+ const d = declarationAt(symbol, i);
334
336
  if (isTypeDeclaration(d) && isDeprecatedDeclaration(d)) {
335
337
  addDeprecatedSuggestion(c, getDeprecatedSuggestionNode(node), getDeclarations(symbol), symbol.name);
336
338
  return;
@@ -115,7 +115,15 @@ import { TypeFacts, getNonNullableType, getTypeWithFacts, hasTypeFacts } from '.
115
115
  import { sliceTupleType } from './checker-signatures.js';
116
116
  import { getPropertyNameFromType, isTypeUsableAsPropertyName, maybeTypeOfKind } from './checker-utilities.js';
117
117
  import { checkPropertyAccessibility } from './checker-property-access.js';
118
- import { CheckFlags, copyDeclarations, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
118
+ import {
119
+ CheckFlags,
120
+ copyDeclarations,
121
+ declarationAt,
122
+ declarationCount,
123
+ getSymbolId,
124
+ type Symbol,
125
+ SymbolFlags,
126
+ } from './symbol.js';
119
127
 
120
128
  function isBindingPatternNode(node: Node | undefined): boolean {
121
129
  return (
@@ -766,7 +774,8 @@ export function isSpreadableProperty(prop: Symbol): boolean {
766
774
  (prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor)) === 0;
767
775
  let hasPrivateName = false;
768
776
  let inClass = false;
769
- for (const d of getDeclarations(prop)) {
777
+ for (let i = 0; i < declarationCount(prop); i++) {
778
+ const d = declarationAt(prop, i);
770
779
  if (isPrivateIdentifierClassElementDeclaration(d)) hasPrivateName = true;
771
780
  if (d.parent !== undefined && isClassLike(d.parent)) inClass = true;
772
781
  }