tsc-ts 0.1.0 → 0.1.2

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 (81) hide show
  1. package/README.md +7 -1
  2. package/dist/api/compiler/ast.d.ts +15 -3
  3. package/dist/api/compiler/ast.js +36 -15
  4. package/dist/api/compiler/checker-classes.js +2 -1
  5. package/dist/api/compiler/checker-contextual.d.ts +20 -0
  6. package/dist/api/compiler/checker-contextual.js +111 -1
  7. package/dist/api/compiler/checker-expressions.js +14 -1
  8. package/dist/api/compiler/checker-grammar.d.ts +39 -4
  9. package/dist/api/compiler/checker-grammar.js +239 -75
  10. package/dist/api/compiler/checker-heritage.js +20 -14
  11. package/dist/api/compiler/checker-jsx.js +2 -1
  12. package/dist/api/compiler/checker-modules.js +4 -2
  13. package/dist/api/compiler/checker-source-file.js +1 -1
  14. package/dist/api/compiler/checker-type-factory.js +70 -19
  15. package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
  16. package/dist/api/compiler/checker-type-nodes.js +5 -5
  17. package/dist/api/compiler/checker-unused.js +15 -10
  18. package/dist/api/compiler/checker.d.ts +7 -1
  19. package/dist/api/compiler/checker.js +14 -4
  20. package/dist/api/compiler/compile-program.d.ts +5 -0
  21. package/dist/api/compiler/compile-program.js +8 -0
  22. package/dist/api/compiler/expr-record.d.ts +11 -0
  23. package/dist/api/compiler/expr-record.js +53 -0
  24. package/dist/api/compiler/file-loader.d.ts +5 -0
  25. package/dist/api/compiler/file-loader.js +7 -0
  26. package/dist/api/compiler/identifier-name.d.ts +9 -0
  27. package/dist/api/compiler/identifier-name.js +10 -0
  28. package/dist/api/compiler/jsdoc.js +4 -2
  29. package/dist/api/compiler/parser.d.ts +2 -1
  30. package/dist/api/compiler/parser.js +10 -8
  31. package/dist/api/compiler/printer/factory.js +3 -2
  32. package/dist/api/compiler/printer/printer.js +3 -2
  33. package/dist/api/compiler/program-checker.d.ts +18 -0
  34. package/dist/api/compiler/program-checker.js +27 -0
  35. package/dist/api/compiler/reparser.js +4 -3
  36. package/dist/api/compiler/scanner.d.ts +8 -0
  37. package/dist/api/compiler/scanner.js +58 -42
  38. package/dist/api/compiler/shared-results.d.ts +376 -143
  39. package/dist/api/compiler/shared-results.js +1550 -773
  40. package/dist/api/compiler/transformers/declarations.js +2 -1
  41. package/package.json +15 -10
  42. package/src/compiler/ast.ts +39 -15
  43. package/src/compiler/cgroup.ts +157 -0
  44. package/src/compiler/checker-classes.ts +2 -1
  45. package/src/compiler/checker-contextual.ts +104 -0
  46. package/src/compiler/checker-expressions.ts +16 -1
  47. package/src/compiler/checker-grammar.ts +247 -88
  48. package/src/compiler/checker-heritage.ts +31 -17
  49. package/src/compiler/checker-jsx.ts +2 -1
  50. package/src/compiler/checker-modules.ts +4 -2
  51. package/src/compiler/checker-source-file.ts +1 -1
  52. package/src/compiler/checker-type-factory.ts +67 -21
  53. package/src/compiler/checker-type-nodes.ts +5 -5
  54. package/src/compiler/checker-unused.ts +13 -8
  55. package/src/compiler/checker.ts +15 -4
  56. package/src/compiler/compile-program.ts +8 -0
  57. package/src/compiler/decoder.ts +2 -1
  58. package/src/compiler/doctor-report.ts +133 -0
  59. package/src/compiler/expr-record.ts +59 -0
  60. package/src/compiler/file-loader.ts +8 -0
  61. package/src/compiler/identifier-name.ts +13 -0
  62. package/src/compiler/jsdoc.ts +4 -2
  63. package/src/compiler/parallel-check.ts +364 -146
  64. package/src/compiler/parallel-emit.ts +3 -3
  65. package/src/compiler/parse-thread.ts +24 -2
  66. package/src/compiler/parser.ts +10 -8
  67. package/src/compiler/printer/factory.ts +3 -2
  68. package/src/compiler/printer/printer.ts +4 -2
  69. package/src/compiler/program-checker.ts +28 -0
  70. package/src/compiler/reparser.ts +7 -3
  71. package/src/compiler/run-config.ts +1383 -0
  72. package/src/compiler/run-record-read.ts +87 -0
  73. package/src/compiler/run-records.ts +575 -0
  74. package/src/compiler/scanner.ts +57 -41
  75. package/src/compiler/shared-results.ts +1626 -896
  76. package/src/compiler/thread-entry.ts +3 -1
  77. package/src/compiler/transformers/declarations.ts +2 -1
  78. package/src/compiler/tsc-build.ts +64 -6
  79. package/src/compiler/tsc-cli.ts +33 -4
  80. package/src/compiler/tsc-compile.ts +223 -9
  81. package/src/compiler/tsc-watch.ts +25 -4
@@ -17,7 +17,7 @@ import { isGenericType } from './checker-type-operators.js';
17
17
  import { getPropertyNameFromType, isTypeUsableAsPropertyName, isValidIndexKeyType } from './checker-utilities.js';
18
18
  import { getSymbolOfDeclaration, resolveAlias } from './checker-symbols.js';
19
19
  import { Diagnostic, messageCategory } from './diagnostics.js';
20
- import { ModuleKind, ScriptTarget, getEmitModuleKind, supportsDeferredImports, supportsSourcePhaseImports, } from './options.js';
20
+ import { ModuleKind, ScriptTarget, getEmitModuleKind, getEmitScriptTarget, supportsDeferredImports, supportsSourcePhaseImports, } from './options.js';
21
21
  import { getEmitSyntaxForModuleSpecifierExpression } from './checker-modules.js';
22
22
  import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
23
23
  import { SourceFileMetadata, getEmitModuleFormatOfFile, getImpliedNodeFormatForEmit, resolutionModeAttribute, } from './program-utilities.js';
@@ -26,11 +26,39 @@ import { typeToString } from './type-printer.js';
26
26
  import { getDeclarations } from './symbol.js';
27
27
  /** Runs the grammar checks of every node of `file`. */
28
28
  export function checkGrammarSourceFile(c, file) {
29
+ const diagnostics = file.grammarDiagnostics;
30
+ const residualNodes = file.grammarResidualNodes;
31
+ // A parse thread walked the file: it reported the checks that don't need the checker, and left the
32
+ // nodes of the checks that do (checkGrammarSourceFileInParseThread).
33
+ if (diagnostics !== undefined && residualNodes !== undefined) {
34
+ for (const diagnostic of diagnostics)
35
+ c.addDiagnostic(diagnostic);
36
+ if (residualNodes.length === 0)
37
+ return;
38
+ const g = new GrammarChecker(c, file, undefined, undefined, file.grammarAmbientReports);
39
+ for (const node of residualNodes)
40
+ g.visitNode(node);
41
+ return;
42
+ }
29
43
  const g = new GrammarChecker(c, file);
30
44
  if ((file.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
31
45
  checkGrammarTopLevelElementsForRequiredDeclareModifier(g, file);
32
46
  file.forEachChild(g);
33
47
  }
48
+ /**
49
+ * Runs the grammar checks of `file` in a parse thread, before the file is published: the checks that
50
+ * don't need the checker report now, and the nodes of those that do are kept for the checker, which
51
+ * runs them in the same tree order (`checkGrammarSourceFile`).
52
+ */
53
+ export function checkGrammarSourceFileInParseThread(file, options, metadata) {
54
+ const g = new GrammarChecker(undefined, file, options, metadata);
55
+ if ((file.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
56
+ checkGrammarTopLevelElementsForRequiredDeclareModifier(g, file);
57
+ file.forEachChild(g);
58
+ file.grammarDiagnostics = g.diagnostics;
59
+ file.grammarResidualNodes = g.residualNodes;
60
+ file.grammarAmbientReports = [...g.reportedAmbientStatements];
61
+ }
34
62
  /** The grammar checker of the file of `node`, for grammar checks run while checking expressions. */
35
63
  function grammarCheckerOf(c, node) {
36
64
  const file = getSourceFileOfNode(node);
@@ -65,7 +93,10 @@ export function checkGrammarYieldOfExpression(c, node) {
65
93
  }
66
94
  /** Per-file state of the grammar walk. */
67
95
  export class GrammarChecker extends NodeVisitor {
96
+ /** The checker of a walk in the checker thread; undefined for a walk in a parse thread. */
68
97
  c;
98
+ compilerOptions;
99
+ languageVersion;
69
100
  file;
70
101
  /** Grammar errors are only reported in files without parse errors. */
71
102
  hasParseErrors;
@@ -73,22 +104,95 @@ export class GrammarChecker extends NodeVisitor {
73
104
  metadata;
74
105
  legacyDecorators;
75
106
  /** Blocks and statements that already reported a statement in an ambient context. */
76
- reportedAmbientStatements = new Set();
107
+ reportedAmbientStatements;
108
+ /**
109
+ * The IDs `reportedAmbientStatements` gained in a parse thread's walk, in the order it gained them, so
110
+ * that the reports of a node whose check the checker runs are undone without copying the set.
111
+ * Undefined in the checker thread, where no check is undone.
112
+ */
113
+ ambientReportLog;
114
+ /**
115
+ * The diagnostics of a walk in a parse thread, which has no checker, for the checker to add to its
116
+ * collection; undefined in the checker thread, where they are reported as they are found.
117
+ */
118
+ diagnostics;
119
+ /** The nodes of a parse thread's walk whose check needs the checker, in tree order. */
120
+ residualNodes;
121
+ /** Set when the check of a parse thread's walk needs the checker: the checker runs that node. */
122
+ needsChecker = false;
77
123
  scanner = undefined;
78
- constructor(c, file) {
124
+ constructor(c, file, options = c.compilerOptions, metadata,
125
+ /** `file.grammarAmbientReports`: what a parse thread's walk already reported. */
126
+ ambientReports) {
79
127
  super();
80
128
  this.c = c;
129
+ this.compilerOptions = options;
130
+ this.languageVersion = getEmitScriptTarget(options);
81
131
  this.file = file;
82
132
  this.hasParseErrors = file.diagnostics.length > 0;
83
- this.moduleKind = getEmitModuleKind(c.compilerOptions);
84
- this.metadata = c.host.getSourceFileMetadata(file) ?? new SourceFileMetadata('', '', ModuleKind.None);
85
- this.legacyDecorators = c.compilerOptions.experimentalDecorators === true;
133
+ this.moduleKind = getEmitModuleKind(options);
134
+ this.metadata = metadata ?? c.host.getSourceFileMetadata(file) ?? new SourceFileMetadata('', '', ModuleKind.None);
135
+ this.legacyDecorators = options.experimentalDecorators === true;
136
+ this.reportedAmbientStatements = new Set(ambientReports);
137
+ this.ambientReportLog = c === undefined ? [] : undefined;
138
+ this.diagnostics = c === undefined ? [] : undefined;
139
+ this.residualNodes = c === undefined ? [] : undefined;
86
140
  }
87
141
  visitNode(node) {
88
- if (checkGrammarNode(this, node))
142
+ const diagnostics = this.diagnostics;
143
+ if (diagnostics === undefined) {
144
+ if (checkGrammarNode(this, node))
145
+ node.forEachChild(this);
146
+ return false;
147
+ }
148
+ // A parse thread has no checker: a node whose check needs it is recorded for the checker, with the
149
+ // diagnostics and the ambient-context reports it made undone, and its children are left to the
150
+ // checker as well.
151
+ const start = diagnostics.length;
152
+ const reportsMark = this.ambientReportLog.length;
153
+ const descend = checkGrammarNode(this, node);
154
+ if (this.needsChecker) {
155
+ this.needsChecker = false;
156
+ diagnostics.length = start;
157
+ this.undoAmbientReports(reportsMark);
158
+ this.residualNodes.push(node);
159
+ return false;
160
+ }
161
+ if (descend)
89
162
  node.forEachChild(this);
90
163
  return false;
91
164
  }
165
+ /** Records that `id` reported a statement in an ambient context. */
166
+ reportAmbientStatement(id) {
167
+ if (this.reportedAmbientStatements.has(id))
168
+ return;
169
+ this.reportedAmbientStatements.add(id);
170
+ this.ambientReportLog?.push(id);
171
+ }
172
+ /** Undoes the ambient-context reports added since the log had `mark` entries. */
173
+ undoAmbientReports(mark) {
174
+ const log = this.ambientReportLog;
175
+ for (let i = mark; i < log.length; i++)
176
+ this.reportedAmbientStatements.delete(log[i]);
177
+ log.length = mark;
178
+ }
179
+ /** Reports an error at `node`, as `Checker.error`; returns the diagnostic. */
180
+ error(node, message, ...args) {
181
+ const c = this.c;
182
+ if (c !== undefined)
183
+ return c.error(node, message, ...args);
184
+ const diagnostic = createDiagnosticForNode(node, message, args);
185
+ this.diagnostics.push(diagnostic);
186
+ return diagnostic;
187
+ }
188
+ /** Reports `diagnostic`, as `Checker.addDiagnostic`. */
189
+ report(diagnostic) {
190
+ const c = this.c;
191
+ if (c !== undefined)
192
+ c.addDiagnostic(diagnostic);
193
+ else
194
+ this.diagnostics.push(diagnostic);
195
+ }
92
196
  /** A scanner over the file's text, for rescanning tokens. */
93
197
  getScanner() {
94
198
  let scanner = this.scanner;
@@ -96,7 +200,7 @@ export class GrammarChecker extends NodeVisitor {
96
200
  scanner = new Scanner(this.file.text);
97
201
  scanner.setLanguageVariant(this.file.languageVariant);
98
202
  // The scanner's target enum has the same values as the option's.
99
- scanner.setScriptTarget(this.c.languageVersion);
203
+ scanner.setScriptTarget(this.languageVersion);
100
204
  this.scanner = scanner;
101
205
  }
102
206
  return scanner;
@@ -106,20 +210,20 @@ export class GrammarChecker extends NodeVisitor {
106
210
  function grammarErrorOnNode(g, node, message, ...args) {
107
211
  if (g.hasParseErrors)
108
212
  return false;
109
- g.c.error(node, message, ...args);
213
+ g.error(node, message, ...args);
110
214
  return true;
111
215
  }
112
216
  function grammarErrorOnFirstToken(g, node, message, ...args) {
113
217
  if (g.hasParseErrors)
114
218
  return false;
115
219
  const range = getRangeOfTokenAtPosition(g.file, node.pos);
116
- g.c.addDiagnostic(new Diagnostic(g.file.diagnosticFile(), range.pos, range.end, message, args));
220
+ g.report(new Diagnostic(g.file.diagnosticFile(), range.pos, range.end, message, args));
117
221
  return true;
118
222
  }
119
223
  function grammarErrorAtPos(g, start, length, message, ...args) {
120
224
  if (g.hasParseErrors)
121
225
  return false;
122
- g.c.addDiagnostic(new Diagnostic(g.file.diagnosticFile(), start, start + length, message, args));
226
+ g.report(new Diagnostic(g.file.diagnosticFile(), start, start + length, message, args));
123
227
  return true;
124
228
  }
125
229
  /** A diagnostic at the first token of `node`. */
@@ -400,9 +504,15 @@ function checkGrammarModifiers(g, node) {
400
504
  return grammarErrorOnFirstToken(g, node, 160 /* Diagnostics.Decorators_are_not_valid_here */);
401
505
  }
402
506
  else if (g.legacyDecorators && (node.kind === 179 /* SyntaxKind.GetAccessor */ || node.kind === 180 /* SyntaxKind.SetAccessor */)) {
403
- const first = getFirstAccessorOfPair(g.c, node);
404
- if (first !== node && hasDecorators(first))
405
- return grammarErrorOnFirstToken(g, node, 161 /* Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name */);
507
+ const c = g.c;
508
+ // Which accessor comes first is a symbol question; a parse thread leaves the node to the checker.
509
+ if (c === undefined)
510
+ g.needsChecker = true;
511
+ else {
512
+ const first = getFirstAccessorOfPair(c, node);
513
+ if (first !== node && hasDecorators(first))
514
+ return grammarErrorOnFirstToken(g, node, 161 /* Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name */);
515
+ }
406
516
  }
407
517
  // Decorators can only follow `export` and `default`.
408
518
  if ((flags & ~(2080 /* ModifierFlags.ExportDefault */ | 32768 /* ModifierFlags.Decorator */)) !== 0)
@@ -410,7 +520,7 @@ function checkGrammarModifiers(g, node) {
410
520
  if (hasLeadingDecorators && (flags & 98303 /* ModifierFlags.Modifier */) !== 0) {
411
521
  if (g.hasParseErrors)
412
522
  return false;
413
- const diagnostic = g.c.error(modifier, 1787 /* Diagnostics.Decorators_may_not_appear_after_export_or_export_default_if_they_also_appear_before_export */);
523
+ const diagnostic = g.error(modifier, 1787 /* Diagnostics.Decorators_may_not_appear_after_export_or_export_default_if_they_also_appear_before_export */);
414
524
  addRelated(diagnostic, firstDecorator, 399 /* Diagnostics.Decorator_used_before_export_here */);
415
525
  return true;
416
526
  }
@@ -532,7 +642,7 @@ function checkGrammarModifiers(g, node) {
532
642
  flags |= 8 /* ModifierFlags.Readonly */;
533
643
  break;
534
644
  case 94 /* SyntaxKind.ExportKeyword */:
535
- if (g.c.compilerOptions.verbatimModuleSyntax === true &&
645
+ if (g.compilerOptions.verbatimModuleSyntax === true &&
536
646
  (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
537
647
  node.kind !== 267 /* SyntaxKind.TypeAliasDeclaration */ &&
538
648
  node.kind !== 266 /* SyntaxKind.InterfaceDeclaration */ &&
@@ -880,7 +990,7 @@ function checkGrammarDecorator(g, decorator) {
880
990
  }
881
991
  if (errorNode === undefined)
882
992
  return false;
883
- const diagnostic = g.c.error(decorator.expression, 410 /* Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator */);
993
+ const diagnostic = g.error(decorator.expression, 410 /* Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator */);
884
994
  addRelated(diagnostic, errorNode, 411 /* Diagnostics.Invalid_syntax_in_decorator */);
885
995
  return true;
886
996
  }
@@ -931,7 +1041,7 @@ function checkGrammarParameterList(g, parameters) {
931
1041
  return false;
932
1042
  }
933
1043
  function checkGrammarForUseStrictSimpleParameterList(g, node) {
934
- if (g.c.languageVersion < ScriptTarget.ES2016)
1044
+ if (g.languageVersion < ScriptTarget.ES2016)
935
1045
  return false;
936
1046
  const body = getBody(node);
937
1047
  if (body === undefined || body.kind !== 243 /* SyntaxKind.Block */)
@@ -948,10 +1058,10 @@ function checkGrammarForUseStrictSimpleParameterList(g, node) {
948
1058
  if (nonSimpleParameters.length === 0)
949
1059
  return false;
950
1060
  for (const parameter of nonSimpleParameters) {
951
- const diagnostic = g.c.error(parameter, 280 /* Diagnostics.This_parameter_is_not_allowed_with_use_strict_directive */);
1061
+ const diagnostic = g.error(parameter, 280 /* Diagnostics.This_parameter_is_not_allowed_with_use_strict_directive */);
952
1062
  addRelated(diagnostic, useStrictDirective, 283 /* Diagnostics.X_use_strict_directive_used_here */);
953
1063
  }
954
- const diagnostic = g.c.error(useStrictDirective, 281 /* Diagnostics.X_use_strict_directive_cannot_be_used_with_non_simple_parameter_list */);
1064
+ const diagnostic = g.error(useStrictDirective, 281 /* Diagnostics.X_use_strict_directive_cannot_be_used_with_non_simple_parameter_list */);
955
1065
  for (let i = 0; i < nonSimpleParameters.length; i++)
956
1066
  addRelated(diagnostic, nonSimpleParameters[i], i === 0 ? 282 /* Diagnostics.Non_simple_parameter_declared_here */ : 1368 /* Diagnostics.X_and_here */);
957
1067
  return true;
@@ -1034,10 +1144,16 @@ function checkGrammarIndexSignatureParameters(g, node) {
1034
1144
  return grammarErrorOnNode(g, parameter.name, 16 /* Diagnostics.An_index_signature_parameter_cannot_have_an_initializer */);
1035
1145
  if (parameter.type === undefined)
1036
1146
  return grammarErrorOnNode(g, parameter.name, 18 /* Diagnostics.An_index_signature_parameter_must_have_a_type_annotation */);
1037
- const t = getTypeFromTypeNode(g.c, parameter.type);
1038
- if (someTypeHasFlags(t, 19456 /* TypeFlags.StringOrNumberLiteralOrUnique */) || isGenericType(g.c, t))
1147
+ const c = g.c;
1148
+ if (c === undefined) {
1149
+ // The parameter's type decides; a parse thread leaves the node to the checker.
1150
+ g.needsChecker = true;
1151
+ return false;
1152
+ }
1153
+ const t = getTypeFromTypeNode(c, parameter.type);
1154
+ if (someTypeHasFlags(t, 19456 /* TypeFlags.StringOrNumberLiteralOrUnique */) || isGenericType(c, t))
1039
1155
  return grammarErrorOnNode(g, parameter.name, 272 /* Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead */);
1040
- if (!everyTypeIsValidIndexKey(g.c, t))
1156
+ if (!everyTypeIsValidIndexKey(c, t))
1041
1157
  return grammarErrorOnNode(g, parameter.name, 217 /* Diagnostics.An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type */);
1042
1158
  if (node.type === undefined)
1043
1159
  return grammarErrorOnNode(g, node, 17 /* Diagnostics.An_index_signature_must_have_a_type_annotation */);
@@ -1193,7 +1309,7 @@ function checkGrammarForInvalidExclamationToken(g, postfixToken, message) {
1193
1309
  grammarErrorOnNode(g, postfixToken, message));
1194
1310
  }
1195
1311
  /** Whether a name is dynamic and can't be late bound: its type isn't a literal or unique symbol. */
1196
- function isNonBindableDynamicName(c, node) {
1312
+ function isNonBindableDynamicName(g, node) {
1197
1313
  if (!isDynamicName(node))
1198
1314
  return false;
1199
1315
  let expression;
@@ -1203,13 +1319,19 @@ function isNonBindableDynamicName(c, node) {
1203
1319
  expression = node.argumentExpression;
1204
1320
  if (expression === undefined || !isEntityNameExpression(expression, false))
1205
1321
  return true;
1322
+ const c = g.c;
1323
+ if (c === undefined) {
1324
+ // The name's type decides; a parse thread leaves the node to the checker.
1325
+ g.needsChecker = true;
1326
+ return false;
1327
+ }
1206
1328
  const t = node.kind === 169 /* SyntaxKind.ComputedPropertyName */
1207
1329
  ? checkComputedPropertyName(c, node)
1208
1330
  : checkExpressionCached(c, expression);
1209
1331
  return !isTypeUsableAsPropertyName(t);
1210
1332
  }
1211
1333
  function checkGrammarForInvalidDynamicName(g, node, message) {
1212
- if (!isNonBindableDynamicName(g.c, node))
1334
+ if (!isNonBindableDynamicName(g, node))
1213
1335
  return false;
1214
1336
  const expression = node instanceof ElementAccessExpression ? skipParentheses(node.argumentExpression) : getExpression(node);
1215
1337
  return !isEntityNameExpression(expression, false) && grammarErrorOnNode(g, node, message);
@@ -1225,11 +1347,11 @@ function checkGrammarMethodDeclaration(g, node) {
1225
1347
  if (!checkGrammarMethod(g, node)) {
1226
1348
  checkGrammarComputedPropertyName(g, name);
1227
1349
  if (getAsteriskToken(node) !== undefined && name instanceof Identifier && name.text === 'constructor')
1228
- g.c.error(name, 302 /* Diagnostics.Class_constructor_may_not_be_a_generator */);
1350
+ g.error(name, 302 /* Diagnostics.Class_constructor_may_not_be_a_generator */);
1229
1351
  }
1230
1352
  checkGrammarDecorators(g, node);
1231
1353
  if (name.kind === 80 /* SyntaxKind.PrivateIdentifier */ && getContainingClass(node) === undefined)
1232
- g.c.error(node, 1858 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
1354
+ g.error(node, 1858 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
1233
1355
  }
1234
1356
  function checkGrammarMethod(g, node) {
1235
1357
  if (checkGrammarFunctionLikeDeclaration(g, node))
@@ -1380,7 +1502,7 @@ function checkAmbientInitializer(g, node) {
1380
1502
  if (initializer === undefined)
1381
1503
  return false;
1382
1504
  const isInvalidInitializer = !(isInitializerStringOrNumberLiteralExpression(initializer) ||
1383
- isInitializerSimpleLiteralEnumReference(g.c, initializer) ||
1505
+ isInitializerSimpleLiteralEnumReference(g, initializer) ||
1384
1506
  initializer.kind === 111 /* SyntaxKind.TrueKeyword */ ||
1385
1507
  initializer.kind === 96 /* SyntaxKind.FalseKeyword */ ||
1386
1508
  isInitializerBigIntLiteralExpression(initializer));
@@ -1420,14 +1542,25 @@ function isInitializerBigIntLiteralExpression(expression) {
1420
1542
  const unary = expression;
1421
1543
  return unary.operator === 40 /* SyntaxKind.MinusToken */ && unary.operand.kind === 9 /* SyntaxKind.BigIntLiteral */;
1422
1544
  }
1423
- function isInitializerSimpleLiteralEnumReference(c, expression) {
1545
+ function isInitializerSimpleLiteralEnumReference(g, expression) {
1546
+ let accessesEnum;
1424
1547
  if (expression.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
1425
- return (checkExpressionCached(c, expression).flags & 98304 /* TypeFlags.EnumLike */) !== 0;
1426
- if (expression instanceof ElementAccessExpression)
1427
- return (isInitializerStringOrNumberLiteralExpression(expression.argumentExpression) &&
1428
- isEntityNameExpression(expression.expression, false) &&
1429
- (checkExpressionCached(c, expression).flags & 98304 /* TypeFlags.EnumLike */) !== 0);
1430
- return false;
1548
+ accessesEnum = true;
1549
+ else if (expression instanceof ElementAccessExpression)
1550
+ accessesEnum =
1551
+ isInitializerStringOrNumberLiteralExpression(expression.argumentExpression) &&
1552
+ isEntityNameExpression(expression.expression, false);
1553
+ else
1554
+ return false;
1555
+ if (!accessesEnum)
1556
+ return false;
1557
+ // Whether the reference is to an enum is a type question.
1558
+ const c = g.c;
1559
+ if (c === undefined) {
1560
+ g.needsChecker = true;
1561
+ return false;
1562
+ }
1563
+ return (checkExpressionCached(c, expression).flags & 98304 /* TypeFlags.EnumLike */) !== 0;
1431
1564
  }
1432
1565
  // ---- Statements
1433
1566
  function checkGrammarStatementInAmbientContext(g, node) {
@@ -1438,7 +1571,7 @@ function checkGrammarStatementInAmbientContext(g, node) {
1438
1571
  if (!g.reportedAmbientStatements.has(id) && (isFunctionLike(parent) || isAccessor(parent))) {
1439
1572
  const reported = grammarErrorOnFirstToken(g, node, 139 /* Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts */);
1440
1573
  if (reported)
1441
- g.reportedAmbientStatements.add(id);
1574
+ g.reportAmbientStatement(id);
1442
1575
  return reported;
1443
1576
  }
1444
1577
  // Report once per block; statements nested in other statements are covered by their parent.
@@ -1449,7 +1582,7 @@ function checkGrammarStatementInAmbientContext(g, node) {
1449
1582
  if (!g.reportedAmbientStatements.has(parentId)) {
1450
1583
  const reported = grammarErrorOnFirstToken(g, node, 27 /* Diagnostics.Statements_are_not_allowed_in_ambient_contexts */);
1451
1584
  if (reported)
1452
- g.reportedAmbientStatements.add(parentId);
1585
+ g.reportAmbientStatement(parentId);
1453
1586
  return reported;
1454
1587
  }
1455
1588
  }
@@ -1477,7 +1610,7 @@ function checkGrammarForDisallowedBlockScopedVariableStatement(g, node) {
1477
1610
  keyword = 'using';
1478
1611
  else
1479
1612
  keyword = 'await using';
1480
- g.c.error(node, 116 /* Diagnostics.X_0_declarations_can_only_be_declared_inside_a_block */, keyword);
1613
+ g.error(node, 116 /* Diagnostics.X_0_declarations_can_only_be_declared_inside_a_block */, keyword);
1481
1614
  }
1482
1615
  function containerAllowsBlockScopedVariable(parent) {
1483
1616
  switch (parent.kind) {
@@ -1627,12 +1760,12 @@ function checkGrammarForInOrForOfStatementWorker(g, node) {
1627
1760
  if (isInTopLevelContext(node)) {
1628
1761
  if (!g.hasParseErrors) {
1629
1762
  if (!isEffectiveExternalModule(g))
1630
- g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 357 /* Diagnostics.X_for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */, []));
1763
+ g.report(createDiagnosticForNode(awaitModifier, 357 /* Diagnostics.X_for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */, []));
1631
1764
  const kind = checkTopLevelAwaitModule(g);
1632
1765
  if (kind === 1 /* TopLevelAwaitSupport.CommonJS */)
1633
- g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */, []));
1766
+ g.report(createDiagnosticForNode(awaitModifier, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */, []));
1634
1767
  else if (kind === 2 /* TopLevelAwaitSupport.Unsupported */)
1635
- g.c.addDiagnostic(createDiagnosticForNode(awaitModifier, 358 /* Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */, []));
1768
+ g.report(createDiagnosticForNode(awaitModifier, 358 /* Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */, []));
1636
1769
  }
1637
1770
  }
1638
1771
  else if (!g.hasParseErrors) {
@@ -1641,7 +1774,7 @@ function checkGrammarForInOrForOfStatementWorker(g, node) {
1641
1774
  const containingFunction = getContainingFunction(node);
1642
1775
  if (containingFunction !== undefined && containingFunction.kind !== 178 /* SyntaxKind.Constructor */)
1643
1776
  addRelated(diagnostic, containingFunction, 290 /* Diagnostics.Did_you_mean_to_mark_this_function_as_async */);
1644
- g.c.addDiagnostic(diagnostic);
1777
+ g.report(diagnostic);
1645
1778
  return true;
1646
1779
  }
1647
1780
  }
@@ -1690,7 +1823,7 @@ function checkTopLevelAwaitModule(g) {
1690
1823
  moduleKind !== ModuleKind.Preserve &&
1691
1824
  moduleKind !== ModuleKind.System)
1692
1825
  return 2 /* TopLevelAwaitSupport.Unsupported */;
1693
- return g.c.languageVersion >= ScriptTarget.ES2017 ? 0 /* TopLevelAwaitSupport.Supported */ : 2 /* TopLevelAwaitSupport.Unsupported */;
1826
+ return g.languageVersion >= ScriptTarget.ES2017 ? 0 /* TopLevelAwaitSupport.Supported */ : 2 /* TopLevelAwaitSupport.Unsupported */;
1694
1827
  }
1695
1828
  function checkGrammarBreakOrContinueStatement(g, node) {
1696
1829
  const targetLabel = getLabel(node);
@@ -1789,7 +1922,13 @@ function checkGrammarCatchClause(g, node) {
1789
1922
  return;
1790
1923
  const typeNode = declaration.type;
1791
1924
  if (typeNode !== undefined) {
1792
- const t = getTypeFromTypeNode(g.c, typeNode);
1925
+ // The annotation's type decides; a parse thread leaves the node to the checker.
1926
+ const c = g.c;
1927
+ if (c === undefined) {
1928
+ g.needsChecker = true;
1929
+ return;
1930
+ }
1931
+ const t = getTypeFromTypeNode(c, typeNode);
1793
1932
  if ((t.flags & 3 /* TypeFlags.AnyOrUnknown */) === 0)
1794
1933
  grammarErrorOnFirstToken(g, typeNode, 152 /* Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified */);
1795
1934
  }
@@ -1900,13 +2039,13 @@ function checkExternalImportOrExportDeclaration(g, node) {
1900
2039
  if (moduleName === undefined || moduleName.pos === moduleName.end)
1901
2040
  return false;
1902
2041
  if (moduleName.kind !== 10 /* SyntaxKind.StringLiteral */) {
1903
- g.c.error(moduleName, 107 /* Diagnostics.String_literal_expected */);
2042
+ g.error(moduleName, 107 /* Diagnostics.String_literal_expected */);
1904
2043
  return false;
1905
2044
  }
1906
2045
  const parent = node.parent;
1907
2046
  const inAmbientExternalModule = parent.kind === 270 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
1908
2047
  if (parent.kind !== 308 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule) {
1909
- g.c.error(moduleName, node.kind === 280 /* SyntaxKind.ExportDeclaration */
2048
+ g.error(moduleName, node.kind === 280 /* SyntaxKind.ExportDeclaration */
1910
2049
  ? 150 /* Diagnostics.Export_declarations_are_not_permitted_in_a_namespace */
1911
2050
  : 112 /* Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module */);
1912
2051
  return false;
@@ -1915,7 +2054,7 @@ function checkExternalImportOrExportDeclaration(g, node) {
1915
2054
  isExternalModuleNameRelative(moduleName.text) &&
1916
2055
  !isModuleAugmentationExternal(parent.parent)) {
1917
2056
  // Module augmentations report relative names when checking the augmentation.
1918
- g.c.error(node, 614 /* Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name */);
2057
+ g.error(node, 614 /* Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name */);
1919
2058
  return false;
1920
2059
  }
1921
2060
  if (node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */)
@@ -1930,7 +2069,7 @@ function checkGrammarImportAttributeValues(g, node) {
1930
2069
  const value = attribute.value;
1931
2070
  if (value.kind !== 10 /* SyntaxKind.StringLiteral */) {
1932
2071
  hasError = true;
1933
- g.c.error(value, 985 /* Diagnostics.Import_attribute_values_must_be_string_literal_expressions */);
2072
+ g.error(value, 985 /* Diagnostics.Import_attribute_values_must_be_string_literal_expressions */);
1934
2073
  }
1935
2074
  }
1936
2075
  return hasError;
@@ -1982,8 +2121,14 @@ function checkGrammarImportClause(g, node) {
1982
2121
  if (!supportsSourcePhaseImports(g.moduleKind))
1983
2122
  return grammarErrorOnNode(g, node, 1948 /* Diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve */);
1984
2123
  const moduleSpecifier = node.parent.moduleSpecifier;
1985
- if (getEmitSyntaxForModuleSpecifierExpression(g.c, moduleSpecifier) === ModuleKind.CommonJS)
1986
- return grammarErrorOnNode(g, node, 1950 /* Diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls */);
2124
+ const c = g.c;
2125
+ // The specifier's emit syntax comes from the module resolution; a parse thread leaves it to the checker.
2126
+ if (c !== undefined) {
2127
+ if (getEmitSyntaxForModuleSpecifierExpression(c, moduleSpecifier) === ModuleKind.CommonJS)
2128
+ return grammarErrorOnNode(g, node, 1950 /* Diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls */);
2129
+ }
2130
+ else
2131
+ g.needsChecker = true;
1987
2132
  }
1988
2133
  return false;
1989
2134
  }
@@ -2005,9 +2150,15 @@ function checkGrammarImportEqualsDeclaration(g, node) {
2005
2150
  const isExternal = node.moduleReference.kind === 285 /* SyntaxKind.ExternalModuleReference */;
2006
2151
  if (!isExternal) {
2007
2152
  if (node.isTypeOnly) {
2008
- const symbol = getSymbolOfDeclaration(g.c, node);
2009
- if (symbol !== undefined && resolveAlias(g.c, symbol) !== g.c.unknownSymbol)
2010
- grammarErrorOnNode(g, node, 318 /* Diagnostics.An_import_alias_cannot_use_import_type */);
2153
+ const c = g.c;
2154
+ // Whether the alias resolves is a symbol question; a parse thread leaves the node to the checker.
2155
+ if (c === undefined)
2156
+ g.needsChecker = true;
2157
+ else {
2158
+ const symbol = getSymbolOfDeclaration(c, node);
2159
+ if (symbol !== undefined && resolveAlias(c, symbol) !== c.unknownSymbol)
2160
+ grammarErrorOnNode(g, node, 318 /* Diagnostics.An_import_alias_cannot_use_import_type */);
2161
+ }
2011
2162
  }
2012
2163
  return;
2013
2164
  }
@@ -2042,7 +2193,7 @@ function checkGrammarExportDeclaration(g, node) {
2042
2193
  !hasModuleSpecifier &&
2043
2194
  (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
2044
2195
  if (parent.kind !== 308 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule && !inAmbientNamespaceDeclaration)
2045
- g.c.error(node, 150 /* Diagnostics.Export_declarations_are_not_permitted_in_a_namespace */);
2196
+ g.error(node, 150 /* Diagnostics.Export_declarations_are_not_permitted_in_a_namespace */);
2046
2197
  }
2047
2198
  checkGrammarImportAttributes(g, node);
2048
2199
  }
@@ -2064,7 +2215,7 @@ function checkGrammarExportAssignment(g, node) {
2064
2215
  const parent = node.parent;
2065
2216
  const container = parent.kind === 308 /* SyntaxKind.SourceFile */ ? parent : parent.parent;
2066
2217
  if (container.kind === 269 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container)) {
2067
- g.c.error(node, isExportEquals
2218
+ g.error(node, isExportEquals
2068
2219
  ? 48 /* Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace */
2069
2220
  : 255 /* Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module */);
2070
2221
  return false;
@@ -2087,7 +2238,7 @@ function checkGrammarExportAssignment(g, node) {
2087
2238
  return true;
2088
2239
  }
2089
2240
  function getEmitModuleFormat(g) {
2090
- return getEmitModuleFormatOfFile(g.file.fileName, g.c.compilerOptions, g.metadata);
2241
+ return getEmitModuleFormatOfFile(g.file.fileName, g.compilerOptions, g.metadata);
2091
2242
  }
2092
2243
  function isEffectiveExternalModule(g) {
2093
2244
  if (isExternalModule(g.file))
@@ -2162,13 +2313,19 @@ function checkGrammarTupleType(g, node) {
2162
2313
  let seenOptionalElement = false;
2163
2314
  let seenRestElement = false;
2164
2315
  for (const element of node.elements.nodes) {
2165
- let flags = getTupleElementFlags(g.c, element);
2316
+ let flags = getTupleElementFlags(element);
2166
2317
  if ((flags & 8 /* ElementFlags.Variadic */) !== 0) {
2167
- const t = getTypeFromTypeNode(g.c, getType(element));
2318
+ const c = g.c;
2319
+ // The element type decides whether a variadic element is a rest element.
2320
+ if (c === undefined) {
2321
+ g.needsChecker = true;
2322
+ return;
2323
+ }
2324
+ const t = getTypeFromTypeNode(c, getType(element));
2168
2325
  // `checkTupleType` reports non-array rest types and stops.
2169
- if (!isArrayLikeType(g.c, t))
2326
+ if (!isArrayLikeType(c, t))
2170
2327
  break;
2171
- if (isArrayType(g.c, t) || (isTupleType(t) && (tupleTargetOf(t).combinedFlags & 4 /* ElementFlags.Rest */) !== 0))
2328
+ if (isArrayType(c, t) || (isTupleType(t) && (tupleTargetOf(t).combinedFlags & 4 /* ElementFlags.Rest */) !== 0))
2172
2329
  flags |= 4 /* ElementFlags.Rest */;
2173
2330
  }
2174
2331
  if ((flags & 4 /* ElementFlags.Rest */) !== 0) {
@@ -2210,12 +2367,18 @@ function checkGrammarJSDocTypeInTypeScript(g, node) {
2210
2367
  const isNullable = node.kind === 312 /* SyntaxKind.JSDocNullableType */;
2211
2368
  const typeNode = getType(node);
2212
2369
  const postfix = node.pos === typeNode.pos;
2213
- let t = getTypeFromTypeNode(g.c, typeNode);
2214
- if (isNullable && t !== g.c.neverType && t !== g.c.voidType)
2215
- t = getNullableType(g.c, t, postfix ? 4 /* TypeFlags.Undefined */ : 12 /* TypeFlags.Nullable */);
2370
+ const c = g.c;
2371
+ // The error names the type's printed form; a parse thread leaves the node to the checker.
2372
+ if (c === undefined) {
2373
+ g.needsChecker = true;
2374
+ return;
2375
+ }
2376
+ let t = getTypeFromTypeNode(c, typeNode);
2377
+ if (isNullable && t !== c.neverType && t !== c.voidType)
2378
+ t = getNullableType(c, t, postfix ? 4 /* TypeFlags.Undefined */ : 12 /* TypeFlags.Nullable */);
2216
2379
  grammarErrorOnNode(g, node, postfix
2217
2380
  ? 1842 /* Diagnostics.X_0_at_the_end_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1 */
2218
- : 1843 /* Diagnostics.X_0_at_the_start_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1 */, isNullable ? '?' : '!', typeToString(g.c, t));
2381
+ : 1843 /* Diagnostics.X_0_at_the_start_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1 */, isNullable ? '?' : '!', typeToString(c, t));
2219
2382
  }
2220
2383
  /** The `resolution-mode` of import type attributes, as tsgo's `GetResolutionModeOverride`. */
2221
2384
  function getResolutionModeOverride(g, node, reportErrors) {
@@ -2321,7 +2484,7 @@ function checkGrammarObjectLiteralExpression(g, node, inDestructuring) {
2321
2484
  checkGrammarForInvalidExclamationToken(g, postfixToken, 205 /* Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context */);
2322
2485
  checkGrammarForInvalidQuestionMark(g, postfixToken, 119 /* Diagnostics.An_object_member_cannot_be_declared_optional */);
2323
2486
  if (name.kind === 9 /* SyntaxKind.BigIntLiteral */)
2324
- g.c.addDiagnostic(createDiagnosticForNode(name, 452 /* Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name */, []));
2487
+ g.report(createDiagnosticForNode(name, 452 /* Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name */, []));
2325
2488
  currentKind = 4 /* DeclarationMeaning.PropertyAssignment */;
2326
2489
  break;
2327
2490
  }
@@ -2337,6 +2500,7 @@ function checkGrammarObjectLiteralExpression(g, node, inDestructuring) {
2337
2500
  }
2338
2501
  if (inDestructuring)
2339
2502
  continue;
2503
+ // Object literals are checked with the checker, when the expression is checked.
2340
2504
  const effectiveName = getEffectivePropertyNameForPropertyNameNode(g.c, name);
2341
2505
  if (effectiveName === undefined || seen === undefined)
2342
2506
  continue;
@@ -2405,7 +2569,7 @@ function checkGrammarCallExpression(g, node) {
2405
2569
  }
2406
2570
  function checkGrammarImportCallExpression(g, node) {
2407
2571
  const moduleKind = g.moduleKind;
2408
- if (g.c.compilerOptions.verbatimModuleSyntax === true && moduleKind === ModuleKind.CommonJS)
2572
+ if (g.compilerOptions.verbatimModuleSyntax === true && moduleKind === ModuleKind.CommonJS)
2409
2573
  return grammarErrorOnNode(g, node, fileExtensionIsOneOf(g.file.fileName, ['.cts', '.cjs'])
2410
2574
  ? 235 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax */
2411
2575
  : 244 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript */);
@@ -2475,7 +2639,7 @@ function checkGrammarAwaitOrAwaitUsing(g, node) {
2475
2639
  const container = getContainingFunctionOrClassStaticBlock(node);
2476
2640
  if (container !== undefined && container.kind === 177 /* SyntaxKind.ClassStaticBlockDeclaration */) {
2477
2641
  // Reported even with parse errors.
2478
- g.c.error(node, isAwaitExpression
2642
+ g.error(node, isAwaitExpression
2479
2643
  ? 1874 /* Diagnostics.X_await_expression_cannot_be_used_inside_a_class_static_block */
2480
2644
  : 1889 /* Diagnostics.X_await_using_statements_cannot_be_used_inside_a_class_static_block */);
2481
2645
  hasError = true;
@@ -2484,18 +2648,18 @@ function checkGrammarAwaitOrAwaitUsing(g, node) {
2484
2648
  if (isInTopLevelContext(node)) {
2485
2649
  if (!g.hasParseErrors) {
2486
2650
  if (!isEffectiveExternalModule(g)) {
2487
- g.c.addDiagnostic(diagnosticAtFirstToken(g, node, isAwaitExpression
2651
+ g.report(diagnosticAtFirstToken(g, node, isAwaitExpression
2488
2652
  ? 304 /* Diagnostics.X_await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */
2489
2653
  : 980 /* Diagnostics.X_await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module */));
2490
2654
  hasError = true;
2491
2655
  }
2492
2656
  const support = checkTopLevelAwaitModule(g);
2493
2657
  if (support === 1 /* TopLevelAwaitSupport.CommonJS */) {
2494
- g.c.addDiagnostic(diagnosticAtFirstToken(g, node, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */));
2658
+ g.report(diagnosticAtFirstToken(g, node, 247 /* Diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level */));
2495
2659
  hasError = true;
2496
2660
  }
2497
2661
  else if (support === 2 /* TopLevelAwaitSupport.Unsupported */) {
2498
- g.c.addDiagnostic(diagnosticAtFirstToken(g, node, isAwaitExpression
2662
+ g.report(diagnosticAtFirstToken(g, node, isAwaitExpression
2499
2663
  ? 307 /* Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */
2500
2664
  : 981 /* Diagnostics.Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher */));
2501
2665
  hasError = true;
@@ -2511,13 +2675,13 @@ function checkGrammarAwaitOrAwaitUsing(g, node) {
2511
2675
  container.kind !== 178 /* SyntaxKind.Constructor */ &&
2512
2676
  !hasSyntacticModifier(container, 1024 /* ModifierFlags.Async */))
2513
2677
  addRelated(diagnostic, container, 290 /* Diagnostics.Did_you_mean_to_mark_this_function_as_async */);
2514
- g.c.addDiagnostic(diagnostic);
2678
+ g.report(diagnostic);
2515
2679
  hasError = true;
2516
2680
  }
2517
2681
  }
2518
2682
  if (isAwaitExpression && isInParameterInitializerBeforeContainingFunction(node)) {
2519
2683
  // Reported even with parse errors.
2520
- g.c.error(node, 690 /* Diagnostics.X_await_expressions_cannot_be_used_in_a_parameter_initializer */);
2684
+ g.error(node, 690 /* Diagnostics.X_await_expressions_cannot_be_used_in_a_parameter_initializer */);
2521
2685
  hasError = true;
2522
2686
  }
2523
2687
  return hasError;
@@ -2529,7 +2693,7 @@ function checkGrammarYieldExpression(g, node) {
2529
2693
  hasError = true;
2530
2694
  }
2531
2695
  if (isInParameterInitializerBeforeContainingFunction(node)) {
2532
- g.c.error(node, 689 /* Diagnostics.X_yield_expressions_cannot_be_used_in_a_parameter_initializer */);
2696
+ g.error(node, 689 /* Diagnostics.X_yield_expressions_cannot_be_used_in_a_parameter_initializer */);
2533
2697
  hasError = true;
2534
2698
  }
2535
2699
  return hasError;
@@ -2579,7 +2743,7 @@ function checkGrammarBigIntLiteral(g, node) {
2579
2743
  // BigInt literals are fine in types and ambient contexts.
2580
2744
  return (!isLiteralType &&
2581
2745
  (node.flags & 8388608 /* NodeFlags.Ambient */) === 0 &&
2582
- g.c.languageVersion < ScriptTarget.ES2020 &&
2746
+ g.languageVersion < ScriptTarget.ES2020 &&
2583
2747
  grammarErrorOnNode(g, node, 876 /* Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020 */));
2584
2748
  }
2585
2749
  /** Reports the errors of rescanning a regular expression; spelling suggestions become related information. */
@@ -2601,7 +2765,7 @@ class RegularExpressionErrorReporter extends ScannerErrorReporter {
2601
2765
  else if (lastError === undefined || start !== lastError.pos) {
2602
2766
  const diagnostic = new Diagnostic(this.g.file.diagnosticFile(), start, start + length, message, args);
2603
2767
  this.lastError = diagnostic;
2604
- this.g.c.addDiagnostic(diagnostic);
2768
+ this.g.report(diagnostic);
2605
2769
  }
2606
2770
  }
2607
2771
  }