typescript 4.7.0-dev.20220323 → 4.7.0-dev.20220327
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.
- package/lib/cs/diagnosticMessages.generated.json +5 -1
- package/lib/de/diagnosticMessages.generated.json +4 -1
- package/lib/es/diagnosticMessages.generated.json +5 -1
- package/lib/fr/diagnosticMessages.generated.json +5 -1
- package/lib/it/diagnosticMessages.generated.json +5 -1
- package/lib/ja/diagnosticMessages.generated.json +4 -1
- package/lib/ko/diagnosticMessages.generated.json +4 -1
- package/lib/pl/diagnosticMessages.generated.json +4 -1
- package/lib/pt-br/diagnosticMessages.generated.json +5 -1
- package/lib/ru/diagnosticMessages.generated.json +4 -1
- package/lib/tr/diagnosticMessages.generated.json +4 -1
- package/lib/tsc.js +443 -394
- package/lib/tsserver.js +608 -518
- package/lib/tsserverlibrary.js +608 -518
- package/lib/typescript.js +608 -518
- package/lib/typescriptServices.js +608 -518
- package/lib/typingsInstaller.js +507 -459
- package/lib/zh-cn/diagnosticMessages.generated.json +5 -1
- package/lib/zh-tw/diagnosticMessages.generated.json +5 -1
- package/package.json +1 -1
|
@@ -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.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220327";
|
|
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
|
|
44628
|
-
!
|
|
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 (!
|
|
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 =
|
|
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 (!
|
|
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
|
|
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
|
-
|
|
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
|
|
49429
|
-
|
|
49430
|
-
!
|
|
49431
|
-
!
|
|
49432
|
-
|
|
49433
|
-
|
|
49434
|
-
|
|
49435
|
-
|
|
49436
|
-
|
|
49437
|
-
|
|
49438
|
-
|
|
49439
|
-
|
|
49440
|
-
|
|
49441
|
-
|
|
49442
|
-
|
|
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
|
-
|
|
49458
|
-
|
|
49459
|
-
|
|
49460
|
-
|
|
49461
|
-
|
|
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
|
-
|
|
49464
|
-
|
|
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
|
-
|
|
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
|
|
49475
|
-
|
|
49476
|
-
//
|
|
49477
|
-
//
|
|
49478
|
-
//
|
|
49479
|
-
|
|
49480
|
-
|
|
49481
|
-
|
|
49482
|
-
|
|
49483
|
-
|
|
49484
|
-
|
|
49485
|
-
|
|
49486
|
-
|
|
49487
|
-
|
|
49488
|
-
|
|
49489
|
-
|
|
49490
|
-
|
|
49491
|
-
|
|
49492
|
-
|
|
49493
|
-
|
|
49494
|
-
|
|
49495
|
-
|
|
49496
|
-
|
|
49497
|
-
|
|
49498
|
-
|
|
49499
|
-
|
|
49500
|
-
|
|
49501
|
-
|
|
49502
|
-
|
|
49503
|
-
|
|
49504
|
-
|
|
49505
|
-
|
|
49506
|
-
|
|
49507
|
-
|
|
49508
|
-
|
|
49509
|
-
|
|
49510
|
-
|
|
49511
|
-
|
|
49512
|
-
|
|
49513
|
-
|
|
49514
|
-
|
|
49515
|
-
|
|
49516
|
-
|
|
49517
|
-
|
|
49518
|
-
|
|
49519
|
-
|
|
49520
|
-
|
|
49521
|
-
|
|
49522
|
-
|
|
49523
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -56099,11 +56109,16 @@ var ts;
|
|
|
56099
56109
|
}
|
|
56100
56110
|
var type = resolveTypeOfAccessors(symbol, writing);
|
|
56101
56111
|
if (!popTypeResolution()) {
|
|
56102
|
-
|
|
56103
|
-
if (
|
|
56104
|
-
|
|
56105
|
-
|
|
56112
|
+
var getter = ts.getDeclarationOfKind(symbol, 172 /* GetAccessor */);
|
|
56113
|
+
if (getter) {
|
|
56114
|
+
if (ts.getEffectiveTypeAnnotationNode(getter)) {
|
|
56115
|
+
error(getter.name, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
|
|
56116
|
+
}
|
|
56117
|
+
else if (noImplicitAny) {
|
|
56118
|
+
error(getter, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
|
|
56119
|
+
}
|
|
56106
56120
|
}
|
|
56121
|
+
type = anyType;
|
|
56107
56122
|
}
|
|
56108
56123
|
return type;
|
|
56109
56124
|
}
|
|
@@ -64510,6 +64525,7 @@ var ts;
|
|
|
64510
64525
|
return 0 /* False */;
|
|
64511
64526
|
}
|
|
64512
64527
|
function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
|
|
64528
|
+
var _a, _b;
|
|
64513
64529
|
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
64514
64530
|
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
64515
64531
|
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
@@ -64550,6 +64566,9 @@ var ts;
|
|
|
64550
64566
|
return;
|
|
64551
64567
|
}
|
|
64552
64568
|
reportRelationError(headMessage, source, target);
|
|
64569
|
+
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 */))) {
|
|
64570
|
+
associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
|
|
64571
|
+
}
|
|
64553
64572
|
}
|
|
64554
64573
|
function traceUnionsOrIntersectionsTooLarge(source, target) {
|
|
64555
64574
|
if (!ts.tracing) {
|
|
@@ -65322,7 +65341,7 @@ var ts;
|
|
|
65322
65341
|
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
|
|
65323
65342
|
if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
|
|
65324
65343
|
var constraint = getConstraintOfType(source);
|
|
65325
|
-
if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
65344
|
+
if (!strictNullChecks && (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */))) {
|
|
65326
65345
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
65327
65346
|
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
65328
65347
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -65330,12 +65349,12 @@ var ts;
|
|
|
65330
65349
|
}
|
|
65331
65350
|
}
|
|
65332
65351
|
// 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)) {
|
|
65352
|
+
else if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState))) {
|
|
65334
65353
|
resetErrorInfo(saveErrorInfo);
|
|
65335
65354
|
return result;
|
|
65336
65355
|
}
|
|
65337
65356
|
// 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)) {
|
|
65357
|
+
else if (constraint && (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState))) {
|
|
65339
65358
|
resetErrorInfo(saveErrorInfo);
|
|
65340
65359
|
return result;
|
|
65341
65360
|
}
|
|
@@ -67394,12 +67413,14 @@ var ts;
|
|
|
67394
67413
|
errorOrSuggestion(noImplicitAny, declaration, diagnostic, ts.declarationNameToString(ts.getNameOfDeclaration(declaration)), typeAsString);
|
|
67395
67414
|
}
|
|
67396
67415
|
function reportErrorsFromWidening(declaration, type, wideningKind) {
|
|
67397
|
-
|
|
67398
|
-
|
|
67399
|
-
|
|
67400
|
-
|
|
67416
|
+
addLazyDiagnostic(function () {
|
|
67417
|
+
if (noImplicitAny && ts.getObjectFlags(type) & 65536 /* ContainsWideningType */ && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration))) {
|
|
67418
|
+
// Report implicit any error within type if possible, otherwise report error on declaration
|
|
67419
|
+
if (!reportWideningErrorsInType(type)) {
|
|
67420
|
+
reportImplicitAny(declaration, type, wideningKind);
|
|
67421
|
+
}
|
|
67401
67422
|
}
|
|
67402
|
-
}
|
|
67423
|
+
});
|
|
67403
67424
|
}
|
|
67404
67425
|
function applyToParameterTypes(source, target, callback) {
|
|
67405
67426
|
var sourceCount = getParameterCount(source);
|
|
@@ -72267,21 +72288,11 @@ var ts;
|
|
|
72267
72288
|
}
|
|
72268
72289
|
return false;
|
|
72269
72290
|
}
|
|
72270
|
-
function uniqueStrings(strings) {
|
|
72271
|
-
var unique = new ts.Set(strings);
|
|
72272
|
-
var result = [];
|
|
72273
|
-
unique.forEach(function (str) { return result.push(str); });
|
|
72274
|
-
return result;
|
|
72275
|
-
}
|
|
72276
72291
|
function discriminateContextualTypeByObjectMembers(node, contextualType) {
|
|
72277
|
-
return getMatchingUnionConstituentForObjectLiteral(contextualType, node) || discriminateTypeByDiscriminableItems(contextualType, ts.concatenate(ts.map(ts.filter(node.properties, function (p) { return !!p.symbol && p.kind === 296 /* PropertyAssignment */ && isPossiblyDiscriminantValue(p.initializer) && isDiscriminantProperty(contextualType, p.symbol.escapedName); }), function (prop) { return [function () { return getContextFreeTypeOfExpression(prop.initializer); }, prop.symbol.escapedName]; }), ts.map(
|
|
72278
|
-
return ts.map(ts.filter(getPropertiesOfType(memberType), function (s) { var _a; return !!(s.flags & 16777216 /* Optional */) && !!((_a = node === null || node === void 0 ? void 0 : node.symbol) === null || _a === void 0 ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName); }), function (s) { return s.escapedName; });
|
|
72279
|
-
})), function (name) { return [function () { return undefinedType; }, name]; })), isTypeAssignableTo, contextualType);
|
|
72292
|
+
return getMatchingUnionConstituentForObjectLiteral(contextualType, node) || discriminateTypeByDiscriminableItems(contextualType, ts.concatenate(ts.map(ts.filter(node.properties, function (p) { return !!p.symbol && p.kind === 296 /* PropertyAssignment */ && isPossiblyDiscriminantValue(p.initializer) && isDiscriminantProperty(contextualType, p.symbol.escapedName); }), function (prop) { return [function () { return getContextFreeTypeOfExpression(prop.initializer); }, prop.symbol.escapedName]; }), ts.map(ts.filter(getPropertiesOfType(contextualType), function (s) { var _a; return !!(s.flags & 16777216 /* Optional */) && !!((_a = node === null || node === void 0 ? void 0 : node.symbol) === null || _a === void 0 ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName); }), function (s) { return [function () { return undefinedType; }, s.escapedName]; })), isTypeAssignableTo, contextualType);
|
|
72280
72293
|
}
|
|
72281
72294
|
function discriminateContextualTypeByJSXAttributes(node, contextualType) {
|
|
72282
|
-
return discriminateTypeByDiscriminableItems(contextualType, ts.concatenate(ts.map(ts.filter(node.properties, function (p) { return !!p.symbol && p.kind === 285 /* JsxAttribute */ && isDiscriminantProperty(contextualType, p.symbol.escapedName) && (!p.initializer || isPossiblyDiscriminantValue(p.initializer)); }), function (prop) { return [!prop.initializer ? (function () { return trueType; }) : (function () { return getContextFreeTypeOfExpression(prop.initializer); }), prop.symbol.escapedName]; }), ts.map(
|
|
72283
|
-
return ts.map(ts.filter(getPropertiesOfType(memberType), function (s) { var _a; return !!(s.flags & 16777216 /* Optional */) && !!((_a = node === null || node === void 0 ? void 0 : node.symbol) === null || _a === void 0 ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName); }), function (s) { return s.escapedName; });
|
|
72284
|
-
})), function (name) { return [function () { return undefinedType; }, name]; })), isTypeAssignableTo, contextualType);
|
|
72295
|
+
return discriminateTypeByDiscriminableItems(contextualType, ts.concatenate(ts.map(ts.filter(node.properties, function (p) { return !!p.symbol && p.kind === 285 /* JsxAttribute */ && isDiscriminantProperty(contextualType, p.symbol.escapedName) && (!p.initializer || isPossiblyDiscriminantValue(p.initializer)); }), function (prop) { return [!prop.initializer ? (function () { return trueType; }) : (function () { return getContextFreeTypeOfExpression(prop.initializer); }), prop.symbol.escapedName]; }), ts.map(ts.filter(getPropertiesOfType(contextualType), function (s) { var _a; return !!(s.flags & 16777216 /* Optional */) && !!((_a = node === null || node === void 0 ? void 0 : node.symbol) === null || _a === void 0 ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName); }), function (s) { return [function () { return undefinedType; }, s.escapedName]; })), isTypeAssignableTo, contextualType);
|
|
72285
72296
|
}
|
|
72286
72297
|
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
|
|
72287
72298
|
// be "pushed" onto a node using the contextualType property.
|
|
@@ -74162,6 +74173,7 @@ var ts;
|
|
|
74162
74173
|
&& !isOptionalPropertyDeclaration(valueDeclaration)
|
|
74163
74174
|
&& !(ts.isAccessExpression(node) && ts.isAccessExpression(node.expression))
|
|
74164
74175
|
&& !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
|
|
74176
|
+
&& !(ts.isMethodDeclaration(valueDeclaration) && ts.getCombinedModifierFlags(valueDeclaration) & 32 /* Static */)
|
|
74165
74177
|
&& (compilerOptions.useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) {
|
|
74166
74178
|
diagnosticMessage = error(right, ts.Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
|
|
74167
74179
|
}
|
|
@@ -75391,7 +75403,7 @@ var ts;
|
|
|
75391
75403
|
var isTaggedTemplate = node.kind === 210 /* TaggedTemplateExpression */;
|
|
75392
75404
|
var isDecorator = node.kind === 165 /* Decorator */;
|
|
75393
75405
|
var isJsxOpeningOrSelfClosingElement = ts.isJsxOpeningLikeElement(node);
|
|
75394
|
-
var reportErrors = !candidatesOutArray
|
|
75406
|
+
var reportErrors = !candidatesOutArray;
|
|
75395
75407
|
var typeArguments;
|
|
75396
75408
|
if (!isDecorator) {
|
|
75397
75409
|
typeArguments = node.typeArguments;
|
|
@@ -76671,11 +76683,13 @@ var ts;
|
|
|
76671
76683
|
checkSourceElement(type);
|
|
76672
76684
|
exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(exprType));
|
|
76673
76685
|
var targetType = getTypeFromTypeNode(type);
|
|
76674
|
-
if (
|
|
76675
|
-
|
|
76676
|
-
|
|
76677
|
-
|
|
76678
|
-
|
|
76686
|
+
if (!isErrorType(targetType)) {
|
|
76687
|
+
addLazyDiagnostic(function () {
|
|
76688
|
+
var widenedType = getWidenedType(exprType);
|
|
76689
|
+
if (!isTypeComparableTo(targetType, widenedType)) {
|
|
76690
|
+
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);
|
|
76691
|
+
}
|
|
76692
|
+
});
|
|
76679
76693
|
}
|
|
76680
76694
|
return targetType;
|
|
76681
76695
|
}
|
|
@@ -77435,47 +77449,48 @@ var ts;
|
|
|
77435
77449
|
* @param returnType - return type of the function, can be undefined if return type is not explicitly specified
|
|
77436
77450
|
*/
|
|
77437
77451
|
function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func, returnType) {
|
|
77438
|
-
|
|
77439
|
-
|
|
77440
|
-
|
|
77441
|
-
|
|
77442
|
-
|
|
77443
|
-
|
|
77444
|
-
|
|
77445
|
-
|
|
77446
|
-
|
|
77447
|
-
|
|
77448
|
-
|
|
77449
|
-
|
|
77450
|
-
|
|
77451
|
-
|
|
77452
|
-
|
|
77453
|
-
|
|
77454
|
-
|
|
77455
|
-
|
|
77456
|
-
|
|
77457
|
-
|
|
77458
|
-
|
|
77459
|
-
|
|
77460
|
-
|
|
77461
|
-
|
|
77462
|
-
|
|
77463
|
-
|
|
77464
|
-
|
|
77465
|
-
|
|
77466
|
-
|
|
77467
|
-
|
|
77468
|
-
|
|
77469
|
-
|
|
77470
|
-
|
|
77471
|
-
|
|
77472
|
-
|
|
77473
|
-
|
|
77474
|
-
|
|
77475
|
-
|
|
77452
|
+
addLazyDiagnostic(checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics);
|
|
77453
|
+
return;
|
|
77454
|
+
function checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics() {
|
|
77455
|
+
var functionFlags = ts.getFunctionFlags(func);
|
|
77456
|
+
var type = returnType && unwrapReturnType(returnType, functionFlags);
|
|
77457
|
+
// Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
|
|
77458
|
+
if (type && maybeTypeOfKind(type, 1 /* Any */ | 16384 /* Void */)) {
|
|
77459
|
+
return;
|
|
77460
|
+
}
|
|
77461
|
+
// If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check.
|
|
77462
|
+
// also if HasImplicitReturn flag is not set this means that all codepaths in function body end with return or throw
|
|
77463
|
+
if (func.kind === 168 /* MethodSignature */ || ts.nodeIsMissing(func.body) || func.body.kind !== 235 /* Block */ || !functionHasImplicitReturn(func)) {
|
|
77464
|
+
return;
|
|
77465
|
+
}
|
|
77466
|
+
var hasExplicitReturn = func.flags & 512 /* HasExplicitReturn */;
|
|
77467
|
+
var errorNode = ts.getEffectiveReturnTypeNode(func) || func;
|
|
77468
|
+
if (type && type.flags & 131072 /* Never */) {
|
|
77469
|
+
error(errorNode, ts.Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
|
|
77470
|
+
}
|
|
77471
|
+
else if (type && !hasExplicitReturn) {
|
|
77472
|
+
// minimal check: function has syntactic return type annotation and no explicit return statements in the body
|
|
77473
|
+
// this function does not conform to the specification.
|
|
77474
|
+
error(errorNode, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
|
|
77475
|
+
}
|
|
77476
|
+
else if (type && strictNullChecks && !isTypeAssignableTo(undefinedType, type)) {
|
|
77477
|
+
error(errorNode, ts.Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined);
|
|
77478
|
+
}
|
|
77479
|
+
else if (compilerOptions.noImplicitReturns) {
|
|
77480
|
+
if (!type) {
|
|
77481
|
+
// If return type annotation is omitted check if function has any explicit return statements.
|
|
77482
|
+
// If it does not have any - its inferred return type is void - don't do any checks.
|
|
77483
|
+
// Otherwise get inferred return type from function body and report error only if it is not void / anytype
|
|
77484
|
+
if (!hasExplicitReturn) {
|
|
77485
|
+
return;
|
|
77486
|
+
}
|
|
77487
|
+
var inferredReturnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
|
|
77488
|
+
if (isUnwrappedReturnTypeVoidOrAny(func, inferredReturnType)) {
|
|
77489
|
+
return;
|
|
77490
|
+
}
|
|
77476
77491
|
}
|
|
77492
|
+
error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
|
|
77477
77493
|
}
|
|
77478
|
-
error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
|
|
77479
77494
|
}
|
|
77480
77495
|
}
|
|
77481
77496
|
function checkFunctionExpressionOrObjectLiteralMethod(node, checkMode) {
|
|
@@ -77735,49 +77750,50 @@ var ts;
|
|
|
77735
77750
|
checkExpression(node.expression);
|
|
77736
77751
|
return undefinedWideningType;
|
|
77737
77752
|
}
|
|
77738
|
-
function
|
|
77753
|
+
function checkAwaitExpressionGrammar(node) {
|
|
77739
77754
|
// Grammar checking
|
|
77740
|
-
|
|
77741
|
-
|
|
77742
|
-
|
|
77743
|
-
|
|
77744
|
-
|
|
77745
|
-
|
|
77746
|
-
|
|
77747
|
-
|
|
77748
|
-
|
|
77749
|
-
|
|
77750
|
-
if (!
|
|
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 */) {
|
|
77755
|
+
var container = ts.getContainingFunctionOrClassStaticBlock(node);
|
|
77756
|
+
if (container && ts.isClassStaticBlockDeclaration(container)) {
|
|
77757
|
+
error(node, ts.Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block);
|
|
77758
|
+
}
|
|
77759
|
+
else if (!(node.flags & 32768 /* AwaitContext */)) {
|
|
77760
|
+
if (ts.isInTopLevelContext(node)) {
|
|
77761
|
+
var sourceFile = ts.getSourceFileOfNode(node);
|
|
77762
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
77763
|
+
var span = void 0;
|
|
77764
|
+
if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
|
|
77765
|
+
if (!span)
|
|
77757
77766
|
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77758
|
-
|
|
77759
|
-
|
|
77760
|
-
}
|
|
77767
|
+
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);
|
|
77768
|
+
diagnostics.add(diagnostic);
|
|
77761
77769
|
}
|
|
77762
|
-
|
|
77763
|
-
|
|
77764
|
-
|
|
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
|
-
}
|
|
77770
|
+
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 */) {
|
|
77771
|
+
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77772
|
+
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
77773
|
diagnostics.add(diagnostic);
|
|
77774
77774
|
}
|
|
77775
77775
|
}
|
|
77776
77776
|
}
|
|
77777
|
-
|
|
77778
|
-
|
|
77777
|
+
else {
|
|
77778
|
+
// use of 'await' in non-async function
|
|
77779
|
+
var sourceFile = ts.getSourceFileOfNode(node);
|
|
77780
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
77781
|
+
var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77782
|
+
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);
|
|
77783
|
+
if (container && container.kind !== 171 /* Constructor */ && (ts.getFunctionFlags(container) & 2 /* Async */) === 0) {
|
|
77784
|
+
var relatedInfo = ts.createDiagnosticForNode(container, ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async);
|
|
77785
|
+
ts.addRelatedInfo(diagnostic, relatedInfo);
|
|
77786
|
+
}
|
|
77787
|
+
diagnostics.add(diagnostic);
|
|
77788
|
+
}
|
|
77779
77789
|
}
|
|
77780
77790
|
}
|
|
77791
|
+
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
|
77792
|
+
error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
|
|
77793
|
+
}
|
|
77794
|
+
}
|
|
77795
|
+
function checkAwaitExpression(node) {
|
|
77796
|
+
addLazyDiagnostic(function () { return checkAwaitExpressionGrammar(node); });
|
|
77781
77797
|
var operandType = checkExpression(node.expression);
|
|
77782
77798
|
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
77799
|
if (awaitedType === operandType && !isErrorType(awaitedType) && !(operandType.flags & 3 /* AnyOrUnknown */)) {
|
|
@@ -78601,7 +78617,10 @@ var ts;
|
|
|
78601
78617
|
}
|
|
78602
78618
|
}
|
|
78603
78619
|
function checkAssignmentOperator(valueType) {
|
|
78604
|
-
if (
|
|
78620
|
+
if (ts.isAssignmentOperator(operator)) {
|
|
78621
|
+
addLazyDiagnostic(checkAssignmentOperatorWorker);
|
|
78622
|
+
}
|
|
78623
|
+
function checkAssignmentOperatorWorker() {
|
|
78605
78624
|
// TypeScript 1.0 spec (April 2014): 4.17
|
|
78606
78625
|
// An assignment of the form
|
|
78607
78626
|
// VarExpr = ValueExpr
|
|
@@ -78700,15 +78719,7 @@ var ts;
|
|
|
78700
78719
|
return [effectiveLeft, effectiveRight];
|
|
78701
78720
|
}
|
|
78702
78721
|
function checkYieldExpression(node) {
|
|
78703
|
-
|
|
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
|
-
}
|
|
78722
|
+
addLazyDiagnostic(checkYieldExpressionGrammar);
|
|
78712
78723
|
var func = ts.getContainingFunction(node);
|
|
78713
78724
|
if (!func)
|
|
78714
78725
|
return anyType;
|
|
@@ -78754,14 +78765,24 @@ var ts;
|
|
|
78754
78765
|
var type = getContextualIterationType(2 /* Next */, func);
|
|
78755
78766
|
if (!type) {
|
|
78756
78767
|
type = anyType;
|
|
78757
|
-
|
|
78758
|
-
|
|
78759
|
-
|
|
78760
|
-
|
|
78768
|
+
addLazyDiagnostic(function () {
|
|
78769
|
+
if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
|
|
78770
|
+
var contextualType = getContextualType(node);
|
|
78771
|
+
if (!contextualType || isTypeAny(contextualType)) {
|
|
78772
|
+
error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
|
|
78773
|
+
}
|
|
78761
78774
|
}
|
|
78762
|
-
}
|
|
78775
|
+
});
|
|
78763
78776
|
}
|
|
78764
78777
|
return type;
|
|
78778
|
+
function checkYieldExpressionGrammar() {
|
|
78779
|
+
if (!(node.flags & 8192 /* YieldContext */)) {
|
|
78780
|
+
grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
|
|
78781
|
+
}
|
|
78782
|
+
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
|
78783
|
+
error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
|
|
78784
|
+
}
|
|
78785
|
+
}
|
|
78765
78786
|
}
|
|
78766
78787
|
function checkConditionalExpression(node, checkMode) {
|
|
78767
78788
|
checkTruthinessExpression(node.condition);
|
|
@@ -79357,9 +79378,7 @@ var ts;
|
|
|
79357
79378
|
varianceTypeParameter = saveVarianceTypeParameter;
|
|
79358
79379
|
}
|
|
79359
79380
|
}
|
|
79360
|
-
|
|
79361
|
-
checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
|
|
79362
|
-
}
|
|
79381
|
+
addLazyDiagnostic(function () { return checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); });
|
|
79363
79382
|
}
|
|
79364
79383
|
function checkParameter(node) {
|
|
79365
79384
|
// Grammar checking
|
|
@@ -79513,7 +79532,8 @@ var ts;
|
|
|
79513
79532
|
if (node.type) {
|
|
79514
79533
|
checkSourceElement(node.type);
|
|
79515
79534
|
}
|
|
79516
|
-
|
|
79535
|
+
addLazyDiagnostic(checkSignatureDeclarationDiagnostics);
|
|
79536
|
+
function checkSignatureDeclarationDiagnostics() {
|
|
79517
79537
|
checkCollisionWithArgumentsInGeneratedCode(node);
|
|
79518
79538
|
var returnTypeNode = ts.getEffectiveReturnTypeNode(node);
|
|
79519
79539
|
if (noImplicitAny && !returnTypeNode) {
|
|
@@ -79803,9 +79823,8 @@ var ts;
|
|
|
79803
79823
|
if (ts.nodeIsMissing(node.body)) {
|
|
79804
79824
|
return;
|
|
79805
79825
|
}
|
|
79806
|
-
|
|
79807
|
-
|
|
79808
|
-
}
|
|
79826
|
+
addLazyDiagnostic(checkConstructorDeclarationDiagnostics);
|
|
79827
|
+
return;
|
|
79809
79828
|
function isInstancePropertyWithInitializerOrPrivateIdentifierProperty(n) {
|
|
79810
79829
|
if (ts.isPrivateIdentifierClassElementDeclaration(n)) {
|
|
79811
79830
|
return true;
|
|
@@ -79814,54 +79833,56 @@ var ts;
|
|
|
79814
79833
|
!ts.isStatic(n) &&
|
|
79815
79834
|
!!n.initializer;
|
|
79816
79835
|
}
|
|
79817
|
-
|
|
79818
|
-
|
|
79819
|
-
|
|
79820
|
-
|
|
79821
|
-
|
|
79822
|
-
|
|
79823
|
-
|
|
79824
|
-
|
|
79825
|
-
|
|
79826
|
-
if (
|
|
79827
|
-
|
|
79828
|
-
|
|
79829
|
-
|
|
79830
|
-
|
|
79831
|
-
|
|
79832
|
-
|
|
79833
|
-
|
|
79834
|
-
(ts.
|
|
79835
|
-
ts.some(node.
|
|
79836
|
-
|
|
79837
|
-
|
|
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
|
-
}
|
|
79836
|
+
function checkConstructorDeclarationDiagnostics() {
|
|
79837
|
+
// TS 1.0 spec (April 2014): 8.3.2
|
|
79838
|
+
// Constructors of classes with no extends clause may not contain super calls, whereas
|
|
79839
|
+
// constructors of derived classes must contain at least one super call somewhere in their function body.
|
|
79840
|
+
var containingClassDecl = node.parent;
|
|
79841
|
+
if (ts.getClassExtendsHeritageElement(containingClassDecl)) {
|
|
79842
|
+
captureLexicalThis(node.parent, containingClassDecl);
|
|
79843
|
+
var classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
|
|
79844
|
+
var superCall = findFirstSuperCall(node.body);
|
|
79845
|
+
if (superCall) {
|
|
79846
|
+
if (classExtendsNull) {
|
|
79847
|
+
error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
|
79848
|
+
}
|
|
79849
|
+
// A super call must be root-level in a constructor if both of the following are true:
|
|
79850
|
+
// - The containing class is a derived class.
|
|
79851
|
+
// - The constructor declares parameter properties
|
|
79852
|
+
// or the containing class declares instance member variables with initializers.
|
|
79853
|
+
var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
|
|
79854
|
+
(ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
|
|
79855
|
+
ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
|
|
79856
|
+
if (superCallShouldBeRootLevel) {
|
|
79855
79857
|
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
79856
79858
|
// See GH #8277
|
|
79857
|
-
if (
|
|
79858
|
-
error(
|
|
79859
|
+
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
79860
|
+
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);
|
|
79861
|
+
}
|
|
79862
|
+
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
79863
|
+
else {
|
|
79864
|
+
var superCallStatement = void 0;
|
|
79865
|
+
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
79866
|
+
var statement = _a[_i];
|
|
79867
|
+
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
79868
|
+
superCallStatement = statement;
|
|
79869
|
+
break;
|
|
79870
|
+
}
|
|
79871
|
+
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
79872
|
+
break;
|
|
79873
|
+
}
|
|
79874
|
+
}
|
|
79875
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
79876
|
+
// See GH #8277
|
|
79877
|
+
if (superCallStatement === undefined) {
|
|
79878
|
+
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);
|
|
79879
|
+
}
|
|
79859
79880
|
}
|
|
79860
79881
|
}
|
|
79861
79882
|
}
|
|
79862
|
-
|
|
79863
|
-
|
|
79864
|
-
|
|
79883
|
+
else if (!classExtendsNull) {
|
|
79884
|
+
error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
|
|
79885
|
+
}
|
|
79865
79886
|
}
|
|
79866
79887
|
}
|
|
79867
79888
|
}
|
|
@@ -79879,7 +79900,10 @@ var ts;
|
|
|
79879
79900
|
return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
|
|
79880
79901
|
}
|
|
79881
79902
|
function checkAccessorDeclaration(node) {
|
|
79882
|
-
|
|
79903
|
+
addLazyDiagnostic(checkAccessorDeclarationDiagnostics);
|
|
79904
|
+
checkSourceElement(node.body);
|
|
79905
|
+
setNodeLinksForPrivateIdentifierScope(node);
|
|
79906
|
+
function checkAccessorDeclarationDiagnostics() {
|
|
79883
79907
|
// Grammar checking accessors
|
|
79884
79908
|
if (!checkGrammarFunctionLikeDeclaration(node) && !checkGrammarAccessor(node))
|
|
79885
79909
|
checkGrammarComputedPropertyName(node.name);
|
|
@@ -79929,8 +79953,6 @@ var ts;
|
|
|
79929
79953
|
checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnType);
|
|
79930
79954
|
}
|
|
79931
79955
|
}
|
|
79932
|
-
checkSourceElement(node.body);
|
|
79933
|
-
setNodeLinksForPrivateIdentifierScope(node);
|
|
79934
79956
|
}
|
|
79935
79957
|
function checkMissingDeclaration(node) {
|
|
79936
79958
|
checkDecorators(node);
|
|
@@ -79973,11 +79995,13 @@ var ts;
|
|
|
79973
79995
|
ts.forEach(node.typeArguments, checkSourceElement);
|
|
79974
79996
|
var type = getTypeFromTypeReference(node);
|
|
79975
79997
|
if (!isErrorType(type)) {
|
|
79976
|
-
if (node.typeArguments
|
|
79977
|
-
|
|
79978
|
-
|
|
79979
|
-
|
|
79980
|
-
|
|
79998
|
+
if (node.typeArguments) {
|
|
79999
|
+
addLazyDiagnostic(function () {
|
|
80000
|
+
var typeParameters = getTypeParametersForTypeReference(node);
|
|
80001
|
+
if (typeParameters) {
|
|
80002
|
+
checkTypeArgumentConstraints(node, typeParameters);
|
|
80003
|
+
}
|
|
80004
|
+
});
|
|
79981
80005
|
}
|
|
79982
80006
|
var symbol = getNodeLinks(node).resolvedSymbol;
|
|
79983
80007
|
if (symbol) {
|
|
@@ -80005,7 +80029,8 @@ var ts;
|
|
|
80005
80029
|
}
|
|
80006
80030
|
function checkTypeLiteral(node) {
|
|
80007
80031
|
ts.forEach(node.members, checkSourceElement);
|
|
80008
|
-
|
|
80032
|
+
addLazyDiagnostic(checkTypeLiteralDiagnostics);
|
|
80033
|
+
function checkTypeLiteralDiagnostics() {
|
|
80009
80034
|
var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
|
|
80010
80035
|
checkIndexConstraints(type, type.symbol);
|
|
80011
80036
|
checkTypeForDuplicateIndexSignatures(node);
|
|
@@ -80196,9 +80221,9 @@ var ts;
|
|
|
80196
80221
|
return flags & flagsToCheck;
|
|
80197
80222
|
}
|
|
80198
80223
|
function checkFunctionOrConstructorSymbol(symbol) {
|
|
80199
|
-
|
|
80200
|
-
|
|
80201
|
-
|
|
80224
|
+
addLazyDiagnostic(function () { return checkFunctionOrConstructorSymbolWorker(symbol); });
|
|
80225
|
+
}
|
|
80226
|
+
function checkFunctionOrConstructorSymbolWorker(symbol) {
|
|
80202
80227
|
function getCanonicalOverload(overloads, implementation) {
|
|
80203
80228
|
// Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
|
|
80204
80229
|
// Error on all deviations from this canonical set of flags
|
|
@@ -80419,9 +80444,9 @@ var ts;
|
|
|
80419
80444
|
}
|
|
80420
80445
|
}
|
|
80421
80446
|
function checkExportsOnMergedDeclarations(node) {
|
|
80422
|
-
|
|
80423
|
-
|
|
80424
|
-
|
|
80447
|
+
addLazyDiagnostic(function () { return checkExportsOnMergedDeclarationsWorker(node); });
|
|
80448
|
+
}
|
|
80449
|
+
function checkExportsOnMergedDeclarationsWorker(node) {
|
|
80425
80450
|
// if localSymbol is defined on node then node itself is exported - check is required
|
|
80426
80451
|
var symbol = node.localSymbol;
|
|
80427
80452
|
if (!symbol) {
|
|
@@ -81065,7 +81090,8 @@ var ts;
|
|
|
81065
81090
|
ts.forEach(node.decorators, checkDecorator);
|
|
81066
81091
|
}
|
|
81067
81092
|
function checkFunctionDeclaration(node) {
|
|
81068
|
-
|
|
81093
|
+
addLazyDiagnostic(checkFunctionDeclarationDiagnostics);
|
|
81094
|
+
function checkFunctionDeclarationDiagnostics() {
|
|
81069
81095
|
checkFunctionOrMethodDeclaration(node);
|
|
81070
81096
|
checkGrammarForGenerator(node);
|
|
81071
81097
|
checkCollisionsForDeclarationName(node, node.name);
|
|
@@ -81099,10 +81125,13 @@ var ts;
|
|
|
81099
81125
|
checkSourceElement(node.typeExpression);
|
|
81100
81126
|
}
|
|
81101
81127
|
function checkJSDocFunctionType(node) {
|
|
81102
|
-
|
|
81103
|
-
reportImplicitAny(node, anyType);
|
|
81104
|
-
}
|
|
81128
|
+
addLazyDiagnostic(checkJSDocFunctionTypeImplicitAny);
|
|
81105
81129
|
checkSignatureDeclaration(node);
|
|
81130
|
+
function checkJSDocFunctionTypeImplicitAny() {
|
|
81131
|
+
if (!node.type && !ts.isJSDocConstructSignature(node)) {
|
|
81132
|
+
reportImplicitAny(node, anyType);
|
|
81133
|
+
}
|
|
81134
|
+
}
|
|
81106
81135
|
}
|
|
81107
81136
|
function checkJSDocImplementsTag(node) {
|
|
81108
81137
|
var classLike = ts.getEffectiveJSDocHost(node);
|
|
@@ -81183,19 +81212,7 @@ var ts;
|
|
|
81183
81212
|
var body = node.kind === 168 /* MethodSignature */ ? undefined : node.body;
|
|
81184
81213
|
checkSourceElement(body);
|
|
81185
81214
|
checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, getReturnTypeFromAnnotation(node));
|
|
81186
|
-
|
|
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
|
-
}
|
|
81215
|
+
addLazyDiagnostic(checkFunctionOrMethodDeclarationDiagnostics);
|
|
81199
81216
|
// A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature
|
|
81200
81217
|
if (ts.isInJSFile(node)) {
|
|
81201
81218
|
var typeTag = ts.getJSDocTypeTag(node);
|
|
@@ -81203,10 +81220,26 @@ var ts;
|
|
|
81203
81220
|
error(typeTag.typeExpression.type, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature);
|
|
81204
81221
|
}
|
|
81205
81222
|
}
|
|
81223
|
+
function checkFunctionOrMethodDeclarationDiagnostics() {
|
|
81224
|
+
if (!ts.getEffectiveReturnTypeNode(node)) {
|
|
81225
|
+
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
|
|
81226
|
+
// in an ambient context
|
|
81227
|
+
if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) {
|
|
81228
|
+
reportImplicitAny(node, anyType);
|
|
81229
|
+
}
|
|
81230
|
+
if (functionFlags & 1 /* Generator */ && ts.nodeIsPresent(body)) {
|
|
81231
|
+
// A generator with a body and no type annotation can still cause errors. It can error if the
|
|
81232
|
+
// yielded values have no common supertype, or it can give an implicit any error if it has no
|
|
81233
|
+
// yielded values. The only way to trigger these errors is to try checking its return type.
|
|
81234
|
+
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
|
|
81235
|
+
}
|
|
81236
|
+
}
|
|
81237
|
+
}
|
|
81206
81238
|
}
|
|
81207
81239
|
function registerForUnusedIdentifiersCheck(node) {
|
|
81208
|
-
|
|
81209
|
-
|
|
81240
|
+
addLazyDiagnostic(registerForUnusedIdentifiersCheckDiagnostics);
|
|
81241
|
+
function registerForUnusedIdentifiersCheckDiagnostics() {
|
|
81242
|
+
// May be in a call such as getTypeOfNode that happened to call this. But potentiallyUnusedIdentifiers is only defined in the scope of `checkSourceFile`.
|
|
81210
81243
|
var sourceFile = ts.getSourceFileOfNode(node);
|
|
81211
81244
|
var potentiallyUnusedIdentifiers = allPotentiallyUnusedIdentifiers.get(sourceFile.path);
|
|
81212
81245
|
if (!potentiallyUnusedIdentifiers) {
|
|
@@ -82980,26 +83013,31 @@ var ts;
|
|
|
82980
83013
|
hasDuplicateDefaultClause = true;
|
|
82981
83014
|
}
|
|
82982
83015
|
}
|
|
82983
|
-
if (
|
|
82984
|
-
|
|
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
|
-
}
|
|
83016
|
+
if (clause.kind === 289 /* CaseClause */) {
|
|
83017
|
+
addLazyDiagnostic(createLazyCaseClauseDiagnostics(clause));
|
|
82998
83018
|
}
|
|
82999
83019
|
ts.forEach(clause.statements, checkSourceElement);
|
|
83000
83020
|
if (compilerOptions.noFallthroughCasesInSwitch && clause.fallthroughFlowNode && isReachableFlowNode(clause.fallthroughFlowNode)) {
|
|
83001
83021
|
error(clause, ts.Diagnostics.Fallthrough_case_in_switch);
|
|
83002
83022
|
}
|
|
83023
|
+
function createLazyCaseClauseDiagnostics(clause) {
|
|
83024
|
+
return function () {
|
|
83025
|
+
// TypeScript 1.0 spec (April 2014): 5.9
|
|
83026
|
+
// In a 'switch' statement, each 'case' expression must be of a type that is comparable
|
|
83027
|
+
// to or from the type of the 'switch' expression.
|
|
83028
|
+
var caseType = checkExpression(clause.expression);
|
|
83029
|
+
var caseIsLiteral = isLiteralType(caseType);
|
|
83030
|
+
var comparedExpressionType = expressionType;
|
|
83031
|
+
if (!caseIsLiteral || !expressionIsLiteral) {
|
|
83032
|
+
caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
|
|
83033
|
+
comparedExpressionType = getBaseTypeOfLiteralType(expressionType);
|
|
83034
|
+
}
|
|
83035
|
+
if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) {
|
|
83036
|
+
// expressionType is not comparable to caseType, try the reversed check and report errors if it fails
|
|
83037
|
+
checkTypeComparableTo(caseType, comparedExpressionType, clause.expression, /*headMessage*/ undefined);
|
|
83038
|
+
}
|
|
83039
|
+
};
|
|
83040
|
+
}
|
|
83003
83041
|
});
|
|
83004
83042
|
if (node.caseBlock.locals) {
|
|
83005
83043
|
registerForUnusedIdentifiersCheck(node.caseBlock);
|
|
@@ -83220,26 +83258,29 @@ var ts;
|
|
|
83220
83258
|
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
|
|
83221
83259
|
*/
|
|
83222
83260
|
function checkTypeParameters(typeParameterDeclarations) {
|
|
83261
|
+
var seenDefault = false;
|
|
83223
83262
|
if (typeParameterDeclarations) {
|
|
83224
|
-
var seenDefault = false;
|
|
83225
83263
|
for (var i = 0; i < typeParameterDeclarations.length; i++) {
|
|
83226
83264
|
var node = typeParameterDeclarations[i];
|
|
83227
83265
|
checkTypeParameter(node);
|
|
83228
|
-
|
|
83229
|
-
|
|
83230
|
-
|
|
83231
|
-
|
|
83232
|
-
|
|
83233
|
-
|
|
83234
|
-
|
|
83235
|
-
|
|
83236
|
-
|
|
83237
|
-
|
|
83238
|
-
|
|
83239
|
-
|
|
83266
|
+
addLazyDiagnostic(createCheckTypeParameterDiagnostic(node, i));
|
|
83267
|
+
}
|
|
83268
|
+
}
|
|
83269
|
+
function createCheckTypeParameterDiagnostic(node, i) {
|
|
83270
|
+
return function () {
|
|
83271
|
+
if (node.default) {
|
|
83272
|
+
seenDefault = true;
|
|
83273
|
+
checkTypeParametersNotReferenced(node.default, typeParameterDeclarations, i);
|
|
83274
|
+
}
|
|
83275
|
+
else if (seenDefault) {
|
|
83276
|
+
error(node, ts.Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters);
|
|
83277
|
+
}
|
|
83278
|
+
for (var j = 0; j < i; j++) {
|
|
83279
|
+
if (typeParameterDeclarations[j].symbol === node.symbol) {
|
|
83280
|
+
error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
|
|
83240
83281
|
}
|
|
83241
83282
|
}
|
|
83242
|
-
}
|
|
83283
|
+
};
|
|
83243
83284
|
}
|
|
83244
83285
|
}
|
|
83245
83286
|
/** Check that type parameter defaults only reference previously declared type parameters */
|
|
@@ -83371,85 +83412,90 @@ var ts;
|
|
|
83371
83412
|
if (extendsNode && extendsNode !== baseTypeNode) {
|
|
83372
83413
|
checkExpression(extendsNode.expression);
|
|
83373
83414
|
}
|
|
83374
|
-
var
|
|
83375
|
-
if (
|
|
83376
|
-
|
|
83377
|
-
|
|
83378
|
-
|
|
83379
|
-
|
|
83380
|
-
|
|
83381
|
-
|
|
83382
|
-
ts.
|
|
83383
|
-
|
|
83384
|
-
var
|
|
83385
|
-
|
|
83386
|
-
|
|
83415
|
+
var baseTypes_2 = getBaseTypes(type);
|
|
83416
|
+
if (baseTypes_2.length) {
|
|
83417
|
+
addLazyDiagnostic(function () {
|
|
83418
|
+
var baseType = baseTypes_2[0];
|
|
83419
|
+
var baseConstructorType = getBaseConstructorTypeOfClass(type);
|
|
83420
|
+
var staticBaseType = getApparentType(baseConstructorType);
|
|
83421
|
+
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
|
|
83422
|
+
checkSourceElement(baseTypeNode.expression);
|
|
83423
|
+
if (ts.some(baseTypeNode.typeArguments)) {
|
|
83424
|
+
ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
|
|
83425
|
+
for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode); _i < _a.length; _i++) {
|
|
83426
|
+
var constructor = _a[_i];
|
|
83427
|
+
if (!checkTypeArgumentConstraints(baseTypeNode, constructor.typeParameters)) {
|
|
83428
|
+
break;
|
|
83429
|
+
}
|
|
83387
83430
|
}
|
|
83388
83431
|
}
|
|
83389
|
-
|
|
83390
|
-
|
|
83391
|
-
|
|
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);
|
|
83432
|
+
var baseWithThis = getTypeWithThisArgument(baseType, type.thisType);
|
|
83433
|
+
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
|
|
83434
|
+
issueMemberSpecificError(node, typeWithThis, baseWithThis, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
|
|
83401
83435
|
}
|
|
83402
83436
|
else {
|
|
83403
|
-
|
|
83404
|
-
|
|
83405
|
-
|
|
83437
|
+
// Report static side error only when instance type is assignable
|
|
83438
|
+
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
|
83439
|
+
}
|
|
83440
|
+
if (baseConstructorType.flags & 8650752 /* TypeVariable */) {
|
|
83441
|
+
if (!isMixinConstructorType(staticType)) {
|
|
83442
|
+
error(node.name || node, ts.Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
|
|
83443
|
+
}
|
|
83444
|
+
else {
|
|
83445
|
+
var constructSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */);
|
|
83446
|
+
if (constructSignatures.some(function (signature) { return signature.flags & 4 /* Abstract */; }) && !ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
|
|
83447
|
+
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);
|
|
83448
|
+
}
|
|
83406
83449
|
}
|
|
83407
83450
|
}
|
|
83408
|
-
|
|
83409
|
-
|
|
83410
|
-
|
|
83411
|
-
|
|
83412
|
-
|
|
83413
|
-
|
|
83414
|
-
|
|
83451
|
+
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */) && !(baseConstructorType.flags & 8650752 /* TypeVariable */)) {
|
|
83452
|
+
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
|
|
83453
|
+
// that all instantiated base constructor signatures return the same type.
|
|
83454
|
+
var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode);
|
|
83455
|
+
if (ts.forEach(constructors, function (sig) { return !isJSConstructor(sig.declaration) && !isTypeIdenticalTo(getReturnTypeOfSignature(sig), baseType); })) {
|
|
83456
|
+
error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
|
|
83457
|
+
}
|
|
83415
83458
|
}
|
|
83416
|
-
|
|
83417
|
-
|
|
83459
|
+
checkKindsOfPropertyMemberOverrides(type, baseType);
|
|
83460
|
+
});
|
|
83418
83461
|
}
|
|
83419
83462
|
}
|
|
83420
83463
|
checkMembersForOverrideModifier(node, type, typeWithThis, staticType);
|
|
83421
83464
|
var implementedTypeNodes = ts.getEffectiveImplementsTypeNodes(node);
|
|
83422
83465
|
if (implementedTypeNodes) {
|
|
83423
|
-
for (var
|
|
83424
|
-
var typeRefNode = implementedTypeNodes_1[
|
|
83466
|
+
for (var _i = 0, implementedTypeNodes_1 = implementedTypeNodes; _i < implementedTypeNodes_1.length; _i++) {
|
|
83467
|
+
var typeRefNode = implementedTypeNodes_1[_i];
|
|
83425
83468
|
if (!ts.isEntityNameExpression(typeRefNode.expression) || ts.isOptionalChain(typeRefNode.expression)) {
|
|
83426
83469
|
error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
|
83427
83470
|
}
|
|
83428
83471
|
checkTypeReferenceNode(typeRefNode);
|
|
83429
|
-
|
|
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
|
-
}
|
|
83472
|
+
addLazyDiagnostic(createImplementsDiagnostics(typeRefNode));
|
|
83446
83473
|
}
|
|
83447
83474
|
}
|
|
83448
|
-
|
|
83475
|
+
addLazyDiagnostic(function () {
|
|
83449
83476
|
checkIndexConstraints(type, symbol);
|
|
83450
83477
|
checkIndexConstraints(staticType, symbol, /*isStaticIndex*/ true);
|
|
83451
83478
|
checkTypeForDuplicateIndexSignatures(node);
|
|
83452
83479
|
checkPropertyInitialization(node);
|
|
83480
|
+
});
|
|
83481
|
+
function createImplementsDiagnostics(typeRefNode) {
|
|
83482
|
+
return function () {
|
|
83483
|
+
var t = getReducedType(getTypeFromTypeNode(typeRefNode));
|
|
83484
|
+
if (!isErrorType(t)) {
|
|
83485
|
+
if (isValidBaseType(t)) {
|
|
83486
|
+
var genericDiag = t.symbol && t.symbol.flags & 32 /* Class */ ?
|
|
83487
|
+
ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
|
|
83488
|
+
ts.Diagnostics.Class_0_incorrectly_implements_interface_1;
|
|
83489
|
+
var baseWithThis = getTypeWithThisArgument(t, type.thisType);
|
|
83490
|
+
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
|
|
83491
|
+
issueMemberSpecificError(node, typeWithThis, baseWithThis, genericDiag);
|
|
83492
|
+
}
|
|
83493
|
+
}
|
|
83494
|
+
else {
|
|
83495
|
+
error(typeRefNode, ts.Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
|
|
83496
|
+
}
|
|
83497
|
+
}
|
|
83498
|
+
};
|
|
83453
83499
|
}
|
|
83454
83500
|
}
|
|
83455
83501
|
function checkMembersForOverrideModifier(node, type, typeWithThis, staticType) {
|
|
@@ -83773,8 +83819,8 @@ var ts;
|
|
|
83773
83819
|
ts.forEach(properties, function (p) {
|
|
83774
83820
|
seen.set(p.escapedName, p);
|
|
83775
83821
|
});
|
|
83776
|
-
for (var _i = 0,
|
|
83777
|
-
var base =
|
|
83822
|
+
for (var _i = 0, baseTypes_3 = baseTypes; _i < baseTypes_3.length; _i++) {
|
|
83823
|
+
var base = baseTypes_3[_i];
|
|
83778
83824
|
var properties_5 = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
|
|
83779
83825
|
for (var _a = 0, properties_4 = properties_5; _a < properties_4.length; _a++) {
|
|
83780
83826
|
var prop = properties_4[_a];
|
|
@@ -83796,8 +83842,8 @@ var ts;
|
|
|
83796
83842
|
seen.set(p.escapedName, { prop: p, containingType: type });
|
|
83797
83843
|
});
|
|
83798
83844
|
var ok = true;
|
|
83799
|
-
for (var _i = 0,
|
|
83800
|
-
var base =
|
|
83845
|
+
for (var _i = 0, baseTypes_4 = baseTypes; _i < baseTypes_4.length; _i++) {
|
|
83846
|
+
var base = baseTypes_4[_i];
|
|
83801
83847
|
var properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
|
|
83802
83848
|
for (var _a = 0, properties_6 = properties; _a < properties_6.length; _a++) {
|
|
83803
83849
|
var prop = properties_6[_a];
|
|
@@ -83881,7 +83927,7 @@ var ts;
|
|
|
83881
83927
|
if (!checkGrammarDecoratorsAndModifiers(node))
|
|
83882
83928
|
checkGrammarInterfaceDeclaration(node);
|
|
83883
83929
|
checkTypeParameters(node.typeParameters);
|
|
83884
|
-
|
|
83930
|
+
addLazyDiagnostic(function () {
|
|
83885
83931
|
checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
|
|
83886
83932
|
checkExportsOnMergedDeclarations(node);
|
|
83887
83933
|
var symbol = getSymbolOfNode(node);
|
|
@@ -83901,7 +83947,7 @@ var ts;
|
|
|
83901
83947
|
}
|
|
83902
83948
|
}
|
|
83903
83949
|
checkObjectTypeForDuplicateDeclarations(node);
|
|
83904
|
-
}
|
|
83950
|
+
});
|
|
83905
83951
|
ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
|
|
83906
83952
|
if (!ts.isEntityNameExpression(heritageElement.expression) || ts.isOptionalChain(heritageElement.expression)) {
|
|
83907
83953
|
error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
|
@@ -83909,10 +83955,10 @@ var ts;
|
|
|
83909
83955
|
checkTypeReferenceNode(heritageElement);
|
|
83910
83956
|
});
|
|
83911
83957
|
ts.forEach(node.members, checkSourceElement);
|
|
83912
|
-
|
|
83958
|
+
addLazyDiagnostic(function () {
|
|
83913
83959
|
checkTypeForDuplicateIndexSignatures(node);
|
|
83914
83960
|
registerForUnusedIdentifiersCheck(node);
|
|
83915
|
-
}
|
|
83961
|
+
});
|
|
83916
83962
|
}
|
|
83917
83963
|
function checkTypeAliasDeclaration(node) {
|
|
83918
83964
|
// Grammar checking
|
|
@@ -84101,9 +84147,9 @@ var ts;
|
|
|
84101
84147
|
ts.isStringLiteralLike(node.argumentExpression);
|
|
84102
84148
|
}
|
|
84103
84149
|
function checkEnumDeclaration(node) {
|
|
84104
|
-
|
|
84105
|
-
|
|
84106
|
-
|
|
84150
|
+
addLazyDiagnostic(function () { return checkEnumDeclarationWorker(node); });
|
|
84151
|
+
}
|
|
84152
|
+
function checkEnumDeclarationWorker(node) {
|
|
84107
84153
|
// Grammar checking
|
|
84108
84154
|
checkGrammarDecoratorsAndModifiers(node);
|
|
84109
84155
|
checkCollisionsForDeclarationName(node, node.name);
|
|
@@ -84183,7 +84229,14 @@ var ts;
|
|
|
84183
84229
|
}
|
|
84184
84230
|
}
|
|
84185
84231
|
function checkModuleDeclaration(node) {
|
|
84186
|
-
if (
|
|
84232
|
+
if (node.body) {
|
|
84233
|
+
checkSourceElement(node.body);
|
|
84234
|
+
if (!ts.isGlobalScopeAugmentation(node)) {
|
|
84235
|
+
registerForUnusedIdentifiersCheck(node);
|
|
84236
|
+
}
|
|
84237
|
+
}
|
|
84238
|
+
addLazyDiagnostic(checkModuleDeclarationDiagnostics);
|
|
84239
|
+
function checkModuleDeclarationDiagnostics() {
|
|
84187
84240
|
// Grammar checking
|
|
84188
84241
|
var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
|
|
84189
84242
|
var inAmbientContext = node.flags & 8388608 /* Ambient */;
|
|
@@ -84266,12 +84319,6 @@ var ts;
|
|
|
84266
84319
|
}
|
|
84267
84320
|
}
|
|
84268
84321
|
}
|
|
84269
|
-
if (node.body) {
|
|
84270
|
-
checkSourceElement(node.body);
|
|
84271
|
-
if (!ts.isGlobalScopeAugmentation(node)) {
|
|
84272
|
-
registerForUnusedIdentifiersCheck(node);
|
|
84273
|
-
}
|
|
84274
|
-
}
|
|
84275
84322
|
}
|
|
84276
84323
|
function checkModuleAugmentationElement(node, isGlobalAugmentation) {
|
|
84277
84324
|
var _a;
|
|
@@ -85208,13 +85255,16 @@ var ts;
|
|
|
85208
85255
|
if (ts.isExternalOrCommonJsModule(node)) {
|
|
85209
85256
|
registerForUnusedIdentifiersCheck(node);
|
|
85210
85257
|
}
|
|
85211
|
-
|
|
85212
|
-
|
|
85213
|
-
|
|
85214
|
-
|
|
85215
|
-
|
|
85216
|
-
|
|
85217
|
-
|
|
85258
|
+
addLazyDiagnostic(function () {
|
|
85259
|
+
// This relies on the results of other lazy diagnostics, so must be computed after them
|
|
85260
|
+
if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
|
|
85261
|
+
checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
|
|
85262
|
+
if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
|
|
85263
|
+
diagnostics.add(diag);
|
|
85264
|
+
}
|
|
85265
|
+
});
|
|
85266
|
+
}
|
|
85267
|
+
});
|
|
85218
85268
|
if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
|
|
85219
85269
|
!node.isDeclarationFile &&
|
|
85220
85270
|
ts.isExternalModule(node)) {
|
|
@@ -85254,15 +85304,35 @@ var ts;
|
|
|
85254
85304
|
cancellationToken = undefined;
|
|
85255
85305
|
}
|
|
85256
85306
|
}
|
|
85307
|
+
function ensurePendingDiagnosticWorkComplete() {
|
|
85308
|
+
// Invoke any existing lazy diagnostics to add them, clear the backlog of diagnostics
|
|
85309
|
+
for (var _i = 0, deferredDiagnosticsCallbacks_1 = deferredDiagnosticsCallbacks; _i < deferredDiagnosticsCallbacks_1.length; _i++) {
|
|
85310
|
+
var cb = deferredDiagnosticsCallbacks_1[_i];
|
|
85311
|
+
cb();
|
|
85312
|
+
}
|
|
85313
|
+
deferredDiagnosticsCallbacks = [];
|
|
85314
|
+
}
|
|
85315
|
+
function checkSourceFileWithEagerDiagnostics(sourceFile) {
|
|
85316
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85317
|
+
// then setup diagnostics for immediate invocation (as we are about to collect them, and
|
|
85318
|
+
// this avoids the overhead of longer-lived callbacks we don't need to allocate)
|
|
85319
|
+
// This also serves to make the shift to possibly lazy diagnostics transparent to serial command-line scenarios
|
|
85320
|
+
// (as in those cases, all the diagnostics will still be computed as the appropriate place in the tree,
|
|
85321
|
+
// thus much more likely retaining the same union ordering as before we had lazy diagnostics)
|
|
85322
|
+
var oldAddLazyDiagnostics = addLazyDiagnostic;
|
|
85323
|
+
addLazyDiagnostic = function (cb) { return cb(); };
|
|
85324
|
+
checkSourceFile(sourceFile);
|
|
85325
|
+
addLazyDiagnostic = oldAddLazyDiagnostics;
|
|
85326
|
+
}
|
|
85257
85327
|
function getDiagnosticsWorker(sourceFile) {
|
|
85258
|
-
throwIfNonDiagnosticsProducing();
|
|
85259
85328
|
if (sourceFile) {
|
|
85329
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85260
85330
|
// Some global diagnostics are deferred until they are needed and
|
|
85261
85331
|
// may not be reported in the first call to getGlobalDiagnostics.
|
|
85262
85332
|
// We should catch these changes and report them.
|
|
85263
85333
|
var previousGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
|
|
85264
85334
|
var previousGlobalDiagnosticsSize = previousGlobalDiagnostics.length;
|
|
85265
|
-
|
|
85335
|
+
checkSourceFileWithEagerDiagnostics(sourceFile);
|
|
85266
85336
|
var semanticDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
|
|
85267
85337
|
var currentGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
|
|
85268
85338
|
if (currentGlobalDiagnostics !== previousGlobalDiagnostics) {
|
|
@@ -85280,18 +85350,13 @@ var ts;
|
|
|
85280
85350
|
}
|
|
85281
85351
|
// Global diagnostics are always added when a file is not provided to
|
|
85282
85352
|
// getDiagnostics
|
|
85283
|
-
ts.forEach(host.getSourceFiles(),
|
|
85353
|
+
ts.forEach(host.getSourceFiles(), checkSourceFileWithEagerDiagnostics);
|
|
85284
85354
|
return diagnostics.getDiagnostics();
|
|
85285
85355
|
}
|
|
85286
85356
|
function getGlobalDiagnostics() {
|
|
85287
|
-
|
|
85357
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85288
85358
|
return diagnostics.getGlobalDiagnostics();
|
|
85289
85359
|
}
|
|
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
85360
|
// Language service support
|
|
85296
85361
|
function getSymbolsInScope(location, meaning) {
|
|
85297
85362
|
if (location.flags & 16777216 /* InWithStatement */) {
|
|
@@ -115765,8 +115830,7 @@ var ts;
|
|
|
115765
115830
|
var files;
|
|
115766
115831
|
var symlinks;
|
|
115767
115832
|
var commonSourceDirectory;
|
|
115768
|
-
var
|
|
115769
|
-
var noDiagnosticsTypeChecker;
|
|
115833
|
+
var typeChecker;
|
|
115770
115834
|
var classifiableNames;
|
|
115771
115835
|
var ambientModuleNameToUnmodifiedFileName = new ts.Map();
|
|
115772
115836
|
var fileReasons = ts.createMultiMap();
|
|
@@ -116012,21 +116076,19 @@ var ts;
|
|
|
116012
116076
|
getProgramDiagnostics: getProgramDiagnostics,
|
|
116013
116077
|
getTypeChecker: getTypeChecker,
|
|
116014
116078
|
getClassifiableNames: getClassifiableNames,
|
|
116015
|
-
getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
|
|
116016
116079
|
getCommonSourceDirectory: getCommonSourceDirectory,
|
|
116017
116080
|
emit: emit,
|
|
116018
116081
|
getCurrentDirectory: function () { return currentDirectory; },
|
|
116019
|
-
getNodeCount: function () { return
|
|
116020
|
-
getIdentifierCount: function () { return
|
|
116021
|
-
getSymbolCount: function () { return
|
|
116022
|
-
getTypeCount: function () { return
|
|
116023
|
-
getInstantiationCount: function () { return
|
|
116024
|
-
getRelationCacheSizes: function () { return
|
|
116082
|
+
getNodeCount: function () { return getTypeChecker().getNodeCount(); },
|
|
116083
|
+
getIdentifierCount: function () { return getTypeChecker().getIdentifierCount(); },
|
|
116084
|
+
getSymbolCount: function () { return getTypeChecker().getSymbolCount(); },
|
|
116085
|
+
getTypeCount: function () { return getTypeChecker().getTypeCount(); },
|
|
116086
|
+
getInstantiationCount: function () { return getTypeChecker().getInstantiationCount(); },
|
|
116087
|
+
getRelationCacheSizes: function () { return getTypeChecker().getRelationCacheSizes(); },
|
|
116025
116088
|
getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; },
|
|
116026
116089
|
getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; },
|
|
116027
116090
|
isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary,
|
|
116028
116091
|
isSourceFileDefaultLibrary: isSourceFileDefaultLibrary,
|
|
116029
|
-
dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker,
|
|
116030
116092
|
getSourceFileFromReference: getSourceFileFromReference,
|
|
116031
116093
|
getLibFileFromReference: getLibFileFromReference,
|
|
116032
116094
|
sourceFileToPackageName: sourceFileToPackageName,
|
|
@@ -116615,14 +116677,8 @@ var ts;
|
|
|
116615
116677
|
return ts.some(options.lib, function (libFileName) { return equalityComparer(file.fileName, pathForLibFile(libFileName)); });
|
|
116616
116678
|
}
|
|
116617
116679
|
}
|
|
116618
|
-
function getDiagnosticsProducingTypeChecker() {
|
|
116619
|
-
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ true));
|
|
116620
|
-
}
|
|
116621
|
-
function dropDiagnosticsProducingTypeChecker() {
|
|
116622
|
-
diagnosticsProducingTypeChecker = undefined;
|
|
116623
|
-
}
|
|
116624
116680
|
function getTypeChecker() {
|
|
116625
|
-
return
|
|
116681
|
+
return typeChecker || (typeChecker = ts.createTypeChecker(program));
|
|
116626
116682
|
}
|
|
116627
116683
|
function emit(sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers, forceDtsEmit) {
|
|
116628
116684
|
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 +116703,7 @@ var ts;
|
|
|
116647
116703
|
// This is because in the -out scenario all files need to be emitted, and therefore all
|
|
116648
116704
|
// files need to be type checked. And the way to specify that all files need to be type
|
|
116649
116705
|
// checked is to not pass the file to getEmitResolver.
|
|
116650
|
-
var emitResolver =
|
|
116706
|
+
var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken);
|
|
116651
116707
|
ts.performance.mark("beforeEmit");
|
|
116652
116708
|
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles,
|
|
116653
116709
|
/*onlyBuildInfo*/ false, forceDtsEmit);
|
|
@@ -116727,15 +116783,7 @@ var ts;
|
|
|
116727
116783
|
if (e instanceof ts.OperationCanceledException) {
|
|
116728
116784
|
// We were canceled while performing the operation. Because our type checker
|
|
116729
116785
|
// 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;
|
|
116786
|
+
typeChecker = undefined;
|
|
116739
116787
|
}
|
|
116740
116788
|
throw e;
|
|
116741
116789
|
}
|
|
@@ -116751,7 +116799,7 @@ var ts;
|
|
|
116751
116799
|
if (ts.skipTypeChecking(sourceFile, options, program)) {
|
|
116752
116800
|
return ts.emptyArray;
|
|
116753
116801
|
}
|
|
116754
|
-
var typeChecker =
|
|
116802
|
+
var typeChecker = getTypeChecker();
|
|
116755
116803
|
ts.Debug.assert(!!sourceFile.bindDiagnostics);
|
|
116756
116804
|
var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
|
|
116757
116805
|
var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
|
|
@@ -116803,7 +116851,7 @@ var ts;
|
|
|
116803
116851
|
}
|
|
116804
116852
|
function getSuggestionDiagnostics(sourceFile, cancellationToken) {
|
|
116805
116853
|
return runWithCancellationToken(function () {
|
|
116806
|
-
return
|
|
116854
|
+
return getTypeChecker().getSuggestionDiagnostics(sourceFile, cancellationToken);
|
|
116807
116855
|
});
|
|
116808
116856
|
}
|
|
116809
116857
|
/**
|
|
@@ -117023,7 +117071,7 @@ var ts;
|
|
|
117023
117071
|
}
|
|
117024
117072
|
function getDeclarationDiagnosticsForFileNoCache(sourceFile, cancellationToken) {
|
|
117025
117073
|
return runWithCancellationToken(function () {
|
|
117026
|
-
var resolver =
|
|
117074
|
+
var resolver = getTypeChecker().getEmitResolver(sourceFile, cancellationToken);
|
|
117027
117075
|
// Don't actually write any files since we're just getting diagnostics.
|
|
117028
117076
|
return ts.getDeclarationDiagnostics(getEmitHost(ts.noop), resolver, sourceFile) || ts.emptyArray;
|
|
117029
117077
|
});
|
|
@@ -117061,7 +117109,7 @@ var ts;
|
|
|
117061
117109
|
return diagnostics;
|
|
117062
117110
|
}
|
|
117063
117111
|
function getGlobalDiagnostics() {
|
|
117064
|
-
return rootNames.length ? ts.sortAndDeduplicateDiagnostics(
|
|
117112
|
+
return rootNames.length ? ts.sortAndDeduplicateDiagnostics(getTypeChecker().getGlobalDiagnostics().slice()) : ts.emptyArray;
|
|
117065
117113
|
}
|
|
117066
117114
|
function getConfigFileParsingDiagnostics() {
|
|
117067
117115
|
return configFileParsingDiagnostics || ts.emptyArray;
|
|
@@ -134183,9 +134231,14 @@ var ts;
|
|
|
134183
134231
|
if (type) {
|
|
134184
134232
|
return type;
|
|
134185
134233
|
}
|
|
134186
|
-
|
|
134234
|
+
var parent = ts.walkUpParenthesizedExpressions(node.parent);
|
|
134235
|
+
if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 63 /* EqualsToken */ && node === parent.left) {
|
|
134187
134236
|
// Object literal is assignment pattern: ({ | } = x)
|
|
134188
|
-
return typeChecker.getTypeAtLocation(
|
|
134237
|
+
return typeChecker.getTypeAtLocation(parent);
|
|
134238
|
+
}
|
|
134239
|
+
if (ts.isExpression(parent)) {
|
|
134240
|
+
// f(() => (({ | })));
|
|
134241
|
+
return typeChecker.getContextualType(parent);
|
|
134189
134242
|
}
|
|
134190
134243
|
return undefined;
|
|
134191
134244
|
}
|
|
@@ -134978,8 +135031,24 @@ var ts;
|
|
|
134978
135031
|
};
|
|
134979
135032
|
}
|
|
134980
135033
|
ts.createDocumentRegistryInternal = createDocumentRegistryInternal;
|
|
135034
|
+
function compilerOptionValueToString(value) {
|
|
135035
|
+
var _a;
|
|
135036
|
+
if (value === null || typeof value !== "object") { // eslint-disable-line no-null/no-null
|
|
135037
|
+
return "" + value;
|
|
135038
|
+
}
|
|
135039
|
+
if (ts.isArray(value)) {
|
|
135040
|
+
return "[" + ((_a = ts.map(value, function (e) { return compilerOptionValueToString(e); })) === null || _a === void 0 ? void 0 : _a.join(",")) + "]";
|
|
135041
|
+
}
|
|
135042
|
+
var str = "{";
|
|
135043
|
+
for (var key in value) {
|
|
135044
|
+
if (ts.hasOwnProperty.call(value, key)) { // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
|
|
135045
|
+
str += key + ": " + compilerOptionValueToString(value[key]);
|
|
135046
|
+
}
|
|
135047
|
+
}
|
|
135048
|
+
return str + "}";
|
|
135049
|
+
}
|
|
134981
135050
|
function getKeyForCompilationSettings(settings) {
|
|
134982
|
-
return ts.sourceFileAffectingCompilerOptions.map(function (option) { return ts.getCompilerOptionValue(settings, option); }).join("|");
|
|
135051
|
+
return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
|
|
134983
135052
|
}
|
|
134984
135053
|
})(ts || (ts = {}));
|
|
134985
135054
|
/* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
|
|
@@ -138955,18 +139024,9 @@ var ts;
|
|
|
138955
139024
|
JsDoc.getJsDocTagsFromDeclarations = getJsDocTagsFromDeclarations;
|
|
138956
139025
|
function getDisplayPartsFromComment(comment, checker) {
|
|
138957
139026
|
if (typeof comment === "string") {
|
|
138958
|
-
return [ts.textPart(
|
|
139027
|
+
return [ts.textPart(comment)];
|
|
138959
139028
|
}
|
|
138960
|
-
return ts.flatMap(comment, function (node) { return node.kind === 321 /* JSDocText */ ? [ts.textPart(
|
|
138961
|
-
}
|
|
138962
|
-
function skipSeparatorFromComment(text) {
|
|
138963
|
-
var pos = 0;
|
|
138964
|
-
if (text.charCodeAt(pos++) === 45 /* minus */) {
|
|
138965
|
-
while (pos < text.length && text.charCodeAt(pos) === 32 /* space */)
|
|
138966
|
-
pos++;
|
|
138967
|
-
return text.slice(pos);
|
|
138968
|
-
}
|
|
138969
|
-
return text;
|
|
139029
|
+
return ts.flatMap(comment, function (node) { return node.kind === 321 /* JSDocText */ ? [ts.textPart(node.text)] : ts.buildLinkParts(node, checker); });
|
|
138970
139030
|
}
|
|
138971
139031
|
function getCommentDisplayParts(tag, checker) {
|
|
138972
139032
|
var comment = tag.comment, kind = tag.kind;
|
|
@@ -146764,7 +146824,28 @@ var ts;
|
|
|
146764
146824
|
// indentation is first non-whitespace character in a previous line
|
|
146765
146825
|
// for block indentation, we should look for a line which contains something that's not
|
|
146766
146826
|
// whitespace.
|
|
146767
|
-
|
|
146827
|
+
var currentToken = ts.getTokenAtPosition(sourceFile, position);
|
|
146828
|
+
// for object literal, we want to the indentation work like block
|
|
146829
|
+
// if { starts in any position (can be in the middle of line)
|
|
146830
|
+
// the following indentation should treat { as starting of that line (including leading whitespace)
|
|
146831
|
+
// ```
|
|
146832
|
+
// const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
|
|
146833
|
+
// ->
|
|
146834
|
+
// const a: { x: undefined, y: undefined } = {
|
|
146835
|
+
// x: undefined,
|
|
146836
|
+
// y: undefined,
|
|
146837
|
+
// }
|
|
146838
|
+
// ---------------------
|
|
146839
|
+
// const a: {x : undefined, y: undefined } =
|
|
146840
|
+
// {}
|
|
146841
|
+
// ->
|
|
146842
|
+
// const a: { x: undefined, y: undefined } =
|
|
146843
|
+
// { // leading 5 whitespaces and { starts at 6 column
|
|
146844
|
+
// x: undefined,
|
|
146845
|
+
// y: undefined,
|
|
146846
|
+
// }
|
|
146847
|
+
// ```
|
|
146848
|
+
if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
|
|
146768
146849
|
return getBlockIndent(sourceFile, position, options);
|
|
146769
146850
|
}
|
|
146770
146851
|
if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
|
|
@@ -147707,7 +147788,7 @@ var ts;
|
|
|
147707
147788
|
}
|
|
147708
147789
|
var startPosition = ts.getPrecedingNonSpaceCharacterPosition(sourceFile.text, fnStart - 1);
|
|
147709
147790
|
var indent = sourceFile.text.slice(startPosition, fnStart);
|
|
147710
|
-
this.insertNodeAt(sourceFile, fnStart, tag, {
|
|
147791
|
+
this.insertNodeAt(sourceFile, fnStart, tag, { suffix: this.newLineCharacter + indent });
|
|
147711
147792
|
};
|
|
147712
147793
|
ChangeTracker.prototype.createJSDocText = function (sourceFile, node) {
|
|
147713
147794
|
var comments = ts.flatMap(node.jsDoc, function (jsDoc) {
|
|
@@ -148238,7 +148319,7 @@ var ts;
|
|
|
148238
148319
|
? 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
148320
|
: format(change.node);
|
|
148240
148321
|
// strip initial indentation (spaces or tabs) if text will be inserted in the middle of the line
|
|
148241
|
-
var noIndent = (options.
|
|
148322
|
+
var noIndent = (options.indentation !== undefined || ts.getLineStartPositionForPosition(pos, sourceFile) === pos) ? text : text.replace(/^\s+/, "");
|
|
148242
148323
|
return (options.prefix || "") + noIndent
|
|
148243
148324
|
+ ((!options.suffix || ts.endsWith(noIndent, options.suffix))
|
|
148244
148325
|
? "" : options.suffix);
|
|
@@ -148931,7 +149012,7 @@ var ts;
|
|
|
148931
149012
|
errorCodes: errorCodes,
|
|
148932
149013
|
getCodeActions: function getCodeActionsToAddMissingAsync(context) {
|
|
148933
149014
|
var sourceFile = context.sourceFile, errorCode = context.errorCode, cancellationToken = context.cancellationToken, program = context.program, span = context.span;
|
|
148934
|
-
var diagnostic = ts.find(program.
|
|
149015
|
+
var diagnostic = ts.find(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
|
|
148935
149016
|
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
149017
|
var decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
|
|
148937
149018
|
if (!decl) {
|
|
@@ -149085,7 +149166,7 @@ var ts;
|
|
|
149085
149166
|
return codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_await, fixId, ts.Diagnostics.Fix_all_expressions_possibly_missing_await);
|
|
149086
149167
|
}
|
|
149087
149168
|
function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
|
|
149088
|
-
var checker = program.
|
|
149169
|
+
var checker = program.getTypeChecker();
|
|
149089
149170
|
var diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
|
|
149090
149171
|
return ts.some(diagnostics, function (_a) {
|
|
149091
149172
|
var start = _a.start, length = _a.length, relatedInformation = _a.relatedInformation, code = _a.code;
|
|
@@ -149752,20 +149833,6 @@ var ts;
|
|
|
149752
149833
|
}
|
|
149753
149834
|
function createClassElementsFromSymbol(symbol) {
|
|
149754
149835
|
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
149836
|
// all static members are stored in the "exports" array of symbol
|
|
149770
149837
|
if (symbol.exports) {
|
|
149771
149838
|
symbol.exports.forEach(function (member) {
|
|
@@ -149778,18 +149845,31 @@ var ts;
|
|
|
149778
149845
|
firstDeclaration.parent.operatorToken.kind === 63 /* EqualsToken */ &&
|
|
149779
149846
|
ts.isObjectLiteralExpression(firstDeclaration.parent.right)) {
|
|
149780
149847
|
var prototypes = firstDeclaration.parent.right;
|
|
149781
|
-
|
|
149782
|
-
if (memberElement) {
|
|
149783
|
-
memberElements.push.apply(memberElements, memberElement);
|
|
149784
|
-
}
|
|
149848
|
+
createClassElement(prototypes.symbol, /** modifiers */ undefined, memberElements);
|
|
149785
149849
|
}
|
|
149786
149850
|
}
|
|
149787
149851
|
else {
|
|
149788
|
-
|
|
149789
|
-
|
|
149790
|
-
|
|
149852
|
+
createClassElement(member, [ts.factory.createToken(124 /* StaticKeyword */)], memberElements);
|
|
149853
|
+
}
|
|
149854
|
+
});
|
|
149855
|
+
}
|
|
149856
|
+
// all instance members are stored in the "member" array of symbol (done last so instance members pulled from prototype assignments have priority)
|
|
149857
|
+
if (symbol.members) {
|
|
149858
|
+
symbol.members.forEach(function (member, key) {
|
|
149859
|
+
var _a, _b, _c, _d;
|
|
149860
|
+
if (key === "constructor" && member.valueDeclaration) {
|
|
149861
|
+
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;
|
|
149862
|
+
if (prototypeAssignment && ts.isBinaryExpression(prototypeAssignment) && ts.isObjectLiteralExpression(prototypeAssignment.right) && ts.some(prototypeAssignment.right.properties, isConstructorAssignment)) {
|
|
149863
|
+
// fn.prototype = { constructor: fn }
|
|
149864
|
+
// Already deleted in `createClassElement` in first pass
|
|
149865
|
+
}
|
|
149866
|
+
else {
|
|
149867
|
+
// fn.prototype.constructor = fn
|
|
149868
|
+
changes.delete(sourceFile, member.valueDeclaration.parent);
|
|
149791
149869
|
}
|
|
149870
|
+
return;
|
|
149792
149871
|
}
|
|
149872
|
+
createClassElement(member, /*modifiers*/ undefined, memberElements);
|
|
149793
149873
|
});
|
|
149794
149874
|
}
|
|
149795
149875
|
return memberElements;
|
|
@@ -149817,18 +149897,26 @@ var ts;
|
|
|
149817
149897
|
});
|
|
149818
149898
|
}
|
|
149819
149899
|
}
|
|
149820
|
-
function createClassElement(symbol, modifiers) {
|
|
149900
|
+
function createClassElement(symbol, modifiers, members) {
|
|
149821
149901
|
// Right now the only thing we can convert are function expressions, which are marked as methods
|
|
149822
149902
|
// or { x: y } type prototype assignments, which are marked as ObjectLiteral
|
|
149823
|
-
var members = [];
|
|
149824
149903
|
if (!(symbol.flags & 8192 /* Method */) && !(symbol.flags & 4096 /* ObjectLiteral */)) {
|
|
149825
|
-
return
|
|
149904
|
+
return;
|
|
149826
149905
|
}
|
|
149827
149906
|
var memberDeclaration = symbol.valueDeclaration;
|
|
149828
149907
|
var assignmentBinaryExpression = memberDeclaration.parent;
|
|
149829
149908
|
var assignmentExpr = assignmentBinaryExpression.right;
|
|
149830
149909
|
if (!shouldConvertDeclaration(memberDeclaration, assignmentExpr)) {
|
|
149831
|
-
return
|
|
149910
|
+
return;
|
|
149911
|
+
}
|
|
149912
|
+
if (ts.some(members, function (m) {
|
|
149913
|
+
var name = ts.getNameOfDeclaration(m);
|
|
149914
|
+
if (name && ts.isIdentifier(name) && ts.idText(name) === ts.symbolName(symbol)) {
|
|
149915
|
+
return true; // class member already made for this name
|
|
149916
|
+
}
|
|
149917
|
+
return false;
|
|
149918
|
+
})) {
|
|
149919
|
+
return;
|
|
149832
149920
|
}
|
|
149833
149921
|
// delete the entire statement if this expression is the sole expression to take care of the semicolon at the end
|
|
149834
149922
|
var nodeToDelete = assignmentBinaryExpression.parent && assignmentBinaryExpression.parent.kind === 238 /* ExpressionStatement */
|
|
@@ -149837,43 +149925,44 @@ var ts;
|
|
|
149837
149925
|
if (!assignmentExpr) {
|
|
149838
149926
|
members.push(ts.factory.createPropertyDeclaration([], modifiers, symbol.name, /*questionToken*/ undefined,
|
|
149839
149927
|
/*type*/ undefined, /*initializer*/ undefined));
|
|
149840
|
-
return
|
|
149928
|
+
return;
|
|
149841
149929
|
}
|
|
149842
149930
|
// f.x = expr
|
|
149843
149931
|
if (ts.isAccessExpression(memberDeclaration) && (ts.isFunctionExpression(assignmentExpr) || ts.isArrowFunction(assignmentExpr))) {
|
|
149844
149932
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
149845
149933
|
var name = tryGetPropertyName(memberDeclaration, compilerOptions, quotePreference);
|
|
149846
149934
|
if (name) {
|
|
149847
|
-
|
|
149935
|
+
createFunctionLikeExpressionMember(members, assignmentExpr, name);
|
|
149848
149936
|
}
|
|
149849
|
-
return
|
|
149937
|
+
return;
|
|
149850
149938
|
}
|
|
149851
149939
|
// f.prototype = { ... }
|
|
149852
149940
|
else if (ts.isObjectLiteralExpression(assignmentExpr)) {
|
|
149853
|
-
|
|
149941
|
+
ts.forEach(assignmentExpr.properties, function (property) {
|
|
149854
149942
|
if (ts.isMethodDeclaration(property) || ts.isGetOrSetAccessorDeclaration(property)) {
|
|
149855
149943
|
// MethodDeclaration and AccessorDeclaration can appear in a class directly
|
|
149856
|
-
|
|
149944
|
+
members.push(property);
|
|
149857
149945
|
}
|
|
149858
149946
|
if (ts.isPropertyAssignment(property) && ts.isFunctionExpression(property.initializer)) {
|
|
149859
|
-
|
|
149947
|
+
createFunctionLikeExpressionMember(members, property.initializer, property.name);
|
|
149860
149948
|
}
|
|
149861
149949
|
// Drop constructor assignments
|
|
149862
149950
|
if (isConstructorAssignment(property))
|
|
149863
|
-
return
|
|
149864
|
-
return
|
|
149951
|
+
return;
|
|
149952
|
+
return;
|
|
149865
149953
|
});
|
|
149954
|
+
return;
|
|
149866
149955
|
}
|
|
149867
149956
|
else {
|
|
149868
149957
|
// Don't try to declare members in JavaScript files
|
|
149869
149958
|
if (ts.isSourceFileJS(sourceFile))
|
|
149870
|
-
return
|
|
149959
|
+
return;
|
|
149871
149960
|
if (!ts.isPropertyAccessExpression(memberDeclaration))
|
|
149872
|
-
return
|
|
149961
|
+
return;
|
|
149873
149962
|
var prop = ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined, /*type*/ undefined, assignmentExpr);
|
|
149874
149963
|
ts.copyLeadingComments(assignmentBinaryExpression.parent, prop, sourceFile);
|
|
149875
149964
|
members.push(prop);
|
|
149876
|
-
return
|
|
149965
|
+
return;
|
|
149877
149966
|
}
|
|
149878
149967
|
function createFunctionLikeExpressionMember(members, expression, name) {
|
|
149879
149968
|
if (ts.isFunctionExpression(expression))
|
|
@@ -149886,7 +149975,8 @@ var ts;
|
|
|
149886
149975
|
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
|
|
149887
149976
|
/*typeParameters*/ undefined, functionExpression.parameters, /*type*/ undefined, functionExpression.body);
|
|
149888
149977
|
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
|
|
149889
|
-
|
|
149978
|
+
members.push(method);
|
|
149979
|
+
return;
|
|
149890
149980
|
}
|
|
149891
149981
|
function createArrowFunctionExpressionMember(members, arrowFunction, name) {
|
|
149892
149982
|
var arrowFunctionBody = arrowFunction.body;
|
|
@@ -149903,7 +149993,7 @@ var ts;
|
|
|
149903
149993
|
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
|
|
149904
149994
|
/*typeParameters*/ undefined, arrowFunction.parameters, /*type*/ undefined, bodyBlock);
|
|
149905
149995
|
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
|
|
149906
|
-
|
|
149996
|
+
members.push(method);
|
|
149907
149997
|
}
|
|
149908
149998
|
}
|
|
149909
149999
|
}
|
|
@@ -153337,7 +153427,7 @@ var ts;
|
|
|
153337
153427
|
var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
|
|
153338
153428
|
if (!ts.length(properties))
|
|
153339
153429
|
return undefined;
|
|
153340
|
-
return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties,
|
|
153430
|
+
return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
|
|
153341
153431
|
}
|
|
153342
153432
|
if (!ts.isMemberName(token))
|
|
153343
153433
|
return undefined;
|
|
@@ -153345,7 +153435,7 @@ var ts;
|
|
|
153345
153435
|
var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
|
|
153346
153436
|
if (!ts.length(properties))
|
|
153347
153437
|
return undefined;
|
|
153348
|
-
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties,
|
|
153438
|
+
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, parentDeclaration: parent.initializer };
|
|
153349
153439
|
}
|
|
153350
153440
|
if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
|
|
153351
153441
|
var target = ts.getEmitScriptTarget(program.getCompilerOptions());
|