typescript 4.7.0-dev.20220323 → 4.7.0-dev.20220325

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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220323";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220325";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8601,6 +8601,7 @@ var ts;
8601
8601
  Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2205, ts.DiagnosticCategory.Error, "Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2205", "Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
8602
8602
  The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement: diag(2206, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206", "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
8603
8603
  The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement: diag(2207, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207", "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
8604
+ This_type_parameter_probably_needs_an_extends_object_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_probably_needs_an_extends_object_constraint_2208", "This type parameter probably needs an `extends object` constraint."),
8604
8605
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8605
8606
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8606
8607
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -44624,11 +44625,14 @@ var ts;
44624
44625
  var saveExceptionTarget = currentExceptionTarget;
44625
44626
  var saveActiveLabelList = activeLabelList;
44626
44627
  var saveHasExplicitReturn = hasExplicitReturn;
44627
- var isIIFE = containerFlags & 16 /* IsFunctionExpression */ && !ts.hasSyntacticModifier(node, 256 /* Async */) &&
44628
- !node.asteriskToken && !!ts.getImmediatelyInvokedFunctionExpression(node);
44628
+ var isImmediatelyInvoked = (containerFlags & 16 /* IsFunctionExpression */ &&
44629
+ !ts.hasSyntacticModifier(node, 256 /* Async */) &&
44630
+ !node.asteriskToken &&
44631
+ !!ts.getImmediatelyInvokedFunctionExpression(node)) ||
44632
+ node.kind === 170 /* ClassStaticBlockDeclaration */;
44629
44633
  // A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
44630
44634
  // similarly to break statements that exit to a label just past the statement body.
44631
- if (!isIIFE) {
44635
+ if (!isImmediatelyInvoked) {
44632
44636
  currentFlow = initFlowNode({ flags: 2 /* Start */ });
44633
44637
  if (containerFlags & (16 /* IsFunctionExpression */ | 128 /* IsObjectLiteralOrClassExpressionMethodOrAccessor */)) {
44634
44638
  currentFlow.node = node;
@@ -44636,7 +44640,7 @@ var ts;
44636
44640
  }
44637
44641
  // We create a return control flow graph for IIFEs and constructors. For constructors
44638
44642
  // we use the return control flow graph in strict property initialization checks.
44639
- currentReturnTarget = isIIFE || node.kind === 171 /* Constructor */ || node.kind === 170 /* ClassStaticBlockDeclaration */ || (ts.isInJSFile(node) && (node.kind === 256 /* FunctionDeclaration */ || node.kind === 213 /* FunctionExpression */)) ? createBranchLabel() : undefined;
44643
+ currentReturnTarget = isImmediatelyInvoked || node.kind === 171 /* Constructor */ || (ts.isInJSFile(node) && (node.kind === 256 /* FunctionDeclaration */ || node.kind === 213 /* FunctionExpression */)) ? createBranchLabel() : undefined;
44640
44644
  currentExceptionTarget = undefined;
44641
44645
  currentBreakTarget = undefined;
44642
44646
  currentContinueTarget = undefined;
@@ -44662,7 +44666,7 @@ var ts;
44662
44666
  node.returnFlowNode = currentFlow;
44663
44667
  }
44664
44668
  }
44665
- if (!isIIFE) {
44669
+ if (!isImmediatelyInvoked) {
44666
44670
  currentFlow = saveCurrentFlow;
44667
44671
  }
44668
44672
  currentBreakTarget = saveBreakTarget;
@@ -47708,7 +47712,7 @@ var ts;
47708
47712
  (preserveConstEnums && moduleState === 2 /* ConstEnumOnly */);
47709
47713
  }
47710
47714
  ts.isInstantiatedModule = isInstantiatedModule;
47711
- function createTypeChecker(host, produceDiagnostics) {
47715
+ function createTypeChecker(host) {
47712
47716
  var getPackagesMap = ts.memoize(function () {
47713
47717
  // A package name maps to true when we detect it has .d.ts files.
47714
47718
  // This is useful as an approximation of whether a package bundles its own types.
@@ -47725,6 +47729,10 @@ var ts;
47725
47729
  });
47726
47730
  return map;
47727
47731
  });
47732
+ var deferredDiagnosticsCallbacks = [];
47733
+ var addLazyDiagnostic = function (arg) {
47734
+ deferredDiagnosticsCallbacks.push(arg);
47735
+ };
47728
47736
  // Cancellation that controls whether or not we can cancel in the middle of type checking.
47729
47737
  // In general cancelling is *not* safe for the type checker. We might be in the middle of
47730
47738
  // computing something, and we will leave our internals in an inconsistent state. Callers
@@ -48088,8 +48096,8 @@ var ts;
48088
48096
  // Do this in a finally block so we can ensure that it gets reset back to nothing after
48089
48097
  // this call is done.
48090
48098
  cancellationToken = ct;
48091
- // Ensure file is type checked
48092
- checkSourceFile(file);
48099
+ // Ensure file is type checked, with _eager_ diagnostic production, so identifiers are registered as potentially unused
48100
+ checkSourceFileWithEagerDiagnostics(file);
48093
48101
  ts.Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
48094
48102
  diagnostics = ts.addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
48095
48103
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) {
@@ -49425,110 +49433,114 @@ var ts;
49425
49433
  }
49426
49434
  }
49427
49435
  if (!result) {
49428
- if (nameNotFoundMessage && produceDiagnostics) {
49429
- if (!errorLocation ||
49430
- !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
49431
- !checkAndReportErrorForExtendingInterface(errorLocation) &&
49432
- !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
49433
- !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
49434
- !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
49435
- !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
49436
- !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
49437
- var suggestion = void 0;
49438
- if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
49439
- suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
49440
- var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
49441
- if (isGlobalScopeAugmentationDeclaration) {
49442
- suggestion = undefined;
49443
- }
49444
- if (suggestion) {
49445
- var suggestionName = symbolToString(suggestion);
49446
- var isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
49447
- var message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && ts.nodeIsSynthesized(nameArg) ? ts.Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
49448
- : isUncheckedJS ? ts.Diagnostics.Could_not_find_name_0_Did_you_mean_1
49449
- : ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1;
49450
- var diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
49451
- addErrorOrSuggestion(!isUncheckedJS, diagnostic);
49452
- if (suggestion.valueDeclaration) {
49453
- ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName));
49436
+ if (nameNotFoundMessage) {
49437
+ addLazyDiagnostic(function () {
49438
+ if (!errorLocation ||
49439
+ !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
49440
+ !checkAndReportErrorForExtendingInterface(errorLocation) &&
49441
+ !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
49442
+ !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
49443
+ !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
49444
+ !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
49445
+ !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
49446
+ var suggestion = void 0;
49447
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
49448
+ suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
49449
+ var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
49450
+ if (isGlobalScopeAugmentationDeclaration) {
49451
+ suggestion = undefined;
49454
49452
  }
49455
- }
49456
- }
49457
- if (!suggestion) {
49458
- if (nameArg) {
49459
- var lib = getSuggestedLibForNonExistentName(nameArg);
49460
- if (lib) {
49461
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
49453
+ if (suggestion) {
49454
+ var suggestionName = symbolToString(suggestion);
49455
+ var isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
49456
+ var message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && ts.nodeIsSynthesized(nameArg) ? ts.Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
49457
+ : isUncheckedJS ? ts.Diagnostics.Could_not_find_name_0_Did_you_mean_1
49458
+ : ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1;
49459
+ var diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
49460
+ addErrorOrSuggestion(!isUncheckedJS, diagnostic);
49461
+ if (suggestion.valueDeclaration) {
49462
+ ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName));
49463
+ }
49462
49464
  }
49463
- else {
49464
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
49465
+ }
49466
+ if (!suggestion) {
49467
+ if (nameArg) {
49468
+ var lib = getSuggestedLibForNonExistentName(nameArg);
49469
+ if (lib) {
49470
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
49471
+ }
49472
+ else {
49473
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
49474
+ }
49465
49475
  }
49466
49476
  }
49477
+ suggestionCount++;
49467
49478
  }
49468
- suggestionCount++;
49469
- }
49479
+ });
49470
49480
  }
49471
49481
  return undefined;
49472
49482
  }
49483
+ if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
49484
+ // We have a match, but the reference occurred within a property initializer and the identifier also binds
49485
+ // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
49486
+ // with ESNext+useDefineForClassFields because the scope semantics are different.
49487
+ var propertyName = propertyWithInvalidInitializer.name;
49488
+ error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
49489
+ return undefined;
49490
+ }
49473
49491
  // Perform extra checks only if error reporting was requested
49474
- if (nameNotFoundMessage && produceDiagnostics) {
49475
- if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
49476
- // We have a match, but the reference occurred within a property initializer and the identifier also binds
49477
- // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
49478
- // with ESNext+useDefineForClassFields because the scope semantics are different.
49479
- var propertyName = propertyWithInvalidInitializer.name;
49480
- error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
49481
- return undefined;
49482
- }
49483
- // Only check for block-scoped variable if we have an error location and are looking for the
49484
- // name with variable meaning
49485
- // For example,
49486
- // declare module foo {
49487
- // interface bar {}
49488
- // }
49489
- // const foo/*1*/: foo/*2*/.bar;
49490
- // The foo at /*1*/ and /*2*/ will share same symbol with two meanings:
49491
- // block-scoped variable and namespace module. However, only when we
49492
- // try to resolve name in /*1*/ which is used in variable position,
49493
- // we want to check for block-scoped
49494
- if (errorLocation &&
49495
- (meaning & 2 /* BlockScopedVariable */ ||
49496
- ((meaning & 32 /* Class */ || meaning & 384 /* Enum */) && (meaning & 111551 /* Value */) === 111551 /* Value */))) {
49497
- var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
49498
- if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */ || exportOrLocalSymbol.flags & 32 /* Class */ || exportOrLocalSymbol.flags & 384 /* Enum */) {
49499
- checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
49500
- }
49501
- }
49502
- // If we're in an external module, we can't reference value symbols created from UMD export declarations
49503
- if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 4194304 /* JSDoc */)) {
49504
- var merged = getMergedSymbol(result);
49505
- if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
49506
- errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name));
49507
- }
49508
- }
49509
- // If we're in a parameter initializer or binding name, we can't reference the values of the parameter whose initializer we're within or parameters to the right
49510
- if (result && associatedDeclarationForContainingInitializerOrBindingName && !withinDeferredContext && (meaning & 111551 /* Value */) === 111551 /* Value */) {
49511
- var candidate = getMergedSymbol(getLateBoundSymbol(result));
49512
- var root = ts.getRootDeclaration(associatedDeclarationForContainingInitializerOrBindingName);
49513
- // A parameter initializer or binding pattern initializer within a parameter cannot refer to itself
49514
- if (candidate === getSymbolOfNode(associatedDeclarationForContainingInitializerOrBindingName)) {
49515
- error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_itself, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name));
49516
- }
49517
- // And it cannot refer to any declarations which come after it
49518
- else if (candidate.valueDeclaration && candidate.valueDeclaration.pos > associatedDeclarationForContainingInitializerOrBindingName.pos && root.parent.locals && lookup(root.parent.locals, candidate.escapedName, meaning) === candidate) {
49519
- error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
49520
- }
49521
- }
49522
- if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
49523
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
49524
- if (typeOnlyDeclaration) {
49525
- var message = typeOnlyDeclaration.kind === 275 /* ExportSpecifier */
49526
- ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
49527
- : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
49528
- var unescapedName = ts.unescapeLeadingUnderscores(name);
49529
- addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
49492
+ if (nameNotFoundMessage) {
49493
+ addLazyDiagnostic(function () {
49494
+ // Only check for block-scoped variable if we have an error location and are looking for the
49495
+ // name with variable meaning
49496
+ // For example,
49497
+ // declare module foo {
49498
+ // interface bar {}
49499
+ // }
49500
+ // const foo/*1*/: foo/*2*/.bar;
49501
+ // The foo at /*1*/ and /*2*/ will share same symbol with two meanings:
49502
+ // block-scoped variable and namespace module. However, only when we
49503
+ // try to resolve name in /*1*/ which is used in variable position,
49504
+ // we want to check for block-scoped
49505
+ if (errorLocation &&
49506
+ (meaning & 2 /* BlockScopedVariable */ ||
49507
+ ((meaning & 32 /* Class */ || meaning & 384 /* Enum */) && (meaning & 111551 /* Value */) === 111551 /* Value */))) {
49508
+ var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
49509
+ if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */ || exportOrLocalSymbol.flags & 32 /* Class */ || exportOrLocalSymbol.flags & 384 /* Enum */) {
49510
+ checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
49511
+ }
49512
+ }
49513
+ // If we're in an external module, we can't reference value symbols created from UMD export declarations
49514
+ if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 4194304 /* JSDoc */)) {
49515
+ var merged = getMergedSymbol(result);
49516
+ if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
49517
+ errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name));
49518
+ }
49519
+ }
49520
+ // If we're in a parameter initializer or binding name, we can't reference the values of the parameter whose initializer we're within or parameters to the right
49521
+ if (result && associatedDeclarationForContainingInitializerOrBindingName && !withinDeferredContext && (meaning & 111551 /* Value */) === 111551 /* Value */) {
49522
+ var candidate = getMergedSymbol(getLateBoundSymbol(result));
49523
+ var root = ts.getRootDeclaration(associatedDeclarationForContainingInitializerOrBindingName);
49524
+ // A parameter initializer or binding pattern initializer within a parameter cannot refer to itself
49525
+ if (candidate === getSymbolOfNode(associatedDeclarationForContainingInitializerOrBindingName)) {
49526
+ error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_itself, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name));
49527
+ }
49528
+ // And it cannot refer to any declarations which come after it
49529
+ else if (candidate.valueDeclaration && candidate.valueDeclaration.pos > associatedDeclarationForContainingInitializerOrBindingName.pos && root.parent.locals && lookup(root.parent.locals, candidate.escapedName, meaning) === candidate) {
49530
+ error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
49531
+ }
49532
+ }
49533
+ if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
49534
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
49535
+ if (typeOnlyDeclaration) {
49536
+ var message = typeOnlyDeclaration.kind === 275 /* ExportSpecifier */
49537
+ ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
49538
+ : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
49539
+ var unescapedName = ts.unescapeLeadingUnderscores(name);
49540
+ addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
49541
+ }
49530
49542
  }
49531
- }
49543
+ });
49532
49544
  }
49533
49545
  return result;
49534
49546
  }
@@ -51174,9 +51186,7 @@ var ts;
51174
51186
  var result = new Type(checker, flags);
51175
51187
  typeCount++;
51176
51188
  result.id = typeCount;
51177
- if (produceDiagnostics) { // Only record types from one checker
51178
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.recordType(result);
51179
- }
51189
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.recordType(result);
51180
51190
  return result;
51181
51191
  }
51182
51192
  function createOriginType(flags) {
@@ -64510,6 +64520,7 @@ var ts;
64510
64520
  return 0 /* False */;
64511
64521
  }
64512
64522
  function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
64523
+ var _a, _b;
64513
64524
  var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
64514
64525
  var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
64515
64526
  source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
@@ -64550,6 +64561,9 @@ var ts;
64550
64561
  return;
64551
64562
  }
64552
64563
  reportRelationError(headMessage, source, target);
64564
+ if (strictNullChecks && source.flags & 8650752 /* TypeVariable */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source) && isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */))) {
64565
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
64566
+ }
64553
64567
  }
64554
64568
  function traceUnionsOrIntersectionsTooLarge(source, target) {
64555
64569
  if (!ts.tracing) {
@@ -65322,7 +65336,7 @@ var ts;
65322
65336
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
65323
65337
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
65324
65338
  var constraint = getConstraintOfType(source);
65325
- if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
65339
+ if (!strictNullChecks && (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */))) {
65326
65340
  // A type variable with no constraint is not related to the non-primitive object type.
65327
65341
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
65328
65342
  resetErrorInfo(saveErrorInfo);
@@ -65330,12 +65344,12 @@ var ts;
65330
65344
  }
65331
65345
  }
65332
65346
  // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
65333
- else if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
65347
+ else if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState))) {
65334
65348
  resetErrorInfo(saveErrorInfo);
65335
65349
  return result;
65336
65350
  }
65337
65351
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
65338
- else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
65352
+ else if (constraint && (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState))) {
65339
65353
  resetErrorInfo(saveErrorInfo);
65340
65354
  return result;
65341
65355
  }
@@ -67394,12 +67408,14 @@ var ts;
67394
67408
  errorOrSuggestion(noImplicitAny, declaration, diagnostic, ts.declarationNameToString(ts.getNameOfDeclaration(declaration)), typeAsString);
67395
67409
  }
67396
67410
  function reportErrorsFromWidening(declaration, type, wideningKind) {
67397
- if (produceDiagnostics && noImplicitAny && ts.getObjectFlags(type) & 65536 /* ContainsWideningType */ && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration))) {
67398
- // Report implicit any error within type if possible, otherwise report error on declaration
67399
- if (!reportWideningErrorsInType(type)) {
67400
- reportImplicitAny(declaration, type, wideningKind);
67411
+ addLazyDiagnostic(function () {
67412
+ if (noImplicitAny && ts.getObjectFlags(type) & 65536 /* ContainsWideningType */ && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration))) {
67413
+ // Report implicit any error within type if possible, otherwise report error on declaration
67414
+ if (!reportWideningErrorsInType(type)) {
67415
+ reportImplicitAny(declaration, type, wideningKind);
67416
+ }
67401
67417
  }
67402
- }
67418
+ });
67403
67419
  }
67404
67420
  function applyToParameterTypes(source, target, callback) {
67405
67421
  var sourceCount = getParameterCount(source);
@@ -74162,6 +74178,7 @@ var ts;
74162
74178
  && !isOptionalPropertyDeclaration(valueDeclaration)
74163
74179
  && !(ts.isAccessExpression(node) && ts.isAccessExpression(node.expression))
74164
74180
  && !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
74181
+ && !(ts.isMethodDeclaration(valueDeclaration) && ts.getCombinedModifierFlags(valueDeclaration) & 32 /* Static */)
74165
74182
  && (compilerOptions.useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) {
74166
74183
  diagnosticMessage = error(right, ts.Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
74167
74184
  }
@@ -75391,7 +75408,7 @@ var ts;
75391
75408
  var isTaggedTemplate = node.kind === 210 /* TaggedTemplateExpression */;
75392
75409
  var isDecorator = node.kind === 165 /* Decorator */;
75393
75410
  var isJsxOpeningOrSelfClosingElement = ts.isJsxOpeningLikeElement(node);
75394
- var reportErrors = !candidatesOutArray && produceDiagnostics;
75411
+ var reportErrors = !candidatesOutArray;
75395
75412
  var typeArguments;
75396
75413
  if (!isDecorator) {
75397
75414
  typeArguments = node.typeArguments;
@@ -76671,11 +76688,13 @@ var ts;
76671
76688
  checkSourceElement(type);
76672
76689
  exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(exprType));
76673
76690
  var targetType = getTypeFromTypeNode(type);
76674
- if (produceDiagnostics && !isErrorType(targetType)) {
76675
- var widenedType = getWidenedType(exprType);
76676
- if (!isTypeComparableTo(targetType, widenedType)) {
76677
- checkTypeComparableTo(exprType, targetType, errNode, ts.Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first);
76678
- }
76691
+ if (!isErrorType(targetType)) {
76692
+ addLazyDiagnostic(function () {
76693
+ var widenedType = getWidenedType(exprType);
76694
+ if (!isTypeComparableTo(targetType, widenedType)) {
76695
+ checkTypeComparableTo(exprType, targetType, errNode, ts.Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first);
76696
+ }
76697
+ });
76679
76698
  }
76680
76699
  return targetType;
76681
76700
  }
@@ -77435,47 +77454,48 @@ var ts;
77435
77454
  * @param returnType - return type of the function, can be undefined if return type is not explicitly specified
77436
77455
  */
77437
77456
  function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func, returnType) {
77438
- if (!produceDiagnostics) {
77439
- return;
77440
- }
77441
- var functionFlags = ts.getFunctionFlags(func);
77442
- var type = returnType && unwrapReturnType(returnType, functionFlags);
77443
- // Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
77444
- if (type && maybeTypeOfKind(type, 1 /* Any */ | 16384 /* Void */)) {
77445
- return;
77446
- }
77447
- // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check.
77448
- // also if HasImplicitReturn flag is not set this means that all codepaths in function body end with return or throw
77449
- if (func.kind === 168 /* MethodSignature */ || ts.nodeIsMissing(func.body) || func.body.kind !== 235 /* Block */ || !functionHasImplicitReturn(func)) {
77450
- return;
77451
- }
77452
- var hasExplicitReturn = func.flags & 512 /* HasExplicitReturn */;
77453
- var errorNode = ts.getEffectiveReturnTypeNode(func) || func;
77454
- if (type && type.flags & 131072 /* Never */) {
77455
- error(errorNode, ts.Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
77456
- }
77457
- else if (type && !hasExplicitReturn) {
77458
- // minimal check: function has syntactic return type annotation and no explicit return statements in the body
77459
- // this function does not conform to the specification.
77460
- error(errorNode, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
77461
- }
77462
- else if (type && strictNullChecks && !isTypeAssignableTo(undefinedType, type)) {
77463
- error(errorNode, ts.Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined);
77464
- }
77465
- else if (compilerOptions.noImplicitReturns) {
77466
- if (!type) {
77467
- // If return type annotation is omitted check if function has any explicit return statements.
77468
- // If it does not have any - its inferred return type is void - don't do any checks.
77469
- // Otherwise get inferred return type from function body and report error only if it is not void / anytype
77470
- if (!hasExplicitReturn) {
77471
- return;
77472
- }
77473
- var inferredReturnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
77474
- if (isUnwrappedReturnTypeVoidOrAny(func, inferredReturnType)) {
77475
- return;
77457
+ addLazyDiagnostic(checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics);
77458
+ return;
77459
+ function checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics() {
77460
+ var functionFlags = ts.getFunctionFlags(func);
77461
+ var type = returnType && unwrapReturnType(returnType, functionFlags);
77462
+ // Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
77463
+ if (type && maybeTypeOfKind(type, 1 /* Any */ | 16384 /* Void */)) {
77464
+ return;
77465
+ }
77466
+ // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check.
77467
+ // also if HasImplicitReturn flag is not set this means that all codepaths in function body end with return or throw
77468
+ if (func.kind === 168 /* MethodSignature */ || ts.nodeIsMissing(func.body) || func.body.kind !== 235 /* Block */ || !functionHasImplicitReturn(func)) {
77469
+ return;
77470
+ }
77471
+ var hasExplicitReturn = func.flags & 512 /* HasExplicitReturn */;
77472
+ var errorNode = ts.getEffectiveReturnTypeNode(func) || func;
77473
+ if (type && type.flags & 131072 /* Never */) {
77474
+ error(errorNode, ts.Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
77475
+ }
77476
+ else if (type && !hasExplicitReturn) {
77477
+ // minimal check: function has syntactic return type annotation and no explicit return statements in the body
77478
+ // this function does not conform to the specification.
77479
+ error(errorNode, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
77480
+ }
77481
+ else if (type && strictNullChecks && !isTypeAssignableTo(undefinedType, type)) {
77482
+ error(errorNode, ts.Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined);
77483
+ }
77484
+ else if (compilerOptions.noImplicitReturns) {
77485
+ if (!type) {
77486
+ // If return type annotation is omitted check if function has any explicit return statements.
77487
+ // If it does not have any - its inferred return type is void - don't do any checks.
77488
+ // Otherwise get inferred return type from function body and report error only if it is not void / anytype
77489
+ if (!hasExplicitReturn) {
77490
+ return;
77491
+ }
77492
+ var inferredReturnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
77493
+ if (isUnwrappedReturnTypeVoidOrAny(func, inferredReturnType)) {
77494
+ return;
77495
+ }
77476
77496
  }
77497
+ error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
77477
77498
  }
77478
- error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
77479
77499
  }
77480
77500
  }
77481
77501
  function checkFunctionExpressionOrObjectLiteralMethod(node, checkMode) {
@@ -77735,49 +77755,50 @@ var ts;
77735
77755
  checkExpression(node.expression);
77736
77756
  return undefinedWideningType;
77737
77757
  }
77738
- function checkAwaitExpression(node) {
77758
+ function checkAwaitExpressionGrammar(node) {
77739
77759
  // Grammar checking
77740
- if (produceDiagnostics) {
77741
- var container = ts.getContainingFunctionOrClassStaticBlock(node);
77742
- if (container && ts.isClassStaticBlockDeclaration(container)) {
77743
- error(node, ts.Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block);
77744
- }
77745
- else if (!(node.flags & 32768 /* AwaitContext */)) {
77746
- if (ts.isInTopLevelContext(node)) {
77747
- var sourceFile = ts.getSourceFileOfNode(node);
77748
- if (!hasParseDiagnostics(sourceFile)) {
77749
- var span = void 0;
77750
- if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
77751
- if (!span)
77752
- span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
77753
- var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.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);
77754
- diagnostics.add(diagnostic);
77755
- }
77756
- if ((moduleKind !== ts.ModuleKind.ES2022 && moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
77760
+ var container = ts.getContainingFunctionOrClassStaticBlock(node);
77761
+ if (container && ts.isClassStaticBlockDeclaration(container)) {
77762
+ error(node, ts.Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block);
77763
+ }
77764
+ else if (!(node.flags & 32768 /* AwaitContext */)) {
77765
+ if (ts.isInTopLevelContext(node)) {
77766
+ var sourceFile = ts.getSourceFileOfNode(node);
77767
+ if (!hasParseDiagnostics(sourceFile)) {
77768
+ var span = void 0;
77769
+ if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
77770
+ if (!span)
77757
77771
  span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
77758
- var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
77759
- diagnostics.add(diagnostic);
77760
- }
77772
+ var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.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);
77773
+ diagnostics.add(diagnostic);
77761
77774
  }
77762
- }
77763
- else {
77764
- // use of 'await' in non-async function
77765
- var sourceFile = ts.getSourceFileOfNode(node);
77766
- if (!hasParseDiagnostics(sourceFile)) {
77767
- var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
77768
- var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules);
77769
- if (container && container.kind !== 171 /* Constructor */ && (ts.getFunctionFlags(container) & 2 /* Async */) === 0) {
77770
- var relatedInfo = ts.createDiagnosticForNode(container, ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async);
77771
- ts.addRelatedInfo(diagnostic, relatedInfo);
77772
- }
77775
+ if ((moduleKind !== ts.ModuleKind.ES2022 && moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
77776
+ span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
77777
+ var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
77773
77778
  diagnostics.add(diagnostic);
77774
77779
  }
77775
77780
  }
77776
77781
  }
77777
- if (isInParameterInitializerBeforeContainingFunction(node)) {
77778
- error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
77782
+ else {
77783
+ // use of 'await' in non-async function
77784
+ var sourceFile = ts.getSourceFileOfNode(node);
77785
+ if (!hasParseDiagnostics(sourceFile)) {
77786
+ var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
77787
+ var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules);
77788
+ if (container && container.kind !== 171 /* Constructor */ && (ts.getFunctionFlags(container) & 2 /* Async */) === 0) {
77789
+ var relatedInfo = ts.createDiagnosticForNode(container, ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async);
77790
+ ts.addRelatedInfo(diagnostic, relatedInfo);
77791
+ }
77792
+ diagnostics.add(diagnostic);
77793
+ }
77779
77794
  }
77780
77795
  }
77796
+ if (isInParameterInitializerBeforeContainingFunction(node)) {
77797
+ error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
77798
+ }
77799
+ }
77800
+ function checkAwaitExpression(node) {
77801
+ addLazyDiagnostic(function () { return checkAwaitExpressionGrammar(node); });
77781
77802
  var operandType = checkExpression(node.expression);
77782
77803
  var awaitedType = checkAwaitedType(operandType, /*withAlias*/ true, node, ts.Diagnostics.Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
77783
77804
  if (awaitedType === operandType && !isErrorType(awaitedType) && !(operandType.flags & 3 /* AnyOrUnknown */)) {
@@ -78601,7 +78622,10 @@ var ts;
78601
78622
  }
78602
78623
  }
78603
78624
  function checkAssignmentOperator(valueType) {
78604
- if (produceDiagnostics && ts.isAssignmentOperator(operator)) {
78625
+ if (ts.isAssignmentOperator(operator)) {
78626
+ addLazyDiagnostic(checkAssignmentOperatorWorker);
78627
+ }
78628
+ function checkAssignmentOperatorWorker() {
78605
78629
  // TypeScript 1.0 spec (April 2014): 4.17
78606
78630
  // An assignment of the form
78607
78631
  // VarExpr = ValueExpr
@@ -78700,15 +78724,7 @@ var ts;
78700
78724
  return [effectiveLeft, effectiveRight];
78701
78725
  }
78702
78726
  function checkYieldExpression(node) {
78703
- // Grammar checking
78704
- if (produceDiagnostics) {
78705
- if (!(node.flags & 8192 /* YieldContext */)) {
78706
- grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
78707
- }
78708
- if (isInParameterInitializerBeforeContainingFunction(node)) {
78709
- error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
78710
- }
78711
- }
78727
+ addLazyDiagnostic(checkYieldExpressionGrammar);
78712
78728
  var func = ts.getContainingFunction(node);
78713
78729
  if (!func)
78714
78730
  return anyType;
@@ -78754,14 +78770,24 @@ var ts;
78754
78770
  var type = getContextualIterationType(2 /* Next */, func);
78755
78771
  if (!type) {
78756
78772
  type = anyType;
78757
- if (produceDiagnostics && noImplicitAny && !ts.expressionResultIsUnused(node)) {
78758
- var contextualType = getContextualType(node);
78759
- if (!contextualType || isTypeAny(contextualType)) {
78760
- error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
78773
+ addLazyDiagnostic(function () {
78774
+ if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
78775
+ var contextualType = getContextualType(node);
78776
+ if (!contextualType || isTypeAny(contextualType)) {
78777
+ error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
78778
+ }
78761
78779
  }
78762
- }
78780
+ });
78763
78781
  }
78764
78782
  return type;
78783
+ function checkYieldExpressionGrammar() {
78784
+ if (!(node.flags & 8192 /* YieldContext */)) {
78785
+ grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
78786
+ }
78787
+ if (isInParameterInitializerBeforeContainingFunction(node)) {
78788
+ error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
78789
+ }
78790
+ }
78765
78791
  }
78766
78792
  function checkConditionalExpression(node, checkMode) {
78767
78793
  checkTruthinessExpression(node.condition);
@@ -79357,9 +79383,7 @@ var ts;
79357
79383
  varianceTypeParameter = saveVarianceTypeParameter;
79358
79384
  }
79359
79385
  }
79360
- if (produceDiagnostics) {
79361
- checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
79362
- }
79386
+ addLazyDiagnostic(function () { return checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); });
79363
79387
  }
79364
79388
  function checkParameter(node) {
79365
79389
  // Grammar checking
@@ -79513,7 +79537,8 @@ var ts;
79513
79537
  if (node.type) {
79514
79538
  checkSourceElement(node.type);
79515
79539
  }
79516
- if (produceDiagnostics) {
79540
+ addLazyDiagnostic(checkSignatureDeclarationDiagnostics);
79541
+ function checkSignatureDeclarationDiagnostics() {
79517
79542
  checkCollisionWithArgumentsInGeneratedCode(node);
79518
79543
  var returnTypeNode = ts.getEffectiveReturnTypeNode(node);
79519
79544
  if (noImplicitAny && !returnTypeNode) {
@@ -79803,9 +79828,8 @@ var ts;
79803
79828
  if (ts.nodeIsMissing(node.body)) {
79804
79829
  return;
79805
79830
  }
79806
- if (!produceDiagnostics) {
79807
- return;
79808
- }
79831
+ addLazyDiagnostic(checkConstructorDeclarationDiagnostics);
79832
+ return;
79809
79833
  function isInstancePropertyWithInitializerOrPrivateIdentifierProperty(n) {
79810
79834
  if (ts.isPrivateIdentifierClassElementDeclaration(n)) {
79811
79835
  return true;
@@ -79814,54 +79838,56 @@ var ts;
79814
79838
  !ts.isStatic(n) &&
79815
79839
  !!n.initializer;
79816
79840
  }
79817
- // TS 1.0 spec (April 2014): 8.3.2
79818
- // Constructors of classes with no extends clause may not contain super calls, whereas
79819
- // constructors of derived classes must contain at least one super call somewhere in their function body.
79820
- var containingClassDecl = node.parent;
79821
- if (ts.getClassExtendsHeritageElement(containingClassDecl)) {
79822
- captureLexicalThis(node.parent, containingClassDecl);
79823
- var classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
79824
- var superCall = findFirstSuperCall(node.body);
79825
- if (superCall) {
79826
- if (classExtendsNull) {
79827
- error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
79828
- }
79829
- // A super call must be root-level in a constructor if both of the following are true:
79830
- // - The containing class is a derived class.
79831
- // - The constructor declares parameter properties
79832
- // or the containing class declares instance member variables with initializers.
79833
- var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
79834
- (ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
79835
- ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
79836
- if (superCallShouldBeRootLevel) {
79837
- // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
79838
- // See GH #8277
79839
- if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
79840
- error(superCall, ts.Diagnostics.A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers);
79841
- }
79842
- // Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
79843
- else {
79844
- var superCallStatement = void 0;
79845
- for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
79846
- var statement = _a[_i];
79847
- if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
79848
- superCallStatement = statement;
79849
- break;
79850
- }
79851
- if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
79852
- break;
79853
- }
79854
- }
79841
+ function checkConstructorDeclarationDiagnostics() {
79842
+ // TS 1.0 spec (April 2014): 8.3.2
79843
+ // Constructors of classes with no extends clause may not contain super calls, whereas
79844
+ // constructors of derived classes must contain at least one super call somewhere in their function body.
79845
+ var containingClassDecl = node.parent;
79846
+ if (ts.getClassExtendsHeritageElement(containingClassDecl)) {
79847
+ captureLexicalThis(node.parent, containingClassDecl);
79848
+ var classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
79849
+ var superCall = findFirstSuperCall(node.body);
79850
+ if (superCall) {
79851
+ if (classExtendsNull) {
79852
+ error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
79853
+ }
79854
+ // A super call must be root-level in a constructor if both of the following are true:
79855
+ // - The containing class is a derived class.
79856
+ // - The constructor declares parameter properties
79857
+ // or the containing class declares instance member variables with initializers.
79858
+ var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
79859
+ (ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
79860
+ ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
79861
+ if (superCallShouldBeRootLevel) {
79855
79862
  // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
79856
79863
  // See GH #8277
79857
- if (superCallStatement === undefined) {
79858
- error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
79864
+ if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
79865
+ error(superCall, ts.Diagnostics.A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers);
79866
+ }
79867
+ // Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
79868
+ else {
79869
+ var superCallStatement = void 0;
79870
+ for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
79871
+ var statement = _a[_i];
79872
+ if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
79873
+ superCallStatement = statement;
79874
+ break;
79875
+ }
79876
+ if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
79877
+ break;
79878
+ }
79879
+ }
79880
+ // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
79881
+ // See GH #8277
79882
+ if (superCallStatement === undefined) {
79883
+ error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
79884
+ }
79859
79885
  }
79860
79886
  }
79861
79887
  }
79862
- }
79863
- else if (!classExtendsNull) {
79864
- error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
79888
+ else if (!classExtendsNull) {
79889
+ error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
79890
+ }
79865
79891
  }
79866
79892
  }
79867
79893
  }
@@ -79879,7 +79905,10 @@ var ts;
79879
79905
  return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
79880
79906
  }
79881
79907
  function checkAccessorDeclaration(node) {
79882
- if (produceDiagnostics) {
79908
+ addLazyDiagnostic(checkAccessorDeclarationDiagnostics);
79909
+ checkSourceElement(node.body);
79910
+ setNodeLinksForPrivateIdentifierScope(node);
79911
+ function checkAccessorDeclarationDiagnostics() {
79883
79912
  // Grammar checking accessors
79884
79913
  if (!checkGrammarFunctionLikeDeclaration(node) && !checkGrammarAccessor(node))
79885
79914
  checkGrammarComputedPropertyName(node.name);
@@ -79929,8 +79958,6 @@ var ts;
79929
79958
  checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnType);
79930
79959
  }
79931
79960
  }
79932
- checkSourceElement(node.body);
79933
- setNodeLinksForPrivateIdentifierScope(node);
79934
79961
  }
79935
79962
  function checkMissingDeclaration(node) {
79936
79963
  checkDecorators(node);
@@ -79973,11 +80000,13 @@ var ts;
79973
80000
  ts.forEach(node.typeArguments, checkSourceElement);
79974
80001
  var type = getTypeFromTypeReference(node);
79975
80002
  if (!isErrorType(type)) {
79976
- if (node.typeArguments && produceDiagnostics) {
79977
- var typeParameters = getTypeParametersForTypeReference(node);
79978
- if (typeParameters) {
79979
- checkTypeArgumentConstraints(node, typeParameters);
79980
- }
80003
+ if (node.typeArguments) {
80004
+ addLazyDiagnostic(function () {
80005
+ var typeParameters = getTypeParametersForTypeReference(node);
80006
+ if (typeParameters) {
80007
+ checkTypeArgumentConstraints(node, typeParameters);
80008
+ }
80009
+ });
79981
80010
  }
79982
80011
  var symbol = getNodeLinks(node).resolvedSymbol;
79983
80012
  if (symbol) {
@@ -80005,7 +80034,8 @@ var ts;
80005
80034
  }
80006
80035
  function checkTypeLiteral(node) {
80007
80036
  ts.forEach(node.members, checkSourceElement);
80008
- if (produceDiagnostics) {
80037
+ addLazyDiagnostic(checkTypeLiteralDiagnostics);
80038
+ function checkTypeLiteralDiagnostics() {
80009
80039
  var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
80010
80040
  checkIndexConstraints(type, type.symbol);
80011
80041
  checkTypeForDuplicateIndexSignatures(node);
@@ -80196,9 +80226,9 @@ var ts;
80196
80226
  return flags & flagsToCheck;
80197
80227
  }
80198
80228
  function checkFunctionOrConstructorSymbol(symbol) {
80199
- if (!produceDiagnostics) {
80200
- return;
80201
- }
80229
+ addLazyDiagnostic(function () { return checkFunctionOrConstructorSymbolWorker(symbol); });
80230
+ }
80231
+ function checkFunctionOrConstructorSymbolWorker(symbol) {
80202
80232
  function getCanonicalOverload(overloads, implementation) {
80203
80233
  // Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
80204
80234
  // Error on all deviations from this canonical set of flags
@@ -80419,9 +80449,9 @@ var ts;
80419
80449
  }
80420
80450
  }
80421
80451
  function checkExportsOnMergedDeclarations(node) {
80422
- if (!produceDiagnostics) {
80423
- return;
80424
- }
80452
+ addLazyDiagnostic(function () { return checkExportsOnMergedDeclarationsWorker(node); });
80453
+ }
80454
+ function checkExportsOnMergedDeclarationsWorker(node) {
80425
80455
  // if localSymbol is defined on node then node itself is exported - check is required
80426
80456
  var symbol = node.localSymbol;
80427
80457
  if (!symbol) {
@@ -81065,7 +81095,8 @@ var ts;
81065
81095
  ts.forEach(node.decorators, checkDecorator);
81066
81096
  }
81067
81097
  function checkFunctionDeclaration(node) {
81068
- if (produceDiagnostics) {
81098
+ addLazyDiagnostic(checkFunctionDeclarationDiagnostics);
81099
+ function checkFunctionDeclarationDiagnostics() {
81069
81100
  checkFunctionOrMethodDeclaration(node);
81070
81101
  checkGrammarForGenerator(node);
81071
81102
  checkCollisionsForDeclarationName(node, node.name);
@@ -81099,10 +81130,13 @@ var ts;
81099
81130
  checkSourceElement(node.typeExpression);
81100
81131
  }
81101
81132
  function checkJSDocFunctionType(node) {
81102
- if (produceDiagnostics && !node.type && !ts.isJSDocConstructSignature(node)) {
81103
- reportImplicitAny(node, anyType);
81104
- }
81133
+ addLazyDiagnostic(checkJSDocFunctionTypeImplicitAny);
81105
81134
  checkSignatureDeclaration(node);
81135
+ function checkJSDocFunctionTypeImplicitAny() {
81136
+ if (!node.type && !ts.isJSDocConstructSignature(node)) {
81137
+ reportImplicitAny(node, anyType);
81138
+ }
81139
+ }
81106
81140
  }
81107
81141
  function checkJSDocImplementsTag(node) {
81108
81142
  var classLike = ts.getEffectiveJSDocHost(node);
@@ -81183,19 +81217,7 @@ var ts;
81183
81217
  var body = node.kind === 168 /* MethodSignature */ ? undefined : node.body;
81184
81218
  checkSourceElement(body);
81185
81219
  checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, getReturnTypeFromAnnotation(node));
81186
- if (produceDiagnostics && !ts.getEffectiveReturnTypeNode(node)) {
81187
- // Report an implicit any error if there is no body, no explicit return type, and node is not a private method
81188
- // in an ambient context
81189
- if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) {
81190
- reportImplicitAny(node, anyType);
81191
- }
81192
- if (functionFlags & 1 /* Generator */ && ts.nodeIsPresent(body)) {
81193
- // A generator with a body and no type annotation can still cause errors. It can error if the
81194
- // yielded values have no common supertype, or it can give an implicit any error if it has no
81195
- // yielded values. The only way to trigger these errors is to try checking its return type.
81196
- getReturnTypeOfSignature(getSignatureFromDeclaration(node));
81197
- }
81198
- }
81220
+ addLazyDiagnostic(checkFunctionOrMethodDeclarationDiagnostics);
81199
81221
  // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature
81200
81222
  if (ts.isInJSFile(node)) {
81201
81223
  var typeTag = ts.getJSDocTypeTag(node);
@@ -81203,10 +81225,26 @@ var ts;
81203
81225
  error(typeTag.typeExpression.type, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature);
81204
81226
  }
81205
81227
  }
81228
+ function checkFunctionOrMethodDeclarationDiagnostics() {
81229
+ if (!ts.getEffectiveReturnTypeNode(node)) {
81230
+ // Report an implicit any error if there is no body, no explicit return type, and node is not a private method
81231
+ // in an ambient context
81232
+ if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) {
81233
+ reportImplicitAny(node, anyType);
81234
+ }
81235
+ if (functionFlags & 1 /* Generator */ && ts.nodeIsPresent(body)) {
81236
+ // A generator with a body and no type annotation can still cause errors. It can error if the
81237
+ // yielded values have no common supertype, or it can give an implicit any error if it has no
81238
+ // yielded values. The only way to trigger these errors is to try checking its return type.
81239
+ getReturnTypeOfSignature(getSignatureFromDeclaration(node));
81240
+ }
81241
+ }
81242
+ }
81206
81243
  }
81207
81244
  function registerForUnusedIdentifiersCheck(node) {
81208
- // May be in a call such as getTypeOfNode that happened to call this. But potentiallyUnusedIdentifiers is only defined in the scope of `checkSourceFile`.
81209
- if (produceDiagnostics) {
81245
+ addLazyDiagnostic(registerForUnusedIdentifiersCheckDiagnostics);
81246
+ function registerForUnusedIdentifiersCheckDiagnostics() {
81247
+ // May be in a call such as getTypeOfNode that happened to call this. But potentiallyUnusedIdentifiers is only defined in the scope of `checkSourceFile`.
81210
81248
  var sourceFile = ts.getSourceFileOfNode(node);
81211
81249
  var potentiallyUnusedIdentifiers = allPotentiallyUnusedIdentifiers.get(sourceFile.path);
81212
81250
  if (!potentiallyUnusedIdentifiers) {
@@ -82980,26 +83018,31 @@ var ts;
82980
83018
  hasDuplicateDefaultClause = true;
82981
83019
  }
82982
83020
  }
82983
- if (produceDiagnostics && clause.kind === 289 /* CaseClause */) {
82984
- // TypeScript 1.0 spec (April 2014): 5.9
82985
- // In a 'switch' statement, each 'case' expression must be of a type that is comparable
82986
- // to or from the type of the 'switch' expression.
82987
- var caseType = checkExpression(clause.expression);
82988
- var caseIsLiteral = isLiteralType(caseType);
82989
- var comparedExpressionType = expressionType;
82990
- if (!caseIsLiteral || !expressionIsLiteral) {
82991
- caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
82992
- comparedExpressionType = getBaseTypeOfLiteralType(expressionType);
82993
- }
82994
- if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) {
82995
- // expressionType is not comparable to caseType, try the reversed check and report errors if it fails
82996
- checkTypeComparableTo(caseType, comparedExpressionType, clause.expression, /*headMessage*/ undefined);
82997
- }
83021
+ if (clause.kind === 289 /* CaseClause */) {
83022
+ addLazyDiagnostic(createLazyCaseClauseDiagnostics(clause));
82998
83023
  }
82999
83024
  ts.forEach(clause.statements, checkSourceElement);
83000
83025
  if (compilerOptions.noFallthroughCasesInSwitch && clause.fallthroughFlowNode && isReachableFlowNode(clause.fallthroughFlowNode)) {
83001
83026
  error(clause, ts.Diagnostics.Fallthrough_case_in_switch);
83002
83027
  }
83028
+ function createLazyCaseClauseDiagnostics(clause) {
83029
+ return function () {
83030
+ // TypeScript 1.0 spec (April 2014): 5.9
83031
+ // In a 'switch' statement, each 'case' expression must be of a type that is comparable
83032
+ // to or from the type of the 'switch' expression.
83033
+ var caseType = checkExpression(clause.expression);
83034
+ var caseIsLiteral = isLiteralType(caseType);
83035
+ var comparedExpressionType = expressionType;
83036
+ if (!caseIsLiteral || !expressionIsLiteral) {
83037
+ caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
83038
+ comparedExpressionType = getBaseTypeOfLiteralType(expressionType);
83039
+ }
83040
+ if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) {
83041
+ // expressionType is not comparable to caseType, try the reversed check and report errors if it fails
83042
+ checkTypeComparableTo(caseType, comparedExpressionType, clause.expression, /*headMessage*/ undefined);
83043
+ }
83044
+ };
83045
+ }
83003
83046
  });
83004
83047
  if (node.caseBlock.locals) {
83005
83048
  registerForUnusedIdentifiersCheck(node.caseBlock);
@@ -83220,26 +83263,29 @@ var ts;
83220
83263
  * Check each type parameter and check that type parameters have no duplicate type parameter declarations
83221
83264
  */
83222
83265
  function checkTypeParameters(typeParameterDeclarations) {
83266
+ var seenDefault = false;
83223
83267
  if (typeParameterDeclarations) {
83224
- var seenDefault = false;
83225
83268
  for (var i = 0; i < typeParameterDeclarations.length; i++) {
83226
83269
  var node = typeParameterDeclarations[i];
83227
83270
  checkTypeParameter(node);
83228
- if (produceDiagnostics) {
83229
- if (node.default) {
83230
- seenDefault = true;
83231
- checkTypeParametersNotReferenced(node.default, typeParameterDeclarations, i);
83232
- }
83233
- else if (seenDefault) {
83234
- error(node, ts.Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters);
83235
- }
83236
- for (var j = 0; j < i; j++) {
83237
- if (typeParameterDeclarations[j].symbol === node.symbol) {
83238
- error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
83239
- }
83271
+ addLazyDiagnostic(createCheckTypeParameterDiagnostic(node, i));
83272
+ }
83273
+ }
83274
+ function createCheckTypeParameterDiagnostic(node, i) {
83275
+ return function () {
83276
+ if (node.default) {
83277
+ seenDefault = true;
83278
+ checkTypeParametersNotReferenced(node.default, typeParameterDeclarations, i);
83279
+ }
83280
+ else if (seenDefault) {
83281
+ error(node, ts.Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters);
83282
+ }
83283
+ for (var j = 0; j < i; j++) {
83284
+ if (typeParameterDeclarations[j].symbol === node.symbol) {
83285
+ error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
83240
83286
  }
83241
83287
  }
83242
- }
83288
+ };
83243
83289
  }
83244
83290
  }
83245
83291
  /** Check that type parameter defaults only reference previously declared type parameters */
@@ -83371,85 +83417,90 @@ var ts;
83371
83417
  if (extendsNode && extendsNode !== baseTypeNode) {
83372
83418
  checkExpression(extendsNode.expression);
83373
83419
  }
83374
- var baseTypes = getBaseTypes(type);
83375
- if (baseTypes.length && produceDiagnostics) {
83376
- var baseType_1 = baseTypes[0];
83377
- var baseConstructorType = getBaseConstructorTypeOfClass(type);
83378
- var staticBaseType = getApparentType(baseConstructorType);
83379
- checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
83380
- checkSourceElement(baseTypeNode.expression);
83381
- if (ts.some(baseTypeNode.typeArguments)) {
83382
- ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
83383
- for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode); _i < _a.length; _i++) {
83384
- var constructor = _a[_i];
83385
- if (!checkTypeArgumentConstraints(baseTypeNode, constructor.typeParameters)) {
83386
- break;
83420
+ var baseTypes_2 = getBaseTypes(type);
83421
+ if (baseTypes_2.length) {
83422
+ addLazyDiagnostic(function () {
83423
+ var baseType = baseTypes_2[0];
83424
+ var baseConstructorType = getBaseConstructorTypeOfClass(type);
83425
+ var staticBaseType = getApparentType(baseConstructorType);
83426
+ checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
83427
+ checkSourceElement(baseTypeNode.expression);
83428
+ if (ts.some(baseTypeNode.typeArguments)) {
83429
+ ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
83430
+ for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode); _i < _a.length; _i++) {
83431
+ var constructor = _a[_i];
83432
+ if (!checkTypeArgumentConstraints(baseTypeNode, constructor.typeParameters)) {
83433
+ break;
83434
+ }
83387
83435
  }
83388
83436
  }
83389
- }
83390
- var baseWithThis = getTypeWithThisArgument(baseType_1, type.thisType);
83391
- if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
83392
- issueMemberSpecificError(node, typeWithThis, baseWithThis, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
83393
- }
83394
- else {
83395
- // Report static side error only when instance type is assignable
83396
- checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
83397
- }
83398
- if (baseConstructorType.flags & 8650752 /* TypeVariable */) {
83399
- if (!isMixinConstructorType(staticType)) {
83400
- error(node.name || node, ts.Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
83437
+ var baseWithThis = getTypeWithThisArgument(baseType, type.thisType);
83438
+ if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
83439
+ issueMemberSpecificError(node, typeWithThis, baseWithThis, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
83401
83440
  }
83402
83441
  else {
83403
- var constructSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */);
83404
- if (constructSignatures.some(function (signature) { return signature.flags & 4 /* Abstract */; }) && !ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
83405
- error(node.name || node, ts.Diagnostics.A_mixin_class_that_extends_from_a_type_variable_containing_an_abstract_construct_signature_must_also_be_declared_abstract);
83442
+ // Report static side error only when instance type is assignable
83443
+ checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
83444
+ }
83445
+ if (baseConstructorType.flags & 8650752 /* TypeVariable */) {
83446
+ if (!isMixinConstructorType(staticType)) {
83447
+ error(node.name || node, ts.Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
83448
+ }
83449
+ else {
83450
+ var constructSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */);
83451
+ if (constructSignatures.some(function (signature) { return signature.flags & 4 /* Abstract */; }) && !ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
83452
+ error(node.name || node, ts.Diagnostics.A_mixin_class_that_extends_from_a_type_variable_containing_an_abstract_construct_signature_must_also_be_declared_abstract);
83453
+ }
83406
83454
  }
83407
83455
  }
83408
- }
83409
- if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */) && !(baseConstructorType.flags & 8650752 /* TypeVariable */)) {
83410
- // When the static base type is a "class-like" constructor function (but not actually a class), we verify
83411
- // that all instantiated base constructor signatures return the same type.
83412
- var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode);
83413
- if (ts.forEach(constructors, function (sig) { return !isJSConstructor(sig.declaration) && !isTypeIdenticalTo(getReturnTypeOfSignature(sig), baseType_1); })) {
83414
- error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
83456
+ if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */) && !(baseConstructorType.flags & 8650752 /* TypeVariable */)) {
83457
+ // When the static base type is a "class-like" constructor function (but not actually a class), we verify
83458
+ // that all instantiated base constructor signatures return the same type.
83459
+ var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode);
83460
+ if (ts.forEach(constructors, function (sig) { return !isJSConstructor(sig.declaration) && !isTypeIdenticalTo(getReturnTypeOfSignature(sig), baseType); })) {
83461
+ error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
83462
+ }
83415
83463
  }
83416
- }
83417
- checkKindsOfPropertyMemberOverrides(type, baseType_1);
83464
+ checkKindsOfPropertyMemberOverrides(type, baseType);
83465
+ });
83418
83466
  }
83419
83467
  }
83420
83468
  checkMembersForOverrideModifier(node, type, typeWithThis, staticType);
83421
83469
  var implementedTypeNodes = ts.getEffectiveImplementsTypeNodes(node);
83422
83470
  if (implementedTypeNodes) {
83423
- for (var _b = 0, implementedTypeNodes_1 = implementedTypeNodes; _b < implementedTypeNodes_1.length; _b++) {
83424
- var typeRefNode = implementedTypeNodes_1[_b];
83471
+ for (var _i = 0, implementedTypeNodes_1 = implementedTypeNodes; _i < implementedTypeNodes_1.length; _i++) {
83472
+ var typeRefNode = implementedTypeNodes_1[_i];
83425
83473
  if (!ts.isEntityNameExpression(typeRefNode.expression) || ts.isOptionalChain(typeRefNode.expression)) {
83426
83474
  error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
83427
83475
  }
83428
83476
  checkTypeReferenceNode(typeRefNode);
83429
- if (produceDiagnostics) {
83430
- var t = getReducedType(getTypeFromTypeNode(typeRefNode));
83431
- if (!isErrorType(t)) {
83432
- if (isValidBaseType(t)) {
83433
- var genericDiag = t.symbol && t.symbol.flags & 32 /* Class */ ?
83434
- ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
83435
- ts.Diagnostics.Class_0_incorrectly_implements_interface_1;
83436
- var baseWithThis = getTypeWithThisArgument(t, type.thisType);
83437
- if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
83438
- issueMemberSpecificError(node, typeWithThis, baseWithThis, genericDiag);
83439
- }
83440
- }
83441
- else {
83442
- error(typeRefNode, ts.Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
83443
- }
83444
- }
83445
- }
83477
+ addLazyDiagnostic(createImplementsDiagnostics(typeRefNode));
83446
83478
  }
83447
83479
  }
83448
- if (produceDiagnostics) {
83480
+ addLazyDiagnostic(function () {
83449
83481
  checkIndexConstraints(type, symbol);
83450
83482
  checkIndexConstraints(staticType, symbol, /*isStaticIndex*/ true);
83451
83483
  checkTypeForDuplicateIndexSignatures(node);
83452
83484
  checkPropertyInitialization(node);
83485
+ });
83486
+ function createImplementsDiagnostics(typeRefNode) {
83487
+ return function () {
83488
+ var t = getReducedType(getTypeFromTypeNode(typeRefNode));
83489
+ if (!isErrorType(t)) {
83490
+ if (isValidBaseType(t)) {
83491
+ var genericDiag = t.symbol && t.symbol.flags & 32 /* Class */ ?
83492
+ ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
83493
+ ts.Diagnostics.Class_0_incorrectly_implements_interface_1;
83494
+ var baseWithThis = getTypeWithThisArgument(t, type.thisType);
83495
+ if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
83496
+ issueMemberSpecificError(node, typeWithThis, baseWithThis, genericDiag);
83497
+ }
83498
+ }
83499
+ else {
83500
+ error(typeRefNode, ts.Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
83501
+ }
83502
+ }
83503
+ };
83453
83504
  }
83454
83505
  }
83455
83506
  function checkMembersForOverrideModifier(node, type, typeWithThis, staticType) {
@@ -83773,8 +83824,8 @@ var ts;
83773
83824
  ts.forEach(properties, function (p) {
83774
83825
  seen.set(p.escapedName, p);
83775
83826
  });
83776
- for (var _i = 0, baseTypes_2 = baseTypes; _i < baseTypes_2.length; _i++) {
83777
- var base = baseTypes_2[_i];
83827
+ for (var _i = 0, baseTypes_3 = baseTypes; _i < baseTypes_3.length; _i++) {
83828
+ var base = baseTypes_3[_i];
83778
83829
  var properties_5 = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
83779
83830
  for (var _a = 0, properties_4 = properties_5; _a < properties_4.length; _a++) {
83780
83831
  var prop = properties_4[_a];
@@ -83796,8 +83847,8 @@ var ts;
83796
83847
  seen.set(p.escapedName, { prop: p, containingType: type });
83797
83848
  });
83798
83849
  var ok = true;
83799
- for (var _i = 0, baseTypes_3 = baseTypes; _i < baseTypes_3.length; _i++) {
83800
- var base = baseTypes_3[_i];
83850
+ for (var _i = 0, baseTypes_4 = baseTypes; _i < baseTypes_4.length; _i++) {
83851
+ var base = baseTypes_4[_i];
83801
83852
  var properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
83802
83853
  for (var _a = 0, properties_6 = properties; _a < properties_6.length; _a++) {
83803
83854
  var prop = properties_6[_a];
@@ -83881,7 +83932,7 @@ var ts;
83881
83932
  if (!checkGrammarDecoratorsAndModifiers(node))
83882
83933
  checkGrammarInterfaceDeclaration(node);
83883
83934
  checkTypeParameters(node.typeParameters);
83884
- if (produceDiagnostics) {
83935
+ addLazyDiagnostic(function () {
83885
83936
  checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
83886
83937
  checkExportsOnMergedDeclarations(node);
83887
83938
  var symbol = getSymbolOfNode(node);
@@ -83901,7 +83952,7 @@ var ts;
83901
83952
  }
83902
83953
  }
83903
83954
  checkObjectTypeForDuplicateDeclarations(node);
83904
- }
83955
+ });
83905
83956
  ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
83906
83957
  if (!ts.isEntityNameExpression(heritageElement.expression) || ts.isOptionalChain(heritageElement.expression)) {
83907
83958
  error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
@@ -83909,10 +83960,10 @@ var ts;
83909
83960
  checkTypeReferenceNode(heritageElement);
83910
83961
  });
83911
83962
  ts.forEach(node.members, checkSourceElement);
83912
- if (produceDiagnostics) {
83963
+ addLazyDiagnostic(function () {
83913
83964
  checkTypeForDuplicateIndexSignatures(node);
83914
83965
  registerForUnusedIdentifiersCheck(node);
83915
- }
83966
+ });
83916
83967
  }
83917
83968
  function checkTypeAliasDeclaration(node) {
83918
83969
  // Grammar checking
@@ -84101,9 +84152,9 @@ var ts;
84101
84152
  ts.isStringLiteralLike(node.argumentExpression);
84102
84153
  }
84103
84154
  function checkEnumDeclaration(node) {
84104
- if (!produceDiagnostics) {
84105
- return;
84106
- }
84155
+ addLazyDiagnostic(function () { return checkEnumDeclarationWorker(node); });
84156
+ }
84157
+ function checkEnumDeclarationWorker(node) {
84107
84158
  // Grammar checking
84108
84159
  checkGrammarDecoratorsAndModifiers(node);
84109
84160
  checkCollisionsForDeclarationName(node, node.name);
@@ -84183,7 +84234,14 @@ var ts;
84183
84234
  }
84184
84235
  }
84185
84236
  function checkModuleDeclaration(node) {
84186
- if (produceDiagnostics) {
84237
+ if (node.body) {
84238
+ checkSourceElement(node.body);
84239
+ if (!ts.isGlobalScopeAugmentation(node)) {
84240
+ registerForUnusedIdentifiersCheck(node);
84241
+ }
84242
+ }
84243
+ addLazyDiagnostic(checkModuleDeclarationDiagnostics);
84244
+ function checkModuleDeclarationDiagnostics() {
84187
84245
  // Grammar checking
84188
84246
  var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
84189
84247
  var inAmbientContext = node.flags & 8388608 /* Ambient */;
@@ -84266,12 +84324,6 @@ var ts;
84266
84324
  }
84267
84325
  }
84268
84326
  }
84269
- if (node.body) {
84270
- checkSourceElement(node.body);
84271
- if (!ts.isGlobalScopeAugmentation(node)) {
84272
- registerForUnusedIdentifiersCheck(node);
84273
- }
84274
- }
84275
84327
  }
84276
84328
  function checkModuleAugmentationElement(node, isGlobalAugmentation) {
84277
84329
  var _a;
@@ -85208,13 +85260,16 @@ var ts;
85208
85260
  if (ts.isExternalOrCommonJsModule(node)) {
85209
85261
  registerForUnusedIdentifiersCheck(node);
85210
85262
  }
85211
- if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
85212
- checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
85213
- if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
85214
- diagnostics.add(diag);
85215
- }
85216
- });
85217
- }
85263
+ addLazyDiagnostic(function () {
85264
+ // This relies on the results of other lazy diagnostics, so must be computed after them
85265
+ if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
85266
+ checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
85267
+ if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
85268
+ diagnostics.add(diag);
85269
+ }
85270
+ });
85271
+ }
85272
+ });
85218
85273
  if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
85219
85274
  !node.isDeclarationFile &&
85220
85275
  ts.isExternalModule(node)) {
@@ -85254,15 +85309,35 @@ var ts;
85254
85309
  cancellationToken = undefined;
85255
85310
  }
85256
85311
  }
85312
+ function ensurePendingDiagnosticWorkComplete() {
85313
+ // Invoke any existing lazy diagnostics to add them, clear the backlog of diagnostics
85314
+ for (var _i = 0, deferredDiagnosticsCallbacks_1 = deferredDiagnosticsCallbacks; _i < deferredDiagnosticsCallbacks_1.length; _i++) {
85315
+ var cb = deferredDiagnosticsCallbacks_1[_i];
85316
+ cb();
85317
+ }
85318
+ deferredDiagnosticsCallbacks = [];
85319
+ }
85320
+ function checkSourceFileWithEagerDiagnostics(sourceFile) {
85321
+ ensurePendingDiagnosticWorkComplete();
85322
+ // then setup diagnostics for immediate invocation (as we are about to collect them, and
85323
+ // this avoids the overhead of longer-lived callbacks we don't need to allocate)
85324
+ // This also serves to make the shift to possibly lazy diagnostics transparent to serial command-line scenarios
85325
+ // (as in those cases, all the diagnostics will still be computed as the appropriate place in the tree,
85326
+ // thus much more likely retaining the same union ordering as before we had lazy diagnostics)
85327
+ var oldAddLazyDiagnostics = addLazyDiagnostic;
85328
+ addLazyDiagnostic = function (cb) { return cb(); };
85329
+ checkSourceFile(sourceFile);
85330
+ addLazyDiagnostic = oldAddLazyDiagnostics;
85331
+ }
85257
85332
  function getDiagnosticsWorker(sourceFile) {
85258
- throwIfNonDiagnosticsProducing();
85259
85333
  if (sourceFile) {
85334
+ ensurePendingDiagnosticWorkComplete();
85260
85335
  // Some global diagnostics are deferred until they are needed and
85261
85336
  // may not be reported in the first call to getGlobalDiagnostics.
85262
85337
  // We should catch these changes and report them.
85263
85338
  var previousGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
85264
85339
  var previousGlobalDiagnosticsSize = previousGlobalDiagnostics.length;
85265
- checkSourceFile(sourceFile);
85340
+ checkSourceFileWithEagerDiagnostics(sourceFile);
85266
85341
  var semanticDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
85267
85342
  var currentGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
85268
85343
  if (currentGlobalDiagnostics !== previousGlobalDiagnostics) {
@@ -85280,18 +85355,13 @@ var ts;
85280
85355
  }
85281
85356
  // Global diagnostics are always added when a file is not provided to
85282
85357
  // getDiagnostics
85283
- ts.forEach(host.getSourceFiles(), checkSourceFile);
85358
+ ts.forEach(host.getSourceFiles(), checkSourceFileWithEagerDiagnostics);
85284
85359
  return diagnostics.getDiagnostics();
85285
85360
  }
85286
85361
  function getGlobalDiagnostics() {
85287
- throwIfNonDiagnosticsProducing();
85362
+ ensurePendingDiagnosticWorkComplete();
85288
85363
  return diagnostics.getGlobalDiagnostics();
85289
85364
  }
85290
- function throwIfNonDiagnosticsProducing() {
85291
- if (!produceDiagnostics) {
85292
- throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
85293
- }
85294
- }
85295
85365
  // Language service support
85296
85366
  function getSymbolsInScope(location, meaning) {
85297
85367
  if (location.flags & 16777216 /* InWithStatement */) {
@@ -115765,8 +115835,7 @@ var ts;
115765
115835
  var files;
115766
115836
  var symlinks;
115767
115837
  var commonSourceDirectory;
115768
- var diagnosticsProducingTypeChecker;
115769
- var noDiagnosticsTypeChecker;
115838
+ var typeChecker;
115770
115839
  var classifiableNames;
115771
115840
  var ambientModuleNameToUnmodifiedFileName = new ts.Map();
115772
115841
  var fileReasons = ts.createMultiMap();
@@ -116012,21 +116081,19 @@ var ts;
116012
116081
  getProgramDiagnostics: getProgramDiagnostics,
116013
116082
  getTypeChecker: getTypeChecker,
116014
116083
  getClassifiableNames: getClassifiableNames,
116015
- getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
116016
116084
  getCommonSourceDirectory: getCommonSourceDirectory,
116017
116085
  emit: emit,
116018
116086
  getCurrentDirectory: function () { return currentDirectory; },
116019
- getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); },
116020
- getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); },
116021
- getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); },
116022
- getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); },
116023
- getInstantiationCount: function () { return getDiagnosticsProducingTypeChecker().getInstantiationCount(); },
116024
- getRelationCacheSizes: function () { return getDiagnosticsProducingTypeChecker().getRelationCacheSizes(); },
116087
+ getNodeCount: function () { return getTypeChecker().getNodeCount(); },
116088
+ getIdentifierCount: function () { return getTypeChecker().getIdentifierCount(); },
116089
+ getSymbolCount: function () { return getTypeChecker().getSymbolCount(); },
116090
+ getTypeCount: function () { return getTypeChecker().getTypeCount(); },
116091
+ getInstantiationCount: function () { return getTypeChecker().getInstantiationCount(); },
116092
+ getRelationCacheSizes: function () { return getTypeChecker().getRelationCacheSizes(); },
116025
116093
  getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; },
116026
116094
  getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; },
116027
116095
  isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary,
116028
116096
  isSourceFileDefaultLibrary: isSourceFileDefaultLibrary,
116029
- dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker,
116030
116097
  getSourceFileFromReference: getSourceFileFromReference,
116031
116098
  getLibFileFromReference: getLibFileFromReference,
116032
116099
  sourceFileToPackageName: sourceFileToPackageName,
@@ -116615,14 +116682,8 @@ var ts;
116615
116682
  return ts.some(options.lib, function (libFileName) { return equalityComparer(file.fileName, pathForLibFile(libFileName)); });
116616
116683
  }
116617
116684
  }
116618
- function getDiagnosticsProducingTypeChecker() {
116619
- return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ true));
116620
- }
116621
- function dropDiagnosticsProducingTypeChecker() {
116622
- diagnosticsProducingTypeChecker = undefined;
116623
- }
116624
116685
  function getTypeChecker() {
116625
- return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ false));
116686
+ return typeChecker || (typeChecker = ts.createTypeChecker(program));
116626
116687
  }
116627
116688
  function emit(sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers, forceDtsEmit) {
116628
116689
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("emit" /* Emit */, "emit", { path: sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.path }, /*separateBeginAndEnd*/ true);
@@ -116647,7 +116708,7 @@ var ts;
116647
116708
  // This is because in the -out scenario all files need to be emitted, and therefore all
116648
116709
  // files need to be type checked. And the way to specify that all files need to be type
116649
116710
  // checked is to not pass the file to getEmitResolver.
116650
- var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken);
116711
+ var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken);
116651
116712
  ts.performance.mark("beforeEmit");
116652
116713
  var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles,
116653
116714
  /*onlyBuildInfo*/ false, forceDtsEmit);
@@ -116727,15 +116788,7 @@ var ts;
116727
116788
  if (e instanceof ts.OperationCanceledException) {
116728
116789
  // We were canceled while performing the operation. Because our type checker
116729
116790
  // might be a bad state, we need to throw it away.
116730
- //
116731
- // Note: we are overly aggressive here. We do not actually *have* to throw away
116732
- // the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
116733
- // the lifetimes of these two TypeCheckers the same. Also, we generally only
116734
- // cancel when the user has made a change anyways. And, in that case, we (the
116735
- // program instance) will get thrown away anyways. So trying to keep one of
116736
- // these type checkers alive doesn't serve much purpose.
116737
- noDiagnosticsTypeChecker = undefined;
116738
- diagnosticsProducingTypeChecker = undefined;
116791
+ typeChecker = undefined;
116739
116792
  }
116740
116793
  throw e;
116741
116794
  }
@@ -116751,7 +116804,7 @@ var ts;
116751
116804
  if (ts.skipTypeChecking(sourceFile, options, program)) {
116752
116805
  return ts.emptyArray;
116753
116806
  }
116754
- var typeChecker = getDiagnosticsProducingTypeChecker();
116807
+ var typeChecker = getTypeChecker();
116755
116808
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
116756
116809
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
116757
116810
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
@@ -116803,7 +116856,7 @@ var ts;
116803
116856
  }
116804
116857
  function getSuggestionDiagnostics(sourceFile, cancellationToken) {
116805
116858
  return runWithCancellationToken(function () {
116806
- return getDiagnosticsProducingTypeChecker().getSuggestionDiagnostics(sourceFile, cancellationToken);
116859
+ return getTypeChecker().getSuggestionDiagnostics(sourceFile, cancellationToken);
116807
116860
  });
116808
116861
  }
116809
116862
  /**
@@ -117023,7 +117076,7 @@ var ts;
117023
117076
  }
117024
117077
  function getDeclarationDiagnosticsForFileNoCache(sourceFile, cancellationToken) {
117025
117078
  return runWithCancellationToken(function () {
117026
- var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
117079
+ var resolver = getTypeChecker().getEmitResolver(sourceFile, cancellationToken);
117027
117080
  // Don't actually write any files since we're just getting diagnostics.
117028
117081
  return ts.getDeclarationDiagnostics(getEmitHost(ts.noop), resolver, sourceFile) || ts.emptyArray;
117029
117082
  });
@@ -117061,7 +117114,7 @@ var ts;
117061
117114
  return diagnostics;
117062
117115
  }
117063
117116
  function getGlobalDiagnostics() {
117064
- return rootNames.length ? ts.sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()) : ts.emptyArray;
117117
+ return rootNames.length ? ts.sortAndDeduplicateDiagnostics(getTypeChecker().getGlobalDiagnostics().slice()) : ts.emptyArray;
117065
117118
  }
117066
117119
  function getConfigFileParsingDiagnostics() {
117067
117120
  return configFileParsingDiagnostics || ts.emptyArray;
@@ -134183,9 +134236,14 @@ var ts;
134183
134236
  if (type) {
134184
134237
  return type;
134185
134238
  }
134186
- if (ts.isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 63 /* EqualsToken */ && node === node.parent.left) {
134239
+ var parent = ts.walkUpParenthesizedExpressions(node.parent);
134240
+ if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 63 /* EqualsToken */ && node === parent.left) {
134187
134241
  // Object literal is assignment pattern: ({ | } = x)
134188
- return typeChecker.getTypeAtLocation(node.parent);
134242
+ return typeChecker.getTypeAtLocation(parent);
134243
+ }
134244
+ if (ts.isExpression(parent)) {
134245
+ // f(() => (({ | })));
134246
+ return typeChecker.getContextualType(parent);
134189
134247
  }
134190
134248
  return undefined;
134191
134249
  }
@@ -134978,8 +135036,24 @@ var ts;
134978
135036
  };
134979
135037
  }
134980
135038
  ts.createDocumentRegistryInternal = createDocumentRegistryInternal;
135039
+ function compilerOptionValueToString(value) {
135040
+ var _a;
135041
+ if (value === null || typeof value !== "object") { // eslint-disable-line no-null/no-null
135042
+ return "" + value;
135043
+ }
135044
+ if (ts.isArray(value)) {
135045
+ return "[" + ((_a = ts.map(value, function (e) { return compilerOptionValueToString(e); })) === null || _a === void 0 ? void 0 : _a.join(",")) + "]";
135046
+ }
135047
+ var str = "{";
135048
+ for (var key in value) {
135049
+ if (ts.hasOwnProperty.call(value, key)) { // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
135050
+ str += key + ": " + compilerOptionValueToString(value[key]);
135051
+ }
135052
+ }
135053
+ return str + "}";
135054
+ }
134981
135055
  function getKeyForCompilationSettings(settings) {
134982
- return ts.sourceFileAffectingCompilerOptions.map(function (option) { return ts.getCompilerOptionValue(settings, option); }).join("|");
135056
+ return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
134983
135057
  }
134984
135058
  })(ts || (ts = {}));
134985
135059
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
@@ -146764,7 +146838,28 @@ var ts;
146764
146838
  // indentation is first non-whitespace character in a previous line
146765
146839
  // for block indentation, we should look for a line which contains something that's not
146766
146840
  // whitespace.
146767
- if (options.indentStyle === ts.IndentStyle.Block) {
146841
+ var currentToken = ts.getTokenAtPosition(sourceFile, position);
146842
+ // for object literal, we want to the indentation work like block
146843
+ // if { starts in any position (can be in the middle of line)
146844
+ // the following indentation should treat { as starting of that line (including leading whitespace)
146845
+ // ```
146846
+ // const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
146847
+ // ->
146848
+ // const a: { x: undefined, y: undefined } = {
146849
+ // x: undefined,
146850
+ // y: undefined,
146851
+ // }
146852
+ // ---------------------
146853
+ // const a: {x : undefined, y: undefined } =
146854
+ // {}
146855
+ // ->
146856
+ // const a: { x: undefined, y: undefined } =
146857
+ // { // leading 5 whitespaces and { starts at 6 column
146858
+ // x: undefined,
146859
+ // y: undefined,
146860
+ // }
146861
+ // ```
146862
+ if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
146768
146863
  return getBlockIndent(sourceFile, position, options);
146769
146864
  }
146770
146865
  if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
@@ -147707,7 +147802,7 @@ var ts;
147707
147802
  }
147708
147803
  var startPosition = ts.getPrecedingNonSpaceCharacterPosition(sourceFile.text, fnStart - 1);
147709
147804
  var indent = sourceFile.text.slice(startPosition, fnStart);
147710
- this.insertNodeAt(sourceFile, fnStart, tag, { preserveLeadingWhitespace: false, suffix: this.newLineCharacter + indent });
147805
+ this.insertNodeAt(sourceFile, fnStart, tag, { suffix: this.newLineCharacter + indent });
147711
147806
  };
147712
147807
  ChangeTracker.prototype.createJSDocText = function (sourceFile, node) {
147713
147808
  var comments = ts.flatMap(node.jsDoc, function (jsDoc) {
@@ -148238,7 +148333,7 @@ var ts;
148238
148333
  ? change.nodes.map(function (n) { return ts.removeSuffix(format(n), newLineCharacter); }).join(((_a = change.options) === null || _a === void 0 ? void 0 : _a.joiner) || newLineCharacter)
148239
148334
  : format(change.node);
148240
148335
  // strip initial indentation (spaces or tabs) if text will be inserted in the middle of the line
148241
- var noIndent = (options.preserveLeadingWhitespace || options.indentation !== undefined || ts.getLineStartPositionForPosition(pos, sourceFile) === pos) ? text : text.replace(/^\s+/, "");
148336
+ var noIndent = (options.indentation !== undefined || ts.getLineStartPositionForPosition(pos, sourceFile) === pos) ? text : text.replace(/^\s+/, "");
148242
148337
  return (options.prefix || "") + noIndent
148243
148338
  + ((!options.suffix || ts.endsWith(noIndent, options.suffix))
148244
148339
  ? "" : options.suffix);
@@ -148931,7 +149026,7 @@ var ts;
148931
149026
  errorCodes: errorCodes,
148932
149027
  getCodeActions: function getCodeActionsToAddMissingAsync(context) {
148933
149028
  var sourceFile = context.sourceFile, errorCode = context.errorCode, cancellationToken = context.cancellationToken, program = context.program, span = context.span;
148934
- var diagnostic = ts.find(program.getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
149029
+ var diagnostic = ts.find(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
148935
149030
  var directSpan = diagnostic && diagnostic.relatedInformation && ts.find(diagnostic.relatedInformation, function (r) { return r.code === ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async.code; });
148936
149031
  var decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
148937
149032
  if (!decl) {
@@ -149085,7 +149180,7 @@ var ts;
149085
149180
  return codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_await, fixId, ts.Diagnostics.Fix_all_expressions_possibly_missing_await);
149086
149181
  }
149087
149182
  function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
149088
- var checker = program.getDiagnosticsProducingTypeChecker();
149183
+ var checker = program.getTypeChecker();
149089
149184
  var diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
149090
149185
  return ts.some(diagnostics, function (_a) {
149091
149186
  var start = _a.start, length = _a.length, relatedInformation = _a.relatedInformation, code = _a.code;
@@ -149752,20 +149847,6 @@ var ts;
149752
149847
  }
149753
149848
  function createClassElementsFromSymbol(symbol) {
149754
149849
  var memberElements = [];
149755
- // all instance members are stored in the "member" array of symbol
149756
- if (symbol.members) {
149757
- symbol.members.forEach(function (member, key) {
149758
- if (key === "constructor" && member.valueDeclaration) {
149759
- // fn.prototype.constructor = fn
149760
- changes.delete(sourceFile, member.valueDeclaration.parent);
149761
- return;
149762
- }
149763
- var memberElement = createClassElement(member, /*modifiers*/ undefined);
149764
- if (memberElement) {
149765
- memberElements.push.apply(memberElements, memberElement);
149766
- }
149767
- });
149768
- }
149769
149850
  // all static members are stored in the "exports" array of symbol
149770
149851
  if (symbol.exports) {
149771
149852
  symbol.exports.forEach(function (member) {
@@ -149778,18 +149859,31 @@ var ts;
149778
149859
  firstDeclaration.parent.operatorToken.kind === 63 /* EqualsToken */ &&
149779
149860
  ts.isObjectLiteralExpression(firstDeclaration.parent.right)) {
149780
149861
  var prototypes = firstDeclaration.parent.right;
149781
- var memberElement = createClassElement(prototypes.symbol, /** modifiers */ undefined);
149782
- if (memberElement) {
149783
- memberElements.push.apply(memberElements, memberElement);
149784
- }
149862
+ createClassElement(prototypes.symbol, /** modifiers */ undefined, memberElements);
149785
149863
  }
149786
149864
  }
149787
149865
  else {
149788
- var memberElement = createClassElement(member, [ts.factory.createToken(124 /* StaticKeyword */)]);
149789
- if (memberElement) {
149790
- memberElements.push.apply(memberElements, memberElement);
149866
+ createClassElement(member, [ts.factory.createToken(124 /* StaticKeyword */)], memberElements);
149867
+ }
149868
+ });
149869
+ }
149870
+ // all instance members are stored in the "member" array of symbol (done last so instance members pulled from prototype assignments have priority)
149871
+ if (symbol.members) {
149872
+ symbol.members.forEach(function (member, key) {
149873
+ var _a, _b, _c, _d;
149874
+ if (key === "constructor" && member.valueDeclaration) {
149875
+ var prototypeAssignment = (_d = (_c = (_b = (_a = symbol.exports) === null || _a === void 0 ? void 0 : _a.get("prototype")) === null || _b === void 0 ? void 0 : _b.declarations) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.parent;
149876
+ if (prototypeAssignment && ts.isBinaryExpression(prototypeAssignment) && ts.isObjectLiteralExpression(prototypeAssignment.right) && ts.some(prototypeAssignment.right.properties, isConstructorAssignment)) {
149877
+ // fn.prototype = { constructor: fn }
149878
+ // Already deleted in `createClassElement` in first pass
149879
+ }
149880
+ else {
149881
+ // fn.prototype.constructor = fn
149882
+ changes.delete(sourceFile, member.valueDeclaration.parent);
149791
149883
  }
149884
+ return;
149792
149885
  }
149886
+ createClassElement(member, /*modifiers*/ undefined, memberElements);
149793
149887
  });
149794
149888
  }
149795
149889
  return memberElements;
@@ -149817,18 +149911,26 @@ var ts;
149817
149911
  });
149818
149912
  }
149819
149913
  }
149820
- function createClassElement(symbol, modifiers) {
149914
+ function createClassElement(symbol, modifiers, members) {
149821
149915
  // Right now the only thing we can convert are function expressions, which are marked as methods
149822
149916
  // or { x: y } type prototype assignments, which are marked as ObjectLiteral
149823
- var members = [];
149824
149917
  if (!(symbol.flags & 8192 /* Method */) && !(symbol.flags & 4096 /* ObjectLiteral */)) {
149825
- return members;
149918
+ return;
149826
149919
  }
149827
149920
  var memberDeclaration = symbol.valueDeclaration;
149828
149921
  var assignmentBinaryExpression = memberDeclaration.parent;
149829
149922
  var assignmentExpr = assignmentBinaryExpression.right;
149830
149923
  if (!shouldConvertDeclaration(memberDeclaration, assignmentExpr)) {
149831
- return members;
149924
+ return;
149925
+ }
149926
+ if (ts.some(members, function (m) {
149927
+ var name = ts.getNameOfDeclaration(m);
149928
+ if (name && ts.isIdentifier(name) && ts.idText(name) === ts.symbolName(symbol)) {
149929
+ return true; // class member already made for this name
149930
+ }
149931
+ return false;
149932
+ })) {
149933
+ return;
149832
149934
  }
149833
149935
  // delete the entire statement if this expression is the sole expression to take care of the semicolon at the end
149834
149936
  var nodeToDelete = assignmentBinaryExpression.parent && assignmentBinaryExpression.parent.kind === 238 /* ExpressionStatement */
@@ -149837,43 +149939,44 @@ var ts;
149837
149939
  if (!assignmentExpr) {
149838
149940
  members.push(ts.factory.createPropertyDeclaration([], modifiers, symbol.name, /*questionToken*/ undefined,
149839
149941
  /*type*/ undefined, /*initializer*/ undefined));
149840
- return members;
149942
+ return;
149841
149943
  }
149842
149944
  // f.x = expr
149843
149945
  if (ts.isAccessExpression(memberDeclaration) && (ts.isFunctionExpression(assignmentExpr) || ts.isArrowFunction(assignmentExpr))) {
149844
149946
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
149845
149947
  var name = tryGetPropertyName(memberDeclaration, compilerOptions, quotePreference);
149846
149948
  if (name) {
149847
- return createFunctionLikeExpressionMember(members, assignmentExpr, name);
149949
+ createFunctionLikeExpressionMember(members, assignmentExpr, name);
149848
149950
  }
149849
- return members;
149951
+ return;
149850
149952
  }
149851
149953
  // f.prototype = { ... }
149852
149954
  else if (ts.isObjectLiteralExpression(assignmentExpr)) {
149853
- return ts.flatMap(assignmentExpr.properties, function (property) {
149955
+ ts.forEach(assignmentExpr.properties, function (property) {
149854
149956
  if (ts.isMethodDeclaration(property) || ts.isGetOrSetAccessorDeclaration(property)) {
149855
149957
  // MethodDeclaration and AccessorDeclaration can appear in a class directly
149856
- return members.concat(property);
149958
+ members.push(property);
149857
149959
  }
149858
149960
  if (ts.isPropertyAssignment(property) && ts.isFunctionExpression(property.initializer)) {
149859
- return createFunctionLikeExpressionMember(members, property.initializer, property.name);
149961
+ createFunctionLikeExpressionMember(members, property.initializer, property.name);
149860
149962
  }
149861
149963
  // Drop constructor assignments
149862
149964
  if (isConstructorAssignment(property))
149863
- return members;
149864
- return [];
149965
+ return;
149966
+ return;
149865
149967
  });
149968
+ return;
149866
149969
  }
149867
149970
  else {
149868
149971
  // Don't try to declare members in JavaScript files
149869
149972
  if (ts.isSourceFileJS(sourceFile))
149870
- return members;
149973
+ return;
149871
149974
  if (!ts.isPropertyAccessExpression(memberDeclaration))
149872
- return members;
149975
+ return;
149873
149976
  var prop = ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined, /*type*/ undefined, assignmentExpr);
149874
149977
  ts.copyLeadingComments(assignmentBinaryExpression.parent, prop, sourceFile);
149875
149978
  members.push(prop);
149876
- return members;
149979
+ return;
149877
149980
  }
149878
149981
  function createFunctionLikeExpressionMember(members, expression, name) {
149879
149982
  if (ts.isFunctionExpression(expression))
@@ -149886,7 +149989,8 @@ var ts;
149886
149989
  var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
149887
149990
  /*typeParameters*/ undefined, functionExpression.parameters, /*type*/ undefined, functionExpression.body);
149888
149991
  ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
149889
- return members.concat(method);
149992
+ members.push(method);
149993
+ return;
149890
149994
  }
149891
149995
  function createArrowFunctionExpressionMember(members, arrowFunction, name) {
149892
149996
  var arrowFunctionBody = arrowFunction.body;
@@ -149903,7 +150007,7 @@ var ts;
149903
150007
  var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
149904
150008
  /*typeParameters*/ undefined, arrowFunction.parameters, /*type*/ undefined, bodyBlock);
149905
150009
  ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
149906
- return members.concat(method);
150010
+ members.push(method);
149907
150011
  }
149908
150012
  }
149909
150013
  }
@@ -153337,7 +153441,7 @@ var ts;
153337
153441
  var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
153338
153442
  if (!ts.length(properties))
153339
153443
  return undefined;
153340
- return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, indentation: 0, parentDeclaration: parent };
153444
+ return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
153341
153445
  }
153342
153446
  if (!ts.isMemberName(token))
153343
153447
  return undefined;
@@ -153345,7 +153449,7 @@ var ts;
153345
153449
  var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
153346
153450
  if (!ts.length(properties))
153347
153451
  return undefined;
153348
- return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, indentation: undefined, parentDeclaration: parent.initializer };
153452
+ return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, parentDeclaration: parent.initializer };
153349
153453
  }
153350
153454
  if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
153351
153455
  var target = ts.getEmitScriptTarget(program.getCompilerOptions());