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
package/lib/tsserver.js
CHANGED
|
@@ -100,7 +100,7 @@ var ts;
|
|
|
100
100
|
// The following is baselined as a literal template type without intervention
|
|
101
101
|
/** The version of the TypeScript compiler release */
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
103
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220327";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -8407,6 +8407,7 @@ var ts;
|
|
|
8407
8407
|
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),
|
|
8408
8408
|
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."),
|
|
8409
8409
|
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."),
|
|
8410
|
+
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."),
|
|
8410
8411
|
Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
|
|
8411
8412
|
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."),
|
|
8412
8413
|
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."),
|
|
@@ -44430,11 +44431,14 @@ var ts;
|
|
|
44430
44431
|
var saveExceptionTarget = currentExceptionTarget;
|
|
44431
44432
|
var saveActiveLabelList = activeLabelList;
|
|
44432
44433
|
var saveHasExplicitReturn = hasExplicitReturn;
|
|
44433
|
-
var
|
|
44434
|
-
!
|
|
44434
|
+
var isImmediatelyInvoked = (containerFlags & 16 /* IsFunctionExpression */ &&
|
|
44435
|
+
!ts.hasSyntacticModifier(node, 256 /* Async */) &&
|
|
44436
|
+
!node.asteriskToken &&
|
|
44437
|
+
!!ts.getImmediatelyInvokedFunctionExpression(node)) ||
|
|
44438
|
+
node.kind === 170 /* ClassStaticBlockDeclaration */;
|
|
44435
44439
|
// A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave
|
|
44436
44440
|
// similarly to break statements that exit to a label just past the statement body.
|
|
44437
|
-
if (!
|
|
44441
|
+
if (!isImmediatelyInvoked) {
|
|
44438
44442
|
currentFlow = initFlowNode({ flags: 2 /* Start */ });
|
|
44439
44443
|
if (containerFlags & (16 /* IsFunctionExpression */ | 128 /* IsObjectLiteralOrClassExpressionMethodOrAccessor */)) {
|
|
44440
44444
|
currentFlow.node = node;
|
|
@@ -44442,7 +44446,7 @@ var ts;
|
|
|
44442
44446
|
}
|
|
44443
44447
|
// We create a return control flow graph for IIFEs and constructors. For constructors
|
|
44444
44448
|
// we use the return control flow graph in strict property initialization checks.
|
|
44445
|
-
currentReturnTarget =
|
|
44449
|
+
currentReturnTarget = isImmediatelyInvoked || node.kind === 171 /* Constructor */ || (ts.isInJSFile(node) && (node.kind === 256 /* FunctionDeclaration */ || node.kind === 213 /* FunctionExpression */)) ? createBranchLabel() : undefined;
|
|
44446
44450
|
currentExceptionTarget = undefined;
|
|
44447
44451
|
currentBreakTarget = undefined;
|
|
44448
44452
|
currentContinueTarget = undefined;
|
|
@@ -44468,7 +44472,7 @@ var ts;
|
|
|
44468
44472
|
node.returnFlowNode = currentFlow;
|
|
44469
44473
|
}
|
|
44470
44474
|
}
|
|
44471
|
-
if (!
|
|
44475
|
+
if (!isImmediatelyInvoked) {
|
|
44472
44476
|
currentFlow = saveCurrentFlow;
|
|
44473
44477
|
}
|
|
44474
44478
|
currentBreakTarget = saveBreakTarget;
|
|
@@ -47514,7 +47518,7 @@ var ts;
|
|
|
47514
47518
|
(preserveConstEnums && moduleState === 2 /* ConstEnumOnly */);
|
|
47515
47519
|
}
|
|
47516
47520
|
ts.isInstantiatedModule = isInstantiatedModule;
|
|
47517
|
-
function createTypeChecker(host
|
|
47521
|
+
function createTypeChecker(host) {
|
|
47518
47522
|
var getPackagesMap = ts.memoize(function () {
|
|
47519
47523
|
// A package name maps to true when we detect it has .d.ts files.
|
|
47520
47524
|
// This is useful as an approximation of whether a package bundles its own types.
|
|
@@ -47531,6 +47535,10 @@ var ts;
|
|
|
47531
47535
|
});
|
|
47532
47536
|
return map;
|
|
47533
47537
|
});
|
|
47538
|
+
var deferredDiagnosticsCallbacks = [];
|
|
47539
|
+
var addLazyDiagnostic = function (arg) {
|
|
47540
|
+
deferredDiagnosticsCallbacks.push(arg);
|
|
47541
|
+
};
|
|
47534
47542
|
// Cancellation that controls whether or not we can cancel in the middle of type checking.
|
|
47535
47543
|
// In general cancelling is *not* safe for the type checker. We might be in the middle of
|
|
47536
47544
|
// computing something, and we will leave our internals in an inconsistent state. Callers
|
|
@@ -47894,8 +47902,8 @@ var ts;
|
|
|
47894
47902
|
// Do this in a finally block so we can ensure that it gets reset back to nothing after
|
|
47895
47903
|
// this call is done.
|
|
47896
47904
|
cancellationToken = ct;
|
|
47897
|
-
// Ensure file is type checked
|
|
47898
|
-
|
|
47905
|
+
// Ensure file is type checked, with _eager_ diagnostic production, so identifiers are registered as potentially unused
|
|
47906
|
+
checkSourceFileWithEagerDiagnostics(file);
|
|
47899
47907
|
ts.Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
|
|
47900
47908
|
diagnostics = ts.addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
|
|
47901
47909
|
checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) {
|
|
@@ -49231,110 +49239,114 @@ var ts;
|
|
|
49231
49239
|
}
|
|
49232
49240
|
}
|
|
49233
49241
|
if (!result) {
|
|
49234
|
-
if (nameNotFoundMessage
|
|
49235
|
-
|
|
49236
|
-
!
|
|
49237
|
-
!
|
|
49238
|
-
|
|
49239
|
-
|
|
49240
|
-
|
|
49241
|
-
|
|
49242
|
-
|
|
49243
|
-
|
|
49244
|
-
|
|
49245
|
-
|
|
49246
|
-
|
|
49247
|
-
|
|
49248
|
-
|
|
49249
|
-
|
|
49250
|
-
if (suggestion) {
|
|
49251
|
-
var suggestionName = symbolToString(suggestion);
|
|
49252
|
-
var isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
|
|
49253
|
-
var message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && ts.nodeIsSynthesized(nameArg) ? ts.Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
|
|
49254
|
-
: isUncheckedJS ? ts.Diagnostics.Could_not_find_name_0_Did_you_mean_1
|
|
49255
|
-
: ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1;
|
|
49256
|
-
var diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
|
|
49257
|
-
addErrorOrSuggestion(!isUncheckedJS, diagnostic);
|
|
49258
|
-
if (suggestion.valueDeclaration) {
|
|
49259
|
-
ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName));
|
|
49242
|
+
if (nameNotFoundMessage) {
|
|
49243
|
+
addLazyDiagnostic(function () {
|
|
49244
|
+
if (!errorLocation ||
|
|
49245
|
+
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
|
|
49246
|
+
!checkAndReportErrorForExtendingInterface(errorLocation) &&
|
|
49247
|
+
!checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
|
|
49248
|
+
!checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
|
|
49249
|
+
!checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
|
|
49250
|
+
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
|
|
49251
|
+
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
|
|
49252
|
+
var suggestion = void 0;
|
|
49253
|
+
if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
|
|
49254
|
+
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
|
|
49255
|
+
var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
|
|
49256
|
+
if (isGlobalScopeAugmentationDeclaration) {
|
|
49257
|
+
suggestion = undefined;
|
|
49260
49258
|
}
|
|
49261
|
-
|
|
49262
|
-
|
|
49263
|
-
|
|
49264
|
-
|
|
49265
|
-
|
|
49266
|
-
|
|
49267
|
-
|
|
49259
|
+
if (suggestion) {
|
|
49260
|
+
var suggestionName = symbolToString(suggestion);
|
|
49261
|
+
var isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
|
|
49262
|
+
var message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && ts.nodeIsSynthesized(nameArg) ? ts.Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
|
|
49263
|
+
: isUncheckedJS ? ts.Diagnostics.Could_not_find_name_0_Did_you_mean_1
|
|
49264
|
+
: ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1;
|
|
49265
|
+
var diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
|
|
49266
|
+
addErrorOrSuggestion(!isUncheckedJS, diagnostic);
|
|
49267
|
+
if (suggestion.valueDeclaration) {
|
|
49268
|
+
ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName));
|
|
49269
|
+
}
|
|
49268
49270
|
}
|
|
49269
|
-
|
|
49270
|
-
|
|
49271
|
+
}
|
|
49272
|
+
if (!suggestion) {
|
|
49273
|
+
if (nameArg) {
|
|
49274
|
+
var lib = getSuggestedLibForNonExistentName(nameArg);
|
|
49275
|
+
if (lib) {
|
|
49276
|
+
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
|
|
49277
|
+
}
|
|
49278
|
+
else {
|
|
49279
|
+
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
|
|
49280
|
+
}
|
|
49271
49281
|
}
|
|
49272
49282
|
}
|
|
49283
|
+
suggestionCount++;
|
|
49273
49284
|
}
|
|
49274
|
-
|
|
49275
|
-
}
|
|
49285
|
+
});
|
|
49276
49286
|
}
|
|
49277
49287
|
return undefined;
|
|
49278
49288
|
}
|
|
49289
|
+
if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
|
|
49290
|
+
// We have a match, but the reference occurred within a property initializer and the identifier also binds
|
|
49291
|
+
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
|
|
49292
|
+
// with ESNext+useDefineForClassFields because the scope semantics are different.
|
|
49293
|
+
var propertyName = propertyWithInvalidInitializer.name;
|
|
49294
|
+
error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
|
|
49295
|
+
return undefined;
|
|
49296
|
+
}
|
|
49279
49297
|
// Perform extra checks only if error reporting was requested
|
|
49280
|
-
if (nameNotFoundMessage
|
|
49281
|
-
|
|
49282
|
-
//
|
|
49283
|
-
//
|
|
49284
|
-
//
|
|
49285
|
-
|
|
49286
|
-
|
|
49287
|
-
|
|
49288
|
-
|
|
49289
|
-
|
|
49290
|
-
|
|
49291
|
-
|
|
49292
|
-
|
|
49293
|
-
|
|
49294
|
-
|
|
49295
|
-
|
|
49296
|
-
|
|
49297
|
-
|
|
49298
|
-
|
|
49299
|
-
|
|
49300
|
-
|
|
49301
|
-
|
|
49302
|
-
|
|
49303
|
-
|
|
49304
|
-
|
|
49305
|
-
|
|
49306
|
-
|
|
49307
|
-
|
|
49308
|
-
|
|
49309
|
-
|
|
49310
|
-
|
|
49311
|
-
|
|
49312
|
-
|
|
49313
|
-
|
|
49314
|
-
|
|
49315
|
-
|
|
49316
|
-
|
|
49317
|
-
|
|
49318
|
-
|
|
49319
|
-
|
|
49320
|
-
|
|
49321
|
-
|
|
49322
|
-
|
|
49323
|
-
|
|
49324
|
-
|
|
49325
|
-
|
|
49326
|
-
|
|
49327
|
-
|
|
49328
|
-
|
|
49329
|
-
|
|
49330
|
-
if (typeOnlyDeclaration) {
|
|
49331
|
-
var message = typeOnlyDeclaration.kind === 275 /* ExportSpecifier */
|
|
49332
|
-
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
49333
|
-
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
49334
|
-
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
49335
|
-
addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
|
|
49298
|
+
if (nameNotFoundMessage) {
|
|
49299
|
+
addLazyDiagnostic(function () {
|
|
49300
|
+
// Only check for block-scoped variable if we have an error location and are looking for the
|
|
49301
|
+
// name with variable meaning
|
|
49302
|
+
// For example,
|
|
49303
|
+
// declare module foo {
|
|
49304
|
+
// interface bar {}
|
|
49305
|
+
// }
|
|
49306
|
+
// const foo/*1*/: foo/*2*/.bar;
|
|
49307
|
+
// The foo at /*1*/ and /*2*/ will share same symbol with two meanings:
|
|
49308
|
+
// block-scoped variable and namespace module. However, only when we
|
|
49309
|
+
// try to resolve name in /*1*/ which is used in variable position,
|
|
49310
|
+
// we want to check for block-scoped
|
|
49311
|
+
if (errorLocation &&
|
|
49312
|
+
(meaning & 2 /* BlockScopedVariable */ ||
|
|
49313
|
+
((meaning & 32 /* Class */ || meaning & 384 /* Enum */) && (meaning & 111551 /* Value */) === 111551 /* Value */))) {
|
|
49314
|
+
var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
|
|
49315
|
+
if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */ || exportOrLocalSymbol.flags & 32 /* Class */ || exportOrLocalSymbol.flags & 384 /* Enum */) {
|
|
49316
|
+
checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
|
|
49317
|
+
}
|
|
49318
|
+
}
|
|
49319
|
+
// If we're in an external module, we can't reference value symbols created from UMD export declarations
|
|
49320
|
+
if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 4194304 /* JSDoc */)) {
|
|
49321
|
+
var merged = getMergedSymbol(result);
|
|
49322
|
+
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
|
|
49323
|
+
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));
|
|
49324
|
+
}
|
|
49325
|
+
}
|
|
49326
|
+
// 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
|
|
49327
|
+
if (result && associatedDeclarationForContainingInitializerOrBindingName && !withinDeferredContext && (meaning & 111551 /* Value */) === 111551 /* Value */) {
|
|
49328
|
+
var candidate = getMergedSymbol(getLateBoundSymbol(result));
|
|
49329
|
+
var root = ts.getRootDeclaration(associatedDeclarationForContainingInitializerOrBindingName);
|
|
49330
|
+
// A parameter initializer or binding pattern initializer within a parameter cannot refer to itself
|
|
49331
|
+
if (candidate === getSymbolOfNode(associatedDeclarationForContainingInitializerOrBindingName)) {
|
|
49332
|
+
error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_itself, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name));
|
|
49333
|
+
}
|
|
49334
|
+
// And it cannot refer to any declarations which come after it
|
|
49335
|
+
else if (candidate.valueDeclaration && candidate.valueDeclaration.pos > associatedDeclarationForContainingInitializerOrBindingName.pos && root.parent.locals && lookup(root.parent.locals, candidate.escapedName, meaning) === candidate) {
|
|
49336
|
+
error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
|
|
49337
|
+
}
|
|
49338
|
+
}
|
|
49339
|
+
if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
|
|
49340
|
+
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
|
|
49341
|
+
if (typeOnlyDeclaration) {
|
|
49342
|
+
var message = typeOnlyDeclaration.kind === 275 /* ExportSpecifier */
|
|
49343
|
+
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
49344
|
+
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
49345
|
+
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
49346
|
+
addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
|
|
49347
|
+
}
|
|
49336
49348
|
}
|
|
49337
|
-
}
|
|
49349
|
+
});
|
|
49338
49350
|
}
|
|
49339
49351
|
return result;
|
|
49340
49352
|
}
|
|
@@ -50980,9 +50992,7 @@ var ts;
|
|
|
50980
50992
|
var result = new Type(checker, flags);
|
|
50981
50993
|
typeCount++;
|
|
50982
50994
|
result.id = typeCount;
|
|
50983
|
-
|
|
50984
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.recordType(result);
|
|
50985
|
-
}
|
|
50995
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.recordType(result);
|
|
50986
50996
|
return result;
|
|
50987
50997
|
}
|
|
50988
50998
|
function createOriginType(flags) {
|
|
@@ -55905,11 +55915,16 @@ var ts;
|
|
|
55905
55915
|
}
|
|
55906
55916
|
var type = resolveTypeOfAccessors(symbol, writing);
|
|
55907
55917
|
if (!popTypeResolution()) {
|
|
55908
|
-
|
|
55909
|
-
if (
|
|
55910
|
-
|
|
55911
|
-
|
|
55918
|
+
var getter = ts.getDeclarationOfKind(symbol, 172 /* GetAccessor */);
|
|
55919
|
+
if (getter) {
|
|
55920
|
+
if (ts.getEffectiveTypeAnnotationNode(getter)) {
|
|
55921
|
+
error(getter.name, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
|
|
55922
|
+
}
|
|
55923
|
+
else if (noImplicitAny) {
|
|
55924
|
+
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));
|
|
55925
|
+
}
|
|
55912
55926
|
}
|
|
55927
|
+
type = anyType;
|
|
55913
55928
|
}
|
|
55914
55929
|
return type;
|
|
55915
55930
|
}
|
|
@@ -64316,6 +64331,7 @@ var ts;
|
|
|
64316
64331
|
return 0 /* False */;
|
|
64317
64332
|
}
|
|
64318
64333
|
function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
|
|
64334
|
+
var _a, _b;
|
|
64319
64335
|
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
64320
64336
|
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
64321
64337
|
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
@@ -64356,6 +64372,9 @@ var ts;
|
|
|
64356
64372
|
return;
|
|
64357
64373
|
}
|
|
64358
64374
|
reportRelationError(headMessage, source, target);
|
|
64375
|
+
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 */))) {
|
|
64376
|
+
associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
|
|
64377
|
+
}
|
|
64359
64378
|
}
|
|
64360
64379
|
function traceUnionsOrIntersectionsTooLarge(source, target) {
|
|
64361
64380
|
if (!ts.tracing) {
|
|
@@ -65128,7 +65147,7 @@ var ts;
|
|
|
65128
65147
|
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
|
|
65129
65148
|
if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
|
|
65130
65149
|
var constraint = getConstraintOfType(source);
|
|
65131
|
-
if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
65150
|
+
if (!strictNullChecks && (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */))) {
|
|
65132
65151
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
65133
65152
|
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
65134
65153
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -65136,12 +65155,12 @@ var ts;
|
|
|
65136
65155
|
}
|
|
65137
65156
|
}
|
|
65138
65157
|
// 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
|
|
65139
|
-
else if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
65158
|
+
else if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState))) {
|
|
65140
65159
|
resetErrorInfo(saveErrorInfo);
|
|
65141
65160
|
return result;
|
|
65142
65161
|
}
|
|
65143
65162
|
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
|
|
65144
|
-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
65163
|
+
else if (constraint && (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState))) {
|
|
65145
65164
|
resetErrorInfo(saveErrorInfo);
|
|
65146
65165
|
return result;
|
|
65147
65166
|
}
|
|
@@ -67200,12 +67219,14 @@ var ts;
|
|
|
67200
67219
|
errorOrSuggestion(noImplicitAny, declaration, diagnostic, ts.declarationNameToString(ts.getNameOfDeclaration(declaration)), typeAsString);
|
|
67201
67220
|
}
|
|
67202
67221
|
function reportErrorsFromWidening(declaration, type, wideningKind) {
|
|
67203
|
-
|
|
67204
|
-
|
|
67205
|
-
|
|
67206
|
-
|
|
67222
|
+
addLazyDiagnostic(function () {
|
|
67223
|
+
if (noImplicitAny && ts.getObjectFlags(type) & 65536 /* ContainsWideningType */ && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration))) {
|
|
67224
|
+
// Report implicit any error within type if possible, otherwise report error on declaration
|
|
67225
|
+
if (!reportWideningErrorsInType(type)) {
|
|
67226
|
+
reportImplicitAny(declaration, type, wideningKind);
|
|
67227
|
+
}
|
|
67207
67228
|
}
|
|
67208
|
-
}
|
|
67229
|
+
});
|
|
67209
67230
|
}
|
|
67210
67231
|
function applyToParameterTypes(source, target, callback) {
|
|
67211
67232
|
var sourceCount = getParameterCount(source);
|
|
@@ -72073,21 +72094,11 @@ var ts;
|
|
|
72073
72094
|
}
|
|
72074
72095
|
return false;
|
|
72075
72096
|
}
|
|
72076
|
-
function uniqueStrings(strings) {
|
|
72077
|
-
var unique = new ts.Set(strings);
|
|
72078
|
-
var result = [];
|
|
72079
|
-
unique.forEach(function (str) { return result.push(str); });
|
|
72080
|
-
return result;
|
|
72081
|
-
}
|
|
72082
72097
|
function discriminateContextualTypeByObjectMembers(node, contextualType) {
|
|
72083
|
-
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(
|
|
72084
|
-
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; });
|
|
72085
|
-
})), function (name) { return [function () { return undefinedType; }, name]; })), isTypeAssignableTo, contextualType);
|
|
72098
|
+
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);
|
|
72086
72099
|
}
|
|
72087
72100
|
function discriminateContextualTypeByJSXAttributes(node, contextualType) {
|
|
72088
|
-
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(
|
|
72089
|
-
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; });
|
|
72090
|
-
})), function (name) { return [function () { return undefinedType; }, name]; })), isTypeAssignableTo, contextualType);
|
|
72101
|
+
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);
|
|
72091
72102
|
}
|
|
72092
72103
|
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
|
|
72093
72104
|
// be "pushed" onto a node using the contextualType property.
|
|
@@ -73968,6 +73979,7 @@ var ts;
|
|
|
73968
73979
|
&& !isOptionalPropertyDeclaration(valueDeclaration)
|
|
73969
73980
|
&& !(ts.isAccessExpression(node) && ts.isAccessExpression(node.expression))
|
|
73970
73981
|
&& !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
|
|
73982
|
+
&& !(ts.isMethodDeclaration(valueDeclaration) && ts.getCombinedModifierFlags(valueDeclaration) & 32 /* Static */)
|
|
73971
73983
|
&& (compilerOptions.useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) {
|
|
73972
73984
|
diagnosticMessage = error(right, ts.Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
|
|
73973
73985
|
}
|
|
@@ -75197,7 +75209,7 @@ var ts;
|
|
|
75197
75209
|
var isTaggedTemplate = node.kind === 210 /* TaggedTemplateExpression */;
|
|
75198
75210
|
var isDecorator = node.kind === 165 /* Decorator */;
|
|
75199
75211
|
var isJsxOpeningOrSelfClosingElement = ts.isJsxOpeningLikeElement(node);
|
|
75200
|
-
var reportErrors = !candidatesOutArray
|
|
75212
|
+
var reportErrors = !candidatesOutArray;
|
|
75201
75213
|
var typeArguments;
|
|
75202
75214
|
if (!isDecorator) {
|
|
75203
75215
|
typeArguments = node.typeArguments;
|
|
@@ -76477,11 +76489,13 @@ var ts;
|
|
|
76477
76489
|
checkSourceElement(type);
|
|
76478
76490
|
exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(exprType));
|
|
76479
76491
|
var targetType = getTypeFromTypeNode(type);
|
|
76480
|
-
if (
|
|
76481
|
-
|
|
76482
|
-
|
|
76483
|
-
|
|
76484
|
-
|
|
76492
|
+
if (!isErrorType(targetType)) {
|
|
76493
|
+
addLazyDiagnostic(function () {
|
|
76494
|
+
var widenedType = getWidenedType(exprType);
|
|
76495
|
+
if (!isTypeComparableTo(targetType, widenedType)) {
|
|
76496
|
+
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);
|
|
76497
|
+
}
|
|
76498
|
+
});
|
|
76485
76499
|
}
|
|
76486
76500
|
return targetType;
|
|
76487
76501
|
}
|
|
@@ -77241,47 +77255,48 @@ var ts;
|
|
|
77241
77255
|
* @param returnType - return type of the function, can be undefined if return type is not explicitly specified
|
|
77242
77256
|
*/
|
|
77243
77257
|
function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func, returnType) {
|
|
77244
|
-
|
|
77245
|
-
|
|
77246
|
-
|
|
77247
|
-
|
|
77248
|
-
|
|
77249
|
-
|
|
77250
|
-
|
|
77251
|
-
|
|
77252
|
-
|
|
77253
|
-
|
|
77254
|
-
|
|
77255
|
-
|
|
77256
|
-
|
|
77257
|
-
|
|
77258
|
-
|
|
77259
|
-
|
|
77260
|
-
|
|
77261
|
-
|
|
77262
|
-
|
|
77263
|
-
|
|
77264
|
-
|
|
77265
|
-
|
|
77266
|
-
|
|
77267
|
-
|
|
77268
|
-
|
|
77269
|
-
|
|
77270
|
-
|
|
77271
|
-
|
|
77272
|
-
|
|
77273
|
-
|
|
77274
|
-
|
|
77275
|
-
|
|
77276
|
-
|
|
77277
|
-
|
|
77278
|
-
|
|
77279
|
-
|
|
77280
|
-
|
|
77281
|
-
|
|
77258
|
+
addLazyDiagnostic(checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics);
|
|
77259
|
+
return;
|
|
77260
|
+
function checkAllCodePathsInNonVoidFunctionReturnOrThrowDiagnostics() {
|
|
77261
|
+
var functionFlags = ts.getFunctionFlags(func);
|
|
77262
|
+
var type = returnType && unwrapReturnType(returnType, functionFlags);
|
|
77263
|
+
// Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
|
|
77264
|
+
if (type && maybeTypeOfKind(type, 1 /* Any */ | 16384 /* Void */)) {
|
|
77265
|
+
return;
|
|
77266
|
+
}
|
|
77267
|
+
// If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check.
|
|
77268
|
+
// also if HasImplicitReturn flag is not set this means that all codepaths in function body end with return or throw
|
|
77269
|
+
if (func.kind === 168 /* MethodSignature */ || ts.nodeIsMissing(func.body) || func.body.kind !== 235 /* Block */ || !functionHasImplicitReturn(func)) {
|
|
77270
|
+
return;
|
|
77271
|
+
}
|
|
77272
|
+
var hasExplicitReturn = func.flags & 512 /* HasExplicitReturn */;
|
|
77273
|
+
var errorNode = ts.getEffectiveReturnTypeNode(func) || func;
|
|
77274
|
+
if (type && type.flags & 131072 /* Never */) {
|
|
77275
|
+
error(errorNode, ts.Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
|
|
77276
|
+
}
|
|
77277
|
+
else if (type && !hasExplicitReturn) {
|
|
77278
|
+
// minimal check: function has syntactic return type annotation and no explicit return statements in the body
|
|
77279
|
+
// this function does not conform to the specification.
|
|
77280
|
+
error(errorNode, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
|
|
77281
|
+
}
|
|
77282
|
+
else if (type && strictNullChecks && !isTypeAssignableTo(undefinedType, type)) {
|
|
77283
|
+
error(errorNode, ts.Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined);
|
|
77284
|
+
}
|
|
77285
|
+
else if (compilerOptions.noImplicitReturns) {
|
|
77286
|
+
if (!type) {
|
|
77287
|
+
// If return type annotation is omitted check if function has any explicit return statements.
|
|
77288
|
+
// If it does not have any - its inferred return type is void - don't do any checks.
|
|
77289
|
+
// Otherwise get inferred return type from function body and report error only if it is not void / anytype
|
|
77290
|
+
if (!hasExplicitReturn) {
|
|
77291
|
+
return;
|
|
77292
|
+
}
|
|
77293
|
+
var inferredReturnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
|
|
77294
|
+
if (isUnwrappedReturnTypeVoidOrAny(func, inferredReturnType)) {
|
|
77295
|
+
return;
|
|
77296
|
+
}
|
|
77282
77297
|
}
|
|
77298
|
+
error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
|
|
77283
77299
|
}
|
|
77284
|
-
error(errorNode, ts.Diagnostics.Not_all_code_paths_return_a_value);
|
|
77285
77300
|
}
|
|
77286
77301
|
}
|
|
77287
77302
|
function checkFunctionExpressionOrObjectLiteralMethod(node, checkMode) {
|
|
@@ -77541,49 +77556,50 @@ var ts;
|
|
|
77541
77556
|
checkExpression(node.expression);
|
|
77542
77557
|
return undefinedWideningType;
|
|
77543
77558
|
}
|
|
77544
|
-
function
|
|
77559
|
+
function checkAwaitExpressionGrammar(node) {
|
|
77545
77560
|
// Grammar checking
|
|
77546
|
-
|
|
77547
|
-
|
|
77548
|
-
|
|
77549
|
-
|
|
77550
|
-
|
|
77551
|
-
|
|
77552
|
-
|
|
77553
|
-
|
|
77554
|
-
|
|
77555
|
-
|
|
77556
|
-
if (!
|
|
77557
|
-
if (!span)
|
|
77558
|
-
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77559
|
-
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);
|
|
77560
|
-
diagnostics.add(diagnostic);
|
|
77561
|
-
}
|
|
77562
|
-
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 */) {
|
|
77561
|
+
var container = ts.getContainingFunctionOrClassStaticBlock(node);
|
|
77562
|
+
if (container && ts.isClassStaticBlockDeclaration(container)) {
|
|
77563
|
+
error(node, ts.Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block);
|
|
77564
|
+
}
|
|
77565
|
+
else if (!(node.flags & 32768 /* AwaitContext */)) {
|
|
77566
|
+
if (ts.isInTopLevelContext(node)) {
|
|
77567
|
+
var sourceFile = ts.getSourceFileOfNode(node);
|
|
77568
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
77569
|
+
var span = void 0;
|
|
77570
|
+
if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
|
|
77571
|
+
if (!span)
|
|
77563
77572
|
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77564
|
-
|
|
77565
|
-
|
|
77566
|
-
}
|
|
77573
|
+
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);
|
|
77574
|
+
diagnostics.add(diagnostic);
|
|
77567
77575
|
}
|
|
77568
|
-
|
|
77569
|
-
|
|
77570
|
-
|
|
77571
|
-
var sourceFile = ts.getSourceFileOfNode(node);
|
|
77572
|
-
if (!hasParseDiagnostics(sourceFile)) {
|
|
77573
|
-
var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77574
|
-
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);
|
|
77575
|
-
if (container && container.kind !== 171 /* Constructor */ && (ts.getFunctionFlags(container) & 2 /* Async */) === 0) {
|
|
77576
|
-
var relatedInfo = ts.createDiagnosticForNode(container, ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async);
|
|
77577
|
-
ts.addRelatedInfo(diagnostic, relatedInfo);
|
|
77578
|
-
}
|
|
77576
|
+
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 */) {
|
|
77577
|
+
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77578
|
+
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);
|
|
77579
77579
|
diagnostics.add(diagnostic);
|
|
77580
77580
|
}
|
|
77581
77581
|
}
|
|
77582
77582
|
}
|
|
77583
|
-
|
|
77584
|
-
|
|
77583
|
+
else {
|
|
77584
|
+
// use of 'await' in non-async function
|
|
77585
|
+
var sourceFile = ts.getSourceFileOfNode(node);
|
|
77586
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
77587
|
+
var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
77588
|
+
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);
|
|
77589
|
+
if (container && container.kind !== 171 /* Constructor */ && (ts.getFunctionFlags(container) & 2 /* Async */) === 0) {
|
|
77590
|
+
var relatedInfo = ts.createDiagnosticForNode(container, ts.Diagnostics.Did_you_mean_to_mark_this_function_as_async);
|
|
77591
|
+
ts.addRelatedInfo(diagnostic, relatedInfo);
|
|
77592
|
+
}
|
|
77593
|
+
diagnostics.add(diagnostic);
|
|
77594
|
+
}
|
|
77585
77595
|
}
|
|
77586
77596
|
}
|
|
77597
|
+
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
|
77598
|
+
error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
|
|
77599
|
+
}
|
|
77600
|
+
}
|
|
77601
|
+
function checkAwaitExpression(node) {
|
|
77602
|
+
addLazyDiagnostic(function () { return checkAwaitExpressionGrammar(node); });
|
|
77587
77603
|
var operandType = checkExpression(node.expression);
|
|
77588
77604
|
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);
|
|
77589
77605
|
if (awaitedType === operandType && !isErrorType(awaitedType) && !(operandType.flags & 3 /* AnyOrUnknown */)) {
|
|
@@ -78407,7 +78423,10 @@ var ts;
|
|
|
78407
78423
|
}
|
|
78408
78424
|
}
|
|
78409
78425
|
function checkAssignmentOperator(valueType) {
|
|
78410
|
-
if (
|
|
78426
|
+
if (ts.isAssignmentOperator(operator)) {
|
|
78427
|
+
addLazyDiagnostic(checkAssignmentOperatorWorker);
|
|
78428
|
+
}
|
|
78429
|
+
function checkAssignmentOperatorWorker() {
|
|
78411
78430
|
// TypeScript 1.0 spec (April 2014): 4.17
|
|
78412
78431
|
// An assignment of the form
|
|
78413
78432
|
// VarExpr = ValueExpr
|
|
@@ -78506,15 +78525,7 @@ var ts;
|
|
|
78506
78525
|
return [effectiveLeft, effectiveRight];
|
|
78507
78526
|
}
|
|
78508
78527
|
function checkYieldExpression(node) {
|
|
78509
|
-
|
|
78510
|
-
if (produceDiagnostics) {
|
|
78511
|
-
if (!(node.flags & 8192 /* YieldContext */)) {
|
|
78512
|
-
grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
|
|
78513
|
-
}
|
|
78514
|
-
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
|
78515
|
-
error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
|
|
78516
|
-
}
|
|
78517
|
-
}
|
|
78528
|
+
addLazyDiagnostic(checkYieldExpressionGrammar);
|
|
78518
78529
|
var func = ts.getContainingFunction(node);
|
|
78519
78530
|
if (!func)
|
|
78520
78531
|
return anyType;
|
|
@@ -78560,14 +78571,24 @@ var ts;
|
|
|
78560
78571
|
var type = getContextualIterationType(2 /* Next */, func);
|
|
78561
78572
|
if (!type) {
|
|
78562
78573
|
type = anyType;
|
|
78563
|
-
|
|
78564
|
-
|
|
78565
|
-
|
|
78566
|
-
|
|
78574
|
+
addLazyDiagnostic(function () {
|
|
78575
|
+
if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
|
|
78576
|
+
var contextualType = getContextualType(node);
|
|
78577
|
+
if (!contextualType || isTypeAny(contextualType)) {
|
|
78578
|
+
error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
|
|
78579
|
+
}
|
|
78567
78580
|
}
|
|
78568
|
-
}
|
|
78581
|
+
});
|
|
78569
78582
|
}
|
|
78570
78583
|
return type;
|
|
78584
|
+
function checkYieldExpressionGrammar() {
|
|
78585
|
+
if (!(node.flags & 8192 /* YieldContext */)) {
|
|
78586
|
+
grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
|
|
78587
|
+
}
|
|
78588
|
+
if (isInParameterInitializerBeforeContainingFunction(node)) {
|
|
78589
|
+
error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
|
|
78590
|
+
}
|
|
78591
|
+
}
|
|
78571
78592
|
}
|
|
78572
78593
|
function checkConditionalExpression(node, checkMode) {
|
|
78573
78594
|
checkTruthinessExpression(node.condition);
|
|
@@ -79163,9 +79184,7 @@ var ts;
|
|
|
79163
79184
|
varianceTypeParameter = saveVarianceTypeParameter;
|
|
79164
79185
|
}
|
|
79165
79186
|
}
|
|
79166
|
-
|
|
79167
|
-
checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
|
|
79168
|
-
}
|
|
79187
|
+
addLazyDiagnostic(function () { return checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); });
|
|
79169
79188
|
}
|
|
79170
79189
|
function checkParameter(node) {
|
|
79171
79190
|
// Grammar checking
|
|
@@ -79319,7 +79338,8 @@ var ts;
|
|
|
79319
79338
|
if (node.type) {
|
|
79320
79339
|
checkSourceElement(node.type);
|
|
79321
79340
|
}
|
|
79322
|
-
|
|
79341
|
+
addLazyDiagnostic(checkSignatureDeclarationDiagnostics);
|
|
79342
|
+
function checkSignatureDeclarationDiagnostics() {
|
|
79323
79343
|
checkCollisionWithArgumentsInGeneratedCode(node);
|
|
79324
79344
|
var returnTypeNode = ts.getEffectiveReturnTypeNode(node);
|
|
79325
79345
|
if (noImplicitAny && !returnTypeNode) {
|
|
@@ -79609,9 +79629,8 @@ var ts;
|
|
|
79609
79629
|
if (ts.nodeIsMissing(node.body)) {
|
|
79610
79630
|
return;
|
|
79611
79631
|
}
|
|
79612
|
-
|
|
79613
|
-
|
|
79614
|
-
}
|
|
79632
|
+
addLazyDiagnostic(checkConstructorDeclarationDiagnostics);
|
|
79633
|
+
return;
|
|
79615
79634
|
function isInstancePropertyWithInitializerOrPrivateIdentifierProperty(n) {
|
|
79616
79635
|
if (ts.isPrivateIdentifierClassElementDeclaration(n)) {
|
|
79617
79636
|
return true;
|
|
@@ -79620,54 +79639,56 @@ var ts;
|
|
|
79620
79639
|
!ts.isStatic(n) &&
|
|
79621
79640
|
!!n.initializer;
|
|
79622
79641
|
}
|
|
79623
|
-
|
|
79624
|
-
|
|
79625
|
-
|
|
79626
|
-
|
|
79627
|
-
|
|
79628
|
-
|
|
79629
|
-
|
|
79630
|
-
|
|
79631
|
-
|
|
79632
|
-
if (
|
|
79633
|
-
|
|
79634
|
-
|
|
79635
|
-
|
|
79636
|
-
|
|
79637
|
-
|
|
79638
|
-
|
|
79639
|
-
|
|
79640
|
-
(ts.
|
|
79641
|
-
ts.some(node.
|
|
79642
|
-
|
|
79643
|
-
|
|
79644
|
-
// See GH #8277
|
|
79645
|
-
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
79646
|
-
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);
|
|
79647
|
-
}
|
|
79648
|
-
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
79649
|
-
else {
|
|
79650
|
-
var superCallStatement = void 0;
|
|
79651
|
-
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
79652
|
-
var statement = _a[_i];
|
|
79653
|
-
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
79654
|
-
superCallStatement = statement;
|
|
79655
|
-
break;
|
|
79656
|
-
}
|
|
79657
|
-
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
79658
|
-
break;
|
|
79659
|
-
}
|
|
79660
|
-
}
|
|
79642
|
+
function checkConstructorDeclarationDiagnostics() {
|
|
79643
|
+
// TS 1.0 spec (April 2014): 8.3.2
|
|
79644
|
+
// Constructors of classes with no extends clause may not contain super calls, whereas
|
|
79645
|
+
// constructors of derived classes must contain at least one super call somewhere in their function body.
|
|
79646
|
+
var containingClassDecl = node.parent;
|
|
79647
|
+
if (ts.getClassExtendsHeritageElement(containingClassDecl)) {
|
|
79648
|
+
captureLexicalThis(node.parent, containingClassDecl);
|
|
79649
|
+
var classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
|
|
79650
|
+
var superCall = findFirstSuperCall(node.body);
|
|
79651
|
+
if (superCall) {
|
|
79652
|
+
if (classExtendsNull) {
|
|
79653
|
+
error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
|
|
79654
|
+
}
|
|
79655
|
+
// A super call must be root-level in a constructor if both of the following are true:
|
|
79656
|
+
// - The containing class is a derived class.
|
|
79657
|
+
// - The constructor declares parameter properties
|
|
79658
|
+
// or the containing class declares instance member variables with initializers.
|
|
79659
|
+
var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
|
|
79660
|
+
(ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
|
|
79661
|
+
ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
|
|
79662
|
+
if (superCallShouldBeRootLevel) {
|
|
79661
79663
|
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
79662
79664
|
// See GH #8277
|
|
79663
|
-
if (
|
|
79664
|
-
error(
|
|
79665
|
+
if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
|
|
79666
|
+
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);
|
|
79667
|
+
}
|
|
79668
|
+
// Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
|
|
79669
|
+
else {
|
|
79670
|
+
var superCallStatement = void 0;
|
|
79671
|
+
for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
|
|
79672
|
+
var statement = _a[_i];
|
|
79673
|
+
if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
|
|
79674
|
+
superCallStatement = statement;
|
|
79675
|
+
break;
|
|
79676
|
+
}
|
|
79677
|
+
if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
|
|
79678
|
+
break;
|
|
79679
|
+
}
|
|
79680
|
+
}
|
|
79681
|
+
// Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
|
|
79682
|
+
// See GH #8277
|
|
79683
|
+
if (superCallStatement === undefined) {
|
|
79684
|
+
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);
|
|
79685
|
+
}
|
|
79665
79686
|
}
|
|
79666
79687
|
}
|
|
79667
79688
|
}
|
|
79668
|
-
|
|
79669
|
-
|
|
79670
|
-
|
|
79689
|
+
else if (!classExtendsNull) {
|
|
79690
|
+
error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
|
|
79691
|
+
}
|
|
79671
79692
|
}
|
|
79672
79693
|
}
|
|
79673
79694
|
}
|
|
@@ -79685,7 +79706,10 @@ var ts;
|
|
|
79685
79706
|
return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
|
|
79686
79707
|
}
|
|
79687
79708
|
function checkAccessorDeclaration(node) {
|
|
79688
|
-
|
|
79709
|
+
addLazyDiagnostic(checkAccessorDeclarationDiagnostics);
|
|
79710
|
+
checkSourceElement(node.body);
|
|
79711
|
+
setNodeLinksForPrivateIdentifierScope(node);
|
|
79712
|
+
function checkAccessorDeclarationDiagnostics() {
|
|
79689
79713
|
// Grammar checking accessors
|
|
79690
79714
|
if (!checkGrammarFunctionLikeDeclaration(node) && !checkGrammarAccessor(node))
|
|
79691
79715
|
checkGrammarComputedPropertyName(node.name);
|
|
@@ -79735,8 +79759,6 @@ var ts;
|
|
|
79735
79759
|
checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnType);
|
|
79736
79760
|
}
|
|
79737
79761
|
}
|
|
79738
|
-
checkSourceElement(node.body);
|
|
79739
|
-
setNodeLinksForPrivateIdentifierScope(node);
|
|
79740
79762
|
}
|
|
79741
79763
|
function checkMissingDeclaration(node) {
|
|
79742
79764
|
checkDecorators(node);
|
|
@@ -79779,11 +79801,13 @@ var ts;
|
|
|
79779
79801
|
ts.forEach(node.typeArguments, checkSourceElement);
|
|
79780
79802
|
var type = getTypeFromTypeReference(node);
|
|
79781
79803
|
if (!isErrorType(type)) {
|
|
79782
|
-
if (node.typeArguments
|
|
79783
|
-
|
|
79784
|
-
|
|
79785
|
-
|
|
79786
|
-
|
|
79804
|
+
if (node.typeArguments) {
|
|
79805
|
+
addLazyDiagnostic(function () {
|
|
79806
|
+
var typeParameters = getTypeParametersForTypeReference(node);
|
|
79807
|
+
if (typeParameters) {
|
|
79808
|
+
checkTypeArgumentConstraints(node, typeParameters);
|
|
79809
|
+
}
|
|
79810
|
+
});
|
|
79787
79811
|
}
|
|
79788
79812
|
var symbol = getNodeLinks(node).resolvedSymbol;
|
|
79789
79813
|
if (symbol) {
|
|
@@ -79811,7 +79835,8 @@ var ts;
|
|
|
79811
79835
|
}
|
|
79812
79836
|
function checkTypeLiteral(node) {
|
|
79813
79837
|
ts.forEach(node.members, checkSourceElement);
|
|
79814
|
-
|
|
79838
|
+
addLazyDiagnostic(checkTypeLiteralDiagnostics);
|
|
79839
|
+
function checkTypeLiteralDiagnostics() {
|
|
79815
79840
|
var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
|
|
79816
79841
|
checkIndexConstraints(type, type.symbol);
|
|
79817
79842
|
checkTypeForDuplicateIndexSignatures(node);
|
|
@@ -80002,9 +80027,9 @@ var ts;
|
|
|
80002
80027
|
return flags & flagsToCheck;
|
|
80003
80028
|
}
|
|
80004
80029
|
function checkFunctionOrConstructorSymbol(symbol) {
|
|
80005
|
-
|
|
80006
|
-
|
|
80007
|
-
|
|
80030
|
+
addLazyDiagnostic(function () { return checkFunctionOrConstructorSymbolWorker(symbol); });
|
|
80031
|
+
}
|
|
80032
|
+
function checkFunctionOrConstructorSymbolWorker(symbol) {
|
|
80008
80033
|
function getCanonicalOverload(overloads, implementation) {
|
|
80009
80034
|
// Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
|
|
80010
80035
|
// Error on all deviations from this canonical set of flags
|
|
@@ -80225,9 +80250,9 @@ var ts;
|
|
|
80225
80250
|
}
|
|
80226
80251
|
}
|
|
80227
80252
|
function checkExportsOnMergedDeclarations(node) {
|
|
80228
|
-
|
|
80229
|
-
|
|
80230
|
-
|
|
80253
|
+
addLazyDiagnostic(function () { return checkExportsOnMergedDeclarationsWorker(node); });
|
|
80254
|
+
}
|
|
80255
|
+
function checkExportsOnMergedDeclarationsWorker(node) {
|
|
80231
80256
|
// if localSymbol is defined on node then node itself is exported - check is required
|
|
80232
80257
|
var symbol = node.localSymbol;
|
|
80233
80258
|
if (!symbol) {
|
|
@@ -80871,7 +80896,8 @@ var ts;
|
|
|
80871
80896
|
ts.forEach(node.decorators, checkDecorator);
|
|
80872
80897
|
}
|
|
80873
80898
|
function checkFunctionDeclaration(node) {
|
|
80874
|
-
|
|
80899
|
+
addLazyDiagnostic(checkFunctionDeclarationDiagnostics);
|
|
80900
|
+
function checkFunctionDeclarationDiagnostics() {
|
|
80875
80901
|
checkFunctionOrMethodDeclaration(node);
|
|
80876
80902
|
checkGrammarForGenerator(node);
|
|
80877
80903
|
checkCollisionsForDeclarationName(node, node.name);
|
|
@@ -80905,10 +80931,13 @@ var ts;
|
|
|
80905
80931
|
checkSourceElement(node.typeExpression);
|
|
80906
80932
|
}
|
|
80907
80933
|
function checkJSDocFunctionType(node) {
|
|
80908
|
-
|
|
80909
|
-
reportImplicitAny(node, anyType);
|
|
80910
|
-
}
|
|
80934
|
+
addLazyDiagnostic(checkJSDocFunctionTypeImplicitAny);
|
|
80911
80935
|
checkSignatureDeclaration(node);
|
|
80936
|
+
function checkJSDocFunctionTypeImplicitAny() {
|
|
80937
|
+
if (!node.type && !ts.isJSDocConstructSignature(node)) {
|
|
80938
|
+
reportImplicitAny(node, anyType);
|
|
80939
|
+
}
|
|
80940
|
+
}
|
|
80912
80941
|
}
|
|
80913
80942
|
function checkJSDocImplementsTag(node) {
|
|
80914
80943
|
var classLike = ts.getEffectiveJSDocHost(node);
|
|
@@ -80989,19 +81018,7 @@ var ts;
|
|
|
80989
81018
|
var body = node.kind === 168 /* MethodSignature */ ? undefined : node.body;
|
|
80990
81019
|
checkSourceElement(body);
|
|
80991
81020
|
checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, getReturnTypeFromAnnotation(node));
|
|
80992
|
-
|
|
80993
|
-
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
|
|
80994
|
-
// in an ambient context
|
|
80995
|
-
if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) {
|
|
80996
|
-
reportImplicitAny(node, anyType);
|
|
80997
|
-
}
|
|
80998
|
-
if (functionFlags & 1 /* Generator */ && ts.nodeIsPresent(body)) {
|
|
80999
|
-
// A generator with a body and no type annotation can still cause errors. It can error if the
|
|
81000
|
-
// yielded values have no common supertype, or it can give an implicit any error if it has no
|
|
81001
|
-
// yielded values. The only way to trigger these errors is to try checking its return type.
|
|
81002
|
-
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
|
|
81003
|
-
}
|
|
81004
|
-
}
|
|
81021
|
+
addLazyDiagnostic(checkFunctionOrMethodDeclarationDiagnostics);
|
|
81005
81022
|
// A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature
|
|
81006
81023
|
if (ts.isInJSFile(node)) {
|
|
81007
81024
|
var typeTag = ts.getJSDocTypeTag(node);
|
|
@@ -81009,10 +81026,26 @@ var ts;
|
|
|
81009
81026
|
error(typeTag.typeExpression.type, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature);
|
|
81010
81027
|
}
|
|
81011
81028
|
}
|
|
81029
|
+
function checkFunctionOrMethodDeclarationDiagnostics() {
|
|
81030
|
+
if (!ts.getEffectiveReturnTypeNode(node)) {
|
|
81031
|
+
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
|
|
81032
|
+
// in an ambient context
|
|
81033
|
+
if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) {
|
|
81034
|
+
reportImplicitAny(node, anyType);
|
|
81035
|
+
}
|
|
81036
|
+
if (functionFlags & 1 /* Generator */ && ts.nodeIsPresent(body)) {
|
|
81037
|
+
// A generator with a body and no type annotation can still cause errors. It can error if the
|
|
81038
|
+
// yielded values have no common supertype, or it can give an implicit any error if it has no
|
|
81039
|
+
// yielded values. The only way to trigger these errors is to try checking its return type.
|
|
81040
|
+
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
|
|
81041
|
+
}
|
|
81042
|
+
}
|
|
81043
|
+
}
|
|
81012
81044
|
}
|
|
81013
81045
|
function registerForUnusedIdentifiersCheck(node) {
|
|
81014
|
-
|
|
81015
|
-
|
|
81046
|
+
addLazyDiagnostic(registerForUnusedIdentifiersCheckDiagnostics);
|
|
81047
|
+
function registerForUnusedIdentifiersCheckDiagnostics() {
|
|
81048
|
+
// May be in a call such as getTypeOfNode that happened to call this. But potentiallyUnusedIdentifiers is only defined in the scope of `checkSourceFile`.
|
|
81016
81049
|
var sourceFile = ts.getSourceFileOfNode(node);
|
|
81017
81050
|
var potentiallyUnusedIdentifiers = allPotentiallyUnusedIdentifiers.get(sourceFile.path);
|
|
81018
81051
|
if (!potentiallyUnusedIdentifiers) {
|
|
@@ -82786,26 +82819,31 @@ var ts;
|
|
|
82786
82819
|
hasDuplicateDefaultClause = true;
|
|
82787
82820
|
}
|
|
82788
82821
|
}
|
|
82789
|
-
if (
|
|
82790
|
-
|
|
82791
|
-
// In a 'switch' statement, each 'case' expression must be of a type that is comparable
|
|
82792
|
-
// to or from the type of the 'switch' expression.
|
|
82793
|
-
var caseType = checkExpression(clause.expression);
|
|
82794
|
-
var caseIsLiteral = isLiteralType(caseType);
|
|
82795
|
-
var comparedExpressionType = expressionType;
|
|
82796
|
-
if (!caseIsLiteral || !expressionIsLiteral) {
|
|
82797
|
-
caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
|
|
82798
|
-
comparedExpressionType = getBaseTypeOfLiteralType(expressionType);
|
|
82799
|
-
}
|
|
82800
|
-
if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) {
|
|
82801
|
-
// expressionType is not comparable to caseType, try the reversed check and report errors if it fails
|
|
82802
|
-
checkTypeComparableTo(caseType, comparedExpressionType, clause.expression, /*headMessage*/ undefined);
|
|
82803
|
-
}
|
|
82822
|
+
if (clause.kind === 289 /* CaseClause */) {
|
|
82823
|
+
addLazyDiagnostic(createLazyCaseClauseDiagnostics(clause));
|
|
82804
82824
|
}
|
|
82805
82825
|
ts.forEach(clause.statements, checkSourceElement);
|
|
82806
82826
|
if (compilerOptions.noFallthroughCasesInSwitch && clause.fallthroughFlowNode && isReachableFlowNode(clause.fallthroughFlowNode)) {
|
|
82807
82827
|
error(clause, ts.Diagnostics.Fallthrough_case_in_switch);
|
|
82808
82828
|
}
|
|
82829
|
+
function createLazyCaseClauseDiagnostics(clause) {
|
|
82830
|
+
return function () {
|
|
82831
|
+
// TypeScript 1.0 spec (April 2014): 5.9
|
|
82832
|
+
// In a 'switch' statement, each 'case' expression must be of a type that is comparable
|
|
82833
|
+
// to or from the type of the 'switch' expression.
|
|
82834
|
+
var caseType = checkExpression(clause.expression);
|
|
82835
|
+
var caseIsLiteral = isLiteralType(caseType);
|
|
82836
|
+
var comparedExpressionType = expressionType;
|
|
82837
|
+
if (!caseIsLiteral || !expressionIsLiteral) {
|
|
82838
|
+
caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType;
|
|
82839
|
+
comparedExpressionType = getBaseTypeOfLiteralType(expressionType);
|
|
82840
|
+
}
|
|
82841
|
+
if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) {
|
|
82842
|
+
// expressionType is not comparable to caseType, try the reversed check and report errors if it fails
|
|
82843
|
+
checkTypeComparableTo(caseType, comparedExpressionType, clause.expression, /*headMessage*/ undefined);
|
|
82844
|
+
}
|
|
82845
|
+
};
|
|
82846
|
+
}
|
|
82809
82847
|
});
|
|
82810
82848
|
if (node.caseBlock.locals) {
|
|
82811
82849
|
registerForUnusedIdentifiersCheck(node.caseBlock);
|
|
@@ -83026,26 +83064,29 @@ var ts;
|
|
|
83026
83064
|
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
|
|
83027
83065
|
*/
|
|
83028
83066
|
function checkTypeParameters(typeParameterDeclarations) {
|
|
83067
|
+
var seenDefault = false;
|
|
83029
83068
|
if (typeParameterDeclarations) {
|
|
83030
|
-
var seenDefault = false;
|
|
83031
83069
|
for (var i = 0; i < typeParameterDeclarations.length; i++) {
|
|
83032
83070
|
var node = typeParameterDeclarations[i];
|
|
83033
83071
|
checkTypeParameter(node);
|
|
83034
|
-
|
|
83035
|
-
|
|
83036
|
-
|
|
83037
|
-
|
|
83038
|
-
|
|
83039
|
-
|
|
83040
|
-
|
|
83041
|
-
|
|
83042
|
-
|
|
83043
|
-
|
|
83044
|
-
|
|
83045
|
-
|
|
83072
|
+
addLazyDiagnostic(createCheckTypeParameterDiagnostic(node, i));
|
|
83073
|
+
}
|
|
83074
|
+
}
|
|
83075
|
+
function createCheckTypeParameterDiagnostic(node, i) {
|
|
83076
|
+
return function () {
|
|
83077
|
+
if (node.default) {
|
|
83078
|
+
seenDefault = true;
|
|
83079
|
+
checkTypeParametersNotReferenced(node.default, typeParameterDeclarations, i);
|
|
83080
|
+
}
|
|
83081
|
+
else if (seenDefault) {
|
|
83082
|
+
error(node, ts.Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters);
|
|
83083
|
+
}
|
|
83084
|
+
for (var j = 0; j < i; j++) {
|
|
83085
|
+
if (typeParameterDeclarations[j].symbol === node.symbol) {
|
|
83086
|
+
error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
|
|
83046
83087
|
}
|
|
83047
83088
|
}
|
|
83048
|
-
}
|
|
83089
|
+
};
|
|
83049
83090
|
}
|
|
83050
83091
|
}
|
|
83051
83092
|
/** Check that type parameter defaults only reference previously declared type parameters */
|
|
@@ -83177,85 +83218,90 @@ var ts;
|
|
|
83177
83218
|
if (extendsNode && extendsNode !== baseTypeNode) {
|
|
83178
83219
|
checkExpression(extendsNode.expression);
|
|
83179
83220
|
}
|
|
83180
|
-
var
|
|
83181
|
-
if (
|
|
83182
|
-
|
|
83183
|
-
|
|
83184
|
-
|
|
83185
|
-
|
|
83186
|
-
|
|
83187
|
-
|
|
83188
|
-
ts.
|
|
83189
|
-
|
|
83190
|
-
var
|
|
83191
|
-
|
|
83192
|
-
|
|
83221
|
+
var baseTypes_2 = getBaseTypes(type);
|
|
83222
|
+
if (baseTypes_2.length) {
|
|
83223
|
+
addLazyDiagnostic(function () {
|
|
83224
|
+
var baseType = baseTypes_2[0];
|
|
83225
|
+
var baseConstructorType = getBaseConstructorTypeOfClass(type);
|
|
83226
|
+
var staticBaseType = getApparentType(baseConstructorType);
|
|
83227
|
+
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
|
|
83228
|
+
checkSourceElement(baseTypeNode.expression);
|
|
83229
|
+
if (ts.some(baseTypeNode.typeArguments)) {
|
|
83230
|
+
ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
|
|
83231
|
+
for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode); _i < _a.length; _i++) {
|
|
83232
|
+
var constructor = _a[_i];
|
|
83233
|
+
if (!checkTypeArgumentConstraints(baseTypeNode, constructor.typeParameters)) {
|
|
83234
|
+
break;
|
|
83235
|
+
}
|
|
83193
83236
|
}
|
|
83194
83237
|
}
|
|
83195
|
-
|
|
83196
|
-
|
|
83197
|
-
|
|
83198
|
-
issueMemberSpecificError(node, typeWithThis, baseWithThis, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
|
|
83199
|
-
}
|
|
83200
|
-
else {
|
|
83201
|
-
// Report static side error only when instance type is assignable
|
|
83202
|
-
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
|
83203
|
-
}
|
|
83204
|
-
if (baseConstructorType.flags & 8650752 /* TypeVariable */) {
|
|
83205
|
-
if (!isMixinConstructorType(staticType)) {
|
|
83206
|
-
error(node.name || node, ts.Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
|
|
83238
|
+
var baseWithThis = getTypeWithThisArgument(baseType, type.thisType);
|
|
83239
|
+
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
|
|
83240
|
+
issueMemberSpecificError(node, typeWithThis, baseWithThis, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
|
|
83207
83241
|
}
|
|
83208
83242
|
else {
|
|
83209
|
-
|
|
83210
|
-
|
|
83211
|
-
|
|
83243
|
+
// Report static side error only when instance type is assignable
|
|
83244
|
+
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
|
83245
|
+
}
|
|
83246
|
+
if (baseConstructorType.flags & 8650752 /* TypeVariable */) {
|
|
83247
|
+
if (!isMixinConstructorType(staticType)) {
|
|
83248
|
+
error(node.name || node, ts.Diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any);
|
|
83249
|
+
}
|
|
83250
|
+
else {
|
|
83251
|
+
var constructSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */);
|
|
83252
|
+
if (constructSignatures.some(function (signature) { return signature.flags & 4 /* Abstract */; }) && !ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
|
|
83253
|
+
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);
|
|
83254
|
+
}
|
|
83212
83255
|
}
|
|
83213
83256
|
}
|
|
83214
|
-
|
|
83215
|
-
|
|
83216
|
-
|
|
83217
|
-
|
|
83218
|
-
|
|
83219
|
-
|
|
83220
|
-
|
|
83257
|
+
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */) && !(baseConstructorType.flags & 8650752 /* TypeVariable */)) {
|
|
83258
|
+
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
|
|
83259
|
+
// that all instantiated base constructor signatures return the same type.
|
|
83260
|
+
var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode);
|
|
83261
|
+
if (ts.forEach(constructors, function (sig) { return !isJSConstructor(sig.declaration) && !isTypeIdenticalTo(getReturnTypeOfSignature(sig), baseType); })) {
|
|
83262
|
+
error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
|
|
83263
|
+
}
|
|
83221
83264
|
}
|
|
83222
|
-
|
|
83223
|
-
|
|
83265
|
+
checkKindsOfPropertyMemberOverrides(type, baseType);
|
|
83266
|
+
});
|
|
83224
83267
|
}
|
|
83225
83268
|
}
|
|
83226
83269
|
checkMembersForOverrideModifier(node, type, typeWithThis, staticType);
|
|
83227
83270
|
var implementedTypeNodes = ts.getEffectiveImplementsTypeNodes(node);
|
|
83228
83271
|
if (implementedTypeNodes) {
|
|
83229
|
-
for (var
|
|
83230
|
-
var typeRefNode = implementedTypeNodes_1[
|
|
83272
|
+
for (var _i = 0, implementedTypeNodes_1 = implementedTypeNodes; _i < implementedTypeNodes_1.length; _i++) {
|
|
83273
|
+
var typeRefNode = implementedTypeNodes_1[_i];
|
|
83231
83274
|
if (!ts.isEntityNameExpression(typeRefNode.expression) || ts.isOptionalChain(typeRefNode.expression)) {
|
|
83232
83275
|
error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
|
83233
83276
|
}
|
|
83234
83277
|
checkTypeReferenceNode(typeRefNode);
|
|
83235
|
-
|
|
83236
|
-
var t = getReducedType(getTypeFromTypeNode(typeRefNode));
|
|
83237
|
-
if (!isErrorType(t)) {
|
|
83238
|
-
if (isValidBaseType(t)) {
|
|
83239
|
-
var genericDiag = t.symbol && t.symbol.flags & 32 /* Class */ ?
|
|
83240
|
-
ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
|
|
83241
|
-
ts.Diagnostics.Class_0_incorrectly_implements_interface_1;
|
|
83242
|
-
var baseWithThis = getTypeWithThisArgument(t, type.thisType);
|
|
83243
|
-
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
|
|
83244
|
-
issueMemberSpecificError(node, typeWithThis, baseWithThis, genericDiag);
|
|
83245
|
-
}
|
|
83246
|
-
}
|
|
83247
|
-
else {
|
|
83248
|
-
error(typeRefNode, ts.Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
|
|
83249
|
-
}
|
|
83250
|
-
}
|
|
83251
|
-
}
|
|
83278
|
+
addLazyDiagnostic(createImplementsDiagnostics(typeRefNode));
|
|
83252
83279
|
}
|
|
83253
83280
|
}
|
|
83254
|
-
|
|
83281
|
+
addLazyDiagnostic(function () {
|
|
83255
83282
|
checkIndexConstraints(type, symbol);
|
|
83256
83283
|
checkIndexConstraints(staticType, symbol, /*isStaticIndex*/ true);
|
|
83257
83284
|
checkTypeForDuplicateIndexSignatures(node);
|
|
83258
83285
|
checkPropertyInitialization(node);
|
|
83286
|
+
});
|
|
83287
|
+
function createImplementsDiagnostics(typeRefNode) {
|
|
83288
|
+
return function () {
|
|
83289
|
+
var t = getReducedType(getTypeFromTypeNode(typeRefNode));
|
|
83290
|
+
if (!isErrorType(t)) {
|
|
83291
|
+
if (isValidBaseType(t)) {
|
|
83292
|
+
var genericDiag = t.symbol && t.symbol.flags & 32 /* Class */ ?
|
|
83293
|
+
ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
|
|
83294
|
+
ts.Diagnostics.Class_0_incorrectly_implements_interface_1;
|
|
83295
|
+
var baseWithThis = getTypeWithThisArgument(t, type.thisType);
|
|
83296
|
+
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
|
|
83297
|
+
issueMemberSpecificError(node, typeWithThis, baseWithThis, genericDiag);
|
|
83298
|
+
}
|
|
83299
|
+
}
|
|
83300
|
+
else {
|
|
83301
|
+
error(typeRefNode, ts.Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
|
|
83302
|
+
}
|
|
83303
|
+
}
|
|
83304
|
+
};
|
|
83259
83305
|
}
|
|
83260
83306
|
}
|
|
83261
83307
|
function checkMembersForOverrideModifier(node, type, typeWithThis, staticType) {
|
|
@@ -83579,8 +83625,8 @@ var ts;
|
|
|
83579
83625
|
ts.forEach(properties, function (p) {
|
|
83580
83626
|
seen.set(p.escapedName, p);
|
|
83581
83627
|
});
|
|
83582
|
-
for (var _i = 0,
|
|
83583
|
-
var base =
|
|
83628
|
+
for (var _i = 0, baseTypes_3 = baseTypes; _i < baseTypes_3.length; _i++) {
|
|
83629
|
+
var base = baseTypes_3[_i];
|
|
83584
83630
|
var properties_5 = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
|
|
83585
83631
|
for (var _a = 0, properties_4 = properties_5; _a < properties_4.length; _a++) {
|
|
83586
83632
|
var prop = properties_4[_a];
|
|
@@ -83602,8 +83648,8 @@ var ts;
|
|
|
83602
83648
|
seen.set(p.escapedName, { prop: p, containingType: type });
|
|
83603
83649
|
});
|
|
83604
83650
|
var ok = true;
|
|
83605
|
-
for (var _i = 0,
|
|
83606
|
-
var base =
|
|
83651
|
+
for (var _i = 0, baseTypes_4 = baseTypes; _i < baseTypes_4.length; _i++) {
|
|
83652
|
+
var base = baseTypes_4[_i];
|
|
83607
83653
|
var properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
|
|
83608
83654
|
for (var _a = 0, properties_6 = properties; _a < properties_6.length; _a++) {
|
|
83609
83655
|
var prop = properties_6[_a];
|
|
@@ -83687,7 +83733,7 @@ var ts;
|
|
|
83687
83733
|
if (!checkGrammarDecoratorsAndModifiers(node))
|
|
83688
83734
|
checkGrammarInterfaceDeclaration(node);
|
|
83689
83735
|
checkTypeParameters(node.typeParameters);
|
|
83690
|
-
|
|
83736
|
+
addLazyDiagnostic(function () {
|
|
83691
83737
|
checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
|
|
83692
83738
|
checkExportsOnMergedDeclarations(node);
|
|
83693
83739
|
var symbol = getSymbolOfNode(node);
|
|
@@ -83707,7 +83753,7 @@ var ts;
|
|
|
83707
83753
|
}
|
|
83708
83754
|
}
|
|
83709
83755
|
checkObjectTypeForDuplicateDeclarations(node);
|
|
83710
|
-
}
|
|
83756
|
+
});
|
|
83711
83757
|
ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
|
|
83712
83758
|
if (!ts.isEntityNameExpression(heritageElement.expression) || ts.isOptionalChain(heritageElement.expression)) {
|
|
83713
83759
|
error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
|
@@ -83715,10 +83761,10 @@ var ts;
|
|
|
83715
83761
|
checkTypeReferenceNode(heritageElement);
|
|
83716
83762
|
});
|
|
83717
83763
|
ts.forEach(node.members, checkSourceElement);
|
|
83718
|
-
|
|
83764
|
+
addLazyDiagnostic(function () {
|
|
83719
83765
|
checkTypeForDuplicateIndexSignatures(node);
|
|
83720
83766
|
registerForUnusedIdentifiersCheck(node);
|
|
83721
|
-
}
|
|
83767
|
+
});
|
|
83722
83768
|
}
|
|
83723
83769
|
function checkTypeAliasDeclaration(node) {
|
|
83724
83770
|
// Grammar checking
|
|
@@ -83907,9 +83953,9 @@ var ts;
|
|
|
83907
83953
|
ts.isStringLiteralLike(node.argumentExpression);
|
|
83908
83954
|
}
|
|
83909
83955
|
function checkEnumDeclaration(node) {
|
|
83910
|
-
|
|
83911
|
-
|
|
83912
|
-
|
|
83956
|
+
addLazyDiagnostic(function () { return checkEnumDeclarationWorker(node); });
|
|
83957
|
+
}
|
|
83958
|
+
function checkEnumDeclarationWorker(node) {
|
|
83913
83959
|
// Grammar checking
|
|
83914
83960
|
checkGrammarDecoratorsAndModifiers(node);
|
|
83915
83961
|
checkCollisionsForDeclarationName(node, node.name);
|
|
@@ -83989,7 +84035,14 @@ var ts;
|
|
|
83989
84035
|
}
|
|
83990
84036
|
}
|
|
83991
84037
|
function checkModuleDeclaration(node) {
|
|
83992
|
-
if (
|
|
84038
|
+
if (node.body) {
|
|
84039
|
+
checkSourceElement(node.body);
|
|
84040
|
+
if (!ts.isGlobalScopeAugmentation(node)) {
|
|
84041
|
+
registerForUnusedIdentifiersCheck(node);
|
|
84042
|
+
}
|
|
84043
|
+
}
|
|
84044
|
+
addLazyDiagnostic(checkModuleDeclarationDiagnostics);
|
|
84045
|
+
function checkModuleDeclarationDiagnostics() {
|
|
83993
84046
|
// Grammar checking
|
|
83994
84047
|
var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
|
|
83995
84048
|
var inAmbientContext = node.flags & 8388608 /* Ambient */;
|
|
@@ -84072,12 +84125,6 @@ var ts;
|
|
|
84072
84125
|
}
|
|
84073
84126
|
}
|
|
84074
84127
|
}
|
|
84075
|
-
if (node.body) {
|
|
84076
|
-
checkSourceElement(node.body);
|
|
84077
|
-
if (!ts.isGlobalScopeAugmentation(node)) {
|
|
84078
|
-
registerForUnusedIdentifiersCheck(node);
|
|
84079
|
-
}
|
|
84080
|
-
}
|
|
84081
84128
|
}
|
|
84082
84129
|
function checkModuleAugmentationElement(node, isGlobalAugmentation) {
|
|
84083
84130
|
var _a;
|
|
@@ -85014,13 +85061,16 @@ var ts;
|
|
|
85014
85061
|
if (ts.isExternalOrCommonJsModule(node)) {
|
|
85015
85062
|
registerForUnusedIdentifiersCheck(node);
|
|
85016
85063
|
}
|
|
85017
|
-
|
|
85018
|
-
|
|
85019
|
-
|
|
85020
|
-
|
|
85021
|
-
|
|
85022
|
-
|
|
85023
|
-
|
|
85064
|
+
addLazyDiagnostic(function () {
|
|
85065
|
+
// This relies on the results of other lazy diagnostics, so must be computed after them
|
|
85066
|
+
if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
|
|
85067
|
+
checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
|
|
85068
|
+
if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
|
|
85069
|
+
diagnostics.add(diag);
|
|
85070
|
+
}
|
|
85071
|
+
});
|
|
85072
|
+
}
|
|
85073
|
+
});
|
|
85024
85074
|
if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
|
|
85025
85075
|
!node.isDeclarationFile &&
|
|
85026
85076
|
ts.isExternalModule(node)) {
|
|
@@ -85060,15 +85110,35 @@ var ts;
|
|
|
85060
85110
|
cancellationToken = undefined;
|
|
85061
85111
|
}
|
|
85062
85112
|
}
|
|
85113
|
+
function ensurePendingDiagnosticWorkComplete() {
|
|
85114
|
+
// Invoke any existing lazy diagnostics to add them, clear the backlog of diagnostics
|
|
85115
|
+
for (var _i = 0, deferredDiagnosticsCallbacks_1 = deferredDiagnosticsCallbacks; _i < deferredDiagnosticsCallbacks_1.length; _i++) {
|
|
85116
|
+
var cb = deferredDiagnosticsCallbacks_1[_i];
|
|
85117
|
+
cb();
|
|
85118
|
+
}
|
|
85119
|
+
deferredDiagnosticsCallbacks = [];
|
|
85120
|
+
}
|
|
85121
|
+
function checkSourceFileWithEagerDiagnostics(sourceFile) {
|
|
85122
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85123
|
+
// then setup diagnostics for immediate invocation (as we are about to collect them, and
|
|
85124
|
+
// this avoids the overhead of longer-lived callbacks we don't need to allocate)
|
|
85125
|
+
// This also serves to make the shift to possibly lazy diagnostics transparent to serial command-line scenarios
|
|
85126
|
+
// (as in those cases, all the diagnostics will still be computed as the appropriate place in the tree,
|
|
85127
|
+
// thus much more likely retaining the same union ordering as before we had lazy diagnostics)
|
|
85128
|
+
var oldAddLazyDiagnostics = addLazyDiagnostic;
|
|
85129
|
+
addLazyDiagnostic = function (cb) { return cb(); };
|
|
85130
|
+
checkSourceFile(sourceFile);
|
|
85131
|
+
addLazyDiagnostic = oldAddLazyDiagnostics;
|
|
85132
|
+
}
|
|
85063
85133
|
function getDiagnosticsWorker(sourceFile) {
|
|
85064
|
-
throwIfNonDiagnosticsProducing();
|
|
85065
85134
|
if (sourceFile) {
|
|
85135
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85066
85136
|
// Some global diagnostics are deferred until they are needed and
|
|
85067
85137
|
// may not be reported in the first call to getGlobalDiagnostics.
|
|
85068
85138
|
// We should catch these changes and report them.
|
|
85069
85139
|
var previousGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
|
|
85070
85140
|
var previousGlobalDiagnosticsSize = previousGlobalDiagnostics.length;
|
|
85071
|
-
|
|
85141
|
+
checkSourceFileWithEagerDiagnostics(sourceFile);
|
|
85072
85142
|
var semanticDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
|
|
85073
85143
|
var currentGlobalDiagnostics = diagnostics.getGlobalDiagnostics();
|
|
85074
85144
|
if (currentGlobalDiagnostics !== previousGlobalDiagnostics) {
|
|
@@ -85086,18 +85156,13 @@ var ts;
|
|
|
85086
85156
|
}
|
|
85087
85157
|
// Global diagnostics are always added when a file is not provided to
|
|
85088
85158
|
// getDiagnostics
|
|
85089
|
-
ts.forEach(host.getSourceFiles(),
|
|
85159
|
+
ts.forEach(host.getSourceFiles(), checkSourceFileWithEagerDiagnostics);
|
|
85090
85160
|
return diagnostics.getDiagnostics();
|
|
85091
85161
|
}
|
|
85092
85162
|
function getGlobalDiagnostics() {
|
|
85093
|
-
|
|
85163
|
+
ensurePendingDiagnosticWorkComplete();
|
|
85094
85164
|
return diagnostics.getGlobalDiagnostics();
|
|
85095
85165
|
}
|
|
85096
|
-
function throwIfNonDiagnosticsProducing() {
|
|
85097
|
-
if (!produceDiagnostics) {
|
|
85098
|
-
throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
|
|
85099
|
-
}
|
|
85100
|
-
}
|
|
85101
85166
|
// Language service support
|
|
85102
85167
|
function getSymbolsInScope(location, meaning) {
|
|
85103
85168
|
if (location.flags & 16777216 /* InWithStatement */) {
|
|
@@ -115571,8 +115636,7 @@ var ts;
|
|
|
115571
115636
|
var files;
|
|
115572
115637
|
var symlinks;
|
|
115573
115638
|
var commonSourceDirectory;
|
|
115574
|
-
var
|
|
115575
|
-
var noDiagnosticsTypeChecker;
|
|
115639
|
+
var typeChecker;
|
|
115576
115640
|
var classifiableNames;
|
|
115577
115641
|
var ambientModuleNameToUnmodifiedFileName = new ts.Map();
|
|
115578
115642
|
var fileReasons = ts.createMultiMap();
|
|
@@ -115818,21 +115882,19 @@ var ts;
|
|
|
115818
115882
|
getProgramDiagnostics: getProgramDiagnostics,
|
|
115819
115883
|
getTypeChecker: getTypeChecker,
|
|
115820
115884
|
getClassifiableNames: getClassifiableNames,
|
|
115821
|
-
getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
|
|
115822
115885
|
getCommonSourceDirectory: getCommonSourceDirectory,
|
|
115823
115886
|
emit: emit,
|
|
115824
115887
|
getCurrentDirectory: function () { return currentDirectory; },
|
|
115825
|
-
getNodeCount: function () { return
|
|
115826
|
-
getIdentifierCount: function () { return
|
|
115827
|
-
getSymbolCount: function () { return
|
|
115828
|
-
getTypeCount: function () { return
|
|
115829
|
-
getInstantiationCount: function () { return
|
|
115830
|
-
getRelationCacheSizes: function () { return
|
|
115888
|
+
getNodeCount: function () { return getTypeChecker().getNodeCount(); },
|
|
115889
|
+
getIdentifierCount: function () { return getTypeChecker().getIdentifierCount(); },
|
|
115890
|
+
getSymbolCount: function () { return getTypeChecker().getSymbolCount(); },
|
|
115891
|
+
getTypeCount: function () { return getTypeChecker().getTypeCount(); },
|
|
115892
|
+
getInstantiationCount: function () { return getTypeChecker().getInstantiationCount(); },
|
|
115893
|
+
getRelationCacheSizes: function () { return getTypeChecker().getRelationCacheSizes(); },
|
|
115831
115894
|
getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; },
|
|
115832
115895
|
getResolvedTypeReferenceDirectives: function () { return resolvedTypeReferenceDirectives; },
|
|
115833
115896
|
isSourceFileFromExternalLibrary: isSourceFileFromExternalLibrary,
|
|
115834
115897
|
isSourceFileDefaultLibrary: isSourceFileDefaultLibrary,
|
|
115835
|
-
dropDiagnosticsProducingTypeChecker: dropDiagnosticsProducingTypeChecker,
|
|
115836
115898
|
getSourceFileFromReference: getSourceFileFromReference,
|
|
115837
115899
|
getLibFileFromReference: getLibFileFromReference,
|
|
115838
115900
|
sourceFileToPackageName: sourceFileToPackageName,
|
|
@@ -116421,14 +116483,8 @@ var ts;
|
|
|
116421
116483
|
return ts.some(options.lib, function (libFileName) { return equalityComparer(file.fileName, pathForLibFile(libFileName)); });
|
|
116422
116484
|
}
|
|
116423
116485
|
}
|
|
116424
|
-
function getDiagnosticsProducingTypeChecker() {
|
|
116425
|
-
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ true));
|
|
116426
|
-
}
|
|
116427
|
-
function dropDiagnosticsProducingTypeChecker() {
|
|
116428
|
-
diagnosticsProducingTypeChecker = undefined;
|
|
116429
|
-
}
|
|
116430
116486
|
function getTypeChecker() {
|
|
116431
|
-
return
|
|
116487
|
+
return typeChecker || (typeChecker = ts.createTypeChecker(program));
|
|
116432
116488
|
}
|
|
116433
116489
|
function emit(sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers, forceDtsEmit) {
|
|
116434
116490
|
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);
|
|
@@ -116453,7 +116509,7 @@ var ts;
|
|
|
116453
116509
|
// This is because in the -out scenario all files need to be emitted, and therefore all
|
|
116454
116510
|
// files need to be type checked. And the way to specify that all files need to be type
|
|
116455
116511
|
// checked is to not pass the file to getEmitResolver.
|
|
116456
|
-
var emitResolver =
|
|
116512
|
+
var emitResolver = getTypeChecker().getEmitResolver(ts.outFile(options) ? undefined : sourceFile, cancellationToken);
|
|
116457
116513
|
ts.performance.mark("beforeEmit");
|
|
116458
116514
|
var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile, ts.getTransformers(options, customTransformers, emitOnlyDtsFiles), emitOnlyDtsFiles,
|
|
116459
116515
|
/*onlyBuildInfo*/ false, forceDtsEmit);
|
|
@@ -116533,15 +116589,7 @@ var ts;
|
|
|
116533
116589
|
if (e instanceof ts.OperationCanceledException) {
|
|
116534
116590
|
// We were canceled while performing the operation. Because our type checker
|
|
116535
116591
|
// might be a bad state, we need to throw it away.
|
|
116536
|
-
|
|
116537
|
-
// Note: we are overly aggressive here. We do not actually *have* to throw away
|
|
116538
|
-
// the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
|
|
116539
|
-
// the lifetimes of these two TypeCheckers the same. Also, we generally only
|
|
116540
|
-
// cancel when the user has made a change anyways. And, in that case, we (the
|
|
116541
|
-
// program instance) will get thrown away anyways. So trying to keep one of
|
|
116542
|
-
// these type checkers alive doesn't serve much purpose.
|
|
116543
|
-
noDiagnosticsTypeChecker = undefined;
|
|
116544
|
-
diagnosticsProducingTypeChecker = undefined;
|
|
116592
|
+
typeChecker = undefined;
|
|
116545
116593
|
}
|
|
116546
116594
|
throw e;
|
|
116547
116595
|
}
|
|
@@ -116557,7 +116605,7 @@ var ts;
|
|
|
116557
116605
|
if (ts.skipTypeChecking(sourceFile, options, program)) {
|
|
116558
116606
|
return ts.emptyArray;
|
|
116559
116607
|
}
|
|
116560
|
-
var typeChecker =
|
|
116608
|
+
var typeChecker = getTypeChecker();
|
|
116561
116609
|
ts.Debug.assert(!!sourceFile.bindDiagnostics);
|
|
116562
116610
|
var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
|
|
116563
116611
|
var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
|
|
@@ -116609,7 +116657,7 @@ var ts;
|
|
|
116609
116657
|
}
|
|
116610
116658
|
function getSuggestionDiagnostics(sourceFile, cancellationToken) {
|
|
116611
116659
|
return runWithCancellationToken(function () {
|
|
116612
|
-
return
|
|
116660
|
+
return getTypeChecker().getSuggestionDiagnostics(sourceFile, cancellationToken);
|
|
116613
116661
|
});
|
|
116614
116662
|
}
|
|
116615
116663
|
/**
|
|
@@ -116829,7 +116877,7 @@ var ts;
|
|
|
116829
116877
|
}
|
|
116830
116878
|
function getDeclarationDiagnosticsForFileNoCache(sourceFile, cancellationToken) {
|
|
116831
116879
|
return runWithCancellationToken(function () {
|
|
116832
|
-
var resolver =
|
|
116880
|
+
var resolver = getTypeChecker().getEmitResolver(sourceFile, cancellationToken);
|
|
116833
116881
|
// Don't actually write any files since we're just getting diagnostics.
|
|
116834
116882
|
return ts.getDeclarationDiagnostics(getEmitHost(ts.noop), resolver, sourceFile) || ts.emptyArray;
|
|
116835
116883
|
});
|
|
@@ -116867,7 +116915,7 @@ var ts;
|
|
|
116867
116915
|
return diagnostics;
|
|
116868
116916
|
}
|
|
116869
116917
|
function getGlobalDiagnostics() {
|
|
116870
|
-
return rootNames.length ? ts.sortAndDeduplicateDiagnostics(
|
|
116918
|
+
return rootNames.length ? ts.sortAndDeduplicateDiagnostics(getTypeChecker().getGlobalDiagnostics().slice()) : ts.emptyArray;
|
|
116871
116919
|
}
|
|
116872
116920
|
function getConfigFileParsingDiagnostics() {
|
|
116873
116921
|
return configFileParsingDiagnostics || ts.emptyArray;
|
|
@@ -133572,9 +133620,14 @@ var ts;
|
|
|
133572
133620
|
if (type) {
|
|
133573
133621
|
return type;
|
|
133574
133622
|
}
|
|
133575
|
-
|
|
133623
|
+
var parent = ts.walkUpParenthesizedExpressions(node.parent);
|
|
133624
|
+
if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === 63 /* EqualsToken */ && node === parent.left) {
|
|
133576
133625
|
// Object literal is assignment pattern: ({ | } = x)
|
|
133577
|
-
return typeChecker.getTypeAtLocation(
|
|
133626
|
+
return typeChecker.getTypeAtLocation(parent);
|
|
133627
|
+
}
|
|
133628
|
+
if (ts.isExpression(parent)) {
|
|
133629
|
+
// f(() => (({ | })));
|
|
133630
|
+
return typeChecker.getContextualType(parent);
|
|
133578
133631
|
}
|
|
133579
133632
|
return undefined;
|
|
133580
133633
|
}
|
|
@@ -134367,8 +134420,24 @@ var ts;
|
|
|
134367
134420
|
};
|
|
134368
134421
|
}
|
|
134369
134422
|
ts.createDocumentRegistryInternal = createDocumentRegistryInternal;
|
|
134423
|
+
function compilerOptionValueToString(value) {
|
|
134424
|
+
var _a;
|
|
134425
|
+
if (value === null || typeof value !== "object") { // eslint-disable-line no-null/no-null
|
|
134426
|
+
return "" + value;
|
|
134427
|
+
}
|
|
134428
|
+
if (ts.isArray(value)) {
|
|
134429
|
+
return "[" + ((_a = ts.map(value, function (e) { return compilerOptionValueToString(e); })) === null || _a === void 0 ? void 0 : _a.join(",")) + "]";
|
|
134430
|
+
}
|
|
134431
|
+
var str = "{";
|
|
134432
|
+
for (var key in value) {
|
|
134433
|
+
if (ts.hasOwnProperty.call(value, key)) { // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
|
|
134434
|
+
str += key + ": " + compilerOptionValueToString(value[key]);
|
|
134435
|
+
}
|
|
134436
|
+
}
|
|
134437
|
+
return str + "}";
|
|
134438
|
+
}
|
|
134370
134439
|
function getKeyForCompilationSettings(settings) {
|
|
134371
|
-
return ts.sourceFileAffectingCompilerOptions.map(function (option) { return ts.getCompilerOptionValue(settings, option); }).join("|");
|
|
134440
|
+
return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
|
|
134372
134441
|
}
|
|
134373
134442
|
})(ts || (ts = {}));
|
|
134374
134443
|
/* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
|
|
@@ -138344,18 +138413,9 @@ var ts;
|
|
|
138344
138413
|
JsDoc.getJsDocTagsFromDeclarations = getJsDocTagsFromDeclarations;
|
|
138345
138414
|
function getDisplayPartsFromComment(comment, checker) {
|
|
138346
138415
|
if (typeof comment === "string") {
|
|
138347
|
-
return [ts.textPart(
|
|
138416
|
+
return [ts.textPart(comment)];
|
|
138348
138417
|
}
|
|
138349
|
-
return ts.flatMap(comment, function (node) { return node.kind === 321 /* JSDocText */ ? [ts.textPart(
|
|
138350
|
-
}
|
|
138351
|
-
function skipSeparatorFromComment(text) {
|
|
138352
|
-
var pos = 0;
|
|
138353
|
-
if (text.charCodeAt(pos++) === 45 /* minus */) {
|
|
138354
|
-
while (pos < text.length && text.charCodeAt(pos) === 32 /* space */)
|
|
138355
|
-
pos++;
|
|
138356
|
-
return text.slice(pos);
|
|
138357
|
-
}
|
|
138358
|
-
return text;
|
|
138418
|
+
return ts.flatMap(comment, function (node) { return node.kind === 321 /* JSDocText */ ? [ts.textPart(node.text)] : ts.buildLinkParts(node, checker); });
|
|
138359
138419
|
}
|
|
138360
138420
|
function getCommentDisplayParts(tag, checker) {
|
|
138361
138421
|
var comment = tag.comment, kind = tag.kind;
|
|
@@ -146153,7 +146213,28 @@ var ts;
|
|
|
146153
146213
|
// indentation is first non-whitespace character in a previous line
|
|
146154
146214
|
// for block indentation, we should look for a line which contains something that's not
|
|
146155
146215
|
// whitespace.
|
|
146156
|
-
|
|
146216
|
+
var currentToken = ts.getTokenAtPosition(sourceFile, position);
|
|
146217
|
+
// for object literal, we want to the indentation work like block
|
|
146218
|
+
// if { starts in any position (can be in the middle of line)
|
|
146219
|
+
// the following indentation should treat { as starting of that line (including leading whitespace)
|
|
146220
|
+
// ```
|
|
146221
|
+
// const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
|
|
146222
|
+
// ->
|
|
146223
|
+
// const a: { x: undefined, y: undefined } = {
|
|
146224
|
+
// x: undefined,
|
|
146225
|
+
// y: undefined,
|
|
146226
|
+
// }
|
|
146227
|
+
// ---------------------
|
|
146228
|
+
// const a: {x : undefined, y: undefined } =
|
|
146229
|
+
// {}
|
|
146230
|
+
// ->
|
|
146231
|
+
// const a: { x: undefined, y: undefined } =
|
|
146232
|
+
// { // leading 5 whitespaces and { starts at 6 column
|
|
146233
|
+
// x: undefined,
|
|
146234
|
+
// y: undefined,
|
|
146235
|
+
// }
|
|
146236
|
+
// ```
|
|
146237
|
+
if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
|
|
146157
146238
|
return getBlockIndent(sourceFile, position, options);
|
|
146158
146239
|
}
|
|
146159
146240
|
if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
|
|
@@ -147096,7 +147177,7 @@ var ts;
|
|
|
147096
147177
|
}
|
|
147097
147178
|
var startPosition = ts.getPrecedingNonSpaceCharacterPosition(sourceFile.text, fnStart - 1);
|
|
147098
147179
|
var indent = sourceFile.text.slice(startPosition, fnStart);
|
|
147099
|
-
this.insertNodeAt(sourceFile, fnStart, tag, {
|
|
147180
|
+
this.insertNodeAt(sourceFile, fnStart, tag, { suffix: this.newLineCharacter + indent });
|
|
147100
147181
|
};
|
|
147101
147182
|
ChangeTracker.prototype.createJSDocText = function (sourceFile, node) {
|
|
147102
147183
|
var comments = ts.flatMap(node.jsDoc, function (jsDoc) {
|
|
@@ -147627,7 +147708,7 @@ var ts;
|
|
|
147627
147708
|
? change.nodes.map(function (n) { return ts.removeSuffix(format(n), newLineCharacter); }).join(((_a = change.options) === null || _a === void 0 ? void 0 : _a.joiner) || newLineCharacter)
|
|
147628
147709
|
: format(change.node);
|
|
147629
147710
|
// strip initial indentation (spaces or tabs) if text will be inserted in the middle of the line
|
|
147630
|
-
var noIndent = (options.
|
|
147711
|
+
var noIndent = (options.indentation !== undefined || ts.getLineStartPositionForPosition(pos, sourceFile) === pos) ? text : text.replace(/^\s+/, "");
|
|
147631
147712
|
return (options.prefix || "") + noIndent
|
|
147632
147713
|
+ ((!options.suffix || ts.endsWith(noIndent, options.suffix))
|
|
147633
147714
|
? "" : options.suffix);
|
|
@@ -148320,7 +148401,7 @@ var ts;
|
|
|
148320
148401
|
errorCodes: errorCodes,
|
|
148321
148402
|
getCodeActions: function getCodeActionsToAddMissingAsync(context) {
|
|
148322
148403
|
var sourceFile = context.sourceFile, errorCode = context.errorCode, cancellationToken = context.cancellationToken, program = context.program, span = context.span;
|
|
148323
|
-
var diagnostic = ts.find(program.
|
|
148404
|
+
var diagnostic = ts.find(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
|
|
148324
148405
|
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; });
|
|
148325
148406
|
var decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
|
|
148326
148407
|
if (!decl) {
|
|
@@ -148474,7 +148555,7 @@ var ts;
|
|
|
148474
148555
|
return codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_await, fixId, ts.Diagnostics.Fix_all_expressions_possibly_missing_await);
|
|
148475
148556
|
}
|
|
148476
148557
|
function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
|
|
148477
|
-
var checker = program.
|
|
148558
|
+
var checker = program.getTypeChecker();
|
|
148478
148559
|
var diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
|
|
148479
148560
|
return ts.some(diagnostics, function (_a) {
|
|
148480
148561
|
var start = _a.start, length = _a.length, relatedInformation = _a.relatedInformation, code = _a.code;
|
|
@@ -149141,20 +149222,6 @@ var ts;
|
|
|
149141
149222
|
}
|
|
149142
149223
|
function createClassElementsFromSymbol(symbol) {
|
|
149143
149224
|
var memberElements = [];
|
|
149144
|
-
// all instance members are stored in the "member" array of symbol
|
|
149145
|
-
if (symbol.members) {
|
|
149146
|
-
symbol.members.forEach(function (member, key) {
|
|
149147
|
-
if (key === "constructor" && member.valueDeclaration) {
|
|
149148
|
-
// fn.prototype.constructor = fn
|
|
149149
|
-
changes.delete(sourceFile, member.valueDeclaration.parent);
|
|
149150
|
-
return;
|
|
149151
|
-
}
|
|
149152
|
-
var memberElement = createClassElement(member, /*modifiers*/ undefined);
|
|
149153
|
-
if (memberElement) {
|
|
149154
|
-
memberElements.push.apply(memberElements, memberElement);
|
|
149155
|
-
}
|
|
149156
|
-
});
|
|
149157
|
-
}
|
|
149158
149225
|
// all static members are stored in the "exports" array of symbol
|
|
149159
149226
|
if (symbol.exports) {
|
|
149160
149227
|
symbol.exports.forEach(function (member) {
|
|
@@ -149167,18 +149234,31 @@ var ts;
|
|
|
149167
149234
|
firstDeclaration.parent.operatorToken.kind === 63 /* EqualsToken */ &&
|
|
149168
149235
|
ts.isObjectLiteralExpression(firstDeclaration.parent.right)) {
|
|
149169
149236
|
var prototypes = firstDeclaration.parent.right;
|
|
149170
|
-
|
|
149171
|
-
if (memberElement) {
|
|
149172
|
-
memberElements.push.apply(memberElements, memberElement);
|
|
149173
|
-
}
|
|
149237
|
+
createClassElement(prototypes.symbol, /** modifiers */ undefined, memberElements);
|
|
149174
149238
|
}
|
|
149175
149239
|
}
|
|
149176
149240
|
else {
|
|
149177
|
-
|
|
149178
|
-
|
|
149179
|
-
|
|
149241
|
+
createClassElement(member, [ts.factory.createToken(124 /* StaticKeyword */)], memberElements);
|
|
149242
|
+
}
|
|
149243
|
+
});
|
|
149244
|
+
}
|
|
149245
|
+
// all instance members are stored in the "member" array of symbol (done last so instance members pulled from prototype assignments have priority)
|
|
149246
|
+
if (symbol.members) {
|
|
149247
|
+
symbol.members.forEach(function (member, key) {
|
|
149248
|
+
var _a, _b, _c, _d;
|
|
149249
|
+
if (key === "constructor" && member.valueDeclaration) {
|
|
149250
|
+
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;
|
|
149251
|
+
if (prototypeAssignment && ts.isBinaryExpression(prototypeAssignment) && ts.isObjectLiteralExpression(prototypeAssignment.right) && ts.some(prototypeAssignment.right.properties, isConstructorAssignment)) {
|
|
149252
|
+
// fn.prototype = { constructor: fn }
|
|
149253
|
+
// Already deleted in `createClassElement` in first pass
|
|
149254
|
+
}
|
|
149255
|
+
else {
|
|
149256
|
+
// fn.prototype.constructor = fn
|
|
149257
|
+
changes.delete(sourceFile, member.valueDeclaration.parent);
|
|
149180
149258
|
}
|
|
149259
|
+
return;
|
|
149181
149260
|
}
|
|
149261
|
+
createClassElement(member, /*modifiers*/ undefined, memberElements);
|
|
149182
149262
|
});
|
|
149183
149263
|
}
|
|
149184
149264
|
return memberElements;
|
|
@@ -149206,18 +149286,26 @@ var ts;
|
|
|
149206
149286
|
});
|
|
149207
149287
|
}
|
|
149208
149288
|
}
|
|
149209
|
-
function createClassElement(symbol, modifiers) {
|
|
149289
|
+
function createClassElement(symbol, modifiers, members) {
|
|
149210
149290
|
// Right now the only thing we can convert are function expressions, which are marked as methods
|
|
149211
149291
|
// or { x: y } type prototype assignments, which are marked as ObjectLiteral
|
|
149212
|
-
var members = [];
|
|
149213
149292
|
if (!(symbol.flags & 8192 /* Method */) && !(symbol.flags & 4096 /* ObjectLiteral */)) {
|
|
149214
|
-
return
|
|
149293
|
+
return;
|
|
149215
149294
|
}
|
|
149216
149295
|
var memberDeclaration = symbol.valueDeclaration;
|
|
149217
149296
|
var assignmentBinaryExpression = memberDeclaration.parent;
|
|
149218
149297
|
var assignmentExpr = assignmentBinaryExpression.right;
|
|
149219
149298
|
if (!shouldConvertDeclaration(memberDeclaration, assignmentExpr)) {
|
|
149220
|
-
return
|
|
149299
|
+
return;
|
|
149300
|
+
}
|
|
149301
|
+
if (ts.some(members, function (m) {
|
|
149302
|
+
var name = ts.getNameOfDeclaration(m);
|
|
149303
|
+
if (name && ts.isIdentifier(name) && ts.idText(name) === ts.symbolName(symbol)) {
|
|
149304
|
+
return true; // class member already made for this name
|
|
149305
|
+
}
|
|
149306
|
+
return false;
|
|
149307
|
+
})) {
|
|
149308
|
+
return;
|
|
149221
149309
|
}
|
|
149222
149310
|
// delete the entire statement if this expression is the sole expression to take care of the semicolon at the end
|
|
149223
149311
|
var nodeToDelete = assignmentBinaryExpression.parent && assignmentBinaryExpression.parent.kind === 238 /* ExpressionStatement */
|
|
@@ -149226,43 +149314,44 @@ var ts;
|
|
|
149226
149314
|
if (!assignmentExpr) {
|
|
149227
149315
|
members.push(ts.factory.createPropertyDeclaration([], modifiers, symbol.name, /*questionToken*/ undefined,
|
|
149228
149316
|
/*type*/ undefined, /*initializer*/ undefined));
|
|
149229
|
-
return
|
|
149317
|
+
return;
|
|
149230
149318
|
}
|
|
149231
149319
|
// f.x = expr
|
|
149232
149320
|
if (ts.isAccessExpression(memberDeclaration) && (ts.isFunctionExpression(assignmentExpr) || ts.isArrowFunction(assignmentExpr))) {
|
|
149233
149321
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
149234
149322
|
var name = tryGetPropertyName(memberDeclaration, compilerOptions, quotePreference);
|
|
149235
149323
|
if (name) {
|
|
149236
|
-
|
|
149324
|
+
createFunctionLikeExpressionMember(members, assignmentExpr, name);
|
|
149237
149325
|
}
|
|
149238
|
-
return
|
|
149326
|
+
return;
|
|
149239
149327
|
}
|
|
149240
149328
|
// f.prototype = { ... }
|
|
149241
149329
|
else if (ts.isObjectLiteralExpression(assignmentExpr)) {
|
|
149242
|
-
|
|
149330
|
+
ts.forEach(assignmentExpr.properties, function (property) {
|
|
149243
149331
|
if (ts.isMethodDeclaration(property) || ts.isGetOrSetAccessorDeclaration(property)) {
|
|
149244
149332
|
// MethodDeclaration and AccessorDeclaration can appear in a class directly
|
|
149245
|
-
|
|
149333
|
+
members.push(property);
|
|
149246
149334
|
}
|
|
149247
149335
|
if (ts.isPropertyAssignment(property) && ts.isFunctionExpression(property.initializer)) {
|
|
149248
|
-
|
|
149336
|
+
createFunctionLikeExpressionMember(members, property.initializer, property.name);
|
|
149249
149337
|
}
|
|
149250
149338
|
// Drop constructor assignments
|
|
149251
149339
|
if (isConstructorAssignment(property))
|
|
149252
|
-
return
|
|
149253
|
-
return
|
|
149340
|
+
return;
|
|
149341
|
+
return;
|
|
149254
149342
|
});
|
|
149343
|
+
return;
|
|
149255
149344
|
}
|
|
149256
149345
|
else {
|
|
149257
149346
|
// Don't try to declare members in JavaScript files
|
|
149258
149347
|
if (ts.isSourceFileJS(sourceFile))
|
|
149259
|
-
return
|
|
149348
|
+
return;
|
|
149260
149349
|
if (!ts.isPropertyAccessExpression(memberDeclaration))
|
|
149261
|
-
return
|
|
149350
|
+
return;
|
|
149262
149351
|
var prop = ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, memberDeclaration.name, /*questionToken*/ undefined, /*type*/ undefined, assignmentExpr);
|
|
149263
149352
|
ts.copyLeadingComments(assignmentBinaryExpression.parent, prop, sourceFile);
|
|
149264
149353
|
members.push(prop);
|
|
149265
|
-
return
|
|
149354
|
+
return;
|
|
149266
149355
|
}
|
|
149267
149356
|
function createFunctionLikeExpressionMember(members, expression, name) {
|
|
149268
149357
|
if (ts.isFunctionExpression(expression))
|
|
@@ -149275,7 +149364,8 @@ var ts;
|
|
|
149275
149364
|
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
|
|
149276
149365
|
/*typeParameters*/ undefined, functionExpression.parameters, /*type*/ undefined, functionExpression.body);
|
|
149277
149366
|
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
|
|
149278
|
-
|
|
149367
|
+
members.push(method);
|
|
149368
|
+
return;
|
|
149279
149369
|
}
|
|
149280
149370
|
function createArrowFunctionExpressionMember(members, arrowFunction, name) {
|
|
149281
149371
|
var arrowFunctionBody = arrowFunction.body;
|
|
@@ -149292,7 +149382,7 @@ var ts;
|
|
|
149292
149382
|
var method = ts.factory.createMethodDeclaration(/*decorators*/ undefined, fullModifiers, /*asteriskToken*/ undefined, name, /*questionToken*/ undefined,
|
|
149293
149383
|
/*typeParameters*/ undefined, arrowFunction.parameters, /*type*/ undefined, bodyBlock);
|
|
149294
149384
|
ts.copyLeadingComments(assignmentBinaryExpression, method, sourceFile);
|
|
149295
|
-
|
|
149385
|
+
members.push(method);
|
|
149296
149386
|
}
|
|
149297
149387
|
}
|
|
149298
149388
|
}
|
|
@@ -152726,7 +152816,7 @@ var ts;
|
|
|
152726
152816
|
var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
|
|
152727
152817
|
if (!ts.length(properties))
|
|
152728
152818
|
return undefined;
|
|
152729
|
-
return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties,
|
|
152819
|
+
return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
|
|
152730
152820
|
}
|
|
152731
152821
|
if (!ts.isMemberName(token))
|
|
152732
152822
|
return undefined;
|
|
@@ -152734,7 +152824,7 @@ var ts;
|
|
|
152734
152824
|
var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
|
|
152735
152825
|
if (!ts.length(properties))
|
|
152736
152826
|
return undefined;
|
|
152737
|
-
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties,
|
|
152827
|
+
return { kind: 3 /* ObjectLiteral */, token: token, properties: properties, parentDeclaration: parent.initializer };
|
|
152738
152828
|
}
|
|
152739
152829
|
if (ts.isIdentifier(token) && ts.isJsxOpeningLikeElement(token.parent)) {
|
|
152740
152830
|
var target = ts.getEmitScriptTarget(program.getCompilerOptions());
|