typescript 5.5.0-dev.20240430 → 5.5.0-dev.20240502
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/tsc.js +83 -58
- package/lib/typescript.js +1147 -228
- package/package.json +2 -2
package/lib/typescript.js
CHANGED
|
@@ -302,6 +302,7 @@ __export(typescript_exports, {
|
|
|
302
302
|
collectExternalModuleInfo: () => collectExternalModuleInfo,
|
|
303
303
|
combine: () => combine,
|
|
304
304
|
combinePaths: () => combinePaths,
|
|
305
|
+
commandLineOptionOfCustomType: () => commandLineOptionOfCustomType,
|
|
305
306
|
commentPragmas: () => commentPragmas,
|
|
306
307
|
commonOptionsWithBuild: () => commonOptionsWithBuild,
|
|
307
308
|
commonPackageFolders: () => commonPackageFolders,
|
|
@@ -2362,7 +2363,7 @@ module.exports = __toCommonJS(typescript_exports);
|
|
|
2362
2363
|
|
|
2363
2364
|
// src/compiler/corePublic.ts
|
|
2364
2365
|
var versionMajorMinor = "5.5";
|
|
2365
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
2366
|
+
var version = `${versionMajorMinor}.0-dev.20240502`;
|
|
2366
2367
|
var Comparison = /* @__PURE__ */ ((Comparison3) => {
|
|
2367
2368
|
Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
|
|
2368
2369
|
Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
|
|
@@ -11330,6 +11331,16 @@ var Diagnostics = {
|
|
|
11330
11331
|
Export_0_from_module_1: diag(90059, 3 /* Message */, "Export_0_from_module_1_90059", "Export '{0}' from module '{1}'"),
|
|
11331
11332
|
Export_all_referenced_locals: diag(90060, 3 /* Message */, "Export_all_referenced_locals_90060", "Export all referenced locals"),
|
|
11332
11333
|
Update_modifiers_of_0: diag(90061, 3 /* Message */, "Update_modifiers_of_0_90061", "Update modifiers of '{0}'"),
|
|
11334
|
+
Add_annotation_of_type_0: diag(90062, 3 /* Message */, "Add_annotation_of_type_0_90062", "Add annotation of type '{0}'"),
|
|
11335
|
+
Add_return_type_0: diag(90063, 3 /* Message */, "Add_return_type_0_90063", "Add return type '{0}'"),
|
|
11336
|
+
Extract_base_class_to_variable: diag(90064, 3 /* Message */, "Extract_base_class_to_variable_90064", "Extract base class to variable"),
|
|
11337
|
+
Extract_default_export_to_variable: diag(90065, 3 /* Message */, "Extract_default_export_to_variable_90065", "Extract default export to variable"),
|
|
11338
|
+
Extract_binding_expressions_to_variable: diag(90066, 3 /* Message */, "Extract_binding_expressions_to_variable_90066", "Extract binding expressions to variable"),
|
|
11339
|
+
Add_all_missing_type_annotations: diag(90067, 3 /* Message */, "Add_all_missing_type_annotations_90067", "Add all missing type annotations"),
|
|
11340
|
+
Add_satisfies_and_an_inline_type_assertion_with_0: diag(90068, 3 /* Message */, "Add_satisfies_and_an_inline_type_assertion_with_0_90068", "Add satisfies and an inline type assertion with '{0}'"),
|
|
11341
|
+
Extract_to_variable_and_replace_with_0_as_typeof_0: diag(90069, 3 /* Message */, "Extract_to_variable_and_replace_with_0_as_typeof_0_90069", "Extract to variable and replace with '{0} as typeof {0}'"),
|
|
11342
|
+
Mark_array_literal_as_const: diag(90070, 3 /* Message */, "Mark_array_literal_as_const_90070", "Mark array literal as const"),
|
|
11343
|
+
Annotate_types_of_properties_expando_function_in_a_namespace: diag(90071, 3 /* Message */, "Annotate_types_of_properties_expando_function_in_a_namespace_90071", "Annotate types of properties expando function in a namespace"),
|
|
11333
11344
|
Convert_function_to_an_ES2015_class: diag(95001, 3 /* Message */, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
|
|
11334
11345
|
Convert_0_to_1_in_0: diag(95003, 3 /* Message */, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
|
|
11335
11346
|
Extract_to_0_in_1: diag(95004, 3 /* Message */, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
|
|
@@ -17450,7 +17461,7 @@ function entityNameToString(name) {
|
|
|
17450
17461
|
return Debug.assertNever(name.name);
|
|
17451
17462
|
}
|
|
17452
17463
|
case 311 /* JSDocMemberName */:
|
|
17453
|
-
return entityNameToString(name.left) + entityNameToString(name.right);
|
|
17464
|
+
return entityNameToString(name.left) + "#" + entityNameToString(name.right);
|
|
17454
17465
|
case 295 /* JsxNamespacedName */:
|
|
17455
17466
|
return entityNameToString(name.namespace) + ":" + entityNameToString(name.name);
|
|
17456
17467
|
default:
|
|
@@ -41434,6 +41445,10 @@ var configDirTemplateSubstitutionOptions = optionDeclarations.filter(
|
|
|
41434
41445
|
var configDirTemplateSubstitutionWatchOptions = optionsForWatch.filter(
|
|
41435
41446
|
(option) => option.allowConfigDirTemplateSubstitution || !option.isCommandLineOnly && option.isFilePath
|
|
41436
41447
|
);
|
|
41448
|
+
var commandLineOptionOfCustomType = optionDeclarations.filter(isCommandLineOptionOfCustomType);
|
|
41449
|
+
function isCommandLineOptionOfCustomType(option) {
|
|
41450
|
+
return !isString(option.type);
|
|
41451
|
+
}
|
|
41437
41452
|
var optionsForBuild = [
|
|
41438
41453
|
{
|
|
41439
41454
|
name: "verbose",
|
|
@@ -50243,7 +50258,7 @@ function createTypeChecker(host) {
|
|
|
50243
50258
|
var externalHelpersModule;
|
|
50244
50259
|
var scanner2;
|
|
50245
50260
|
var Symbol47 = objectAllocator.getSymbolConstructor();
|
|
50246
|
-
var
|
|
50261
|
+
var Type29 = objectAllocator.getTypeConstructor();
|
|
50247
50262
|
var Signature14 = objectAllocator.getSignatureConstructor();
|
|
50248
50263
|
var typeCount = 0;
|
|
50249
50264
|
var symbolCount = 0;
|
|
@@ -50385,6 +50400,7 @@ function createTypeChecker(host) {
|
|
|
50385
50400
|
getBaseTypes,
|
|
50386
50401
|
getBaseTypeOfLiteralType,
|
|
50387
50402
|
getWidenedType,
|
|
50403
|
+
getWidenedLiteralType,
|
|
50388
50404
|
getTypeFromTypeNode: (nodeIn) => {
|
|
50389
50405
|
const node = getParseTreeNode(nodeIn, isTypeNode);
|
|
50390
50406
|
return node ? getTypeFromTypeNode(node) : errorType;
|
|
@@ -52962,12 +52978,6 @@ function createTypeChecker(host) {
|
|
|
52962
52978
|
}
|
|
52963
52979
|
}
|
|
52964
52980
|
}
|
|
52965
|
-
function markConstEnumAliasAsReferenced(symbol) {
|
|
52966
|
-
const links = getSymbolLinks(symbol);
|
|
52967
|
-
if (!links.constEnumReferenced) {
|
|
52968
|
-
links.constEnumReferenced = true;
|
|
52969
|
-
}
|
|
52970
|
-
}
|
|
52971
52981
|
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, dontResolveAlias) {
|
|
52972
52982
|
if (entityName.kind === 80 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
|
52973
52983
|
entityName = entityName.parent;
|
|
@@ -53842,7 +53852,7 @@ function createTypeChecker(host) {
|
|
|
53842
53852
|
}
|
|
53843
53853
|
function createType(flags) {
|
|
53844
53854
|
var _a;
|
|
53845
|
-
const result = new
|
|
53855
|
+
const result = new Type29(checker, flags);
|
|
53846
53856
|
typeCount++;
|
|
53847
53857
|
result.id = typeCount;
|
|
53848
53858
|
(_a = tracing) == null ? void 0 : _a.recordType(result);
|
|
@@ -53854,7 +53864,7 @@ function createTypeChecker(host) {
|
|
|
53854
53864
|
return result;
|
|
53855
53865
|
}
|
|
53856
53866
|
function createOriginType(flags) {
|
|
53857
|
-
return new
|
|
53867
|
+
return new Type29(checker, flags);
|
|
53858
53868
|
}
|
|
53859
53869
|
function createIntrinsicType(kind, intrinsicName, objectFlags = 0 /* None */, debugIntrinsicName) {
|
|
53860
53870
|
checkIntrinsicName(intrinsicName, debugIntrinsicName);
|
|
@@ -54452,31 +54462,31 @@ function createTypeChecker(host) {
|
|
|
54452
54462
|
}
|
|
54453
54463
|
function createNodeBuilder() {
|
|
54454
54464
|
return {
|
|
54455
|
-
typeToTypeNode: (type, enclosingDeclaration, flags, tracker) =>
|
|
54456
|
-
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, tracker) =>
|
|
54457
|
-
expressionOrTypeToTypeNode: (expr, type, addUndefined, enclosingDeclaration, flags, tracker) =>
|
|
54458
|
-
serializeTypeForDeclaration: (declaration, type, symbol, enclosingDeclaration, flags, tracker) =>
|
|
54459
|
-
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, tracker) =>
|
|
54460
|
-
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, tracker) =>
|
|
54465
|
+
typeToTypeNode: (type, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeToTypeNodeHelper(type, context)),
|
|
54466
|
+
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
|
|
54467
|
+
expressionOrTypeToTypeNode: (expr, type, addUndefined, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => expressionOrTypeToTypeNode(context, expr, type, addUndefined)),
|
|
54468
|
+
serializeTypeForDeclaration: (declaration, type, symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => serializeTypeForDeclaration(context, declaration, type, symbol)),
|
|
54469
|
+
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => serializeReturnTypeForSignature(context, signature)),
|
|
54470
|
+
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
|
|
54461
54471
|
indexInfo,
|
|
54462
54472
|
context,
|
|
54463
54473
|
/*typeNode*/
|
|
54464
54474
|
void 0
|
|
54465
54475
|
)),
|
|
54466
|
-
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, tracker) =>
|
|
54467
|
-
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, tracker) =>
|
|
54476
|
+
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
|
|
54477
|
+
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToName(
|
|
54468
54478
|
symbol,
|
|
54469
54479
|
context,
|
|
54470
54480
|
meaning,
|
|
54471
54481
|
/*expectsIdentifier*/
|
|
54472
54482
|
false
|
|
54473
54483
|
)),
|
|
54474
|
-
symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, tracker) =>
|
|
54475
|
-
symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, tracker) =>
|
|
54476
|
-
symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, tracker) =>
|
|
54477
|
-
typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, tracker) =>
|
|
54478
|
-
symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, tracker) =>
|
|
54479
|
-
symbolToNode: (symbol, meaning, enclosingDeclaration, flags, tracker) =>
|
|
54484
|
+
symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
|
|
54485
|
+
symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
|
|
54486
|
+
symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
|
|
54487
|
+
typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
|
|
54488
|
+
symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
|
|
54489
|
+
symbolToNode: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToNode(symbol, context, meaning))
|
|
54480
54490
|
};
|
|
54481
54491
|
function setTextRange2(context, range, location) {
|
|
54482
54492
|
if (!nodeIsSynthesized(range) && !(range.flags & 16 /* Synthesized */) && (!context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(range))) {
|
|
@@ -54559,7 +54569,7 @@ function createTypeChecker(host) {
|
|
|
54559
54569
|
}
|
|
54560
54570
|
return symbolToExpression(symbol, context, meaning);
|
|
54561
54571
|
}
|
|
54562
|
-
function
|
|
54572
|
+
function withContext2(enclosingDeclaration, flags, tracker, cb) {
|
|
54563
54573
|
Debug.assert(enclosingDeclaration === void 0 || (enclosingDeclaration.flags & 16 /* Synthesized */) === 0);
|
|
54564
54574
|
const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : flags & 134217728 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
|
|
54565
54575
|
const context = {
|
|
@@ -73830,7 +73840,7 @@ function createTypeChecker(host) {
|
|
|
73830
73840
|
if (!hasDefaultClause) {
|
|
73831
73841
|
return caseType;
|
|
73832
73842
|
}
|
|
73833
|
-
const defaultType = filterType(type, (t) => !(isUnitLikeType(t) && contains(switchTypes, getRegularTypeOfLiteralType(extractUnitType(t)))));
|
|
73843
|
+
const defaultType = filterType(type, (t) => !(isUnitLikeType(t) && contains(switchTypes, t.flags & 32768 /* Undefined */ ? undefinedType : getRegularTypeOfLiteralType(extractUnitType(t)))));
|
|
73834
73844
|
return caseType.flags & 131072 /* Never */ ? defaultType : getUnionType([caseType, defaultType]);
|
|
73835
73845
|
}
|
|
73836
73846
|
function narrowTypeByTypeName(type, typeName) {
|
|
@@ -74352,8 +74362,6 @@ function createTypeChecker(host) {
|
|
|
74352
74362
|
) & (111551 /* Value */ | 1048576 /* ExportValue */)) {
|
|
74353
74363
|
if (getIsolatedModules(compilerOptions) || shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(location) || !isConstEnumOrConstEnumOnlyModule(getExportSymbolOfValueSymbolIfExported(target))) {
|
|
74354
74364
|
markAliasSymbolAsReferenced(symbol);
|
|
74355
|
-
} else {
|
|
74356
|
-
markConstEnumAliasAsReferenced(symbol);
|
|
74357
74365
|
}
|
|
74358
74366
|
}
|
|
74359
74367
|
}
|
|
@@ -75610,60 +75618,71 @@ function createTypeChecker(host) {
|
|
|
75610
75618
|
return false;
|
|
75611
75619
|
}
|
|
75612
75620
|
function discriminateContextualTypeByObjectMembers(node, contextualType) {
|
|
75613
|
-
|
|
75614
|
-
|
|
75615
|
-
|
|
75616
|
-
|
|
75617
|
-
|
|
75618
|
-
|
|
75621
|
+
const key = `D${getNodeId(node)},${getTypeId(contextualType)}`;
|
|
75622
|
+
return getCachedType(key) ?? setCachedType(
|
|
75623
|
+
key,
|
|
75624
|
+
getMatchingUnionConstituentForObjectLiteral(contextualType, node) ?? discriminateTypeByDiscriminableItems(
|
|
75625
|
+
contextualType,
|
|
75626
|
+
concatenate(
|
|
75627
|
+
map(
|
|
75628
|
+
filter(node.properties, (p) => {
|
|
75629
|
+
if (!p.symbol) {
|
|
75630
|
+
return false;
|
|
75631
|
+
}
|
|
75632
|
+
if (p.kind === 303 /* PropertyAssignment */) {
|
|
75633
|
+
return isPossiblyDiscriminantValue(p.initializer) && isDiscriminantProperty(contextualType, p.symbol.escapedName);
|
|
75634
|
+
}
|
|
75635
|
+
if (p.kind === 304 /* ShorthandPropertyAssignment */) {
|
|
75636
|
+
return isDiscriminantProperty(contextualType, p.symbol.escapedName);
|
|
75637
|
+
}
|
|
75619
75638
|
return false;
|
|
75620
|
-
}
|
|
75621
|
-
|
|
75622
|
-
|
|
75623
|
-
|
|
75624
|
-
|
|
75625
|
-
|
|
75626
|
-
|
|
75627
|
-
|
|
75628
|
-
|
|
75629
|
-
|
|
75639
|
+
}),
|
|
75640
|
+
(prop) => [() => getContextFreeTypeOfExpression(prop.kind === 303 /* PropertyAssignment */ ? prop.initializer : prop.name), prop.symbol.escapedName]
|
|
75641
|
+
),
|
|
75642
|
+
map(
|
|
75643
|
+
filter(getPropertiesOfType(contextualType), (s) => {
|
|
75644
|
+
var _a;
|
|
75645
|
+
return !!(s.flags & 16777216 /* Optional */) && !!((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
|
|
75646
|
+
}),
|
|
75647
|
+
(s) => [() => undefinedType, s.escapedName]
|
|
75648
|
+
)
|
|
75630
75649
|
),
|
|
75631
|
-
|
|
75632
|
-
|
|
75633
|
-
var _a;
|
|
75634
|
-
return !!(s.flags & 16777216 /* Optional */) && !!((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members) && !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
|
|
75635
|
-
}),
|
|
75636
|
-
(s) => [() => undefinedType, s.escapedName]
|
|
75637
|
-
)
|
|
75638
|
-
),
|
|
75639
|
-
isTypeAssignableTo
|
|
75650
|
+
isTypeAssignableTo
|
|
75651
|
+
)
|
|
75640
75652
|
);
|
|
75641
75653
|
}
|
|
75642
75654
|
function discriminateContextualTypeByJSXAttributes(node, contextualType) {
|
|
75655
|
+
const key = `D${getNodeId(node)},${getTypeId(contextualType)}`;
|
|
75656
|
+
const cached = getCachedType(key);
|
|
75657
|
+
if (cached)
|
|
75658
|
+
return cached;
|
|
75643
75659
|
const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node));
|
|
75644
|
-
return
|
|
75645
|
-
|
|
75646
|
-
|
|
75647
|
-
|
|
75648
|
-
|
|
75649
|
-
(
|
|
75660
|
+
return setCachedType(
|
|
75661
|
+
key,
|
|
75662
|
+
discriminateTypeByDiscriminableItems(
|
|
75663
|
+
contextualType,
|
|
75664
|
+
concatenate(
|
|
75665
|
+
map(
|
|
75666
|
+
filter(node.properties, (p) => !!p.symbol && p.kind === 291 /* JsxAttribute */ && isDiscriminantProperty(contextualType, p.symbol.escapedName) && (!p.initializer || isPossiblyDiscriminantValue(p.initializer))),
|
|
75667
|
+
(prop) => [!prop.initializer ? () => trueType : () => getContextFreeTypeOfExpression(prop.initializer), prop.symbol.escapedName]
|
|
75668
|
+
),
|
|
75669
|
+
map(
|
|
75670
|
+
filter(getPropertiesOfType(contextualType), (s) => {
|
|
75671
|
+
var _a;
|
|
75672
|
+
if (!(s.flags & 16777216 /* Optional */) || !((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members)) {
|
|
75673
|
+
return false;
|
|
75674
|
+
}
|
|
75675
|
+
const element = node.parent.parent;
|
|
75676
|
+
if (s.escapedName === jsxChildrenPropertyName && isJsxElement(element) && getSemanticJsxChildren(element.children).length) {
|
|
75677
|
+
return false;
|
|
75678
|
+
}
|
|
75679
|
+
return !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
|
|
75680
|
+
}),
|
|
75681
|
+
(s) => [() => undefinedType, s.escapedName]
|
|
75682
|
+
)
|
|
75650
75683
|
),
|
|
75651
|
-
|
|
75652
|
-
|
|
75653
|
-
var _a;
|
|
75654
|
-
if (!(s.flags & 16777216 /* Optional */) || !((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members)) {
|
|
75655
|
-
return false;
|
|
75656
|
-
}
|
|
75657
|
-
const element = node.parent.parent;
|
|
75658
|
-
if (s.escapedName === jsxChildrenPropertyName && isJsxElement(element) && getSemanticJsxChildren(element.children).length) {
|
|
75659
|
-
return false;
|
|
75660
|
-
}
|
|
75661
|
-
return !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
|
|
75662
|
-
}),
|
|
75663
|
-
(s) => [() => undefinedType, s.escapedName]
|
|
75664
|
-
)
|
|
75665
|
-
),
|
|
75666
|
-
isTypeAssignableTo
|
|
75684
|
+
isTypeAssignableTo
|
|
75685
|
+
)
|
|
75667
75686
|
);
|
|
75668
75687
|
}
|
|
75669
75688
|
function getApparentTypeOfContextualType(node, contextFlags) {
|
|
@@ -124081,6 +124100,13 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
|
|
|
124081
124100
|
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions;
|
|
124082
124101
|
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion: typeScriptVersion3 } = createProgramOptions;
|
|
124083
124102
|
let { oldProgram } = createProgramOptions;
|
|
124103
|
+
for (const option of commandLineOptionOfCustomType) {
|
|
124104
|
+
if (hasProperty(options, option.name)) {
|
|
124105
|
+
if (typeof options[option.name] === "string") {
|
|
124106
|
+
throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);
|
|
124107
|
+
}
|
|
124108
|
+
}
|
|
124109
|
+
}
|
|
124084
124110
|
const reportInvalidIgnoreDeprecations = memoize(() => createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations));
|
|
124085
124111
|
let processingDefaultLibFiles;
|
|
124086
124112
|
let processingOtherFiles;
|
|
@@ -142878,6 +142904,7 @@ __export(ts_refactor_exports, {
|
|
|
142878
142904
|
generateGetAccessorAndSetAccessor: () => ts_refactor_generateGetAccessorAndSetAccessor_exports,
|
|
142879
142905
|
getApplicableRefactors: () => getApplicableRefactors,
|
|
142880
142906
|
getEditsForRefactor: () => getEditsForRefactor,
|
|
142907
|
+
getIdentifierForNode: () => getIdentifierForNode,
|
|
142881
142908
|
getNewStatementsAndRemoveFromOldFile: () => getNewStatementsAndRemoveFromOldFile,
|
|
142882
142909
|
getStatementsToMove: () => getStatementsToMove,
|
|
142883
142910
|
getTopLevelDeclarationStatement: () => getTopLevelDeclarationStatement,
|
|
@@ -144606,6 +144633,15 @@ function refactorKindBeginsWith(known, requested) {
|
|
|
144606
144633
|
return true;
|
|
144607
144634
|
return known.substr(0, requested.length) === requested;
|
|
144608
144635
|
}
|
|
144636
|
+
function getIdentifierForNode(node, scope, checker, file) {
|
|
144637
|
+
return isPropertyAccessExpression(node) && !isClassLike(scope) && !checker.resolveName(
|
|
144638
|
+
node.name.text,
|
|
144639
|
+
node,
|
|
144640
|
+
111551 /* Value */,
|
|
144641
|
+
/*excludeGlobals*/
|
|
144642
|
+
false
|
|
144643
|
+
) && !isPrivateIdentifier(node.name) && !identifierToKeywordKind(node.name) ? node.name.text : getUniqueName(isClassLike(scope) ? "newProperty" : "newLocal", file);
|
|
144644
|
+
}
|
|
144609
144645
|
function addTargetFileImports(oldFile, importsToCopy, targetFileImportsFromOldFile, checker, program, importAdder) {
|
|
144610
144646
|
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
|
|
144611
144647
|
var _a;
|
|
@@ -147289,13 +147325,7 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
147289
147325
|
function extractConstantInScope(node, scope, { substitutions }, rangeFacts, context) {
|
|
147290
147326
|
const checker = context.program.getTypeChecker();
|
|
147291
147327
|
const file = scope.getSourceFile();
|
|
147292
|
-
const localNameText =
|
|
147293
|
-
node.name.text,
|
|
147294
|
-
node,
|
|
147295
|
-
111551 /* Value */,
|
|
147296
|
-
/*excludeGlobals*/
|
|
147297
|
-
false
|
|
147298
|
-
) && !isPrivateIdentifier(node.name) && !identifierToKeywordKind(node.name) ? node.name.text : getUniqueName(isClassLike(scope) ? "newProperty" : "newLocal", file);
|
|
147328
|
+
const localNameText = getIdentifierForNode(node, scope, checker, file);
|
|
147299
147329
|
const isJS = isInJSFile(scope);
|
|
147300
147330
|
let variableType = isJS || !checker.isContextSensitive(node) ? void 0 : checker.typeToTypeNode(checker.getContextualType(node), scope, 1 /* NoTruncation */);
|
|
147301
147331
|
let initializer = transformConstantInitializer(skipParentheses(node), substitutions);
|
|
@@ -149863,22 +149893,22 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
|
149863
149893
|
}
|
|
149864
149894
|
return [];
|
|
149865
149895
|
}
|
|
149866
|
-
function getCodeFixesAtPosition(fileName, start, end,
|
|
149896
|
+
function getCodeFixesAtPosition(fileName, start, end, errorCodes67, formatOptions, preferences = emptyOptions) {
|
|
149867
149897
|
synchronizeHostData();
|
|
149868
149898
|
const sourceFile = getValidSourceFile(fileName);
|
|
149869
149899
|
const span = createTextSpanFromBounds(start, end);
|
|
149870
149900
|
const formatContext = ts_formatting_exports.getFormatContext(formatOptions, host);
|
|
149871
|
-
return flatMap(deduplicate(
|
|
149901
|
+
return flatMap(deduplicate(errorCodes67, equateValues, compareValues), (errorCode) => {
|
|
149872
149902
|
cancellationToken.throwIfCancellationRequested();
|
|
149873
149903
|
return ts_codefix_exports.getFixes({ errorCode, sourceFile, span, program, host, cancellationToken, formatContext, preferences });
|
|
149874
149904
|
});
|
|
149875
149905
|
}
|
|
149876
|
-
function getCombinedCodeFix(scope,
|
|
149906
|
+
function getCombinedCodeFix(scope, fixId54, formatOptions, preferences = emptyOptions) {
|
|
149877
149907
|
synchronizeHostData();
|
|
149878
149908
|
Debug.assert(scope.type === "file");
|
|
149879
149909
|
const sourceFile = getValidSourceFile(scope.fileName);
|
|
149880
149910
|
const formatContext = ts_formatting_exports.getFormatContext(formatOptions, host);
|
|
149881
|
-
return ts_codefix_exports.getAllFixes({ fixId:
|
|
149911
|
+
return ts_codefix_exports.getAllFixes({ fixId: fixId54, sourceFile, program, host, cancellationToken, formatContext, preferences });
|
|
149882
149912
|
}
|
|
149883
149913
|
function organizeImports2(args, formatOptions, preferences = emptyOptions) {
|
|
149884
149914
|
synchronizeHostData();
|
|
@@ -151557,14 +151587,14 @@ function createCodeFixActionWithoutFixAll(fixName8, changes, description3) {
|
|
|
151557
151587
|
void 0
|
|
151558
151588
|
);
|
|
151559
151589
|
}
|
|
151560
|
-
function createCodeFixAction(fixName8, changes, description3,
|
|
151561
|
-
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes,
|
|
151590
|
+
function createCodeFixAction(fixName8, changes, description3, fixId54, fixAllDescription, command) {
|
|
151591
|
+
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes, fixId54, diagnosticToString(fixAllDescription), command);
|
|
151562
151592
|
}
|
|
151563
|
-
function createCodeFixActionMaybeFixAll(fixName8, changes, description3,
|
|
151564
|
-
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes,
|
|
151593
|
+
function createCodeFixActionMaybeFixAll(fixName8, changes, description3, fixId54, fixAllDescription, command) {
|
|
151594
|
+
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes, fixId54, fixAllDescription && diagnosticToString(fixAllDescription), command);
|
|
151565
151595
|
}
|
|
151566
|
-
function createCodeFixActionWorker(fixName8, description3, changes,
|
|
151567
|
-
return { fixName: fixName8, description: description3, changes, fixId:
|
|
151596
|
+
function createCodeFixActionWorker(fixName8, description3, changes, fixId54, fixAllDescription, command) {
|
|
151597
|
+
return { fixName: fixName8, description: description3, changes, fixId: fixId54, fixAllDescription, commands: command ? [command] : void 0 };
|
|
151568
151598
|
}
|
|
151569
151599
|
function registerCodeFix(reg) {
|
|
151570
151600
|
for (const error2 of reg.errorCodes) {
|
|
@@ -151572,9 +151602,9 @@ function registerCodeFix(reg) {
|
|
|
151572
151602
|
errorCodeToFixes.add(String(error2), reg);
|
|
151573
151603
|
}
|
|
151574
151604
|
if (reg.fixIds) {
|
|
151575
|
-
for (const
|
|
151576
|
-
Debug.assert(!fixIdToRegistration.has(
|
|
151577
|
-
fixIdToRegistration.set(
|
|
151605
|
+
for (const fixId54 of reg.fixIds) {
|
|
151606
|
+
Debug.assert(!fixIdToRegistration.has(fixId54));
|
|
151607
|
+
fixIdToRegistration.set(fixId54, reg);
|
|
151578
151608
|
}
|
|
151579
151609
|
}
|
|
151580
151610
|
}
|
|
@@ -151583,17 +151613,17 @@ function getSupportedErrorCodes() {
|
|
|
151583
151613
|
return errorCodeToFixesArray ?? (errorCodeToFixesArray = arrayFrom(errorCodeToFixes.keys()));
|
|
151584
151614
|
}
|
|
151585
151615
|
function removeFixIdIfFixAllUnavailable(registration, diagnostics) {
|
|
151586
|
-
const { errorCodes:
|
|
151616
|
+
const { errorCodes: errorCodes67 } = registration;
|
|
151587
151617
|
let maybeFixableDiagnostics = 0;
|
|
151588
151618
|
for (const diag2 of diagnostics) {
|
|
151589
|
-
if (contains(
|
|
151619
|
+
if (contains(errorCodes67, diag2.code))
|
|
151590
151620
|
maybeFixableDiagnostics++;
|
|
151591
151621
|
if (maybeFixableDiagnostics > 1)
|
|
151592
151622
|
break;
|
|
151593
151623
|
}
|
|
151594
151624
|
const fixAllUnavailable = maybeFixableDiagnostics < 2;
|
|
151595
|
-
return ({ fixId:
|
|
151596
|
-
return fixAllUnavailable ? action : { ...action, fixId:
|
|
151625
|
+
return ({ fixId: fixId54, fixAllDescription, ...action }) => {
|
|
151626
|
+
return fixAllUnavailable ? action : { ...action, fixId: fixId54, fixAllDescription };
|
|
151597
151627
|
};
|
|
151598
151628
|
}
|
|
151599
151629
|
function getFixes(context) {
|
|
@@ -151610,24 +151640,30 @@ function createCombinedCodeActions(changes, commands) {
|
|
|
151610
151640
|
function createFileTextChanges(fileName, textChanges2) {
|
|
151611
151641
|
return { fileName, textChanges: textChanges2 };
|
|
151612
151642
|
}
|
|
151613
|
-
function codeFixAll(context,
|
|
151643
|
+
function codeFixAll(context, errorCodes67, use) {
|
|
151614
151644
|
const commands = [];
|
|
151615
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context,
|
|
151645
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context, errorCodes67, (diag2) => use(t, diag2, commands)));
|
|
151616
151646
|
return createCombinedCodeActions(changes, commands.length === 0 ? void 0 : commands);
|
|
151617
151647
|
}
|
|
151618
|
-
function eachDiagnostic(context,
|
|
151648
|
+
function eachDiagnostic(context, errorCodes67, cb) {
|
|
151619
151649
|
for (const diag2 of getDiagnostics(context)) {
|
|
151620
|
-
if (contains(
|
|
151650
|
+
if (contains(errorCodes67, diag2.code)) {
|
|
151621
151651
|
cb(diag2);
|
|
151622
151652
|
}
|
|
151623
151653
|
}
|
|
151624
151654
|
}
|
|
151625
151655
|
function getDiagnostics({ program, sourceFile, cancellationToken }) {
|
|
151626
|
-
|
|
151656
|
+
const diagnostics = [
|
|
151627
151657
|
...program.getSemanticDiagnostics(sourceFile, cancellationToken),
|
|
151628
151658
|
...program.getSyntacticDiagnostics(sourceFile, cancellationToken),
|
|
151629
151659
|
...computeSuggestionDiagnostics(sourceFile, program, cancellationToken)
|
|
151630
151660
|
];
|
|
151661
|
+
if (getEmitDeclarations(program.getCompilerOptions())) {
|
|
151662
|
+
diagnostics.push(
|
|
151663
|
+
...program.getDeclarationDiagnostics(sourceFile, cancellationToken)
|
|
151664
|
+
);
|
|
151665
|
+
}
|
|
151666
|
+
return diagnostics;
|
|
151631
151667
|
}
|
|
151632
151668
|
|
|
151633
151669
|
// src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts
|
|
@@ -156315,10 +156351,10 @@ registerCodeFix({
|
|
|
156315
156351
|
const info = errorCodeFixIdMap[errorCode];
|
|
156316
156352
|
if (!info)
|
|
156317
156353
|
return emptyArray;
|
|
156318
|
-
const { descriptions, fixId:
|
|
156354
|
+
const { descriptions, fixId: fixId54, fixAllDescriptions } = info;
|
|
156319
156355
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (changes2) => dispatchChanges(changes2, context, errorCode, span.start));
|
|
156320
156356
|
return [
|
|
156321
|
-
createCodeFixActionMaybeFixAll(fixName, changes, descriptions,
|
|
156357
|
+
createCodeFixActionMaybeFixAll(fixName, changes, descriptions, fixId54, fixAllDescriptions)
|
|
156322
156358
|
];
|
|
156323
156359
|
},
|
|
156324
156360
|
fixIds: [fixName, fixAddOverrideId, fixRemoveOverrideId],
|
|
@@ -157123,7 +157159,7 @@ registerCodeFix({
|
|
|
157123
157159
|
},
|
|
157124
157160
|
fixIds: [fixMissingMember, fixMissingFunctionDeclaration, fixMissingProperties, fixMissingAttributes],
|
|
157125
157161
|
getAllCodeActions: (context) => {
|
|
157126
|
-
const { program, fixId:
|
|
157162
|
+
const { program, fixId: fixId54 } = context;
|
|
157127
157163
|
const checker = program.getTypeChecker();
|
|
157128
157164
|
const seen = /* @__PURE__ */ new Map();
|
|
157129
157165
|
const typeDeclToMembers = /* @__PURE__ */ new Map();
|
|
@@ -157133,11 +157169,11 @@ registerCodeFix({
|
|
|
157133
157169
|
if (!info || !addToSeen(seen, getNodeId(info.parentDeclaration) + "#" + (info.kind === 3 /* ObjectLiteral */ ? info.identifier : info.token.text))) {
|
|
157134
157170
|
return;
|
|
157135
157171
|
}
|
|
157136
|
-
if (
|
|
157172
|
+
if (fixId54 === fixMissingFunctionDeclaration && (info.kind === 2 /* Function */ || info.kind === 5 /* Signature */)) {
|
|
157137
157173
|
addFunctionDeclaration(changes, context, info);
|
|
157138
|
-
} else if (
|
|
157174
|
+
} else if (fixId54 === fixMissingProperties && info.kind === 3 /* ObjectLiteral */) {
|
|
157139
157175
|
addObjectLiteralProperties(changes, context, info);
|
|
157140
|
-
} else if (
|
|
157176
|
+
} else if (fixId54 === fixMissingAttributes && info.kind === 4 /* JsxAttributes */) {
|
|
157141
157177
|
addJsxAttributes(changes, context, info);
|
|
157142
157178
|
} else {
|
|
157143
157179
|
if (info.kind === 1 /* Enum */) {
|
|
@@ -159059,21 +159095,21 @@ registerCodeFix({
|
|
|
159059
159095
|
actions2.push(fix(type, fixIdNullable, Diagnostics.Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types));
|
|
159060
159096
|
}
|
|
159061
159097
|
return actions2;
|
|
159062
|
-
function fix(type2,
|
|
159098
|
+
function fix(type2, fixId54, fixAllDescription) {
|
|
159063
159099
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange29(t, sourceFile, typeNode, type2, checker));
|
|
159064
|
-
return createCodeFixAction("jdocTypes", changes, [Diagnostics.Change_0_to_1, original, checker.typeToString(type2)],
|
|
159100
|
+
return createCodeFixAction("jdocTypes", changes, [Diagnostics.Change_0_to_1, original, checker.typeToString(type2)], fixId54, fixAllDescription);
|
|
159065
159101
|
}
|
|
159066
159102
|
},
|
|
159067
159103
|
fixIds: [fixIdPlain, fixIdNullable],
|
|
159068
159104
|
getAllCodeActions(context) {
|
|
159069
|
-
const { fixId:
|
|
159105
|
+
const { fixId: fixId54, program, sourceFile } = context;
|
|
159070
159106
|
const checker = program.getTypeChecker();
|
|
159071
159107
|
return codeFixAll(context, errorCodes45, (changes, err) => {
|
|
159072
159108
|
const info = getInfo15(err.file, err.start, checker);
|
|
159073
159109
|
if (!info)
|
|
159074
159110
|
return;
|
|
159075
159111
|
const { typeNode, type } = info;
|
|
159076
|
-
const fixedType = typeNode.kind === 314 /* JSDocNullableType */ &&
|
|
159112
|
+
const fixedType = typeNode.kind === 314 /* JSDocNullableType */ && fixId54 === fixIdNullable ? checker.getNullableType(type, 32768 /* Undefined */) : type;
|
|
159077
159113
|
doChange29(changes, sourceFile, typeNode, fixedType, checker);
|
|
159078
159114
|
});
|
|
159079
159115
|
}
|
|
@@ -159168,28 +159204,909 @@ function getCallName(sourceFile, start) {
|
|
|
159168
159204
|
return void 0;
|
|
159169
159205
|
}
|
|
159170
159206
|
|
|
159171
|
-
// src/services/codefixes/
|
|
159172
|
-
var fixId36 = "
|
|
159207
|
+
// src/services/codefixes/fixMissingTypeAnnotationOnExports.ts
|
|
159208
|
+
var fixId36 = "fixMissingTypeAnnotationOnExports";
|
|
159209
|
+
var addAnnotationFix = "add-annotation";
|
|
159210
|
+
var addInlineTypeAssertion = "add-type-assertion";
|
|
159211
|
+
var extractExpression = "extract-expression";
|
|
159173
159212
|
var errorCodes47 = [
|
|
159213
|
+
Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159214
|
+
Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159215
|
+
Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159216
|
+
Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159217
|
+
Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159218
|
+
Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159219
|
+
Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159220
|
+
Diagnostics.Binding_elements_can_t_be_exported_directly_with_isolatedDeclarations.code,
|
|
159221
|
+
Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations.code,
|
|
159222
|
+
Diagnostics.Enum_member_initializers_must_be_computable_without_references_to_external_symbols_with_isolatedDeclarations.code,
|
|
159223
|
+
Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations.code,
|
|
159224
|
+
Diagnostics.Objects_that_contain_shorthand_properties_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159225
|
+
Diagnostics.Objects_that_contain_spread_assignments_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159226
|
+
Diagnostics.Arrays_with_spread_elements_can_t_inferred_with_isolatedDeclarations.code,
|
|
159227
|
+
Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159228
|
+
Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations.code,
|
|
159229
|
+
Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function.code,
|
|
159230
|
+
Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations.code,
|
|
159231
|
+
Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_the_type_explicit.code
|
|
159232
|
+
];
|
|
159233
|
+
var canHaveTypeAnnotation = /* @__PURE__ */ new Set([
|
|
159234
|
+
177 /* GetAccessor */,
|
|
159235
|
+
174 /* MethodDeclaration */,
|
|
159236
|
+
172 /* PropertyDeclaration */,
|
|
159237
|
+
262 /* FunctionDeclaration */,
|
|
159238
|
+
218 /* FunctionExpression */,
|
|
159239
|
+
219 /* ArrowFunction */,
|
|
159240
|
+
260 /* VariableDeclaration */,
|
|
159241
|
+
169 /* Parameter */,
|
|
159242
|
+
277 /* ExportAssignment */,
|
|
159243
|
+
263 /* ClassDeclaration */,
|
|
159244
|
+
206 /* ObjectBindingPattern */,
|
|
159245
|
+
207 /* ArrayBindingPattern */
|
|
159246
|
+
]);
|
|
159247
|
+
var declarationEmitNodeBuilderFlags2 = 1024 /* MultilineObjectLiterals */ | 2048 /* WriteClassExpressionAsTypeLiteral */ | 4096 /* UseTypeOfFunction */ | 8 /* UseStructuralFallback */ | 524288 /* AllowEmptyTuple */ | 4 /* GenerateNamesForShadowedTypeParams */ | 1 /* NoTruncation */ | 1073741824 /* WriteComputedProps */;
|
|
159248
|
+
registerCodeFix({
|
|
159249
|
+
errorCodes: errorCodes47,
|
|
159250
|
+
fixIds: [fixId36],
|
|
159251
|
+
getCodeActions(context) {
|
|
159252
|
+
const fixes = [];
|
|
159253
|
+
addCodeAction(addAnnotationFix, fixes, context, 0 /* Full */, (f) => f.addTypeAnnotation(context.span));
|
|
159254
|
+
addCodeAction(addAnnotationFix, fixes, context, 1 /* Relative */, (f) => f.addTypeAnnotation(context.span));
|
|
159255
|
+
addCodeAction(addAnnotationFix, fixes, context, 2 /* Widened */, (f) => f.addTypeAnnotation(context.span));
|
|
159256
|
+
addCodeAction(addInlineTypeAssertion, fixes, context, 0 /* Full */, (f) => f.addInlineAssertion(context.span));
|
|
159257
|
+
addCodeAction(addInlineTypeAssertion, fixes, context, 1 /* Relative */, (f) => f.addInlineAssertion(context.span));
|
|
159258
|
+
addCodeAction(addAnnotationFix, fixes, context, 2 /* Widened */, (f) => f.addInlineAssertion(context.span));
|
|
159259
|
+
addCodeAction(extractExpression, fixes, context, 0 /* Full */, (f) => f.extractAsVariable(context.span));
|
|
159260
|
+
return fixes;
|
|
159261
|
+
},
|
|
159262
|
+
getAllCodeActions: (context) => {
|
|
159263
|
+
const changes = withContext(context, 0 /* Full */, (f) => {
|
|
159264
|
+
eachDiagnostic(context, errorCodes47, (diag2) => {
|
|
159265
|
+
f.addTypeAnnotation(diag2);
|
|
159266
|
+
});
|
|
159267
|
+
});
|
|
159268
|
+
return createCombinedCodeActions(changes.textChanges);
|
|
159269
|
+
}
|
|
159270
|
+
});
|
|
159271
|
+
function addCodeAction(fixName8, fixes, context, typePrintMode, cb) {
|
|
159272
|
+
const changes = withContext(context, typePrintMode, cb);
|
|
159273
|
+
if (changes.result && changes.textChanges.length) {
|
|
159274
|
+
fixes.push(createCodeFixAction(
|
|
159275
|
+
fixName8,
|
|
159276
|
+
changes.textChanges,
|
|
159277
|
+
changes.result,
|
|
159278
|
+
fixId36,
|
|
159279
|
+
Diagnostics.Add_all_missing_type_annotations
|
|
159280
|
+
));
|
|
159281
|
+
}
|
|
159282
|
+
}
|
|
159283
|
+
function withContext(context, typePrintMode, cb) {
|
|
159284
|
+
const emptyInferenceResult = { typeNode: void 0, mutatedTarget: false };
|
|
159285
|
+
const changeTracker = ts_textChanges_exports.ChangeTracker.fromContext(context);
|
|
159286
|
+
const sourceFile = context.sourceFile;
|
|
159287
|
+
const program = context.program;
|
|
159288
|
+
const typeChecker = program.getTypeChecker();
|
|
159289
|
+
const emitResolver = typeChecker.getEmitResolver();
|
|
159290
|
+
const scriptTarget = getEmitScriptTarget(program.getCompilerOptions());
|
|
159291
|
+
const importAdder = createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
159292
|
+
const fixedNodes = /* @__PURE__ */ new Set();
|
|
159293
|
+
const expandoPropertiesAdded = /* @__PURE__ */ new Set();
|
|
159294
|
+
const typePrinter = createPrinter({
|
|
159295
|
+
preserveSourceNewlines: false
|
|
159296
|
+
});
|
|
159297
|
+
const result = cb({ addTypeAnnotation, addInlineAssertion, extractAsVariable });
|
|
159298
|
+
importAdder.writeFixes(changeTracker);
|
|
159299
|
+
return {
|
|
159300
|
+
result,
|
|
159301
|
+
textChanges: changeTracker.getChanges()
|
|
159302
|
+
};
|
|
159303
|
+
function addTypeAnnotation(span) {
|
|
159304
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159305
|
+
const expandoFunction = findExpandoFunction(nodeWithDiag);
|
|
159306
|
+
if (expandoFunction) {
|
|
159307
|
+
if (isFunctionDeclaration(expandoFunction)) {
|
|
159308
|
+
return createNamespaceForExpandoProperties(expandoFunction);
|
|
159309
|
+
}
|
|
159310
|
+
return fixIsolatedDeclarationError(expandoFunction);
|
|
159311
|
+
}
|
|
159312
|
+
const nodeMissingType = findAncestorWithMissingType(nodeWithDiag);
|
|
159313
|
+
if (nodeMissingType) {
|
|
159314
|
+
return fixIsolatedDeclarationError(nodeMissingType);
|
|
159315
|
+
}
|
|
159316
|
+
return void 0;
|
|
159317
|
+
}
|
|
159318
|
+
function createNamespaceForExpandoProperties(expandoFunc) {
|
|
159319
|
+
var _a;
|
|
159320
|
+
if (expandoPropertiesAdded == null ? void 0 : expandoPropertiesAdded.has(expandoFunc))
|
|
159321
|
+
return void 0;
|
|
159322
|
+
expandoPropertiesAdded == null ? void 0 : expandoPropertiesAdded.add(expandoFunc);
|
|
159323
|
+
const type = typeChecker.getTypeAtLocation(expandoFunc);
|
|
159324
|
+
const elements = typeChecker.getPropertiesOfType(type);
|
|
159325
|
+
if (!expandoFunc.name || elements.length === 0)
|
|
159326
|
+
return void 0;
|
|
159327
|
+
const newProperties = [];
|
|
159328
|
+
for (const symbol of elements) {
|
|
159329
|
+
if (!isIdentifierText(symbol.name, getEmitScriptTarget(program.getCompilerOptions())))
|
|
159330
|
+
continue;
|
|
159331
|
+
if (symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration))
|
|
159332
|
+
continue;
|
|
159333
|
+
newProperties.push(factory.createVariableStatement(
|
|
159334
|
+
[factory.createModifier(95 /* ExportKeyword */)],
|
|
159335
|
+
factory.createVariableDeclarationList(
|
|
159336
|
+
[factory.createVariableDeclaration(
|
|
159337
|
+
symbol.name,
|
|
159338
|
+
/*exclamationToken*/
|
|
159339
|
+
void 0,
|
|
159340
|
+
typeToTypeNode2(typeChecker.getTypeOfSymbol(symbol), expandoFunc),
|
|
159341
|
+
/*initializer*/
|
|
159342
|
+
void 0
|
|
159343
|
+
)]
|
|
159344
|
+
)
|
|
159345
|
+
));
|
|
159346
|
+
}
|
|
159347
|
+
if (newProperties.length === 0)
|
|
159348
|
+
return void 0;
|
|
159349
|
+
const modifiers = [];
|
|
159350
|
+
if ((_a = expandoFunc.modifiers) == null ? void 0 : _a.some((modifier) => modifier.kind === 95 /* ExportKeyword */)) {
|
|
159351
|
+
modifiers.push(factory.createModifier(95 /* ExportKeyword */));
|
|
159352
|
+
}
|
|
159353
|
+
modifiers.push(factory.createModifier(138 /* DeclareKeyword */));
|
|
159354
|
+
const namespace = factory.createModuleDeclaration(
|
|
159355
|
+
modifiers,
|
|
159356
|
+
expandoFunc.name,
|
|
159357
|
+
factory.createModuleBlock(newProperties),
|
|
159358
|
+
/*flags*/
|
|
159359
|
+
32 /* Namespace */ | 128 /* ExportContext */ | 33554432 /* Ambient */ | 101441536 /* ContextFlags */
|
|
159360
|
+
);
|
|
159361
|
+
changeTracker.insertNodeAfter(sourceFile, expandoFunc, namespace);
|
|
159362
|
+
return [Diagnostics.Annotate_types_of_properties_expando_function_in_a_namespace];
|
|
159363
|
+
}
|
|
159364
|
+
function needsParenthesizedExpressionForAssertion(node) {
|
|
159365
|
+
return !isEntityNameExpression(node) && !isCallExpression(node) && !isObjectLiteralExpression(node) && !isArrayLiteralExpression(node);
|
|
159366
|
+
}
|
|
159367
|
+
function createAsExpression(node, type) {
|
|
159368
|
+
if (needsParenthesizedExpressionForAssertion(node)) {
|
|
159369
|
+
node = factory.createParenthesizedExpression(node);
|
|
159370
|
+
}
|
|
159371
|
+
return factory.createAsExpression(node, type);
|
|
159372
|
+
}
|
|
159373
|
+
function createSatisfiesAsExpression(node, type) {
|
|
159374
|
+
if (needsParenthesizedExpressionForAssertion(node)) {
|
|
159375
|
+
node = factory.createParenthesizedExpression(node);
|
|
159376
|
+
}
|
|
159377
|
+
return factory.createAsExpression(factory.createSatisfiesExpression(node, getSynthesizedDeepClone(type)), type);
|
|
159378
|
+
}
|
|
159379
|
+
function addInlineAssertion(span) {
|
|
159380
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159381
|
+
const expandoFunction = findExpandoFunction(nodeWithDiag);
|
|
159382
|
+
if (expandoFunction)
|
|
159383
|
+
return;
|
|
159384
|
+
const targetNode = findBestFittingNode(nodeWithDiag, span);
|
|
159385
|
+
if (!targetNode || isValueSignatureDeclaration(targetNode) || isValueSignatureDeclaration(targetNode.parent))
|
|
159386
|
+
return;
|
|
159387
|
+
const isExpressionTarget = isExpression(targetNode);
|
|
159388
|
+
const isShorthandPropertyAssignmentTarget = isShorthandPropertyAssignment(targetNode);
|
|
159389
|
+
if (!isShorthandPropertyAssignmentTarget && isDeclaration(targetNode)) {
|
|
159390
|
+
return void 0;
|
|
159391
|
+
}
|
|
159392
|
+
if (findAncestor(targetNode, isBindingPattern)) {
|
|
159393
|
+
return void 0;
|
|
159394
|
+
}
|
|
159395
|
+
if (findAncestor(targetNode, isEnumMember)) {
|
|
159396
|
+
return void 0;
|
|
159397
|
+
}
|
|
159398
|
+
if (isExpressionTarget && findAncestor(targetNode, isHeritageClause)) {
|
|
159399
|
+
return void 0;
|
|
159400
|
+
}
|
|
159401
|
+
if (isSpreadElement(targetNode)) {
|
|
159402
|
+
return void 0;
|
|
159403
|
+
}
|
|
159404
|
+
const variableDeclaration = findAncestor(targetNode, isVariableDeclaration);
|
|
159405
|
+
const type = variableDeclaration && typeChecker.getTypeAtLocation(variableDeclaration);
|
|
159406
|
+
if (type && type.flags & 8192 /* UniqueESSymbol */) {
|
|
159407
|
+
return void 0;
|
|
159408
|
+
}
|
|
159409
|
+
if (!(isExpressionTarget || isShorthandPropertyAssignmentTarget))
|
|
159410
|
+
return void 0;
|
|
159411
|
+
const { typeNode, mutatedTarget } = inferType(targetNode, type);
|
|
159412
|
+
if (!typeNode || mutatedTarget)
|
|
159413
|
+
return void 0;
|
|
159414
|
+
if (isShorthandPropertyAssignmentTarget) {
|
|
159415
|
+
changeTracker.insertNodeAt(
|
|
159416
|
+
sourceFile,
|
|
159417
|
+
targetNode.end,
|
|
159418
|
+
createAsExpression(
|
|
159419
|
+
getSynthesizedDeepClone(targetNode.name),
|
|
159420
|
+
typeNode
|
|
159421
|
+
),
|
|
159422
|
+
{
|
|
159423
|
+
prefix: ": "
|
|
159424
|
+
}
|
|
159425
|
+
);
|
|
159426
|
+
} else if (isExpressionTarget) {
|
|
159427
|
+
changeTracker.replaceNode(
|
|
159428
|
+
sourceFile,
|
|
159429
|
+
targetNode,
|
|
159430
|
+
createSatisfiesAsExpression(
|
|
159431
|
+
getSynthesizedDeepClone(targetNode),
|
|
159432
|
+
typeNode
|
|
159433
|
+
)
|
|
159434
|
+
);
|
|
159435
|
+
} else {
|
|
159436
|
+
Debug.assertNever(targetNode);
|
|
159437
|
+
}
|
|
159438
|
+
return [Diagnostics.Add_satisfies_and_an_inline_type_assertion_with_0, typeToStringForDiag(typeNode)];
|
|
159439
|
+
}
|
|
159440
|
+
function extractAsVariable(span) {
|
|
159441
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159442
|
+
const targetNode = findBestFittingNode(nodeWithDiag, span);
|
|
159443
|
+
if (!targetNode || isValueSignatureDeclaration(targetNode) || isValueSignatureDeclaration(targetNode.parent))
|
|
159444
|
+
return;
|
|
159445
|
+
const isExpressionTarget = isExpression(targetNode);
|
|
159446
|
+
if (!isExpressionTarget)
|
|
159447
|
+
return;
|
|
159448
|
+
if (isArrayLiteralExpression(targetNode)) {
|
|
159449
|
+
changeTracker.replaceNode(
|
|
159450
|
+
sourceFile,
|
|
159451
|
+
targetNode,
|
|
159452
|
+
createAsExpression(targetNode, factory.createTypeReferenceNode("const"))
|
|
159453
|
+
);
|
|
159454
|
+
return [Diagnostics.Mark_array_literal_as_const];
|
|
159455
|
+
}
|
|
159456
|
+
const parentPropertyAssignment = findAncestor(targetNode, isPropertyAssignment);
|
|
159457
|
+
if (parentPropertyAssignment) {
|
|
159458
|
+
if (parentPropertyAssignment === targetNode.parent && isEntityNameExpression(targetNode))
|
|
159459
|
+
return;
|
|
159460
|
+
const tempName = factory.createUniqueName(
|
|
159461
|
+
getIdentifierForNode(targetNode, sourceFile, typeChecker, sourceFile),
|
|
159462
|
+
16 /* Optimistic */
|
|
159463
|
+
);
|
|
159464
|
+
let replacementTarget = targetNode;
|
|
159465
|
+
let initializationNode = targetNode;
|
|
159466
|
+
if (isSpreadElement(replacementTarget)) {
|
|
159467
|
+
replacementTarget = walkUpParenthesizedExpressions(replacementTarget.parent);
|
|
159468
|
+
if (isConstAssertion2(replacementTarget.parent)) {
|
|
159469
|
+
initializationNode = replacementTarget = replacementTarget.parent;
|
|
159470
|
+
} else {
|
|
159471
|
+
initializationNode = createAsExpression(
|
|
159472
|
+
replacementTarget,
|
|
159473
|
+
factory.createTypeReferenceNode("const")
|
|
159474
|
+
);
|
|
159475
|
+
}
|
|
159476
|
+
}
|
|
159477
|
+
if (isEntityNameExpression(replacementTarget))
|
|
159478
|
+
return void 0;
|
|
159479
|
+
const variableDefinition = factory.createVariableStatement(
|
|
159480
|
+
/*modifiers*/
|
|
159481
|
+
void 0,
|
|
159482
|
+
factory.createVariableDeclarationList([
|
|
159483
|
+
factory.createVariableDeclaration(
|
|
159484
|
+
tempName,
|
|
159485
|
+
/*exclamationToken*/
|
|
159486
|
+
void 0,
|
|
159487
|
+
/*type*/
|
|
159488
|
+
void 0,
|
|
159489
|
+
initializationNode
|
|
159490
|
+
)
|
|
159491
|
+
], 2 /* Const */)
|
|
159492
|
+
);
|
|
159493
|
+
const statement = findAncestor(targetNode, isStatement);
|
|
159494
|
+
changeTracker.insertNodeBefore(sourceFile, statement, variableDefinition);
|
|
159495
|
+
changeTracker.replaceNode(
|
|
159496
|
+
sourceFile,
|
|
159497
|
+
replacementTarget,
|
|
159498
|
+
factory.createAsExpression(
|
|
159499
|
+
factory.cloneNode(tempName),
|
|
159500
|
+
factory.createTypeQueryNode(
|
|
159501
|
+
factory.cloneNode(tempName)
|
|
159502
|
+
)
|
|
159503
|
+
)
|
|
159504
|
+
);
|
|
159505
|
+
return [Diagnostics.Extract_to_variable_and_replace_with_0_as_typeof_0, typeToStringForDiag(tempName)];
|
|
159506
|
+
}
|
|
159507
|
+
}
|
|
159508
|
+
function findExpandoFunction(node) {
|
|
159509
|
+
const expandoDeclaration = findAncestor(node, (n) => isStatement(n) ? "quit" : isExpandoPropertyDeclaration(n));
|
|
159510
|
+
if (expandoDeclaration && isExpandoPropertyDeclaration(expandoDeclaration)) {
|
|
159511
|
+
let assignmentTarget = expandoDeclaration;
|
|
159512
|
+
if (isBinaryExpression(assignmentTarget)) {
|
|
159513
|
+
assignmentTarget = assignmentTarget.left;
|
|
159514
|
+
if (!isExpandoPropertyDeclaration(assignmentTarget))
|
|
159515
|
+
return void 0;
|
|
159516
|
+
}
|
|
159517
|
+
const targetType = typeChecker.getTypeAtLocation(assignmentTarget.expression);
|
|
159518
|
+
if (!targetType)
|
|
159519
|
+
return;
|
|
159520
|
+
const properties = typeChecker.getPropertiesOfType(targetType);
|
|
159521
|
+
if (some(properties, (p) => p.valueDeclaration === expandoDeclaration || p.valueDeclaration === expandoDeclaration.parent)) {
|
|
159522
|
+
const fn = targetType.symbol.valueDeclaration;
|
|
159523
|
+
if (fn) {
|
|
159524
|
+
if (isFunctionExpressionOrArrowFunction(fn) && isVariableDeclaration(fn.parent)) {
|
|
159525
|
+
return fn.parent;
|
|
159526
|
+
}
|
|
159527
|
+
if (isFunctionDeclaration(fn)) {
|
|
159528
|
+
return fn;
|
|
159529
|
+
}
|
|
159530
|
+
}
|
|
159531
|
+
}
|
|
159532
|
+
}
|
|
159533
|
+
return void 0;
|
|
159534
|
+
}
|
|
159535
|
+
function fixIsolatedDeclarationError(node) {
|
|
159536
|
+
if (fixedNodes == null ? void 0 : fixedNodes.has(node))
|
|
159537
|
+
return void 0;
|
|
159538
|
+
fixedNodes == null ? void 0 : fixedNodes.add(node);
|
|
159539
|
+
switch (node.kind) {
|
|
159540
|
+
case 169 /* Parameter */:
|
|
159541
|
+
case 172 /* PropertyDeclaration */:
|
|
159542
|
+
case 260 /* VariableDeclaration */:
|
|
159543
|
+
return addTypeToVariableLike(node);
|
|
159544
|
+
case 219 /* ArrowFunction */:
|
|
159545
|
+
case 218 /* FunctionExpression */:
|
|
159546
|
+
case 262 /* FunctionDeclaration */:
|
|
159547
|
+
case 174 /* MethodDeclaration */:
|
|
159548
|
+
case 177 /* GetAccessor */:
|
|
159549
|
+
return addTypeToSignatureDeclaration(node, sourceFile);
|
|
159550
|
+
case 277 /* ExportAssignment */:
|
|
159551
|
+
return transformExportAssignment(node);
|
|
159552
|
+
case 263 /* ClassDeclaration */:
|
|
159553
|
+
return transformExtendsClauseWithExpression(node);
|
|
159554
|
+
case 206 /* ObjectBindingPattern */:
|
|
159555
|
+
case 207 /* ArrayBindingPattern */:
|
|
159556
|
+
return transformDestructuringPatterns(node);
|
|
159557
|
+
default:
|
|
159558
|
+
throw new Error(`Cannot find a fix for the given node ${node.kind}`);
|
|
159559
|
+
}
|
|
159560
|
+
}
|
|
159561
|
+
function addTypeToSignatureDeclaration(func, sourceFile2) {
|
|
159562
|
+
if (func.type) {
|
|
159563
|
+
return;
|
|
159564
|
+
}
|
|
159565
|
+
const { typeNode } = inferType(func);
|
|
159566
|
+
if (typeNode) {
|
|
159567
|
+
changeTracker.tryInsertTypeAnnotation(
|
|
159568
|
+
sourceFile2,
|
|
159569
|
+
func,
|
|
159570
|
+
typeNode
|
|
159571
|
+
);
|
|
159572
|
+
return [Diagnostics.Add_return_type_0, typeToStringForDiag(typeNode)];
|
|
159573
|
+
}
|
|
159574
|
+
}
|
|
159575
|
+
function transformExportAssignment(defaultExport) {
|
|
159576
|
+
if (defaultExport.isExportEquals) {
|
|
159577
|
+
return;
|
|
159578
|
+
}
|
|
159579
|
+
const { typeNode } = inferType(defaultExport.expression);
|
|
159580
|
+
if (!typeNode)
|
|
159581
|
+
return void 0;
|
|
159582
|
+
const defaultIdentifier = factory.createUniqueName("_default");
|
|
159583
|
+
changeTracker.replaceNodeWithNodes(sourceFile, defaultExport, [
|
|
159584
|
+
factory.createVariableStatement(
|
|
159585
|
+
/*modifiers*/
|
|
159586
|
+
void 0,
|
|
159587
|
+
factory.createVariableDeclarationList(
|
|
159588
|
+
[factory.createVariableDeclaration(
|
|
159589
|
+
defaultIdentifier,
|
|
159590
|
+
/*exclamationToken*/
|
|
159591
|
+
void 0,
|
|
159592
|
+
typeNode,
|
|
159593
|
+
defaultExport.expression
|
|
159594
|
+
)],
|
|
159595
|
+
2 /* Const */
|
|
159596
|
+
)
|
|
159597
|
+
),
|
|
159598
|
+
factory.updateExportAssignment(defaultExport, defaultExport == null ? void 0 : defaultExport.modifiers, defaultIdentifier)
|
|
159599
|
+
]);
|
|
159600
|
+
return [
|
|
159601
|
+
Diagnostics.Extract_default_export_to_variable
|
|
159602
|
+
];
|
|
159603
|
+
}
|
|
159604
|
+
function transformExtendsClauseWithExpression(classDecl) {
|
|
159605
|
+
var _a, _b;
|
|
159606
|
+
const extendsClause = (_a = classDecl.heritageClauses) == null ? void 0 : _a.find((p) => p.token === 96 /* ExtendsKeyword */);
|
|
159607
|
+
const heritageExpression = extendsClause == null ? void 0 : extendsClause.types[0];
|
|
159608
|
+
if (!heritageExpression) {
|
|
159609
|
+
return void 0;
|
|
159610
|
+
}
|
|
159611
|
+
const { typeNode: heritageTypeNode } = inferType(heritageExpression.expression);
|
|
159612
|
+
if (!heritageTypeNode) {
|
|
159613
|
+
return void 0;
|
|
159614
|
+
}
|
|
159615
|
+
const baseClassName = factory.createUniqueName(
|
|
159616
|
+
classDecl.name ? classDecl.name.text + "Base" : "Anonymous",
|
|
159617
|
+
16 /* Optimistic */
|
|
159618
|
+
);
|
|
159619
|
+
const heritageVariable = factory.createVariableStatement(
|
|
159620
|
+
/*modifiers*/
|
|
159621
|
+
void 0,
|
|
159622
|
+
factory.createVariableDeclarationList(
|
|
159623
|
+
[factory.createVariableDeclaration(
|
|
159624
|
+
baseClassName,
|
|
159625
|
+
/*exclamationToken*/
|
|
159626
|
+
void 0,
|
|
159627
|
+
heritageTypeNode,
|
|
159628
|
+
heritageExpression.expression
|
|
159629
|
+
)],
|
|
159630
|
+
2 /* Const */
|
|
159631
|
+
)
|
|
159632
|
+
);
|
|
159633
|
+
changeTracker.insertNodeBefore(sourceFile, classDecl, heritageVariable);
|
|
159634
|
+
const trailingComments = getTrailingCommentRanges(sourceFile.text, heritageExpression.end);
|
|
159635
|
+
const realEnd = ((_b = trailingComments == null ? void 0 : trailingComments[trailingComments.length - 1]) == null ? void 0 : _b.end) ?? heritageExpression.end;
|
|
159636
|
+
changeTracker.replaceRange(
|
|
159637
|
+
sourceFile,
|
|
159638
|
+
{
|
|
159639
|
+
pos: heritageExpression.getFullStart(),
|
|
159640
|
+
end: realEnd
|
|
159641
|
+
},
|
|
159642
|
+
baseClassName,
|
|
159643
|
+
{
|
|
159644
|
+
prefix: " "
|
|
159645
|
+
}
|
|
159646
|
+
);
|
|
159647
|
+
return [Diagnostics.Extract_base_class_to_variable];
|
|
159648
|
+
}
|
|
159649
|
+
let ExpressionType;
|
|
159650
|
+
((ExpressionType2) => {
|
|
159651
|
+
ExpressionType2[ExpressionType2["Text"] = 0] = "Text";
|
|
159652
|
+
ExpressionType2[ExpressionType2["Computed"] = 1] = "Computed";
|
|
159653
|
+
ExpressionType2[ExpressionType2["ArrayAccess"] = 2] = "ArrayAccess";
|
|
159654
|
+
ExpressionType2[ExpressionType2["Identifier"] = 3] = "Identifier";
|
|
159655
|
+
})(ExpressionType || (ExpressionType = {}));
|
|
159656
|
+
function transformDestructuringPatterns(bindingPattern) {
|
|
159657
|
+
var _a;
|
|
159658
|
+
const enclosingVariableDeclaration = bindingPattern.parent;
|
|
159659
|
+
const enclosingVarStmt = bindingPattern.parent.parent.parent;
|
|
159660
|
+
if (!enclosingVariableDeclaration.initializer)
|
|
159661
|
+
return void 0;
|
|
159662
|
+
let baseExpr;
|
|
159663
|
+
const newNodes = [];
|
|
159664
|
+
if (!isIdentifier(enclosingVariableDeclaration.initializer)) {
|
|
159665
|
+
const tempHolderForReturn = factory.createUniqueName("dest", 16 /* Optimistic */);
|
|
159666
|
+
baseExpr = { expression: { kind: 3 /* Identifier */, identifier: tempHolderForReturn } };
|
|
159667
|
+
newNodes.push(factory.createVariableStatement(
|
|
159668
|
+
/*modifiers*/
|
|
159669
|
+
void 0,
|
|
159670
|
+
factory.createVariableDeclarationList(
|
|
159671
|
+
[factory.createVariableDeclaration(
|
|
159672
|
+
tempHolderForReturn,
|
|
159673
|
+
/*exclamationToken*/
|
|
159674
|
+
void 0,
|
|
159675
|
+
/*type*/
|
|
159676
|
+
void 0,
|
|
159677
|
+
enclosingVariableDeclaration.initializer
|
|
159678
|
+
)],
|
|
159679
|
+
2 /* Const */
|
|
159680
|
+
)
|
|
159681
|
+
));
|
|
159682
|
+
} else {
|
|
159683
|
+
baseExpr = { expression: { kind: 3 /* Identifier */, identifier: enclosingVariableDeclaration.initializer } };
|
|
159684
|
+
}
|
|
159685
|
+
const bindingElements = [];
|
|
159686
|
+
if (isArrayBindingPattern(bindingPattern)) {
|
|
159687
|
+
addArrayBindingPatterns(bindingPattern, bindingElements, baseExpr);
|
|
159688
|
+
} else {
|
|
159689
|
+
addObjectBindingPatterns(bindingPattern, bindingElements, baseExpr);
|
|
159690
|
+
}
|
|
159691
|
+
const expressionToVar = /* @__PURE__ */ new Map();
|
|
159692
|
+
for (const bindingElement of bindingElements) {
|
|
159693
|
+
if (bindingElement.element.propertyName && isComputedPropertyName(bindingElement.element.propertyName)) {
|
|
159694
|
+
const computedExpression = bindingElement.element.propertyName.expression;
|
|
159695
|
+
const identifierForComputedProperty = factory.getGeneratedNameForNode(computedExpression);
|
|
159696
|
+
const variableDecl = factory.createVariableDeclaration(
|
|
159697
|
+
identifierForComputedProperty,
|
|
159698
|
+
/*exclamationToken*/
|
|
159699
|
+
void 0,
|
|
159700
|
+
/*type*/
|
|
159701
|
+
void 0,
|
|
159702
|
+
computedExpression
|
|
159703
|
+
);
|
|
159704
|
+
const variableList = factory.createVariableDeclarationList([variableDecl], 2 /* Const */);
|
|
159705
|
+
const variableStatement = factory.createVariableStatement(
|
|
159706
|
+
/*modifiers*/
|
|
159707
|
+
void 0,
|
|
159708
|
+
variableList
|
|
159709
|
+
);
|
|
159710
|
+
newNodes.push(variableStatement);
|
|
159711
|
+
expressionToVar.set(computedExpression, identifierForComputedProperty);
|
|
159712
|
+
}
|
|
159713
|
+
const name = bindingElement.element.name;
|
|
159714
|
+
if (isArrayBindingPattern(name)) {
|
|
159715
|
+
addArrayBindingPatterns(name, bindingElements, bindingElement);
|
|
159716
|
+
} else if (isObjectBindingPattern(name)) {
|
|
159717
|
+
addObjectBindingPatterns(name, bindingElements, bindingElement);
|
|
159718
|
+
} else {
|
|
159719
|
+
const { typeNode } = inferType(name);
|
|
159720
|
+
let variableInitializer = createChainedExpression(bindingElement, expressionToVar);
|
|
159721
|
+
if (bindingElement.element.initializer) {
|
|
159722
|
+
const propertyName = (_a = bindingElement.element) == null ? void 0 : _a.propertyName;
|
|
159723
|
+
const tempName = factory.createUniqueName(
|
|
159724
|
+
propertyName && isIdentifier(propertyName) ? propertyName.text : "temp",
|
|
159725
|
+
16 /* Optimistic */
|
|
159726
|
+
);
|
|
159727
|
+
newNodes.push(factory.createVariableStatement(
|
|
159728
|
+
/*modifiers*/
|
|
159729
|
+
void 0,
|
|
159730
|
+
factory.createVariableDeclarationList(
|
|
159731
|
+
[factory.createVariableDeclaration(
|
|
159732
|
+
tempName,
|
|
159733
|
+
/*exclamationToken*/
|
|
159734
|
+
void 0,
|
|
159735
|
+
/*type*/
|
|
159736
|
+
void 0,
|
|
159737
|
+
variableInitializer
|
|
159738
|
+
)],
|
|
159739
|
+
2 /* Const */
|
|
159740
|
+
)
|
|
159741
|
+
));
|
|
159742
|
+
variableInitializer = factory.createConditionalExpression(
|
|
159743
|
+
factory.createBinaryExpression(
|
|
159744
|
+
tempName,
|
|
159745
|
+
factory.createToken(37 /* EqualsEqualsEqualsToken */),
|
|
159746
|
+
factory.createIdentifier("undefined")
|
|
159747
|
+
),
|
|
159748
|
+
factory.createToken(58 /* QuestionToken */),
|
|
159749
|
+
bindingElement.element.initializer,
|
|
159750
|
+
factory.createToken(59 /* ColonToken */),
|
|
159751
|
+
variableInitializer
|
|
159752
|
+
);
|
|
159753
|
+
}
|
|
159754
|
+
const exportModifier = hasSyntacticModifier(enclosingVarStmt, 32 /* Export */) ? [factory.createToken(95 /* ExportKeyword */)] : void 0;
|
|
159755
|
+
newNodes.push(factory.createVariableStatement(
|
|
159756
|
+
exportModifier,
|
|
159757
|
+
factory.createVariableDeclarationList(
|
|
159758
|
+
[factory.createVariableDeclaration(
|
|
159759
|
+
name,
|
|
159760
|
+
/*exclamationToken*/
|
|
159761
|
+
void 0,
|
|
159762
|
+
typeNode,
|
|
159763
|
+
variableInitializer
|
|
159764
|
+
)],
|
|
159765
|
+
2 /* Const */
|
|
159766
|
+
)
|
|
159767
|
+
));
|
|
159768
|
+
}
|
|
159769
|
+
}
|
|
159770
|
+
if (enclosingVarStmt.declarationList.declarations.length > 1) {
|
|
159771
|
+
newNodes.push(factory.updateVariableStatement(
|
|
159772
|
+
enclosingVarStmt,
|
|
159773
|
+
enclosingVarStmt.modifiers,
|
|
159774
|
+
factory.updateVariableDeclarationList(
|
|
159775
|
+
enclosingVarStmt.declarationList,
|
|
159776
|
+
enclosingVarStmt.declarationList.declarations.filter((node) => node !== bindingPattern.parent)
|
|
159777
|
+
)
|
|
159778
|
+
));
|
|
159779
|
+
}
|
|
159780
|
+
changeTracker.replaceNodeWithNodes(sourceFile, enclosingVarStmt, newNodes);
|
|
159781
|
+
return [
|
|
159782
|
+
Diagnostics.Extract_binding_expressions_to_variable
|
|
159783
|
+
];
|
|
159784
|
+
}
|
|
159785
|
+
function addArrayBindingPatterns(bindingPattern, bindingElements, parent2) {
|
|
159786
|
+
for (let i = 0; i < bindingPattern.elements.length; ++i) {
|
|
159787
|
+
const element = bindingPattern.elements[i];
|
|
159788
|
+
if (isOmittedExpression(element)) {
|
|
159789
|
+
continue;
|
|
159790
|
+
}
|
|
159791
|
+
bindingElements.push({
|
|
159792
|
+
element,
|
|
159793
|
+
parent: parent2,
|
|
159794
|
+
expression: { kind: 2 /* ArrayAccess */, arrayIndex: i }
|
|
159795
|
+
});
|
|
159796
|
+
}
|
|
159797
|
+
}
|
|
159798
|
+
function addObjectBindingPatterns(bindingPattern, bindingElements, parent2) {
|
|
159799
|
+
for (const bindingElement of bindingPattern.elements) {
|
|
159800
|
+
let name;
|
|
159801
|
+
if (bindingElement.propertyName) {
|
|
159802
|
+
if (isComputedPropertyName(bindingElement.propertyName)) {
|
|
159803
|
+
bindingElements.push({
|
|
159804
|
+
element: bindingElement,
|
|
159805
|
+
parent: parent2,
|
|
159806
|
+
expression: { kind: 1 /* Computed */, computed: bindingElement.propertyName.expression }
|
|
159807
|
+
});
|
|
159808
|
+
continue;
|
|
159809
|
+
} else {
|
|
159810
|
+
name = bindingElement.propertyName.text;
|
|
159811
|
+
}
|
|
159812
|
+
} else {
|
|
159813
|
+
name = bindingElement.name.text;
|
|
159814
|
+
}
|
|
159815
|
+
bindingElements.push({
|
|
159816
|
+
element: bindingElement,
|
|
159817
|
+
parent: parent2,
|
|
159818
|
+
expression: { kind: 0 /* Text */, text: name }
|
|
159819
|
+
});
|
|
159820
|
+
}
|
|
159821
|
+
}
|
|
159822
|
+
function createChainedExpression(expression, expressionToVar) {
|
|
159823
|
+
const reverseTraverse = [expression];
|
|
159824
|
+
while (expression.parent) {
|
|
159825
|
+
expression = expression.parent;
|
|
159826
|
+
reverseTraverse.push(expression);
|
|
159827
|
+
}
|
|
159828
|
+
let chainedExpression = reverseTraverse[reverseTraverse.length - 1].expression.identifier;
|
|
159829
|
+
for (let i = reverseTraverse.length - 2; i >= 0; --i) {
|
|
159830
|
+
const nextSubExpr = reverseTraverse[i].expression;
|
|
159831
|
+
if (nextSubExpr.kind === 0 /* Text */) {
|
|
159832
|
+
chainedExpression = factory.createPropertyAccessChain(
|
|
159833
|
+
chainedExpression,
|
|
159834
|
+
/*questionDotToken*/
|
|
159835
|
+
void 0,
|
|
159836
|
+
factory.createIdentifier(nextSubExpr.text)
|
|
159837
|
+
);
|
|
159838
|
+
} else if (nextSubExpr.kind === 1 /* Computed */) {
|
|
159839
|
+
chainedExpression = factory.createElementAccessExpression(
|
|
159840
|
+
chainedExpression,
|
|
159841
|
+
expressionToVar.get(nextSubExpr.computed)
|
|
159842
|
+
);
|
|
159843
|
+
} else if (nextSubExpr.kind === 2 /* ArrayAccess */) {
|
|
159844
|
+
chainedExpression = factory.createElementAccessExpression(
|
|
159845
|
+
chainedExpression,
|
|
159846
|
+
nextSubExpr.arrayIndex
|
|
159847
|
+
);
|
|
159848
|
+
}
|
|
159849
|
+
}
|
|
159850
|
+
return chainedExpression;
|
|
159851
|
+
}
|
|
159852
|
+
function inferType(node, variableType) {
|
|
159853
|
+
if (typePrintMode === 1 /* Relative */) {
|
|
159854
|
+
return relativeType(node);
|
|
159855
|
+
}
|
|
159856
|
+
let type = isValueSignatureDeclaration(node) ? tryGetReturnType2(node) : typeChecker.getTypeAtLocation(node);
|
|
159857
|
+
if (!type) {
|
|
159858
|
+
return emptyInferenceResult;
|
|
159859
|
+
}
|
|
159860
|
+
if (typePrintMode === 2 /* Widened */) {
|
|
159861
|
+
if (variableType) {
|
|
159862
|
+
type = variableType;
|
|
159863
|
+
}
|
|
159864
|
+
const widenedType = typeChecker.getWidenedLiteralType(type);
|
|
159865
|
+
if (typeChecker.isTypeAssignableTo(widenedType, type)) {
|
|
159866
|
+
return emptyInferenceResult;
|
|
159867
|
+
}
|
|
159868
|
+
type = widenedType;
|
|
159869
|
+
}
|
|
159870
|
+
if (isParameter(node) && emitResolver.requiresAddingImplicitUndefined(node)) {
|
|
159871
|
+
type = typeChecker.getUnionType([typeChecker.getUndefinedType(), type], 0 /* None */);
|
|
159872
|
+
}
|
|
159873
|
+
const flags = (isVariableDeclaration(node) || isPropertyDeclaration(node) && hasSyntacticModifier(node, 256 /* Static */ | 8 /* Readonly */)) && type.flags & 8192 /* UniqueESSymbol */ ? 1048576 /* AllowUniqueESSymbolType */ : 0 /* None */;
|
|
159874
|
+
return {
|
|
159875
|
+
typeNode: typeToTypeNode2(type, findAncestor(node, isDeclaration) ?? sourceFile, flags),
|
|
159876
|
+
mutatedTarget: false
|
|
159877
|
+
};
|
|
159878
|
+
}
|
|
159879
|
+
function createTypeOfFromEntityNameExpression(node) {
|
|
159880
|
+
return factory.createTypeQueryNode(getSynthesizedDeepClone(node));
|
|
159881
|
+
}
|
|
159882
|
+
function typeFromArraySpreadElements(node, name = "temp") {
|
|
159883
|
+
const isConstContext = !!findAncestor(node, isConstAssertion2);
|
|
159884
|
+
if (!isConstContext)
|
|
159885
|
+
return emptyInferenceResult;
|
|
159886
|
+
return typeFromSpreads(
|
|
159887
|
+
node,
|
|
159888
|
+
name,
|
|
159889
|
+
isConstContext,
|
|
159890
|
+
(n) => n.elements,
|
|
159891
|
+
isSpreadElement,
|
|
159892
|
+
factory.createSpreadElement,
|
|
159893
|
+
(props) => factory.createArrayLiteralExpression(
|
|
159894
|
+
props,
|
|
159895
|
+
/*multiLine*/
|
|
159896
|
+
true
|
|
159897
|
+
),
|
|
159898
|
+
(types) => factory.createTupleTypeNode(types.map(factory.createRestTypeNode))
|
|
159899
|
+
);
|
|
159900
|
+
}
|
|
159901
|
+
function typeFromObjectSpreadAssignment(node, name = "temp") {
|
|
159902
|
+
const isConstContext = !!findAncestor(node, isConstAssertion2);
|
|
159903
|
+
return typeFromSpreads(
|
|
159904
|
+
node,
|
|
159905
|
+
name,
|
|
159906
|
+
isConstContext,
|
|
159907
|
+
(n) => n.properties,
|
|
159908
|
+
isSpreadAssignment,
|
|
159909
|
+
factory.createSpreadAssignment,
|
|
159910
|
+
(props) => factory.createObjectLiteralExpression(
|
|
159911
|
+
props,
|
|
159912
|
+
/*multiLine*/
|
|
159913
|
+
true
|
|
159914
|
+
),
|
|
159915
|
+
factory.createIntersectionTypeNode
|
|
159916
|
+
);
|
|
159917
|
+
}
|
|
159918
|
+
function typeFromSpreads(node, name, isConstContext, getChildren, isSpread, createSpread, makeNodeOfKind, finalType) {
|
|
159919
|
+
const intersectionTypes = [];
|
|
159920
|
+
const newSpreads = [];
|
|
159921
|
+
let currentVariableProperties;
|
|
159922
|
+
const statement = findAncestor(node, isStatement);
|
|
159923
|
+
for (const prop of getChildren(node)) {
|
|
159924
|
+
if (isSpread(prop)) {
|
|
159925
|
+
finalizesVariablePart();
|
|
159926
|
+
if (isEntityNameExpression(prop.expression)) {
|
|
159927
|
+
intersectionTypes.push(createTypeOfFromEntityNameExpression(prop.expression));
|
|
159928
|
+
newSpreads.push(prop);
|
|
159929
|
+
} else {
|
|
159930
|
+
makeVariable(prop.expression);
|
|
159931
|
+
}
|
|
159932
|
+
} else {
|
|
159933
|
+
(currentVariableProperties ?? (currentVariableProperties = [])).push(prop);
|
|
159934
|
+
}
|
|
159935
|
+
}
|
|
159936
|
+
if (newSpreads.length === 0) {
|
|
159937
|
+
return emptyInferenceResult;
|
|
159938
|
+
}
|
|
159939
|
+
finalizesVariablePart();
|
|
159940
|
+
changeTracker.replaceNode(sourceFile, node, makeNodeOfKind(newSpreads));
|
|
159941
|
+
return {
|
|
159942
|
+
typeNode: finalType(intersectionTypes),
|
|
159943
|
+
mutatedTarget: true
|
|
159944
|
+
};
|
|
159945
|
+
function makeVariable(expression) {
|
|
159946
|
+
const tempName = factory.createUniqueName(
|
|
159947
|
+
name + "_Part" + (newSpreads.length + 1),
|
|
159948
|
+
16 /* Optimistic */
|
|
159949
|
+
);
|
|
159950
|
+
const initializer = !isConstContext ? expression : factory.createAsExpression(
|
|
159951
|
+
expression,
|
|
159952
|
+
factory.createTypeReferenceNode("const")
|
|
159953
|
+
);
|
|
159954
|
+
const variableDefinition = factory.createVariableStatement(
|
|
159955
|
+
/*modifiers*/
|
|
159956
|
+
void 0,
|
|
159957
|
+
factory.createVariableDeclarationList([
|
|
159958
|
+
factory.createVariableDeclaration(
|
|
159959
|
+
tempName,
|
|
159960
|
+
/*exclamationToken*/
|
|
159961
|
+
void 0,
|
|
159962
|
+
/*type*/
|
|
159963
|
+
void 0,
|
|
159964
|
+
initializer
|
|
159965
|
+
)
|
|
159966
|
+
], 2 /* Const */)
|
|
159967
|
+
);
|
|
159968
|
+
changeTracker.insertNodeBefore(sourceFile, statement, variableDefinition);
|
|
159969
|
+
intersectionTypes.push(createTypeOfFromEntityNameExpression(tempName));
|
|
159970
|
+
newSpreads.push(createSpread(tempName));
|
|
159971
|
+
}
|
|
159972
|
+
function finalizesVariablePart() {
|
|
159973
|
+
if (currentVariableProperties) {
|
|
159974
|
+
makeVariable(makeNodeOfKind(
|
|
159975
|
+
currentVariableProperties
|
|
159976
|
+
));
|
|
159977
|
+
currentVariableProperties = void 0;
|
|
159978
|
+
}
|
|
159979
|
+
}
|
|
159980
|
+
}
|
|
159981
|
+
function isConstAssertion2(location) {
|
|
159982
|
+
return isAssertionExpression(location) && isConstTypeReference(location.type);
|
|
159983
|
+
}
|
|
159984
|
+
function relativeType(node) {
|
|
159985
|
+
if (isParameter(node)) {
|
|
159986
|
+
return emptyInferenceResult;
|
|
159987
|
+
}
|
|
159988
|
+
if (isShorthandPropertyAssignment(node)) {
|
|
159989
|
+
return {
|
|
159990
|
+
typeNode: createTypeOfFromEntityNameExpression(node.name),
|
|
159991
|
+
mutatedTarget: false
|
|
159992
|
+
};
|
|
159993
|
+
}
|
|
159994
|
+
if (isEntityNameExpression(node)) {
|
|
159995
|
+
return {
|
|
159996
|
+
typeNode: createTypeOfFromEntityNameExpression(node),
|
|
159997
|
+
mutatedTarget: false
|
|
159998
|
+
};
|
|
159999
|
+
}
|
|
160000
|
+
if (isConstAssertion2(node)) {
|
|
160001
|
+
return relativeType(node.expression);
|
|
160002
|
+
}
|
|
160003
|
+
if (isArrayLiteralExpression(node)) {
|
|
160004
|
+
const variableDecl = findAncestor(node, isVariableDeclaration);
|
|
160005
|
+
const partName = variableDecl && isIdentifier(variableDecl.name) ? variableDecl.name.text : void 0;
|
|
160006
|
+
return typeFromArraySpreadElements(node, partName);
|
|
160007
|
+
}
|
|
160008
|
+
if (isObjectLiteralExpression(node)) {
|
|
160009
|
+
const variableDecl = findAncestor(node, isVariableDeclaration);
|
|
160010
|
+
const partName = variableDecl && isIdentifier(variableDecl.name) ? variableDecl.name.text : void 0;
|
|
160011
|
+
return typeFromObjectSpreadAssignment(node, partName);
|
|
160012
|
+
}
|
|
160013
|
+
if (isVariableDeclaration(node) && node.initializer) {
|
|
160014
|
+
return relativeType(node.initializer);
|
|
160015
|
+
}
|
|
160016
|
+
if (isConditionalExpression(node)) {
|
|
160017
|
+
const { typeNode: trueType, mutatedTarget: mTrue } = relativeType(node.whenTrue);
|
|
160018
|
+
if (!trueType)
|
|
160019
|
+
return emptyInferenceResult;
|
|
160020
|
+
const { typeNode: falseType, mutatedTarget: mFalse } = relativeType(node.whenFalse);
|
|
160021
|
+
if (!falseType)
|
|
160022
|
+
return emptyInferenceResult;
|
|
160023
|
+
return {
|
|
160024
|
+
typeNode: factory.createUnionTypeNode([trueType, falseType]),
|
|
160025
|
+
mutatedTarget: mTrue || mFalse
|
|
160026
|
+
};
|
|
160027
|
+
}
|
|
160028
|
+
return emptyInferenceResult;
|
|
160029
|
+
}
|
|
160030
|
+
function typeToTypeNode2(type, enclosingDeclaration, flags = 0 /* None */) {
|
|
160031
|
+
let isTruncated = false;
|
|
160032
|
+
const result2 = typeToAutoImportableTypeNode(typeChecker, importAdder, type, enclosingDeclaration, scriptTarget, declarationEmitNodeBuilderFlags2 | flags, {
|
|
160033
|
+
moduleResolverHost: program,
|
|
160034
|
+
trackSymbol() {
|
|
160035
|
+
return true;
|
|
160036
|
+
},
|
|
160037
|
+
reportTruncationError() {
|
|
160038
|
+
isTruncated = true;
|
|
160039
|
+
}
|
|
160040
|
+
});
|
|
160041
|
+
return isTruncated ? factory.createKeywordTypeNode(133 /* AnyKeyword */) : result2;
|
|
160042
|
+
}
|
|
160043
|
+
function tryGetReturnType2(node) {
|
|
160044
|
+
const signature = typeChecker.getSignatureFromDeclaration(node);
|
|
160045
|
+
if (signature) {
|
|
160046
|
+
return typeChecker.getReturnTypeOfSignature(signature);
|
|
160047
|
+
}
|
|
160048
|
+
}
|
|
160049
|
+
function addTypeToVariableLike(decl) {
|
|
160050
|
+
const { typeNode } = inferType(decl);
|
|
160051
|
+
if (typeNode) {
|
|
160052
|
+
if (decl.type) {
|
|
160053
|
+
changeTracker.replaceNode(getSourceFileOfNode(decl), decl.type, typeNode);
|
|
160054
|
+
} else {
|
|
160055
|
+
changeTracker.tryInsertTypeAnnotation(getSourceFileOfNode(decl), decl, typeNode);
|
|
160056
|
+
}
|
|
160057
|
+
return [Diagnostics.Add_annotation_of_type_0, typeToStringForDiag(typeNode)];
|
|
160058
|
+
}
|
|
160059
|
+
}
|
|
160060
|
+
function typeToStringForDiag(node) {
|
|
160061
|
+
setEmitFlags(node, 1 /* SingleLine */);
|
|
160062
|
+
const result2 = typePrinter.printNode(4 /* Unspecified */, node, sourceFile);
|
|
160063
|
+
if (result2.length > defaultMaximumTruncationLength) {
|
|
160064
|
+
return result2.substring(0, defaultMaximumTruncationLength - "...".length) + "...";
|
|
160065
|
+
}
|
|
160066
|
+
setEmitFlags(node, 0 /* None */);
|
|
160067
|
+
return result2;
|
|
160068
|
+
}
|
|
160069
|
+
}
|
|
160070
|
+
function findAncestorWithMissingType(node) {
|
|
160071
|
+
return findAncestor(node, (n) => {
|
|
160072
|
+
return canHaveTypeAnnotation.has(n.kind) && (!isObjectBindingPattern(n) && !isArrayBindingPattern(n) || isVariableDeclaration(n.parent));
|
|
160073
|
+
});
|
|
160074
|
+
}
|
|
160075
|
+
function findBestFittingNode(node, span) {
|
|
160076
|
+
while (node && node.end < span.start + span.length) {
|
|
160077
|
+
node = node.parent;
|
|
160078
|
+
}
|
|
160079
|
+
while (node.parent.pos === node.pos && node.parent.end === node.end) {
|
|
160080
|
+
node = node.parent;
|
|
160081
|
+
}
|
|
160082
|
+
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
|
|
160083
|
+
return node.parent.initializer;
|
|
160084
|
+
}
|
|
160085
|
+
return node;
|
|
160086
|
+
}
|
|
160087
|
+
|
|
160088
|
+
// src/services/codefixes/fixAwaitInSyncFunction.ts
|
|
160089
|
+
var fixId37 = "fixAwaitInSyncFunction";
|
|
160090
|
+
var errorCodes48 = [
|
|
159174
160091
|
Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159175
160092
|
Diagnostics.await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159176
160093
|
Diagnostics.for_await_loops_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159177
160094
|
Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function.code
|
|
159178
160095
|
];
|
|
159179
160096
|
registerCodeFix({
|
|
159180
|
-
errorCodes:
|
|
160097
|
+
errorCodes: errorCodes48,
|
|
159181
160098
|
getCodeActions(context) {
|
|
159182
160099
|
const { sourceFile, span } = context;
|
|
159183
160100
|
const nodes = getNodes3(sourceFile, span.start);
|
|
159184
160101
|
if (!nodes)
|
|
159185
160102
|
return void 0;
|
|
159186
160103
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange31(t, sourceFile, nodes));
|
|
159187
|
-
return [createCodeFixAction(
|
|
160104
|
+
return [createCodeFixAction(fixId37, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId37, Diagnostics.Add_all_missing_async_modifiers)];
|
|
159188
160105
|
},
|
|
159189
|
-
fixIds: [
|
|
160106
|
+
fixIds: [fixId37],
|
|
159190
160107
|
getAllCodeActions: function getAllCodeActionsToFixAwaitInSyncFunction(context) {
|
|
159191
160108
|
const seen = /* @__PURE__ */ new Map();
|
|
159192
|
-
return codeFixAll(context,
|
|
160109
|
+
return codeFixAll(context, errorCodes48, (changes, diag2) => {
|
|
159193
160110
|
const nodes = getNodes3(diag2.file, diag2.start);
|
|
159194
160111
|
if (!nodes || !addToSeen(seen, getNodeId(nodes.insertBefore)))
|
|
159195
160112
|
return;
|
|
@@ -159243,21 +160160,21 @@ function doChange31(changes, sourceFile, { insertBefore, returnType }) {
|
|
|
159243
160160
|
}
|
|
159244
160161
|
|
|
159245
160162
|
// src/services/codefixes/fixPropertyOverrideAccessor.ts
|
|
159246
|
-
var
|
|
160163
|
+
var errorCodes49 = [
|
|
159247
160164
|
Diagnostics._0_is_defined_as_an_accessor_in_class_1_but_is_overridden_here_in_2_as_an_instance_property.code,
|
|
159248
160165
|
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor.code
|
|
159249
160166
|
];
|
|
159250
|
-
var
|
|
160167
|
+
var fixId38 = "fixPropertyOverrideAccessor";
|
|
159251
160168
|
registerCodeFix({
|
|
159252
|
-
errorCodes:
|
|
160169
|
+
errorCodes: errorCodes49,
|
|
159253
160170
|
getCodeActions(context) {
|
|
159254
160171
|
const edits = doChange32(context.sourceFile, context.span.start, context.span.length, context.errorCode, context);
|
|
159255
160172
|
if (edits) {
|
|
159256
|
-
return [createCodeFixAction(
|
|
160173
|
+
return [createCodeFixAction(fixId38, edits, Diagnostics.Generate_get_and_set_accessors, fixId38, Diagnostics.Generate_get_and_set_accessors_for_all_overriding_properties)];
|
|
159257
160174
|
}
|
|
159258
160175
|
},
|
|
159259
|
-
fixIds: [
|
|
159260
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
160176
|
+
fixIds: [fixId38],
|
|
160177
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes49, (changes, diag2) => {
|
|
159261
160178
|
const edits = doChange32(diag2.file, diag2.start, diag2.length, diag2.code, context);
|
|
159262
160179
|
if (edits) {
|
|
159263
160180
|
for (const edit of edits) {
|
|
@@ -159295,8 +160212,8 @@ function doChange32(file, start, length2, code, context) {
|
|
|
159295
160212
|
}
|
|
159296
160213
|
|
|
159297
160214
|
// src/services/codefixes/inferFromUsage.ts
|
|
159298
|
-
var
|
|
159299
|
-
var
|
|
160215
|
+
var fixId39 = "inferFromUsage";
|
|
160216
|
+
var errorCodes50 = [
|
|
159300
160217
|
// Variable declarations
|
|
159301
160218
|
Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined.code,
|
|
159302
160219
|
// Variable uses
|
|
@@ -159330,7 +160247,7 @@ var errorCodes49 = [
|
|
|
159330
160247
|
Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation.code
|
|
159331
160248
|
];
|
|
159332
160249
|
registerCodeFix({
|
|
159333
|
-
errorCodes:
|
|
160250
|
+
errorCodes: errorCodes50,
|
|
159334
160251
|
getCodeActions(context) {
|
|
159335
160252
|
const { sourceFile, program, span: { start }, errorCode, cancellationToken, host, preferences } = context;
|
|
159336
160253
|
const token = getTokenAtPosition(sourceFile, start);
|
|
@@ -159350,13 +160267,13 @@ registerCodeFix({
|
|
|
159350
160267
|
);
|
|
159351
160268
|
});
|
|
159352
160269
|
const name = declaration && getNameOfDeclaration(declaration);
|
|
159353
|
-
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(
|
|
160270
|
+
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(fixId39, changes, [getDiagnostic(errorCode, token), getTextOfNode(name)], fixId39, Diagnostics.Infer_all_types_from_usage)];
|
|
159354
160271
|
},
|
|
159355
|
-
fixIds: [
|
|
160272
|
+
fixIds: [fixId39],
|
|
159356
160273
|
getAllCodeActions(context) {
|
|
159357
160274
|
const { sourceFile, program, cancellationToken, host, preferences } = context;
|
|
159358
160275
|
const markSeen = nodeSeenTracker();
|
|
159359
|
-
return codeFixAll(context,
|
|
160276
|
+
return codeFixAll(context, errorCodes50, (changes, err) => {
|
|
159360
160277
|
doChange33(changes, sourceFile, getTokenAtPosition(err.file, err.start), err.code, program, cancellationToken, markSeen, host, preferences);
|
|
159361
160278
|
});
|
|
159362
160279
|
}
|
|
@@ -160295,13 +161212,13 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
160295
161212
|
}
|
|
160296
161213
|
|
|
160297
161214
|
// src/services/codefixes/fixReturnTypeInAsyncFunction.ts
|
|
160298
|
-
var
|
|
160299
|
-
var
|
|
161215
|
+
var fixId40 = "fixReturnTypeInAsyncFunction";
|
|
161216
|
+
var errorCodes51 = [
|
|
160300
161217
|
Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0.code
|
|
160301
161218
|
];
|
|
160302
161219
|
registerCodeFix({
|
|
160303
|
-
errorCodes:
|
|
160304
|
-
fixIds: [
|
|
161220
|
+
errorCodes: errorCodes51,
|
|
161221
|
+
fixIds: [fixId40],
|
|
160305
161222
|
getCodeActions: function getCodeActionsToFixReturnTypeInAsyncFunction(context) {
|
|
160306
161223
|
const { sourceFile, program, span } = context;
|
|
160307
161224
|
const checker = program.getTypeChecker();
|
|
@@ -160312,14 +161229,14 @@ registerCodeFix({
|
|
|
160312
161229
|
const { returnTypeNode, returnType, promisedTypeNode, promisedType } = info;
|
|
160313
161230
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange34(t, sourceFile, returnTypeNode, promisedTypeNode));
|
|
160314
161231
|
return [createCodeFixAction(
|
|
160315
|
-
|
|
161232
|
+
fixId40,
|
|
160316
161233
|
changes,
|
|
160317
161234
|
[Diagnostics.Replace_0_with_Promise_1, checker.typeToString(returnType), checker.typeToString(promisedType)],
|
|
160318
|
-
|
|
161235
|
+
fixId40,
|
|
160319
161236
|
Diagnostics.Fix_all_incorrect_return_type_of_an_async_functions
|
|
160320
161237
|
)];
|
|
160321
161238
|
},
|
|
160322
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
161239
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes51, (changes, diag2) => {
|
|
160323
161240
|
const info = getInfo16(diag2.file, context.program.getTypeChecker(), diag2.start);
|
|
160324
161241
|
if (info) {
|
|
160325
161242
|
doChange34(changes, diag2.file, info.returnTypeNode, info.promisedTypeNode);
|
|
@@ -160355,13 +161272,13 @@ function doChange34(changes, sourceFile, returnTypeNode, promisedTypeNode) {
|
|
|
160355
161272
|
|
|
160356
161273
|
// src/services/codefixes/disableJsDiagnostics.ts
|
|
160357
161274
|
var fixName4 = "disableJsDiagnostics";
|
|
160358
|
-
var
|
|
160359
|
-
var
|
|
161275
|
+
var fixId41 = "disableJsDiagnostics";
|
|
161276
|
+
var errorCodes52 = mapDefined(Object.keys(Diagnostics), (key) => {
|
|
160360
161277
|
const diag2 = Diagnostics[key];
|
|
160361
161278
|
return diag2.category === 1 /* Error */ ? diag2.code : void 0;
|
|
160362
161279
|
});
|
|
160363
161280
|
registerCodeFix({
|
|
160364
|
-
errorCodes:
|
|
161281
|
+
errorCodes: errorCodes52,
|
|
160365
161282
|
getCodeActions: function getCodeActionsToDisableJsDiagnostics(context) {
|
|
160366
161283
|
const { sourceFile, program, span, host, formatContext } = context;
|
|
160367
161284
|
if (!isInJSFile(sourceFile) || !isCheckJsEnabledForFile(sourceFile, program.getCompilerOptions())) {
|
|
@@ -160382,14 +161299,14 @@ registerCodeFix({
|
|
|
160382
161299
|
)
|
|
160383
161300
|
];
|
|
160384
161301
|
if (ts_textChanges_exports.isValidLocationToAddComment(sourceFile, span.start)) {
|
|
160385
|
-
fixes.unshift(createCodeFixAction(fixName4, ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange8(t, sourceFile, span.start)), Diagnostics.Ignore_this_error_message,
|
|
161302
|
+
fixes.unshift(createCodeFixAction(fixName4, ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange8(t, sourceFile, span.start)), Diagnostics.Ignore_this_error_message, fixId41, Diagnostics.Add_ts_ignore_to_all_error_messages));
|
|
160386
161303
|
}
|
|
160387
161304
|
return fixes;
|
|
160388
161305
|
},
|
|
160389
|
-
fixIds: [
|
|
161306
|
+
fixIds: [fixId41],
|
|
160390
161307
|
getAllCodeActions: (context) => {
|
|
160391
161308
|
const seenLines = /* @__PURE__ */ new Set();
|
|
160392
|
-
return codeFixAll(context,
|
|
161309
|
+
return codeFixAll(context, errorCodes52, (changes, diag2) => {
|
|
160393
161310
|
if (ts_textChanges_exports.isValidLocationToAddComment(diag2.file, diag2.start)) {
|
|
160394
161311
|
makeChange8(changes, diag2.file, diag2.start, seenLines);
|
|
160395
161312
|
}
|
|
@@ -161388,9 +162305,9 @@ var fixName6 = "strictClassInitialization";
|
|
|
161388
162305
|
var fixIdAddDefiniteAssignmentAssertions = "addMissingPropertyDefiniteAssignmentAssertions";
|
|
161389
162306
|
var fixIdAddUndefinedType = "addMissingPropertyUndefinedType";
|
|
161390
162307
|
var fixIdAddInitializer = "addMissingPropertyInitializer";
|
|
161391
|
-
var
|
|
162308
|
+
var errorCodes53 = [Diagnostics.Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor.code];
|
|
161392
162309
|
registerCodeFix({
|
|
161393
|
-
errorCodes:
|
|
162310
|
+
errorCodes: errorCodes53,
|
|
161394
162311
|
getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
|
|
161395
162312
|
const info = getInfo17(context.sourceFile, context.span.start);
|
|
161396
162313
|
if (!info)
|
|
@@ -161403,7 +162320,7 @@ registerCodeFix({
|
|
|
161403
162320
|
},
|
|
161404
162321
|
fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
|
|
161405
162322
|
getAllCodeActions: (context) => {
|
|
161406
|
-
return codeFixAll(context,
|
|
162323
|
+
return codeFixAll(context, errorCodes53, (changes, diag2) => {
|
|
161407
162324
|
const info = getInfo17(diag2.file, diag2.start);
|
|
161408
162325
|
if (!info)
|
|
161409
162326
|
return;
|
|
@@ -161533,20 +162450,20 @@ function getDefaultValueFromType(checker, type) {
|
|
|
161533
162450
|
}
|
|
161534
162451
|
|
|
161535
162452
|
// src/services/codefixes/requireInTs.ts
|
|
161536
|
-
var
|
|
161537
|
-
var
|
|
162453
|
+
var fixId42 = "requireInTs";
|
|
162454
|
+
var errorCodes54 = [Diagnostics.require_call_may_be_converted_to_an_import.code];
|
|
161538
162455
|
registerCodeFix({
|
|
161539
|
-
errorCodes:
|
|
162456
|
+
errorCodes: errorCodes54,
|
|
161540
162457
|
getCodeActions(context) {
|
|
161541
162458
|
const info = getInfo18(context.sourceFile, context.program, context.span.start);
|
|
161542
162459
|
if (!info) {
|
|
161543
162460
|
return void 0;
|
|
161544
162461
|
}
|
|
161545
162462
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange35(t, context.sourceFile, info));
|
|
161546
|
-
return [createCodeFixAction(
|
|
162463
|
+
return [createCodeFixAction(fixId42, changes, Diagnostics.Convert_require_to_import, fixId42, Diagnostics.Convert_all_require_to_import)];
|
|
161547
162464
|
},
|
|
161548
|
-
fixIds: [
|
|
161549
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162465
|
+
fixIds: [fixId42],
|
|
162466
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes54, (changes, diag2) => {
|
|
161550
162467
|
const info = getInfo18(diag2.file, context.program, diag2.start);
|
|
161551
162468
|
if (info) {
|
|
161552
162469
|
doChange35(changes, context.sourceFile, info);
|
|
@@ -161621,20 +162538,20 @@ function tryCreateNamedImportsFromObjectBindingPattern(node) {
|
|
|
161621
162538
|
}
|
|
161622
162539
|
|
|
161623
162540
|
// src/services/codefixes/useDefaultImport.ts
|
|
161624
|
-
var
|
|
161625
|
-
var
|
|
162541
|
+
var fixId43 = "useDefaultImport";
|
|
162542
|
+
var errorCodes55 = [Diagnostics.Import_may_be_converted_to_a_default_import.code];
|
|
161626
162543
|
registerCodeFix({
|
|
161627
|
-
errorCodes:
|
|
162544
|
+
errorCodes: errorCodes55,
|
|
161628
162545
|
getCodeActions(context) {
|
|
161629
162546
|
const { sourceFile, span: { start } } = context;
|
|
161630
162547
|
const info = getInfo19(sourceFile, start);
|
|
161631
162548
|
if (!info)
|
|
161632
162549
|
return void 0;
|
|
161633
162550
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange36(t, sourceFile, info, context.preferences));
|
|
161634
|
-
return [createCodeFixAction(
|
|
162551
|
+
return [createCodeFixAction(fixId43, changes, Diagnostics.Convert_to_default_import, fixId43, Diagnostics.Convert_all_to_default_imports)];
|
|
161635
162552
|
},
|
|
161636
|
-
fixIds: [
|
|
161637
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162553
|
+
fixIds: [fixId43],
|
|
162554
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes55, (changes, diag2) => {
|
|
161638
162555
|
const info = getInfo19(diag2.file, diag2.start);
|
|
161639
162556
|
if (info)
|
|
161640
162557
|
doChange36(changes, diag2.file, info, context.preferences);
|
|
@@ -161663,21 +162580,21 @@ function doChange36(changes, sourceFile, info, preferences) {
|
|
|
161663
162580
|
}
|
|
161664
162581
|
|
|
161665
162582
|
// src/services/codefixes/useBigintLiteral.ts
|
|
161666
|
-
var
|
|
161667
|
-
var
|
|
162583
|
+
var fixId44 = "useBigintLiteral";
|
|
162584
|
+
var errorCodes56 = [
|
|
161668
162585
|
Diagnostics.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_integers.code
|
|
161669
162586
|
];
|
|
161670
162587
|
registerCodeFix({
|
|
161671
|
-
errorCodes:
|
|
162588
|
+
errorCodes: errorCodes56,
|
|
161672
162589
|
getCodeActions: function getCodeActionsToUseBigintLiteral(context) {
|
|
161673
162590
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange9(t, context.sourceFile, context.span));
|
|
161674
162591
|
if (changes.length > 0) {
|
|
161675
|
-
return [createCodeFixAction(
|
|
162592
|
+
return [createCodeFixAction(fixId44, changes, Diagnostics.Convert_to_a_bigint_numeric_literal, fixId44, Diagnostics.Convert_all_to_bigint_numeric_literals)];
|
|
161676
162593
|
}
|
|
161677
162594
|
},
|
|
161678
|
-
fixIds: [
|
|
162595
|
+
fixIds: [fixId44],
|
|
161679
162596
|
getAllCodeActions: (context) => {
|
|
161680
|
-
return codeFixAll(context,
|
|
162597
|
+
return codeFixAll(context, errorCodes56, (changes, diag2) => makeChange9(changes, diag2.file, diag2));
|
|
161681
162598
|
}
|
|
161682
162599
|
});
|
|
161683
162600
|
function makeChange9(changeTracker, sourceFile, span) {
|
|
@@ -161691,18 +162608,18 @@ function makeChange9(changeTracker, sourceFile, span) {
|
|
|
161691
162608
|
|
|
161692
162609
|
// src/services/codefixes/fixAddModuleReferTypeMissingTypeof.ts
|
|
161693
162610
|
var fixIdAddMissingTypeof = "fixAddModuleReferTypeMissingTypeof";
|
|
161694
|
-
var
|
|
161695
|
-
var
|
|
162611
|
+
var fixId45 = fixIdAddMissingTypeof;
|
|
162612
|
+
var errorCodes57 = [Diagnostics.Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0.code];
|
|
161696
162613
|
registerCodeFix({
|
|
161697
|
-
errorCodes:
|
|
162614
|
+
errorCodes: errorCodes57,
|
|
161698
162615
|
getCodeActions: function getCodeActionsToAddMissingTypeof(context) {
|
|
161699
162616
|
const { sourceFile, span } = context;
|
|
161700
162617
|
const importType = getImportTypeNode(sourceFile, span.start);
|
|
161701
162618
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange37(t, sourceFile, importType));
|
|
161702
|
-
return [createCodeFixAction(
|
|
162619
|
+
return [createCodeFixAction(fixId45, changes, Diagnostics.Add_missing_typeof, fixId45, Diagnostics.Add_missing_typeof)];
|
|
161703
162620
|
},
|
|
161704
|
-
fixIds: [
|
|
161705
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162621
|
+
fixIds: [fixId45],
|
|
162622
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes57, (changes, diag2) => doChange37(changes, context.sourceFile, getImportTypeNode(diag2.file, diag2.start)))
|
|
161706
162623
|
});
|
|
161707
162624
|
function getImportTypeNode(sourceFile, pos) {
|
|
161708
162625
|
const token = getTokenAtPosition(sourceFile, pos);
|
|
@@ -161725,9 +162642,9 @@ function doChange37(changes, sourceFile, importType) {
|
|
|
161725
162642
|
|
|
161726
162643
|
// src/services/codefixes/wrapJsxInFragment.ts
|
|
161727
162644
|
var fixID2 = "wrapJsxInFragment";
|
|
161728
|
-
var
|
|
162645
|
+
var errorCodes58 = [Diagnostics.JSX_expressions_must_have_one_parent_element.code];
|
|
161729
162646
|
registerCodeFix({
|
|
161730
|
-
errorCodes:
|
|
162647
|
+
errorCodes: errorCodes58,
|
|
161731
162648
|
getCodeActions: function getCodeActionsToWrapJsxInFragment(context) {
|
|
161732
162649
|
const { sourceFile, span } = context;
|
|
161733
162650
|
const node = findNodeToFix(sourceFile, span.start);
|
|
@@ -161737,7 +162654,7 @@ registerCodeFix({
|
|
|
161737
162654
|
return [createCodeFixAction(fixID2, changes, Diagnostics.Wrap_in_JSX_fragment, fixID2, Diagnostics.Wrap_all_unparented_JSX_in_JSX_fragment)];
|
|
161738
162655
|
},
|
|
161739
162656
|
fixIds: [fixID2],
|
|
161740
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162657
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes58, (changes, diag2) => {
|
|
161741
162658
|
const node = findNodeToFix(context.sourceFile, diag2.start);
|
|
161742
162659
|
if (!node)
|
|
161743
162660
|
return void 0;
|
|
@@ -161782,16 +162699,16 @@ function flattenInvalidBinaryExpr(node) {
|
|
|
161782
162699
|
}
|
|
161783
162700
|
|
|
161784
162701
|
// src/services/codefixes/wrapDecoratorInParentheses.ts
|
|
161785
|
-
var
|
|
161786
|
-
var
|
|
162702
|
+
var fixId46 = "wrapDecoratorInParentheses";
|
|
162703
|
+
var errorCodes59 = [Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator.code];
|
|
161787
162704
|
registerCodeFix({
|
|
161788
|
-
errorCodes:
|
|
162705
|
+
errorCodes: errorCodes59,
|
|
161789
162706
|
getCodeActions: function getCodeActionsToWrapDecoratorExpressionInParentheses(context) {
|
|
161790
162707
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange10(t, context.sourceFile, context.span.start));
|
|
161791
|
-
return [createCodeFixAction(
|
|
162708
|
+
return [createCodeFixAction(fixId46, changes, Diagnostics.Wrap_in_parentheses, fixId46, Diagnostics.Wrap_all_invalid_decorator_expressions_in_parentheses)];
|
|
161792
162709
|
},
|
|
161793
|
-
fixIds: [
|
|
161794
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162710
|
+
fixIds: [fixId46],
|
|
162711
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes59, (changes, diag2) => makeChange10(changes, diag2.file, diag2.start))
|
|
161795
162712
|
});
|
|
161796
162713
|
function makeChange10(changeTracker, sourceFile, pos) {
|
|
161797
162714
|
const token = getTokenAtPosition(sourceFile, pos);
|
|
@@ -161802,10 +162719,10 @@ function makeChange10(changeTracker, sourceFile, pos) {
|
|
|
161802
162719
|
}
|
|
161803
162720
|
|
|
161804
162721
|
// src/services/codefixes/convertToMappedObjectType.ts
|
|
161805
|
-
var
|
|
161806
|
-
var
|
|
162722
|
+
var fixId47 = "fixConvertToMappedObjectType";
|
|
162723
|
+
var errorCodes60 = [Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead.code];
|
|
161807
162724
|
registerCodeFix({
|
|
161808
|
-
errorCodes:
|
|
162725
|
+
errorCodes: errorCodes60,
|
|
161809
162726
|
getCodeActions: function getCodeActionsToConvertToMappedTypeObject(context) {
|
|
161810
162727
|
const { sourceFile, span } = context;
|
|
161811
162728
|
const info = getInfo20(sourceFile, span.start);
|
|
@@ -161813,10 +162730,10 @@ registerCodeFix({
|
|
|
161813
162730
|
return void 0;
|
|
161814
162731
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange39(t, sourceFile, info));
|
|
161815
162732
|
const name = idText(info.container.name);
|
|
161816
|
-
return [createCodeFixAction(
|
|
162733
|
+
return [createCodeFixAction(fixId47, changes, [Diagnostics.Convert_0_to_mapped_object_type, name], fixId47, [Diagnostics.Convert_0_to_mapped_object_type, name])];
|
|
161817
162734
|
},
|
|
161818
|
-
fixIds: [
|
|
161819
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162735
|
+
fixIds: [fixId47],
|
|
162736
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes60, (changes, diag2) => {
|
|
161820
162737
|
const info = getInfo20(diag2.file, diag2.start);
|
|
161821
162738
|
if (info)
|
|
161822
162739
|
doChange39(changes, diag2.file, info);
|
|
@@ -161864,12 +162781,12 @@ function doChange39(changes, sourceFile, { indexSignature, container }) {
|
|
|
161864
162781
|
}
|
|
161865
162782
|
|
|
161866
162783
|
// src/services/codefixes/removeAccidentalCallParentheses.ts
|
|
161867
|
-
var
|
|
161868
|
-
var
|
|
162784
|
+
var fixId48 = "removeAccidentalCallParentheses";
|
|
162785
|
+
var errorCodes61 = [
|
|
161869
162786
|
Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without.code
|
|
161870
162787
|
];
|
|
161871
162788
|
registerCodeFix({
|
|
161872
|
-
errorCodes:
|
|
162789
|
+
errorCodes: errorCodes61,
|
|
161873
162790
|
getCodeActions(context) {
|
|
161874
162791
|
const callExpression = findAncestor(getTokenAtPosition(context.sourceFile, context.span.start), isCallExpression);
|
|
161875
162792
|
if (!callExpression) {
|
|
@@ -161878,27 +162795,27 @@ registerCodeFix({
|
|
|
161878
162795
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
161879
162796
|
t.deleteRange(context.sourceFile, { pos: callExpression.expression.end, end: callExpression.end });
|
|
161880
162797
|
});
|
|
161881
|
-
return [createCodeFixActionWithoutFixAll(
|
|
162798
|
+
return [createCodeFixActionWithoutFixAll(fixId48, changes, Diagnostics.Remove_parentheses)];
|
|
161882
162799
|
},
|
|
161883
|
-
fixIds: [
|
|
162800
|
+
fixIds: [fixId48]
|
|
161884
162801
|
});
|
|
161885
162802
|
|
|
161886
162803
|
// src/services/codefixes/removeUnnecessaryAwait.ts
|
|
161887
|
-
var
|
|
161888
|
-
var
|
|
162804
|
+
var fixId49 = "removeUnnecessaryAwait";
|
|
162805
|
+
var errorCodes62 = [
|
|
161889
162806
|
Diagnostics.await_has_no_effect_on_the_type_of_this_expression.code
|
|
161890
162807
|
];
|
|
161891
162808
|
registerCodeFix({
|
|
161892
|
-
errorCodes:
|
|
162809
|
+
errorCodes: errorCodes62,
|
|
161893
162810
|
getCodeActions: function getCodeActionsToRemoveUnnecessaryAwait(context) {
|
|
161894
162811
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange11(t, context.sourceFile, context.span));
|
|
161895
162812
|
if (changes.length > 0) {
|
|
161896
|
-
return [createCodeFixAction(
|
|
162813
|
+
return [createCodeFixAction(fixId49, changes, Diagnostics.Remove_unnecessary_await, fixId49, Diagnostics.Remove_all_unnecessary_uses_of_await)];
|
|
161897
162814
|
}
|
|
161898
162815
|
},
|
|
161899
|
-
fixIds: [
|
|
162816
|
+
fixIds: [fixId49],
|
|
161900
162817
|
getAllCodeActions: (context) => {
|
|
161901
|
-
return codeFixAll(context,
|
|
162818
|
+
return codeFixAll(context, errorCodes62, (changes, diag2) => makeChange11(changes, diag2.file, diag2));
|
|
161902
162819
|
}
|
|
161903
162820
|
});
|
|
161904
162821
|
function makeChange11(changeTracker, sourceFile, span) {
|
|
@@ -161926,20 +162843,20 @@ function makeChange11(changeTracker, sourceFile, span) {
|
|
|
161926
162843
|
}
|
|
161927
162844
|
|
|
161928
162845
|
// src/services/codefixes/splitTypeOnlyImport.ts
|
|
161929
|
-
var
|
|
161930
|
-
var
|
|
162846
|
+
var errorCodes63 = [Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both.code];
|
|
162847
|
+
var fixId50 = "splitTypeOnlyImport";
|
|
161931
162848
|
registerCodeFix({
|
|
161932
|
-
errorCodes:
|
|
161933
|
-
fixIds: [
|
|
162849
|
+
errorCodes: errorCodes63,
|
|
162850
|
+
fixIds: [fixId50],
|
|
161934
162851
|
getCodeActions: function getCodeActionsToSplitTypeOnlyImport(context) {
|
|
161935
162852
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
161936
162853
|
return splitTypeOnlyImport(t, getImportDeclaration2(context.sourceFile, context.span), context);
|
|
161937
162854
|
});
|
|
161938
162855
|
if (changes.length) {
|
|
161939
|
-
return [createCodeFixAction(
|
|
162856
|
+
return [createCodeFixAction(fixId50, changes, Diagnostics.Split_into_two_separate_import_declarations, fixId50, Diagnostics.Split_all_invalid_type_only_imports)];
|
|
161940
162857
|
}
|
|
161941
162858
|
},
|
|
161942
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162859
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes63, (changes, error2) => {
|
|
161943
162860
|
splitTypeOnlyImport(changes, getImportDeclaration2(context.sourceFile, error2), context);
|
|
161944
162861
|
})
|
|
161945
162862
|
});
|
|
@@ -161988,23 +162905,23 @@ function splitTypeOnlyImport(changes, importDeclaration, context) {
|
|
|
161988
162905
|
}
|
|
161989
162906
|
|
|
161990
162907
|
// src/services/codefixes/convertConstToLet.ts
|
|
161991
|
-
var
|
|
161992
|
-
var
|
|
162908
|
+
var fixId51 = "fixConvertConstToLet";
|
|
162909
|
+
var errorCodes64 = [Diagnostics.Cannot_assign_to_0_because_it_is_a_constant.code];
|
|
161993
162910
|
registerCodeFix({
|
|
161994
|
-
errorCodes:
|
|
162911
|
+
errorCodes: errorCodes64,
|
|
161995
162912
|
getCodeActions: function getCodeActionsToConvertConstToLet(context) {
|
|
161996
162913
|
const { sourceFile, span, program } = context;
|
|
161997
162914
|
const info = getInfo21(sourceFile, span.start, program);
|
|
161998
162915
|
if (info === void 0)
|
|
161999
162916
|
return;
|
|
162000
162917
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange40(t, sourceFile, info.token));
|
|
162001
|
-
return [createCodeFixActionMaybeFixAll(
|
|
162918
|
+
return [createCodeFixActionMaybeFixAll(fixId51, changes, Diagnostics.Convert_const_to_let, fixId51, Diagnostics.Convert_all_const_to_let)];
|
|
162002
162919
|
},
|
|
162003
162920
|
getAllCodeActions: (context) => {
|
|
162004
162921
|
const { program } = context;
|
|
162005
162922
|
const seen = /* @__PURE__ */ new Map();
|
|
162006
162923
|
return createCombinedCodeActions(ts_textChanges_exports.ChangeTracker.with(context, (changes) => {
|
|
162007
|
-
eachDiagnostic(context,
|
|
162924
|
+
eachDiagnostic(context, errorCodes64, (diag2) => {
|
|
162008
162925
|
const info = getInfo21(diag2.file, diag2.start, program);
|
|
162009
162926
|
if (info) {
|
|
162010
162927
|
if (addToSeen(seen, getSymbolId(info.symbol))) {
|
|
@@ -162015,7 +162932,7 @@ registerCodeFix({
|
|
|
162015
162932
|
});
|
|
162016
162933
|
}));
|
|
162017
162934
|
},
|
|
162018
|
-
fixIds: [
|
|
162935
|
+
fixIds: [fixId51]
|
|
162019
162936
|
});
|
|
162020
162937
|
function getInfo21(sourceFile, pos, program) {
|
|
162021
162938
|
var _a;
|
|
@@ -162036,11 +162953,11 @@ function doChange40(changes, sourceFile, token) {
|
|
|
162036
162953
|
}
|
|
162037
162954
|
|
|
162038
162955
|
// src/services/codefixes/fixExpectedComma.ts
|
|
162039
|
-
var
|
|
162956
|
+
var fixId52 = "fixExpectedComma";
|
|
162040
162957
|
var expectedErrorCode = Diagnostics._0_expected.code;
|
|
162041
|
-
var
|
|
162958
|
+
var errorCodes65 = [expectedErrorCode];
|
|
162042
162959
|
registerCodeFix({
|
|
162043
|
-
errorCodes:
|
|
162960
|
+
errorCodes: errorCodes65,
|
|
162044
162961
|
getCodeActions(context) {
|
|
162045
162962
|
const { sourceFile } = context;
|
|
162046
162963
|
const info = getInfo22(sourceFile, context.span.start, context.errorCode);
|
|
@@ -162048,15 +162965,15 @@ registerCodeFix({
|
|
|
162048
162965
|
return void 0;
|
|
162049
162966
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange41(t, sourceFile, info));
|
|
162050
162967
|
return [createCodeFixAction(
|
|
162051
|
-
|
|
162968
|
+
fixId52,
|
|
162052
162969
|
changes,
|
|
162053
162970
|
[Diagnostics.Change_0_to_1, ";", ","],
|
|
162054
|
-
|
|
162971
|
+
fixId52,
|
|
162055
162972
|
[Diagnostics.Change_0_to_1, ";", ","]
|
|
162056
162973
|
)];
|
|
162057
162974
|
},
|
|
162058
|
-
fixIds: [
|
|
162059
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162975
|
+
fixIds: [fixId52],
|
|
162976
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes65, (changes, diag2) => {
|
|
162060
162977
|
const info = getInfo22(diag2.file, diag2.start, diag2.code);
|
|
162061
162978
|
if (info)
|
|
162062
162979
|
doChange41(changes, context.sourceFile, info);
|
|
@@ -162073,22 +162990,22 @@ function doChange41(changes, sourceFile, { node }) {
|
|
|
162073
162990
|
|
|
162074
162991
|
// src/services/codefixes/fixAddVoidToPromise.ts
|
|
162075
162992
|
var fixName7 = "addVoidToPromise";
|
|
162076
|
-
var
|
|
162077
|
-
var
|
|
162993
|
+
var fixId53 = "addVoidToPromise";
|
|
162994
|
+
var errorCodes66 = [
|
|
162078
162995
|
Diagnostics.Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_without_arguments.code,
|
|
162079
162996
|
Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise.code
|
|
162080
162997
|
];
|
|
162081
162998
|
registerCodeFix({
|
|
162082
|
-
errorCodes:
|
|
162083
|
-
fixIds: [
|
|
162999
|
+
errorCodes: errorCodes66,
|
|
163000
|
+
fixIds: [fixId53],
|
|
162084
163001
|
getCodeActions(context) {
|
|
162085
163002
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange12(t, context.sourceFile, context.span, context.program));
|
|
162086
163003
|
if (changes.length > 0) {
|
|
162087
|
-
return [createCodeFixAction(fixName7, changes, Diagnostics.Add_void_to_Promise_resolved_without_a_value,
|
|
163004
|
+
return [createCodeFixAction(fixName7, changes, Diagnostics.Add_void_to_Promise_resolved_without_a_value, fixId53, Diagnostics.Add_void_to_all_Promises_resolved_without_a_value)];
|
|
162088
163005
|
}
|
|
162089
163006
|
},
|
|
162090
163007
|
getAllCodeActions(context) {
|
|
162091
|
-
return codeFixAll(context,
|
|
163008
|
+
return codeFixAll(context, errorCodes66, (changes, diag2) => makeChange12(changes, diag2.file, diag2, context.program, /* @__PURE__ */ new Set()));
|
|
162092
163009
|
}
|
|
162093
163010
|
});
|
|
162094
163011
|
function makeChange12(changes, sourceFile, span, program, seen) {
|
|
@@ -178175,6 +179092,7 @@ __export(ts_exports2, {
|
|
|
178175
179092
|
collectExternalModuleInfo: () => collectExternalModuleInfo,
|
|
178176
179093
|
combine: () => combine,
|
|
178177
179094
|
combinePaths: () => combinePaths,
|
|
179095
|
+
commandLineOptionOfCustomType: () => commandLineOptionOfCustomType,
|
|
178178
179096
|
commentPragmas: () => commentPragmas,
|
|
178179
179097
|
commonOptionsWithBuild: () => commonOptionsWithBuild,
|
|
178180
179098
|
commonPackageFolders: () => commonPackageFolders,
|
|
@@ -190862,10 +191780,10 @@ ${e.message}`;
|
|
|
190862
191780
|
}
|
|
190863
191781
|
return simplifiedResult ? codeActions.map((codeAction) => this.mapCodeFixAction(codeAction)) : codeActions;
|
|
190864
191782
|
}
|
|
190865
|
-
getCombinedCodeFix({ scope, fixId:
|
|
191783
|
+
getCombinedCodeFix({ scope, fixId: fixId54 }, simplifiedResult) {
|
|
190866
191784
|
Debug.assert(scope.type === "file");
|
|
190867
191785
|
const { file, project } = this.getFileAndProject(scope.args);
|
|
190868
|
-
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file },
|
|
191786
|
+
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId54, this.getFormatOptions(file), this.getPreferences(file));
|
|
190869
191787
|
if (simplifiedResult) {
|
|
190870
191788
|
return { changes: this.mapTextChangesToCodeEdits(res.changes), commands: res.commands };
|
|
190871
191789
|
} else {
|
|
@@ -190904,8 +191822,8 @@ ${e.message}`;
|
|
|
190904
191822
|
mapCodeAction({ description: description3, changes, commands }) {
|
|
190905
191823
|
return { description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands };
|
|
190906
191824
|
}
|
|
190907
|
-
mapCodeFixAction({ fixName: fixName8, description: description3, changes, commands, fixId:
|
|
190908
|
-
return { fixName: fixName8, description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId:
|
|
191825
|
+
mapCodeFixAction({ fixName: fixName8, description: description3, changes, commands, fixId: fixId54, fixAllDescription }) {
|
|
191826
|
+
return { fixName: fixName8, description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId: fixId54, fixAllDescription };
|
|
190909
191827
|
}
|
|
190910
191828
|
mapTextChangesToCodeEdits(textChanges2) {
|
|
190911
191829
|
return textChanges2.map((change) => this.mapTextChangeToCodeEdit(change));
|
|
@@ -192603,6 +193521,7 @@ if (typeof console !== "undefined") {
|
|
|
192603
193521
|
collectExternalModuleInfo,
|
|
192604
193522
|
combine,
|
|
192605
193523
|
combinePaths,
|
|
193524
|
+
commandLineOptionOfCustomType,
|
|
192606
193525
|
commentPragmas,
|
|
192607
193526
|
commonOptionsWithBuild,
|
|
192608
193527
|
commonPackageFolders,
|