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
package/README.md CHANGED
@@ -31,7 +31,7 @@ npx tsc-ts -p tsconfig.json
31
31
  npx tsc-ts --noEmit src/index.ts
32
32
  ```
33
33
 
34
- `tsc-ts --api` serves the TypeScript API over stdin and stdout, like `tsc --api`.
34
+ `tsc-ts --api` serves the TypeScript API over stdin and stdout, like `tsc --api`. On Windows, `--api --pipe \\.\pipe\<name>` serves it over a named pipe it creates, as `tsc --api --pipe` does, for clients that connect to the pipe (such as scriptc under Node.js); only the native executable supports `--pipe`.
35
35
 
36
36
  `--checkers N` checks the program on N threads. Unless `--checkers` or `--singleThreaded` is given, the native executable uses one checker per CPU it may run on (up to 16), and at least tsgo's four; it uses fewer than the CPUs, but never fewer than four, when the estimated peak memory of more checkers would not fit 85% of the machine's memory (`TSC_TS_CHECKERS=fixed` keeps tsgo's four), and checkers beyond the fourth stop taking files, one at a time, when the process's memory reaches that share; it shares one program between its threads and also parses and binds the program's files on them. Unless `--singleThreaded` is given, the program's files are parsed and bound on threads also with `--checkers 1`, as tsgo does. Files that share costly declarations, such as a large generated schema and the few files importing it, are checked together on one checker. Under Node.js, where every thread builds its own copy of the program, tsc-ts checks on one thread unless `--checkers` is given. `--incremental`, `--watch` and `--build` always check on one thread. The diagnostics are the same as with one checker.
37
37
 
@@ -1183,16 +1183,30 @@ export declare class ElementAccessExpression extends Node {
1183
1183
  }
1184
1184
  export declare class CallExpression extends Node {
1185
1185
  expression: Expression;
1186
+ arguments: NodeList;
1187
+ constructor(expression: Expression, args: NodeList, flags: NodeFlags);
1188
+ forEachChild(v: NodeVisitor): boolean;
1189
+ setParentOfChildren(): void;
1190
+ deepClone(): Node;
1191
+ copy(): CallExpression;
1192
+ }
1193
+ /**
1194
+ * A call with `?.` or type arguments, or in a JavaScript file, where the binder can declare a symbol
1195
+ * for it (`Object.defineProperty`). Other calls are a plain `CallExpression`, without these fields.
1196
+ */
1197
+ export declare class FullCallExpression extends CallExpression {
1186
1198
  questionDotToken: Token | undefined;
1187
1199
  typeArguments: NodeList | undefined;
1188
- arguments: NodeList;
1189
1200
  symbol: Symbol | undefined;
1190
1201
  constructor(expression: Expression, questionDotToken: Token | undefined, typeArguments: NodeList | undefined, args: NodeList, flags: NodeFlags);
1191
1202
  forEachChild(v: NodeVisitor): boolean;
1192
1203
  setParentOfChildren(): void;
1193
- deepClone(): Node;
1194
1204
  copy(): CallExpression;
1195
1205
  }
1206
+ /** A `FullCallExpression` when one of its fields is set or `inJavaScript`, else a `CallExpression`. */
1207
+ export declare function newCallExpression(expression: Expression, questionDotToken: Token | undefined, typeArguments: NodeList | undefined, args: NodeList, flags: NodeFlags, inJavaScript: boolean): CallExpression;
1208
+ export declare function callQuestionDotToken(node: CallExpression): Token | undefined;
1209
+ export declare function callTypeArguments(node: CallExpression): NodeList | undefined;
1196
1210
  export declare class NewExpression extends Node {
1197
1211
  expression: Expression;
1198
1212
  typeArguments: NodeList | undefined;
@@ -1295,18 +1309,34 @@ export declare class SpreadAssignment extends Node {
1295
1309
  copy(): SpreadAssignment;
1296
1310
  }
1297
1311
  export declare class PropertyAssignment extends Node {
1298
- modifiers: ModifierList | undefined;
1299
1312
  name: PropertyName;
1300
- postfixToken: Token | undefined;
1301
- type: TypeNode | undefined;
1302
1313
  initializer: Expression;
1303
1314
  symbol: Symbol | undefined;
1304
- constructor(modifiers: ModifierList | undefined, name: PropertyName, postfixToken: Token | undefined, type: TypeNode | undefined, initializer: Expression);
1315
+ constructor(name: PropertyName, initializer: Expression);
1305
1316
  forEachChild(v: NodeVisitor): boolean;
1306
1317
  setParentOfChildren(): void;
1307
1318
  deepClone(): Node;
1308
1319
  copy(): PropertyAssignment;
1309
1320
  }
1321
+ /**
1322
+ * A property assignment with modifiers, a `?` or `!`, or a type annotation (which the grammar checker
1323
+ * reports), or in a JavaScript file, where JSDoc can give it a type or modifiers. Other property
1324
+ * assignments are a plain `PropertyAssignment`, without these fields.
1325
+ */
1326
+ export declare class FullPropertyAssignment extends PropertyAssignment {
1327
+ modifiers: ModifierList | undefined;
1328
+ postfixToken: Token | undefined;
1329
+ type: TypeNode | undefined;
1330
+ constructor(modifiers: ModifierList | undefined, name: PropertyName, postfixToken: Token | undefined, type: TypeNode | undefined, initializer: Expression);
1331
+ forEachChild(v: NodeVisitor): boolean;
1332
+ setParentOfChildren(): void;
1333
+ copy(): PropertyAssignment;
1334
+ }
1335
+ /** A `FullPropertyAssignment` when one of its fields is set or `inJavaScript`, else a `PropertyAssignment`. */
1336
+ export declare function newPropertyAssignment(modifiers: ModifierList | undefined, name: PropertyName, postfixToken: Token | undefined, type: TypeNode | undefined, initializer: Expression, inJavaScript: boolean): PropertyAssignment;
1337
+ export declare function propertyAssignmentModifiers(node: PropertyAssignment): ModifierList | undefined;
1338
+ export declare function propertyAssignmentPostfixToken(node: PropertyAssignment): Token | undefined;
1339
+ export declare function propertyAssignmentType(node: PropertyAssignment): TypeNode | undefined;
1310
1340
  export declare class ShorthandPropertyAssignment extends Node {
1311
1341
  modifiers: ModifierList | undefined;
1312
1342
  name: PropertyName;
@@ -2220,6 +2250,15 @@ export declare class JSDocParameterOrPropertyTag extends Node {
2220
2250
  deepClone(): Node;
2221
2251
  copy(): JSDocParameterOrPropertyTag;
2222
2252
  }
2253
+ export declare const emptyDiagnostics: readonly Diagnostic[];
2254
+ export declare const emptyNodes: readonly Node[];
2255
+ export declare const emptyStrings: readonly string[];
2256
+ export declare const emptyCommentDirectives: readonly CommentDirective[];
2257
+ export declare const emptyPragmas: readonly Pragma[];
2258
+ export declare const emptyFileReferences: readonly FileReference[];
2259
+ export declare const emptyPatternAmbientModules: readonly PatternAmbientModule[];
2260
+ /** `list` with `item` appended: a new array when `list` is empty (it may be shared), else `list` itself. */
2261
+ export declare function appendToList<T>(list: readonly T[], item: T): readonly T[];
2223
2262
  export declare class SourceFile extends Node {
2224
2263
  readonly fileName: string;
2225
2264
  readonly path: string;
@@ -2227,10 +2266,10 @@ export declare class SourceFile extends Node {
2227
2266
  readonly externalModuleIndicatorOptions: ExternalModuleIndicatorOptions;
2228
2267
  statements: NodeList;
2229
2268
  endOfFileToken: Token;
2230
- diagnostics: Diagnostic[];
2269
+ diagnostics: readonly Diagnostic[];
2231
2270
  /** Diagnostics for TypeScript-only syntax in JavaScript files. */
2232
- jsDiagnostics: Diagnostic[];
2233
- jsDocDiagnostics: Diagnostic[];
2271
+ jsDiagnostics: readonly Diagnostic[];
2272
+ jsDocDiagnostics: readonly Diagnostic[];
2234
2273
  languageVariant: LanguageVariant;
2235
2274
  scriptKind: ScriptKind;
2236
2275
  isDeclarationFile: boolean;
@@ -2245,20 +2284,20 @@ export declare class SourceFile extends Node {
2245
2284
  /** Module specifiers of imports, exports, `require` calls and `import()` types, in source order. */
2246
2285
  imports: Node[];
2247
2286
  /** Names of `declare module "x"` augmentations and `declare global` blocks in modules. */
2248
- moduleAugmentations: Node[];
2249
- ambientModuleNames: string[];
2287
+ moduleAugmentations: readonly Node[];
2288
+ ambientModuleNames: readonly string[];
2250
2289
  commentDirectives: readonly CommentDirective[];
2251
- pragmas: Pragma[];
2252
- referencedFiles: FileReference[];
2253
- typeReferenceDirectives: FileReference[];
2254
- libReferenceDirectives: FileReference[];
2290
+ pragmas: readonly Pragma[];
2291
+ referencedFiles: readonly FileReference[];
2292
+ typeReferenceDirectives: readonly FileReference[];
2293
+ libReferenceDirectives: readonly FileReference[];
2255
2294
  checkJsDirective: CheckJsDirective | undefined;
2256
2295
  /** The first CommonJS `module.exports`/`exports.x` use in a JavaScript file. */
2257
2296
  commonJSModuleIndicator: Node | undefined;
2258
2297
  /** What makes this file a module: an import or export statement, `import.meta`, a JSX tag, or the file itself when forced. */
2259
2298
  externalModuleIndicator: Node | undefined;
2260
2299
  /** Nodes cloned by JSDoc reparsing, sorted by position. */
2261
- reparsedClones: Node[];
2300
+ reparsedClones: readonly Node[];
2262
2301
  /** Whether JSDoc of TypeScript files is parsed on first use. */
2263
2302
  hasLazyJSDoc: boolean;
2264
2303
  /**
@@ -2271,12 +2310,12 @@ export declare class SourceFile extends Node {
2271
2310
  locals: SymbolTable | undefined;
2272
2311
  nextContainer: Node | undefined;
2273
2312
  isBound: boolean;
2274
- bindDiagnostics: Diagnostic[];
2313
+ bindDiagnostics: readonly Diagnostic[];
2275
2314
  /** The flow at the end of the file. */
2276
2315
  endFlowNode: FlowNode | undefined;
2277
2316
  symbolCount: number;
2278
2317
  /** Ambient modules with a `*` in their name, like `declare module "*.css"`. */
2279
- patternAmbientModules: PatternAmbientModule[];
2318
+ patternAmbientModules: readonly PatternAmbientModule[];
2280
2319
  /** UMD exports from `export as namespace N`. */
2281
2320
  globalExports: SymbolTable | undefined;
2282
2321
  constructor(fileName: string, path: string, text: string, externalModuleIndicatorOptions: ExternalModuleIndicatorOptions, statements: NodeList, endOfFileToken: Token);
@@ -3230,18 +3230,46 @@ export class ElementAccessExpression extends Node {
3230
3230
  }
3231
3231
  export class CallExpression extends Node {
3232
3232
  expression;
3233
+ arguments;
3234
+ constructor(expression, args, flags) {
3235
+ super(214 /* SyntaxKind.CallExpression */);
3236
+ this.expression = expression;
3237
+ this.arguments = args;
3238
+ this.flags |= flags & 32 /* NodeFlags.OptionalChain */;
3239
+ }
3240
+ forEachChild(v) {
3241
+ if (v.visitNode(this.expression))
3242
+ return true;
3243
+ return v.visitList(this.arguments);
3244
+ }
3245
+ setParentOfChildren() {
3246
+ this.expression.parent = this;
3247
+ setParents(this.arguments.nodes, this);
3248
+ }
3249
+ deepClone() {
3250
+ return this.copy();
3251
+ }
3252
+ copy() {
3253
+ const node = new CallExpression(this.expression.deepClone(), cloneList(this.arguments), this.flags);
3254
+ node.flags = this.flags;
3255
+ node.pos = this.pos;
3256
+ node.end = this.end;
3257
+ return node;
3258
+ }
3259
+ }
3260
+ /**
3261
+ * A call with `?.` or type arguments, or in a JavaScript file, where the binder can declare a symbol
3262
+ * for it (`Object.defineProperty`). Other calls are a plain `CallExpression`, without these fields.
3263
+ */
3264
+ export class FullCallExpression extends CallExpression {
3233
3265
  questionDotToken;
3234
3266
  typeArguments;
3235
- arguments;
3236
3267
  // Set by the binder.
3237
3268
  symbol;
3238
3269
  constructor(expression, questionDotToken, typeArguments, args, flags) {
3239
- super(214 /* SyntaxKind.CallExpression */);
3240
- this.expression = expression;
3270
+ super(expression, args, flags);
3241
3271
  this.questionDotToken = questionDotToken;
3242
3272
  this.typeArguments = typeArguments;
3243
- this.arguments = args;
3244
- this.flags |= flags & 32 /* NodeFlags.OptionalChain */;
3245
3273
  this.symbol = undefined;
3246
3274
  }
3247
3275
  forEachChild(v) {
@@ -3261,17 +3289,26 @@ export class CallExpression extends Node {
3261
3289
  setParents(this.typeArguments.nodes, this);
3262
3290
  setParents(this.arguments.nodes, this);
3263
3291
  }
3264
- deepClone() {
3265
- return this.copy();
3266
- }
3267
3292
  copy() {
3268
- const node = new CallExpression(this.expression.deepClone(), this.questionDotToken === undefined ? undefined : this.questionDotToken.copy(), this.typeArguments === undefined ? undefined : cloneList(this.typeArguments), cloneList(this.arguments), this.flags);
3293
+ const node = new FullCallExpression(this.expression.deepClone(), this.questionDotToken === undefined ? undefined : this.questionDotToken.copy(), this.typeArguments === undefined ? undefined : cloneList(this.typeArguments), cloneList(this.arguments), this.flags);
3269
3294
  node.flags = this.flags;
3270
3295
  node.pos = this.pos;
3271
3296
  node.end = this.end;
3272
3297
  return node;
3273
3298
  }
3274
3299
  }
3300
+ /** A `FullCallExpression` when one of its fields is set or `inJavaScript`, else a `CallExpression`. */
3301
+ export function newCallExpression(expression, questionDotToken, typeArguments, args, flags, inJavaScript) {
3302
+ if (inJavaScript || questionDotToken !== undefined || typeArguments !== undefined)
3303
+ return new FullCallExpression(expression, questionDotToken, typeArguments, args, flags);
3304
+ return new CallExpression(expression, args, flags);
3305
+ }
3306
+ export function callQuestionDotToken(node) {
3307
+ return node instanceof FullCallExpression ? node.questionDotToken : undefined;
3308
+ }
3309
+ export function callTypeArguments(node) {
3310
+ return node instanceof FullCallExpression ? node.typeArguments : undefined;
3311
+ }
3275
3312
  export class NewExpression extends Node {
3276
3313
  expression;
3277
3314
  typeArguments;
@@ -3582,22 +3619,51 @@ export class SpreadAssignment extends Node {
3582
3619
  }
3583
3620
  }
3584
3621
  export class PropertyAssignment extends Node {
3585
- modifiers;
3586
3622
  name;
3587
- postfixToken;
3588
- type;
3589
3623
  initializer;
3590
3624
  // Set by the binder.
3591
3625
  symbol;
3592
- constructor(modifiers, name, postfixToken, type, initializer) {
3626
+ constructor(name, initializer) {
3593
3627
  super(303 /* SyntaxKind.PropertyAssignment */);
3594
- this.modifiers = modifiers;
3595
3628
  this.name = name;
3596
- this.postfixToken = postfixToken;
3597
- this.type = type;
3598
3629
  this.initializer = initializer;
3599
3630
  this.symbol = undefined;
3600
3631
  }
3632
+ forEachChild(v) {
3633
+ if (v.visitNode(this.name))
3634
+ return true;
3635
+ return v.visitNode(this.initializer);
3636
+ }
3637
+ setParentOfChildren() {
3638
+ this.name.parent = this;
3639
+ this.initializer.parent = this;
3640
+ }
3641
+ deepClone() {
3642
+ return this.copy();
3643
+ }
3644
+ copy() {
3645
+ const node = new PropertyAssignment(this.name.deepClone(), this.initializer.deepClone());
3646
+ node.flags = this.flags;
3647
+ node.pos = this.pos;
3648
+ node.end = this.end;
3649
+ return node;
3650
+ }
3651
+ }
3652
+ /**
3653
+ * A property assignment with modifiers, a `?` or `!`, or a type annotation (which the grammar checker
3654
+ * reports), or in a JavaScript file, where JSDoc can give it a type or modifiers. Other property
3655
+ * assignments are a plain `PropertyAssignment`, without these fields.
3656
+ */
3657
+ export class FullPropertyAssignment extends PropertyAssignment {
3658
+ modifiers;
3659
+ postfixToken;
3660
+ type;
3661
+ constructor(modifiers, name, postfixToken, type, initializer) {
3662
+ super(name, initializer);
3663
+ this.modifiers = modifiers;
3664
+ this.postfixToken = postfixToken;
3665
+ this.type = type;
3666
+ }
3601
3667
  forEachChild(v) {
3602
3668
  if (this.modifiers !== undefined && v.visitModifiers(this.modifiers))
3603
3669
  return true;
@@ -3619,17 +3685,29 @@ export class PropertyAssignment extends Node {
3619
3685
  this.type.parent = this;
3620
3686
  this.initializer.parent = this;
3621
3687
  }
3622
- deepClone() {
3623
- return this.copy();
3624
- }
3625
3688
  copy() {
3626
- const node = new PropertyAssignment(this.modifiers === undefined ? undefined : cloneModifiers(this.modifiers), this.name.deepClone(), this.postfixToken === undefined ? undefined : this.postfixToken.copy(), this.type === undefined ? undefined : this.type.deepClone(), this.initializer.deepClone());
3689
+ const node = new FullPropertyAssignment(this.modifiers === undefined ? undefined : cloneModifiers(this.modifiers), this.name.deepClone(), this.postfixToken === undefined ? undefined : this.postfixToken.copy(), this.type === undefined ? undefined : this.type.deepClone(), this.initializer.deepClone());
3627
3690
  node.flags = this.flags;
3628
3691
  node.pos = this.pos;
3629
3692
  node.end = this.end;
3630
3693
  return node;
3631
3694
  }
3632
3695
  }
3696
+ /** A `FullPropertyAssignment` when one of its fields is set or `inJavaScript`, else a `PropertyAssignment`. */
3697
+ export function newPropertyAssignment(modifiers, name, postfixToken, type, initializer, inJavaScript) {
3698
+ if (inJavaScript || modifiers !== undefined || postfixToken !== undefined || type !== undefined)
3699
+ return new FullPropertyAssignment(modifiers, name, postfixToken, type, initializer);
3700
+ return new PropertyAssignment(name, initializer);
3701
+ }
3702
+ export function propertyAssignmentModifiers(node) {
3703
+ return node instanceof FullPropertyAssignment ? node.modifiers : undefined;
3704
+ }
3705
+ export function propertyAssignmentPostfixToken(node) {
3706
+ return node instanceof FullPropertyAssignment ? node.postfixToken : undefined;
3707
+ }
3708
+ export function propertyAssignmentType(node) {
3709
+ return node instanceof FullPropertyAssignment ? node.type : undefined;
3710
+ }
3633
3711
  export class ShorthandPropertyAssignment extends Node {
3634
3712
  modifiers;
3635
3713
  name;
@@ -6523,6 +6601,23 @@ export class JSDocParameterOrPropertyTag extends Node {
6523
6601
  return node;
6524
6602
  }
6525
6603
  }
6604
+ // The lists of a source file that has none. Most files have no diagnostics, references, pragmas
6605
+ // or ambient modules, so they share these instead of holding empty arrays of their own. A list
6606
+ // that grows replaces an empty one rather than pushing to it (appendToList).
6607
+ export const emptyDiagnostics = [];
6608
+ export const emptyNodes = [];
6609
+ export const emptyStrings = [];
6610
+ export const emptyCommentDirectives = [];
6611
+ export const emptyPragmas = [];
6612
+ export const emptyFileReferences = [];
6613
+ export const emptyPatternAmbientModules = [];
6614
+ /** `list` with `item` appended: a new array when `list` is empty (it may be shared), else `list` itself. */
6615
+ export function appendToList(list, item) {
6616
+ if (list.length === 0)
6617
+ return [item];
6618
+ list.push(item);
6619
+ return list;
6620
+ }
6526
6621
  export class SourceFile extends Node {
6527
6622
  fileName;
6528
6623
  path;
@@ -6592,9 +6687,9 @@ export class SourceFile extends Node {
6592
6687
  this.externalModuleIndicatorOptions = externalModuleIndicatorOptions;
6593
6688
  this.statements = statements;
6594
6689
  this.endOfFileToken = endOfFileToken;
6595
- this.diagnostics = [];
6596
- this.jsDiagnostics = [];
6597
- this.jsDocDiagnostics = [];
6690
+ this.diagnostics = emptyDiagnostics;
6691
+ this.jsDiagnostics = emptyDiagnostics;
6692
+ this.jsDocDiagnostics = emptyDiagnostics;
6598
6693
  this.languageVariant = 0;
6599
6694
  this.scriptKind = 0 /* ScriptKind.Unknown */;
6600
6695
  this.isDeclarationFile = false;
@@ -6605,17 +6700,17 @@ export class SourceFile extends Node {
6605
6700
  this.nodeCount = 0;
6606
6701
  this.textCount = 0;
6607
6702
  this.imports = [];
6608
- this.moduleAugmentations = [];
6609
- this.ambientModuleNames = [];
6610
- this.commentDirectives = [];
6611
- this.pragmas = [];
6612
- this.referencedFiles = [];
6613
- this.typeReferenceDirectives = [];
6614
- this.libReferenceDirectives = [];
6703
+ this.moduleAugmentations = emptyNodes;
6704
+ this.ambientModuleNames = emptyStrings;
6705
+ this.commentDirectives = emptyCommentDirectives;
6706
+ this.pragmas = emptyPragmas;
6707
+ this.referencedFiles = emptyFileReferences;
6708
+ this.typeReferenceDirectives = emptyFileReferences;
6709
+ this.libReferenceDirectives = emptyFileReferences;
6615
6710
  this.checkJsDirective = undefined;
6616
6711
  this.commonJSModuleIndicator = undefined;
6617
6712
  this.externalModuleIndicator = undefined;
6618
- this.reparsedClones = [];
6713
+ this.reparsedClones = emptyNodes;
6619
6714
  this.hasLazyJSDoc = false;
6620
6715
  this.jsDocs = undefined;
6621
6716
  this.diagnosticFileCache = undefined;
@@ -6623,10 +6718,10 @@ export class SourceFile extends Node {
6623
6718
  this.locals = undefined;
6624
6719
  this.nextContainer = undefined;
6625
6720
  this.isBound = false;
6626
- this.bindDiagnostics = [];
6721
+ this.bindDiagnostics = emptyDiagnostics;
6627
6722
  this.endFlowNode = undefined;
6628
6723
  this.symbolCount = 0;
6629
- this.patternAmbientModules = [];
6724
+ this.patternAmbientModules = emptyPatternAmbientModules;
6630
6725
  this.globalExports = undefined;
6631
6726
  }
6632
6727
  forEachChild(v) {
@@ -7090,7 +7185,7 @@ export function getModifiers(node) {
7090
7185
  }
7091
7186
  break;
7092
7187
  case 303 /* SyntaxKind.PropertyAssignment */:
7093
- if (node instanceof PropertyAssignment) {
7188
+ if (node instanceof FullPropertyAssignment) {
7094
7189
  const holder = node;
7095
7190
  return holder.modifiers;
7096
7191
  }
@@ -7461,7 +7556,7 @@ export function getType(node) {
7461
7556
  }
7462
7557
  break;
7463
7558
  case 303 /* SyntaxKind.PropertyAssignment */:
7464
- if (node instanceof PropertyAssignment) {
7559
+ if (node instanceof FullPropertyAssignment) {
7465
7560
  const holder = node;
7466
7561
  return holder.type;
7467
7562
  }
@@ -7946,7 +8041,7 @@ export function getPostfixToken(node) {
7946
8041
  }
7947
8042
  break;
7948
8043
  case 303 /* SyntaxKind.PropertyAssignment */:
7949
- if (node instanceof PropertyAssignment) {
8044
+ if (node instanceof FullPropertyAssignment) {
7950
8045
  const holder = node;
7951
8046
  return holder.postfixToken;
7952
8047
  }
@@ -7963,7 +8058,7 @@ export function getPostfixToken(node) {
7963
8058
  export function getTypeArguments(node) {
7964
8059
  switch (node.kind) {
7965
8060
  case 214 /* SyntaxKind.CallExpression */:
7966
- if (node instanceof CallExpression) {
8061
+ if (node instanceof FullCallExpression) {
7967
8062
  const holder = node;
7968
8063
  return holder.typeArguments;
7969
8064
  }
@@ -9195,7 +9290,7 @@ export function getSymbol(node) {
9195
9290
  }
9196
9291
  break;
9197
9292
  case 214 /* SyntaxKind.CallExpression */:
9198
- if (node instanceof CallExpression) {
9293
+ if (node instanceof FullCallExpression) {
9199
9294
  const holder = node;
9200
9295
  return holder.symbol;
9201
9296
  }
@@ -9526,7 +9621,7 @@ export function setSymbol(node, value) {
9526
9621
  }
9527
9622
  break;
9528
9623
  case 214 /* SyntaxKind.CallExpression */:
9529
- if (node instanceof CallExpression) {
9624
+ if (node instanceof FullCallExpression) {
9530
9625
  const target = node;
9531
9626
  target.symbol = value;
9532
9627
  }
@@ -3,7 +3,7 @@
3
3
  //
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
- import { BinaryExpression, CallExpression, ElementAccessExpression, ExpressionStatement, Identifier, JSDoc, JSDocSatisfiesTag, JsxNamespacedName, MetaProperty, ModuleDeclaration, NodeVisitor, PrefixUnaryExpression, ParenthesizedExpression, PropertyAccessExpression, TaggedTemplateExpression, TypeReferenceNode, VariableDeclaration, VariableStatement, getArguments, getAsteriskToken, getBody, getElements, getExpression, getInitializer, getMembers, getModifiers, getName, getProperties, getPropertyName, getStatements, getTagName, getText, getType, } from './ast.js';
6
+ import { BinaryExpression, CallExpression, ElementAccessExpression, ExpressionStatement, Identifier, JSDoc, JSDocSatisfiesTag, JsxNamespacedName, MetaProperty, ModuleDeclaration, NodeVisitor, PrefixUnaryExpression, ParenthesizedExpression, PropertyAccessExpression, TaggedTemplateExpression, TypeReferenceNode, VariableDeclaration, VariableStatement, getArguments, getAsteriskToken, getBody, getElements, getExpression, getInitializer, getMembers, getModifiers, getName, getProperties, getPropertyName, getStatements, getTagName, getText, getType, callQuestionDotToken, } from './ast.js';
7
7
  import { getJSDoc } from './parser.js';
8
8
  import { isAssignmentOperator, isLeftHandSideExpression, isStringLiteralLike, nodeIsMissing } from './ast-utilities.js';
9
9
  import { Scanner, computeLineOfPosition, skipTrivia } from './scanner.js';
@@ -266,7 +266,7 @@ function getQuestionDotToken(node) {
266
266
  if (node instanceof ElementAccessExpression)
267
267
  return node.questionDotToken;
268
268
  if (node instanceof CallExpression)
269
- return node.questionDotToken;
269
+ return callQuestionDotToken(node);
270
270
  if (node instanceof TaggedTemplateExpression)
271
271
  return node.questionDotToken;
272
272
  return undefined;
@@ -3,7 +3,7 @@
3
3
  //
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
- import { BinaryExpression, CallExpression, ConditionalTypeNode, ElementAccessExpression, ExportAssignment, FunctionExpression, KeywordExpression, ModuleDeclaration, NodeVisitor, PatternAmbientModule, PrefixUnaryExpression, PropertyAccessExpression, ReferenceIdentifier, TypeAliasDeclaration, VariableDeclaration, getArguments, getBody, getElements, getExpression, getInitializer, getLabel, getLocals, getModifiers, getName, getParameters, getPostfixToken, getProperties, getStatements, getSymbol, getText, isDeclarationNode, isLocalsContainer, setEndFlowNode, setFlowNode, setLocalSymbol, setLocals, setNextContainer, setReturnFlowNode, setSymbol, } from './ast.js';
6
+ import { appendToList, BinaryExpression, CallExpression, ConditionalTypeNode, ElementAccessExpression, ExportAssignment, FunctionExpression, KeywordExpression, ModuleDeclaration, NodeVisitor, PatternAmbientModule, PrefixUnaryExpression, PropertyAccessExpression, ReferenceIdentifier, TypeAliasDeclaration, VariableDeclaration, getArguments, getBody, getElements, getExpression, getInitializer, getLabel, getLocals, getModifiers, getName, getParameters, getPostfixToken, getProperties, getStatements, getSymbol, getText, isDeclarationNode, isLocalsContainer, setEndFlowNode, setFlowNode, setLocalSymbol, setLocals, setNextContainer, setReturnFlowNode, setSymbol, callQuestionDotToken, callTypeArguments, } from './ast.js';
7
7
  import { isAmbientModule, isAssignmentOperator, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLeftHandSideExpression, isRequireCall, isStringLiteralLike, nodeIsMissing, nodeIsPresent, } from './ast-utilities.js';
8
8
  import { declarationNameToString, expressionIsAlias, getAssignmentDeclarationKind, getCombinedModifierFlags, getContainingClass, getElementOrPropertyAccessName, getErrorRangeForNode, getImmediatelyInvokedFunctionExpression, getModuleInstanceState, StatementsByName, getNameOfDeclaration, getRangeOfTokenAtPosition, getSourceTextOfNode, hasDynamicName, hasSyntacticModifier, isAssignmentTarget, isAsyncFunction, isAutoAccessorPropertyDeclaration, isBlockOrCatchScoped, isBooleanLiteral, isDeclarationStatementKind, isDestructuringAssignment, isDottedName, isEntityNameExpression, isEnumConst, isExpandoInitializer, isExpressionOfOptionalChainRoot, isExternalModule, isExternalOrCommonJSModule, isIdentifierName, isImplicitlyExportedJSDocDeclaration, isInTopLevelContext, isJsonSourceFile, isLogicalExpression, isLogicalOrCoalescingAssignmentExpression, isLogicalOrCoalescingAssignmentOperator, isLogicalOrCoalescingBinaryOperator, isModuleAugmentationExternal, isNullishCoalesce, isObjectLiteralMethod, isObjectLiteralOrClassExpressionMethodOrAccessor, isOptionalChain, isOptionalChainRoot, isOutermostOptionalChain, isParameterPropertyDeclaration, isPartOfParameterDeclaration, isPartOfTypeQuery, isPotentiallyExecutableNode, isPrologueDirective, isPropertyNameLiteral, isPushOrUnshiftIdentifier, isSignedNumericLiteral, isStatic, isStringOrNumericLiteralLike, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, nodeText, skipParentheses, } from './binder-utilities.js';
9
9
  import { Diagnostic } from './diagnostics.js';
@@ -541,7 +541,7 @@ class Binder extends NodeVisitor {
541
541
  this.addDiagnostic(new Diagnostic(this.file.diagnosticFile(), range.pos, range.end, message, args));
542
542
  }
543
543
  addDiagnostic(diagnostic) {
544
- this.file.bindDiagnostics.push(diagnostic);
544
+ this.file.bindDiagnostics = appendToList(this.file.bindDiagnostics, diagnostic);
545
545
  }
546
546
  // Traversal
547
547
  bindOptional(node) {
@@ -1619,8 +1619,8 @@ class Binder extends NodeVisitor {
1619
1619
  this.bind(node.argumentExpression);
1620
1620
  }
1621
1621
  else if (node instanceof CallExpression) {
1622
- this.bindOptional(node.questionDotToken);
1623
- this.bindNodes(node.typeArguments);
1622
+ this.bindOptional(callQuestionDotToken(node));
1623
+ this.bindNodes(callTypeArguments(node));
1624
1624
  this.bindNodes(node.arguments);
1625
1625
  }
1626
1626
  }
@@ -1631,7 +1631,7 @@ class Binder extends NodeVisitor {
1631
1631
  // An IIFE's flow node includes the evaluation of its arguments.
1632
1632
  const callee = skipParentheses(node.expression);
1633
1633
  if (callee.kind === 219 /* SyntaxKind.FunctionExpression */ || callee.kind === 220 /* SyntaxKind.ArrowFunction */) {
1634
- this.bindNodes(node.typeArguments);
1634
+ this.bindNodes(callTypeArguments(node));
1635
1635
  this.bindNodes(node.arguments);
1636
1636
  this.bind(node.expression);
1637
1637
  }
@@ -1697,7 +1697,7 @@ class Binder extends NodeVisitor {
1697
1697
  if (starIndex >= 0 && text.indexOf('*', starIndex + 1) >= 0)
1698
1698
  this.errorOnFirstToken(name, 1136 /* Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character */, [text]);
1699
1699
  else if (starIndex >= 0)
1700
- this.file.patternAmbientModules.push(new PatternAmbientModule(text, starIndex, symbol));
1700
+ this.file.patternAmbientModules = appendToList(this.file.patternAmbientModules, new PatternAmbientModule(text, starIndex, symbol));
1701
1701
  }
1702
1702
  return;
1703
1703
  }
@@ -1,7 +1,7 @@
1
1
  // Calls, `new` and tagged templates: signature resolution with type argument inference and overload
2
2
  // selection, argument checks and resolution errors.
3
3
  import { checkDeprecatedSignature } from './checker-deprecation.js';
4
- import { Node, getArguments as getArgumentList, getExpression, getName, getParameters, getText, getTypeArguments as getTypeArgumentList, getNodeId, getBody, getSymbol, } from './ast.js';
4
+ import { Node, getArguments as getArgumentList, getExpression, getName, getParameters, getText, getTypeArguments as getTypeArgumentList, getNodeId, getBody, getSymbol, callQuestionDotToken, callTypeArguments, } from './ast.js';
5
5
  import { canHaveDecorators, getEffectiveCheckNode, isFunctionLikeDeclarationKind, isImportCall, nodeIsPresent, } from './ast-utilities.js';
6
6
  import { getContainingClass, getSourceFileOfNode, isAccessExpression, isExpressionOfOptionalChainRoot, isOptionalChain, isOutermostOptionalChain, isDottedName, } from './binder-utilities.js';
7
7
  import { Diagnostic, chainDiagnostic } from './diagnostics.js';
@@ -72,7 +72,7 @@ export function checkCallExpression(c, node, checkMode) {
72
72
  if ((returnType.flags & 16896 /* TypeFlags.ESSymbolLike */) !== 0 && isSymbolOrSymbolForCall(c, call))
73
73
  return getESSymbolLikeTypeForNode(c, walkUpParenthesizedExpressions(node.parent));
74
74
  // An assertion call must name its target through explicitly typed declarations.
75
- if (call.questionDotToken === undefined &&
75
+ if (callQuestionDotToken(call) === undefined &&
76
76
  node.parent.kind === 245 /* SyntaxKind.ExpressionStatement */ &&
77
77
  (returnType.flags & 16 /* TypeFlags.Void */) !== 0 &&
78
78
  getTypePredicateOfSignature(c, signature) !== undefined) {
@@ -196,7 +196,7 @@ function resolveCallExpression(c, node, checkMode) {
196
196
  const callSignatures = getSignaturesOfType(c, apparentType, 0 /* SignatureKind.Call */);
197
197
  const numConstructSignatures = getSignaturesOfType(c, apparentType, 1 /* SignatureKind.Construct */).length;
198
198
  if (isUntypedFunctionCall(c, funcType, apparentType, callSignatures.length, numConstructSignatures)) {
199
- if (!isErrorType(c, funcType) && node.typeArguments !== undefined)
199
+ if (!isErrorType(c, funcType) && callTypeArguments(node) !== undefined)
200
200
  c.error(node, 523 /* Diagnostics.Untyped_function_calls_may_not_accept_type_arguments */);
201
201
  return resolveUntypedCall(c, node);
202
202
  }
@@ -210,7 +210,7 @@ function resolveCallExpression(c, node, checkMode) {
210
210
  // An inner generic call returning a function is deferred while an outer call infers, so that
211
211
  // inferences can flow through function composition.
212
212
  if ((checkMode & 8 /* CheckMode.SkipGenericFunctions */) !== 0 &&
213
- node.typeArguments === undefined &&
213
+ callTypeArguments(node) === undefined &&
214
214
  someGenericFunctionReturningFunction(c, callSignatures)) {
215
215
  skippedGenericFunction(c, node, checkMode);
216
216
  return c.resolvingSignature;
@@ -110,7 +110,7 @@ export function checkExpressionWithContextualType(c, node, contextualType, infer
110
110
  let t = checkExpressionEx(c, node, checkMode | 1 /* CheckMode.Contextual */ | (inferenceContext !== undefined ? 2 /* CheckMode.Inferential */ : 0));
111
111
  // Intra-expression inference sites only matter during this check.
112
112
  if (inferenceContext !== undefined)
113
- inferenceContext.intraExpressionInferenceSites = [];
113
+ inferenceContext.intraExpressionInferenceSites = undefined;
114
114
  // Contextually typed literals keep their literal types rather than widening during inference.
115
115
  if (maybeTypeOfKind(t, 15360 /* TypeFlags.Literal */) &&
116
116
  isLiteralOfContextualType(c, t, instantiateContextualType(c, contextualType, node, 0 /* ContextFlags.None */)))
@@ -12,7 +12,7 @@ import { getExportSymbolOfValueSymbolIfExported } from './checker-symbols.js';
12
12
  import { getBaseTypes, getDeclaredTypeOfSymbol } from './checker-declared-types.js';
13
13
  import { getPropertyOfType } from './checker-members.js';
14
14
  import { getFunctionFlags } from './checker-utilities.js';
15
- import { getDeclarations } from './symbol.js';
15
+ import { declarationAt, declarationCount } from './symbol.js';
16
16
  /** Reports a block-scoped variable, class or enum resolved at `errorLocation` before its declaration. */
17
17
  export function checkResolvedBlockScopedVariable(c, resolved, errorLocation) {
18
18
  const result = getExportSymbolOfValueSymbolIfExported(c, resolved);
@@ -23,7 +23,8 @@ export function checkResolvedBlockScopedVariable(c, resolved, errorLocation) {
23
23
  (result.flags & 32 /* SymbolFlags.Class */) !== 0)
24
24
  return;
25
25
  let declaration;
26
- for (const d of getDeclarations(result)) {
26
+ for (let i = 0; i < declarationCount(result); i++) {
27
+ const d = declarationAt(result, i);
27
28
  if (isBlockOrCatchScoped(d) || isClassLike(d) || d.kind === 267 /* SyntaxKind.EnumDeclaration */) {
28
29
  declaration = d;
29
30
  break;
@@ -20,7 +20,7 @@ import { getIndexedAccessType, isGenericMappedType } from './checker-type-operat
20
20
  import { getSignatureInstantiation } from './checker-signatures.js';
21
21
  import { evaluateEnumMember } from './checker-evaluator.js';
22
22
  import { checkTypeAssignableTo, isTypeIdenticalTo } from './relations.js';
23
- import { getDeclarations } from './symbol.js';
23
+ import { declarationAt, declarationCount, getDeclarations } from './symbol.js';
24
24
  export { getParentOfSymbol };
25
25
  export function getDeclaredTypeOfSymbol(c, symbol) {
26
26
  return tryGetDeclaredTypeOfSymbol(c, symbol) ?? c.errorType;
@@ -752,11 +752,14 @@ export function getMinTypeArgumentCount(c, typeParameters) {
752
752
  }
753
753
  /** Whether a type parameter is declared with a default, without resolving it. */
754
754
  function hasTypeParameterDefault(t) {
755
- if (t.symbol === undefined)
755
+ const symbol = t.symbol;
756
+ if (symbol === undefined)
756
757
  return false;
757
- for (const d of getDeclarations(t.symbol))
758
+ for (let i = 0; i < declarationCount(symbol); i++) {
759
+ const d = declarationAt(symbol, i);
758
760
  if (d.kind === 169 /* SyntaxKind.TypeParameter */ && d.defaultType !== undefined)
759
761
  return true;
762
+ }
760
763
  return false;
761
764
  }
762
765
  export function fillMissingTypeArguments(c, typeArguments, typeParameters, minTypeArgumentCount, isJavaScriptImplicitAny) {