typescript 5.5.0-dev.20240430 → 5.5.0-dev.20240501
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 +70 -56
- package/lib/typescript.js +1131 -226
- package/package.json +2 -2
package/lib/typescript.js
CHANGED
|
@@ -2362,7 +2362,7 @@ module.exports = __toCommonJS(typescript_exports);
|
|
|
2362
2362
|
|
|
2363
2363
|
// src/compiler/corePublic.ts
|
|
2364
2364
|
var versionMajorMinor = "5.5";
|
|
2365
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
2365
|
+
var version = `${versionMajorMinor}.0-dev.20240501`;
|
|
2366
2366
|
var Comparison = /* @__PURE__ */ ((Comparison3) => {
|
|
2367
2367
|
Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
|
|
2368
2368
|
Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
|
|
@@ -11330,6 +11330,16 @@ var Diagnostics = {
|
|
|
11330
11330
|
Export_0_from_module_1: diag(90059, 3 /* Message */, "Export_0_from_module_1_90059", "Export '{0}' from module '{1}'"),
|
|
11331
11331
|
Export_all_referenced_locals: diag(90060, 3 /* Message */, "Export_all_referenced_locals_90060", "Export all referenced locals"),
|
|
11332
11332
|
Update_modifiers_of_0: diag(90061, 3 /* Message */, "Update_modifiers_of_0_90061", "Update modifiers of '{0}'"),
|
|
11333
|
+
Add_annotation_of_type_0: diag(90062, 3 /* Message */, "Add_annotation_of_type_0_90062", "Add annotation of type '{0}'"),
|
|
11334
|
+
Add_return_type_0: diag(90063, 3 /* Message */, "Add_return_type_0_90063", "Add return type '{0}'"),
|
|
11335
|
+
Extract_base_class_to_variable: diag(90064, 3 /* Message */, "Extract_base_class_to_variable_90064", "Extract base class to variable"),
|
|
11336
|
+
Extract_default_export_to_variable: diag(90065, 3 /* Message */, "Extract_default_export_to_variable_90065", "Extract default export to variable"),
|
|
11337
|
+
Extract_binding_expressions_to_variable: diag(90066, 3 /* Message */, "Extract_binding_expressions_to_variable_90066", "Extract binding expressions to variable"),
|
|
11338
|
+
Add_all_missing_type_annotations: diag(90067, 3 /* Message */, "Add_all_missing_type_annotations_90067", "Add all missing type annotations"),
|
|
11339
|
+
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}'"),
|
|
11340
|
+
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}'"),
|
|
11341
|
+
Mark_array_literal_as_const: diag(90070, 3 /* Message */, "Mark_array_literal_as_const_90070", "Mark array literal as const"),
|
|
11342
|
+
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
11343
|
Convert_function_to_an_ES2015_class: diag(95001, 3 /* Message */, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
|
|
11334
11344
|
Convert_0_to_1_in_0: diag(95003, 3 /* Message */, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
|
|
11335
11345
|
Extract_to_0_in_1: diag(95004, 3 /* Message */, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
|
|
@@ -50243,7 +50253,7 @@ function createTypeChecker(host) {
|
|
|
50243
50253
|
var externalHelpersModule;
|
|
50244
50254
|
var scanner2;
|
|
50245
50255
|
var Symbol47 = objectAllocator.getSymbolConstructor();
|
|
50246
|
-
var
|
|
50256
|
+
var Type29 = objectAllocator.getTypeConstructor();
|
|
50247
50257
|
var Signature14 = objectAllocator.getSignatureConstructor();
|
|
50248
50258
|
var typeCount = 0;
|
|
50249
50259
|
var symbolCount = 0;
|
|
@@ -50385,6 +50395,7 @@ function createTypeChecker(host) {
|
|
|
50385
50395
|
getBaseTypes,
|
|
50386
50396
|
getBaseTypeOfLiteralType,
|
|
50387
50397
|
getWidenedType,
|
|
50398
|
+
getWidenedLiteralType,
|
|
50388
50399
|
getTypeFromTypeNode: (nodeIn) => {
|
|
50389
50400
|
const node = getParseTreeNode(nodeIn, isTypeNode);
|
|
50390
50401
|
return node ? getTypeFromTypeNode(node) : errorType;
|
|
@@ -52962,12 +52973,6 @@ function createTypeChecker(host) {
|
|
|
52962
52973
|
}
|
|
52963
52974
|
}
|
|
52964
52975
|
}
|
|
52965
|
-
function markConstEnumAliasAsReferenced(symbol) {
|
|
52966
|
-
const links = getSymbolLinks(symbol);
|
|
52967
|
-
if (!links.constEnumReferenced) {
|
|
52968
|
-
links.constEnumReferenced = true;
|
|
52969
|
-
}
|
|
52970
|
-
}
|
|
52971
52976
|
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, dontResolveAlias) {
|
|
52972
52977
|
if (entityName.kind === 80 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
|
52973
52978
|
entityName = entityName.parent;
|
|
@@ -53842,7 +53847,7 @@ function createTypeChecker(host) {
|
|
|
53842
53847
|
}
|
|
53843
53848
|
function createType(flags) {
|
|
53844
53849
|
var _a;
|
|
53845
|
-
const result = new
|
|
53850
|
+
const result = new Type29(checker, flags);
|
|
53846
53851
|
typeCount++;
|
|
53847
53852
|
result.id = typeCount;
|
|
53848
53853
|
(_a = tracing) == null ? void 0 : _a.recordType(result);
|
|
@@ -53854,7 +53859,7 @@ function createTypeChecker(host) {
|
|
|
53854
53859
|
return result;
|
|
53855
53860
|
}
|
|
53856
53861
|
function createOriginType(flags) {
|
|
53857
|
-
return new
|
|
53862
|
+
return new Type29(checker, flags);
|
|
53858
53863
|
}
|
|
53859
53864
|
function createIntrinsicType(kind, intrinsicName, objectFlags = 0 /* None */, debugIntrinsicName) {
|
|
53860
53865
|
checkIntrinsicName(intrinsicName, debugIntrinsicName);
|
|
@@ -54452,31 +54457,31 @@ function createTypeChecker(host) {
|
|
|
54452
54457
|
}
|
|
54453
54458
|
function createNodeBuilder() {
|
|
54454
54459
|
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) =>
|
|
54460
|
+
typeToTypeNode: (type, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeToTypeNodeHelper(type, context)),
|
|
54461
|
+
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
|
|
54462
|
+
expressionOrTypeToTypeNode: (expr, type, addUndefined, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => expressionOrTypeToTypeNode(context, expr, type, addUndefined)),
|
|
54463
|
+
serializeTypeForDeclaration: (declaration, type, symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => serializeTypeForDeclaration(context, declaration, type, symbol)),
|
|
54464
|
+
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => serializeReturnTypeForSignature(context, signature)),
|
|
54465
|
+
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
|
|
54461
54466
|
indexInfo,
|
|
54462
54467
|
context,
|
|
54463
54468
|
/*typeNode*/
|
|
54464
54469
|
void 0
|
|
54465
54470
|
)),
|
|
54466
|
-
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, tracker) =>
|
|
54467
|
-
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, tracker) =>
|
|
54471
|
+
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
|
|
54472
|
+
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToName(
|
|
54468
54473
|
symbol,
|
|
54469
54474
|
context,
|
|
54470
54475
|
meaning,
|
|
54471
54476
|
/*expectsIdentifier*/
|
|
54472
54477
|
false
|
|
54473
54478
|
)),
|
|
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) =>
|
|
54479
|
+
symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
|
|
54480
|
+
symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
|
|
54481
|
+
symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
|
|
54482
|
+
typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
|
|
54483
|
+
symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
|
|
54484
|
+
symbolToNode: (symbol, meaning, enclosingDeclaration, flags, tracker) => withContext2(enclosingDeclaration, flags, tracker, (context) => symbolToNode(symbol, context, meaning))
|
|
54480
54485
|
};
|
|
54481
54486
|
function setTextRange2(context, range, location) {
|
|
54482
54487
|
if (!nodeIsSynthesized(range) && !(range.flags & 16 /* Synthesized */) && (!context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(range))) {
|
|
@@ -54559,7 +54564,7 @@ function createTypeChecker(host) {
|
|
|
54559
54564
|
}
|
|
54560
54565
|
return symbolToExpression(symbol, context, meaning);
|
|
54561
54566
|
}
|
|
54562
|
-
function
|
|
54567
|
+
function withContext2(enclosingDeclaration, flags, tracker, cb) {
|
|
54563
54568
|
Debug.assert(enclosingDeclaration === void 0 || (enclosingDeclaration.flags & 16 /* Synthesized */) === 0);
|
|
54564
54569
|
const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : flags & 134217728 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
|
|
54565
54570
|
const context = {
|
|
@@ -74352,8 +74357,6 @@ function createTypeChecker(host) {
|
|
|
74352
74357
|
) & (111551 /* Value */ | 1048576 /* ExportValue */)) {
|
|
74353
74358
|
if (getIsolatedModules(compilerOptions) || shouldPreserveConstEnums(compilerOptions) && isExportOrExportExpression(location) || !isConstEnumOrConstEnumOnlyModule(getExportSymbolOfValueSymbolIfExported(target))) {
|
|
74354
74359
|
markAliasSymbolAsReferenced(symbol);
|
|
74355
|
-
} else {
|
|
74356
|
-
markConstEnumAliasAsReferenced(symbol);
|
|
74357
74360
|
}
|
|
74358
74361
|
}
|
|
74359
74362
|
}
|
|
@@ -75610,60 +75613,71 @@ function createTypeChecker(host) {
|
|
|
75610
75613
|
return false;
|
|
75611
75614
|
}
|
|
75612
75615
|
function discriminateContextualTypeByObjectMembers(node, contextualType) {
|
|
75613
|
-
|
|
75614
|
-
|
|
75615
|
-
|
|
75616
|
-
|
|
75617
|
-
|
|
75618
|
-
|
|
75616
|
+
const key = `D${getNodeId(node)},${getTypeId(contextualType)}`;
|
|
75617
|
+
return getCachedType(key) ?? setCachedType(
|
|
75618
|
+
key,
|
|
75619
|
+
getMatchingUnionConstituentForObjectLiteral(contextualType, node) ?? discriminateTypeByDiscriminableItems(
|
|
75620
|
+
contextualType,
|
|
75621
|
+
concatenate(
|
|
75622
|
+
map(
|
|
75623
|
+
filter(node.properties, (p) => {
|
|
75624
|
+
if (!p.symbol) {
|
|
75625
|
+
return false;
|
|
75626
|
+
}
|
|
75627
|
+
if (p.kind === 303 /* PropertyAssignment */) {
|
|
75628
|
+
return isPossiblyDiscriminantValue(p.initializer) && isDiscriminantProperty(contextualType, p.symbol.escapedName);
|
|
75629
|
+
}
|
|
75630
|
+
if (p.kind === 304 /* ShorthandPropertyAssignment */) {
|
|
75631
|
+
return isDiscriminantProperty(contextualType, p.symbol.escapedName);
|
|
75632
|
+
}
|
|
75619
75633
|
return false;
|
|
75620
|
-
}
|
|
75621
|
-
|
|
75622
|
-
|
|
75623
|
-
|
|
75624
|
-
|
|
75625
|
-
|
|
75626
|
-
|
|
75627
|
-
|
|
75628
|
-
|
|
75629
|
-
|
|
75634
|
+
}),
|
|
75635
|
+
(prop) => [() => getContextFreeTypeOfExpression(prop.kind === 303 /* PropertyAssignment */ ? prop.initializer : prop.name), prop.symbol.escapedName]
|
|
75636
|
+
),
|
|
75637
|
+
map(
|
|
75638
|
+
filter(getPropertiesOfType(contextualType), (s) => {
|
|
75639
|
+
var _a;
|
|
75640
|
+
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);
|
|
75641
|
+
}),
|
|
75642
|
+
(s) => [() => undefinedType, s.escapedName]
|
|
75643
|
+
)
|
|
75630
75644
|
),
|
|
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
|
|
75645
|
+
isTypeAssignableTo
|
|
75646
|
+
)
|
|
75640
75647
|
);
|
|
75641
75648
|
}
|
|
75642
75649
|
function discriminateContextualTypeByJSXAttributes(node, contextualType) {
|
|
75650
|
+
const key = `D${getNodeId(node)},${getTypeId(contextualType)}`;
|
|
75651
|
+
const cached = getCachedType(key);
|
|
75652
|
+
if (cached)
|
|
75653
|
+
return cached;
|
|
75643
75654
|
const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node));
|
|
75644
|
-
return
|
|
75645
|
-
|
|
75646
|
-
|
|
75647
|
-
|
|
75648
|
-
|
|
75649
|
-
(
|
|
75655
|
+
return setCachedType(
|
|
75656
|
+
key,
|
|
75657
|
+
discriminateTypeByDiscriminableItems(
|
|
75658
|
+
contextualType,
|
|
75659
|
+
concatenate(
|
|
75660
|
+
map(
|
|
75661
|
+
filter(node.properties, (p) => !!p.symbol && p.kind === 291 /* JsxAttribute */ && isDiscriminantProperty(contextualType, p.symbol.escapedName) && (!p.initializer || isPossiblyDiscriminantValue(p.initializer))),
|
|
75662
|
+
(prop) => [!prop.initializer ? () => trueType : () => getContextFreeTypeOfExpression(prop.initializer), prop.symbol.escapedName]
|
|
75663
|
+
),
|
|
75664
|
+
map(
|
|
75665
|
+
filter(getPropertiesOfType(contextualType), (s) => {
|
|
75666
|
+
var _a;
|
|
75667
|
+
if (!(s.flags & 16777216 /* Optional */) || !((_a = node == null ? void 0 : node.symbol) == null ? void 0 : _a.members)) {
|
|
75668
|
+
return false;
|
|
75669
|
+
}
|
|
75670
|
+
const element = node.parent.parent;
|
|
75671
|
+
if (s.escapedName === jsxChildrenPropertyName && isJsxElement(element) && getSemanticJsxChildren(element.children).length) {
|
|
75672
|
+
return false;
|
|
75673
|
+
}
|
|
75674
|
+
return !node.symbol.members.has(s.escapedName) && isDiscriminantProperty(contextualType, s.escapedName);
|
|
75675
|
+
}),
|
|
75676
|
+
(s) => [() => undefinedType, s.escapedName]
|
|
75677
|
+
)
|
|
75650
75678
|
),
|
|
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
|
|
75679
|
+
isTypeAssignableTo
|
|
75680
|
+
)
|
|
75667
75681
|
);
|
|
75668
75682
|
}
|
|
75669
75683
|
function getApparentTypeOfContextualType(node, contextFlags) {
|
|
@@ -142878,6 +142892,7 @@ __export(ts_refactor_exports, {
|
|
|
142878
142892
|
generateGetAccessorAndSetAccessor: () => ts_refactor_generateGetAccessorAndSetAccessor_exports,
|
|
142879
142893
|
getApplicableRefactors: () => getApplicableRefactors,
|
|
142880
142894
|
getEditsForRefactor: () => getEditsForRefactor,
|
|
142895
|
+
getIdentifierForNode: () => getIdentifierForNode,
|
|
142881
142896
|
getNewStatementsAndRemoveFromOldFile: () => getNewStatementsAndRemoveFromOldFile,
|
|
142882
142897
|
getStatementsToMove: () => getStatementsToMove,
|
|
142883
142898
|
getTopLevelDeclarationStatement: () => getTopLevelDeclarationStatement,
|
|
@@ -144606,6 +144621,15 @@ function refactorKindBeginsWith(known, requested) {
|
|
|
144606
144621
|
return true;
|
|
144607
144622
|
return known.substr(0, requested.length) === requested;
|
|
144608
144623
|
}
|
|
144624
|
+
function getIdentifierForNode(node, scope, checker, file) {
|
|
144625
|
+
return isPropertyAccessExpression(node) && !isClassLike(scope) && !checker.resolveName(
|
|
144626
|
+
node.name.text,
|
|
144627
|
+
node,
|
|
144628
|
+
111551 /* Value */,
|
|
144629
|
+
/*excludeGlobals*/
|
|
144630
|
+
false
|
|
144631
|
+
) && !isPrivateIdentifier(node.name) && !identifierToKeywordKind(node.name) ? node.name.text : getUniqueName(isClassLike(scope) ? "newProperty" : "newLocal", file);
|
|
144632
|
+
}
|
|
144609
144633
|
function addTargetFileImports(oldFile, importsToCopy, targetFileImportsFromOldFile, checker, program, importAdder) {
|
|
144610
144634
|
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
|
|
144611
144635
|
var _a;
|
|
@@ -147289,13 +147313,7 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
147289
147313
|
function extractConstantInScope(node, scope, { substitutions }, rangeFacts, context) {
|
|
147290
147314
|
const checker = context.program.getTypeChecker();
|
|
147291
147315
|
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);
|
|
147316
|
+
const localNameText = getIdentifierForNode(node, scope, checker, file);
|
|
147299
147317
|
const isJS = isInJSFile(scope);
|
|
147300
147318
|
let variableType = isJS || !checker.isContextSensitive(node) ? void 0 : checker.typeToTypeNode(checker.getContextualType(node), scope, 1 /* NoTruncation */);
|
|
147301
147319
|
let initializer = transformConstantInitializer(skipParentheses(node), substitutions);
|
|
@@ -149863,22 +149881,22 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
|
149863
149881
|
}
|
|
149864
149882
|
return [];
|
|
149865
149883
|
}
|
|
149866
|
-
function getCodeFixesAtPosition(fileName, start, end,
|
|
149884
|
+
function getCodeFixesAtPosition(fileName, start, end, errorCodes67, formatOptions, preferences = emptyOptions) {
|
|
149867
149885
|
synchronizeHostData();
|
|
149868
149886
|
const sourceFile = getValidSourceFile(fileName);
|
|
149869
149887
|
const span = createTextSpanFromBounds(start, end);
|
|
149870
149888
|
const formatContext = ts_formatting_exports.getFormatContext(formatOptions, host);
|
|
149871
|
-
return flatMap(deduplicate(
|
|
149889
|
+
return flatMap(deduplicate(errorCodes67, equateValues, compareValues), (errorCode) => {
|
|
149872
149890
|
cancellationToken.throwIfCancellationRequested();
|
|
149873
149891
|
return ts_codefix_exports.getFixes({ errorCode, sourceFile, span, program, host, cancellationToken, formatContext, preferences });
|
|
149874
149892
|
});
|
|
149875
149893
|
}
|
|
149876
|
-
function getCombinedCodeFix(scope,
|
|
149894
|
+
function getCombinedCodeFix(scope, fixId54, formatOptions, preferences = emptyOptions) {
|
|
149877
149895
|
synchronizeHostData();
|
|
149878
149896
|
Debug.assert(scope.type === "file");
|
|
149879
149897
|
const sourceFile = getValidSourceFile(scope.fileName);
|
|
149880
149898
|
const formatContext = ts_formatting_exports.getFormatContext(formatOptions, host);
|
|
149881
|
-
return ts_codefix_exports.getAllFixes({ fixId:
|
|
149899
|
+
return ts_codefix_exports.getAllFixes({ fixId: fixId54, sourceFile, program, host, cancellationToken, formatContext, preferences });
|
|
149882
149900
|
}
|
|
149883
149901
|
function organizeImports2(args, formatOptions, preferences = emptyOptions) {
|
|
149884
149902
|
synchronizeHostData();
|
|
@@ -151557,14 +151575,14 @@ function createCodeFixActionWithoutFixAll(fixName8, changes, description3) {
|
|
|
151557
151575
|
void 0
|
|
151558
151576
|
);
|
|
151559
151577
|
}
|
|
151560
|
-
function createCodeFixAction(fixName8, changes, description3,
|
|
151561
|
-
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes,
|
|
151578
|
+
function createCodeFixAction(fixName8, changes, description3, fixId54, fixAllDescription, command) {
|
|
151579
|
+
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes, fixId54, diagnosticToString(fixAllDescription), command);
|
|
151562
151580
|
}
|
|
151563
|
-
function createCodeFixActionMaybeFixAll(fixName8, changes, description3,
|
|
151564
|
-
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes,
|
|
151581
|
+
function createCodeFixActionMaybeFixAll(fixName8, changes, description3, fixId54, fixAllDescription, command) {
|
|
151582
|
+
return createCodeFixActionWorker(fixName8, diagnosticToString(description3), changes, fixId54, fixAllDescription && diagnosticToString(fixAllDescription), command);
|
|
151565
151583
|
}
|
|
151566
|
-
function createCodeFixActionWorker(fixName8, description3, changes,
|
|
151567
|
-
return { fixName: fixName8, description: description3, changes, fixId:
|
|
151584
|
+
function createCodeFixActionWorker(fixName8, description3, changes, fixId54, fixAllDescription, command) {
|
|
151585
|
+
return { fixName: fixName8, description: description3, changes, fixId: fixId54, fixAllDescription, commands: command ? [command] : void 0 };
|
|
151568
151586
|
}
|
|
151569
151587
|
function registerCodeFix(reg) {
|
|
151570
151588
|
for (const error2 of reg.errorCodes) {
|
|
@@ -151572,9 +151590,9 @@ function registerCodeFix(reg) {
|
|
|
151572
151590
|
errorCodeToFixes.add(String(error2), reg);
|
|
151573
151591
|
}
|
|
151574
151592
|
if (reg.fixIds) {
|
|
151575
|
-
for (const
|
|
151576
|
-
Debug.assert(!fixIdToRegistration.has(
|
|
151577
|
-
fixIdToRegistration.set(
|
|
151593
|
+
for (const fixId54 of reg.fixIds) {
|
|
151594
|
+
Debug.assert(!fixIdToRegistration.has(fixId54));
|
|
151595
|
+
fixIdToRegistration.set(fixId54, reg);
|
|
151578
151596
|
}
|
|
151579
151597
|
}
|
|
151580
151598
|
}
|
|
@@ -151583,17 +151601,17 @@ function getSupportedErrorCodes() {
|
|
|
151583
151601
|
return errorCodeToFixesArray ?? (errorCodeToFixesArray = arrayFrom(errorCodeToFixes.keys()));
|
|
151584
151602
|
}
|
|
151585
151603
|
function removeFixIdIfFixAllUnavailable(registration, diagnostics) {
|
|
151586
|
-
const { errorCodes:
|
|
151604
|
+
const { errorCodes: errorCodes67 } = registration;
|
|
151587
151605
|
let maybeFixableDiagnostics = 0;
|
|
151588
151606
|
for (const diag2 of diagnostics) {
|
|
151589
|
-
if (contains(
|
|
151607
|
+
if (contains(errorCodes67, diag2.code))
|
|
151590
151608
|
maybeFixableDiagnostics++;
|
|
151591
151609
|
if (maybeFixableDiagnostics > 1)
|
|
151592
151610
|
break;
|
|
151593
151611
|
}
|
|
151594
151612
|
const fixAllUnavailable = maybeFixableDiagnostics < 2;
|
|
151595
|
-
return ({ fixId:
|
|
151596
|
-
return fixAllUnavailable ? action : { ...action, fixId:
|
|
151613
|
+
return ({ fixId: fixId54, fixAllDescription, ...action }) => {
|
|
151614
|
+
return fixAllUnavailable ? action : { ...action, fixId: fixId54, fixAllDescription };
|
|
151597
151615
|
};
|
|
151598
151616
|
}
|
|
151599
151617
|
function getFixes(context) {
|
|
@@ -151610,24 +151628,30 @@ function createCombinedCodeActions(changes, commands) {
|
|
|
151610
151628
|
function createFileTextChanges(fileName, textChanges2) {
|
|
151611
151629
|
return { fileName, textChanges: textChanges2 };
|
|
151612
151630
|
}
|
|
151613
|
-
function codeFixAll(context,
|
|
151631
|
+
function codeFixAll(context, errorCodes67, use) {
|
|
151614
151632
|
const commands = [];
|
|
151615
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context,
|
|
151633
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context, errorCodes67, (diag2) => use(t, diag2, commands)));
|
|
151616
151634
|
return createCombinedCodeActions(changes, commands.length === 0 ? void 0 : commands);
|
|
151617
151635
|
}
|
|
151618
|
-
function eachDiagnostic(context,
|
|
151636
|
+
function eachDiagnostic(context, errorCodes67, cb) {
|
|
151619
151637
|
for (const diag2 of getDiagnostics(context)) {
|
|
151620
|
-
if (contains(
|
|
151638
|
+
if (contains(errorCodes67, diag2.code)) {
|
|
151621
151639
|
cb(diag2);
|
|
151622
151640
|
}
|
|
151623
151641
|
}
|
|
151624
151642
|
}
|
|
151625
151643
|
function getDiagnostics({ program, sourceFile, cancellationToken }) {
|
|
151626
|
-
|
|
151644
|
+
const diagnostics = [
|
|
151627
151645
|
...program.getSemanticDiagnostics(sourceFile, cancellationToken),
|
|
151628
151646
|
...program.getSyntacticDiagnostics(sourceFile, cancellationToken),
|
|
151629
151647
|
...computeSuggestionDiagnostics(sourceFile, program, cancellationToken)
|
|
151630
151648
|
];
|
|
151649
|
+
if (getEmitDeclarations(program.getCompilerOptions())) {
|
|
151650
|
+
diagnostics.push(
|
|
151651
|
+
...program.getDeclarationDiagnostics(sourceFile, cancellationToken)
|
|
151652
|
+
);
|
|
151653
|
+
}
|
|
151654
|
+
return diagnostics;
|
|
151631
151655
|
}
|
|
151632
151656
|
|
|
151633
151657
|
// src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts
|
|
@@ -156315,10 +156339,10 @@ registerCodeFix({
|
|
|
156315
156339
|
const info = errorCodeFixIdMap[errorCode];
|
|
156316
156340
|
if (!info)
|
|
156317
156341
|
return emptyArray;
|
|
156318
|
-
const { descriptions, fixId:
|
|
156342
|
+
const { descriptions, fixId: fixId54, fixAllDescriptions } = info;
|
|
156319
156343
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (changes2) => dispatchChanges(changes2, context, errorCode, span.start));
|
|
156320
156344
|
return [
|
|
156321
|
-
createCodeFixActionMaybeFixAll(fixName, changes, descriptions,
|
|
156345
|
+
createCodeFixActionMaybeFixAll(fixName, changes, descriptions, fixId54, fixAllDescriptions)
|
|
156322
156346
|
];
|
|
156323
156347
|
},
|
|
156324
156348
|
fixIds: [fixName, fixAddOverrideId, fixRemoveOverrideId],
|
|
@@ -157123,7 +157147,7 @@ registerCodeFix({
|
|
|
157123
157147
|
},
|
|
157124
157148
|
fixIds: [fixMissingMember, fixMissingFunctionDeclaration, fixMissingProperties, fixMissingAttributes],
|
|
157125
157149
|
getAllCodeActions: (context) => {
|
|
157126
|
-
const { program, fixId:
|
|
157150
|
+
const { program, fixId: fixId54 } = context;
|
|
157127
157151
|
const checker = program.getTypeChecker();
|
|
157128
157152
|
const seen = /* @__PURE__ */ new Map();
|
|
157129
157153
|
const typeDeclToMembers = /* @__PURE__ */ new Map();
|
|
@@ -157133,11 +157157,11 @@ registerCodeFix({
|
|
|
157133
157157
|
if (!info || !addToSeen(seen, getNodeId(info.parentDeclaration) + "#" + (info.kind === 3 /* ObjectLiteral */ ? info.identifier : info.token.text))) {
|
|
157134
157158
|
return;
|
|
157135
157159
|
}
|
|
157136
|
-
if (
|
|
157160
|
+
if (fixId54 === fixMissingFunctionDeclaration && (info.kind === 2 /* Function */ || info.kind === 5 /* Signature */)) {
|
|
157137
157161
|
addFunctionDeclaration(changes, context, info);
|
|
157138
|
-
} else if (
|
|
157162
|
+
} else if (fixId54 === fixMissingProperties && info.kind === 3 /* ObjectLiteral */) {
|
|
157139
157163
|
addObjectLiteralProperties(changes, context, info);
|
|
157140
|
-
} else if (
|
|
157164
|
+
} else if (fixId54 === fixMissingAttributes && info.kind === 4 /* JsxAttributes */) {
|
|
157141
157165
|
addJsxAttributes(changes, context, info);
|
|
157142
157166
|
} else {
|
|
157143
157167
|
if (info.kind === 1 /* Enum */) {
|
|
@@ -159059,21 +159083,21 @@ registerCodeFix({
|
|
|
159059
159083
|
actions2.push(fix(type, fixIdNullable, Diagnostics.Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types));
|
|
159060
159084
|
}
|
|
159061
159085
|
return actions2;
|
|
159062
|
-
function fix(type2,
|
|
159086
|
+
function fix(type2, fixId54, fixAllDescription) {
|
|
159063
159087
|
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)],
|
|
159088
|
+
return createCodeFixAction("jdocTypes", changes, [Diagnostics.Change_0_to_1, original, checker.typeToString(type2)], fixId54, fixAllDescription);
|
|
159065
159089
|
}
|
|
159066
159090
|
},
|
|
159067
159091
|
fixIds: [fixIdPlain, fixIdNullable],
|
|
159068
159092
|
getAllCodeActions(context) {
|
|
159069
|
-
const { fixId:
|
|
159093
|
+
const { fixId: fixId54, program, sourceFile } = context;
|
|
159070
159094
|
const checker = program.getTypeChecker();
|
|
159071
159095
|
return codeFixAll(context, errorCodes45, (changes, err) => {
|
|
159072
159096
|
const info = getInfo15(err.file, err.start, checker);
|
|
159073
159097
|
if (!info)
|
|
159074
159098
|
return;
|
|
159075
159099
|
const { typeNode, type } = info;
|
|
159076
|
-
const fixedType = typeNode.kind === 314 /* JSDocNullableType */ &&
|
|
159100
|
+
const fixedType = typeNode.kind === 314 /* JSDocNullableType */ && fixId54 === fixIdNullable ? checker.getNullableType(type, 32768 /* Undefined */) : type;
|
|
159077
159101
|
doChange29(changes, sourceFile, typeNode, fixedType, checker);
|
|
159078
159102
|
});
|
|
159079
159103
|
}
|
|
@@ -159168,28 +159192,909 @@ function getCallName(sourceFile, start) {
|
|
|
159168
159192
|
return void 0;
|
|
159169
159193
|
}
|
|
159170
159194
|
|
|
159171
|
-
// src/services/codefixes/
|
|
159172
|
-
var fixId36 = "
|
|
159195
|
+
// src/services/codefixes/fixMissingTypeAnnotationOnExports.ts
|
|
159196
|
+
var fixId36 = "fixMissingTypeAnnotationOnExports";
|
|
159197
|
+
var addAnnotationFix = "add-annotation";
|
|
159198
|
+
var addInlineTypeAssertion = "add-type-assertion";
|
|
159199
|
+
var extractExpression = "extract-expression";
|
|
159173
159200
|
var errorCodes47 = [
|
|
159201
|
+
Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159202
|
+
Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159203
|
+
Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations.code,
|
|
159204
|
+
Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159205
|
+
Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159206
|
+
Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations.code,
|
|
159207
|
+
Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159208
|
+
Diagnostics.Binding_elements_can_t_be_exported_directly_with_isolatedDeclarations.code,
|
|
159209
|
+
Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations.code,
|
|
159210
|
+
Diagnostics.Enum_member_initializers_must_be_computable_without_references_to_external_symbols_with_isolatedDeclarations.code,
|
|
159211
|
+
Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations.code,
|
|
159212
|
+
Diagnostics.Objects_that_contain_shorthand_properties_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159213
|
+
Diagnostics.Objects_that_contain_spread_assignments_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159214
|
+
Diagnostics.Arrays_with_spread_elements_can_t_inferred_with_isolatedDeclarations.code,
|
|
159215
|
+
Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations.code,
|
|
159216
|
+
Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations.code,
|
|
159217
|
+
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,
|
|
159218
|
+
Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations.code,
|
|
159219
|
+
Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_the_type_explicit.code
|
|
159220
|
+
];
|
|
159221
|
+
var canHaveTypeAnnotation = /* @__PURE__ */ new Set([
|
|
159222
|
+
177 /* GetAccessor */,
|
|
159223
|
+
174 /* MethodDeclaration */,
|
|
159224
|
+
172 /* PropertyDeclaration */,
|
|
159225
|
+
262 /* FunctionDeclaration */,
|
|
159226
|
+
218 /* FunctionExpression */,
|
|
159227
|
+
219 /* ArrowFunction */,
|
|
159228
|
+
260 /* VariableDeclaration */,
|
|
159229
|
+
169 /* Parameter */,
|
|
159230
|
+
277 /* ExportAssignment */,
|
|
159231
|
+
263 /* ClassDeclaration */,
|
|
159232
|
+
206 /* ObjectBindingPattern */,
|
|
159233
|
+
207 /* ArrayBindingPattern */
|
|
159234
|
+
]);
|
|
159235
|
+
var declarationEmitNodeBuilderFlags2 = 1024 /* MultilineObjectLiterals */ | 2048 /* WriteClassExpressionAsTypeLiteral */ | 4096 /* UseTypeOfFunction */ | 8 /* UseStructuralFallback */ | 524288 /* AllowEmptyTuple */ | 4 /* GenerateNamesForShadowedTypeParams */ | 1 /* NoTruncation */ | 1073741824 /* WriteComputedProps */;
|
|
159236
|
+
registerCodeFix({
|
|
159237
|
+
errorCodes: errorCodes47,
|
|
159238
|
+
fixIds: [fixId36],
|
|
159239
|
+
getCodeActions(context) {
|
|
159240
|
+
const fixes = [];
|
|
159241
|
+
addCodeAction(addAnnotationFix, fixes, context, 0 /* Full */, (f) => f.addTypeAnnotation(context.span));
|
|
159242
|
+
addCodeAction(addAnnotationFix, fixes, context, 1 /* Relative */, (f) => f.addTypeAnnotation(context.span));
|
|
159243
|
+
addCodeAction(addAnnotationFix, fixes, context, 2 /* Widened */, (f) => f.addTypeAnnotation(context.span));
|
|
159244
|
+
addCodeAction(addInlineTypeAssertion, fixes, context, 0 /* Full */, (f) => f.addInlineAssertion(context.span));
|
|
159245
|
+
addCodeAction(addInlineTypeAssertion, fixes, context, 1 /* Relative */, (f) => f.addInlineAssertion(context.span));
|
|
159246
|
+
addCodeAction(addAnnotationFix, fixes, context, 2 /* Widened */, (f) => f.addInlineAssertion(context.span));
|
|
159247
|
+
addCodeAction(extractExpression, fixes, context, 0 /* Full */, (f) => f.extractAsVariable(context.span));
|
|
159248
|
+
return fixes;
|
|
159249
|
+
},
|
|
159250
|
+
getAllCodeActions: (context) => {
|
|
159251
|
+
const changes = withContext(context, 0 /* Full */, (f) => {
|
|
159252
|
+
eachDiagnostic(context, errorCodes47, (diag2) => {
|
|
159253
|
+
f.addTypeAnnotation(diag2);
|
|
159254
|
+
});
|
|
159255
|
+
});
|
|
159256
|
+
return createCombinedCodeActions(changes.textChanges);
|
|
159257
|
+
}
|
|
159258
|
+
});
|
|
159259
|
+
function addCodeAction(fixName8, fixes, context, typePrintMode, cb) {
|
|
159260
|
+
const changes = withContext(context, typePrintMode, cb);
|
|
159261
|
+
if (changes.result && changes.textChanges.length) {
|
|
159262
|
+
fixes.push(createCodeFixAction(
|
|
159263
|
+
fixName8,
|
|
159264
|
+
changes.textChanges,
|
|
159265
|
+
changes.result,
|
|
159266
|
+
fixId36,
|
|
159267
|
+
Diagnostics.Add_all_missing_type_annotations
|
|
159268
|
+
));
|
|
159269
|
+
}
|
|
159270
|
+
}
|
|
159271
|
+
function withContext(context, typePrintMode, cb) {
|
|
159272
|
+
const emptyInferenceResult = { typeNode: void 0, mutatedTarget: false };
|
|
159273
|
+
const changeTracker = ts_textChanges_exports.ChangeTracker.fromContext(context);
|
|
159274
|
+
const sourceFile = context.sourceFile;
|
|
159275
|
+
const program = context.program;
|
|
159276
|
+
const typeChecker = program.getTypeChecker();
|
|
159277
|
+
const emitResolver = typeChecker.getEmitResolver();
|
|
159278
|
+
const scriptTarget = getEmitScriptTarget(program.getCompilerOptions());
|
|
159279
|
+
const importAdder = createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
159280
|
+
const fixedNodes = /* @__PURE__ */ new Set();
|
|
159281
|
+
const expandoPropertiesAdded = /* @__PURE__ */ new Set();
|
|
159282
|
+
const typePrinter = createPrinter({
|
|
159283
|
+
preserveSourceNewlines: false
|
|
159284
|
+
});
|
|
159285
|
+
const result = cb({ addTypeAnnotation, addInlineAssertion, extractAsVariable });
|
|
159286
|
+
importAdder.writeFixes(changeTracker);
|
|
159287
|
+
return {
|
|
159288
|
+
result,
|
|
159289
|
+
textChanges: changeTracker.getChanges()
|
|
159290
|
+
};
|
|
159291
|
+
function addTypeAnnotation(span) {
|
|
159292
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159293
|
+
const expandoFunction = findExpandoFunction(nodeWithDiag);
|
|
159294
|
+
if (expandoFunction) {
|
|
159295
|
+
if (isFunctionDeclaration(expandoFunction)) {
|
|
159296
|
+
return createNamespaceForExpandoProperties(expandoFunction);
|
|
159297
|
+
}
|
|
159298
|
+
return fixIsolatedDeclarationError(expandoFunction);
|
|
159299
|
+
}
|
|
159300
|
+
const nodeMissingType = findAncestorWithMissingType(nodeWithDiag);
|
|
159301
|
+
if (nodeMissingType) {
|
|
159302
|
+
return fixIsolatedDeclarationError(nodeMissingType);
|
|
159303
|
+
}
|
|
159304
|
+
return void 0;
|
|
159305
|
+
}
|
|
159306
|
+
function createNamespaceForExpandoProperties(expandoFunc) {
|
|
159307
|
+
var _a;
|
|
159308
|
+
if (expandoPropertiesAdded == null ? void 0 : expandoPropertiesAdded.has(expandoFunc))
|
|
159309
|
+
return void 0;
|
|
159310
|
+
expandoPropertiesAdded == null ? void 0 : expandoPropertiesAdded.add(expandoFunc);
|
|
159311
|
+
const type = typeChecker.getTypeAtLocation(expandoFunc);
|
|
159312
|
+
const elements = typeChecker.getPropertiesOfType(type);
|
|
159313
|
+
if (!expandoFunc.name || elements.length === 0)
|
|
159314
|
+
return void 0;
|
|
159315
|
+
const newProperties = [];
|
|
159316
|
+
for (const symbol of elements) {
|
|
159317
|
+
if (!isIdentifierText(symbol.name, getEmitScriptTarget(program.getCompilerOptions())))
|
|
159318
|
+
continue;
|
|
159319
|
+
if (symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration))
|
|
159320
|
+
continue;
|
|
159321
|
+
newProperties.push(factory.createVariableStatement(
|
|
159322
|
+
[factory.createModifier(95 /* ExportKeyword */)],
|
|
159323
|
+
factory.createVariableDeclarationList(
|
|
159324
|
+
[factory.createVariableDeclaration(
|
|
159325
|
+
symbol.name,
|
|
159326
|
+
/*exclamationToken*/
|
|
159327
|
+
void 0,
|
|
159328
|
+
typeToTypeNode2(typeChecker.getTypeOfSymbol(symbol), expandoFunc),
|
|
159329
|
+
/*initializer*/
|
|
159330
|
+
void 0
|
|
159331
|
+
)]
|
|
159332
|
+
)
|
|
159333
|
+
));
|
|
159334
|
+
}
|
|
159335
|
+
if (newProperties.length === 0)
|
|
159336
|
+
return void 0;
|
|
159337
|
+
const modifiers = [];
|
|
159338
|
+
if ((_a = expandoFunc.modifiers) == null ? void 0 : _a.some((modifier) => modifier.kind === 95 /* ExportKeyword */)) {
|
|
159339
|
+
modifiers.push(factory.createModifier(95 /* ExportKeyword */));
|
|
159340
|
+
}
|
|
159341
|
+
modifiers.push(factory.createModifier(138 /* DeclareKeyword */));
|
|
159342
|
+
const namespace = factory.createModuleDeclaration(
|
|
159343
|
+
modifiers,
|
|
159344
|
+
expandoFunc.name,
|
|
159345
|
+
factory.createModuleBlock(newProperties),
|
|
159346
|
+
/*flags*/
|
|
159347
|
+
32 /* Namespace */ | 128 /* ExportContext */ | 33554432 /* Ambient */ | 101441536 /* ContextFlags */
|
|
159348
|
+
);
|
|
159349
|
+
changeTracker.insertNodeAfter(sourceFile, expandoFunc, namespace);
|
|
159350
|
+
return [Diagnostics.Annotate_types_of_properties_expando_function_in_a_namespace];
|
|
159351
|
+
}
|
|
159352
|
+
function needsParenthesizedExpressionForAssertion(node) {
|
|
159353
|
+
return !isEntityNameExpression(node) && !isCallExpression(node) && !isObjectLiteralExpression(node) && !isArrayLiteralExpression(node);
|
|
159354
|
+
}
|
|
159355
|
+
function createAsExpression(node, type) {
|
|
159356
|
+
if (needsParenthesizedExpressionForAssertion(node)) {
|
|
159357
|
+
node = factory.createParenthesizedExpression(node);
|
|
159358
|
+
}
|
|
159359
|
+
return factory.createAsExpression(node, type);
|
|
159360
|
+
}
|
|
159361
|
+
function createSatisfiesAsExpression(node, type) {
|
|
159362
|
+
if (needsParenthesizedExpressionForAssertion(node)) {
|
|
159363
|
+
node = factory.createParenthesizedExpression(node);
|
|
159364
|
+
}
|
|
159365
|
+
return factory.createAsExpression(factory.createSatisfiesExpression(node, getSynthesizedDeepClone(type)), type);
|
|
159366
|
+
}
|
|
159367
|
+
function addInlineAssertion(span) {
|
|
159368
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159369
|
+
const expandoFunction = findExpandoFunction(nodeWithDiag);
|
|
159370
|
+
if (expandoFunction)
|
|
159371
|
+
return;
|
|
159372
|
+
const targetNode = findBestFittingNode(nodeWithDiag, span);
|
|
159373
|
+
if (!targetNode || isValueSignatureDeclaration(targetNode) || isValueSignatureDeclaration(targetNode.parent))
|
|
159374
|
+
return;
|
|
159375
|
+
const isExpressionTarget = isExpression(targetNode);
|
|
159376
|
+
const isShorthandPropertyAssignmentTarget = isShorthandPropertyAssignment(targetNode);
|
|
159377
|
+
if (!isShorthandPropertyAssignmentTarget && isDeclaration(targetNode)) {
|
|
159378
|
+
return void 0;
|
|
159379
|
+
}
|
|
159380
|
+
if (findAncestor(targetNode, isBindingPattern)) {
|
|
159381
|
+
return void 0;
|
|
159382
|
+
}
|
|
159383
|
+
if (findAncestor(targetNode, isEnumMember)) {
|
|
159384
|
+
return void 0;
|
|
159385
|
+
}
|
|
159386
|
+
if (isExpressionTarget && findAncestor(targetNode, isHeritageClause)) {
|
|
159387
|
+
return void 0;
|
|
159388
|
+
}
|
|
159389
|
+
if (isSpreadElement(targetNode)) {
|
|
159390
|
+
return void 0;
|
|
159391
|
+
}
|
|
159392
|
+
const variableDeclaration = findAncestor(targetNode, isVariableDeclaration);
|
|
159393
|
+
const type = variableDeclaration && typeChecker.getTypeAtLocation(variableDeclaration);
|
|
159394
|
+
if (type && type.flags & 8192 /* UniqueESSymbol */) {
|
|
159395
|
+
return void 0;
|
|
159396
|
+
}
|
|
159397
|
+
if (!(isExpressionTarget || isShorthandPropertyAssignmentTarget))
|
|
159398
|
+
return void 0;
|
|
159399
|
+
const { typeNode, mutatedTarget } = inferType(targetNode, type);
|
|
159400
|
+
if (!typeNode || mutatedTarget)
|
|
159401
|
+
return void 0;
|
|
159402
|
+
if (isShorthandPropertyAssignmentTarget) {
|
|
159403
|
+
changeTracker.insertNodeAt(
|
|
159404
|
+
sourceFile,
|
|
159405
|
+
targetNode.end,
|
|
159406
|
+
createAsExpression(
|
|
159407
|
+
getSynthesizedDeepClone(targetNode.name),
|
|
159408
|
+
typeNode
|
|
159409
|
+
),
|
|
159410
|
+
{
|
|
159411
|
+
prefix: ": "
|
|
159412
|
+
}
|
|
159413
|
+
);
|
|
159414
|
+
} else if (isExpressionTarget) {
|
|
159415
|
+
changeTracker.replaceNode(
|
|
159416
|
+
sourceFile,
|
|
159417
|
+
targetNode,
|
|
159418
|
+
createSatisfiesAsExpression(
|
|
159419
|
+
getSynthesizedDeepClone(targetNode),
|
|
159420
|
+
typeNode
|
|
159421
|
+
)
|
|
159422
|
+
);
|
|
159423
|
+
} else {
|
|
159424
|
+
Debug.assertNever(targetNode);
|
|
159425
|
+
}
|
|
159426
|
+
return [Diagnostics.Add_satisfies_and_an_inline_type_assertion_with_0, typeToStringForDiag(typeNode)];
|
|
159427
|
+
}
|
|
159428
|
+
function extractAsVariable(span) {
|
|
159429
|
+
const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
|
|
159430
|
+
const targetNode = findBestFittingNode(nodeWithDiag, span);
|
|
159431
|
+
if (!targetNode || isValueSignatureDeclaration(targetNode) || isValueSignatureDeclaration(targetNode.parent))
|
|
159432
|
+
return;
|
|
159433
|
+
const isExpressionTarget = isExpression(targetNode);
|
|
159434
|
+
if (!isExpressionTarget)
|
|
159435
|
+
return;
|
|
159436
|
+
if (isArrayLiteralExpression(targetNode)) {
|
|
159437
|
+
changeTracker.replaceNode(
|
|
159438
|
+
sourceFile,
|
|
159439
|
+
targetNode,
|
|
159440
|
+
createAsExpression(targetNode, factory.createTypeReferenceNode("const"))
|
|
159441
|
+
);
|
|
159442
|
+
return [Diagnostics.Mark_array_literal_as_const];
|
|
159443
|
+
}
|
|
159444
|
+
const parentPropertyAssignment = findAncestor(targetNode, isPropertyAssignment);
|
|
159445
|
+
if (parentPropertyAssignment) {
|
|
159446
|
+
if (parentPropertyAssignment === targetNode.parent && isEntityNameExpression(targetNode))
|
|
159447
|
+
return;
|
|
159448
|
+
const tempName = factory.createUniqueName(
|
|
159449
|
+
getIdentifierForNode(targetNode, sourceFile, typeChecker, sourceFile),
|
|
159450
|
+
16 /* Optimistic */
|
|
159451
|
+
);
|
|
159452
|
+
let replacementTarget = targetNode;
|
|
159453
|
+
let initializationNode = targetNode;
|
|
159454
|
+
if (isSpreadElement(replacementTarget)) {
|
|
159455
|
+
replacementTarget = walkUpParenthesizedExpressions(replacementTarget.parent);
|
|
159456
|
+
if (isConstAssertion2(replacementTarget.parent)) {
|
|
159457
|
+
initializationNode = replacementTarget = replacementTarget.parent;
|
|
159458
|
+
} else {
|
|
159459
|
+
initializationNode = createAsExpression(
|
|
159460
|
+
replacementTarget,
|
|
159461
|
+
factory.createTypeReferenceNode("const")
|
|
159462
|
+
);
|
|
159463
|
+
}
|
|
159464
|
+
}
|
|
159465
|
+
if (isEntityNameExpression(replacementTarget))
|
|
159466
|
+
return void 0;
|
|
159467
|
+
const variableDefinition = factory.createVariableStatement(
|
|
159468
|
+
/*modifiers*/
|
|
159469
|
+
void 0,
|
|
159470
|
+
factory.createVariableDeclarationList([
|
|
159471
|
+
factory.createVariableDeclaration(
|
|
159472
|
+
tempName,
|
|
159473
|
+
/*exclamationToken*/
|
|
159474
|
+
void 0,
|
|
159475
|
+
/*type*/
|
|
159476
|
+
void 0,
|
|
159477
|
+
initializationNode
|
|
159478
|
+
)
|
|
159479
|
+
], 2 /* Const */)
|
|
159480
|
+
);
|
|
159481
|
+
const statement = findAncestor(targetNode, isStatement);
|
|
159482
|
+
changeTracker.insertNodeBefore(sourceFile, statement, variableDefinition);
|
|
159483
|
+
changeTracker.replaceNode(
|
|
159484
|
+
sourceFile,
|
|
159485
|
+
replacementTarget,
|
|
159486
|
+
factory.createAsExpression(
|
|
159487
|
+
factory.cloneNode(tempName),
|
|
159488
|
+
factory.createTypeQueryNode(
|
|
159489
|
+
factory.cloneNode(tempName)
|
|
159490
|
+
)
|
|
159491
|
+
)
|
|
159492
|
+
);
|
|
159493
|
+
return [Diagnostics.Extract_to_variable_and_replace_with_0_as_typeof_0, typeToStringForDiag(tempName)];
|
|
159494
|
+
}
|
|
159495
|
+
}
|
|
159496
|
+
function findExpandoFunction(node) {
|
|
159497
|
+
const expandoDeclaration = findAncestor(node, (n) => isStatement(n) ? "quit" : isExpandoPropertyDeclaration(n));
|
|
159498
|
+
if (expandoDeclaration && isExpandoPropertyDeclaration(expandoDeclaration)) {
|
|
159499
|
+
let assignmentTarget = expandoDeclaration;
|
|
159500
|
+
if (isBinaryExpression(assignmentTarget)) {
|
|
159501
|
+
assignmentTarget = assignmentTarget.left;
|
|
159502
|
+
if (!isExpandoPropertyDeclaration(assignmentTarget))
|
|
159503
|
+
return void 0;
|
|
159504
|
+
}
|
|
159505
|
+
const targetType = typeChecker.getTypeAtLocation(assignmentTarget.expression);
|
|
159506
|
+
if (!targetType)
|
|
159507
|
+
return;
|
|
159508
|
+
const properties = typeChecker.getPropertiesOfType(targetType);
|
|
159509
|
+
if (some(properties, (p) => p.valueDeclaration === expandoDeclaration || p.valueDeclaration === expandoDeclaration.parent)) {
|
|
159510
|
+
const fn = targetType.symbol.valueDeclaration;
|
|
159511
|
+
if (fn) {
|
|
159512
|
+
if (isFunctionExpressionOrArrowFunction(fn) && isVariableDeclaration(fn.parent)) {
|
|
159513
|
+
return fn.parent;
|
|
159514
|
+
}
|
|
159515
|
+
if (isFunctionDeclaration(fn)) {
|
|
159516
|
+
return fn;
|
|
159517
|
+
}
|
|
159518
|
+
}
|
|
159519
|
+
}
|
|
159520
|
+
}
|
|
159521
|
+
return void 0;
|
|
159522
|
+
}
|
|
159523
|
+
function fixIsolatedDeclarationError(node) {
|
|
159524
|
+
if (fixedNodes == null ? void 0 : fixedNodes.has(node))
|
|
159525
|
+
return void 0;
|
|
159526
|
+
fixedNodes == null ? void 0 : fixedNodes.add(node);
|
|
159527
|
+
switch (node.kind) {
|
|
159528
|
+
case 169 /* Parameter */:
|
|
159529
|
+
case 172 /* PropertyDeclaration */:
|
|
159530
|
+
case 260 /* VariableDeclaration */:
|
|
159531
|
+
return addTypeToVariableLike(node);
|
|
159532
|
+
case 219 /* ArrowFunction */:
|
|
159533
|
+
case 218 /* FunctionExpression */:
|
|
159534
|
+
case 262 /* FunctionDeclaration */:
|
|
159535
|
+
case 174 /* MethodDeclaration */:
|
|
159536
|
+
case 177 /* GetAccessor */:
|
|
159537
|
+
return addTypeToSignatureDeclaration(node, sourceFile);
|
|
159538
|
+
case 277 /* ExportAssignment */:
|
|
159539
|
+
return transformExportAssignment(node);
|
|
159540
|
+
case 263 /* ClassDeclaration */:
|
|
159541
|
+
return transformExtendsClauseWithExpression(node);
|
|
159542
|
+
case 206 /* ObjectBindingPattern */:
|
|
159543
|
+
case 207 /* ArrayBindingPattern */:
|
|
159544
|
+
return transformDestructuringPatterns(node);
|
|
159545
|
+
default:
|
|
159546
|
+
throw new Error(`Cannot find a fix for the given node ${node.kind}`);
|
|
159547
|
+
}
|
|
159548
|
+
}
|
|
159549
|
+
function addTypeToSignatureDeclaration(func, sourceFile2) {
|
|
159550
|
+
if (func.type) {
|
|
159551
|
+
return;
|
|
159552
|
+
}
|
|
159553
|
+
const { typeNode } = inferType(func);
|
|
159554
|
+
if (typeNode) {
|
|
159555
|
+
changeTracker.tryInsertTypeAnnotation(
|
|
159556
|
+
sourceFile2,
|
|
159557
|
+
func,
|
|
159558
|
+
typeNode
|
|
159559
|
+
);
|
|
159560
|
+
return [Diagnostics.Add_return_type_0, typeToStringForDiag(typeNode)];
|
|
159561
|
+
}
|
|
159562
|
+
}
|
|
159563
|
+
function transformExportAssignment(defaultExport) {
|
|
159564
|
+
if (defaultExport.isExportEquals) {
|
|
159565
|
+
return;
|
|
159566
|
+
}
|
|
159567
|
+
const { typeNode } = inferType(defaultExport.expression);
|
|
159568
|
+
if (!typeNode)
|
|
159569
|
+
return void 0;
|
|
159570
|
+
const defaultIdentifier = factory.createUniqueName("_default");
|
|
159571
|
+
changeTracker.replaceNodeWithNodes(sourceFile, defaultExport, [
|
|
159572
|
+
factory.createVariableStatement(
|
|
159573
|
+
/*modifiers*/
|
|
159574
|
+
void 0,
|
|
159575
|
+
factory.createVariableDeclarationList(
|
|
159576
|
+
[factory.createVariableDeclaration(
|
|
159577
|
+
defaultIdentifier,
|
|
159578
|
+
/*exclamationToken*/
|
|
159579
|
+
void 0,
|
|
159580
|
+
typeNode,
|
|
159581
|
+
defaultExport.expression
|
|
159582
|
+
)],
|
|
159583
|
+
2 /* Const */
|
|
159584
|
+
)
|
|
159585
|
+
),
|
|
159586
|
+
factory.updateExportAssignment(defaultExport, defaultExport == null ? void 0 : defaultExport.modifiers, defaultIdentifier)
|
|
159587
|
+
]);
|
|
159588
|
+
return [
|
|
159589
|
+
Diagnostics.Extract_default_export_to_variable
|
|
159590
|
+
];
|
|
159591
|
+
}
|
|
159592
|
+
function transformExtendsClauseWithExpression(classDecl) {
|
|
159593
|
+
var _a, _b;
|
|
159594
|
+
const extendsClause = (_a = classDecl.heritageClauses) == null ? void 0 : _a.find((p) => p.token === 96 /* ExtendsKeyword */);
|
|
159595
|
+
const heritageExpression = extendsClause == null ? void 0 : extendsClause.types[0];
|
|
159596
|
+
if (!heritageExpression) {
|
|
159597
|
+
return void 0;
|
|
159598
|
+
}
|
|
159599
|
+
const { typeNode: heritageTypeNode } = inferType(heritageExpression.expression);
|
|
159600
|
+
if (!heritageTypeNode) {
|
|
159601
|
+
return void 0;
|
|
159602
|
+
}
|
|
159603
|
+
const baseClassName = factory.createUniqueName(
|
|
159604
|
+
classDecl.name ? classDecl.name.text + "Base" : "Anonymous",
|
|
159605
|
+
16 /* Optimistic */
|
|
159606
|
+
);
|
|
159607
|
+
const heritageVariable = factory.createVariableStatement(
|
|
159608
|
+
/*modifiers*/
|
|
159609
|
+
void 0,
|
|
159610
|
+
factory.createVariableDeclarationList(
|
|
159611
|
+
[factory.createVariableDeclaration(
|
|
159612
|
+
baseClassName,
|
|
159613
|
+
/*exclamationToken*/
|
|
159614
|
+
void 0,
|
|
159615
|
+
heritageTypeNode,
|
|
159616
|
+
heritageExpression.expression
|
|
159617
|
+
)],
|
|
159618
|
+
2 /* Const */
|
|
159619
|
+
)
|
|
159620
|
+
);
|
|
159621
|
+
changeTracker.insertNodeBefore(sourceFile, classDecl, heritageVariable);
|
|
159622
|
+
const trailingComments = getTrailingCommentRanges(sourceFile.text, heritageExpression.end);
|
|
159623
|
+
const realEnd = ((_b = trailingComments == null ? void 0 : trailingComments[trailingComments.length - 1]) == null ? void 0 : _b.end) ?? heritageExpression.end;
|
|
159624
|
+
changeTracker.replaceRange(
|
|
159625
|
+
sourceFile,
|
|
159626
|
+
{
|
|
159627
|
+
pos: heritageExpression.getFullStart(),
|
|
159628
|
+
end: realEnd
|
|
159629
|
+
},
|
|
159630
|
+
baseClassName,
|
|
159631
|
+
{
|
|
159632
|
+
prefix: " "
|
|
159633
|
+
}
|
|
159634
|
+
);
|
|
159635
|
+
return [Diagnostics.Extract_base_class_to_variable];
|
|
159636
|
+
}
|
|
159637
|
+
let ExpressionType;
|
|
159638
|
+
((ExpressionType2) => {
|
|
159639
|
+
ExpressionType2[ExpressionType2["Text"] = 0] = "Text";
|
|
159640
|
+
ExpressionType2[ExpressionType2["Computed"] = 1] = "Computed";
|
|
159641
|
+
ExpressionType2[ExpressionType2["ArrayAccess"] = 2] = "ArrayAccess";
|
|
159642
|
+
ExpressionType2[ExpressionType2["Identifier"] = 3] = "Identifier";
|
|
159643
|
+
})(ExpressionType || (ExpressionType = {}));
|
|
159644
|
+
function transformDestructuringPatterns(bindingPattern) {
|
|
159645
|
+
var _a;
|
|
159646
|
+
const enclosingVariableDeclaration = bindingPattern.parent;
|
|
159647
|
+
const enclosingVarStmt = bindingPattern.parent.parent.parent;
|
|
159648
|
+
if (!enclosingVariableDeclaration.initializer)
|
|
159649
|
+
return void 0;
|
|
159650
|
+
let baseExpr;
|
|
159651
|
+
const newNodes = [];
|
|
159652
|
+
if (!isIdentifier(enclosingVariableDeclaration.initializer)) {
|
|
159653
|
+
const tempHolderForReturn = factory.createUniqueName("dest", 16 /* Optimistic */);
|
|
159654
|
+
baseExpr = { expression: { kind: 3 /* Identifier */, identifier: tempHolderForReturn } };
|
|
159655
|
+
newNodes.push(factory.createVariableStatement(
|
|
159656
|
+
/*modifiers*/
|
|
159657
|
+
void 0,
|
|
159658
|
+
factory.createVariableDeclarationList(
|
|
159659
|
+
[factory.createVariableDeclaration(
|
|
159660
|
+
tempHolderForReturn,
|
|
159661
|
+
/*exclamationToken*/
|
|
159662
|
+
void 0,
|
|
159663
|
+
/*type*/
|
|
159664
|
+
void 0,
|
|
159665
|
+
enclosingVariableDeclaration.initializer
|
|
159666
|
+
)],
|
|
159667
|
+
2 /* Const */
|
|
159668
|
+
)
|
|
159669
|
+
));
|
|
159670
|
+
} else {
|
|
159671
|
+
baseExpr = { expression: { kind: 3 /* Identifier */, identifier: enclosingVariableDeclaration.initializer } };
|
|
159672
|
+
}
|
|
159673
|
+
const bindingElements = [];
|
|
159674
|
+
if (isArrayBindingPattern(bindingPattern)) {
|
|
159675
|
+
addArrayBindingPatterns(bindingPattern, bindingElements, baseExpr);
|
|
159676
|
+
} else {
|
|
159677
|
+
addObjectBindingPatterns(bindingPattern, bindingElements, baseExpr);
|
|
159678
|
+
}
|
|
159679
|
+
const expressionToVar = /* @__PURE__ */ new Map();
|
|
159680
|
+
for (const bindingElement of bindingElements) {
|
|
159681
|
+
if (bindingElement.element.propertyName && isComputedPropertyName(bindingElement.element.propertyName)) {
|
|
159682
|
+
const computedExpression = bindingElement.element.propertyName.expression;
|
|
159683
|
+
const identifierForComputedProperty = factory.getGeneratedNameForNode(computedExpression);
|
|
159684
|
+
const variableDecl = factory.createVariableDeclaration(
|
|
159685
|
+
identifierForComputedProperty,
|
|
159686
|
+
/*exclamationToken*/
|
|
159687
|
+
void 0,
|
|
159688
|
+
/*type*/
|
|
159689
|
+
void 0,
|
|
159690
|
+
computedExpression
|
|
159691
|
+
);
|
|
159692
|
+
const variableList = factory.createVariableDeclarationList([variableDecl], 2 /* Const */);
|
|
159693
|
+
const variableStatement = factory.createVariableStatement(
|
|
159694
|
+
/*modifiers*/
|
|
159695
|
+
void 0,
|
|
159696
|
+
variableList
|
|
159697
|
+
);
|
|
159698
|
+
newNodes.push(variableStatement);
|
|
159699
|
+
expressionToVar.set(computedExpression, identifierForComputedProperty);
|
|
159700
|
+
}
|
|
159701
|
+
const name = bindingElement.element.name;
|
|
159702
|
+
if (isArrayBindingPattern(name)) {
|
|
159703
|
+
addArrayBindingPatterns(name, bindingElements, bindingElement);
|
|
159704
|
+
} else if (isObjectBindingPattern(name)) {
|
|
159705
|
+
addObjectBindingPatterns(name, bindingElements, bindingElement);
|
|
159706
|
+
} else {
|
|
159707
|
+
const { typeNode } = inferType(name);
|
|
159708
|
+
let variableInitializer = createChainedExpression(bindingElement, expressionToVar);
|
|
159709
|
+
if (bindingElement.element.initializer) {
|
|
159710
|
+
const propertyName = (_a = bindingElement.element) == null ? void 0 : _a.propertyName;
|
|
159711
|
+
const tempName = factory.createUniqueName(
|
|
159712
|
+
propertyName && isIdentifier(propertyName) ? propertyName.text : "temp",
|
|
159713
|
+
16 /* Optimistic */
|
|
159714
|
+
);
|
|
159715
|
+
newNodes.push(factory.createVariableStatement(
|
|
159716
|
+
/*modifiers*/
|
|
159717
|
+
void 0,
|
|
159718
|
+
factory.createVariableDeclarationList(
|
|
159719
|
+
[factory.createVariableDeclaration(
|
|
159720
|
+
tempName,
|
|
159721
|
+
/*exclamationToken*/
|
|
159722
|
+
void 0,
|
|
159723
|
+
/*type*/
|
|
159724
|
+
void 0,
|
|
159725
|
+
variableInitializer
|
|
159726
|
+
)],
|
|
159727
|
+
2 /* Const */
|
|
159728
|
+
)
|
|
159729
|
+
));
|
|
159730
|
+
variableInitializer = factory.createConditionalExpression(
|
|
159731
|
+
factory.createBinaryExpression(
|
|
159732
|
+
tempName,
|
|
159733
|
+
factory.createToken(37 /* EqualsEqualsEqualsToken */),
|
|
159734
|
+
factory.createIdentifier("undefined")
|
|
159735
|
+
),
|
|
159736
|
+
factory.createToken(58 /* QuestionToken */),
|
|
159737
|
+
bindingElement.element.initializer,
|
|
159738
|
+
factory.createToken(59 /* ColonToken */),
|
|
159739
|
+
variableInitializer
|
|
159740
|
+
);
|
|
159741
|
+
}
|
|
159742
|
+
const exportModifier = hasSyntacticModifier(enclosingVarStmt, 32 /* Export */) ? [factory.createToken(95 /* ExportKeyword */)] : void 0;
|
|
159743
|
+
newNodes.push(factory.createVariableStatement(
|
|
159744
|
+
exportModifier,
|
|
159745
|
+
factory.createVariableDeclarationList(
|
|
159746
|
+
[factory.createVariableDeclaration(
|
|
159747
|
+
name,
|
|
159748
|
+
/*exclamationToken*/
|
|
159749
|
+
void 0,
|
|
159750
|
+
typeNode,
|
|
159751
|
+
variableInitializer
|
|
159752
|
+
)],
|
|
159753
|
+
2 /* Const */
|
|
159754
|
+
)
|
|
159755
|
+
));
|
|
159756
|
+
}
|
|
159757
|
+
}
|
|
159758
|
+
if (enclosingVarStmt.declarationList.declarations.length > 1) {
|
|
159759
|
+
newNodes.push(factory.updateVariableStatement(
|
|
159760
|
+
enclosingVarStmt,
|
|
159761
|
+
enclosingVarStmt.modifiers,
|
|
159762
|
+
factory.updateVariableDeclarationList(
|
|
159763
|
+
enclosingVarStmt.declarationList,
|
|
159764
|
+
enclosingVarStmt.declarationList.declarations.filter((node) => node !== bindingPattern.parent)
|
|
159765
|
+
)
|
|
159766
|
+
));
|
|
159767
|
+
}
|
|
159768
|
+
changeTracker.replaceNodeWithNodes(sourceFile, enclosingVarStmt, newNodes);
|
|
159769
|
+
return [
|
|
159770
|
+
Diagnostics.Extract_binding_expressions_to_variable
|
|
159771
|
+
];
|
|
159772
|
+
}
|
|
159773
|
+
function addArrayBindingPatterns(bindingPattern, bindingElements, parent2) {
|
|
159774
|
+
for (let i = 0; i < bindingPattern.elements.length; ++i) {
|
|
159775
|
+
const element = bindingPattern.elements[i];
|
|
159776
|
+
if (isOmittedExpression(element)) {
|
|
159777
|
+
continue;
|
|
159778
|
+
}
|
|
159779
|
+
bindingElements.push({
|
|
159780
|
+
element,
|
|
159781
|
+
parent: parent2,
|
|
159782
|
+
expression: { kind: 2 /* ArrayAccess */, arrayIndex: i }
|
|
159783
|
+
});
|
|
159784
|
+
}
|
|
159785
|
+
}
|
|
159786
|
+
function addObjectBindingPatterns(bindingPattern, bindingElements, parent2) {
|
|
159787
|
+
for (const bindingElement of bindingPattern.elements) {
|
|
159788
|
+
let name;
|
|
159789
|
+
if (bindingElement.propertyName) {
|
|
159790
|
+
if (isComputedPropertyName(bindingElement.propertyName)) {
|
|
159791
|
+
bindingElements.push({
|
|
159792
|
+
element: bindingElement,
|
|
159793
|
+
parent: parent2,
|
|
159794
|
+
expression: { kind: 1 /* Computed */, computed: bindingElement.propertyName.expression }
|
|
159795
|
+
});
|
|
159796
|
+
continue;
|
|
159797
|
+
} else {
|
|
159798
|
+
name = bindingElement.propertyName.text;
|
|
159799
|
+
}
|
|
159800
|
+
} else {
|
|
159801
|
+
name = bindingElement.name.text;
|
|
159802
|
+
}
|
|
159803
|
+
bindingElements.push({
|
|
159804
|
+
element: bindingElement,
|
|
159805
|
+
parent: parent2,
|
|
159806
|
+
expression: { kind: 0 /* Text */, text: name }
|
|
159807
|
+
});
|
|
159808
|
+
}
|
|
159809
|
+
}
|
|
159810
|
+
function createChainedExpression(expression, expressionToVar) {
|
|
159811
|
+
const reverseTraverse = [expression];
|
|
159812
|
+
while (expression.parent) {
|
|
159813
|
+
expression = expression.parent;
|
|
159814
|
+
reverseTraverse.push(expression);
|
|
159815
|
+
}
|
|
159816
|
+
let chainedExpression = reverseTraverse[reverseTraverse.length - 1].expression.identifier;
|
|
159817
|
+
for (let i = reverseTraverse.length - 2; i >= 0; --i) {
|
|
159818
|
+
const nextSubExpr = reverseTraverse[i].expression;
|
|
159819
|
+
if (nextSubExpr.kind === 0 /* Text */) {
|
|
159820
|
+
chainedExpression = factory.createPropertyAccessChain(
|
|
159821
|
+
chainedExpression,
|
|
159822
|
+
/*questionDotToken*/
|
|
159823
|
+
void 0,
|
|
159824
|
+
factory.createIdentifier(nextSubExpr.text)
|
|
159825
|
+
);
|
|
159826
|
+
} else if (nextSubExpr.kind === 1 /* Computed */) {
|
|
159827
|
+
chainedExpression = factory.createElementAccessExpression(
|
|
159828
|
+
chainedExpression,
|
|
159829
|
+
expressionToVar.get(nextSubExpr.computed)
|
|
159830
|
+
);
|
|
159831
|
+
} else if (nextSubExpr.kind === 2 /* ArrayAccess */) {
|
|
159832
|
+
chainedExpression = factory.createElementAccessExpression(
|
|
159833
|
+
chainedExpression,
|
|
159834
|
+
nextSubExpr.arrayIndex
|
|
159835
|
+
);
|
|
159836
|
+
}
|
|
159837
|
+
}
|
|
159838
|
+
return chainedExpression;
|
|
159839
|
+
}
|
|
159840
|
+
function inferType(node, variableType) {
|
|
159841
|
+
if (typePrintMode === 1 /* Relative */) {
|
|
159842
|
+
return relativeType(node);
|
|
159843
|
+
}
|
|
159844
|
+
let type = isValueSignatureDeclaration(node) ? tryGetReturnType2(node) : typeChecker.getTypeAtLocation(node);
|
|
159845
|
+
if (!type) {
|
|
159846
|
+
return emptyInferenceResult;
|
|
159847
|
+
}
|
|
159848
|
+
if (typePrintMode === 2 /* Widened */) {
|
|
159849
|
+
if (variableType) {
|
|
159850
|
+
type = variableType;
|
|
159851
|
+
}
|
|
159852
|
+
const widenedType = typeChecker.getWidenedLiteralType(type);
|
|
159853
|
+
if (typeChecker.isTypeAssignableTo(widenedType, type)) {
|
|
159854
|
+
return emptyInferenceResult;
|
|
159855
|
+
}
|
|
159856
|
+
type = widenedType;
|
|
159857
|
+
}
|
|
159858
|
+
if (isParameter(node) && emitResolver.requiresAddingImplicitUndefined(node)) {
|
|
159859
|
+
type = typeChecker.getUnionType([typeChecker.getUndefinedType(), type], 0 /* None */);
|
|
159860
|
+
}
|
|
159861
|
+
const flags = (isVariableDeclaration(node) || isPropertyDeclaration(node) && hasSyntacticModifier(node, 256 /* Static */ | 8 /* Readonly */)) && type.flags & 8192 /* UniqueESSymbol */ ? 1048576 /* AllowUniqueESSymbolType */ : 0 /* None */;
|
|
159862
|
+
return {
|
|
159863
|
+
typeNode: typeToTypeNode2(type, findAncestor(node, isDeclaration) ?? sourceFile, flags),
|
|
159864
|
+
mutatedTarget: false
|
|
159865
|
+
};
|
|
159866
|
+
}
|
|
159867
|
+
function createTypeOfFromEntityNameExpression(node) {
|
|
159868
|
+
return factory.createTypeQueryNode(getSynthesizedDeepClone(node));
|
|
159869
|
+
}
|
|
159870
|
+
function typeFromArraySpreadElements(node, name = "temp") {
|
|
159871
|
+
const isConstContext = !!findAncestor(node, isConstAssertion2);
|
|
159872
|
+
if (!isConstContext)
|
|
159873
|
+
return emptyInferenceResult;
|
|
159874
|
+
return typeFromSpreads(
|
|
159875
|
+
node,
|
|
159876
|
+
name,
|
|
159877
|
+
isConstContext,
|
|
159878
|
+
(n) => n.elements,
|
|
159879
|
+
isSpreadElement,
|
|
159880
|
+
factory.createSpreadElement,
|
|
159881
|
+
(props) => factory.createArrayLiteralExpression(
|
|
159882
|
+
props,
|
|
159883
|
+
/*multiLine*/
|
|
159884
|
+
true
|
|
159885
|
+
),
|
|
159886
|
+
(types) => factory.createTupleTypeNode(types.map(factory.createRestTypeNode))
|
|
159887
|
+
);
|
|
159888
|
+
}
|
|
159889
|
+
function typeFromObjectSpreadAssignment(node, name = "temp") {
|
|
159890
|
+
const isConstContext = !!findAncestor(node, isConstAssertion2);
|
|
159891
|
+
return typeFromSpreads(
|
|
159892
|
+
node,
|
|
159893
|
+
name,
|
|
159894
|
+
isConstContext,
|
|
159895
|
+
(n) => n.properties,
|
|
159896
|
+
isSpreadAssignment,
|
|
159897
|
+
factory.createSpreadAssignment,
|
|
159898
|
+
(props) => factory.createObjectLiteralExpression(
|
|
159899
|
+
props,
|
|
159900
|
+
/*multiLine*/
|
|
159901
|
+
true
|
|
159902
|
+
),
|
|
159903
|
+
factory.createIntersectionTypeNode
|
|
159904
|
+
);
|
|
159905
|
+
}
|
|
159906
|
+
function typeFromSpreads(node, name, isConstContext, getChildren, isSpread, createSpread, makeNodeOfKind, finalType) {
|
|
159907
|
+
const intersectionTypes = [];
|
|
159908
|
+
const newSpreads = [];
|
|
159909
|
+
let currentVariableProperties;
|
|
159910
|
+
const statement = findAncestor(node, isStatement);
|
|
159911
|
+
for (const prop of getChildren(node)) {
|
|
159912
|
+
if (isSpread(prop)) {
|
|
159913
|
+
finalizesVariablePart();
|
|
159914
|
+
if (isEntityNameExpression(prop.expression)) {
|
|
159915
|
+
intersectionTypes.push(createTypeOfFromEntityNameExpression(prop.expression));
|
|
159916
|
+
newSpreads.push(prop);
|
|
159917
|
+
} else {
|
|
159918
|
+
makeVariable(prop.expression);
|
|
159919
|
+
}
|
|
159920
|
+
} else {
|
|
159921
|
+
(currentVariableProperties ?? (currentVariableProperties = [])).push(prop);
|
|
159922
|
+
}
|
|
159923
|
+
}
|
|
159924
|
+
if (newSpreads.length === 0) {
|
|
159925
|
+
return emptyInferenceResult;
|
|
159926
|
+
}
|
|
159927
|
+
finalizesVariablePart();
|
|
159928
|
+
changeTracker.replaceNode(sourceFile, node, makeNodeOfKind(newSpreads));
|
|
159929
|
+
return {
|
|
159930
|
+
typeNode: finalType(intersectionTypes),
|
|
159931
|
+
mutatedTarget: true
|
|
159932
|
+
};
|
|
159933
|
+
function makeVariable(expression) {
|
|
159934
|
+
const tempName = factory.createUniqueName(
|
|
159935
|
+
name + "_Part" + (newSpreads.length + 1),
|
|
159936
|
+
16 /* Optimistic */
|
|
159937
|
+
);
|
|
159938
|
+
const initializer = !isConstContext ? expression : factory.createAsExpression(
|
|
159939
|
+
expression,
|
|
159940
|
+
factory.createTypeReferenceNode("const")
|
|
159941
|
+
);
|
|
159942
|
+
const variableDefinition = factory.createVariableStatement(
|
|
159943
|
+
/*modifiers*/
|
|
159944
|
+
void 0,
|
|
159945
|
+
factory.createVariableDeclarationList([
|
|
159946
|
+
factory.createVariableDeclaration(
|
|
159947
|
+
tempName,
|
|
159948
|
+
/*exclamationToken*/
|
|
159949
|
+
void 0,
|
|
159950
|
+
/*type*/
|
|
159951
|
+
void 0,
|
|
159952
|
+
initializer
|
|
159953
|
+
)
|
|
159954
|
+
], 2 /* Const */)
|
|
159955
|
+
);
|
|
159956
|
+
changeTracker.insertNodeBefore(sourceFile, statement, variableDefinition);
|
|
159957
|
+
intersectionTypes.push(createTypeOfFromEntityNameExpression(tempName));
|
|
159958
|
+
newSpreads.push(createSpread(tempName));
|
|
159959
|
+
}
|
|
159960
|
+
function finalizesVariablePart() {
|
|
159961
|
+
if (currentVariableProperties) {
|
|
159962
|
+
makeVariable(makeNodeOfKind(
|
|
159963
|
+
currentVariableProperties
|
|
159964
|
+
));
|
|
159965
|
+
currentVariableProperties = void 0;
|
|
159966
|
+
}
|
|
159967
|
+
}
|
|
159968
|
+
}
|
|
159969
|
+
function isConstAssertion2(location) {
|
|
159970
|
+
return isAssertionExpression(location) && isConstTypeReference(location.type);
|
|
159971
|
+
}
|
|
159972
|
+
function relativeType(node) {
|
|
159973
|
+
if (isParameter(node)) {
|
|
159974
|
+
return emptyInferenceResult;
|
|
159975
|
+
}
|
|
159976
|
+
if (isShorthandPropertyAssignment(node)) {
|
|
159977
|
+
return {
|
|
159978
|
+
typeNode: createTypeOfFromEntityNameExpression(node.name),
|
|
159979
|
+
mutatedTarget: false
|
|
159980
|
+
};
|
|
159981
|
+
}
|
|
159982
|
+
if (isEntityNameExpression(node)) {
|
|
159983
|
+
return {
|
|
159984
|
+
typeNode: createTypeOfFromEntityNameExpression(node),
|
|
159985
|
+
mutatedTarget: false
|
|
159986
|
+
};
|
|
159987
|
+
}
|
|
159988
|
+
if (isConstAssertion2(node)) {
|
|
159989
|
+
return relativeType(node.expression);
|
|
159990
|
+
}
|
|
159991
|
+
if (isArrayLiteralExpression(node)) {
|
|
159992
|
+
const variableDecl = findAncestor(node, isVariableDeclaration);
|
|
159993
|
+
const partName = variableDecl && isIdentifier(variableDecl.name) ? variableDecl.name.text : void 0;
|
|
159994
|
+
return typeFromArraySpreadElements(node, partName);
|
|
159995
|
+
}
|
|
159996
|
+
if (isObjectLiteralExpression(node)) {
|
|
159997
|
+
const variableDecl = findAncestor(node, isVariableDeclaration);
|
|
159998
|
+
const partName = variableDecl && isIdentifier(variableDecl.name) ? variableDecl.name.text : void 0;
|
|
159999
|
+
return typeFromObjectSpreadAssignment(node, partName);
|
|
160000
|
+
}
|
|
160001
|
+
if (isVariableDeclaration(node) && node.initializer) {
|
|
160002
|
+
return relativeType(node.initializer);
|
|
160003
|
+
}
|
|
160004
|
+
if (isConditionalExpression(node)) {
|
|
160005
|
+
const { typeNode: trueType, mutatedTarget: mTrue } = relativeType(node.whenTrue);
|
|
160006
|
+
if (!trueType)
|
|
160007
|
+
return emptyInferenceResult;
|
|
160008
|
+
const { typeNode: falseType, mutatedTarget: mFalse } = relativeType(node.whenFalse);
|
|
160009
|
+
if (!falseType)
|
|
160010
|
+
return emptyInferenceResult;
|
|
160011
|
+
return {
|
|
160012
|
+
typeNode: factory.createUnionTypeNode([trueType, falseType]),
|
|
160013
|
+
mutatedTarget: mTrue || mFalse
|
|
160014
|
+
};
|
|
160015
|
+
}
|
|
160016
|
+
return emptyInferenceResult;
|
|
160017
|
+
}
|
|
160018
|
+
function typeToTypeNode2(type, enclosingDeclaration, flags = 0 /* None */) {
|
|
160019
|
+
let isTruncated = false;
|
|
160020
|
+
const result2 = typeToAutoImportableTypeNode(typeChecker, importAdder, type, enclosingDeclaration, scriptTarget, declarationEmitNodeBuilderFlags2 | flags, {
|
|
160021
|
+
moduleResolverHost: program,
|
|
160022
|
+
trackSymbol() {
|
|
160023
|
+
return true;
|
|
160024
|
+
},
|
|
160025
|
+
reportTruncationError() {
|
|
160026
|
+
isTruncated = true;
|
|
160027
|
+
}
|
|
160028
|
+
});
|
|
160029
|
+
return isTruncated ? factory.createKeywordTypeNode(133 /* AnyKeyword */) : result2;
|
|
160030
|
+
}
|
|
160031
|
+
function tryGetReturnType2(node) {
|
|
160032
|
+
const signature = typeChecker.getSignatureFromDeclaration(node);
|
|
160033
|
+
if (signature) {
|
|
160034
|
+
return typeChecker.getReturnTypeOfSignature(signature);
|
|
160035
|
+
}
|
|
160036
|
+
}
|
|
160037
|
+
function addTypeToVariableLike(decl) {
|
|
160038
|
+
const { typeNode } = inferType(decl);
|
|
160039
|
+
if (typeNode) {
|
|
160040
|
+
if (decl.type) {
|
|
160041
|
+
changeTracker.replaceNode(getSourceFileOfNode(decl), decl.type, typeNode);
|
|
160042
|
+
} else {
|
|
160043
|
+
changeTracker.tryInsertTypeAnnotation(getSourceFileOfNode(decl), decl, typeNode);
|
|
160044
|
+
}
|
|
160045
|
+
return [Diagnostics.Add_annotation_of_type_0, typeToStringForDiag(typeNode)];
|
|
160046
|
+
}
|
|
160047
|
+
}
|
|
160048
|
+
function typeToStringForDiag(node) {
|
|
160049
|
+
setEmitFlags(node, 1 /* SingleLine */);
|
|
160050
|
+
const result2 = typePrinter.printNode(4 /* Unspecified */, node, sourceFile);
|
|
160051
|
+
if (result2.length > defaultMaximumTruncationLength) {
|
|
160052
|
+
return result2.substring(0, defaultMaximumTruncationLength - "...".length) + "...";
|
|
160053
|
+
}
|
|
160054
|
+
setEmitFlags(node, 0 /* None */);
|
|
160055
|
+
return result2;
|
|
160056
|
+
}
|
|
160057
|
+
}
|
|
160058
|
+
function findAncestorWithMissingType(node) {
|
|
160059
|
+
return findAncestor(node, (n) => {
|
|
160060
|
+
return canHaveTypeAnnotation.has(n.kind) && (!isObjectBindingPattern(n) && !isArrayBindingPattern(n) || isVariableDeclaration(n.parent));
|
|
160061
|
+
});
|
|
160062
|
+
}
|
|
160063
|
+
function findBestFittingNode(node, span) {
|
|
160064
|
+
while (node && node.end < span.start + span.length) {
|
|
160065
|
+
node = node.parent;
|
|
160066
|
+
}
|
|
160067
|
+
while (node.parent.pos === node.pos && node.parent.end === node.end) {
|
|
160068
|
+
node = node.parent;
|
|
160069
|
+
}
|
|
160070
|
+
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
|
|
160071
|
+
return node.parent.initializer;
|
|
160072
|
+
}
|
|
160073
|
+
return node;
|
|
160074
|
+
}
|
|
160075
|
+
|
|
160076
|
+
// src/services/codefixes/fixAwaitInSyncFunction.ts
|
|
160077
|
+
var fixId37 = "fixAwaitInSyncFunction";
|
|
160078
|
+
var errorCodes48 = [
|
|
159174
160079
|
Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159175
160080
|
Diagnostics.await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159176
160081
|
Diagnostics.for_await_loops_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
159177
160082
|
Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function.code
|
|
159178
160083
|
];
|
|
159179
160084
|
registerCodeFix({
|
|
159180
|
-
errorCodes:
|
|
160085
|
+
errorCodes: errorCodes48,
|
|
159181
160086
|
getCodeActions(context) {
|
|
159182
160087
|
const { sourceFile, span } = context;
|
|
159183
160088
|
const nodes = getNodes3(sourceFile, span.start);
|
|
159184
160089
|
if (!nodes)
|
|
159185
160090
|
return void 0;
|
|
159186
160091
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange31(t, sourceFile, nodes));
|
|
159187
|
-
return [createCodeFixAction(
|
|
160092
|
+
return [createCodeFixAction(fixId37, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId37, Diagnostics.Add_all_missing_async_modifiers)];
|
|
159188
160093
|
},
|
|
159189
|
-
fixIds: [
|
|
160094
|
+
fixIds: [fixId37],
|
|
159190
160095
|
getAllCodeActions: function getAllCodeActionsToFixAwaitInSyncFunction(context) {
|
|
159191
160096
|
const seen = /* @__PURE__ */ new Map();
|
|
159192
|
-
return codeFixAll(context,
|
|
160097
|
+
return codeFixAll(context, errorCodes48, (changes, diag2) => {
|
|
159193
160098
|
const nodes = getNodes3(diag2.file, diag2.start);
|
|
159194
160099
|
if (!nodes || !addToSeen(seen, getNodeId(nodes.insertBefore)))
|
|
159195
160100
|
return;
|
|
@@ -159243,21 +160148,21 @@ function doChange31(changes, sourceFile, { insertBefore, returnType }) {
|
|
|
159243
160148
|
}
|
|
159244
160149
|
|
|
159245
160150
|
// src/services/codefixes/fixPropertyOverrideAccessor.ts
|
|
159246
|
-
var
|
|
160151
|
+
var errorCodes49 = [
|
|
159247
160152
|
Diagnostics._0_is_defined_as_an_accessor_in_class_1_but_is_overridden_here_in_2_as_an_instance_property.code,
|
|
159248
160153
|
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor.code
|
|
159249
160154
|
];
|
|
159250
|
-
var
|
|
160155
|
+
var fixId38 = "fixPropertyOverrideAccessor";
|
|
159251
160156
|
registerCodeFix({
|
|
159252
|
-
errorCodes:
|
|
160157
|
+
errorCodes: errorCodes49,
|
|
159253
160158
|
getCodeActions(context) {
|
|
159254
160159
|
const edits = doChange32(context.sourceFile, context.span.start, context.span.length, context.errorCode, context);
|
|
159255
160160
|
if (edits) {
|
|
159256
|
-
return [createCodeFixAction(
|
|
160161
|
+
return [createCodeFixAction(fixId38, edits, Diagnostics.Generate_get_and_set_accessors, fixId38, Diagnostics.Generate_get_and_set_accessors_for_all_overriding_properties)];
|
|
159257
160162
|
}
|
|
159258
160163
|
},
|
|
159259
|
-
fixIds: [
|
|
159260
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
160164
|
+
fixIds: [fixId38],
|
|
160165
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes49, (changes, diag2) => {
|
|
159261
160166
|
const edits = doChange32(diag2.file, diag2.start, diag2.length, diag2.code, context);
|
|
159262
160167
|
if (edits) {
|
|
159263
160168
|
for (const edit of edits) {
|
|
@@ -159295,8 +160200,8 @@ function doChange32(file, start, length2, code, context) {
|
|
|
159295
160200
|
}
|
|
159296
160201
|
|
|
159297
160202
|
// src/services/codefixes/inferFromUsage.ts
|
|
159298
|
-
var
|
|
159299
|
-
var
|
|
160203
|
+
var fixId39 = "inferFromUsage";
|
|
160204
|
+
var errorCodes50 = [
|
|
159300
160205
|
// Variable declarations
|
|
159301
160206
|
Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined.code,
|
|
159302
160207
|
// Variable uses
|
|
@@ -159330,7 +160235,7 @@ var errorCodes49 = [
|
|
|
159330
160235
|
Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation.code
|
|
159331
160236
|
];
|
|
159332
160237
|
registerCodeFix({
|
|
159333
|
-
errorCodes:
|
|
160238
|
+
errorCodes: errorCodes50,
|
|
159334
160239
|
getCodeActions(context) {
|
|
159335
160240
|
const { sourceFile, program, span: { start }, errorCode, cancellationToken, host, preferences } = context;
|
|
159336
160241
|
const token = getTokenAtPosition(sourceFile, start);
|
|
@@ -159350,13 +160255,13 @@ registerCodeFix({
|
|
|
159350
160255
|
);
|
|
159351
160256
|
});
|
|
159352
160257
|
const name = declaration && getNameOfDeclaration(declaration);
|
|
159353
|
-
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(
|
|
160258
|
+
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(fixId39, changes, [getDiagnostic(errorCode, token), getTextOfNode(name)], fixId39, Diagnostics.Infer_all_types_from_usage)];
|
|
159354
160259
|
},
|
|
159355
|
-
fixIds: [
|
|
160260
|
+
fixIds: [fixId39],
|
|
159356
160261
|
getAllCodeActions(context) {
|
|
159357
160262
|
const { sourceFile, program, cancellationToken, host, preferences } = context;
|
|
159358
160263
|
const markSeen = nodeSeenTracker();
|
|
159359
|
-
return codeFixAll(context,
|
|
160264
|
+
return codeFixAll(context, errorCodes50, (changes, err) => {
|
|
159360
160265
|
doChange33(changes, sourceFile, getTokenAtPosition(err.file, err.start), err.code, program, cancellationToken, markSeen, host, preferences);
|
|
159361
160266
|
});
|
|
159362
160267
|
}
|
|
@@ -160295,13 +161200,13 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
160295
161200
|
}
|
|
160296
161201
|
|
|
160297
161202
|
// src/services/codefixes/fixReturnTypeInAsyncFunction.ts
|
|
160298
|
-
var
|
|
160299
|
-
var
|
|
161203
|
+
var fixId40 = "fixReturnTypeInAsyncFunction";
|
|
161204
|
+
var errorCodes51 = [
|
|
160300
161205
|
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
161206
|
];
|
|
160302
161207
|
registerCodeFix({
|
|
160303
|
-
errorCodes:
|
|
160304
|
-
fixIds: [
|
|
161208
|
+
errorCodes: errorCodes51,
|
|
161209
|
+
fixIds: [fixId40],
|
|
160305
161210
|
getCodeActions: function getCodeActionsToFixReturnTypeInAsyncFunction(context) {
|
|
160306
161211
|
const { sourceFile, program, span } = context;
|
|
160307
161212
|
const checker = program.getTypeChecker();
|
|
@@ -160312,14 +161217,14 @@ registerCodeFix({
|
|
|
160312
161217
|
const { returnTypeNode, returnType, promisedTypeNode, promisedType } = info;
|
|
160313
161218
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange34(t, sourceFile, returnTypeNode, promisedTypeNode));
|
|
160314
161219
|
return [createCodeFixAction(
|
|
160315
|
-
|
|
161220
|
+
fixId40,
|
|
160316
161221
|
changes,
|
|
160317
161222
|
[Diagnostics.Replace_0_with_Promise_1, checker.typeToString(returnType), checker.typeToString(promisedType)],
|
|
160318
|
-
|
|
161223
|
+
fixId40,
|
|
160319
161224
|
Diagnostics.Fix_all_incorrect_return_type_of_an_async_functions
|
|
160320
161225
|
)];
|
|
160321
161226
|
},
|
|
160322
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
161227
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes51, (changes, diag2) => {
|
|
160323
161228
|
const info = getInfo16(diag2.file, context.program.getTypeChecker(), diag2.start);
|
|
160324
161229
|
if (info) {
|
|
160325
161230
|
doChange34(changes, diag2.file, info.returnTypeNode, info.promisedTypeNode);
|
|
@@ -160355,13 +161260,13 @@ function doChange34(changes, sourceFile, returnTypeNode, promisedTypeNode) {
|
|
|
160355
161260
|
|
|
160356
161261
|
// src/services/codefixes/disableJsDiagnostics.ts
|
|
160357
161262
|
var fixName4 = "disableJsDiagnostics";
|
|
160358
|
-
var
|
|
160359
|
-
var
|
|
161263
|
+
var fixId41 = "disableJsDiagnostics";
|
|
161264
|
+
var errorCodes52 = mapDefined(Object.keys(Diagnostics), (key) => {
|
|
160360
161265
|
const diag2 = Diagnostics[key];
|
|
160361
161266
|
return diag2.category === 1 /* Error */ ? diag2.code : void 0;
|
|
160362
161267
|
});
|
|
160363
161268
|
registerCodeFix({
|
|
160364
|
-
errorCodes:
|
|
161269
|
+
errorCodes: errorCodes52,
|
|
160365
161270
|
getCodeActions: function getCodeActionsToDisableJsDiagnostics(context) {
|
|
160366
161271
|
const { sourceFile, program, span, host, formatContext } = context;
|
|
160367
161272
|
if (!isInJSFile(sourceFile) || !isCheckJsEnabledForFile(sourceFile, program.getCompilerOptions())) {
|
|
@@ -160382,14 +161287,14 @@ registerCodeFix({
|
|
|
160382
161287
|
)
|
|
160383
161288
|
];
|
|
160384
161289
|
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,
|
|
161290
|
+
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
161291
|
}
|
|
160387
161292
|
return fixes;
|
|
160388
161293
|
},
|
|
160389
|
-
fixIds: [
|
|
161294
|
+
fixIds: [fixId41],
|
|
160390
161295
|
getAllCodeActions: (context) => {
|
|
160391
161296
|
const seenLines = /* @__PURE__ */ new Set();
|
|
160392
|
-
return codeFixAll(context,
|
|
161297
|
+
return codeFixAll(context, errorCodes52, (changes, diag2) => {
|
|
160393
161298
|
if (ts_textChanges_exports.isValidLocationToAddComment(diag2.file, diag2.start)) {
|
|
160394
161299
|
makeChange8(changes, diag2.file, diag2.start, seenLines);
|
|
160395
161300
|
}
|
|
@@ -161388,9 +162293,9 @@ var fixName6 = "strictClassInitialization";
|
|
|
161388
162293
|
var fixIdAddDefiniteAssignmentAssertions = "addMissingPropertyDefiniteAssignmentAssertions";
|
|
161389
162294
|
var fixIdAddUndefinedType = "addMissingPropertyUndefinedType";
|
|
161390
162295
|
var fixIdAddInitializer = "addMissingPropertyInitializer";
|
|
161391
|
-
var
|
|
162296
|
+
var errorCodes53 = [Diagnostics.Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor.code];
|
|
161392
162297
|
registerCodeFix({
|
|
161393
|
-
errorCodes:
|
|
162298
|
+
errorCodes: errorCodes53,
|
|
161394
162299
|
getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
|
|
161395
162300
|
const info = getInfo17(context.sourceFile, context.span.start);
|
|
161396
162301
|
if (!info)
|
|
@@ -161403,7 +162308,7 @@ registerCodeFix({
|
|
|
161403
162308
|
},
|
|
161404
162309
|
fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
|
|
161405
162310
|
getAllCodeActions: (context) => {
|
|
161406
|
-
return codeFixAll(context,
|
|
162311
|
+
return codeFixAll(context, errorCodes53, (changes, diag2) => {
|
|
161407
162312
|
const info = getInfo17(diag2.file, diag2.start);
|
|
161408
162313
|
if (!info)
|
|
161409
162314
|
return;
|
|
@@ -161533,20 +162438,20 @@ function getDefaultValueFromType(checker, type) {
|
|
|
161533
162438
|
}
|
|
161534
162439
|
|
|
161535
162440
|
// src/services/codefixes/requireInTs.ts
|
|
161536
|
-
var
|
|
161537
|
-
var
|
|
162441
|
+
var fixId42 = "requireInTs";
|
|
162442
|
+
var errorCodes54 = [Diagnostics.require_call_may_be_converted_to_an_import.code];
|
|
161538
162443
|
registerCodeFix({
|
|
161539
|
-
errorCodes:
|
|
162444
|
+
errorCodes: errorCodes54,
|
|
161540
162445
|
getCodeActions(context) {
|
|
161541
162446
|
const info = getInfo18(context.sourceFile, context.program, context.span.start);
|
|
161542
162447
|
if (!info) {
|
|
161543
162448
|
return void 0;
|
|
161544
162449
|
}
|
|
161545
162450
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange35(t, context.sourceFile, info));
|
|
161546
|
-
return [createCodeFixAction(
|
|
162451
|
+
return [createCodeFixAction(fixId42, changes, Diagnostics.Convert_require_to_import, fixId42, Diagnostics.Convert_all_require_to_import)];
|
|
161547
162452
|
},
|
|
161548
|
-
fixIds: [
|
|
161549
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162453
|
+
fixIds: [fixId42],
|
|
162454
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes54, (changes, diag2) => {
|
|
161550
162455
|
const info = getInfo18(diag2.file, context.program, diag2.start);
|
|
161551
162456
|
if (info) {
|
|
161552
162457
|
doChange35(changes, context.sourceFile, info);
|
|
@@ -161621,20 +162526,20 @@ function tryCreateNamedImportsFromObjectBindingPattern(node) {
|
|
|
161621
162526
|
}
|
|
161622
162527
|
|
|
161623
162528
|
// src/services/codefixes/useDefaultImport.ts
|
|
161624
|
-
var
|
|
161625
|
-
var
|
|
162529
|
+
var fixId43 = "useDefaultImport";
|
|
162530
|
+
var errorCodes55 = [Diagnostics.Import_may_be_converted_to_a_default_import.code];
|
|
161626
162531
|
registerCodeFix({
|
|
161627
|
-
errorCodes:
|
|
162532
|
+
errorCodes: errorCodes55,
|
|
161628
162533
|
getCodeActions(context) {
|
|
161629
162534
|
const { sourceFile, span: { start } } = context;
|
|
161630
162535
|
const info = getInfo19(sourceFile, start);
|
|
161631
162536
|
if (!info)
|
|
161632
162537
|
return void 0;
|
|
161633
162538
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange36(t, sourceFile, info, context.preferences));
|
|
161634
|
-
return [createCodeFixAction(
|
|
162539
|
+
return [createCodeFixAction(fixId43, changes, Diagnostics.Convert_to_default_import, fixId43, Diagnostics.Convert_all_to_default_imports)];
|
|
161635
162540
|
},
|
|
161636
|
-
fixIds: [
|
|
161637
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162541
|
+
fixIds: [fixId43],
|
|
162542
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes55, (changes, diag2) => {
|
|
161638
162543
|
const info = getInfo19(diag2.file, diag2.start);
|
|
161639
162544
|
if (info)
|
|
161640
162545
|
doChange36(changes, diag2.file, info, context.preferences);
|
|
@@ -161663,21 +162568,21 @@ function doChange36(changes, sourceFile, info, preferences) {
|
|
|
161663
162568
|
}
|
|
161664
162569
|
|
|
161665
162570
|
// src/services/codefixes/useBigintLiteral.ts
|
|
161666
|
-
var
|
|
161667
|
-
var
|
|
162571
|
+
var fixId44 = "useBigintLiteral";
|
|
162572
|
+
var errorCodes56 = [
|
|
161668
162573
|
Diagnostics.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_integers.code
|
|
161669
162574
|
];
|
|
161670
162575
|
registerCodeFix({
|
|
161671
|
-
errorCodes:
|
|
162576
|
+
errorCodes: errorCodes56,
|
|
161672
162577
|
getCodeActions: function getCodeActionsToUseBigintLiteral(context) {
|
|
161673
162578
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange9(t, context.sourceFile, context.span));
|
|
161674
162579
|
if (changes.length > 0) {
|
|
161675
|
-
return [createCodeFixAction(
|
|
162580
|
+
return [createCodeFixAction(fixId44, changes, Diagnostics.Convert_to_a_bigint_numeric_literal, fixId44, Diagnostics.Convert_all_to_bigint_numeric_literals)];
|
|
161676
162581
|
}
|
|
161677
162582
|
},
|
|
161678
|
-
fixIds: [
|
|
162583
|
+
fixIds: [fixId44],
|
|
161679
162584
|
getAllCodeActions: (context) => {
|
|
161680
|
-
return codeFixAll(context,
|
|
162585
|
+
return codeFixAll(context, errorCodes56, (changes, diag2) => makeChange9(changes, diag2.file, diag2));
|
|
161681
162586
|
}
|
|
161682
162587
|
});
|
|
161683
162588
|
function makeChange9(changeTracker, sourceFile, span) {
|
|
@@ -161691,18 +162596,18 @@ function makeChange9(changeTracker, sourceFile, span) {
|
|
|
161691
162596
|
|
|
161692
162597
|
// src/services/codefixes/fixAddModuleReferTypeMissingTypeof.ts
|
|
161693
162598
|
var fixIdAddMissingTypeof = "fixAddModuleReferTypeMissingTypeof";
|
|
161694
|
-
var
|
|
161695
|
-
var
|
|
162599
|
+
var fixId45 = fixIdAddMissingTypeof;
|
|
162600
|
+
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
162601
|
registerCodeFix({
|
|
161697
|
-
errorCodes:
|
|
162602
|
+
errorCodes: errorCodes57,
|
|
161698
162603
|
getCodeActions: function getCodeActionsToAddMissingTypeof(context) {
|
|
161699
162604
|
const { sourceFile, span } = context;
|
|
161700
162605
|
const importType = getImportTypeNode(sourceFile, span.start);
|
|
161701
162606
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange37(t, sourceFile, importType));
|
|
161702
|
-
return [createCodeFixAction(
|
|
162607
|
+
return [createCodeFixAction(fixId45, changes, Diagnostics.Add_missing_typeof, fixId45, Diagnostics.Add_missing_typeof)];
|
|
161703
162608
|
},
|
|
161704
|
-
fixIds: [
|
|
161705
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162609
|
+
fixIds: [fixId45],
|
|
162610
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes57, (changes, diag2) => doChange37(changes, context.sourceFile, getImportTypeNode(diag2.file, diag2.start)))
|
|
161706
162611
|
});
|
|
161707
162612
|
function getImportTypeNode(sourceFile, pos) {
|
|
161708
162613
|
const token = getTokenAtPosition(sourceFile, pos);
|
|
@@ -161725,9 +162630,9 @@ function doChange37(changes, sourceFile, importType) {
|
|
|
161725
162630
|
|
|
161726
162631
|
// src/services/codefixes/wrapJsxInFragment.ts
|
|
161727
162632
|
var fixID2 = "wrapJsxInFragment";
|
|
161728
|
-
var
|
|
162633
|
+
var errorCodes58 = [Diagnostics.JSX_expressions_must_have_one_parent_element.code];
|
|
161729
162634
|
registerCodeFix({
|
|
161730
|
-
errorCodes:
|
|
162635
|
+
errorCodes: errorCodes58,
|
|
161731
162636
|
getCodeActions: function getCodeActionsToWrapJsxInFragment(context) {
|
|
161732
162637
|
const { sourceFile, span } = context;
|
|
161733
162638
|
const node = findNodeToFix(sourceFile, span.start);
|
|
@@ -161737,7 +162642,7 @@ registerCodeFix({
|
|
|
161737
162642
|
return [createCodeFixAction(fixID2, changes, Diagnostics.Wrap_in_JSX_fragment, fixID2, Diagnostics.Wrap_all_unparented_JSX_in_JSX_fragment)];
|
|
161738
162643
|
},
|
|
161739
162644
|
fixIds: [fixID2],
|
|
161740
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162645
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes58, (changes, diag2) => {
|
|
161741
162646
|
const node = findNodeToFix(context.sourceFile, diag2.start);
|
|
161742
162647
|
if (!node)
|
|
161743
162648
|
return void 0;
|
|
@@ -161782,16 +162687,16 @@ function flattenInvalidBinaryExpr(node) {
|
|
|
161782
162687
|
}
|
|
161783
162688
|
|
|
161784
162689
|
// src/services/codefixes/wrapDecoratorInParentheses.ts
|
|
161785
|
-
var
|
|
161786
|
-
var
|
|
162690
|
+
var fixId46 = "wrapDecoratorInParentheses";
|
|
162691
|
+
var errorCodes59 = [Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator.code];
|
|
161787
162692
|
registerCodeFix({
|
|
161788
|
-
errorCodes:
|
|
162693
|
+
errorCodes: errorCodes59,
|
|
161789
162694
|
getCodeActions: function getCodeActionsToWrapDecoratorExpressionInParentheses(context) {
|
|
161790
162695
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange10(t, context.sourceFile, context.span.start));
|
|
161791
|
-
return [createCodeFixAction(
|
|
162696
|
+
return [createCodeFixAction(fixId46, changes, Diagnostics.Wrap_in_parentheses, fixId46, Diagnostics.Wrap_all_invalid_decorator_expressions_in_parentheses)];
|
|
161792
162697
|
},
|
|
161793
|
-
fixIds: [
|
|
161794
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162698
|
+
fixIds: [fixId46],
|
|
162699
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes59, (changes, diag2) => makeChange10(changes, diag2.file, diag2.start))
|
|
161795
162700
|
});
|
|
161796
162701
|
function makeChange10(changeTracker, sourceFile, pos) {
|
|
161797
162702
|
const token = getTokenAtPosition(sourceFile, pos);
|
|
@@ -161802,10 +162707,10 @@ function makeChange10(changeTracker, sourceFile, pos) {
|
|
|
161802
162707
|
}
|
|
161803
162708
|
|
|
161804
162709
|
// src/services/codefixes/convertToMappedObjectType.ts
|
|
161805
|
-
var
|
|
161806
|
-
var
|
|
162710
|
+
var fixId47 = "fixConvertToMappedObjectType";
|
|
162711
|
+
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
162712
|
registerCodeFix({
|
|
161808
|
-
errorCodes:
|
|
162713
|
+
errorCodes: errorCodes60,
|
|
161809
162714
|
getCodeActions: function getCodeActionsToConvertToMappedTypeObject(context) {
|
|
161810
162715
|
const { sourceFile, span } = context;
|
|
161811
162716
|
const info = getInfo20(sourceFile, span.start);
|
|
@@ -161813,10 +162718,10 @@ registerCodeFix({
|
|
|
161813
162718
|
return void 0;
|
|
161814
162719
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange39(t, sourceFile, info));
|
|
161815
162720
|
const name = idText(info.container.name);
|
|
161816
|
-
return [createCodeFixAction(
|
|
162721
|
+
return [createCodeFixAction(fixId47, changes, [Diagnostics.Convert_0_to_mapped_object_type, name], fixId47, [Diagnostics.Convert_0_to_mapped_object_type, name])];
|
|
161817
162722
|
},
|
|
161818
|
-
fixIds: [
|
|
161819
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162723
|
+
fixIds: [fixId47],
|
|
162724
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes60, (changes, diag2) => {
|
|
161820
162725
|
const info = getInfo20(diag2.file, diag2.start);
|
|
161821
162726
|
if (info)
|
|
161822
162727
|
doChange39(changes, diag2.file, info);
|
|
@@ -161864,12 +162769,12 @@ function doChange39(changes, sourceFile, { indexSignature, container }) {
|
|
|
161864
162769
|
}
|
|
161865
162770
|
|
|
161866
162771
|
// src/services/codefixes/removeAccidentalCallParentheses.ts
|
|
161867
|
-
var
|
|
161868
|
-
var
|
|
162772
|
+
var fixId48 = "removeAccidentalCallParentheses";
|
|
162773
|
+
var errorCodes61 = [
|
|
161869
162774
|
Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without.code
|
|
161870
162775
|
];
|
|
161871
162776
|
registerCodeFix({
|
|
161872
|
-
errorCodes:
|
|
162777
|
+
errorCodes: errorCodes61,
|
|
161873
162778
|
getCodeActions(context) {
|
|
161874
162779
|
const callExpression = findAncestor(getTokenAtPosition(context.sourceFile, context.span.start), isCallExpression);
|
|
161875
162780
|
if (!callExpression) {
|
|
@@ -161878,27 +162783,27 @@ registerCodeFix({
|
|
|
161878
162783
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
161879
162784
|
t.deleteRange(context.sourceFile, { pos: callExpression.expression.end, end: callExpression.end });
|
|
161880
162785
|
});
|
|
161881
|
-
return [createCodeFixActionWithoutFixAll(
|
|
162786
|
+
return [createCodeFixActionWithoutFixAll(fixId48, changes, Diagnostics.Remove_parentheses)];
|
|
161882
162787
|
},
|
|
161883
|
-
fixIds: [
|
|
162788
|
+
fixIds: [fixId48]
|
|
161884
162789
|
});
|
|
161885
162790
|
|
|
161886
162791
|
// src/services/codefixes/removeUnnecessaryAwait.ts
|
|
161887
|
-
var
|
|
161888
|
-
var
|
|
162792
|
+
var fixId49 = "removeUnnecessaryAwait";
|
|
162793
|
+
var errorCodes62 = [
|
|
161889
162794
|
Diagnostics.await_has_no_effect_on_the_type_of_this_expression.code
|
|
161890
162795
|
];
|
|
161891
162796
|
registerCodeFix({
|
|
161892
|
-
errorCodes:
|
|
162797
|
+
errorCodes: errorCodes62,
|
|
161893
162798
|
getCodeActions: function getCodeActionsToRemoveUnnecessaryAwait(context) {
|
|
161894
162799
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange11(t, context.sourceFile, context.span));
|
|
161895
162800
|
if (changes.length > 0) {
|
|
161896
|
-
return [createCodeFixAction(
|
|
162801
|
+
return [createCodeFixAction(fixId49, changes, Diagnostics.Remove_unnecessary_await, fixId49, Diagnostics.Remove_all_unnecessary_uses_of_await)];
|
|
161897
162802
|
}
|
|
161898
162803
|
},
|
|
161899
|
-
fixIds: [
|
|
162804
|
+
fixIds: [fixId49],
|
|
161900
162805
|
getAllCodeActions: (context) => {
|
|
161901
|
-
return codeFixAll(context,
|
|
162806
|
+
return codeFixAll(context, errorCodes62, (changes, diag2) => makeChange11(changes, diag2.file, diag2));
|
|
161902
162807
|
}
|
|
161903
162808
|
});
|
|
161904
162809
|
function makeChange11(changeTracker, sourceFile, span) {
|
|
@@ -161926,20 +162831,20 @@ function makeChange11(changeTracker, sourceFile, span) {
|
|
|
161926
162831
|
}
|
|
161927
162832
|
|
|
161928
162833
|
// src/services/codefixes/splitTypeOnlyImport.ts
|
|
161929
|
-
var
|
|
161930
|
-
var
|
|
162834
|
+
var errorCodes63 = [Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both.code];
|
|
162835
|
+
var fixId50 = "splitTypeOnlyImport";
|
|
161931
162836
|
registerCodeFix({
|
|
161932
|
-
errorCodes:
|
|
161933
|
-
fixIds: [
|
|
162837
|
+
errorCodes: errorCodes63,
|
|
162838
|
+
fixIds: [fixId50],
|
|
161934
162839
|
getCodeActions: function getCodeActionsToSplitTypeOnlyImport(context) {
|
|
161935
162840
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
161936
162841
|
return splitTypeOnlyImport(t, getImportDeclaration2(context.sourceFile, context.span), context);
|
|
161937
162842
|
});
|
|
161938
162843
|
if (changes.length) {
|
|
161939
|
-
return [createCodeFixAction(
|
|
162844
|
+
return [createCodeFixAction(fixId50, changes, Diagnostics.Split_into_two_separate_import_declarations, fixId50, Diagnostics.Split_all_invalid_type_only_imports)];
|
|
161940
162845
|
}
|
|
161941
162846
|
},
|
|
161942
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162847
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes63, (changes, error2) => {
|
|
161943
162848
|
splitTypeOnlyImport(changes, getImportDeclaration2(context.sourceFile, error2), context);
|
|
161944
162849
|
})
|
|
161945
162850
|
});
|
|
@@ -161988,23 +162893,23 @@ function splitTypeOnlyImport(changes, importDeclaration, context) {
|
|
|
161988
162893
|
}
|
|
161989
162894
|
|
|
161990
162895
|
// src/services/codefixes/convertConstToLet.ts
|
|
161991
|
-
var
|
|
161992
|
-
var
|
|
162896
|
+
var fixId51 = "fixConvertConstToLet";
|
|
162897
|
+
var errorCodes64 = [Diagnostics.Cannot_assign_to_0_because_it_is_a_constant.code];
|
|
161993
162898
|
registerCodeFix({
|
|
161994
|
-
errorCodes:
|
|
162899
|
+
errorCodes: errorCodes64,
|
|
161995
162900
|
getCodeActions: function getCodeActionsToConvertConstToLet(context) {
|
|
161996
162901
|
const { sourceFile, span, program } = context;
|
|
161997
162902
|
const info = getInfo21(sourceFile, span.start, program);
|
|
161998
162903
|
if (info === void 0)
|
|
161999
162904
|
return;
|
|
162000
162905
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange40(t, sourceFile, info.token));
|
|
162001
|
-
return [createCodeFixActionMaybeFixAll(
|
|
162906
|
+
return [createCodeFixActionMaybeFixAll(fixId51, changes, Diagnostics.Convert_const_to_let, fixId51, Diagnostics.Convert_all_const_to_let)];
|
|
162002
162907
|
},
|
|
162003
162908
|
getAllCodeActions: (context) => {
|
|
162004
162909
|
const { program } = context;
|
|
162005
162910
|
const seen = /* @__PURE__ */ new Map();
|
|
162006
162911
|
return createCombinedCodeActions(ts_textChanges_exports.ChangeTracker.with(context, (changes) => {
|
|
162007
|
-
eachDiagnostic(context,
|
|
162912
|
+
eachDiagnostic(context, errorCodes64, (diag2) => {
|
|
162008
162913
|
const info = getInfo21(diag2.file, diag2.start, program);
|
|
162009
162914
|
if (info) {
|
|
162010
162915
|
if (addToSeen(seen, getSymbolId(info.symbol))) {
|
|
@@ -162015,7 +162920,7 @@ registerCodeFix({
|
|
|
162015
162920
|
});
|
|
162016
162921
|
}));
|
|
162017
162922
|
},
|
|
162018
|
-
fixIds: [
|
|
162923
|
+
fixIds: [fixId51]
|
|
162019
162924
|
});
|
|
162020
162925
|
function getInfo21(sourceFile, pos, program) {
|
|
162021
162926
|
var _a;
|
|
@@ -162036,11 +162941,11 @@ function doChange40(changes, sourceFile, token) {
|
|
|
162036
162941
|
}
|
|
162037
162942
|
|
|
162038
162943
|
// src/services/codefixes/fixExpectedComma.ts
|
|
162039
|
-
var
|
|
162944
|
+
var fixId52 = "fixExpectedComma";
|
|
162040
162945
|
var expectedErrorCode = Diagnostics._0_expected.code;
|
|
162041
|
-
var
|
|
162946
|
+
var errorCodes65 = [expectedErrorCode];
|
|
162042
162947
|
registerCodeFix({
|
|
162043
|
-
errorCodes:
|
|
162948
|
+
errorCodes: errorCodes65,
|
|
162044
162949
|
getCodeActions(context) {
|
|
162045
162950
|
const { sourceFile } = context;
|
|
162046
162951
|
const info = getInfo22(sourceFile, context.span.start, context.errorCode);
|
|
@@ -162048,15 +162953,15 @@ registerCodeFix({
|
|
|
162048
162953
|
return void 0;
|
|
162049
162954
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange41(t, sourceFile, info));
|
|
162050
162955
|
return [createCodeFixAction(
|
|
162051
|
-
|
|
162956
|
+
fixId52,
|
|
162052
162957
|
changes,
|
|
162053
162958
|
[Diagnostics.Change_0_to_1, ";", ","],
|
|
162054
|
-
|
|
162959
|
+
fixId52,
|
|
162055
162960
|
[Diagnostics.Change_0_to_1, ";", ","]
|
|
162056
162961
|
)];
|
|
162057
162962
|
},
|
|
162058
|
-
fixIds: [
|
|
162059
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
162963
|
+
fixIds: [fixId52],
|
|
162964
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes65, (changes, diag2) => {
|
|
162060
162965
|
const info = getInfo22(diag2.file, diag2.start, diag2.code);
|
|
162061
162966
|
if (info)
|
|
162062
162967
|
doChange41(changes, context.sourceFile, info);
|
|
@@ -162073,22 +162978,22 @@ function doChange41(changes, sourceFile, { node }) {
|
|
|
162073
162978
|
|
|
162074
162979
|
// src/services/codefixes/fixAddVoidToPromise.ts
|
|
162075
162980
|
var fixName7 = "addVoidToPromise";
|
|
162076
|
-
var
|
|
162077
|
-
var
|
|
162981
|
+
var fixId53 = "addVoidToPromise";
|
|
162982
|
+
var errorCodes66 = [
|
|
162078
162983
|
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
162984
|
Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise.code
|
|
162080
162985
|
];
|
|
162081
162986
|
registerCodeFix({
|
|
162082
|
-
errorCodes:
|
|
162083
|
-
fixIds: [
|
|
162987
|
+
errorCodes: errorCodes66,
|
|
162988
|
+
fixIds: [fixId53],
|
|
162084
162989
|
getCodeActions(context) {
|
|
162085
162990
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange12(t, context.sourceFile, context.span, context.program));
|
|
162086
162991
|
if (changes.length > 0) {
|
|
162087
|
-
return [createCodeFixAction(fixName7, changes, Diagnostics.Add_void_to_Promise_resolved_without_a_value,
|
|
162992
|
+
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
162993
|
}
|
|
162089
162994
|
},
|
|
162090
162995
|
getAllCodeActions(context) {
|
|
162091
|
-
return codeFixAll(context,
|
|
162996
|
+
return codeFixAll(context, errorCodes66, (changes, diag2) => makeChange12(changes, diag2.file, diag2, context.program, /* @__PURE__ */ new Set()));
|
|
162092
162997
|
}
|
|
162093
162998
|
});
|
|
162094
162999
|
function makeChange12(changes, sourceFile, span, program, seen) {
|
|
@@ -190862,10 +191767,10 @@ ${e.message}`;
|
|
|
190862
191767
|
}
|
|
190863
191768
|
return simplifiedResult ? codeActions.map((codeAction) => this.mapCodeFixAction(codeAction)) : codeActions;
|
|
190864
191769
|
}
|
|
190865
|
-
getCombinedCodeFix({ scope, fixId:
|
|
191770
|
+
getCombinedCodeFix({ scope, fixId: fixId54 }, simplifiedResult) {
|
|
190866
191771
|
Debug.assert(scope.type === "file");
|
|
190867
191772
|
const { file, project } = this.getFileAndProject(scope.args);
|
|
190868
|
-
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file },
|
|
191773
|
+
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId54, this.getFormatOptions(file), this.getPreferences(file));
|
|
190869
191774
|
if (simplifiedResult) {
|
|
190870
191775
|
return { changes: this.mapTextChangesToCodeEdits(res.changes), commands: res.commands };
|
|
190871
191776
|
} else {
|
|
@@ -190904,8 +191809,8 @@ ${e.message}`;
|
|
|
190904
191809
|
mapCodeAction({ description: description3, changes, commands }) {
|
|
190905
191810
|
return { description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands };
|
|
190906
191811
|
}
|
|
190907
|
-
mapCodeFixAction({ fixName: fixName8, description: description3, changes, commands, fixId:
|
|
190908
|
-
return { fixName: fixName8, description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId:
|
|
191812
|
+
mapCodeFixAction({ fixName: fixName8, description: description3, changes, commands, fixId: fixId54, fixAllDescription }) {
|
|
191813
|
+
return { fixName: fixName8, description: description3, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId: fixId54, fixAllDescription };
|
|
190909
191814
|
}
|
|
190910
191815
|
mapTextChangesToCodeEdits(textChanges2) {
|
|
190911
191816
|
return textChanges2.map((change) => this.mapTextChangeToCodeEdit(change));
|