@tslite/services 1.16.1 → 1.18.0
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/dist/_namespaces/edit.js +707 -735
- package/dist/_namespaces/ts.codefix.d.ts +0 -1
- package/dist/_namespaces/ts.d.ts +1 -0
- package/dist/_namespaces/ts.js +34 -33
- package/dist/packageVersion.d.ts +2 -0
- package/dist/suggestionDiagnostics.d.ts +3 -3
- package/dist/types.d.ts +0 -2
- package/package.json +6 -6
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
package/dist/_namespaces/edit.js
CHANGED
|
@@ -1053,7 +1053,6 @@ function isBinaryOpContext(context) {
|
|
|
1053
1053
|
return context.contextNode.operatorToken.kind !== SyntaxKind4.CommaToken;
|
|
1054
1054
|
case SyntaxKind4.ConditionalExpression:
|
|
1055
1055
|
case SyntaxKind4.ConditionalType:
|
|
1056
|
-
case SyntaxKind4.AsExpression:
|
|
1057
1056
|
case SyntaxKind4.ExportSpecifier:
|
|
1058
1057
|
case SyntaxKind4.ImportSpecifier:
|
|
1059
1058
|
case SyntaxKind4.TypePredicate:
|
|
@@ -4124,20 +4123,20 @@ function createCodeFixActionWithoutFixAll(fixName2, changes, description) {
|
|
|
4124
4123
|
void 0
|
|
4125
4124
|
);
|
|
4126
4125
|
}
|
|
4127
|
-
function createCodeFixAction(fixName2, changes, description,
|
|
4128
|
-
return createCodeFixActionWorker(fixName2, diagnosticToString(description), changes,
|
|
4126
|
+
function createCodeFixAction(fixName2, changes, description, fixId20, fixAllDescription) {
|
|
4127
|
+
return createCodeFixActionWorker(fixName2, diagnosticToString(description), changes, fixId20, diagnosticToString(fixAllDescription));
|
|
4129
4128
|
}
|
|
4130
|
-
function createCodeFixActionWorker(fixName2, description, changes,
|
|
4131
|
-
return { fixName: fixName2, description, changes, fixId:
|
|
4129
|
+
function createCodeFixActionWorker(fixName2, description, changes, fixId20, fixAllDescription) {
|
|
4130
|
+
return { fixName: fixName2, description, changes, fixId: fixId20, fixAllDescription };
|
|
4132
4131
|
}
|
|
4133
4132
|
function registerCodeFix(reg) {
|
|
4134
4133
|
for (const error of reg.errorCodes) {
|
|
4135
4134
|
errorCodeToFixes.add(String(error), reg);
|
|
4136
4135
|
}
|
|
4137
4136
|
if (reg.fixIds) {
|
|
4138
|
-
for (const
|
|
4139
|
-
Debug7.assert(!fixIdToRegistration.has(
|
|
4140
|
-
fixIdToRegistration.set(
|
|
4137
|
+
for (const fixId20 of reg.fixIds) {
|
|
4138
|
+
Debug7.assert(!fixIdToRegistration.has(fixId20));
|
|
4139
|
+
fixIdToRegistration.set(fixId20, reg);
|
|
4141
4140
|
}
|
|
4142
4141
|
}
|
|
4143
4142
|
}
|
|
@@ -4145,15 +4144,15 @@ function getSupportedErrorCodes() {
|
|
|
4145
4144
|
return arrayFrom(errorCodeToFixes.keys());
|
|
4146
4145
|
}
|
|
4147
4146
|
function removeFixIdIfFixAllUnavailable(registration, diagnostics) {
|
|
4148
|
-
const { errorCodes:
|
|
4147
|
+
const { errorCodes: errorCodes23 } = registration;
|
|
4149
4148
|
let maybeFixableDiagnostics = 0;
|
|
4150
4149
|
for (const diag of diagnostics) {
|
|
4151
|
-
if (contains4(
|
|
4150
|
+
if (contains4(errorCodes23, diag.code)) maybeFixableDiagnostics++;
|
|
4152
4151
|
if (maybeFixableDiagnostics > 1) break;
|
|
4153
4152
|
}
|
|
4154
4153
|
const fixAllUnavailable = maybeFixableDiagnostics < 2;
|
|
4155
|
-
return ({ fixId:
|
|
4156
|
-
return fixAllUnavailable ? action : { ...action, fixId:
|
|
4154
|
+
return ({ fixId: fixId20, fixAllDescription, ...action }) => {
|
|
4155
|
+
return fixAllUnavailable ? action : { ...action, fixId: fixId20, fixAllDescription };
|
|
4157
4156
|
};
|
|
4158
4157
|
}
|
|
4159
4158
|
function getFixes(context) {
|
|
@@ -4170,13 +4169,13 @@ function createCombinedCodeActions(changes) {
|
|
|
4170
4169
|
function createFileTextChanges(fileName, textChanges) {
|
|
4171
4170
|
return { fileName, textChanges };
|
|
4172
4171
|
}
|
|
4173
|
-
function codeFixAll(context,
|
|
4174
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context,
|
|
4172
|
+
function codeFixAll(context, errorCodes23, use) {
|
|
4173
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => eachDiagnostic(context, errorCodes23, (diag) => use(t, diag)));
|
|
4175
4174
|
return createCombinedCodeActions(changes);
|
|
4176
4175
|
}
|
|
4177
|
-
function eachDiagnostic(context,
|
|
4176
|
+
function eachDiagnostic(context, errorCodes23, cb) {
|
|
4178
4177
|
for (const diag of getDiagnostics(context)) {
|
|
4179
|
-
if (contains4(
|
|
4178
|
+
if (contains4(errorCodes23, diag.code)) {
|
|
4180
4179
|
cb(diag);
|
|
4181
4180
|
}
|
|
4182
4181
|
}
|
|
@@ -4190,45 +4189,14 @@ function getDiagnostics({ program, sourceFile, cancellationToken }) {
|
|
|
4190
4189
|
];
|
|
4191
4190
|
}
|
|
4192
4191
|
|
|
4193
|
-
// src/codefixes/addConvertToUnknownForNonOverlappingTypes.ts
|
|
4194
|
-
import {
|
|
4195
|
-
Debug as Debug8,
|
|
4196
|
-
Diagnostics,
|
|
4197
|
-
SyntaxKind as SyntaxKind9,
|
|
4198
|
-
createAsExpression,
|
|
4199
|
-
createKeywordTypeNode,
|
|
4200
|
-
findAncestor as findAncestor3,
|
|
4201
|
-
isAsExpression
|
|
4202
|
-
} from "@tslite/parser";
|
|
4203
|
-
import {
|
|
4204
|
-
getTokenAtPosition as getTokenAtPosition2
|
|
4205
|
-
} from "@tslite/services";
|
|
4206
|
-
var fixId = "addConvertToUnknownForNonOverlappingTypes";
|
|
4207
|
-
var errorCodes = [Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first.code];
|
|
4208
|
-
registerCodeFix({
|
|
4209
|
-
errorCodes,
|
|
4210
|
-
getCodeActions: (context) => {
|
|
4211
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange(t, context.sourceFile, context.span.start));
|
|
4212
|
-
return [createCodeFixAction(fixId, changes, Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
|
|
4213
|
-
},
|
|
4214
|
-
fixIds: [fixId],
|
|
4215
|
-
getAllCodeActions: (context) => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start))
|
|
4216
|
-
});
|
|
4217
|
-
function makeChange(changeTracker, sourceFile, pos) {
|
|
4218
|
-
const token = getTokenAtPosition2(sourceFile, pos);
|
|
4219
|
-
const assertion = Debug8.checkDefined(findAncestor3(token, (n) => isAsExpression(n)), "Expected to find an assertion expression");
|
|
4220
|
-
const replacement = createAsExpression(assertion.expression, createKeywordTypeNode(SyntaxKind9.UnknownKeyword));
|
|
4221
|
-
changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
|
|
4222
|
-
}
|
|
4223
|
-
|
|
4224
4192
|
// src/codefixes/addEmptyExportDeclaration.ts
|
|
4225
4193
|
import {
|
|
4226
|
-
Diagnostics
|
|
4194
|
+
Diagnostics,
|
|
4227
4195
|
createExportDeclaration,
|
|
4228
4196
|
createNamedExports
|
|
4229
4197
|
} from "@tslite/parser";
|
|
4230
4198
|
registerCodeFix({
|
|
4231
|
-
errorCodes: [
|
|
4199
|
+
errorCodes: [Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module.code],
|
|
4232
4200
|
getCodeActions: (context) => {
|
|
4233
4201
|
const { sourceFile } = context;
|
|
4234
4202
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (changes2) => {
|
|
@@ -4243,19 +4211,19 @@ registerCodeFix({
|
|
|
4243
4211
|
);
|
|
4244
4212
|
changes2.insertNodeAtEndOfScope(sourceFile, sourceFile, exportDeclaration);
|
|
4245
4213
|
});
|
|
4246
|
-
return [createCodeFixActionWithoutFixAll("addEmptyExportDeclaration", changes,
|
|
4214
|
+
return [createCodeFixActionWithoutFixAll("addEmptyExportDeclaration", changes, Diagnostics.Add_export_to_make_this_file_into_a_module)];
|
|
4247
4215
|
}
|
|
4248
4216
|
});
|
|
4249
4217
|
|
|
4250
4218
|
// src/codefixes/addMissingAsync.ts
|
|
4251
4219
|
import {
|
|
4252
|
-
Diagnostics as
|
|
4220
|
+
Diagnostics as Diagnostics2,
|
|
4253
4221
|
ModifierFlags,
|
|
4254
4222
|
createMap as createMap3,
|
|
4255
4223
|
createModifiersFromModifierFlags,
|
|
4256
4224
|
createNodeArray as createNodeArray2,
|
|
4257
4225
|
find as find4,
|
|
4258
|
-
findAncestor as
|
|
4226
|
+
findAncestor as findAncestor3,
|
|
4259
4227
|
getModifierFlags,
|
|
4260
4228
|
getNodeId as getNodeId2,
|
|
4261
4229
|
isArrowFunction as isArrowFunction2,
|
|
@@ -4266,22 +4234,22 @@ import {
|
|
|
4266
4234
|
import {
|
|
4267
4235
|
createTextSpanFromNode,
|
|
4268
4236
|
getSynthesizedDeepClone,
|
|
4269
|
-
getTokenAtPosition as
|
|
4237
|
+
getTokenAtPosition as getTokenAtPosition2,
|
|
4270
4238
|
textSpansEqual
|
|
4271
4239
|
} from "@tslite/services";
|
|
4272
|
-
var
|
|
4273
|
-
var
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4240
|
+
var fixId = "addMissingAsync";
|
|
4241
|
+
var errorCodes = [
|
|
4242
|
+
Diagnostics2.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
|
|
4243
|
+
Diagnostics2.Type_0_is_not_assignable_to_type_1.code,
|
|
4244
|
+
Diagnostics2.Type_0_is_not_comparable_to_type_1.code
|
|
4277
4245
|
];
|
|
4278
4246
|
registerCodeFix({
|
|
4279
|
-
fixIds: [
|
|
4280
|
-
errorCodes
|
|
4247
|
+
fixIds: [fixId],
|
|
4248
|
+
errorCodes,
|
|
4281
4249
|
getCodeActions: (context) => {
|
|
4282
4250
|
const { sourceFile, errorCode, cancellationToken, program, span } = context;
|
|
4283
4251
|
const diagnostic = find4(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
|
|
4284
|
-
const directSpan = diagnostic && diagnostic.relatedInformation && find4(diagnostic.relatedInformation, (r) => r.code ===
|
|
4252
|
+
const directSpan = diagnostic && diagnostic.relatedInformation && find4(diagnostic.relatedInformation, (r) => r.code === Diagnostics2.Did_you_mean_to_mark_this_function_as_async.code);
|
|
4285
4253
|
const decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
|
|
4286
4254
|
if (!decl) {
|
|
4287
4255
|
return;
|
|
@@ -4292,8 +4260,8 @@ registerCodeFix({
|
|
|
4292
4260
|
getAllCodeActions: (context) => {
|
|
4293
4261
|
const { sourceFile } = context;
|
|
4294
4262
|
const fixedDeclarations = createMap3();
|
|
4295
|
-
return codeFixAll(context,
|
|
4296
|
-
const span = diagnostic.relatedInformation && find4(diagnostic.relatedInformation, (r) => r.code ===
|
|
4263
|
+
return codeFixAll(context, errorCodes, (t, diagnostic) => {
|
|
4264
|
+
const span = diagnostic.relatedInformation && find4(diagnostic.relatedInformation, (r) => r.code === Diagnostics2.Did_you_mean_to_mark_this_function_as_async.code);
|
|
4297
4265
|
const decl = getFixableErrorSpanDeclaration(sourceFile, span);
|
|
4298
4266
|
if (!decl) {
|
|
4299
4267
|
return;
|
|
@@ -4304,10 +4272,10 @@ registerCodeFix({
|
|
|
4304
4272
|
}
|
|
4305
4273
|
});
|
|
4306
4274
|
function getFix(context, decl, trackChanges, fixedDeclarations) {
|
|
4307
|
-
const changes = trackChanges((t) =>
|
|
4308
|
-
return createCodeFixAction(
|
|
4275
|
+
const changes = trackChanges((t) => makeChange(t, context.sourceFile, decl, fixedDeclarations));
|
|
4276
|
+
return createCodeFixAction(fixId, changes, Diagnostics2.Add_async_modifier_to_containing_function, fixId, Diagnostics2.Add_all_missing_async_modifiers);
|
|
4309
4277
|
}
|
|
4310
|
-
function
|
|
4278
|
+
function makeChange(changeTracker, sourceFile, insertionSite, fixedDeclarations) {
|
|
4311
4279
|
if (fixedDeclarations) {
|
|
4312
4280
|
if (fixedDeclarations.has(getNodeId2(insertionSite).toString())) {
|
|
4313
4281
|
return;
|
|
@@ -4329,8 +4297,8 @@ function makeChange2(changeTracker, sourceFile, insertionSite, fixedDeclarations
|
|
|
4329
4297
|
}
|
|
4330
4298
|
function getFixableErrorSpanDeclaration(sourceFile, span) {
|
|
4331
4299
|
if (!span) return void 0;
|
|
4332
|
-
const token =
|
|
4333
|
-
const decl =
|
|
4300
|
+
const token = getTokenAtPosition2(sourceFile, span.start);
|
|
4301
|
+
const decl = findAncestor3(token, (node) => {
|
|
4334
4302
|
if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd2(span)) {
|
|
4335
4303
|
return "quit";
|
|
4336
4304
|
}
|
|
@@ -4339,15 +4307,15 @@ function getFixableErrorSpanDeclaration(sourceFile, span) {
|
|
|
4339
4307
|
return decl;
|
|
4340
4308
|
}
|
|
4341
4309
|
function getIsMatchingAsyncError(span, errorCode) {
|
|
4342
|
-
return ({ start, length: length3, relatedInformation, code }) => isNumber(start) && isNumber(length3) && textSpansEqual({ start, length: length3 }, span) && code === errorCode && !!relatedInformation && some(relatedInformation, (related) => related.code ===
|
|
4310
|
+
return ({ start, length: length3, relatedInformation, code }) => isNumber(start) && isNumber(length3) && textSpansEqual({ start, length: length3 }, span) && code === errorCode && !!relatedInformation && some(relatedInformation, (related) => related.code === Diagnostics2.Did_you_mean_to_mark_this_function_as_async.code);
|
|
4343
4311
|
}
|
|
4344
4312
|
|
|
4345
4313
|
// src/codefixes/addMissingAwait.ts
|
|
4346
4314
|
import {
|
|
4347
|
-
Diagnostics as
|
|
4315
|
+
Diagnostics as Diagnostics3,
|
|
4348
4316
|
ModifierFlags as ModifierFlags2,
|
|
4349
4317
|
NodeFlags,
|
|
4350
|
-
SyntaxKind as
|
|
4318
|
+
SyntaxKind as SyntaxKind9,
|
|
4351
4319
|
addToSeen as addToSeen2,
|
|
4352
4320
|
compact,
|
|
4353
4321
|
contains as contains5,
|
|
@@ -4355,7 +4323,7 @@ import {
|
|
|
4355
4323
|
createMap as createMap4,
|
|
4356
4324
|
createParen as createParen2,
|
|
4357
4325
|
find as find5,
|
|
4358
|
-
findAncestor as
|
|
4326
|
+
findAncestor as findAncestor4,
|
|
4359
4327
|
forEach,
|
|
4360
4328
|
getAncestor as getAncestor2,
|
|
4361
4329
|
hasModifier,
|
|
@@ -4380,30 +4348,30 @@ import {
|
|
|
4380
4348
|
FindAllReferences as FindAllReferences2,
|
|
4381
4349
|
createTextSpanFromNode as createTextSpanFromNode2,
|
|
4382
4350
|
findPrecedingToken as findPrecedingToken4,
|
|
4383
|
-
getTokenAtPosition as
|
|
4351
|
+
getTokenAtPosition as getTokenAtPosition3,
|
|
4384
4352
|
positionIsASICandidate as positionIsASICandidate2,
|
|
4385
4353
|
textSpansEqual as textSpansEqual2
|
|
4386
4354
|
} from "@tslite/services";
|
|
4387
|
-
var
|
|
4388
|
-
var propertyAccessCode =
|
|
4355
|
+
var fixId2 = "addMissingAwait";
|
|
4356
|
+
var propertyAccessCode = Diagnostics3.Property_0_does_not_exist_on_type_1.code;
|
|
4389
4357
|
var callableConstructableErrorCodes = [
|
|
4390
|
-
|
|
4358
|
+
Diagnostics3.This_expression_is_not_callable.code
|
|
4391
4359
|
];
|
|
4392
|
-
var
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4360
|
+
var errorCodes2 = [
|
|
4361
|
+
Diagnostics3.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
4362
|
+
Diagnostics3.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
4363
|
+
Diagnostics3.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
4364
|
+
Diagnostics3.Operator_0_cannot_be_applied_to_type_1.code,
|
|
4365
|
+
Diagnostics3.Operator_0_cannot_be_applied_to_types_1_and_2.code,
|
|
4366
|
+
Diagnostics3.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code,
|
|
4367
|
+
Diagnostics3.Type_0_is_not_an_array_type.code,
|
|
4368
|
+
Diagnostics3.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
|
|
4401
4369
|
propertyAccessCode,
|
|
4402
4370
|
...callableConstructableErrorCodes
|
|
4403
4371
|
];
|
|
4404
4372
|
registerCodeFix({
|
|
4405
|
-
fixIds: [
|
|
4406
|
-
errorCodes:
|
|
4373
|
+
fixIds: [fixId2],
|
|
4374
|
+
errorCodes: errorCodes2,
|
|
4407
4375
|
getCodeActions: (context) => {
|
|
4408
4376
|
const { sourceFile, errorCode, span, cancellationToken, program } = context;
|
|
4409
4377
|
const expression = getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
|
|
@@ -4421,7 +4389,7 @@ registerCodeFix({
|
|
|
4421
4389
|
const { sourceFile, program, cancellationToken } = context;
|
|
4422
4390
|
const checker = context.program.getTypeChecker();
|
|
4423
4391
|
const fixedDeclarations = createMap4();
|
|
4424
|
-
return codeFixAll(context,
|
|
4392
|
+
return codeFixAll(context, errorCodes2, (t, diagnostic) => {
|
|
4425
4393
|
const expression = getFixableErrorSpanExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program);
|
|
4426
4394
|
if (!expression) {
|
|
4427
4395
|
return;
|
|
@@ -4436,30 +4404,30 @@ function getDeclarationSiteFix(context, expression, errorCode, checker, trackCha
|
|
|
4436
4404
|
const awaitableInitializers = findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker);
|
|
4437
4405
|
if (awaitableInitializers) {
|
|
4438
4406
|
const initializerChanges = trackChanges((t) => {
|
|
4439
|
-
forEach(awaitableInitializers.initializers, ({ expression: expression2 }) =>
|
|
4407
|
+
forEach(awaitableInitializers.initializers, ({ expression: expression2 }) => makeChange2(t, errorCode, sourceFile, checker, expression2, fixedDeclarations));
|
|
4440
4408
|
if (fixedDeclarations && awaitableInitializers.needsSecondPassForFixAll) {
|
|
4441
|
-
|
|
4409
|
+
makeChange2(t, errorCode, sourceFile, checker, expression, fixedDeclarations);
|
|
4442
4410
|
}
|
|
4443
4411
|
});
|
|
4444
4412
|
return createCodeFixActionWithoutFixAll(
|
|
4445
4413
|
"addMissingAwaitToInitializer",
|
|
4446
4414
|
initializerChanges,
|
|
4447
|
-
awaitableInitializers.initializers.length === 1 ? [
|
|
4415
|
+
awaitableInitializers.initializers.length === 1 ? [Diagnostics3.Add_await_to_initializer_for_0, awaitableInitializers.initializers[0].declarationSymbol.name] : Diagnostics3.Add_await_to_initializers
|
|
4448
4416
|
);
|
|
4449
4417
|
}
|
|
4450
4418
|
}
|
|
4451
4419
|
function getUseSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
|
|
4452
|
-
const changes = trackChanges((t) =>
|
|
4453
|
-
return createCodeFixAction(
|
|
4420
|
+
const changes = trackChanges((t) => makeChange2(t, errorCode, context.sourceFile, checker, expression, fixedDeclarations));
|
|
4421
|
+
return createCodeFixAction(fixId2, changes, Diagnostics3.Add_await, fixId2, Diagnostics3.Fix_all_expressions_possibly_missing_await);
|
|
4454
4422
|
}
|
|
4455
4423
|
function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
|
|
4456
4424
|
const checker = program.getTypeChecker();
|
|
4457
4425
|
const diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
|
|
4458
|
-
return some2(diagnostics, ({ start, length: length3, relatedInformation, code }) => isNumber2(start) && isNumber2(length3) && textSpansEqual2({ start, length: length3 }, span) && code === errorCode && !!relatedInformation && some2(relatedInformation, (related) => related.code ===
|
|
4426
|
+
return some2(diagnostics, ({ start, length: length3, relatedInformation, code }) => isNumber2(start) && isNumber2(length3) && textSpansEqual2({ start, length: length3 }, span) && code === errorCode && !!relatedInformation && some2(relatedInformation, (related) => related.code === Diagnostics3.Did_you_forget_to_use_await.code));
|
|
4459
4427
|
}
|
|
4460
4428
|
function getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program) {
|
|
4461
|
-
const token =
|
|
4462
|
-
const expression =
|
|
4429
|
+
const token = getTokenAtPosition3(sourceFile, span.start);
|
|
4430
|
+
const expression = findAncestor4(token, (node) => {
|
|
4463
4431
|
if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd3(span)) {
|
|
4464
4432
|
return "quit";
|
|
4465
4433
|
}
|
|
@@ -4481,7 +4449,7 @@ function findAwaitableInitializers(expression, sourceFile, cancellationToken, pr
|
|
|
4481
4449
|
}
|
|
4482
4450
|
const declaration = tryCast(symbol.valueDeclaration, isVariableDeclaration2);
|
|
4483
4451
|
const variableName = declaration && tryCast(declaration.name, isIdentifier);
|
|
4484
|
-
const variableStatement = getAncestor2(declaration,
|
|
4452
|
+
const variableStatement = getAncestor2(declaration, SyntaxKind9.VariableStatement);
|
|
4485
4453
|
if (!declaration || !variableStatement || declaration.type || !declaration.initializer || variableStatement.getSourceFile() !== sourceFile || hasModifier(variableStatement, ModifierFlags2.Export) || !variableName || !isInsideAwaitableBody(declaration.initializer)) {
|
|
4486
4454
|
isCompleteFix = false;
|
|
4487
4455
|
continue;
|
|
@@ -4530,7 +4498,7 @@ function getIdentifiersFromErrorSpanExpression(expression, checker) {
|
|
|
4530
4498
|
function symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker) {
|
|
4531
4499
|
const errorNode = isPropertyAccessExpression(reference.parent) ? reference.parent.name : isBinaryExpression(reference.parent) ? reference.parent : reference;
|
|
4532
4500
|
const diagnostic = find5(diagnostics, (diagnostic2) => diagnostic2.start === errorNode.getStart(sourceFile) && diagnostic2.start + diagnostic2.length === errorNode.getEnd());
|
|
4533
|
-
return diagnostic && contains5(
|
|
4501
|
+
return diagnostic && contains5(errorCodes2, diagnostic.code) || // A Promise is usually not correct in a binary expression (it’s not valid
|
|
4534
4502
|
// in an arithmetic expression and an equality comparison seems unusual),
|
|
4535
4503
|
// but if the other side of the binary expression has an error, the side
|
|
4536
4504
|
// is typed `any` which will squash the error that would identify this
|
|
@@ -4540,9 +4508,9 @@ function symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, c
|
|
|
4540
4508
|
checker.getTypeAtLocation(errorNode).flags & TypeFlags.Any;
|
|
4541
4509
|
}
|
|
4542
4510
|
function isInsideAwaitableBody(node) {
|
|
4543
|
-
return node.kind & NodeFlags.AwaitContext || !!
|
|
4511
|
+
return node.kind & NodeFlags.AwaitContext || !!findAncestor4(node, (ancestor) => ancestor.parent && isArrowFunction3(ancestor.parent) && ancestor.parent.body === ancestor || isBlock(ancestor) && ancestor.parent.kind === SyntaxKind9.ArrowFunction);
|
|
4544
4512
|
}
|
|
4545
|
-
function
|
|
4513
|
+
function makeChange2(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
|
|
4546
4514
|
if (isBinaryExpression(insertionSite)) {
|
|
4547
4515
|
for (const side of [insertionSite.left, insertionSite.right]) {
|
|
4548
4516
|
if (fixedDeclarations && isIdentifier(side)) {
|
|
@@ -4596,11 +4564,11 @@ function insertLeadingSemicolonIfNeeded(changeTracker, beforeNode, sourceFile) {
|
|
|
4596
4564
|
|
|
4597
4565
|
// src/codefixes/addMissingConst.ts
|
|
4598
4566
|
import {
|
|
4599
|
-
Diagnostics as
|
|
4567
|
+
Diagnostics as Diagnostics4,
|
|
4600
4568
|
NodeSet as NodeSet2,
|
|
4601
|
-
SyntaxKind as
|
|
4569
|
+
SyntaxKind as SyntaxKind10,
|
|
4602
4570
|
every as every2,
|
|
4603
|
-
findAncestor as
|
|
4571
|
+
findAncestor as findAncestor5,
|
|
4604
4572
|
isArrayLiteralExpression,
|
|
4605
4573
|
isAssignmentExpression,
|
|
4606
4574
|
isBinaryExpression as isBinaryExpression2,
|
|
@@ -4609,36 +4577,36 @@ import {
|
|
|
4609
4577
|
isIdentifier as isIdentifier2
|
|
4610
4578
|
} from "@tslite/parser";
|
|
4611
4579
|
import {
|
|
4612
|
-
getTokenAtPosition as
|
|
4580
|
+
getTokenAtPosition as getTokenAtPosition4
|
|
4613
4581
|
} from "@tslite/services";
|
|
4614
|
-
var
|
|
4615
|
-
var
|
|
4616
|
-
|
|
4617
|
-
|
|
4582
|
+
var fixId3 = "addMissingConst";
|
|
4583
|
+
var errorCodes3 = [
|
|
4584
|
+
Diagnostics4.Cannot_find_name_0.code,
|
|
4585
|
+
Diagnostics4.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
|
|
4618
4586
|
];
|
|
4619
4587
|
registerCodeFix({
|
|
4620
|
-
errorCodes:
|
|
4588
|
+
errorCodes: errorCodes3,
|
|
4621
4589
|
getCodeActions: (context) => {
|
|
4622
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) =>
|
|
4590
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange3(t, context.sourceFile, context.span.start, context.program));
|
|
4623
4591
|
if (changes.length > 0) {
|
|
4624
|
-
return [createCodeFixAction(
|
|
4592
|
+
return [createCodeFixAction(fixId3, changes, Diagnostics4.Add_const_to_unresolved_variable, fixId3, Diagnostics4.Add_const_to_all_unresolved_variables)];
|
|
4625
4593
|
}
|
|
4626
4594
|
},
|
|
4627
|
-
fixIds: [
|
|
4595
|
+
fixIds: [fixId3],
|
|
4628
4596
|
getAllCodeActions: (context) => {
|
|
4629
4597
|
const fixedNodes = new NodeSet2();
|
|
4630
|
-
return codeFixAll(context,
|
|
4598
|
+
return codeFixAll(context, errorCodes3, (changes, diag) => makeChange3(changes, diag.file, diag.start, context.program, fixedNodes));
|
|
4631
4599
|
}
|
|
4632
4600
|
});
|
|
4633
|
-
function
|
|
4634
|
-
const token =
|
|
4635
|
-
const forInitializer =
|
|
4601
|
+
function makeChange3(changeTracker, sourceFile, pos, program, fixedNodes) {
|
|
4602
|
+
const token = getTokenAtPosition4(sourceFile, pos);
|
|
4603
|
+
const forInitializer = findAncestor5(
|
|
4636
4604
|
token,
|
|
4637
4605
|
(node) => isForInOrOfStatement(node.parent) ? node.parent.initializer === node : isPossiblyPartOfDestructuring(node) ? false : "quit"
|
|
4638
4606
|
);
|
|
4639
4607
|
if (forInitializer) return applyChange(changeTracker, forInitializer, sourceFile, fixedNodes);
|
|
4640
4608
|
const parent = token.parent;
|
|
4641
|
-
if (isBinaryExpression2(parent) && parent.operatorToken.kind ===
|
|
4609
|
+
if (isBinaryExpression2(parent) && parent.operatorToken.kind === SyntaxKind10.EqualsToken && isExpressionStatement(parent.parent)) {
|
|
4642
4610
|
return applyChange(changeTracker, token, sourceFile, fixedNodes);
|
|
4643
4611
|
}
|
|
4644
4612
|
if (isArrayLiteralExpression(parent)) {
|
|
@@ -4648,7 +4616,7 @@ function makeChange4(changeTracker, sourceFile, pos, program, fixedNodes) {
|
|
|
4648
4616
|
}
|
|
4649
4617
|
return applyChange(changeTracker, parent, sourceFile, fixedNodes);
|
|
4650
4618
|
}
|
|
4651
|
-
const commaExpression =
|
|
4619
|
+
const commaExpression = findAncestor5(
|
|
4652
4620
|
token,
|
|
4653
4621
|
(node) => isExpressionStatement(node.parent) ? true : isPossiblyPartOfCommaSeperatedInitializer(node) ? false : "quit"
|
|
4654
4622
|
);
|
|
@@ -4662,16 +4630,16 @@ function makeChange4(changeTracker, sourceFile, pos, program, fixedNodes) {
|
|
|
4662
4630
|
}
|
|
4663
4631
|
function applyChange(changeTracker, initializer, sourceFile, fixedNodes) {
|
|
4664
4632
|
if (!fixedNodes || fixedNodes.tryAdd(initializer)) {
|
|
4665
|
-
changeTracker.insertModifierBefore(sourceFile,
|
|
4633
|
+
changeTracker.insertModifierBefore(sourceFile, SyntaxKind10.ConstKeyword, initializer);
|
|
4666
4634
|
}
|
|
4667
4635
|
}
|
|
4668
4636
|
function isPossiblyPartOfDestructuring(node) {
|
|
4669
4637
|
switch (node.kind) {
|
|
4670
|
-
case
|
|
4671
|
-
case
|
|
4672
|
-
case
|
|
4673
|
-
case
|
|
4674
|
-
case
|
|
4638
|
+
case SyntaxKind10.Identifier:
|
|
4639
|
+
case SyntaxKind10.ArrayLiteralExpression:
|
|
4640
|
+
case SyntaxKind10.ObjectLiteralExpression:
|
|
4641
|
+
case SyntaxKind10.PropertyAssignment:
|
|
4642
|
+
case SyntaxKind10.ShorthandPropertyAssignment:
|
|
4675
4643
|
return true;
|
|
4676
4644
|
default:
|
|
4677
4645
|
return false;
|
|
@@ -4687,8 +4655,8 @@ function arrayElementCouldBeVariableDeclaration(expression, checker) {
|
|
|
4687
4655
|
}
|
|
4688
4656
|
function isPossiblyPartOfCommaSeperatedInitializer(node) {
|
|
4689
4657
|
switch (node.kind) {
|
|
4690
|
-
case
|
|
4691
|
-
case
|
|
4658
|
+
case SyntaxKind10.Identifier:
|
|
4659
|
+
case SyntaxKind10.BinaryExpression:
|
|
4692
4660
|
return true;
|
|
4693
4661
|
default:
|
|
4694
4662
|
return false;
|
|
@@ -4698,44 +4666,44 @@ function expressionCouldBeVariableDeclaration(expression, checker) {
|
|
|
4698
4666
|
if (!isBinaryExpression2(expression)) {
|
|
4699
4667
|
return false;
|
|
4700
4668
|
}
|
|
4701
|
-
return expression.operatorToken.kind ===
|
|
4669
|
+
return expression.operatorToken.kind === SyntaxKind10.EqualsToken && isIdentifier2(expression.left) && !checker.getSymbolAtLocation(expression.left);
|
|
4702
4670
|
}
|
|
4703
4671
|
|
|
4704
4672
|
// src/codefixes/addNameToNamelessParameter.ts
|
|
4705
4673
|
import {
|
|
4706
|
-
Debug as
|
|
4707
|
-
Diagnostics as
|
|
4674
|
+
Debug as Debug8,
|
|
4675
|
+
Diagnostics as Diagnostics5,
|
|
4708
4676
|
createParameter,
|
|
4709
4677
|
createTypeReferenceNode,
|
|
4710
4678
|
isIdentifier as isIdentifier3,
|
|
4711
4679
|
isParameter as isParameter2
|
|
4712
4680
|
} from "@tslite/parser";
|
|
4713
4681
|
import {
|
|
4714
|
-
getTokenAtPosition as
|
|
4682
|
+
getTokenAtPosition as getTokenAtPosition5
|
|
4715
4683
|
} from "@tslite/services";
|
|
4716
|
-
var
|
|
4717
|
-
var
|
|
4684
|
+
var fixId4 = "addNameToNamelessParameter";
|
|
4685
|
+
var errorCodes4 = [Diagnostics5.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
|
|
4718
4686
|
registerCodeFix({
|
|
4719
|
-
errorCodes:
|
|
4687
|
+
errorCodes: errorCodes4,
|
|
4720
4688
|
getCodeActions: (context) => {
|
|
4721
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) =>
|
|
4722
|
-
return [createCodeFixAction(
|
|
4689
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange4(t, context.sourceFile, context.span.start));
|
|
4690
|
+
return [createCodeFixAction(fixId4, changes, Diagnostics5.Add_parameter_name, fixId4, Diagnostics5.Add_names_to_all_parameters_without_names)];
|
|
4723
4691
|
},
|
|
4724
|
-
fixIds: [
|
|
4725
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
4692
|
+
fixIds: [fixId4],
|
|
4693
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes4, (changes, diag) => makeChange4(changes, diag.file, diag.start))
|
|
4726
4694
|
});
|
|
4727
|
-
function
|
|
4728
|
-
const token =
|
|
4695
|
+
function makeChange4(changeTracker, sourceFile, pos) {
|
|
4696
|
+
const token = getTokenAtPosition5(sourceFile, pos);
|
|
4729
4697
|
if (!isIdentifier3(token)) {
|
|
4730
|
-
return
|
|
4698
|
+
return Debug8.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug8.formatSyntaxKind(token.kind));
|
|
4731
4699
|
}
|
|
4732
4700
|
const param = token.parent;
|
|
4733
4701
|
if (!isParameter2(param)) {
|
|
4734
|
-
return
|
|
4702
|
+
return Debug8.fail("Tried to add a parameter name to a non-parameter: " + Debug8.formatSyntaxKind(token.kind));
|
|
4735
4703
|
}
|
|
4736
4704
|
const i = param.parent.parameters.indexOf(param);
|
|
4737
|
-
|
|
4738
|
-
|
|
4705
|
+
Debug8.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
|
|
4706
|
+
Debug8.assert(i > -1, "Parameter not found in parent parameter list.");
|
|
4739
4707
|
const replacement = createParameter(
|
|
4740
4708
|
param.modifiers,
|
|
4741
4709
|
param.dotDotDotToken,
|
|
@@ -4753,10 +4721,10 @@ function makeChange5(changeTracker, sourceFile, pos) {
|
|
|
4753
4721
|
|
|
4754
4722
|
// src/codefixes/convertToAsyncFunction.ts
|
|
4755
4723
|
import {
|
|
4756
|
-
Debug as
|
|
4757
|
-
Diagnostics as
|
|
4724
|
+
Debug as Debug9,
|
|
4725
|
+
Diagnostics as Diagnostics6,
|
|
4758
4726
|
NodeFlags as NodeFlags2,
|
|
4759
|
-
SyntaxKind as
|
|
4727
|
+
SyntaxKind as SyntaxKind11,
|
|
4760
4728
|
compact as compact2,
|
|
4761
4729
|
createAssignment,
|
|
4762
4730
|
createAwait as createAwait2,
|
|
@@ -4804,44 +4772,44 @@ import {
|
|
|
4804
4772
|
import {
|
|
4805
4773
|
getSynthesizedDeepClone as getSynthesizedDeepClone2,
|
|
4806
4774
|
getSynthesizedDeepCloneWithRenames,
|
|
4807
|
-
getTokenAtPosition as
|
|
4775
|
+
getTokenAtPosition as getTokenAtPosition6,
|
|
4808
4776
|
hasPropertyAccessExpressionWithName,
|
|
4809
4777
|
isFixablePromiseHandler,
|
|
4810
4778
|
isReturnStatementWithFixablePromiseHandler
|
|
4811
4779
|
} from "@tslite/services";
|
|
4812
|
-
var
|
|
4813
|
-
var
|
|
4780
|
+
var fixId5 = "convertToAsyncFunction";
|
|
4781
|
+
var errorCodes5 = [Diagnostics6.This_may_be_converted_to_an_async_function.code];
|
|
4814
4782
|
var codeActionSucceeded = true;
|
|
4815
4783
|
registerCodeFix({
|
|
4816
|
-
errorCodes:
|
|
4784
|
+
errorCodes: errorCodes5,
|
|
4817
4785
|
getCodeActions(context) {
|
|
4818
4786
|
codeActionSucceeded = true;
|
|
4819
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => convertToAsyncFunction(t, context.sourceFile, context.span.start, context.program.getTypeChecker()
|
|
4820
|
-
return codeActionSucceeded ? [createCodeFixAction(
|
|
4787
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => convertToAsyncFunction(t, context.sourceFile, context.span.start, context.program.getTypeChecker()));
|
|
4788
|
+
return codeActionSucceeded ? [createCodeFixAction(fixId5, changes, Diagnostics6.Convert_to_async_function, fixId5, Diagnostics6.Convert_all_to_async_functions)] : [];
|
|
4821
4789
|
},
|
|
4822
|
-
fixIds: [
|
|
4823
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
4790
|
+
fixIds: [fixId5],
|
|
4791
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes5, (changes, err) => convertToAsyncFunction(changes, err.file, err.start, context.program.getTypeChecker()))
|
|
4824
4792
|
});
|
|
4825
|
-
function convertToAsyncFunction(changes, sourceFile, position, checker
|
|
4826
|
-
const tokenAtPosition =
|
|
4793
|
+
function convertToAsyncFunction(changes, sourceFile, position, checker) {
|
|
4794
|
+
const tokenAtPosition = getTokenAtPosition6(sourceFile, position);
|
|
4827
4795
|
let functionToConvert;
|
|
4828
4796
|
if (isIdentifier4(tokenAtPosition) && isVariableDeclaration3(tokenAtPosition.parent) && tokenAtPosition.parent.initializer && isFunctionLikeDeclaration(tokenAtPosition.parent.initializer)) {
|
|
4829
4797
|
functionToConvert = tokenAtPosition.parent.initializer;
|
|
4830
4798
|
} else {
|
|
4831
|
-
functionToConvert = tryCast2(getContainingFunction(
|
|
4799
|
+
functionToConvert = tryCast2(getContainingFunction(getTokenAtPosition6(sourceFile, position)), isFunctionLikeDeclaration);
|
|
4832
4800
|
}
|
|
4833
4801
|
if (!functionToConvert) {
|
|
4834
4802
|
return;
|
|
4835
4803
|
}
|
|
4836
4804
|
const synthNamesMap = createMap5();
|
|
4837
4805
|
const setOfExpressionsToReturn = getAllPromiseExpressionsToReturn(functionToConvert, checker);
|
|
4838
|
-
const functionToConvertRenamed = renameCollidingVarNames(functionToConvert, checker, synthNamesMap
|
|
4839
|
-
const returnStatements = functionToConvertRenamed.body && isBlock2(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body) : emptyArray3;
|
|
4806
|
+
const functionToConvertRenamed = renameCollidingVarNames(functionToConvert, checker, synthNamesMap);
|
|
4807
|
+
const returnStatements = functionToConvertRenamed.body && isBlock2(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body, checker) : emptyArray3;
|
|
4840
4808
|
const transformer = { checker, synthNamesMap, setOfExpressionsToReturn };
|
|
4841
4809
|
if (!returnStatements.length) {
|
|
4842
4810
|
return;
|
|
4843
4811
|
}
|
|
4844
|
-
changes.insertLastModifierBefore(sourceFile,
|
|
4812
|
+
changes.insertLastModifierBefore(sourceFile, SyntaxKind11.AsyncKeyword, functionToConvert);
|
|
4845
4813
|
for (const returnStatement of returnStatements) {
|
|
4846
4814
|
forEachChild2(returnStatement, function visit(node) {
|
|
4847
4815
|
if (isCallExpression3(node)) {
|
|
@@ -4853,10 +4821,10 @@ function convertToAsyncFunction(changes, sourceFile, position, checker, context)
|
|
|
4853
4821
|
});
|
|
4854
4822
|
}
|
|
4855
4823
|
}
|
|
4856
|
-
function getReturnStatementsWithPromiseHandlers(body) {
|
|
4824
|
+
function getReturnStatementsWithPromiseHandlers(body, checker) {
|
|
4857
4825
|
const res = [];
|
|
4858
4826
|
forEachReturnStatement(body, (ret) => {
|
|
4859
|
-
if (isReturnStatementWithFixablePromiseHandler(ret)) res.push(ret);
|
|
4827
|
+
if (isReturnStatementWithFixablePromiseHandler(ret, checker)) res.push(ret);
|
|
4860
4828
|
});
|
|
4861
4829
|
return res;
|
|
4862
4830
|
}
|
|
@@ -4890,10 +4858,7 @@ function isPromiseTypedExpression(node, checker) {
|
|
|
4890
4858
|
if (!isExpression3(node)) return false;
|
|
4891
4859
|
return !!checker.getPromisedTypeOfPromise(checker.getTypeAtLocation(node));
|
|
4892
4860
|
}
|
|
4893
|
-
function
|
|
4894
|
-
return symbol.valueDeclaration && symbol.valueDeclaration.getSourceFile() === sourceFile;
|
|
4895
|
-
}
|
|
4896
|
-
function renameCollidingVarNames(nodeToRename, checker, synthNamesMap, sourceFile) {
|
|
4861
|
+
function renameCollidingVarNames(nodeToRename, checker, synthNamesMap) {
|
|
4897
4862
|
const identsToRenameMap = createMap5();
|
|
4898
4863
|
const collidingSymbolMap = createMultiMap2();
|
|
4899
4864
|
forEachChild2(nodeToRename, function visit(node) {
|
|
@@ -4902,14 +4867,13 @@ function renameCollidingVarNames(nodeToRename, checker, synthNamesMap, sourceFil
|
|
|
4902
4867
|
return;
|
|
4903
4868
|
}
|
|
4904
4869
|
const symbol = checker.getSymbolAtLocation(node);
|
|
4905
|
-
|
|
4906
|
-
if (symbol && isDefinedInFile) {
|
|
4870
|
+
if (symbol) {
|
|
4907
4871
|
const type = checker.getTypeAtLocation(node);
|
|
4908
4872
|
const lastCallSignature = getLastCallSignature(type, checker);
|
|
4909
4873
|
const symbolIdString = getSymbolId2(symbol).toString();
|
|
4910
4874
|
if (lastCallSignature && !isFunctionLikeDeclaration(node.parent) && !synthNamesMap.has(symbolIdString)) {
|
|
4911
4875
|
const firstParameter = firstOrUndefined2(lastCallSignature.parameters);
|
|
4912
|
-
const ident = firstParameter && isParameter3(firstParameter.valueDeclaration) && tryCast2(firstParameter.valueDeclaration.name, isIdentifier4) || createOptimisticUniqueName("result");
|
|
4876
|
+
const ident = firstParameter?.valueDeclaration && isParameter3(firstParameter.valueDeclaration) && tryCast2(firstParameter.valueDeclaration.name, isIdentifier4) || createOptimisticUniqueName("result");
|
|
4913
4877
|
const synthName = getNewNameIfConflict(ident, collidingSymbolMap);
|
|
4914
4878
|
synthNamesMap.set(symbolIdString, synthName);
|
|
4915
4879
|
collidingSymbolMap.add(ident.text, symbol);
|
|
@@ -4960,7 +4924,7 @@ function transformExpression(node, transformer, prevArgName) {
|
|
|
4960
4924
|
}
|
|
4961
4925
|
const nodeType = transformer.checker.getTypeAtLocation(node);
|
|
4962
4926
|
if (nodeType && transformer.checker.getPromisedTypeOfPromise(nodeType)) {
|
|
4963
|
-
|
|
4927
|
+
Debug9.assertNode(node.original.parent, isPropertyAccessExpression2);
|
|
4964
4928
|
return transformPromiseExpressionOfPropertyAccess(node, transformer, prevArgName);
|
|
4965
4929
|
}
|
|
4966
4930
|
return silentFail();
|
|
@@ -5097,9 +5061,9 @@ function maybeAnnotateAndReturn(expressionToReturn, typeAnnotation) {
|
|
|
5097
5061
|
}
|
|
5098
5062
|
function getTransformationBody(func, prevArgName, argName, parent, transformer) {
|
|
5099
5063
|
switch (func.kind) {
|
|
5100
|
-
case
|
|
5064
|
+
case SyntaxKind11.NullKeyword:
|
|
5101
5065
|
break;
|
|
5102
|
-
case
|
|
5066
|
+
case SyntaxKind11.Identifier:
|
|
5103
5067
|
if (!argName) {
|
|
5104
5068
|
break;
|
|
5105
5069
|
}
|
|
@@ -5124,7 +5088,7 @@ function getTransformationBody(func, prevArgName, argName, parent, transformer)
|
|
|
5124
5088
|
}
|
|
5125
5089
|
return varDeclOrAssignment;
|
|
5126
5090
|
// Na tag, também a function expression (CK-02).
|
|
5127
|
-
case
|
|
5091
|
+
case SyntaxKind11.ArrowFunction: {
|
|
5128
5092
|
const funcBody = func.body;
|
|
5129
5093
|
if (isBlock2(funcBody)) {
|
|
5130
5094
|
let refactoredStmts = [];
|
|
@@ -5132,7 +5096,7 @@ function getTransformationBody(func, prevArgName, argName, parent, transformer)
|
|
|
5132
5096
|
for (const statement of funcBody.statements) {
|
|
5133
5097
|
if (isReturnStatement(statement)) {
|
|
5134
5098
|
seenReturnStatement = true;
|
|
5135
|
-
if (isReturnStatementWithFixablePromiseHandler(statement)) {
|
|
5099
|
+
if (isReturnStatementWithFixablePromiseHandler(statement, transformer.checker)) {
|
|
5136
5100
|
refactoredStmts = refactoredStmts.concat(getInnerTransformationBody(transformer, [statement], prevArgName));
|
|
5137
5101
|
} else {
|
|
5138
5102
|
refactoredStmts.push(...maybeAnnotateAndReturn(statement.expression, parent.typeArguments?.[0]));
|
|
@@ -5148,7 +5112,7 @@ function getTransformationBody(func, prevArgName, argName, parent, transformer)
|
|
|
5148
5112
|
seenReturnStatement
|
|
5149
5113
|
);
|
|
5150
5114
|
} else {
|
|
5151
|
-
const innerRetStmts = isFixablePromiseHandler(funcBody) ? [createReturn(funcBody)] : emptyArray3;
|
|
5115
|
+
const innerRetStmts = isFixablePromiseHandler(funcBody, transformer.checker) ? [createReturn(funcBody)] : emptyArray3;
|
|
5152
5116
|
const innerCbBody = getInnerTransformationBody(transformer, innerRetStmts, prevArgName);
|
|
5153
5117
|
if (innerCbBody.length > 0) {
|
|
5154
5118
|
return innerCbBody;
|
|
@@ -5307,32 +5271,32 @@ function shouldReturn(expression, transformer) {
|
|
|
5307
5271
|
|
|
5308
5272
|
// src/codefixes/correctQualifiedNameToIndexedAccessType.ts
|
|
5309
5273
|
import {
|
|
5310
|
-
Debug as
|
|
5311
|
-
Diagnostics as
|
|
5274
|
+
Debug as Debug10,
|
|
5275
|
+
Diagnostics as Diagnostics7,
|
|
5312
5276
|
createIndexedAccessTypeNode,
|
|
5313
5277
|
createLiteral,
|
|
5314
5278
|
createLiteralTypeNode,
|
|
5315
5279
|
createTypeReferenceNode as createTypeReferenceNode2,
|
|
5316
|
-
findAncestor as
|
|
5280
|
+
findAncestor as findAncestor6,
|
|
5317
5281
|
isIdentifier as isIdentifier5,
|
|
5318
5282
|
isQualifiedName
|
|
5319
5283
|
} from "@tslite/parser";
|
|
5320
5284
|
import {
|
|
5321
|
-
getTokenAtPosition as
|
|
5285
|
+
getTokenAtPosition as getTokenAtPosition7
|
|
5322
5286
|
} from "@tslite/services";
|
|
5323
|
-
var
|
|
5324
|
-
var
|
|
5287
|
+
var fixId6 = "correctQualifiedNameToIndexedAccessType";
|
|
5288
|
+
var errorCodes6 = [Diagnostics7.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1.code];
|
|
5325
5289
|
registerCodeFix({
|
|
5326
|
-
errorCodes:
|
|
5290
|
+
errorCodes: errorCodes6,
|
|
5327
5291
|
getCodeActions(context) {
|
|
5328
5292
|
const qualifiedName = getQualifiedName(context.sourceFile, context.span.start);
|
|
5329
5293
|
if (!qualifiedName) return void 0;
|
|
5330
5294
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange(t, context.sourceFile, qualifiedName));
|
|
5331
5295
|
const newText = `${qualifiedName.left.text}["${qualifiedName.right.text}"]`;
|
|
5332
|
-
return [createCodeFixAction(
|
|
5296
|
+
return [createCodeFixAction(fixId6, changes, [Diagnostics7.Rewrite_as_the_indexed_access_type_0, newText], fixId6, Diagnostics7.Rewrite_all_as_indexed_access_types)];
|
|
5333
5297
|
},
|
|
5334
|
-
fixIds: [
|
|
5335
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
5298
|
+
fixIds: [fixId6],
|
|
5299
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes6, (changes, diag) => {
|
|
5336
5300
|
const q = getQualifiedName(diag.file, diag.start);
|
|
5337
5301
|
if (q) {
|
|
5338
5302
|
doChange(changes, diag.file, q);
|
|
@@ -5340,8 +5304,8 @@ registerCodeFix({
|
|
|
5340
5304
|
})
|
|
5341
5305
|
});
|
|
5342
5306
|
function getQualifiedName(sourceFile, pos) {
|
|
5343
|
-
const qualifiedName =
|
|
5344
|
-
|
|
5307
|
+
const qualifiedName = findAncestor6(getTokenAtPosition7(sourceFile, pos), isQualifiedName);
|
|
5308
|
+
Debug10.assert(!!qualifiedName, "Expected position to be owned by a qualified name.");
|
|
5345
5309
|
return isIdentifier5(qualifiedName.left) ? qualifiedName : void 0;
|
|
5346
5310
|
}
|
|
5347
5311
|
function doChange(changeTracker, sourceFile, qualifiedName) {
|
|
@@ -5359,12 +5323,12 @@ function doChange(changeTracker, sourceFile, qualifiedName) {
|
|
|
5359
5323
|
|
|
5360
5324
|
// src/codefixes/importFixes.ts
|
|
5361
5325
|
import {
|
|
5362
|
-
Debug as
|
|
5363
|
-
Diagnostics as
|
|
5326
|
+
Debug as Debug11,
|
|
5327
|
+
Diagnostics as Diagnostics8,
|
|
5364
5328
|
InternalSymbolName,
|
|
5365
5329
|
ScriptTarget as ScriptTarget3,
|
|
5366
5330
|
SymbolFlags,
|
|
5367
|
-
SyntaxKind as
|
|
5331
|
+
SyntaxKind as SyntaxKind12,
|
|
5368
5332
|
arrayFrom as arrayFrom2,
|
|
5369
5333
|
cast as cast2,
|
|
5370
5334
|
combine,
|
|
@@ -5410,7 +5374,7 @@ import {
|
|
|
5410
5374
|
getMeaningFromLocation,
|
|
5411
5375
|
getNameForExportedSymbol,
|
|
5412
5376
|
getQuotePreference,
|
|
5413
|
-
getTokenAtPosition as
|
|
5377
|
+
getTokenAtPosition as getTokenAtPosition8,
|
|
5414
5378
|
getTypeKeywordOfTypeOnlyImport,
|
|
5415
5379
|
getUniqueSymbolId,
|
|
5416
5380
|
insertImports,
|
|
@@ -5419,15 +5383,15 @@ import {
|
|
|
5419
5383
|
} from "@tslite/services";
|
|
5420
5384
|
var importFixName = "import";
|
|
5421
5385
|
var importFixId = "fixMissingImport";
|
|
5422
|
-
var
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5386
|
+
var errorCodes7 = [
|
|
5387
|
+
Diagnostics8.Cannot_find_name_0.code,
|
|
5388
|
+
Diagnostics8.Cannot_find_name_0_Did_you_mean_1.code,
|
|
5389
|
+
Diagnostics8.Cannot_find_namespace_0.code,
|
|
5390
|
+
Diagnostics8._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code
|
|
5427
5391
|
];
|
|
5428
5392
|
var languageVersion = ScriptTarget3.ES2020;
|
|
5429
5393
|
registerCodeFix({
|
|
5430
|
-
errorCodes:
|
|
5394
|
+
errorCodes: errorCodes7,
|
|
5431
5395
|
getCodeActions(context) {
|
|
5432
5396
|
const { preferences, sourceFile, span } = context;
|
|
5433
5397
|
const info = getFixesInfo(context, span.start);
|
|
@@ -5440,7 +5404,7 @@ registerCodeFix({
|
|
|
5440
5404
|
getAllCodeActions: (context) => {
|
|
5441
5405
|
const { sourceFile, program, preferences, host } = context;
|
|
5442
5406
|
const importAdder = createImportAdder(sourceFile, program, preferences, host);
|
|
5443
|
-
eachDiagnostic(context,
|
|
5407
|
+
eachDiagnostic(context, errorCodes7, (diag) => importAdder.addImportFromDiagnostic(diag, context));
|
|
5444
5408
|
return createCombinedCodeActions(ts_textChanges_exports.ChangeTracker.with(context, importAdder.writeFixes));
|
|
5445
5409
|
}
|
|
5446
5410
|
});
|
|
@@ -5455,7 +5419,7 @@ function createImportAdder(sourceFile, program, preferences, host) {
|
|
|
5455
5419
|
addImport(info);
|
|
5456
5420
|
}
|
|
5457
5421
|
function addImportFromExportedSymbol(exportedSymbol) {
|
|
5458
|
-
const moduleSymbol =
|
|
5422
|
+
const moduleSymbol = Debug11.checkDefined(exportedSymbol.parent);
|
|
5459
5423
|
const symbolName2 = getNameForExportedSymbol(exportedSymbol, languageVersion);
|
|
5460
5424
|
const checker = program.getTypeChecker();
|
|
5461
5425
|
const symbol = checker.getMergedSymbol(skipAlias(exportedSymbol, checker));
|
|
@@ -5490,7 +5454,7 @@ function createImportAdder(sourceFile, program, preferences, host) {
|
|
|
5490
5454
|
if (importKind === 0 /* Named */) {
|
|
5491
5455
|
pushIfUnique(entry.namedImports, symbolName2);
|
|
5492
5456
|
} else {
|
|
5493
|
-
|
|
5457
|
+
Debug11.assert(entry.defaultImport === void 0 || entry.defaultImport === symbolName2, "(Add to Existing) Default import should be missing or match symbolName");
|
|
5494
5458
|
entry.defaultImport = symbolName2;
|
|
5495
5459
|
}
|
|
5496
5460
|
break;
|
|
@@ -5503,7 +5467,7 @@ function createImportAdder(sourceFile, program, preferences, host) {
|
|
|
5503
5467
|
}
|
|
5504
5468
|
switch (importKind) {
|
|
5505
5469
|
case 1 /* Default */:
|
|
5506
|
-
|
|
5470
|
+
Debug11.assert(entry.defaultImport === void 0 || entry.defaultImport === symbolName2, "(Add new) Default import should be missing or match symbolName");
|
|
5507
5471
|
entry.defaultImport = symbolName2;
|
|
5508
5472
|
break;
|
|
5509
5473
|
case 0 /* Named */:
|
|
@@ -5513,7 +5477,7 @@ function createImportAdder(sourceFile, program, preferences, host) {
|
|
|
5513
5477
|
break;
|
|
5514
5478
|
}
|
|
5515
5479
|
default:
|
|
5516
|
-
|
|
5480
|
+
Debug11.assertNever(fix, `fix wasn't never - got kind ${fix.kind}`);
|
|
5517
5481
|
}
|
|
5518
5482
|
}
|
|
5519
5483
|
function writeFixes(changeTracker) {
|
|
@@ -5546,7 +5510,7 @@ function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, sym
|
|
|
5546
5510
|
return { moduleSpecifier, codeAction: codeFixActionToCodeAction(codeActionForFix({ host, formatContext, preferences }, sourceFile, symbolName2, fix, getQuotePreference(sourceFile, preferences))) };
|
|
5547
5511
|
}
|
|
5548
5512
|
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName2, program, position, host, preferences) {
|
|
5549
|
-
|
|
5513
|
+
Debug11.assert(exportInfos.some((info) => info.moduleSymbol === moduleSymbol), "Some exportInfo should match the specified moduleSymbol");
|
|
5550
5514
|
return first2(getFixForImport(exportInfos, symbolName2, position, program, sourceFile, host, preferences));
|
|
5551
5515
|
}
|
|
5552
5516
|
function codeFixActionToCodeAction({ description, changes }) {
|
|
@@ -5571,7 +5535,7 @@ function getAllReExportingModules(importingFile, exportedSymbol, exportingModule
|
|
|
5571
5535
|
return result;
|
|
5572
5536
|
}
|
|
5573
5537
|
function isTypeOnlyPosition(sourceFile, position) {
|
|
5574
|
-
return isValidTypeOnlyAliasUseSite(
|
|
5538
|
+
return isValidTypeOnlyAliasUseSite(getTokenAtPosition8(sourceFile, position));
|
|
5575
5539
|
}
|
|
5576
5540
|
function getFixForImport(exportInfos, symbolName2, position, program, sourceFile, host, preferences) {
|
|
5577
5541
|
const checker = program.getTypeChecker();
|
|
@@ -5604,13 +5568,13 @@ function tryAddToExistingImport(existingImports, canUseTypeOnlyImport) {
|
|
|
5604
5568
|
const { importClause } = declaration;
|
|
5605
5569
|
if (!importClause) return void 0;
|
|
5606
5570
|
const { name, namedBindings } = importClause;
|
|
5607
|
-
return importKind === 1 /* Default */ && !name || importKind === 0 /* Named */ && (!namedBindings || namedBindings.kind ===
|
|
5571
|
+
return importKind === 1 /* Default */ && !name || importKind === 0 /* Named */ && (!namedBindings || namedBindings.kind === SyntaxKind12.NamedImports) ? { kind: 1 /* AddToExisting */, importClauseOrBindingPattern: importClause, importKind, moduleSpecifier: declaration.moduleSpecifier.getText(), canUseTypeOnlyImport } : void 0;
|
|
5608
5572
|
});
|
|
5609
5573
|
}
|
|
5610
5574
|
function getExistingImportDeclarations({ moduleSymbol, importKind }, checker, sourceFile) {
|
|
5611
5575
|
return mapDefined2(sourceFile.imports, (moduleSpecifier) => {
|
|
5612
5576
|
const i = importFromModuleSpecifier(moduleSpecifier);
|
|
5613
|
-
if (i.kind ===
|
|
5577
|
+
if (i.kind === SyntaxKind12.ImportDeclaration) {
|
|
5614
5578
|
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind } : void 0;
|
|
5615
5579
|
}
|
|
5616
5580
|
});
|
|
@@ -5628,14 +5592,14 @@ function newImportInfoFromExistingSpecifier({ declaration, importKind }) {
|
|
|
5628
5592
|
return isStringLiteral2(moduleSpecifier) ? { kind: 2 /* AddNew */, moduleSpecifier: moduleSpecifier.text, importKind } : void 0;
|
|
5629
5593
|
}
|
|
5630
5594
|
function getFixesInfo(context, pos) {
|
|
5631
|
-
const symbolToken =
|
|
5595
|
+
const symbolToken = getTokenAtPosition8(context.sourceFile, pos);
|
|
5632
5596
|
const info = isIdentifier6(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken) : void 0;
|
|
5633
5597
|
return info && { ...info, fixes: sort(info.fixes, (a, b) => a.kind - b.kind) };
|
|
5634
5598
|
}
|
|
5635
5599
|
function getFixesInfoForNonUMDImport({ sourceFile, program, cancellationToken, host, preferences }, symbolToken) {
|
|
5636
5600
|
const checker = program.getTypeChecker();
|
|
5637
5601
|
const symbolName2 = symbolToken.text;
|
|
5638
|
-
|
|
5602
|
+
Debug11.assert(symbolName2 !== InternalSymbolName.Default, "'default' isn't a legal identifier and couldn't occur here");
|
|
5639
5603
|
const exportInfos = getExportInfos(symbolName2, getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, checker, program, host);
|
|
5640
5604
|
const fixes = arrayFrom2(flatMapIterator(exportInfos.entries(), ([_, exportInfos2]) => getFixForImport(exportInfos2, symbolName2, symbolToken.getStart(sourceFile), program, sourceFile, host, preferences)));
|
|
5641
5605
|
return { fixes, symbolName: symbolName2 };
|
|
@@ -5675,7 +5639,7 @@ function getDefaultExportInfoWorker(defaultExport, moduleSymbol, checker) {
|
|
|
5675
5639
|
if (name !== void 0) return { symbolForMeaning: defaultExport, name };
|
|
5676
5640
|
if (defaultExport.flags & SymbolFlags.Alias) {
|
|
5677
5641
|
const aliased = checker.getImmediateAliasedSymbol(defaultExport);
|
|
5678
|
-
return aliased && getDefaultExportInfoWorker(aliased,
|
|
5642
|
+
return aliased && getDefaultExportInfoWorker(aliased, Debug11.checkDefined(aliased.parent, "Alias targets of default exports must have a parent"), checker);
|
|
5679
5643
|
}
|
|
5680
5644
|
if (defaultExport.escapedName !== InternalSymbolName.Default) {
|
|
5681
5645
|
return { symbolForMeaning: defaultExport, name: defaultExport.getName() };
|
|
@@ -5689,7 +5653,7 @@ function getNameForExportDefault(symbol) {
|
|
|
5689
5653
|
return declaration.expression.text;
|
|
5690
5654
|
}
|
|
5691
5655
|
} else if (isExportSpecifier(declaration)) {
|
|
5692
|
-
|
|
5656
|
+
Debug11.assert(declaration.name.text === InternalSymbolName.Default, "Expected the specifier to be a default export");
|
|
5693
5657
|
return declaration.propertyName && declaration.propertyName.text;
|
|
5694
5658
|
}
|
|
5695
5659
|
});
|
|
@@ -5699,18 +5663,18 @@ function codeActionForFix(context, sourceFile, symbolName2, fix, quotePreference
|
|
|
5699
5663
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (tracker) => {
|
|
5700
5664
|
diag = codeActionForFixWorker(tracker, sourceFile, symbolName2, fix, quotePreference);
|
|
5701
5665
|
});
|
|
5702
|
-
return createCodeFixAction(importFixName, changes, diag, importFixId,
|
|
5666
|
+
return createCodeFixAction(importFixName, changes, diag, importFixId, Diagnostics8.Add_all_missing_imports);
|
|
5703
5667
|
}
|
|
5704
5668
|
function codeActionForFixWorker(changes, sourceFile, symbolName2, fix, quotePreference) {
|
|
5705
5669
|
switch (fix.kind) {
|
|
5706
5670
|
case 0 /* UseNamespace */:
|
|
5707
5671
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
5708
|
-
return [
|
|
5672
|
+
return [Diagnostics8.Change_0_to_1, symbolName2, `${fix.namespacePrefix}.${symbolName2}`];
|
|
5709
5673
|
case 1 /* AddToExisting */: {
|
|
5710
5674
|
const { importClauseOrBindingPattern, importKind, canUseTypeOnlyImport, moduleSpecifier } = fix;
|
|
5711
5675
|
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName2 : void 0, importKind === 0 /* Named */ ? [symbolName2] : emptyArray4, canUseTypeOnlyImport);
|
|
5712
5676
|
const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier);
|
|
5713
|
-
return [importKind === 1 /* Default */ ?
|
|
5677
|
+
return [importKind === 1 /* Default */ ? Diagnostics8.Add_default_import_0_to_existing_import_declaration_from_1 : Diagnostics8.Add_0_to_existing_import_declaration_from_1, symbolName2, moduleSpecifierWithoutQuotes];
|
|
5714
5678
|
}
|
|
5715
5679
|
case 2 /* AddNew */: {
|
|
5716
5680
|
const { importKind, moduleSpecifier } = fix;
|
|
@@ -5722,16 +5686,16 @@ function codeActionForFixWorker(changes, sourceFile, symbolName2, fix, quotePref
|
|
|
5722
5686
|
/*blankLineBetween*/
|
|
5723
5687
|
true
|
|
5724
5688
|
);
|
|
5725
|
-
return [importKind === 1 /* Default */ ?
|
|
5689
|
+
return [importKind === 1 /* Default */ ? Diagnostics8.Import_default_0_from_module_1 : Diagnostics8.Import_0_from_module_1, symbolName2, moduleSpecifier];
|
|
5726
5690
|
}
|
|
5727
5691
|
default:
|
|
5728
|
-
return
|
|
5692
|
+
return Debug11.assertNever(fix, `Unexpected fix kind ${fix.kind}`);
|
|
5729
5693
|
}
|
|
5730
5694
|
}
|
|
5731
5695
|
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, canUseTypeOnlyImport) {
|
|
5732
5696
|
const convertTypeOnlyToRegular = !canUseTypeOnlyImport && clause.isTypeOnly;
|
|
5733
5697
|
if (defaultImport) {
|
|
5734
|
-
|
|
5698
|
+
Debug11.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
5735
5699
|
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), createIdentifier3(defaultImport), { suffix: ", " });
|
|
5736
5700
|
}
|
|
5737
5701
|
if (namedImports.length) {
|
|
@@ -5750,7 +5714,7 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
|
|
|
5750
5714
|
if (clause.namedBindings) {
|
|
5751
5715
|
changes.replaceNode(sourceFile, clause.namedBindings, namedImports2);
|
|
5752
5716
|
} else {
|
|
5753
|
-
changes.insertNodeAfter(sourceFile,
|
|
5717
|
+
changes.insertNodeAfter(sourceFile, Debug11.checkDefined(clause.name, "Import clause must have either named imports or a default import"), namedImports2);
|
|
5754
5718
|
}
|
|
5755
5719
|
}
|
|
5756
5720
|
}
|
|
@@ -5776,7 +5740,7 @@ function getNewImports(moduleSpecifier, quotePreference, imports) {
|
|
|
5776
5740
|
quotePreference
|
|
5777
5741
|
));
|
|
5778
5742
|
}
|
|
5779
|
-
return
|
|
5743
|
+
return Debug11.checkDefined(statements);
|
|
5780
5744
|
}
|
|
5781
5745
|
function symbolHasMeaning({ declarations }, meaning) {
|
|
5782
5746
|
return some3(declarations, (decl) => !!(getMeaningFromDeclaration(decl) & meaning));
|
|
@@ -5802,15 +5766,15 @@ Completions.registerAutoImportProvider({
|
|
|
5802
5766
|
|
|
5803
5767
|
// src/codefixes/fixSpelling.ts
|
|
5804
5768
|
import {
|
|
5805
|
-
Debug as
|
|
5806
|
-
Diagnostics as
|
|
5769
|
+
Debug as Debug12,
|
|
5770
|
+
Diagnostics as Diagnostics9,
|
|
5807
5771
|
NodeFlags as NodeFlags3,
|
|
5808
5772
|
ScriptTarget as ScriptTarget4,
|
|
5809
5773
|
SymbolFlags as SymbolFlags2,
|
|
5810
5774
|
createElementAccess,
|
|
5811
5775
|
createIdentifier as createIdentifier4,
|
|
5812
5776
|
createLiteral as createLiteral2,
|
|
5813
|
-
findAncestor as
|
|
5777
|
+
findAncestor as findAncestor7,
|
|
5814
5778
|
getResolvedModule as getResolvedModule2,
|
|
5815
5779
|
getTextOfNode,
|
|
5816
5780
|
isIdentifier as isIdentifier7,
|
|
@@ -5824,46 +5788,46 @@ import {
|
|
|
5824
5788
|
import {
|
|
5825
5789
|
SemanticMeaning as SemanticMeaning2,
|
|
5826
5790
|
getMeaningFromLocation as getMeaningFromLocation2,
|
|
5827
|
-
getTokenAtPosition as
|
|
5791
|
+
getTokenAtPosition as getTokenAtPosition9
|
|
5828
5792
|
} from "@tslite/services";
|
|
5829
|
-
var
|
|
5830
|
-
var
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5793
|
+
var fixId7 = "fixSpelling";
|
|
5794
|
+
var errorCodes8 = [
|
|
5795
|
+
Diagnostics9.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code,
|
|
5796
|
+
Diagnostics9.Cannot_find_name_0_Did_you_mean_1.code,
|
|
5797
|
+
Diagnostics9.Module_0_has_no_exported_member_1_Did_you_mean_2.code
|
|
5834
5798
|
];
|
|
5835
5799
|
var languageVersion2 = ScriptTarget4.ES2020;
|
|
5836
5800
|
registerCodeFix({
|
|
5837
|
-
errorCodes:
|
|
5801
|
+
errorCodes: errorCodes8,
|
|
5838
5802
|
getCodeActions(context) {
|
|
5839
5803
|
const { sourceFile } = context;
|
|
5840
5804
|
const info = getInfo(sourceFile, context.span.start, context);
|
|
5841
5805
|
if (!info) return void 0;
|
|
5842
5806
|
const { node, suggestedSymbol } = info;
|
|
5843
5807
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange2(t, sourceFile, node, suggestedSymbol, languageVersion2));
|
|
5844
|
-
return [createCodeFixAction("spelling", changes, [
|
|
5808
|
+
return [createCodeFixAction("spelling", changes, [Diagnostics9.Change_spelling_to_0, symbolName(suggestedSymbol)], fixId7, Diagnostics9.Fix_all_detected_spelling_errors)];
|
|
5845
5809
|
},
|
|
5846
|
-
fixIds: [
|
|
5847
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
5810
|
+
fixIds: [fixId7],
|
|
5811
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes8, (changes, diag) => {
|
|
5848
5812
|
const info = getInfo(diag.file, diag.start, context);
|
|
5849
5813
|
if (info) doChange2(changes, context.sourceFile, info.node, info.suggestedSymbol, languageVersion2);
|
|
5850
5814
|
})
|
|
5851
5815
|
});
|
|
5852
5816
|
function getInfo(sourceFile, pos, context) {
|
|
5853
|
-
const node =
|
|
5817
|
+
const node = getTokenAtPosition9(sourceFile, pos);
|
|
5854
5818
|
const parent = node.parent;
|
|
5855
5819
|
const checker = context.program.getTypeChecker();
|
|
5856
5820
|
let suggestedSymbol;
|
|
5857
5821
|
if (isPropertyAccessExpression3(parent) && parent.name === node) {
|
|
5858
|
-
|
|
5822
|
+
Debug12.assert(isIdentifier7(node), "Expected an identifier for spelling (property access)");
|
|
5859
5823
|
let containingType = checker.getTypeAtLocation(parent.expression);
|
|
5860
5824
|
if (parent.flags & NodeFlags3.OptionalChain) {
|
|
5861
5825
|
containingType = checker.getNonNullableType(containingType);
|
|
5862
5826
|
}
|
|
5863
5827
|
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType);
|
|
5864
5828
|
} else if (isImportSpecifier(parent) && parent.name === node) {
|
|
5865
|
-
|
|
5866
|
-
const importDeclaration =
|
|
5829
|
+
Debug12.assertNode(node, isIdentifier7, "Expected an identifier for spelling (import)");
|
|
5830
|
+
const importDeclaration = findAncestor7(node, isImportDeclaration3);
|
|
5867
5831
|
const resolvedSourceFile = getResolvedSourceFileFromImportDeclaration(sourceFile, context, importDeclaration);
|
|
5868
5832
|
if (resolvedSourceFile && resolvedSourceFile.symbol) {
|
|
5869
5833
|
suggestedSymbol = checker.getSuggestedSymbolForNonexistentModule(node, resolvedSourceFile.symbol);
|
|
@@ -5871,7 +5835,7 @@ function getInfo(sourceFile, pos, context) {
|
|
|
5871
5835
|
} else {
|
|
5872
5836
|
const meaning = getMeaningFromLocation2(node);
|
|
5873
5837
|
const name = getTextOfNode(node);
|
|
5874
|
-
|
|
5838
|
+
Debug12.assert(name !== void 0, "name should be defined");
|
|
5875
5839
|
suggestedSymbol = checker.getSuggestedSymbolForNonexistentSymbol(node, name, convertSemanticMeaningToSymbolFlags(meaning));
|
|
5876
5840
|
}
|
|
5877
5841
|
return suggestedSymbol === void 0 ? void 0 : { node, suggestedSymbol };
|
|
@@ -5906,14 +5870,14 @@ function getResolvedSourceFileFromImportDeclaration(sourceFile, context, importD
|
|
|
5906
5870
|
|
|
5907
5871
|
// src/codefixes/returnValueCorrect.ts
|
|
5908
5872
|
import {
|
|
5909
|
-
Debug as
|
|
5910
|
-
Diagnostics as
|
|
5911
|
-
SyntaxKind as
|
|
5873
|
+
Debug as Debug13,
|
|
5874
|
+
Diagnostics as Diagnostics10,
|
|
5875
|
+
SyntaxKind as SyntaxKind13,
|
|
5912
5876
|
append as append2,
|
|
5913
5877
|
createBlock as createBlock2,
|
|
5914
5878
|
createParen as createParen3,
|
|
5915
5879
|
createReturn as createReturn2,
|
|
5916
|
-
findAncestor as
|
|
5880
|
+
findAncestor as findAncestor8,
|
|
5917
5881
|
first as first3,
|
|
5918
5882
|
isArrowFunction as isArrowFunction4,
|
|
5919
5883
|
isBlock as isBlock3,
|
|
@@ -5929,22 +5893,22 @@ import {
|
|
|
5929
5893
|
} from "@tslite/parser";
|
|
5930
5894
|
import {
|
|
5931
5895
|
copyComments,
|
|
5932
|
-
getTokenAtPosition as
|
|
5896
|
+
getTokenAtPosition as getTokenAtPosition10,
|
|
5933
5897
|
needsParentheses,
|
|
5934
5898
|
probablyUsesSemicolons as probablyUsesSemicolons2,
|
|
5935
5899
|
rangeContainsRange as rangeContainsRange3,
|
|
5936
5900
|
suppressLeadingAndTrailingTrivia
|
|
5937
5901
|
} from "@tslite/services";
|
|
5938
|
-
var
|
|
5902
|
+
var fixId8 = "returnValueCorrect";
|
|
5939
5903
|
var fixIdAddReturnStatement = "fixAddReturnStatement";
|
|
5940
5904
|
var fixIdRemoveBlockBodyBrace = "fixRemoveBlockBodyBrace";
|
|
5941
|
-
var
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5905
|
+
var errorCodes9 = [
|
|
5906
|
+
Diagnostics10.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code,
|
|
5907
|
+
Diagnostics10.Type_0_is_not_assignable_to_type_1.code,
|
|
5908
|
+
Diagnostics10.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code
|
|
5945
5909
|
];
|
|
5946
5910
|
registerCodeFix({
|
|
5947
|
-
errorCodes:
|
|
5911
|
+
errorCodes: errorCodes9,
|
|
5948
5912
|
fixIds: [fixIdAddReturnStatement, fixIdRemoveBlockBodyBrace],
|
|
5949
5913
|
getCodeActions: (context) => {
|
|
5950
5914
|
const { program, sourceFile, span: { start }, errorCode } = context;
|
|
@@ -5955,7 +5919,7 @@ registerCodeFix({
|
|
|
5955
5919
|
isArrowFunction4(info.declaration) ? getActionForfixRemoveBlockBodyBrace(context, info.declaration, info.expression, info.commentSource) : void 0
|
|
5956
5920
|
);
|
|
5957
5921
|
},
|
|
5958
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
5922
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes9, (changes, diag) => {
|
|
5959
5923
|
const info = getInfo2(context.program.getTypeChecker(), diag.file, diag.start, diag.code);
|
|
5960
5924
|
if (!info) return void 0;
|
|
5961
5925
|
switch (context.fixId) {
|
|
@@ -5975,7 +5939,7 @@ registerCodeFix({
|
|
|
5975
5939
|
);
|
|
5976
5940
|
break;
|
|
5977
5941
|
default:
|
|
5978
|
-
|
|
5942
|
+
Debug13.fail(JSON.stringify(context.fixId));
|
|
5979
5943
|
}
|
|
5980
5944
|
})
|
|
5981
5945
|
});
|
|
@@ -5997,11 +5961,11 @@ function checkFixedAssignableTo(checker, declaration, expr, type, isFunctionType
|
|
|
5997
5961
|
return checker.isTypeAssignableTo(checker.getTypeAtLocation(isFunctionType ? updateFunctionLikeBody(declaration, createBlock2([createReturn2(expr)])) : expr), type);
|
|
5998
5962
|
}
|
|
5999
5963
|
function getInfo2(checker, sourceFile, position, errorCode) {
|
|
6000
|
-
const node =
|
|
5964
|
+
const node = getTokenAtPosition10(sourceFile, position);
|
|
6001
5965
|
if (!node.parent) return void 0;
|
|
6002
|
-
const declaration =
|
|
5966
|
+
const declaration = findAncestor8(node.parent, isFunctionLikeDeclaration2);
|
|
6003
5967
|
switch (errorCode) {
|
|
6004
|
-
case
|
|
5968
|
+
case Diagnostics10.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code:
|
|
6005
5969
|
if (!declaration || !declaration.body || !declaration.type || !rangeContainsRange3(declaration.type, node)) return void 0;
|
|
6006
5970
|
return getFixInfo(
|
|
6007
5971
|
checker,
|
|
@@ -6010,7 +5974,7 @@ function getInfo2(checker, sourceFile, position, errorCode) {
|
|
|
6010
5974
|
/* isFunctionType */
|
|
6011
5975
|
false
|
|
6012
5976
|
);
|
|
6013
|
-
case
|
|
5977
|
+
case Diagnostics10.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code:
|
|
6014
5978
|
if (!declaration || !isCallExpression4(declaration.parent) || !declaration.body) return void 0;
|
|
6015
5979
|
const pos = declaration.parent.arguments.indexOf(declaration);
|
|
6016
5980
|
const type = checker.getContextualTypeForArgumentAtIndex(declaration.parent, pos);
|
|
@@ -6022,7 +5986,7 @@ function getInfo2(checker, sourceFile, position, errorCode) {
|
|
|
6022
5986
|
/* isFunctionType */
|
|
6023
5987
|
true
|
|
6024
5988
|
);
|
|
6025
|
-
case
|
|
5989
|
+
case Diagnostics10.Type_0_is_not_assignable_to_type_1.code:
|
|
6026
5990
|
if (!isDeclarationName(node) || !isVariableLike(node.parent) && !isJsxAttribute2(node.parent)) return void 0;
|
|
6027
5991
|
const initializer = getVariableLikeInitializer(node.parent);
|
|
6028
5992
|
if (!initializer || !isFunctionLikeDeclaration2(initializer) || !initializer.body) return void 0;
|
|
@@ -6038,15 +6002,15 @@ function getInfo2(checker, sourceFile, position, errorCode) {
|
|
|
6038
6002
|
}
|
|
6039
6003
|
function getVariableLikeInitializer(declaration) {
|
|
6040
6004
|
switch (declaration.kind) {
|
|
6041
|
-
case
|
|
6042
|
-
case
|
|
6043
|
-
case
|
|
6044
|
-
case
|
|
6005
|
+
case SyntaxKind13.VariableDeclaration:
|
|
6006
|
+
case SyntaxKind13.Parameter:
|
|
6007
|
+
case SyntaxKind13.BindingElement:
|
|
6008
|
+
case SyntaxKind13.PropertyAssignment:
|
|
6045
6009
|
return declaration.initializer;
|
|
6046
|
-
case
|
|
6010
|
+
case SyntaxKind13.JsxAttribute:
|
|
6047
6011
|
return declaration.initializer && (isJsxExpression(declaration.initializer) ? declaration.initializer.expression : void 0);
|
|
6048
|
-
case
|
|
6049
|
-
case
|
|
6012
|
+
case SyntaxKind13.ShorthandPropertyAssignment:
|
|
6013
|
+
case SyntaxKind13.PropertySignature:
|
|
6050
6014
|
return void 0;
|
|
6051
6015
|
}
|
|
6052
6016
|
}
|
|
@@ -6067,7 +6031,7 @@ function removeBlockBodyBrace(changes, sourceFile, declaration, expression, comm
|
|
|
6067
6031
|
}
|
|
6068
6032
|
function getActionForfixAddReturnStatement(context, expression, statement) {
|
|
6069
6033
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => addReturnStatement(t, context.sourceFile, expression, statement));
|
|
6070
|
-
return createCodeFixAction(
|
|
6034
|
+
return createCodeFixAction(fixId8, changes, Diagnostics10.Add_a_return_statement, fixIdAddReturnStatement, Diagnostics10.Add_all_missing_return_statement);
|
|
6071
6035
|
}
|
|
6072
6036
|
function getActionForfixRemoveBlockBodyBrace(context, declaration, expression, commentSource) {
|
|
6073
6037
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => removeBlockBodyBrace(
|
|
@@ -6079,12 +6043,12 @@ function getActionForfixRemoveBlockBodyBrace(context, declaration, expression, c
|
|
|
6079
6043
|
/* withParen */
|
|
6080
6044
|
false
|
|
6081
6045
|
));
|
|
6082
|
-
return createCodeFixAction(
|
|
6046
|
+
return createCodeFixAction(fixId8, changes, Diagnostics10.Remove_block_body_braces, fixIdRemoveBlockBodyBrace, Diagnostics10.Remove_all_incorrect_body_block_braces);
|
|
6083
6047
|
}
|
|
6084
6048
|
|
|
6085
6049
|
// src/codefixes/fixInvalidJsxCharacters.ts
|
|
6086
6050
|
import {
|
|
6087
|
-
Diagnostics as
|
|
6051
|
+
Diagnostics as Diagnostics11,
|
|
6088
6052
|
hasProperty
|
|
6089
6053
|
} from "@tslite/parser";
|
|
6090
6054
|
import {
|
|
@@ -6092,12 +6056,12 @@ import {
|
|
|
6092
6056
|
} from "@tslite/services";
|
|
6093
6057
|
var fixIdExpression = "fixInvalidJsxCharacters_expression";
|
|
6094
6058
|
var fixIdHtmlEntity = "fixInvalidJsxCharacters_htmlEntity";
|
|
6095
|
-
var
|
|
6096
|
-
|
|
6097
|
-
|
|
6059
|
+
var errorCodes10 = [
|
|
6060
|
+
Diagnostics11.Unexpected_token_Did_you_mean_or_gt.code,
|
|
6061
|
+
Diagnostics11.Unexpected_token_Did_you_mean_or_rbrace.code
|
|
6098
6062
|
];
|
|
6099
6063
|
registerCodeFix({
|
|
6100
|
-
errorCodes:
|
|
6064
|
+
errorCodes: errorCodes10,
|
|
6101
6065
|
fixIds: [fixIdExpression, fixIdHtmlEntity],
|
|
6102
6066
|
getCodeActions(context) {
|
|
6103
6067
|
const { sourceFile, preferences, span } = context;
|
|
@@ -6118,12 +6082,12 @@ registerCodeFix({
|
|
|
6118
6082
|
true
|
|
6119
6083
|
));
|
|
6120
6084
|
return [
|
|
6121
|
-
createCodeFixAction(fixIdExpression, changeToExpression,
|
|
6122
|
-
createCodeFixAction(fixIdHtmlEntity, changeToHtmlEntity,
|
|
6085
|
+
createCodeFixAction(fixIdExpression, changeToExpression, Diagnostics11.Wrap_invalid_character_in_an_expression_container, fixIdExpression, Diagnostics11.Wrap_all_invalid_characters_in_an_expression_container),
|
|
6086
|
+
createCodeFixAction(fixIdHtmlEntity, changeToHtmlEntity, Diagnostics11.Convert_invalid_character_to_its_html_entity_code, fixIdHtmlEntity, Diagnostics11.Convert_all_invalid_characters_to_HTML_entity_code)
|
|
6123
6087
|
];
|
|
6124
6088
|
},
|
|
6125
6089
|
getAllCodeActions(context) {
|
|
6126
|
-
return codeFixAll(context,
|
|
6090
|
+
return codeFixAll(context, errorCodes10, (changes, diagnostic) => doChange3(changes, context.preferences, diagnostic.file, diagnostic.start, context.fixId === fixIdHtmlEntity));
|
|
6127
6091
|
}
|
|
6128
6092
|
});
|
|
6129
6093
|
var htmlEntity = {
|
|
@@ -6144,12 +6108,12 @@ function doChange3(changes, preferences, sourceFile, start, useHtmlEntity) {
|
|
|
6144
6108
|
|
|
6145
6109
|
// src/codefixes/fixUnusedIdentifier.ts
|
|
6146
6110
|
import {
|
|
6147
|
-
Debug as
|
|
6148
|
-
Diagnostics as
|
|
6149
|
-
SyntaxKind as
|
|
6111
|
+
Debug as Debug14,
|
|
6112
|
+
Diagnostics as Diagnostics12,
|
|
6113
|
+
SyntaxKind as SyntaxKind14,
|
|
6150
6114
|
cast as cast3,
|
|
6151
6115
|
createIdentifier as createIdentifier5,
|
|
6152
|
-
createKeywordTypeNode
|
|
6116
|
+
createKeywordTypeNode,
|
|
6153
6117
|
isBinaryExpression as isBinaryExpression3,
|
|
6154
6118
|
isComputedPropertyName,
|
|
6155
6119
|
isDeclarationWithTypeParameterChildren,
|
|
@@ -6167,36 +6131,36 @@ import {
|
|
|
6167
6131
|
} from "@tslite/parser";
|
|
6168
6132
|
import {
|
|
6169
6133
|
FindAllReferences as FindAllReferences3,
|
|
6170
|
-
getTokenAtPosition as
|
|
6134
|
+
getTokenAtPosition as getTokenAtPosition11
|
|
6171
6135
|
} from "@tslite/services";
|
|
6172
6136
|
var fixName = "unusedIdentifier";
|
|
6173
6137
|
var fixIdPrefix = "unusedIdentifier_prefix";
|
|
6174
6138
|
var fixIdDelete = "unusedIdentifier_delete";
|
|
6175
6139
|
var fixIdInfer = "unusedIdentifier_infer";
|
|
6176
|
-
var
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6140
|
+
var errorCodes11 = [
|
|
6141
|
+
Diagnostics12._0_is_declared_but_its_value_is_never_read.code,
|
|
6142
|
+
Diagnostics12._0_is_declared_but_never_used.code,
|
|
6143
|
+
Diagnostics12.Property_0_is_declared_but_its_value_is_never_read.code,
|
|
6144
|
+
Diagnostics12.All_imports_in_import_declaration_are_unused.code,
|
|
6145
|
+
Diagnostics12.All_destructured_elements_are_unused.code,
|
|
6146
|
+
Diagnostics12.All_variables_are_unused.code,
|
|
6147
|
+
Diagnostics12.All_type_parameters_are_unused.code
|
|
6184
6148
|
];
|
|
6185
6149
|
registerCodeFix({
|
|
6186
|
-
errorCodes:
|
|
6150
|
+
errorCodes: errorCodes11,
|
|
6187
6151
|
getCodeActions(context) {
|
|
6188
6152
|
const { errorCode, sourceFile, program } = context;
|
|
6189
6153
|
const checker = program.getTypeChecker();
|
|
6190
6154
|
const sourceFiles = program.getSourceFiles();
|
|
6191
|
-
const token =
|
|
6192
|
-
if (token.kind ===
|
|
6155
|
+
const token = getTokenAtPosition11(sourceFile, context.span.start);
|
|
6156
|
+
if (token.kind === SyntaxKind14.LessThanToken) {
|
|
6193
6157
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => deleteTypeParameters(t, sourceFile, token));
|
|
6194
|
-
return [createDeleteFix(changes,
|
|
6158
|
+
return [createDeleteFix(changes, Diagnostics12.Remove_type_parameters)];
|
|
6195
6159
|
}
|
|
6196
6160
|
const importDecl = tryGetFullImport(token);
|
|
6197
6161
|
if (importDecl) {
|
|
6198
6162
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => t.delete(sourceFile, importDecl));
|
|
6199
|
-
return [createDeleteFix(changes, [
|
|
6163
|
+
return [createDeleteFix(changes, [Diagnostics12.Remove_import_from_0, showModuleSpecifier(importDecl)])];
|
|
6200
6164
|
}
|
|
6201
6165
|
const delDestructure = ts_textChanges_exports.ChangeTracker.with(context, (t) => tryDeleteFullDestructure(
|
|
6202
6166
|
token,
|
|
@@ -6208,17 +6172,17 @@ registerCodeFix({
|
|
|
6208
6172
|
false
|
|
6209
6173
|
));
|
|
6210
6174
|
if (delDestructure.length) {
|
|
6211
|
-
return [createDeleteFix(delDestructure,
|
|
6175
|
+
return [createDeleteFix(delDestructure, Diagnostics12.Remove_destructuring)];
|
|
6212
6176
|
}
|
|
6213
6177
|
const delVar = ts_textChanges_exports.ChangeTracker.with(context, (t) => tryDeleteFullVariableStatement(sourceFile, token, t));
|
|
6214
6178
|
if (delVar.length) {
|
|
6215
|
-
return [createDeleteFix(delVar,
|
|
6179
|
+
return [createDeleteFix(delVar, Diagnostics12.Remove_variable_statement)];
|
|
6216
6180
|
}
|
|
6217
6181
|
const result = [];
|
|
6218
|
-
if (token.kind ===
|
|
6182
|
+
if (token.kind === SyntaxKind14.InferKeyword) {
|
|
6219
6183
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => changeInferToUnknown(t, sourceFile, token));
|
|
6220
6184
|
const name = cast3(token.parent, isInferTypeNode).typeParameter.name.text;
|
|
6221
|
-
result.push(createCodeFixAction(fixName, changes, [
|
|
6185
|
+
result.push(createCodeFixAction(fixName, changes, [Diagnostics12.Replace_infer_0_with_unknown, name], fixIdInfer, Diagnostics12.Replace_all_unused_infer_with_unknown));
|
|
6222
6186
|
} else {
|
|
6223
6187
|
const deletion = ts_textChanges_exports.ChangeTracker.with(context, (t) => tryDeleteDeclaration(
|
|
6224
6188
|
sourceFile,
|
|
@@ -6231,12 +6195,12 @@ registerCodeFix({
|
|
|
6231
6195
|
));
|
|
6232
6196
|
if (deletion.length) {
|
|
6233
6197
|
const name = isComputedPropertyName(token.parent) ? token.parent : token;
|
|
6234
|
-
result.push(createDeleteFix(deletion, [
|
|
6198
|
+
result.push(createDeleteFix(deletion, [Diagnostics12.Remove_unused_declaration_for_Colon_0, name.getText(sourceFile)]));
|
|
6235
6199
|
}
|
|
6236
6200
|
}
|
|
6237
6201
|
const prefix = ts_textChanges_exports.ChangeTracker.with(context, (t) => tryPrefixDeclaration(t, errorCode, sourceFile, token));
|
|
6238
6202
|
if (prefix.length) {
|
|
6239
|
-
result.push(createCodeFixAction(fixName, prefix, [
|
|
6203
|
+
result.push(createCodeFixAction(fixName, prefix, [Diagnostics12.Prefix_0_with_an_underscore, token.getText(sourceFile)], fixIdPrefix, Diagnostics12.Prefix_all_unused_declarations_with_where_possible));
|
|
6240
6204
|
}
|
|
6241
6205
|
return result;
|
|
6242
6206
|
},
|
|
@@ -6245,18 +6209,18 @@ registerCodeFix({
|
|
|
6245
6209
|
const { sourceFile, program } = context;
|
|
6246
6210
|
const checker = program.getTypeChecker();
|
|
6247
6211
|
const sourceFiles = program.getSourceFiles();
|
|
6248
|
-
return codeFixAll(context,
|
|
6249
|
-
const token =
|
|
6212
|
+
return codeFixAll(context, errorCodes11, (changes, diag) => {
|
|
6213
|
+
const token = getTokenAtPosition11(sourceFile, diag.start);
|
|
6250
6214
|
switch (context.fixId) {
|
|
6251
6215
|
case fixIdPrefix:
|
|
6252
6216
|
tryPrefixDeclaration(changes, diag.code, sourceFile, token);
|
|
6253
6217
|
break;
|
|
6254
6218
|
case fixIdDelete: {
|
|
6255
|
-
if (token.kind ===
|
|
6219
|
+
if (token.kind === SyntaxKind14.InferKeyword) break;
|
|
6256
6220
|
const importDecl = tryGetFullImport(token);
|
|
6257
6221
|
if (importDecl) {
|
|
6258
6222
|
changes.delete(sourceFile, importDecl);
|
|
6259
|
-
} else if (token.kind ===
|
|
6223
|
+
} else if (token.kind === SyntaxKind14.LessThanToken) {
|
|
6260
6224
|
deleteTypeParameters(changes, sourceFile, token);
|
|
6261
6225
|
} else if (!tryDeleteFullDestructure(
|
|
6262
6226
|
token,
|
|
@@ -6280,32 +6244,32 @@ registerCodeFix({
|
|
|
6280
6244
|
break;
|
|
6281
6245
|
}
|
|
6282
6246
|
case fixIdInfer:
|
|
6283
|
-
if (token.kind ===
|
|
6247
|
+
if (token.kind === SyntaxKind14.InferKeyword) {
|
|
6284
6248
|
changeInferToUnknown(changes, sourceFile, token);
|
|
6285
6249
|
}
|
|
6286
6250
|
break;
|
|
6287
6251
|
default:
|
|
6288
|
-
|
|
6252
|
+
Debug14.fail(JSON.stringify(context.fixId));
|
|
6289
6253
|
}
|
|
6290
6254
|
});
|
|
6291
6255
|
}
|
|
6292
6256
|
});
|
|
6293
6257
|
function changeInferToUnknown(changes, sourceFile, token) {
|
|
6294
|
-
changes.replaceNode(sourceFile, token.parent,
|
|
6258
|
+
changes.replaceNode(sourceFile, token.parent, createKeywordTypeNode(SyntaxKind14.UnknownKeyword));
|
|
6295
6259
|
}
|
|
6296
6260
|
function createDeleteFix(changes, diag) {
|
|
6297
|
-
return createCodeFixAction(fixName, changes, diag, fixIdDelete,
|
|
6261
|
+
return createCodeFixAction(fixName, changes, diag, fixIdDelete, Diagnostics12.Delete_all_unused_declarations);
|
|
6298
6262
|
}
|
|
6299
6263
|
function deleteTypeParameters(changes, sourceFile, token) {
|
|
6300
|
-
changes.delete(sourceFile,
|
|
6264
|
+
changes.delete(sourceFile, Debug14.checkDefined(cast3(token.parent, isDeclarationWithTypeParameterChildren).typeParameters, "The type parameter to delete should exist"));
|
|
6301
6265
|
}
|
|
6302
6266
|
function tryGetFullImport(token) {
|
|
6303
|
-
return token.kind ===
|
|
6267
|
+
return token.kind === SyntaxKind14.ImportKeyword ? tryCast4(token.parent, isImportDeclaration4) : void 0;
|
|
6304
6268
|
}
|
|
6305
6269
|
function tryDeleteFullDestructure(token, changes, sourceFile, checker, sourceFiles, isFixAll) {
|
|
6306
|
-
if (token.kind !==
|
|
6270
|
+
if (token.kind !== SyntaxKind14.OpenBraceToken || !isObjectBindingPattern(token.parent)) return false;
|
|
6307
6271
|
const decl = token.parent.parent;
|
|
6308
|
-
if (decl.kind ===
|
|
6272
|
+
if (decl.kind === SyntaxKind14.Parameter) {
|
|
6309
6273
|
tryDeleteParameter(changes, sourceFile, decl, checker, sourceFiles, isFixAll);
|
|
6310
6274
|
} else {
|
|
6311
6275
|
changes.delete(sourceFile, decl);
|
|
@@ -6315,14 +6279,14 @@ function tryDeleteFullDestructure(token, changes, sourceFile, checker, sourceFil
|
|
|
6315
6279
|
function tryDeleteFullVariableStatement(sourceFile, token, changes) {
|
|
6316
6280
|
const declarationList = tryCast4(token.parent, isVariableDeclarationList);
|
|
6317
6281
|
if (declarationList && declarationList.getChildren(sourceFile)[0] === token) {
|
|
6318
|
-
changes.delete(sourceFile, declarationList.parent.kind ===
|
|
6282
|
+
changes.delete(sourceFile, declarationList.parent.kind === SyntaxKind14.VariableStatement ? declarationList.parent : declarationList);
|
|
6319
6283
|
return true;
|
|
6320
6284
|
}
|
|
6321
6285
|
return false;
|
|
6322
6286
|
}
|
|
6323
6287
|
function tryPrefixDeclaration(changes, errorCode, sourceFile, token) {
|
|
6324
|
-
if (errorCode ===
|
|
6325
|
-
if (token.kind ===
|
|
6288
|
+
if (errorCode === Diagnostics12.Property_0_is_declared_but_its_value_is_never_read.code) return;
|
|
6289
|
+
if (token.kind === SyntaxKind14.InferKeyword) {
|
|
6326
6290
|
token = cast3(token.parent, isInferTypeNode).typeParameter.name;
|
|
6327
6291
|
}
|
|
6328
6292
|
if (isIdentifier8(token) && canPrefix(token)) {
|
|
@@ -6331,14 +6295,14 @@ function tryPrefixDeclaration(changes, errorCode, sourceFile, token) {
|
|
|
6331
6295
|
}
|
|
6332
6296
|
function canPrefix(token) {
|
|
6333
6297
|
switch (token.parent.kind) {
|
|
6334
|
-
case
|
|
6335
|
-
case
|
|
6298
|
+
case SyntaxKind14.Parameter:
|
|
6299
|
+
case SyntaxKind14.TypeParameter:
|
|
6336
6300
|
return true;
|
|
6337
|
-
case
|
|
6301
|
+
case SyntaxKind14.VariableDeclaration: {
|
|
6338
6302
|
const varDecl = token.parent;
|
|
6339
6303
|
switch (varDecl.parent.parent.kind) {
|
|
6340
|
-
case
|
|
6341
|
-
case
|
|
6304
|
+
case SyntaxKind14.ForOfStatement:
|
|
6305
|
+
case SyntaxKind14.ForInStatement:
|
|
6342
6306
|
return true;
|
|
6343
6307
|
}
|
|
6344
6308
|
}
|
|
@@ -6380,14 +6344,14 @@ function tryDeleteParameter(changes, sourceFile, p, checker, sourceFiles, isFixA
|
|
|
6380
6344
|
function mayDeleteParameter(p, isFixAll) {
|
|
6381
6345
|
const { parent } = p;
|
|
6382
6346
|
switch (parent.kind) {
|
|
6383
|
-
case
|
|
6347
|
+
case SyntaxKind14.ArrowFunction: {
|
|
6384
6348
|
const { parameters } = parent;
|
|
6385
6349
|
const index = parameters.indexOf(p);
|
|
6386
|
-
|
|
6387
|
-
return isFixAll ? parameters.slice(index + 1).every((p2) => p2.name.kind ===
|
|
6350
|
+
Debug14.assert(index !== -1, "The parameter should already be in the list");
|
|
6351
|
+
return isFixAll ? parameters.slice(index + 1).every((p2) => p2.name.kind === SyntaxKind14.Identifier && !p2.symbol.isReferenced) : index === parameters.length - 1;
|
|
6388
6352
|
}
|
|
6389
6353
|
default:
|
|
6390
|
-
return
|
|
6354
|
+
return Debug14.failBadSyntaxKind(parent);
|
|
6391
6355
|
}
|
|
6392
6356
|
}
|
|
6393
6357
|
function deleteUnusedArguments(changes, sourceFile, deletedParameter, sourceFiles, checker) {
|
|
@@ -6401,48 +6365,48 @@ function deleteUnusedArguments(changes, sourceFile, deletedParameter, sourceFile
|
|
|
6401
6365
|
|
|
6402
6366
|
// src/codefixes/fixUnreachableCode.ts
|
|
6403
6367
|
import {
|
|
6404
|
-
Debug as
|
|
6405
|
-
Diagnostics as
|
|
6406
|
-
SyntaxKind as
|
|
6368
|
+
Debug as Debug15,
|
|
6369
|
+
Diagnostics as Diagnostics13,
|
|
6370
|
+
SyntaxKind as SyntaxKind15,
|
|
6407
6371
|
createBlock as createBlock3,
|
|
6408
6372
|
emptyArray as emptyArray5,
|
|
6409
|
-
findAncestor as
|
|
6373
|
+
findAncestor as findAncestor9,
|
|
6410
6374
|
first as first4,
|
|
6411
6375
|
isBlock as isBlock4,
|
|
6412
6376
|
isStatement as isStatement2,
|
|
6413
6377
|
sliceAfter
|
|
6414
6378
|
} from "@tslite/parser";
|
|
6415
6379
|
import {
|
|
6416
|
-
getTokenAtPosition as
|
|
6380
|
+
getTokenAtPosition as getTokenAtPosition12
|
|
6417
6381
|
} from "@tslite/services";
|
|
6418
|
-
var
|
|
6419
|
-
var
|
|
6382
|
+
var fixId9 = "fixUnreachableCode";
|
|
6383
|
+
var errorCodes12 = [Diagnostics13.Unreachable_code_detected.code];
|
|
6420
6384
|
registerCodeFix({
|
|
6421
|
-
errorCodes:
|
|
6385
|
+
errorCodes: errorCodes12,
|
|
6422
6386
|
getCodeActions(context) {
|
|
6423
6387
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(t, context.sourceFile, context.span.start, context.span.length, context.errorCode));
|
|
6424
|
-
return [createCodeFixAction(
|
|
6388
|
+
return [createCodeFixAction(fixId9, changes, Diagnostics13.Remove_unreachable_code, fixId9, Diagnostics13.Remove_all_unreachable_code)];
|
|
6425
6389
|
},
|
|
6426
|
-
fixIds: [
|
|
6427
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
6390
|
+
fixIds: [fixId9],
|
|
6391
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes12, (changes, diag) => doChange4(changes, diag.file, diag.start, diag.length, diag.code))
|
|
6428
6392
|
});
|
|
6429
6393
|
function doChange4(changes, sourceFile, start, length3, errorCode) {
|
|
6430
|
-
const token =
|
|
6431
|
-
const statement =
|
|
6394
|
+
const token = getTokenAtPosition12(sourceFile, start);
|
|
6395
|
+
const statement = findAncestor9(token, isStatement2);
|
|
6432
6396
|
if (statement.getStart(sourceFile) !== token.getStart(sourceFile)) {
|
|
6433
6397
|
const logData = JSON.stringify({
|
|
6434
|
-
statementKind:
|
|
6435
|
-
tokenKind:
|
|
6398
|
+
statementKind: Debug15.formatSyntaxKind(statement.kind),
|
|
6399
|
+
tokenKind: Debug15.formatSyntaxKind(token.kind),
|
|
6436
6400
|
errorCode,
|
|
6437
6401
|
start,
|
|
6438
6402
|
length: length3
|
|
6439
6403
|
});
|
|
6440
|
-
|
|
6404
|
+
Debug15.fail("Token and statement should start at the same point. " + logData);
|
|
6441
6405
|
}
|
|
6442
6406
|
const container = (isBlock4(statement.parent) ? statement.parent : statement).parent;
|
|
6443
6407
|
if (!isBlock4(statement.parent) || statement === first4(statement.parent.statements)) {
|
|
6444
6408
|
switch (container.kind) {
|
|
6445
|
-
case
|
|
6409
|
+
case SyntaxKind15.IfStatement:
|
|
6446
6410
|
if (container.elseStatement) {
|
|
6447
6411
|
if (isBlock4(statement.parent)) {
|
|
6448
6412
|
break;
|
|
@@ -6452,15 +6416,15 @@ function doChange4(changes, sourceFile, start, length3, errorCode) {
|
|
|
6452
6416
|
return;
|
|
6453
6417
|
}
|
|
6454
6418
|
// falls through
|
|
6455
|
-
case
|
|
6456
|
-
case
|
|
6419
|
+
case SyntaxKind15.WhileStatement:
|
|
6420
|
+
case SyntaxKind15.ForStatement:
|
|
6457
6421
|
changes.delete(sourceFile, container);
|
|
6458
6422
|
return;
|
|
6459
6423
|
}
|
|
6460
6424
|
}
|
|
6461
6425
|
if (isBlock4(statement.parent)) {
|
|
6462
6426
|
const end = start + length3;
|
|
6463
|
-
const lastStatement =
|
|
6427
|
+
const lastStatement = Debug15.checkDefined(lastWhere(sliceAfter(statement.parent.statements, statement), (s) => s.pos < end), "Some statement should be last");
|
|
6464
6428
|
changes.deleteNodeRange(sourceFile, statement, lastStatement);
|
|
6465
6429
|
} else {
|
|
6466
6430
|
changes.delete(sourceFile, statement);
|
|
@@ -6477,28 +6441,28 @@ function lastWhere(a, pred) {
|
|
|
6477
6441
|
|
|
6478
6442
|
// src/codefixes/fixMissingCallParentheses.ts
|
|
6479
6443
|
import {
|
|
6480
|
-
Diagnostics as
|
|
6444
|
+
Diagnostics as Diagnostics14,
|
|
6481
6445
|
isIdentifier as isIdentifier9,
|
|
6482
6446
|
isPropertyAccessExpression as isPropertyAccessExpression5
|
|
6483
6447
|
} from "@tslite/parser";
|
|
6484
6448
|
import {
|
|
6485
|
-
getTokenAtPosition as
|
|
6449
|
+
getTokenAtPosition as getTokenAtPosition13
|
|
6486
6450
|
} from "@tslite/services";
|
|
6487
|
-
var
|
|
6488
|
-
var
|
|
6489
|
-
|
|
6451
|
+
var fixId10 = "fixMissingCallParentheses";
|
|
6452
|
+
var errorCodes13 = [
|
|
6453
|
+
Diagnostics14.This_condition_will_always_return_true_since_the_function_is_always_defined_Did_you_mean_to_call_it_instead.code
|
|
6490
6454
|
];
|
|
6491
6455
|
registerCodeFix({
|
|
6492
|
-
errorCodes:
|
|
6493
|
-
fixIds: [
|
|
6456
|
+
errorCodes: errorCodes13,
|
|
6457
|
+
fixIds: [fixId10],
|
|
6494
6458
|
getCodeActions(context) {
|
|
6495
6459
|
const { sourceFile, span } = context;
|
|
6496
6460
|
const callName = getCallName(sourceFile, span.start);
|
|
6497
6461
|
if (!callName) return;
|
|
6498
6462
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange5(t, context.sourceFile, callName));
|
|
6499
|
-
return [createCodeFixAction(
|
|
6463
|
+
return [createCodeFixAction(fixId10, changes, Diagnostics14.Add_missing_call_parentheses, fixId10, Diagnostics14.Add_all_missing_call_parentheses)];
|
|
6500
6464
|
},
|
|
6501
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
6465
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes13, (changes, diag) => {
|
|
6502
6466
|
const callName = getCallName(diag.file, diag.start);
|
|
6503
6467
|
if (callName) doChange5(changes, diag.file, callName);
|
|
6504
6468
|
})
|
|
@@ -6507,7 +6471,7 @@ function doChange5(changes, sourceFile, name) {
|
|
|
6507
6471
|
changes.replaceNodeWithText(sourceFile, name, `${name.text}()`);
|
|
6508
6472
|
}
|
|
6509
6473
|
function getCallName(sourceFile, start) {
|
|
6510
|
-
const token =
|
|
6474
|
+
const token = getTokenAtPosition13(sourceFile, start);
|
|
6511
6475
|
if (isPropertyAccessExpression5(token.parent)) {
|
|
6512
6476
|
let current = token.parent;
|
|
6513
6477
|
while (isPropertyAccessExpression5(current.parent)) {
|
|
@@ -6523,8 +6487,8 @@ function getCallName(sourceFile, start) {
|
|
|
6523
6487
|
|
|
6524
6488
|
// src/codefixes/fixAwaitInSyncFunction.ts
|
|
6525
6489
|
import {
|
|
6526
|
-
Diagnostics as
|
|
6527
|
-
SyntaxKind as
|
|
6490
|
+
Diagnostics as Diagnostics15,
|
|
6491
|
+
SyntaxKind as SyntaxKind16,
|
|
6528
6492
|
addToSeen as addToSeen3,
|
|
6529
6493
|
createMap as createMap7,
|
|
6530
6494
|
createNodeArray as createNodeArray3,
|
|
@@ -6538,26 +6502,26 @@ import {
|
|
|
6538
6502
|
} from "@tslite/parser";
|
|
6539
6503
|
import {
|
|
6540
6504
|
findChildOfKind as findChildOfKind4,
|
|
6541
|
-
getTokenAtPosition as
|
|
6505
|
+
getTokenAtPosition as getTokenAtPosition14
|
|
6542
6506
|
} from "@tslite/services";
|
|
6543
|
-
var
|
|
6544
|
-
var
|
|
6545
|
-
|
|
6546
|
-
|
|
6507
|
+
var fixId11 = "fixAwaitInSyncFunction";
|
|
6508
|
+
var errorCodes14 = [
|
|
6509
|
+
Diagnostics15.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
|
6510
|
+
Diagnostics15.A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator.code
|
|
6547
6511
|
];
|
|
6548
6512
|
registerCodeFix({
|
|
6549
|
-
errorCodes:
|
|
6513
|
+
errorCodes: errorCodes14,
|
|
6550
6514
|
getCodeActions(context) {
|
|
6551
6515
|
const { sourceFile, span } = context;
|
|
6552
6516
|
const nodes = getNodes(sourceFile, span.start);
|
|
6553
6517
|
if (!nodes) return void 0;
|
|
6554
6518
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange6(t, sourceFile, nodes));
|
|
6555
|
-
return [createCodeFixAction(
|
|
6519
|
+
return [createCodeFixAction(fixId11, changes, Diagnostics15.Add_async_modifier_to_containing_function, fixId11, Diagnostics15.Add_all_missing_async_modifiers)];
|
|
6556
6520
|
},
|
|
6557
|
-
fixIds: [
|
|
6521
|
+
fixIds: [fixId11],
|
|
6558
6522
|
getAllCodeActions: (context) => {
|
|
6559
6523
|
const seen = createMap7();
|
|
6560
|
-
return codeFixAll(context,
|
|
6524
|
+
return codeFixAll(context, errorCodes14, (changes, diag) => {
|
|
6561
6525
|
const nodes = getNodes(diag.file, diag.start);
|
|
6562
6526
|
if (!nodes || !addToSeen3(seen, getNodeId5(nodes.insertBefore))) return;
|
|
6563
6527
|
doChange6(changes, context.sourceFile, nodes);
|
|
@@ -6573,15 +6537,15 @@ function getReturnType(expr) {
|
|
|
6573
6537
|
}
|
|
6574
6538
|
}
|
|
6575
6539
|
function getNodes(sourceFile, start) {
|
|
6576
|
-
const token =
|
|
6540
|
+
const token = getTokenAtPosition14(sourceFile, start);
|
|
6577
6541
|
const containingFunction = getContainingFunction2(token);
|
|
6578
6542
|
if (!containingFunction) {
|
|
6579
6543
|
return;
|
|
6580
6544
|
}
|
|
6581
6545
|
let insertBefore;
|
|
6582
6546
|
switch (containingFunction.kind) {
|
|
6583
|
-
case
|
|
6584
|
-
insertBefore = findChildOfKind4(containingFunction,
|
|
6547
|
+
case SyntaxKind16.ArrowFunction:
|
|
6548
|
+
insertBefore = findChildOfKind4(containingFunction, SyntaxKind16.OpenParenToken, sourceFile) || first5(containingFunction.parameters);
|
|
6585
6549
|
break;
|
|
6586
6550
|
default:
|
|
6587
6551
|
return;
|
|
@@ -6594,21 +6558,22 @@ function getNodes(sourceFile, start) {
|
|
|
6594
6558
|
function doChange6(changes, sourceFile, { insertBefore, returnType }) {
|
|
6595
6559
|
if (returnType) {
|
|
6596
6560
|
const entityName = getEntityNameFromTypeNode(returnType);
|
|
6597
|
-
if (!entityName || entityName.kind !==
|
|
6561
|
+
if (!entityName || entityName.kind !== SyntaxKind16.Identifier || entityName.text !== "Promise") {
|
|
6598
6562
|
changes.replaceNode(sourceFile, returnType, createTypeReferenceNode3("Promise", createNodeArray3([returnType])));
|
|
6599
6563
|
}
|
|
6600
6564
|
}
|
|
6601
|
-
changes.insertModifierBefore(sourceFile,
|
|
6565
|
+
changes.insertModifierBefore(sourceFile, SyntaxKind16.AsyncKeyword, insertBefore);
|
|
6602
6566
|
}
|
|
6603
6567
|
|
|
6604
6568
|
// src/codefixes/inferFromUsage.ts
|
|
6605
6569
|
import {
|
|
6606
|
-
Debug as
|
|
6607
|
-
Diagnostics as
|
|
6570
|
+
Debug as Debug16,
|
|
6571
|
+
Diagnostics as Diagnostics16,
|
|
6608
6572
|
ScriptTarget as ScriptTarget5,
|
|
6609
6573
|
SymbolFlags as SymbolFlags3,
|
|
6610
|
-
SyntaxKind as
|
|
6574
|
+
SyntaxKind as SyntaxKind17,
|
|
6611
6575
|
cast as cast4,
|
|
6576
|
+
createKeywordTypeNode as createKeywordTypeNode2,
|
|
6612
6577
|
createMultiMap as createMultiMap4,
|
|
6613
6578
|
createSymbolTable,
|
|
6614
6579
|
createToken as createToken2,
|
|
@@ -6633,9 +6598,11 @@ import {
|
|
|
6633
6598
|
last as last4,
|
|
6634
6599
|
mapDefined as mapDefined3,
|
|
6635
6600
|
mapEntries,
|
|
6601
|
+
nullTransformationContext as nullTransformationContext2,
|
|
6636
6602
|
returnTrue,
|
|
6637
6603
|
singleOrUndefined,
|
|
6638
|
-
tryCast as tryCast5
|
|
6604
|
+
tryCast as tryCast5,
|
|
6605
|
+
visitEachChild as visitEachChild2
|
|
6639
6606
|
} from "@tslite/parser";
|
|
6640
6607
|
import {
|
|
6641
6608
|
ObjectFlags,
|
|
@@ -6647,28 +6614,28 @@ import {
|
|
|
6647
6614
|
import {
|
|
6648
6615
|
FindAllReferences as FindAllReferences4,
|
|
6649
6616
|
findChildOfKind as findChildOfKind5,
|
|
6650
|
-
getTokenAtPosition as
|
|
6617
|
+
getTokenAtPosition as getTokenAtPosition15,
|
|
6651
6618
|
getTypeNodeIfAccessible,
|
|
6652
6619
|
nodeSeenTracker
|
|
6653
6620
|
} from "@tslite/services";
|
|
6654
|
-
var
|
|
6655
|
-
var
|
|
6621
|
+
var fixId12 = "inferFromUsage";
|
|
6622
|
+
var errorCodes15 = [
|
|
6656
6623
|
// Variable declarations
|
|
6657
|
-
|
|
6624
|
+
Diagnostics16.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined.code,
|
|
6658
6625
|
// Variable uses
|
|
6659
|
-
|
|
6626
|
+
Diagnostics16.Variable_0_implicitly_has_an_1_type.code,
|
|
6660
6627
|
// Parameter declarations
|
|
6661
|
-
|
|
6662
|
-
|
|
6628
|
+
Diagnostics16.Parameter_0_implicitly_has_an_1_type.code,
|
|
6629
|
+
Diagnostics16.Rest_parameter_0_implicitly_has_an_any_type.code,
|
|
6663
6630
|
// Property declarations
|
|
6664
|
-
|
|
6631
|
+
Diagnostics16.Member_0_implicitly_has_an_1_type.code
|
|
6665
6632
|
];
|
|
6666
6633
|
var languageVersion3 = ScriptTarget5.ES2020;
|
|
6667
6634
|
registerCodeFix({
|
|
6668
|
-
errorCodes:
|
|
6635
|
+
errorCodes: errorCodes15,
|
|
6669
6636
|
getCodeActions(context) {
|
|
6670
6637
|
const { sourceFile, program, span: { start }, errorCode, cancellationToken, host, preferences } = context;
|
|
6671
|
-
const token =
|
|
6638
|
+
const token = getTokenAtPosition15(sourceFile, start);
|
|
6672
6639
|
let declaration;
|
|
6673
6640
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (changes2) => {
|
|
6674
6641
|
declaration = doChange7(
|
|
@@ -6685,44 +6652,44 @@ registerCodeFix({
|
|
|
6685
6652
|
);
|
|
6686
6653
|
});
|
|
6687
6654
|
const name = declaration && getNameOfDeclaration(declaration);
|
|
6688
|
-
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(
|
|
6655
|
+
return !name || changes.length === 0 ? void 0 : [createCodeFixAction(fixId12, changes, [getDiagnostic(errorCode), name.getText(sourceFile)], fixId12, Diagnostics16.Infer_all_types_from_usage)];
|
|
6689
6656
|
},
|
|
6690
|
-
fixIds: [
|
|
6657
|
+
fixIds: [fixId12],
|
|
6691
6658
|
getAllCodeActions(context) {
|
|
6692
6659
|
const { sourceFile, program, cancellationToken, host, preferences } = context;
|
|
6693
6660
|
const markSeen = nodeSeenTracker();
|
|
6694
|
-
return codeFixAll(context,
|
|
6695
|
-
doChange7(changes, sourceFile,
|
|
6661
|
+
return codeFixAll(context, errorCodes15, (changes, err) => {
|
|
6662
|
+
doChange7(changes, sourceFile, getTokenAtPosition15(err.file, err.start), err.code, program, cancellationToken, markSeen, host, preferences);
|
|
6696
6663
|
});
|
|
6697
6664
|
}
|
|
6698
6665
|
});
|
|
6699
6666
|
function getDiagnostic(errorCode) {
|
|
6700
6667
|
switch (errorCode) {
|
|
6701
|
-
case
|
|
6702
|
-
return
|
|
6703
|
-
case
|
|
6704
|
-
return
|
|
6668
|
+
case Diagnostics16.Parameter_0_implicitly_has_an_1_type.code:
|
|
6669
|
+
return Diagnostics16.Infer_parameter_types_from_usage;
|
|
6670
|
+
case Diagnostics16.Rest_parameter_0_implicitly_has_an_any_type.code:
|
|
6671
|
+
return Diagnostics16.Infer_parameter_types_from_usage;
|
|
6705
6672
|
default:
|
|
6706
|
-
return
|
|
6673
|
+
return Diagnostics16.Infer_type_of_0_from_usage;
|
|
6707
6674
|
}
|
|
6708
6675
|
}
|
|
6709
6676
|
function doChange7(changes, sourceFile, token, errorCode, program, cancellationToken, markSeen, host, preferences) {
|
|
6710
|
-
if (token.kind !==
|
|
6677
|
+
if (token.kind !== SyntaxKind17.Identifier && token.kind !== SyntaxKind17.DotDotDotToken) {
|
|
6711
6678
|
return void 0;
|
|
6712
6679
|
}
|
|
6713
6680
|
const { parent } = token;
|
|
6714
6681
|
const importAdder = createImportAdder(sourceFile, program, preferences, host);
|
|
6715
6682
|
switch (errorCode) {
|
|
6716
6683
|
// Variable and Property declarations
|
|
6717
|
-
case
|
|
6718
|
-
case
|
|
6684
|
+
case Diagnostics16.Member_0_implicitly_has_an_1_type.code:
|
|
6685
|
+
case Diagnostics16.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined.code:
|
|
6719
6686
|
if (isVariableDeclaration5(parent) && markSeen(parent) || isPropertySignature3(parent)) {
|
|
6720
6687
|
annotateVariableDeclaration(changes, importAdder, sourceFile, parent, program, host, cancellationToken);
|
|
6721
6688
|
importAdder.writeFixes(changes);
|
|
6722
6689
|
return parent;
|
|
6723
6690
|
}
|
|
6724
6691
|
return void 0;
|
|
6725
|
-
case
|
|
6692
|
+
case Diagnostics16.Variable_0_implicitly_has_an_1_type.code: {
|
|
6726
6693
|
const symbol = program.getTypeChecker().getSymbolAtLocation(token);
|
|
6727
6694
|
if (symbol && symbol.valueDeclaration && isVariableDeclaration5(symbol.valueDeclaration) && markSeen(symbol.valueDeclaration)) {
|
|
6728
6695
|
annotateVariableDeclaration(changes, importAdder, sourceFile, symbol.valueDeclaration, program, host, cancellationToken);
|
|
@@ -6740,8 +6707,8 @@ function doChange7(changes, sourceFile, token, errorCode, program, cancellationT
|
|
|
6740
6707
|
switch (errorCode) {
|
|
6741
6708
|
// Parameter declarations
|
|
6742
6709
|
// Na tag, o parâmetro de um setter anotava o setter (CK-02).
|
|
6743
|
-
case
|
|
6744
|
-
case
|
|
6710
|
+
case Diagnostics16.Parameter_0_implicitly_has_an_1_type.code:
|
|
6711
|
+
case Diagnostics16.Rest_parameter_0_implicitly_has_an_any_type.code:
|
|
6745
6712
|
if (markSeen(containingFunction)) {
|
|
6746
6713
|
const param = cast4(parent, isParameter5);
|
|
6747
6714
|
annotateParameters(changes, importAdder, sourceFile, param, containingFunction, program, host, cancellationToken);
|
|
@@ -6750,7 +6717,7 @@ function doChange7(changes, sourceFile, token, errorCode, program, cancellationT
|
|
|
6750
6717
|
break;
|
|
6751
6718
|
// Na tag, também o retorno de um getter, o parâmetro de um setter e o `this` de uma função (CK-02).
|
|
6752
6719
|
default:
|
|
6753
|
-
return
|
|
6720
|
+
return Debug16.fail(String(errorCode));
|
|
6754
6721
|
}
|
|
6755
6722
|
importAdder.writeFixes(changes);
|
|
6756
6723
|
return declaration;
|
|
@@ -6765,24 +6732,29 @@ function annotateParameters(changes, importAdder, sourceFile, parameterDeclarati
|
|
|
6765
6732
|
return;
|
|
6766
6733
|
}
|
|
6767
6734
|
const parameterInferences = inferTypeForParametersFromUsage(containingFunction, program, cancellationToken);
|
|
6768
|
-
|
|
6769
|
-
const needParens = isArrowFunction5(containingFunction) && !findChildOfKind5(containingFunction,
|
|
6770
|
-
if (needParens) changes.insertNodeBefore(sourceFile, first6(containingFunction.parameters), createToken2(
|
|
6735
|
+
Debug16.assert(containingFunction.parameters.length === parameterInferences.length, "Parameter count and inference count should match");
|
|
6736
|
+
const needParens = isArrowFunction5(containingFunction) && !findChildOfKind5(containingFunction, SyntaxKind17.OpenParenToken, sourceFile);
|
|
6737
|
+
if (needParens) changes.insertNodeBefore(sourceFile, first6(containingFunction.parameters), createToken2(SyntaxKind17.OpenParenToken));
|
|
6771
6738
|
for (const { declaration, type } of parameterInferences) {
|
|
6772
6739
|
if (declaration && !declaration.type && !declaration.initializer) {
|
|
6773
6740
|
annotate(changes, importAdder, sourceFile, declaration, type, program, host);
|
|
6774
6741
|
}
|
|
6775
6742
|
}
|
|
6776
|
-
if (needParens) changes.insertNodeAfter(sourceFile, last4(containingFunction.parameters), createToken2(
|
|
6743
|
+
if (needParens) changes.insertNodeAfter(sourceFile, last4(containingFunction.parameters), createToken2(SyntaxKind17.CloseParenToken));
|
|
6777
6744
|
}
|
|
6778
6745
|
function annotate(changes, importAdder, sourceFile, declaration, type, program, host) {
|
|
6779
|
-
const
|
|
6746
|
+
const inferred = getTypeNodeIfAccessible(type, declaration, program, host);
|
|
6747
|
+
const typeNode = inferred && withoutAny(inferred);
|
|
6780
6748
|
if (typeNode) {
|
|
6781
6749
|
if (!tryReplaceImportTypeNodeWithAutoImport(typeNode, declaration, type, sourceFile, changes, importAdder, languageVersion3)) {
|
|
6782
6750
|
changes.tryInsertTypeAnnotation(sourceFile, declaration, typeNode);
|
|
6783
6751
|
}
|
|
6784
6752
|
}
|
|
6785
6753
|
}
|
|
6754
|
+
function withoutAny(node) {
|
|
6755
|
+
const visit = (n) => n.kind === SyntaxKind17.AnyKeyword ? createKeywordTypeNode2(SyntaxKind17.UnknownKeyword) : visitEachChild2(n, visit, nullTransformationContext2);
|
|
6756
|
+
return visit(node);
|
|
6757
|
+
}
|
|
6786
6758
|
function tryReplaceImportTypeNodeWithAutoImport(typeNode, declaration, type, sourceFile, changes, importAdder, scriptTarget) {
|
|
6787
6759
|
const importableReference = tryGetAutoImportableReferenceFromImportTypeNode(typeNode, type, scriptTarget);
|
|
6788
6760
|
if (importableReference && changes.tryInsertTypeAnnotation(sourceFile, declaration, importableReference.typeReference)) {
|
|
@@ -6812,7 +6784,7 @@ function inferTypeForParametersFromUsage(func, program, cancellationToken) {
|
|
|
6812
6784
|
function getFunctionReferences(containingFunction, program, cancellationToken) {
|
|
6813
6785
|
let searchToken;
|
|
6814
6786
|
switch (containingFunction.kind) {
|
|
6815
|
-
case
|
|
6787
|
+
case SyntaxKind17.ArrowFunction:
|
|
6816
6788
|
const parent = containingFunction.parent;
|
|
6817
6789
|
searchToken = isVariableDeclaration5(parent) && isIdentifier10(parent.name) ? parent.name : containingFunction.name;
|
|
6818
6790
|
break;
|
|
@@ -6933,41 +6905,41 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
6933
6905
|
node = node.parent;
|
|
6934
6906
|
}
|
|
6935
6907
|
switch (node.parent.kind) {
|
|
6936
|
-
case
|
|
6908
|
+
case SyntaxKind17.ExpressionStatement:
|
|
6937
6909
|
inferTypeFromExpressionStatement(node, usage);
|
|
6938
6910
|
break;
|
|
6939
|
-
case
|
|
6911
|
+
case SyntaxKind17.PostfixUnaryExpression:
|
|
6940
6912
|
usage.isNumber = true;
|
|
6941
6913
|
break;
|
|
6942
|
-
case
|
|
6914
|
+
case SyntaxKind17.PrefixUnaryExpression:
|
|
6943
6915
|
inferTypeFromPrefixUnaryExpression(node.parent, usage);
|
|
6944
6916
|
break;
|
|
6945
|
-
case
|
|
6917
|
+
case SyntaxKind17.BinaryExpression:
|
|
6946
6918
|
inferTypeFromBinaryExpression(node, node.parent, usage);
|
|
6947
6919
|
break;
|
|
6948
|
-
case
|
|
6949
|
-
case
|
|
6920
|
+
case SyntaxKind17.CaseClause:
|
|
6921
|
+
case SyntaxKind17.DefaultClause:
|
|
6950
6922
|
inferTypeFromSwitchStatementLabel(node.parent, usage);
|
|
6951
6923
|
break;
|
|
6952
6924
|
// Na tag, também a chamada com `new` (CK-02).
|
|
6953
|
-
case
|
|
6925
|
+
case SyntaxKind17.CallExpression:
|
|
6954
6926
|
if (node.parent.expression === node) {
|
|
6955
6927
|
inferTypeFromCallExpression(node.parent, usage);
|
|
6956
6928
|
} else {
|
|
6957
6929
|
inferTypeFromContextualType(node, usage);
|
|
6958
6930
|
}
|
|
6959
6931
|
break;
|
|
6960
|
-
case
|
|
6932
|
+
case SyntaxKind17.PropertyAccessExpression:
|
|
6961
6933
|
inferTypeFromPropertyAccessExpression(node.parent, usage);
|
|
6962
6934
|
break;
|
|
6963
|
-
case
|
|
6935
|
+
case SyntaxKind17.ElementAccessExpression:
|
|
6964
6936
|
inferTypeFromPropertyElementExpression(node.parent, node, usage);
|
|
6965
6937
|
break;
|
|
6966
|
-
case
|
|
6967
|
-
case
|
|
6938
|
+
case SyntaxKind17.PropertyAssignment:
|
|
6939
|
+
case SyntaxKind17.ShorthandPropertyAssignment:
|
|
6968
6940
|
break;
|
|
6969
6941
|
// Na tag, também a propriedade de classe, que dava o tipo do `this` (CK-02).
|
|
6970
|
-
case
|
|
6942
|
+
case SyntaxKind17.VariableDeclaration: {
|
|
6971
6943
|
const { name, initializer } = node.parent;
|
|
6972
6944
|
if (node === name) {
|
|
6973
6945
|
if (initializer) {
|
|
@@ -6991,13 +6963,13 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
6991
6963
|
}
|
|
6992
6964
|
function inferTypeFromPrefixUnaryExpression(node, usage) {
|
|
6993
6965
|
switch (node.operator) {
|
|
6994
|
-
case
|
|
6995
|
-
case
|
|
6996
|
-
case
|
|
6997
|
-
case
|
|
6966
|
+
case SyntaxKind17.PlusPlusToken:
|
|
6967
|
+
case SyntaxKind17.MinusMinusToken:
|
|
6968
|
+
case SyntaxKind17.MinusToken:
|
|
6969
|
+
case SyntaxKind17.TildeToken:
|
|
6998
6970
|
usage.isNumber = true;
|
|
6999
6971
|
break;
|
|
7000
|
-
case
|
|
6972
|
+
case SyntaxKind17.PlusToken:
|
|
7001
6973
|
usage.isNumberOrString = true;
|
|
7002
6974
|
break;
|
|
7003
6975
|
}
|
|
@@ -7005,48 +6977,48 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7005
6977
|
function inferTypeFromBinaryExpression(node, parent, usage) {
|
|
7006
6978
|
switch (parent.operatorToken.kind) {
|
|
7007
6979
|
// ExponentiationOperator
|
|
7008
|
-
case
|
|
6980
|
+
case SyntaxKind17.AsteriskAsteriskToken:
|
|
7009
6981
|
// MultiplicativeOperator
|
|
7010
6982
|
// falls through
|
|
7011
|
-
case
|
|
7012
|
-
case
|
|
7013
|
-
case
|
|
6983
|
+
case SyntaxKind17.AsteriskToken:
|
|
6984
|
+
case SyntaxKind17.SlashToken:
|
|
6985
|
+
case SyntaxKind17.PercentToken:
|
|
7014
6986
|
// ShiftOperator
|
|
7015
6987
|
// falls through
|
|
7016
|
-
case
|
|
7017
|
-
case
|
|
7018
|
-
case
|
|
6988
|
+
case SyntaxKind17.LessThanLessThanToken:
|
|
6989
|
+
case SyntaxKind17.GreaterThanGreaterThanToken:
|
|
6990
|
+
case SyntaxKind17.GreaterThanGreaterThanGreaterThanToken:
|
|
7019
6991
|
// BitwiseOperator
|
|
7020
6992
|
// falls through
|
|
7021
|
-
case
|
|
7022
|
-
case
|
|
7023
|
-
case
|
|
6993
|
+
case SyntaxKind17.AmpersandToken:
|
|
6994
|
+
case SyntaxKind17.BarToken:
|
|
6995
|
+
case SyntaxKind17.CaretToken:
|
|
7024
6996
|
// CompoundAssignmentOperator
|
|
7025
6997
|
// falls through
|
|
7026
|
-
case
|
|
7027
|
-
case
|
|
7028
|
-
case
|
|
7029
|
-
case
|
|
7030
|
-
case
|
|
7031
|
-
case
|
|
7032
|
-
case
|
|
7033
|
-
case
|
|
7034
|
-
case
|
|
7035
|
-
case
|
|
7036
|
-
case
|
|
6998
|
+
case SyntaxKind17.MinusEqualsToken:
|
|
6999
|
+
case SyntaxKind17.AsteriskAsteriskEqualsToken:
|
|
7000
|
+
case SyntaxKind17.AsteriskEqualsToken:
|
|
7001
|
+
case SyntaxKind17.SlashEqualsToken:
|
|
7002
|
+
case SyntaxKind17.PercentEqualsToken:
|
|
7003
|
+
case SyntaxKind17.AmpersandEqualsToken:
|
|
7004
|
+
case SyntaxKind17.BarEqualsToken:
|
|
7005
|
+
case SyntaxKind17.CaretEqualsToken:
|
|
7006
|
+
case SyntaxKind17.LessThanLessThanEqualsToken:
|
|
7007
|
+
case SyntaxKind17.GreaterThanGreaterThanGreaterThanEqualsToken:
|
|
7008
|
+
case SyntaxKind17.GreaterThanGreaterThanEqualsToken:
|
|
7037
7009
|
// AdditiveOperator
|
|
7038
7010
|
// falls through
|
|
7039
|
-
case
|
|
7011
|
+
case SyntaxKind17.MinusToken:
|
|
7040
7012
|
// RelationalOperator
|
|
7041
7013
|
// falls through
|
|
7042
|
-
case
|
|
7043
|
-
case
|
|
7044
|
-
case
|
|
7045
|
-
case
|
|
7014
|
+
case SyntaxKind17.LessThanToken:
|
|
7015
|
+
case SyntaxKind17.LessThanEqualsToken:
|
|
7016
|
+
case SyntaxKind17.GreaterThanToken:
|
|
7017
|
+
case SyntaxKind17.GreaterThanEqualsToken:
|
|
7046
7018
|
usage.isNumber = true;
|
|
7047
7019
|
break;
|
|
7048
|
-
case
|
|
7049
|
-
case
|
|
7020
|
+
case SyntaxKind17.PlusEqualsToken:
|
|
7021
|
+
case SyntaxKind17.PlusToken:
|
|
7050
7022
|
const otherOperandType = checker.getTypeAtLocation(parent.left === node ? parent.right : parent.left);
|
|
7051
7023
|
if (otherOperandType.flags & TypeFlags2.NumberLike) {
|
|
7052
7024
|
usage.isNumber = true;
|
|
@@ -7059,20 +7031,20 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7059
7031
|
break;
|
|
7060
7032
|
// AssignmentOperators
|
|
7061
7033
|
// Na tag, também o `===` e o `!==`, que a Linguagem não tem (CK-70).
|
|
7062
|
-
case
|
|
7063
|
-
case
|
|
7064
|
-
case
|
|
7034
|
+
case SyntaxKind17.EqualsToken:
|
|
7035
|
+
case SyntaxKind17.EqualsEqualsToken:
|
|
7036
|
+
case SyntaxKind17.ExclamationEqualsToken:
|
|
7065
7037
|
addCandidateType(usage, checker.getTypeAtLocation(parent.left === node ? parent.right : parent.left));
|
|
7066
7038
|
break;
|
|
7067
|
-
case
|
|
7039
|
+
case SyntaxKind17.InKeyword:
|
|
7068
7040
|
if (node === parent.left) {
|
|
7069
7041
|
usage.isString = true;
|
|
7070
7042
|
}
|
|
7071
7043
|
break;
|
|
7072
7044
|
// LogicalOperator Or NullishCoalescing
|
|
7073
|
-
case
|
|
7074
|
-
case
|
|
7075
|
-
if (node === parent.left && (node.parent.parent.kind ===
|
|
7045
|
+
case SyntaxKind17.BarBarToken:
|
|
7046
|
+
case SyntaxKind17.QuestionQuestionToken:
|
|
7047
|
+
if (node === parent.left && (node.parent.parent.kind === SyntaxKind17.VariableDeclaration || isAssignmentExpression2(
|
|
7076
7048
|
node.parent.parent,
|
|
7077
7049
|
/*excludeCompoundAssignment*/
|
|
7078
7050
|
true
|
|
@@ -7081,7 +7053,7 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7081
7053
|
}
|
|
7082
7054
|
break;
|
|
7083
7055
|
// Na tag, também a vírgula e o `instanceof`, de que nada se infere (CK-02).
|
|
7084
|
-
case
|
|
7056
|
+
case SyntaxKind17.AmpersandAmpersandToken:
|
|
7085
7057
|
break;
|
|
7086
7058
|
}
|
|
7087
7059
|
}
|
|
@@ -7130,7 +7102,7 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7130
7102
|
for (const i of inferences) {
|
|
7131
7103
|
for (const { high, low } of priorities) {
|
|
7132
7104
|
if (high(i)) {
|
|
7133
|
-
|
|
7105
|
+
Debug16.assert(!low(i), "Priority can't have both low and high");
|
|
7134
7106
|
toRemove.push(low);
|
|
7135
7107
|
}
|
|
7136
7108
|
}
|
|
@@ -7282,7 +7254,7 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7282
7254
|
const types = [];
|
|
7283
7255
|
usage.properties.forEach((propUsage, name) => {
|
|
7284
7256
|
const genericPropertyType = checker.getTypeOfPropertyOfType(generic, name);
|
|
7285
|
-
|
|
7257
|
+
Debug16.assert(!!genericPropertyType, "generic should have all the properties of its reference.");
|
|
7286
7258
|
types.push(...inferTypeParameters(genericPropertyType, combineFromUsage(propUsage), singleTypeParameter));
|
|
7287
7259
|
});
|
|
7288
7260
|
return builtinConstructors[type.symbol.escapedName](combineTypes(types));
|
|
@@ -7380,7 +7352,7 @@ function inferTypeFromReferences(program, references, cancellationToken) {
|
|
|
7380
7352
|
|
|
7381
7353
|
// src/codefixes/helpers.ts
|
|
7382
7354
|
import {
|
|
7383
|
-
SyntaxKind as
|
|
7355
|
+
SyntaxKind as SyntaxKind18,
|
|
7384
7356
|
createIdentifier as createIdentifier6,
|
|
7385
7357
|
createQualifiedName,
|
|
7386
7358
|
createTypeReferenceNode as createTypeReferenceNode4,
|
|
@@ -7432,7 +7404,7 @@ function tryGetAutoImportableReferenceFromImportTypeNode(importTypeNode, type, s
|
|
|
7432
7404
|
}
|
|
7433
7405
|
}
|
|
7434
7406
|
function replaceFirstIdentifierOfEntityName(name, newIdentifier) {
|
|
7435
|
-
if (name.kind ===
|
|
7407
|
+
if (name.kind === SyntaxKind18.Identifier) {
|
|
7436
7408
|
return newIdentifier;
|
|
7437
7409
|
}
|
|
7438
7410
|
return createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
|
|
@@ -7447,33 +7419,33 @@ function importSymbols(importAdder, symbols) {
|
|
|
7447
7419
|
|
|
7448
7420
|
// src/codefixes/useBigintLiteral.ts
|
|
7449
7421
|
import {
|
|
7450
|
-
Diagnostics as
|
|
7422
|
+
Diagnostics as Diagnostics17,
|
|
7451
7423
|
createBigIntLiteral,
|
|
7452
7424
|
isNumericLiteral,
|
|
7453
7425
|
tryCast as tryCast6
|
|
7454
7426
|
} from "@tslite/parser";
|
|
7455
7427
|
import {
|
|
7456
|
-
getTokenAtPosition as
|
|
7428
|
+
getTokenAtPosition as getTokenAtPosition16
|
|
7457
7429
|
} from "@tslite/services";
|
|
7458
|
-
var
|
|
7459
|
-
var
|
|
7460
|
-
|
|
7430
|
+
var fixId13 = "useBigintLiteral";
|
|
7431
|
+
var errorCodes16 = [
|
|
7432
|
+
Diagnostics17.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_integers.code
|
|
7461
7433
|
];
|
|
7462
7434
|
registerCodeFix({
|
|
7463
|
-
errorCodes:
|
|
7435
|
+
errorCodes: errorCodes16,
|
|
7464
7436
|
getCodeActions: (context) => {
|
|
7465
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) =>
|
|
7437
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange5(t, context.sourceFile, context.span));
|
|
7466
7438
|
if (changes.length > 0) {
|
|
7467
|
-
return [createCodeFixAction(
|
|
7439
|
+
return [createCodeFixAction(fixId13, changes, Diagnostics17.Convert_to_a_bigint_numeric_literal, fixId13, Diagnostics17.Convert_all_to_bigint_numeric_literals)];
|
|
7468
7440
|
}
|
|
7469
7441
|
},
|
|
7470
|
-
fixIds: [
|
|
7442
|
+
fixIds: [fixId13],
|
|
7471
7443
|
getAllCodeActions: (context) => {
|
|
7472
|
-
return codeFixAll(context,
|
|
7444
|
+
return codeFixAll(context, errorCodes16, (changes, diag) => makeChange5(changes, diag.file, diag));
|
|
7473
7445
|
}
|
|
7474
7446
|
});
|
|
7475
|
-
function
|
|
7476
|
-
const numericLiteral = tryCast6(
|
|
7447
|
+
function makeChange5(changeTracker, sourceFile, span) {
|
|
7448
|
+
const numericLiteral = tryCast6(getTokenAtPosition16(sourceFile, span.start), isNumericLiteral);
|
|
7477
7449
|
if (!numericLiteral) {
|
|
7478
7450
|
return;
|
|
7479
7451
|
}
|
|
@@ -7483,32 +7455,32 @@ function makeChange6(changeTracker, sourceFile, span) {
|
|
|
7483
7455
|
|
|
7484
7456
|
// src/codefixes/fixAddModuleReferTypeMissingTypeof.ts
|
|
7485
7457
|
import {
|
|
7486
|
-
Debug as
|
|
7487
|
-
Diagnostics as
|
|
7488
|
-
SyntaxKind as
|
|
7458
|
+
Debug as Debug17,
|
|
7459
|
+
Diagnostics as Diagnostics18,
|
|
7460
|
+
SyntaxKind as SyntaxKind19,
|
|
7489
7461
|
updateImportTypeNode
|
|
7490
7462
|
} from "@tslite/parser";
|
|
7491
7463
|
import {
|
|
7492
|
-
getTokenAtPosition as
|
|
7464
|
+
getTokenAtPosition as getTokenAtPosition17
|
|
7493
7465
|
} from "@tslite/services";
|
|
7494
7466
|
var fixIdAddMissingTypeof = "fixAddModuleReferTypeMissingTypeof";
|
|
7495
|
-
var
|
|
7496
|
-
var
|
|
7467
|
+
var fixId14 = fixIdAddMissingTypeof;
|
|
7468
|
+
var errorCodes17 = [Diagnostics18.Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0.code];
|
|
7497
7469
|
registerCodeFix({
|
|
7498
|
-
errorCodes:
|
|
7470
|
+
errorCodes: errorCodes17,
|
|
7499
7471
|
getCodeActions: (context) => {
|
|
7500
7472
|
const { sourceFile, span } = context;
|
|
7501
7473
|
const importType = getImportTypeNode(sourceFile, span.start);
|
|
7502
7474
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange8(t, sourceFile, importType));
|
|
7503
|
-
return [createCodeFixAction(
|
|
7475
|
+
return [createCodeFixAction(fixId14, changes, Diagnostics18.Add_missing_typeof, fixId14, Diagnostics18.Add_missing_typeof)];
|
|
7504
7476
|
},
|
|
7505
|
-
fixIds: [
|
|
7506
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
7477
|
+
fixIds: [fixId14],
|
|
7478
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes17, (changes, diag) => doChange8(changes, context.sourceFile, getImportTypeNode(diag.file, diag.start)))
|
|
7507
7479
|
});
|
|
7508
7480
|
function getImportTypeNode(sourceFile, pos) {
|
|
7509
|
-
const token =
|
|
7510
|
-
|
|
7511
|
-
|
|
7481
|
+
const token = getTokenAtPosition17(sourceFile, pos);
|
|
7482
|
+
Debug17.assert(token.kind === SyntaxKind19.ImportKeyword, "This token should be an ImportKeyword");
|
|
7483
|
+
Debug17.assert(token.parent.kind === SyntaxKind19.ImportType, "Token parent should be an ImportType");
|
|
7512
7484
|
return token.parent;
|
|
7513
7485
|
}
|
|
7514
7486
|
function doChange8(changes, sourceFile, importType) {
|
|
@@ -7525,8 +7497,8 @@ function doChange8(changes, sourceFile, importType) {
|
|
|
7525
7497
|
|
|
7526
7498
|
// src/codefixes/convertToMappedObjectType.ts
|
|
7527
7499
|
import {
|
|
7528
|
-
Diagnostics as
|
|
7529
|
-
SyntaxKind as
|
|
7500
|
+
Diagnostics as Diagnostics19,
|
|
7501
|
+
SyntaxKind as SyntaxKind20,
|
|
7530
7502
|
cast as cast5,
|
|
7531
7503
|
createIntersectionTypeNode,
|
|
7532
7504
|
createMappedTypeNode,
|
|
@@ -7543,29 +7515,29 @@ import {
|
|
|
7543
7515
|
isTypeAliasDeclaration
|
|
7544
7516
|
} from "@tslite/parser";
|
|
7545
7517
|
import {
|
|
7546
|
-
getTokenAtPosition as
|
|
7518
|
+
getTokenAtPosition as getTokenAtPosition18
|
|
7547
7519
|
} from "@tslite/services";
|
|
7548
7520
|
var fixIdAddMissingTypeof2 = "fixConvertToMappedObjectType";
|
|
7549
|
-
var
|
|
7550
|
-
var
|
|
7521
|
+
var fixId15 = fixIdAddMissingTypeof2;
|
|
7522
|
+
var errorCodes18 = [Diagnostics19.An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead.code];
|
|
7551
7523
|
registerCodeFix({
|
|
7552
|
-
errorCodes:
|
|
7524
|
+
errorCodes: errorCodes18,
|
|
7553
7525
|
getCodeActions: (context) => {
|
|
7554
7526
|
const { sourceFile, span } = context;
|
|
7555
7527
|
const info = getInfo3(sourceFile, span.start);
|
|
7556
7528
|
if (!info) return void 0;
|
|
7557
7529
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange9(t, sourceFile, info));
|
|
7558
7530
|
const name = idText(info.container.name);
|
|
7559
|
-
return [createCodeFixAction(
|
|
7531
|
+
return [createCodeFixAction(fixId15, changes, [Diagnostics19.Convert_0_to_mapped_object_type, name], fixId15, [Diagnostics19.Convert_0_to_mapped_object_type, name])];
|
|
7560
7532
|
},
|
|
7561
|
-
fixIds: [
|
|
7562
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
7533
|
+
fixIds: [fixId15],
|
|
7534
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes18, (changes, diag) => {
|
|
7563
7535
|
const info = getInfo3(diag.file, diag.start);
|
|
7564
7536
|
if (info) doChange9(changes, diag.file, info);
|
|
7565
7537
|
})
|
|
7566
7538
|
});
|
|
7567
7539
|
function getInfo3(sourceFile, pos) {
|
|
7568
|
-
const token =
|
|
7540
|
+
const token = getTokenAtPosition18(sourceFile, pos);
|
|
7569
7541
|
const indexSignature = cast5(token.parent.parent, isIndexSignatureDeclaration);
|
|
7570
7542
|
const container = cast5(indexSignature.parent.parent, isTypeAliasDeclaration);
|
|
7571
7543
|
return { indexSignature, container };
|
|
@@ -7579,7 +7551,7 @@ function doChange9(changes, sourceFile, { indexSignature, container }) {
|
|
|
7579
7551
|
const parameter = first7(indexSignature.parameters);
|
|
7580
7552
|
const mappedTypeParameter = createTypeParameterDeclaration(cast5(parameter.name, isIdentifier11), parameter.type);
|
|
7581
7553
|
const mappedIntersectionType = createMappedTypeNode(
|
|
7582
|
-
hasReadonlyModifier(indexSignature) ? createModifier(
|
|
7554
|
+
hasReadonlyModifier(indexSignature) ? createModifier(SyntaxKind20.ReadonlyKeyword) : void 0,
|
|
7583
7555
|
mappedTypeParameter,
|
|
7584
7556
|
indexSignature.questionToken,
|
|
7585
7557
|
indexSignature.type
|
|
@@ -7594,8 +7566,8 @@ function doChange9(changes, sourceFile, { indexSignature, container }) {
|
|
|
7594
7566
|
|
|
7595
7567
|
// src/codefixes/removeUnnecessaryAwait.ts
|
|
7596
7568
|
import {
|
|
7597
|
-
Diagnostics as
|
|
7598
|
-
SyntaxKind as
|
|
7569
|
+
Diagnostics as Diagnostics20,
|
|
7570
|
+
SyntaxKind as SyntaxKind21,
|
|
7599
7571
|
getLeftmostExpression,
|
|
7600
7572
|
isAwaitExpression,
|
|
7601
7573
|
isIdentifier as isIdentifier12,
|
|
@@ -7604,27 +7576,27 @@ import {
|
|
|
7604
7576
|
} from "@tslite/parser";
|
|
7605
7577
|
import {
|
|
7606
7578
|
findPrecedingToken as findPrecedingToken5,
|
|
7607
|
-
getTokenAtPosition as
|
|
7579
|
+
getTokenAtPosition as getTokenAtPosition19
|
|
7608
7580
|
} from "@tslite/services";
|
|
7609
|
-
var
|
|
7610
|
-
var
|
|
7611
|
-
|
|
7581
|
+
var fixId16 = "removeUnnecessaryAwait";
|
|
7582
|
+
var errorCodes19 = [
|
|
7583
|
+
Diagnostics20.await_has_no_effect_on_the_type_of_this_expression.code
|
|
7612
7584
|
];
|
|
7613
7585
|
registerCodeFix({
|
|
7614
|
-
errorCodes:
|
|
7586
|
+
errorCodes: errorCodes19,
|
|
7615
7587
|
getCodeActions: (context) => {
|
|
7616
|
-
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) =>
|
|
7588
|
+
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => makeChange6(t, context.sourceFile, context.span));
|
|
7617
7589
|
if (changes.length > 0) {
|
|
7618
|
-
return [createCodeFixAction(
|
|
7590
|
+
return [createCodeFixAction(fixId16, changes, Diagnostics20.Remove_unnecessary_await, fixId16, Diagnostics20.Remove_all_unnecessary_uses_of_await)];
|
|
7619
7591
|
}
|
|
7620
7592
|
},
|
|
7621
|
-
fixIds: [
|
|
7593
|
+
fixIds: [fixId16],
|
|
7622
7594
|
getAllCodeActions: (context) => {
|
|
7623
|
-
return codeFixAll(context,
|
|
7595
|
+
return codeFixAll(context, errorCodes19, (changes, diag) => makeChange6(changes, diag.file, diag));
|
|
7624
7596
|
}
|
|
7625
7597
|
});
|
|
7626
|
-
function
|
|
7627
|
-
const awaitKeyword = tryCast7(
|
|
7598
|
+
function makeChange6(changeTracker, sourceFile, span) {
|
|
7599
|
+
const awaitKeyword = tryCast7(getTokenAtPosition19(sourceFile, span.start), (node) => node.kind === SyntaxKind21.AwaitKeyword);
|
|
7628
7600
|
const awaitExpression = awaitKeyword && tryCast7(awaitKeyword.parent, isAwaitExpression);
|
|
7629
7601
|
if (!awaitExpression) {
|
|
7630
7602
|
return;
|
|
@@ -7645,42 +7617,42 @@ function makeChange7(changeTracker, sourceFile, span) {
|
|
|
7645
7617
|
|
|
7646
7618
|
// src/codefixes/splitTypeOnlyImport.ts
|
|
7647
7619
|
import {
|
|
7648
|
-
Debug as
|
|
7649
|
-
Diagnostics as
|
|
7620
|
+
Debug as Debug18,
|
|
7621
|
+
Diagnostics as Diagnostics21,
|
|
7650
7622
|
createImportDeclaration,
|
|
7651
|
-
findAncestor as
|
|
7623
|
+
findAncestor as findAncestor10,
|
|
7652
7624
|
isImportDeclaration as isImportDeclaration5,
|
|
7653
7625
|
updateImportClause as updateImportClause2,
|
|
7654
7626
|
updateImportDeclaration as updateImportDeclaration2
|
|
7655
7627
|
} from "@tslite/parser";
|
|
7656
7628
|
import {
|
|
7657
|
-
getTokenAtPosition as
|
|
7629
|
+
getTokenAtPosition as getTokenAtPosition20
|
|
7658
7630
|
} from "@tslite/services";
|
|
7659
|
-
var
|
|
7660
|
-
var
|
|
7631
|
+
var errorCodes20 = [Diagnostics21.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both.code];
|
|
7632
|
+
var fixId17 = "splitTypeOnlyImport";
|
|
7661
7633
|
registerCodeFix({
|
|
7662
|
-
errorCodes:
|
|
7663
|
-
fixIds: [
|
|
7634
|
+
errorCodes: errorCodes20,
|
|
7635
|
+
fixIds: [fixId17],
|
|
7664
7636
|
getCodeActions: (context) => {
|
|
7665
7637
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
7666
7638
|
return splitTypeOnlyImport(t, getImportDeclaration(context.sourceFile, context.span), context);
|
|
7667
7639
|
});
|
|
7668
7640
|
if (changes.length) {
|
|
7669
|
-
return [createCodeFixAction(
|
|
7641
|
+
return [createCodeFixAction(fixId17, changes, Diagnostics21.Split_into_two_separate_import_declarations, fixId17, Diagnostics21.Split_all_invalid_type_only_imports)];
|
|
7670
7642
|
}
|
|
7671
7643
|
},
|
|
7672
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
7644
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes20, (changes, error) => {
|
|
7673
7645
|
splitTypeOnlyImport(changes, getImportDeclaration(context.sourceFile, error), context);
|
|
7674
7646
|
})
|
|
7675
7647
|
});
|
|
7676
7648
|
function getImportDeclaration(sourceFile, span) {
|
|
7677
|
-
return
|
|
7649
|
+
return findAncestor10(getTokenAtPosition20(sourceFile, span.start), isImportDeclaration5);
|
|
7678
7650
|
}
|
|
7679
7651
|
function splitTypeOnlyImport(changes, importDeclaration, context) {
|
|
7680
7652
|
if (!importDeclaration) {
|
|
7681
7653
|
return;
|
|
7682
7654
|
}
|
|
7683
|
-
const importClause =
|
|
7655
|
+
const importClause = Debug18.checkDefined(importDeclaration.importClause);
|
|
7684
7656
|
changes.replaceNode(context.sourceFile, importDeclaration, updateImportDeclaration2(
|
|
7685
7657
|
importDeclaration,
|
|
7686
7658
|
importDeclaration.modifiers,
|
|
@@ -7709,25 +7681,25 @@ function splitTypeOnlyImport(changes, importDeclaration, context) {
|
|
|
7709
7681
|
|
|
7710
7682
|
// src/codefixes/convertConstToLet.ts
|
|
7711
7683
|
import {
|
|
7712
|
-
Diagnostics as
|
|
7684
|
+
Diagnostics as Diagnostics22
|
|
7713
7685
|
} from "@tslite/parser";
|
|
7714
7686
|
import {
|
|
7715
|
-
getTokenAtPosition as
|
|
7687
|
+
getTokenAtPosition as getTokenAtPosition21
|
|
7716
7688
|
} from "@tslite/services";
|
|
7717
|
-
var
|
|
7718
|
-
var
|
|
7689
|
+
var fixId18 = "fixConvertConstToLet";
|
|
7690
|
+
var errorCodes21 = [Diagnostics22.Cannot_assign_to_0_because_it_is_a_constant.code];
|
|
7719
7691
|
registerCodeFix({
|
|
7720
|
-
errorCodes:
|
|
7692
|
+
errorCodes: errorCodes21,
|
|
7721
7693
|
getCodeActions: (context) => {
|
|
7722
7694
|
const { sourceFile, span, program } = context;
|
|
7723
7695
|
const variableStatement = getVariableStatement(sourceFile, span.start, program);
|
|
7724
7696
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange10(t, sourceFile, variableStatement));
|
|
7725
|
-
return [createCodeFixAction(
|
|
7697
|
+
return [createCodeFixAction(fixId18, changes, Diagnostics22.Convert_const_to_let, fixId18, Diagnostics22.Convert_const_to_let)];
|
|
7726
7698
|
},
|
|
7727
|
-
fixIds: [
|
|
7699
|
+
fixIds: [fixId18]
|
|
7728
7700
|
});
|
|
7729
7701
|
function getVariableStatement(sourceFile, pos, program) {
|
|
7730
|
-
const token =
|
|
7702
|
+
const token = getTokenAtPosition21(sourceFile, pos);
|
|
7731
7703
|
const checker = program.getTypeChecker();
|
|
7732
7704
|
const symbol = checker.getSymbolAtLocation(token);
|
|
7733
7705
|
if (symbol) {
|
|
@@ -7744,20 +7716,20 @@ function doChange10(changes, sourceFile, variableStatement) {
|
|
|
7744
7716
|
|
|
7745
7717
|
// src/codefixes/fixExpectedComma.ts
|
|
7746
7718
|
import {
|
|
7747
|
-
Diagnostics as
|
|
7748
|
-
SyntaxKind as
|
|
7719
|
+
Diagnostics as Diagnostics23,
|
|
7720
|
+
SyntaxKind as SyntaxKind22,
|
|
7749
7721
|
createNode,
|
|
7750
7722
|
isArrayLiteralExpression as isArrayLiteralExpression2,
|
|
7751
7723
|
isObjectLiteralExpression as isObjectLiteralExpression2
|
|
7752
7724
|
} from "@tslite/parser";
|
|
7753
7725
|
import {
|
|
7754
|
-
getTokenAtPosition as
|
|
7726
|
+
getTokenAtPosition as getTokenAtPosition22
|
|
7755
7727
|
} from "@tslite/services";
|
|
7756
|
-
var
|
|
7757
|
-
var expectedErrorCode =
|
|
7758
|
-
var
|
|
7728
|
+
var fixId19 = "fixExpectedComma";
|
|
7729
|
+
var expectedErrorCode = Diagnostics23._0_expected.code;
|
|
7730
|
+
var errorCodes22 = [expectedErrorCode];
|
|
7759
7731
|
registerCodeFix({
|
|
7760
|
-
errorCodes:
|
|
7732
|
+
errorCodes: errorCodes22,
|
|
7761
7733
|
getCodeActions(context) {
|
|
7762
7734
|
const { sourceFile } = context;
|
|
7763
7735
|
const info = getInfo4(sourceFile, context.span.start, context.errorCode);
|
|
@@ -7766,25 +7738,25 @@ registerCodeFix({
|
|
|
7766
7738
|
}
|
|
7767
7739
|
const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange11(t, sourceFile, info));
|
|
7768
7740
|
return [createCodeFixAction(
|
|
7769
|
-
|
|
7741
|
+
fixId19,
|
|
7770
7742
|
changes,
|
|
7771
|
-
[
|
|
7772
|
-
|
|
7773
|
-
[
|
|
7743
|
+
[Diagnostics23.Change_0_to_1, ";", ","],
|
|
7744
|
+
fixId19,
|
|
7745
|
+
[Diagnostics23.Change_0_to_1, ";", ","]
|
|
7774
7746
|
)];
|
|
7775
7747
|
},
|
|
7776
|
-
fixIds: [
|
|
7777
|
-
getAllCodeActions: (context) => codeFixAll(context,
|
|
7748
|
+
fixIds: [fixId19],
|
|
7749
|
+
getAllCodeActions: (context) => codeFixAll(context, errorCodes22, (changes, diag) => {
|
|
7778
7750
|
const info = getInfo4(diag.file, diag.start, diag.code);
|
|
7779
7751
|
if (info) doChange11(changes, context.sourceFile, info);
|
|
7780
7752
|
})
|
|
7781
7753
|
});
|
|
7782
7754
|
function getInfo4(sourceFile, pos, _) {
|
|
7783
|
-
const node =
|
|
7784
|
-
return node.kind ===
|
|
7755
|
+
const node = getTokenAtPosition22(sourceFile, pos);
|
|
7756
|
+
return node.kind === SyntaxKind22.SemicolonToken && node.parent && (isObjectLiteralExpression2(node.parent) || isArrayLiteralExpression2(node.parent)) ? { node } : void 0;
|
|
7785
7757
|
}
|
|
7786
7758
|
function doChange11(changes, sourceFile, { node }) {
|
|
7787
|
-
const newNode = createNode(
|
|
7759
|
+
const newNode = createNode(SyntaxKind22.CommaToken);
|
|
7788
7760
|
changes.replaceNode(sourceFile, node, newNode);
|
|
7789
7761
|
}
|
|
7790
7762
|
|
|
@@ -7820,12 +7792,12 @@ function getEditsForRefactor(context, refactorName9, actionName) {
|
|
|
7820
7792
|
|
|
7821
7793
|
// src/refactors/convertExport.ts
|
|
7822
7794
|
import {
|
|
7823
|
-
Debug as
|
|
7824
|
-
Diagnostics as
|
|
7795
|
+
Debug as Debug19,
|
|
7796
|
+
Diagnostics as Diagnostics24,
|
|
7825
7797
|
InternalSymbolName as InternalSymbolName2,
|
|
7826
7798
|
ModifierFlags as ModifierFlags3,
|
|
7827
7799
|
NodeFlags as NodeFlags4,
|
|
7828
|
-
SyntaxKind as
|
|
7800
|
+
SyntaxKind as SyntaxKind23,
|
|
7829
7801
|
createExportDefault,
|
|
7830
7802
|
createExportSpecifier,
|
|
7831
7803
|
createIdentifier as createIdentifier7,
|
|
@@ -7842,7 +7814,7 @@ import {
|
|
|
7842
7814
|
findModifier,
|
|
7843
7815
|
getParentNodeInSpan,
|
|
7844
7816
|
getRefactorContextSpan,
|
|
7845
|
-
getTokenAtPosition as
|
|
7817
|
+
getTokenAtPosition as getTokenAtPosition23
|
|
7846
7818
|
} from "@tslite/services";
|
|
7847
7819
|
var refactorName = "Convert export";
|
|
7848
7820
|
var actionNameNamedToDefault = "Convert named export to default export";
|
|
@@ -7850,20 +7822,20 @@ registerRefactor(refactorName, {
|
|
|
7850
7822
|
getAvailableActions(context) {
|
|
7851
7823
|
const info = getInfo5(context);
|
|
7852
7824
|
if (!info) return emptyArray7;
|
|
7853
|
-
const description =
|
|
7825
|
+
const description = Diagnostics24.Convert_named_export_to_default_export.message;
|
|
7854
7826
|
const actionName = actionNameNamedToDefault;
|
|
7855
7827
|
return [{ name: refactorName, description, actions: [{ name: actionName, description }] }];
|
|
7856
7828
|
},
|
|
7857
7829
|
getEditsForAction(context, actionName) {
|
|
7858
|
-
|
|
7859
|
-
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange12(context.file, context.program,
|
|
7830
|
+
Debug19.assert(actionName === actionNameNamedToDefault, "Unexpected action name");
|
|
7831
|
+
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange12(context.file, context.program, Debug19.checkDefined(getInfo5(context), "context must have info"), t, context.cancellationToken));
|
|
7860
7832
|
return { edits, renameFilename: void 0, renameLocation: void 0 };
|
|
7861
7833
|
}
|
|
7862
7834
|
});
|
|
7863
7835
|
function getInfo5(context) {
|
|
7864
7836
|
const { file } = context;
|
|
7865
7837
|
const span = getRefactorContextSpan(context);
|
|
7866
|
-
const token =
|
|
7838
|
+
const token = getTokenAtPosition23(file, span.start);
|
|
7867
7839
|
const exportNode = getParentNodeInSpan(token, file, span);
|
|
7868
7840
|
if (!exportNode || !isSourceFile2(exportNode.parent) && !(isModuleBlock(exportNode.parent) && isAmbientModule3(exportNode.parent.parent))) {
|
|
7869
7841
|
return void 0;
|
|
@@ -7874,12 +7846,12 @@ function getInfo5(context) {
|
|
|
7874
7846
|
return void 0;
|
|
7875
7847
|
}
|
|
7876
7848
|
switch (exportNode.kind) {
|
|
7877
|
-
case
|
|
7878
|
-
case
|
|
7849
|
+
case SyntaxKind23.TypeAliasDeclaration:
|
|
7850
|
+
case SyntaxKind23.ModuleDeclaration: {
|
|
7879
7851
|
const node = exportNode;
|
|
7880
7852
|
return node.name && isIdentifier13(node.name) ? { exportNode: node, exportName: node.name, exportingModuleSymbol } : void 0;
|
|
7881
7853
|
}
|
|
7882
|
-
case
|
|
7854
|
+
case SyntaxKind23.VariableStatement: {
|
|
7883
7855
|
const vs = exportNode;
|
|
7884
7856
|
if (!(vs.declarationList.flags & NodeFlags4.Const) || vs.declarationList.declarations.length !== 1) {
|
|
7885
7857
|
return void 0;
|
|
@@ -7897,26 +7869,26 @@ function doChange12(exportingSourceFile, program, info, changes, cancellationTok
|
|
|
7897
7869
|
changeImports(program, info, changes, cancellationToken);
|
|
7898
7870
|
}
|
|
7899
7871
|
function changeExport(exportingSourceFile, { exportNode, exportName }, changes, checker) {
|
|
7900
|
-
const exportKeyword =
|
|
7872
|
+
const exportKeyword = Debug19.checkDefined(findModifier(exportNode, SyntaxKind23.ExportKeyword), "Should find an export keyword in modifier list");
|
|
7901
7873
|
switch (exportNode.kind) {
|
|
7902
|
-
case
|
|
7874
|
+
case SyntaxKind23.VariableStatement:
|
|
7903
7875
|
if (!FindAllReferences5.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile)) {
|
|
7904
|
-
changes.replaceNode(exportingSourceFile, exportNode, createExportDefault(
|
|
7876
|
+
changes.replaceNode(exportingSourceFile, exportNode, createExportDefault(Debug19.checkDefined(first8(exportNode.declarationList.declarations).initializer, "Initializer was previously known to be present")));
|
|
7905
7877
|
break;
|
|
7906
7878
|
}
|
|
7907
7879
|
// falls through
|
|
7908
|
-
case
|
|
7909
|
-
case
|
|
7880
|
+
case SyntaxKind23.TypeAliasDeclaration:
|
|
7881
|
+
case SyntaxKind23.ModuleDeclaration:
|
|
7910
7882
|
changes.deleteModifier(exportingSourceFile, exportKeyword);
|
|
7911
7883
|
changes.insertNodeAfter(exportingSourceFile, exportNode, createExportDefault(createIdentifier7(exportName.text)));
|
|
7912
7884
|
break;
|
|
7913
7885
|
default:
|
|
7914
|
-
|
|
7886
|
+
Debug19.assertNever(exportNode, `Unexpected exportNode kind ${exportNode.kind}`);
|
|
7915
7887
|
}
|
|
7916
7888
|
}
|
|
7917
7889
|
function changeImports(program, { exportName, exportingModuleSymbol }, changes, cancellationToken) {
|
|
7918
7890
|
const checker = program.getTypeChecker();
|
|
7919
|
-
const exportSymbol =
|
|
7891
|
+
const exportSymbol = Debug19.checkDefined(checker.getSymbolAtLocation(exportName), "Export name should resolve to a symbol");
|
|
7920
7892
|
FindAllReferences5.Core.eachExportReference(
|
|
7921
7893
|
program.getSourceFiles(),
|
|
7922
7894
|
checker,
|
|
@@ -7935,10 +7907,10 @@ function changeImports(program, { exportName, exportingModuleSymbol }, changes,
|
|
|
7935
7907
|
function changeNamedToDefaultImport(importingSourceFile, ref, changes) {
|
|
7936
7908
|
const parent = ref.parent;
|
|
7937
7909
|
switch (parent.kind) {
|
|
7938
|
-
case
|
|
7910
|
+
case SyntaxKind23.PropertyAccessExpression:
|
|
7939
7911
|
changes.replaceNode(importingSourceFile, ref, createIdentifier7("default"));
|
|
7940
7912
|
break;
|
|
7941
|
-
case
|
|
7913
|
+
case SyntaxKind23.ImportSpecifier: {
|
|
7942
7914
|
const defaultImport = createIdentifier7(parent.name.text);
|
|
7943
7915
|
if (parent.parent.elements.length === 1) {
|
|
7944
7916
|
changes.replaceNode(importingSourceFile, parent.parent, defaultImport);
|
|
@@ -7948,12 +7920,12 @@ function changeNamedToDefaultImport(importingSourceFile, ref, changes) {
|
|
|
7948
7920
|
}
|
|
7949
7921
|
break;
|
|
7950
7922
|
}
|
|
7951
|
-
case
|
|
7923
|
+
case SyntaxKind23.ExportSpecifier: {
|
|
7952
7924
|
changes.replaceNode(importingSourceFile, parent, makeExportSpecifier("default", parent.name.text));
|
|
7953
7925
|
break;
|
|
7954
7926
|
}
|
|
7955
7927
|
default:
|
|
7956
|
-
|
|
7928
|
+
Debug19.assertNever(parent, `Unexpected parent kind ${parent.kind}`);
|
|
7957
7929
|
}
|
|
7958
7930
|
}
|
|
7959
7931
|
function makeExportSpecifier(propertyName, name) {
|
|
@@ -7962,11 +7934,11 @@ function makeExportSpecifier(propertyName, name) {
|
|
|
7962
7934
|
|
|
7963
7935
|
// src/refactors/convertImport.ts
|
|
7964
7936
|
import {
|
|
7965
|
-
Debug as
|
|
7966
|
-
Diagnostics as
|
|
7937
|
+
Debug as Debug20,
|
|
7938
|
+
Diagnostics as Diagnostics25,
|
|
7967
7939
|
ScriptTarget as ScriptTarget6,
|
|
7968
7940
|
SymbolFlags as SymbolFlags4,
|
|
7969
|
-
SyntaxKind as
|
|
7941
|
+
SyntaxKind as SyntaxKind24,
|
|
7970
7942
|
cast as cast6,
|
|
7971
7943
|
createIdentifier as createIdentifier8,
|
|
7972
7944
|
createImportClause,
|
|
@@ -7988,7 +7960,7 @@ import {
|
|
|
7988
7960
|
FindAllReferences as FindAllReferences6,
|
|
7989
7961
|
getParentNodeInSpan as getParentNodeInSpan2,
|
|
7990
7962
|
getRefactorContextSpan as getRefactorContextSpan2,
|
|
7991
|
-
getTokenAtPosition as
|
|
7963
|
+
getTokenAtPosition as getTokenAtPosition24,
|
|
7992
7964
|
getUniqueName,
|
|
7993
7965
|
moduleSpecifierToValidIdentifier
|
|
7994
7966
|
} from "@tslite/services";
|
|
@@ -7999,20 +7971,20 @@ registerRefactor(refactorName2, {
|
|
|
7999
7971
|
getAvailableActions(context) {
|
|
8000
7972
|
const i = getImportToConvert(context);
|
|
8001
7973
|
if (!i) return emptyArray8;
|
|
8002
|
-
const description = i.kind ===
|
|
8003
|
-
const actionName = i.kind ===
|
|
7974
|
+
const description = i.kind === SyntaxKind24.NamespaceImport ? Diagnostics25.Convert_namespace_import_to_named_imports.message : Diagnostics25.Convert_named_imports_to_namespace_import.message;
|
|
7975
|
+
const actionName = i.kind === SyntaxKind24.NamespaceImport ? actionNameNamespaceToNamed : actionNameNamedToNamespace;
|
|
8004
7976
|
return [{ name: refactorName2, description, actions: [{ name: actionName, description }] }];
|
|
8005
7977
|
},
|
|
8006
7978
|
getEditsForAction(context, actionName) {
|
|
8007
|
-
|
|
8008
|
-
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange13(context.file, context.program, t,
|
|
7979
|
+
Debug20.assert(actionName === actionNameNamespaceToNamed || actionName === actionNameNamedToNamespace, "Unexpected action name");
|
|
7980
|
+
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange13(context.file, context.program, t, Debug20.checkDefined(getImportToConvert(context), "Context must provide an import to convert")));
|
|
8009
7981
|
return { edits, renameFilename: void 0, renameLocation: void 0 };
|
|
8010
7982
|
}
|
|
8011
7983
|
});
|
|
8012
7984
|
function getImportToConvert(context) {
|
|
8013
7985
|
const { file } = context;
|
|
8014
7986
|
const span = getRefactorContextSpan2(context);
|
|
8015
|
-
const token =
|
|
7987
|
+
const token = getTokenAtPosition24(file, span.start);
|
|
8016
7988
|
const importDecl = getParentNodeInSpan2(token, file, span);
|
|
8017
7989
|
if (!importDecl || !isImportDeclaration6(importDecl)) return void 0;
|
|
8018
7990
|
const { importClause } = importDecl;
|
|
@@ -8020,7 +7992,7 @@ function getImportToConvert(context) {
|
|
|
8020
7992
|
}
|
|
8021
7993
|
function doChange13(sourceFile, program, changes, toConvert) {
|
|
8022
7994
|
const checker = program.getTypeChecker();
|
|
8023
|
-
if (toConvert.kind ===
|
|
7995
|
+
if (toConvert.kind === SyntaxKind24.NamespaceImport) {
|
|
8024
7996
|
doChangeNamespaceToNamed(sourceFile, checker, changes, toConvert);
|
|
8025
7997
|
} else {
|
|
8026
7998
|
doChangeNamedToNamespace(sourceFile, checker, changes, toConvert);
|
|
@@ -8045,7 +8017,7 @@ function doChangeNamespaceToNamed(sourceFile, checker, changes, toConvert) {
|
|
|
8045
8017
|
)) {
|
|
8046
8018
|
conflictingNames.set(exportName, true);
|
|
8047
8019
|
}
|
|
8048
|
-
|
|
8020
|
+
Debug20.assert(parent.expression === id, "Parent expression should match id");
|
|
8049
8021
|
nodesToReplace.push(parent);
|
|
8050
8022
|
}
|
|
8051
8023
|
});
|
|
@@ -8137,14 +8109,14 @@ __export(ts_refactor_extractSymbol_exports, {
|
|
|
8137
8109
|
|
|
8138
8110
|
// src/refactors/extractSymbol.ts
|
|
8139
8111
|
import {
|
|
8140
|
-
Debug as
|
|
8112
|
+
Debug as Debug21,
|
|
8141
8113
|
DiagnosticCategory,
|
|
8142
|
-
Diagnostics as
|
|
8114
|
+
Diagnostics as Diagnostics26,
|
|
8143
8115
|
EmitFlags,
|
|
8144
8116
|
ModifierFlags as ModifierFlags4,
|
|
8145
8117
|
NodeFlags as NodeFlags5,
|
|
8146
8118
|
SymbolFlags as SymbolFlags5,
|
|
8147
|
-
SyntaxKind as
|
|
8119
|
+
SyntaxKind as SyntaxKind25,
|
|
8148
8120
|
ScriptTarget as ScriptTarget7,
|
|
8149
8121
|
arrayFrom as arrayFrom4,
|
|
8150
8122
|
compareProperties,
|
|
@@ -8181,7 +8153,7 @@ import {
|
|
|
8181
8153
|
createVariableStatement as createVariableStatement2,
|
|
8182
8154
|
emptyArray as emptyArray9,
|
|
8183
8155
|
find as find6,
|
|
8184
|
-
findAncestor as
|
|
8156
|
+
findAncestor as findAncestor11,
|
|
8185
8157
|
first as first9,
|
|
8186
8158
|
forEachChild as forEachChild3,
|
|
8187
8159
|
formatStringFromArgs as formatStringFromArgs2,
|
|
@@ -8222,14 +8194,14 @@ import {
|
|
|
8222
8194
|
isVariableStatement,
|
|
8223
8195
|
last as last5,
|
|
8224
8196
|
map as map2,
|
|
8225
|
-
nullTransformationContext as
|
|
8197
|
+
nullTransformationContext as nullTransformationContext3,
|
|
8226
8198
|
positionIsSynthesized,
|
|
8227
8199
|
setEmitFlags,
|
|
8228
8200
|
singleOrUndefined as singleOrUndefined2,
|
|
8229
8201
|
textSpanEnd as textSpanEnd4,
|
|
8230
8202
|
updateArrowFunction,
|
|
8231
8203
|
updateParameter,
|
|
8232
|
-
visitEachChild as
|
|
8204
|
+
visitEachChild as visitEachChild3,
|
|
8233
8205
|
visitNode,
|
|
8234
8206
|
visitNodes as visitNodes2
|
|
8235
8207
|
} from "@tslite/parser";
|
|
@@ -8244,7 +8216,7 @@ import {
|
|
|
8244
8216
|
getRefactorContextSpan as getRefactorContextSpan3,
|
|
8245
8217
|
getRenameLocation,
|
|
8246
8218
|
getSynthesizedDeepClone as getSynthesizedDeepClone3,
|
|
8247
|
-
getTokenAtPosition as
|
|
8219
|
+
getTokenAtPosition as getTokenAtPosition25,
|
|
8248
8220
|
getUniqueName as getUniqueName2,
|
|
8249
8221
|
rangeContainsStartEnd as rangeContainsStartEnd3,
|
|
8250
8222
|
suppressLeadingAndTrailingTrivia as suppressLeadingAndTrailingTrivia2
|
|
@@ -8293,14 +8265,14 @@ function getAvailableActions(context) {
|
|
|
8293
8265
|
if (constantActions.length) {
|
|
8294
8266
|
infos.push({
|
|
8295
8267
|
name: refactorName3,
|
|
8296
|
-
description: getLocaleSpecificMessage2(
|
|
8268
|
+
description: getLocaleSpecificMessage2(Diagnostics26.Extract_constant),
|
|
8297
8269
|
actions: constantActions
|
|
8298
8270
|
});
|
|
8299
8271
|
}
|
|
8300
8272
|
if (functionActions.length) {
|
|
8301
8273
|
infos.push({
|
|
8302
8274
|
name: refactorName3,
|
|
8303
|
-
description: getLocaleSpecificMessage2(
|
|
8275
|
+
description: getLocaleSpecificMessage2(Diagnostics26.Extract_function),
|
|
8304
8276
|
actions: functionActions
|
|
8305
8277
|
});
|
|
8306
8278
|
}
|
|
@@ -8312,16 +8284,16 @@ function getEditsForAction(context, actionName) {
|
|
|
8312
8284
|
const parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
|
|
8313
8285
|
if (parsedFunctionIndexMatch) {
|
|
8314
8286
|
const index = +parsedFunctionIndexMatch[1];
|
|
8315
|
-
|
|
8287
|
+
Debug21.assert(isFinite(index), "Expected to parse a finite number from the function scope index");
|
|
8316
8288
|
return getFunctionExtractionAtIndex(targetRange, context, index);
|
|
8317
8289
|
}
|
|
8318
8290
|
const parsedConstantIndexMatch = /^constant_scope_(\d+)$/.exec(actionName);
|
|
8319
8291
|
if (parsedConstantIndexMatch) {
|
|
8320
8292
|
const index = +parsedConstantIndexMatch[1];
|
|
8321
|
-
|
|
8293
|
+
Debug21.assert(isFinite(index), "Expected to parse a finite number from the constant scope index");
|
|
8322
8294
|
return getConstantExtractionAtIndex(targetRange, context, index);
|
|
8323
8295
|
}
|
|
8324
|
-
|
|
8296
|
+
Debug21.fail("Unrecognized action name");
|
|
8325
8297
|
}
|
|
8326
8298
|
var Messages;
|
|
8327
8299
|
((Messages2) => {
|
|
@@ -8350,7 +8322,7 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8350
8322
|
if (length3 === 0) {
|
|
8351
8323
|
return { errors: [createFileDiagnostic(sourceFile, span.start, length3, Messages.cannotExtractEmpty)] };
|
|
8352
8324
|
}
|
|
8353
|
-
const start = getParentNodeInSpan3(
|
|
8325
|
+
const start = getParentNodeInSpan3(getTokenAtPosition25(sourceFile, span.start), sourceFile, span);
|
|
8354
8326
|
const end = getParentNodeInSpan3(findTokenOnLeftOfPosition(sourceFile, textSpanEnd4(span)), sourceFile, span);
|
|
8355
8327
|
const declarations = [];
|
|
8356
8328
|
let rangeFacts = 0 /* None */;
|
|
@@ -8430,8 +8402,8 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8430
8402
|
PermittedJumps2[PermittedJumps2["Continue"] = 2] = "Continue";
|
|
8431
8403
|
PermittedJumps2[PermittedJumps2["Return"] = 4] = "Return";
|
|
8432
8404
|
})(PermittedJumps || (PermittedJumps = {}));
|
|
8433
|
-
|
|
8434
|
-
|
|
8405
|
+
Debug21.assert(nodeToCheck.pos <= nodeToCheck.end, "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809 (1)");
|
|
8406
|
+
Debug21.assert(!positionIsSynthesized(nodeToCheck.pos), "This failure could trigger https://github.com/Microsoft/TypeScript/issues/20809 (2)");
|
|
8435
8407
|
if (!isStatement3(nodeToCheck) && !(isExpressionNode2(nodeToCheck) && isExtractableExpression(nodeToCheck))) {
|
|
8436
8408
|
return [createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
|
|
8437
8409
|
}
|
|
@@ -8447,7 +8419,7 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8447
8419
|
return true;
|
|
8448
8420
|
}
|
|
8449
8421
|
if (isDeclaration2(node2)) {
|
|
8450
|
-
const declaringNode = node2.kind ===
|
|
8422
|
+
const declaringNode = node2.kind === SyntaxKind25.VariableDeclaration ? node2.parent.parent : node2;
|
|
8451
8423
|
if (hasModifier2(declaringNode, ModifierFlags4.Export)) {
|
|
8452
8424
|
(errors2 || (errors2 = [])).push(createDiagnosticForNode(node2, Messages.cannotExtractExportedEntity));
|
|
8453
8425
|
return true;
|
|
@@ -8455,7 +8427,7 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8455
8427
|
declarations.push(node2.symbol);
|
|
8456
8428
|
}
|
|
8457
8429
|
switch (node2.kind) {
|
|
8458
|
-
case
|
|
8430
|
+
case SyntaxKind25.ImportDeclaration:
|
|
8459
8431
|
(errors2 || (errors2 = [])).push(createDiagnosticForNode(node2, Messages.cannotExtractImport));
|
|
8460
8432
|
return true;
|
|
8461
8433
|
}
|
|
@@ -8464,19 +8436,19 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8464
8436
|
}
|
|
8465
8437
|
const savedPermittedJumps = permittedJumps;
|
|
8466
8438
|
switch (node2.kind) {
|
|
8467
|
-
case
|
|
8439
|
+
case SyntaxKind25.IfStatement:
|
|
8468
8440
|
permittedJumps = 0 /* None */;
|
|
8469
8441
|
break;
|
|
8470
|
-
case
|
|
8442
|
+
case SyntaxKind25.TryStatement:
|
|
8471
8443
|
permittedJumps = 0 /* None */;
|
|
8472
8444
|
break;
|
|
8473
|
-
case
|
|
8474
|
-
if (node2.parent && node2.parent.kind ===
|
|
8445
|
+
case SyntaxKind25.Block:
|
|
8446
|
+
if (node2.parent && node2.parent.kind === SyntaxKind25.TryStatement && node2.parent.finallyBlock === node2) {
|
|
8475
8447
|
permittedJumps = 4 /* Return */;
|
|
8476
8448
|
}
|
|
8477
8449
|
break;
|
|
8478
|
-
case
|
|
8479
|
-
case
|
|
8450
|
+
case SyntaxKind25.DefaultClause:
|
|
8451
|
+
case SyntaxKind25.CaseClause:
|
|
8480
8452
|
permittedJumps |= 1 /* Break */;
|
|
8481
8453
|
break;
|
|
8482
8454
|
default:
|
|
@@ -8486,17 +8458,17 @@ function getRangeToExtract(sourceFile, span) {
|
|
|
8486
8458
|
break;
|
|
8487
8459
|
}
|
|
8488
8460
|
switch (node2.kind) {
|
|
8489
|
-
case
|
|
8490
|
-
case
|
|
8491
|
-
if (!(permittedJumps & (node2.kind ===
|
|
8461
|
+
case SyntaxKind25.BreakStatement:
|
|
8462
|
+
case SyntaxKind25.ContinueStatement: {
|
|
8463
|
+
if (!(permittedJumps & (node2.kind === SyntaxKind25.BreakStatement ? 1 /* Break */ : 2 /* Continue */))) {
|
|
8492
8464
|
(errors2 || (errors2 = [])).push(createDiagnosticForNode(node2, Messages.cannotExtractRangeContainingConditionalBreakOrContinueStatements));
|
|
8493
8465
|
}
|
|
8494
8466
|
break;
|
|
8495
8467
|
}
|
|
8496
|
-
case
|
|
8468
|
+
case SyntaxKind25.AwaitExpression:
|
|
8497
8469
|
rangeFacts |= 4 /* IsAsyncFunction */;
|
|
8498
8470
|
break;
|
|
8499
|
-
case
|
|
8471
|
+
case SyntaxKind25.ReturnStatement:
|
|
8500
8472
|
if (permittedJumps & 4 /* Return */) {
|
|
8501
8473
|
rangeFacts |= 1 /* HasReturn */;
|
|
8502
8474
|
} else {
|
|
@@ -8527,12 +8499,12 @@ function collectEnclosingScopes(range) {
|
|
|
8527
8499
|
const scopes = [];
|
|
8528
8500
|
while (true) {
|
|
8529
8501
|
current = current.parent;
|
|
8530
|
-
if (current.kind ===
|
|
8531
|
-
current =
|
|
8502
|
+
if (current.kind === SyntaxKind25.Parameter) {
|
|
8503
|
+
current = findAncestor11(current, (parent) => isFunctionLikeDeclaration3(parent)).parent;
|
|
8532
8504
|
}
|
|
8533
8505
|
if (isScope(current)) {
|
|
8534
8506
|
scopes.push(current);
|
|
8535
|
-
if (current.kind ===
|
|
8507
|
+
if (current.kind === SyntaxKind25.SourceFile) {
|
|
8536
8508
|
return scopes;
|
|
8537
8509
|
}
|
|
8538
8510
|
}
|
|
@@ -8540,14 +8512,14 @@ function collectEnclosingScopes(range) {
|
|
|
8540
8512
|
}
|
|
8541
8513
|
function getFunctionExtractionAtIndex(targetRange, context, requestedChangesIndex) {
|
|
8542
8514
|
const { scopes, readsAndWrites: { target, usagesPerScope, functionErrorsPerScope, exposedVariableDeclarations } } = getPossibleExtractionsWorker(targetRange, context);
|
|
8543
|
-
|
|
8515
|
+
Debug21.assert(!functionErrorsPerScope[requestedChangesIndex].length, "The extraction went missing? How?");
|
|
8544
8516
|
context.cancellationToken.throwIfCancellationRequested();
|
|
8545
8517
|
return extractFunctionInScope(target, scopes[requestedChangesIndex], usagesPerScope[requestedChangesIndex], exposedVariableDeclarations, targetRange, context);
|
|
8546
8518
|
}
|
|
8547
8519
|
function getConstantExtractionAtIndex(targetRange, context, requestedChangesIndex) {
|
|
8548
8520
|
const { scopes, readsAndWrites: { target, usagesPerScope, constantErrorsPerScope, exposedVariableDeclarations } } = getPossibleExtractionsWorker(targetRange, context);
|
|
8549
|
-
|
|
8550
|
-
|
|
8521
|
+
Debug21.assert(!constantErrorsPerScope[requestedChangesIndex].length, "The extraction went missing? How?");
|
|
8522
|
+
Debug21.assert(exposedVariableDeclarations.length === 0, "Extract constant accepted a range containing a variable declaration?");
|
|
8551
8523
|
context.cancellationToken.throwIfCancellationRequested();
|
|
8552
8524
|
const expression = isExpression4(target) ? target : target.statements[0].expression;
|
|
8553
8525
|
return extractConstantInScope(expression, scopes[requestedChangesIndex], usagesPerScope[requestedChangesIndex], context);
|
|
@@ -8561,17 +8533,17 @@ function getPossibleExtractions(targetRange, context) {
|
|
|
8561
8533
|
let functionDescription;
|
|
8562
8534
|
let constantDescription;
|
|
8563
8535
|
if (scopeDescription === 1 /* Global */) {
|
|
8564
|
-
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8565
|
-
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8536
|
+
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1_scope), [functionDescriptionPart, "global"]);
|
|
8537
|
+
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1_scope), [constantDescriptionPart, "global"]);
|
|
8566
8538
|
} else if (scopeDescription === 0 /* Module */) {
|
|
8567
|
-
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8568
|
-
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8539
|
+
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1_scope), [functionDescriptionPart, "module"]);
|
|
8540
|
+
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1_scope), [constantDescriptionPart, "module"]);
|
|
8569
8541
|
} else {
|
|
8570
|
-
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8571
|
-
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8542
|
+
functionDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1), [functionDescriptionPart, scopeDescription]);
|
|
8543
|
+
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_1), [constantDescriptionPart, scopeDescription]);
|
|
8572
8544
|
}
|
|
8573
8545
|
if (i === 0) {
|
|
8574
|
-
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(
|
|
8546
|
+
constantDescription = formatStringFromArgs2(getLocaleSpecificMessage2(Diagnostics26.Extract_to_0_in_enclosing_scope), [constantDescriptionPart]);
|
|
8575
8547
|
}
|
|
8576
8548
|
return {
|
|
8577
8549
|
functionExtraction: {
|
|
@@ -8610,7 +8582,7 @@ function getDescriptionForFunctionLikeDeclaration(_scope) {
|
|
|
8610
8582
|
return "arrow function";
|
|
8611
8583
|
}
|
|
8612
8584
|
function getDescriptionForModuleLikeDeclaration(scope) {
|
|
8613
|
-
return scope.kind ===
|
|
8585
|
+
return scope.kind === SyntaxKind25.ModuleBlock ? `namespace '${scope.parent.name.getText()}'` : scope.externalModuleIndicator ? 0 /* Module */ : 1 /* Global */;
|
|
8614
8586
|
}
|
|
8615
8587
|
function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParameterUsages, substitutions }, exposedVariableDeclarations, range, context) {
|
|
8616
8588
|
const checker = context.program.getTypeChecker();
|
|
@@ -8667,7 +8639,7 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
8667
8639
|
/*type*/
|
|
8668
8640
|
void 0,
|
|
8669
8641
|
createArrowFunction(
|
|
8670
|
-
range.facts & 4 /* IsAsyncFunction */ ? [createToken3(
|
|
8642
|
+
range.facts & 4 /* IsAsyncFunction */ ? [createToken3(SyntaxKind25.AsyncKeyword)] : void 0,
|
|
8671
8643
|
typeParameters,
|
|
8672
8644
|
parameters,
|
|
8673
8645
|
returnType,
|
|
@@ -8710,8 +8682,8 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
8710
8682
|
call = createAwait3(call);
|
|
8711
8683
|
}
|
|
8712
8684
|
if (exposedVariableDeclarations.length && !writes) {
|
|
8713
|
-
|
|
8714
|
-
|
|
8685
|
+
Debug21.assert(!returnValueProperty, "Expected no returnValueProperty");
|
|
8686
|
+
Debug21.assert(!(range.facts & 1 /* HasReturn */), "Expected RangeFacts.HasReturn flag to be unset");
|
|
8715
8687
|
if (exposedVariableDeclarations.length === 1) {
|
|
8716
8688
|
const variableDeclaration = exposedVariableDeclarations[0];
|
|
8717
8689
|
newNodes.push(createVariableStatement2(
|
|
@@ -8814,7 +8786,7 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
8814
8786
|
assignments.unshift(createShorthandPropertyAssignment(returnValueProperty));
|
|
8815
8787
|
}
|
|
8816
8788
|
if (assignments.length === 1) {
|
|
8817
|
-
|
|
8789
|
+
Debug21.assert(!returnValueProperty, "Shouldn't have returnValueProperty here");
|
|
8818
8790
|
newNodes.push(createStatement(createAssignment2(assignments[0].name, call)));
|
|
8819
8791
|
if (range.facts & 1 /* HasReturn */) {
|
|
8820
8792
|
newNodes.push(createReturn3());
|
|
@@ -8859,7 +8831,7 @@ function extractFunctionInScope(node, scope, { usages: usagesInScope, typeParame
|
|
|
8859
8831
|
while (isParenthesizedTypeNode(withoutParens)) {
|
|
8860
8832
|
withoutParens = withoutParens.type;
|
|
8861
8833
|
}
|
|
8862
|
-
return isUnionTypeNode(withoutParens) && find6(withoutParens.types, (t) => t.kind ===
|
|
8834
|
+
return isUnionTypeNode(withoutParens) && find6(withoutParens.types, (t) => t.kind === SyntaxKind25.UndefinedKeyword) ? clone : createUnionTypeNode([clone, createKeywordTypeNode3(SyntaxKind25.UndefinedKeyword)]);
|
|
8863
8835
|
}
|
|
8864
8836
|
}
|
|
8865
8837
|
function extractConstantInScope(node, scope, { substitutions }, context) {
|
|
@@ -8877,7 +8849,7 @@ function extractConstantInScope(node, scope, { substitutions }, context) {
|
|
|
8877
8849
|
changeTracker.insertNodeBefore(context.file, oldVariableDeclaration, newVariableDeclaration);
|
|
8878
8850
|
const localReference = createIdentifier9(localNameText);
|
|
8879
8851
|
changeTracker.replaceNode(context.file, node, localReference);
|
|
8880
|
-
} else if (node.parent.kind ===
|
|
8852
|
+
} else if (node.parent.kind === SyntaxKind25.ExpressionStatement && scope === findAncestor11(node, isScope)) {
|
|
8881
8853
|
const newVariableStatement = createVariableStatement2(
|
|
8882
8854
|
/*modifiers*/
|
|
8883
8855
|
void 0,
|
|
@@ -8907,7 +8879,7 @@ function extractConstantInScope(node, scope, { substitutions }, context) {
|
|
|
8907
8879
|
false
|
|
8908
8880
|
);
|
|
8909
8881
|
}
|
|
8910
|
-
if (node.parent.kind ===
|
|
8882
|
+
if (node.parent.kind === SyntaxKind25.ExpressionStatement) {
|
|
8911
8883
|
changeTracker.delete(context.file, node.parent);
|
|
8912
8884
|
} else {
|
|
8913
8885
|
const localReference = createIdentifier9(localNameText);
|
|
@@ -9027,7 +8999,7 @@ function transformFunctionBody(body, exposedVariableDeclarations, writes, substi
|
|
|
9027
8999
|
), returnValueProperty: void 0 };
|
|
9028
9000
|
}
|
|
9029
9001
|
function visitor(node) {
|
|
9030
|
-
if (!ignoreReturns && node.kind ===
|
|
9002
|
+
if (!ignoreReturns && node.kind === SyntaxKind25.ReturnStatement && hasWritesOrVariableDeclarations) {
|
|
9031
9003
|
const assignments = getPropertyAssignmentsForWritesAndVariableDeclarations(exposedVariableDeclarations, writes);
|
|
9032
9004
|
if (node.expression) {
|
|
9033
9005
|
if (!returnValueProperty) {
|
|
@@ -9044,7 +9016,7 @@ function transformFunctionBody(body, exposedVariableDeclarations, writes, substi
|
|
|
9044
9016
|
const oldIgnoreReturns = ignoreReturns;
|
|
9045
9017
|
ignoreReturns = ignoreReturns || isFunctionLikeDeclaration3(node);
|
|
9046
9018
|
const substitution = substitutions.get(getNodeId6(node).toString());
|
|
9047
|
-
const result = substitution ? getSynthesizedDeepClone3(substitution) :
|
|
9019
|
+
const result = substitution ? getSynthesizedDeepClone3(substitution) : visitEachChild3(node, visitor, nullTransformationContext3);
|
|
9048
9020
|
ignoreReturns = oldIgnoreReturns;
|
|
9049
9021
|
return result;
|
|
9050
9022
|
}
|
|
@@ -9054,7 +9026,7 @@ function transformConstantInitializer(initializer, substitutions) {
|
|
|
9054
9026
|
return substitutions.size ? visitor(initializer) : initializer;
|
|
9055
9027
|
function visitor(node) {
|
|
9056
9028
|
const substitution = substitutions.get(getNodeId6(node).toString());
|
|
9057
|
-
return substitution ? getSynthesizedDeepClone3(substitution) :
|
|
9029
|
+
return substitution ? getSynthesizedDeepClone3(substitution) : visitEachChild3(node, visitor, nullTransformationContext3);
|
|
9058
9030
|
}
|
|
9059
9031
|
}
|
|
9060
9032
|
function getNodeToInsertConstantBefore(node, scope) {
|
|
@@ -9074,12 +9046,12 @@ function getNodeToInsertConstantBefore(node, scope) {
|
|
|
9074
9046
|
prevStatement = statement;
|
|
9075
9047
|
}
|
|
9076
9048
|
if (!prevStatement && isCaseClause(curr)) {
|
|
9077
|
-
|
|
9049
|
+
Debug21.assert(isSwitchStatement(curr.parent.parent), "Grandparent isn't a switch statement");
|
|
9078
9050
|
return curr.parent.parent;
|
|
9079
9051
|
}
|
|
9080
|
-
return
|
|
9052
|
+
return Debug21.checkDefined(prevStatement, "prevStatement failed to get set");
|
|
9081
9053
|
}
|
|
9082
|
-
|
|
9054
|
+
Debug21.assert(curr !== scope, "Didn't encounter a block-like before encountering scope");
|
|
9083
9055
|
}
|
|
9084
9056
|
}
|
|
9085
9057
|
function getPropertyAssignmentsForWritesAndVariableDeclarations(exposedVariableDeclarations, writes) {
|
|
@@ -9156,7 +9128,7 @@ function collectReadsAndWrites(targetRange, scopes, enclosingTextRange, sourceFi
|
|
|
9156
9128
|
}
|
|
9157
9129
|
}
|
|
9158
9130
|
}
|
|
9159
|
-
|
|
9131
|
+
Debug21.assert(i === scopes.length, "Should have iterated all scopes");
|
|
9160
9132
|
}
|
|
9161
9133
|
if (visibleDeclarationsInExtractedRange.length) {
|
|
9162
9134
|
const containingLexicalScopeOfExtraction = isBlockScope(scopes[0], scopes[0].parent) ? scopes[0] : getEnclosingBlockScopeContainer(scopes[0]);
|
|
@@ -9174,7 +9146,7 @@ function collectReadsAndWrites(targetRange, scopes, enclosingTextRange, sourceFi
|
|
|
9174
9146
|
hasWrite = true;
|
|
9175
9147
|
}
|
|
9176
9148
|
});
|
|
9177
|
-
|
|
9149
|
+
Debug21.assert(isReadonlyArray(targetRange.range) || exposedVariableDeclarations.length === 0, "No variable declarations expected if something was extracted");
|
|
9178
9150
|
if (hasWrite && !isReadonlyArray(targetRange.range)) {
|
|
9179
9151
|
const diag = createDiagnosticForNode(targetRange.range, Messages.cannotWriteInExpression);
|
|
9180
9152
|
functionErrorsPerScope[i].push(diag);
|
|
@@ -9187,7 +9159,7 @@ function collectReadsAndWrites(targetRange, scopes, enclosingTextRange, sourceFi
|
|
|
9187
9159
|
}
|
|
9188
9160
|
return { target, usagesPerScope, functionErrorsPerScope, constantErrorsPerScope, exposedVariableDeclarations };
|
|
9189
9161
|
function isInGenericContext(node) {
|
|
9190
|
-
return !!
|
|
9162
|
+
return !!findAncestor11(node, (n) => isDeclarationWithTypeParameters(n) && getEffectiveTypeParameterDeclarations(n).length !== 0);
|
|
9191
9163
|
}
|
|
9192
9164
|
function recordTypeParameterUsages(type) {
|
|
9193
9165
|
const symbolWalker = checker.getSymbolWalker(() => (cancellationToken.throwIfCancellationRequested(), true));
|
|
@@ -9343,23 +9315,23 @@ function collectReadsAndWrites(targetRange, scopes, enclosingTextRange, sourceFi
|
|
|
9343
9315
|
function isExtractableExpression(node) {
|
|
9344
9316
|
const { parent } = node;
|
|
9345
9317
|
switch (node.kind) {
|
|
9346
|
-
case
|
|
9347
|
-
return parent.kind !==
|
|
9348
|
-
case
|
|
9349
|
-
case
|
|
9350
|
-
case
|
|
9318
|
+
case SyntaxKind25.StringLiteral:
|
|
9319
|
+
return parent.kind !== SyntaxKind25.ImportDeclaration && parent.kind !== SyntaxKind25.ImportSpecifier;
|
|
9320
|
+
case SyntaxKind25.SpreadElement:
|
|
9321
|
+
case SyntaxKind25.ObjectBindingPattern:
|
|
9322
|
+
case SyntaxKind25.BindingElement:
|
|
9351
9323
|
return false;
|
|
9352
|
-
case
|
|
9353
|
-
return parent.kind !==
|
|
9324
|
+
case SyntaxKind25.Identifier:
|
|
9325
|
+
return parent.kind !== SyntaxKind25.BindingElement && parent.kind !== SyntaxKind25.ImportSpecifier && parent.kind !== SyntaxKind25.ExportSpecifier;
|
|
9354
9326
|
}
|
|
9355
9327
|
return true;
|
|
9356
9328
|
}
|
|
9357
9329
|
function isBlockLike(node) {
|
|
9358
9330
|
switch (node.kind) {
|
|
9359
|
-
case
|
|
9360
|
-
case
|
|
9361
|
-
case
|
|
9362
|
-
case
|
|
9331
|
+
case SyntaxKind25.Block:
|
|
9332
|
+
case SyntaxKind25.SourceFile:
|
|
9333
|
+
case SyntaxKind25.ModuleBlock:
|
|
9334
|
+
case SyntaxKind25.CaseClause:
|
|
9363
9335
|
return true;
|
|
9364
9336
|
default:
|
|
9365
9337
|
return false;
|
|
@@ -9368,14 +9340,14 @@ function isBlockLike(node) {
|
|
|
9368
9340
|
|
|
9369
9341
|
// src/refactors/extractType.ts
|
|
9370
9342
|
import {
|
|
9371
|
-
Debug as
|
|
9372
|
-
Diagnostics as
|
|
9343
|
+
Debug as Debug22,
|
|
9344
|
+
Diagnostics as Diagnostics27,
|
|
9373
9345
|
SymbolFlags as SymbolFlags6,
|
|
9374
9346
|
cast as cast7,
|
|
9375
9347
|
createTypeAliasDeclaration as createTypeAliasDeclaration2,
|
|
9376
9348
|
createTypeReferenceNode as createTypeReferenceNode6,
|
|
9377
9349
|
emptyArray as emptyArray10,
|
|
9378
|
-
findAncestor as
|
|
9350
|
+
findAncestor as findAncestor12,
|
|
9379
9351
|
first as first10,
|
|
9380
9352
|
forEachChild as forEachChild4,
|
|
9381
9353
|
getLocaleSpecificMessage as getLocaleSpecificMessage3,
|
|
@@ -9397,7 +9369,7 @@ import {
|
|
|
9397
9369
|
createTextRangeFromSpan as createTextRangeFromSpan2,
|
|
9398
9370
|
getRefactorContextSpan as getRefactorContextSpan4,
|
|
9399
9371
|
getRenameLocation as getRenameLocation2,
|
|
9400
|
-
getTokenAtPosition as
|
|
9372
|
+
getTokenAtPosition as getTokenAtPosition26,
|
|
9401
9373
|
getUniqueName as getUniqueName3,
|
|
9402
9374
|
rangeContainsStartEnd as rangeContainsStartEnd4
|
|
9403
9375
|
} from "@tslite/services";
|
|
@@ -9409,23 +9381,23 @@ registerRefactor(refactorName4, {
|
|
|
9409
9381
|
if (!info) return emptyArray10;
|
|
9410
9382
|
return [{
|
|
9411
9383
|
name: refactorName4,
|
|
9412
|
-
description: getLocaleSpecificMessage3(
|
|
9384
|
+
description: getLocaleSpecificMessage3(Diagnostics27.Extract_type),
|
|
9413
9385
|
actions: [{
|
|
9414
9386
|
name: extractToTypeAlias,
|
|
9415
|
-
description: getLocaleSpecificMessage3(
|
|
9387
|
+
description: getLocaleSpecificMessage3(Diagnostics27.Extract_to_type_alias)
|
|
9416
9388
|
}]
|
|
9417
9389
|
}];
|
|
9418
9390
|
},
|
|
9419
9391
|
getEditsForAction(context, actionName) {
|
|
9420
9392
|
const { file } = context;
|
|
9421
|
-
const info =
|
|
9393
|
+
const info = Debug22.checkDefined(getRangeToExtract2(context), "Expected to find a range to extract");
|
|
9422
9394
|
const name = getUniqueName3("NewType", file);
|
|
9423
9395
|
const edits = ts_textChanges_exports.ChangeTracker.with(context, (changes) => {
|
|
9424
9396
|
switch (actionName) {
|
|
9425
9397
|
case extractToTypeAlias:
|
|
9426
9398
|
return doTypeAliasChange(changes, file, name, info);
|
|
9427
9399
|
default:
|
|
9428
|
-
|
|
9400
|
+
Debug22.fail("Unexpected action name");
|
|
9429
9401
|
}
|
|
9430
9402
|
});
|
|
9431
9403
|
const renameFilename = file.fileName;
|
|
@@ -9441,12 +9413,12 @@ registerRefactor(refactorName4, {
|
|
|
9441
9413
|
});
|
|
9442
9414
|
function getRangeToExtract2(context) {
|
|
9443
9415
|
const { file, startPosition } = context;
|
|
9444
|
-
const current =
|
|
9416
|
+
const current = getTokenAtPosition26(file, startPosition);
|
|
9445
9417
|
const range = createTextRangeFromSpan2(getRefactorContextSpan4(context));
|
|
9446
|
-
const selection =
|
|
9418
|
+
const selection = findAncestor12(current, ((node) => node.parent && rangeContainsSkipTrivia(range, node, file) && !rangeContainsSkipTrivia(range, node.parent, file)));
|
|
9447
9419
|
if (!selection || !isTypeNode(selection)) return void 0;
|
|
9448
9420
|
const checker = context.program.getTypeChecker();
|
|
9449
|
-
const firstStatement =
|
|
9421
|
+
const firstStatement = Debug22.checkDefined(findAncestor12(selection, isStatement4), "Should find a statement");
|
|
9450
9422
|
const typeParameters = collectTypeParameters(checker, selection, firstStatement, file);
|
|
9451
9423
|
if (!typeParameters) return void 0;
|
|
9452
9424
|
return { selection, firstStatement, typeParameters };
|
|
@@ -9475,12 +9447,12 @@ function collectTypeParameters(checker, selection, statement, file) {
|
|
|
9475
9447
|
}
|
|
9476
9448
|
}
|
|
9477
9449
|
} else if (isInferTypeNode2(node)) {
|
|
9478
|
-
const conditionalTypeNode =
|
|
9450
|
+
const conditionalTypeNode = findAncestor12(node, (n) => isConditionalTypeNode(n) && rangeContainsSkipTrivia(n.extendsType, node, file));
|
|
9479
9451
|
if (!conditionalTypeNode || !rangeContainsSkipTrivia(selection, conditionalTypeNode, file)) {
|
|
9480
9452
|
return true;
|
|
9481
9453
|
}
|
|
9482
9454
|
} else if (isTypePredicateNode(node)) {
|
|
9483
|
-
const functionLikeNode =
|
|
9455
|
+
const functionLikeNode = findAncestor12(node.parent, isFunctionLike3);
|
|
9484
9456
|
if (functionLikeNode && functionLikeNode.type && rangeContainsSkipTrivia(functionLikeNode.type, node, file) && !rangeContainsSkipTrivia(selection, functionLikeNode, file)) {
|
|
9485
9457
|
return true;
|
|
9486
9458
|
}
|
|
@@ -9532,12 +9504,12 @@ function doTypeAliasChange(changes, file, name, info) {
|
|
|
9532
9504
|
|
|
9533
9505
|
// src/refactors/moveToNewFile.ts
|
|
9534
9506
|
import {
|
|
9535
|
-
Debug as
|
|
9536
|
-
Diagnostics as
|
|
9507
|
+
Debug as Debug23,
|
|
9508
|
+
Diagnostics as Diagnostics28,
|
|
9537
9509
|
ModifierFlags as ModifierFlags5,
|
|
9538
9510
|
ScriptTarget as ScriptTarget8,
|
|
9539
9511
|
SymbolFlags as SymbolFlags7,
|
|
9540
|
-
SyntaxKind as
|
|
9512
|
+
SyntaxKind as SyntaxKind26,
|
|
9541
9513
|
append as append3,
|
|
9542
9514
|
cast as cast8,
|
|
9543
9515
|
combinePaths,
|
|
@@ -9605,12 +9577,12 @@ var refactorName5 = "Move to a new file";
|
|
|
9605
9577
|
registerRefactor(refactorName5, {
|
|
9606
9578
|
getAvailableActions(context) {
|
|
9607
9579
|
if (!context.preferences.allowTextChangesInNewFiles || getStatementsToMove(context) === void 0) return emptyArray11;
|
|
9608
|
-
const description = getLocaleSpecificMessage4(
|
|
9580
|
+
const description = getLocaleSpecificMessage4(Diagnostics28.Move_to_a_new_file);
|
|
9609
9581
|
return [{ name: refactorName5, description, actions: [{ name: refactorName5, description }] }];
|
|
9610
9582
|
},
|
|
9611
9583
|
getEditsForAction(context, actionName) {
|
|
9612
|
-
|
|
9613
|
-
const statements =
|
|
9584
|
+
Debug23.assert(actionName === refactorName5, "Wrong refactor invoked");
|
|
9585
|
+
const statements = Debug23.checkDefined(getStatementsToMove(context));
|
|
9614
9586
|
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange14(context.file, context.program, statements, t, context.host, context.preferences));
|
|
9615
9587
|
return { edits, renameFilename: void 0, renameLocation: void 0 };
|
|
9616
9588
|
}
|
|
@@ -9656,7 +9628,7 @@ function getStatementsToMove(context) {
|
|
|
9656
9628
|
}
|
|
9657
9629
|
function isPureImport(node) {
|
|
9658
9630
|
switch (node.kind) {
|
|
9659
|
-
case
|
|
9631
|
+
case SyntaxKind26.ImportDeclaration:
|
|
9660
9632
|
return true;
|
|
9661
9633
|
default:
|
|
9662
9634
|
return false;
|
|
@@ -9721,10 +9693,10 @@ function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newM
|
|
|
9721
9693
|
}
|
|
9722
9694
|
function getNamespaceLikeImport(node) {
|
|
9723
9695
|
switch (node.kind) {
|
|
9724
|
-
case
|
|
9725
|
-
return node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind ===
|
|
9696
|
+
case SyntaxKind26.ImportDeclaration:
|
|
9697
|
+
return node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind26.NamespaceImport ? node.importClause.namedBindings.name : void 0;
|
|
9726
9698
|
default:
|
|
9727
|
-
return
|
|
9699
|
+
return Debug23.assertNever(node.kind, `Unexpected node kind ${node.kind}`);
|
|
9728
9700
|
}
|
|
9729
9701
|
}
|
|
9730
9702
|
function updateNamespaceLikeImport(changes, sourceFile, checker, movedSymbols, newModuleName, newModuleSpecifier, oldImportId, oldImportNode) {
|
|
@@ -9756,7 +9728,7 @@ function updateNamespaceLikeImportNode(node, newNamespaceName, newModuleSpecifie
|
|
|
9756
9728
|
const newNamespaceId = createIdentifier10(newNamespaceName);
|
|
9757
9729
|
const newModuleString = createLiteral3(newModuleSpecifier);
|
|
9758
9730
|
switch (node.kind) {
|
|
9759
|
-
case
|
|
9731
|
+
case SyntaxKind26.ImportDeclaration:
|
|
9760
9732
|
return createImportDeclaration3(
|
|
9761
9733
|
/*modifiers*/
|
|
9762
9734
|
void 0,
|
|
@@ -9768,7 +9740,7 @@ function updateNamespaceLikeImportNode(node, newNamespaceName, newModuleSpecifie
|
|
|
9768
9740
|
newModuleString
|
|
9769
9741
|
);
|
|
9770
9742
|
default:
|
|
9771
|
-
return
|
|
9743
|
+
return Debug23.assertNever(node.kind, `Unexpected node kind ${node.kind}`);
|
|
9772
9744
|
}
|
|
9773
9745
|
}
|
|
9774
9746
|
function moduleSpecifierFromImport(i) {
|
|
@@ -9803,7 +9775,7 @@ function makeImportOrRequire(defaultImport, imports, path, quotePreference) {
|
|
|
9803
9775
|
}
|
|
9804
9776
|
function addExports(sourceFile, toMove, needExport) {
|
|
9805
9777
|
return flatMap6(toMove, (statement) => {
|
|
9806
|
-
if (isTopLevelDeclarationStatement(statement) && !isExported(sourceFile, statement) && forEachTopLevelDeclaration(statement, (d) => needExport.has(
|
|
9778
|
+
if (isTopLevelDeclarationStatement(statement) && !isExported(sourceFile, statement) && forEachTopLevelDeclaration(statement, (d) => needExport.has(Debug23.checkDefined(d.symbol)))) {
|
|
9807
9779
|
const exports = addExport(statement);
|
|
9808
9780
|
if (exports) return exports;
|
|
9809
9781
|
}
|
|
@@ -9812,18 +9784,18 @@ function addExports(sourceFile, toMove, needExport) {
|
|
|
9812
9784
|
}
|
|
9813
9785
|
function deleteUnusedImports(sourceFile, importDecl, changes, isUnused) {
|
|
9814
9786
|
switch (importDecl.kind) {
|
|
9815
|
-
case
|
|
9787
|
+
case SyntaxKind26.ImportDeclaration:
|
|
9816
9788
|
deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnused);
|
|
9817
9789
|
break;
|
|
9818
9790
|
default:
|
|
9819
|
-
|
|
9791
|
+
Debug23.assertNever(importDecl.kind, `Unexpected import decl kind ${importDecl.kind}`);
|
|
9820
9792
|
}
|
|
9821
9793
|
}
|
|
9822
9794
|
function deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnused) {
|
|
9823
9795
|
if (!importDecl.importClause) return;
|
|
9824
9796
|
const { name, namedBindings } = importDecl.importClause;
|
|
9825
9797
|
const defaultUnused = !name || isUnused(name);
|
|
9826
|
-
const namedBindingsUnused = !namedBindings || (namedBindings.kind ===
|
|
9798
|
+
const namedBindingsUnused = !namedBindings || (namedBindings.kind === SyntaxKind26.NamespaceImport ? isUnused(namedBindings.name) : namedBindings.elements.length !== 0 && namedBindings.elements.every((e) => isUnused(e.name)));
|
|
9827
9799
|
if (defaultUnused && namedBindingsUnused) {
|
|
9828
9800
|
changes.delete(sourceFile, importDecl);
|
|
9829
9801
|
} else {
|
|
@@ -9843,7 +9815,7 @@ function deleteUnusedImportsInDeclaration(sourceFile, importDecl, changes, isUnu
|
|
|
9843
9815
|
importDecl.importClause.isTypeOnly
|
|
9844
9816
|
)
|
|
9845
9817
|
);
|
|
9846
|
-
} else if (namedBindings.kind ===
|
|
9818
|
+
} else if (namedBindings.kind === SyntaxKind26.NamedImports) {
|
|
9847
9819
|
for (const element of namedBindings.elements) {
|
|
9848
9820
|
if (isUnused(element.name)) changes.delete(sourceFile, element);
|
|
9849
9821
|
}
|
|
@@ -9898,7 +9870,7 @@ function getUsageInfo(oldFile, toMove, checker) {
|
|
|
9898
9870
|
const newFileImportsFromOldFile = new SymbolSet();
|
|
9899
9871
|
for (const statement of toMove) {
|
|
9900
9872
|
forEachTopLevelDeclaration(statement, (decl) => {
|
|
9901
|
-
movedSymbols.add(
|
|
9873
|
+
movedSymbols.add(Debug23.checkDefined(decl.symbol, "Need a symbol here"));
|
|
9902
9874
|
});
|
|
9903
9875
|
}
|
|
9904
9876
|
for (const statement of toMove) {
|
|
@@ -9926,9 +9898,9 @@ function getUsageInfo(oldFile, toMove, checker) {
|
|
|
9926
9898
|
}
|
|
9927
9899
|
function isInImport(decl) {
|
|
9928
9900
|
switch (decl.kind) {
|
|
9929
|
-
case
|
|
9930
|
-
case
|
|
9931
|
-
case
|
|
9901
|
+
case SyntaxKind26.ImportSpecifier:
|
|
9902
|
+
case SyntaxKind26.ImportClause:
|
|
9903
|
+
case SyntaxKind26.NamespaceImport:
|
|
9932
9904
|
return true;
|
|
9933
9905
|
default:
|
|
9934
9906
|
return false;
|
|
@@ -9936,7 +9908,7 @@ function isInImport(decl) {
|
|
|
9936
9908
|
}
|
|
9937
9909
|
function filterImport(i, moduleSpecifier, keep) {
|
|
9938
9910
|
switch (i.kind) {
|
|
9939
|
-
case
|
|
9911
|
+
case SyntaxKind26.ImportDeclaration: {
|
|
9940
9912
|
const clause = i.importClause;
|
|
9941
9913
|
if (!clause) return void 0;
|
|
9942
9914
|
const defaultImport = clause.name && keep(clause.name) ? clause.name : void 0;
|
|
@@ -9949,11 +9921,11 @@ function filterImport(i, moduleSpecifier, keep) {
|
|
|
9949
9921
|
) : void 0;
|
|
9950
9922
|
}
|
|
9951
9923
|
default:
|
|
9952
|
-
return
|
|
9924
|
+
return Debug23.assertNever(i.kind, `Unexpected import kind ${i.kind}`);
|
|
9953
9925
|
}
|
|
9954
9926
|
}
|
|
9955
9927
|
function filterNamedBindings(namedBindings, keep) {
|
|
9956
|
-
if (namedBindings.kind ===
|
|
9928
|
+
if (namedBindings.kind === SyntaxKind26.NamespaceImport) {
|
|
9957
9929
|
return keep(namedBindings.name) ? namedBindings : void 0;
|
|
9958
9930
|
} else {
|
|
9959
9931
|
const newElements = namedBindings.elements.filter((e) => keep(e.name));
|
|
@@ -10002,13 +9974,13 @@ function sourceFileOfTopLevelDeclaration(node) {
|
|
|
10002
9974
|
return isVariableDeclaration7(node) ? node.parent.parent.parent : node.parent;
|
|
10003
9975
|
}
|
|
10004
9976
|
function isTopLevelDeclarationStatement(node) {
|
|
10005
|
-
|
|
9977
|
+
Debug23.assert(isSourceFile4(node.parent), "Node parent should be a SourceFile");
|
|
10006
9978
|
return isNonVariableTopLevelDeclaration(node) || isVariableStatement2(node);
|
|
10007
9979
|
}
|
|
10008
9980
|
function isNonVariableTopLevelDeclaration(node) {
|
|
10009
9981
|
switch (node.kind) {
|
|
10010
|
-
case
|
|
10011
|
-
case
|
|
9982
|
+
case SyntaxKind26.ModuleDeclaration:
|
|
9983
|
+
case SyntaxKind26.TypeAliasDeclaration:
|
|
10012
9984
|
return true;
|
|
10013
9985
|
default:
|
|
10014
9986
|
return false;
|
|
@@ -10016,22 +9988,22 @@ function isNonVariableTopLevelDeclaration(node) {
|
|
|
10016
9988
|
}
|
|
10017
9989
|
function forEachTopLevelDeclaration(statement, cb) {
|
|
10018
9990
|
switch (statement.kind) {
|
|
10019
|
-
case
|
|
10020
|
-
case
|
|
9991
|
+
case SyntaxKind26.ModuleDeclaration:
|
|
9992
|
+
case SyntaxKind26.TypeAliasDeclaration:
|
|
10021
9993
|
return cb(statement);
|
|
10022
|
-
case
|
|
9994
|
+
case SyntaxKind26.VariableStatement:
|
|
10023
9995
|
return firstDefined2(statement.declarationList.declarations, (decl) => forEachTopLevelDeclarationInBindingName(decl.name, cb));
|
|
10024
9996
|
}
|
|
10025
9997
|
}
|
|
10026
9998
|
function forEachTopLevelDeclarationInBindingName(name, cb) {
|
|
10027
9999
|
switch (name.kind) {
|
|
10028
|
-
case
|
|
10000
|
+
case SyntaxKind26.Identifier:
|
|
10029
10001
|
return cb(cast8(name.parent, (x) => isVariableDeclaration7(x) || isBindingElement2(x)));
|
|
10030
|
-
case
|
|
10031
|
-
case
|
|
10002
|
+
case SyntaxKind26.ArrayBindingPattern:
|
|
10003
|
+
case SyntaxKind26.ObjectBindingPattern:
|
|
10032
10004
|
return firstDefined2(name.elements, (em) => isOmittedExpression2(em) ? void 0 : forEachTopLevelDeclarationInBindingName(em.name, cb));
|
|
10033
10005
|
default:
|
|
10034
|
-
return
|
|
10006
|
+
return Debug23.assertNever(name, `Unexpected name kind ${name.kind}`);
|
|
10035
10007
|
}
|
|
10036
10008
|
}
|
|
10037
10009
|
function nameOfTopLevelDeclaration(d) {
|
|
@@ -10039,9 +10011,9 @@ function nameOfTopLevelDeclaration(d) {
|
|
|
10039
10011
|
}
|
|
10040
10012
|
function getTopLevelDeclarationStatement(d) {
|
|
10041
10013
|
switch (d.kind) {
|
|
10042
|
-
case
|
|
10014
|
+
case SyntaxKind26.VariableDeclaration:
|
|
10043
10015
|
return d.parent.parent;
|
|
10044
|
-
case
|
|
10016
|
+
case SyntaxKind26.BindingElement:
|
|
10045
10017
|
return getTopLevelDeclarationStatement(
|
|
10046
10018
|
cast8(d.parent.parent, (p) => isVariableDeclaration7(p) || isBindingElement2(p))
|
|
10047
10019
|
);
|
|
@@ -10060,16 +10032,16 @@ function addExport(decl) {
|
|
|
10060
10032
|
return [addEs6Export(decl)];
|
|
10061
10033
|
}
|
|
10062
10034
|
function addEs6Export(d) {
|
|
10063
|
-
const modifiers = concatenate([createModifier2(
|
|
10035
|
+
const modifiers = concatenate([createModifier2(SyntaxKind26.ExportKeyword)], d.modifiers);
|
|
10064
10036
|
switch (d.kind) {
|
|
10065
|
-
case
|
|
10037
|
+
case SyntaxKind26.VariableStatement:
|
|
10066
10038
|
return updateVariableStatement(d, modifiers, d.declarationList);
|
|
10067
|
-
case
|
|
10039
|
+
case SyntaxKind26.ModuleDeclaration:
|
|
10068
10040
|
return updateModuleDeclaration(d, modifiers, d.name, d.body);
|
|
10069
|
-
case
|
|
10041
|
+
case SyntaxKind26.TypeAliasDeclaration:
|
|
10070
10042
|
return updateTypeAliasDeclaration(d, modifiers, d.name, d.typeParameters, d.type);
|
|
10071
10043
|
default:
|
|
10072
|
-
return
|
|
10044
|
+
return Debug23.assertNever(d, `Unexpected declaration kind ${d.kind}`);
|
|
10073
10045
|
}
|
|
10074
10046
|
}
|
|
10075
10047
|
|
|
@@ -10078,9 +10050,9 @@ var ts_refactor_addOrRemoveBracesToArrowFunction_exports = {};
|
|
|
10078
10050
|
|
|
10079
10051
|
// src/refactors/addOrRemoveBracesToArrowFunction.ts
|
|
10080
10052
|
import {
|
|
10081
|
-
Debug as
|
|
10082
|
-
Diagnostics as
|
|
10083
|
-
SyntaxKind as
|
|
10053
|
+
Debug as Debug24,
|
|
10054
|
+
Diagnostics as Diagnostics29,
|
|
10055
|
+
SyntaxKind as SyntaxKind27,
|
|
10084
10056
|
createBlock as createBlock5,
|
|
10085
10057
|
createIdentifier as createIdentifier11,
|
|
10086
10058
|
createParen as createParen4,
|
|
@@ -10096,17 +10068,17 @@ import {
|
|
|
10096
10068
|
copyLeadingComments,
|
|
10097
10069
|
copyTrailingAsLeadingComments,
|
|
10098
10070
|
copyTrailingComments,
|
|
10099
|
-
getTokenAtPosition as
|
|
10071
|
+
getTokenAtPosition as getTokenAtPosition27,
|
|
10100
10072
|
needsParentheses as needsParentheses2,
|
|
10101
10073
|
rangeContainsRange as rangeContainsRange5,
|
|
10102
10074
|
suppressLeadingAndTrailingTrivia as suppressLeadingAndTrailingTrivia3
|
|
10103
10075
|
} from "@tslite/services";
|
|
10104
10076
|
var refactorName6 = "Add or remove braces in an arrow function";
|
|
10105
|
-
var refactorDescription =
|
|
10077
|
+
var refactorDescription = Diagnostics29.Add_or_remove_braces_in_an_arrow_function.message;
|
|
10106
10078
|
var addBracesActionName = "Add braces to arrow function";
|
|
10107
10079
|
var removeBracesActionName = "Remove braces from arrow function";
|
|
10108
|
-
var addBracesActionDescription =
|
|
10109
|
-
var removeBracesActionDescription =
|
|
10080
|
+
var addBracesActionDescription = Diagnostics29.Add_braces_to_arrow_function.message;
|
|
10081
|
+
var removeBracesActionDescription = Diagnostics29.Remove_braces_from_arrow_function.message;
|
|
10110
10082
|
registerRefactor(refactorName6, { getEditsForAction: getEditsForAction2, getAvailableActions: getAvailableActions2 });
|
|
10111
10083
|
function getAvailableActions2(context) {
|
|
10112
10084
|
const { file, startPosition } = context;
|
|
@@ -10144,7 +10116,7 @@ function getEditsForAction2(context, actionName) {
|
|
|
10144
10116
|
expression,
|
|
10145
10117
|
returnStatement2,
|
|
10146
10118
|
file,
|
|
10147
|
-
|
|
10119
|
+
SyntaxKind27.MultiLineCommentTrivia,
|
|
10148
10120
|
/* hasTrailingNewLine */
|
|
10149
10121
|
true
|
|
10150
10122
|
);
|
|
@@ -10156,7 +10128,7 @@ function getEditsForAction2(context, actionName) {
|
|
|
10156
10128
|
returnStatement,
|
|
10157
10129
|
body,
|
|
10158
10130
|
file,
|
|
10159
|
-
|
|
10131
|
+
SyntaxKind27.MultiLineCommentTrivia,
|
|
10160
10132
|
/* hasTrailingNewLine */
|
|
10161
10133
|
false
|
|
10162
10134
|
);
|
|
@@ -10164,7 +10136,7 @@ function getEditsForAction2(context, actionName) {
|
|
|
10164
10136
|
returnStatement,
|
|
10165
10137
|
body,
|
|
10166
10138
|
file,
|
|
10167
|
-
|
|
10139
|
+
SyntaxKind27.MultiLineCommentTrivia,
|
|
10168
10140
|
/* hasTrailingNewLine */
|
|
10169
10141
|
false
|
|
10170
10142
|
);
|
|
@@ -10172,12 +10144,12 @@ function getEditsForAction2(context, actionName) {
|
|
|
10172
10144
|
returnStatement,
|
|
10173
10145
|
body,
|
|
10174
10146
|
file,
|
|
10175
|
-
|
|
10147
|
+
SyntaxKind27.MultiLineCommentTrivia,
|
|
10176
10148
|
/* hasTrailingNewLine */
|
|
10177
10149
|
false
|
|
10178
10150
|
);
|
|
10179
10151
|
} else {
|
|
10180
|
-
|
|
10152
|
+
Debug24.fail("invalid action");
|
|
10181
10153
|
}
|
|
10182
10154
|
const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => {
|
|
10183
10155
|
t.replaceNode(file, func.body, body);
|
|
@@ -10185,7 +10157,7 @@ function getEditsForAction2(context, actionName) {
|
|
|
10185
10157
|
return { renameFilename: void 0, renameLocation: void 0, edits };
|
|
10186
10158
|
}
|
|
10187
10159
|
function getConvertibleArrowFunctionAtPosition(file, startPosition) {
|
|
10188
|
-
const node =
|
|
10160
|
+
const node = getTokenAtPosition27(file, startPosition);
|
|
10189
10161
|
const func = getContainingFunction4(node);
|
|
10190
10162
|
if (!func || !isArrowFunction7(func) || (!rangeContainsRange5(func, node) || rangeContainsRange5(func.body, node))) return void 0;
|
|
10191
10163
|
if (isExpression5(func.body)) {
|
|
@@ -10213,10 +10185,10 @@ var ts_refactor_convertParamsToDestructuredObject_exports = {};
|
|
|
10213
10185
|
|
|
10214
10186
|
// src/refactors/convertParamsToDestructuredObject.ts
|
|
10215
10187
|
import {
|
|
10216
|
-
Debug as
|
|
10217
|
-
Diagnostics as
|
|
10188
|
+
Debug as Debug25,
|
|
10189
|
+
Diagnostics as Diagnostics30,
|
|
10218
10190
|
EmitFlags as EmitFlags2,
|
|
10219
|
-
SyntaxKind as
|
|
10191
|
+
SyntaxKind as SyntaxKind28,
|
|
10220
10192
|
addEmitFlags,
|
|
10221
10193
|
compareValues as compareValues2,
|
|
10222
10194
|
contains as contains7,
|
|
@@ -10277,7 +10249,7 @@ function getAvailableActions3(context) {
|
|
|
10277
10249
|
const { file, startPosition } = context;
|
|
10278
10250
|
const functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, context.program.getTypeChecker());
|
|
10279
10251
|
if (!functionDeclaration) return emptyArray13;
|
|
10280
|
-
const description = getLocaleSpecificMessage5(
|
|
10252
|
+
const description = getLocaleSpecificMessage5(Diagnostics30.Convert_parameters_to_destructured_object);
|
|
10281
10253
|
return [{
|
|
10282
10254
|
name: refactorName7,
|
|
10283
10255
|
description,
|
|
@@ -10288,7 +10260,7 @@ function getAvailableActions3(context) {
|
|
|
10288
10260
|
}];
|
|
10289
10261
|
}
|
|
10290
10262
|
function getEditsForAction3(context, actionName) {
|
|
10291
|
-
|
|
10263
|
+
Debug25.assert(actionName === refactorName7, "Unexpected action name");
|
|
10292
10264
|
const { file, startPosition, program, cancellationToken, host } = context;
|
|
10293
10265
|
const functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
|
|
10294
10266
|
if (!functionDeclaration || !cancellationToken) return void 0;
|
|
@@ -10409,14 +10381,14 @@ function entryToFunctionCall(entry) {
|
|
|
10409
10381
|
const parent = functionReference.parent;
|
|
10410
10382
|
switch (parent.kind) {
|
|
10411
10383
|
// foo(...); na tag, também o `super(...)` e o `new Foo(...)` (CK-02)
|
|
10412
|
-
case
|
|
10384
|
+
case SyntaxKind28.CallExpression:
|
|
10413
10385
|
const callOrNewExpression = tryCast9(parent, isCallOrNewExpression3);
|
|
10414
10386
|
if (callOrNewExpression && callOrNewExpression.expression === functionReference) {
|
|
10415
10387
|
return callOrNewExpression;
|
|
10416
10388
|
}
|
|
10417
10389
|
break;
|
|
10418
10390
|
// x.foo(...)
|
|
10419
|
-
case
|
|
10391
|
+
case SyntaxKind28.PropertyAccessExpression:
|
|
10420
10392
|
const propertyAccessExpression = tryCast9(parent, isPropertyAccessExpression9);
|
|
10421
10393
|
if (propertyAccessExpression && propertyAccessExpression.parent && propertyAccessExpression.name === functionReference) {
|
|
10422
10394
|
const callOrNewExpression2 = tryCast9(propertyAccessExpression.parent, isCallOrNewExpression3);
|
|
@@ -10426,7 +10398,7 @@ function entryToFunctionCall(entry) {
|
|
|
10426
10398
|
}
|
|
10427
10399
|
break;
|
|
10428
10400
|
// x["foo"](...)
|
|
10429
|
-
case
|
|
10401
|
+
case SyntaxKind28.ElementAccessExpression:
|
|
10430
10402
|
const elementAccessExpression = tryCast9(parent, isElementAccessExpression2);
|
|
10431
10403
|
if (elementAccessExpression && elementAccessExpression.parent && elementAccessExpression.argumentExpression === functionReference) {
|
|
10432
10404
|
const callOrNewExpression2 = tryCast9(elementAccessExpression.parent, isCallOrNewExpression3);
|
|
@@ -10448,7 +10420,7 @@ function getFunctionDeclarationAtPosition(file, startPosition, checker) {
|
|
|
10448
10420
|
function isValidFunctionDeclaration(functionDeclaration, checker) {
|
|
10449
10421
|
if (!isValidParameterNodeArray(functionDeclaration.parameters, checker)) return false;
|
|
10450
10422
|
switch (functionDeclaration.kind) {
|
|
10451
|
-
case
|
|
10423
|
+
case SyntaxKind28.ArrowFunction:
|
|
10452
10424
|
return isValidVariableDeclaration(functionDeclaration.parent);
|
|
10453
10425
|
}
|
|
10454
10426
|
return false;
|
|
@@ -10551,7 +10523,7 @@ function createNewParameters(functionDeclaration, program, host) {
|
|
|
10551
10523
|
/*modifiers*/
|
|
10552
10524
|
void 0,
|
|
10553
10525
|
getParameterName(parameterDeclaration),
|
|
10554
|
-
isOptionalParameter(parameterDeclaration) ? createToken4(
|
|
10526
|
+
isOptionalParameter(parameterDeclaration) ? createToken4(SyntaxKind28.QuestionToken) : parameterDeclaration.questionToken,
|
|
10555
10527
|
parameterType,
|
|
10556
10528
|
/*initializer*/
|
|
10557
10529
|
void 0
|
|
@@ -10587,9 +10559,9 @@ var ts_refactor_convertStringOrTemplateLiteral_exports = {};
|
|
|
10587
10559
|
|
|
10588
10560
|
// src/refactors/convertStringOrTemplateLiteral.ts
|
|
10589
10561
|
import {
|
|
10590
|
-
Debug as
|
|
10591
|
-
Diagnostics as
|
|
10592
|
-
SyntaxKind as
|
|
10562
|
+
Debug as Debug26,
|
|
10563
|
+
Diagnostics as Diagnostics31,
|
|
10564
|
+
SyntaxKind as SyntaxKind29,
|
|
10593
10565
|
createNoSubstitutionTemplateLiteral,
|
|
10594
10566
|
createTemplateExpression,
|
|
10595
10567
|
createTemplateHead,
|
|
@@ -10606,10 +10578,10 @@ import {
|
|
|
10606
10578
|
import {
|
|
10607
10579
|
copyTrailingAsLeadingComments as copyTrailingAsLeadingComments2,
|
|
10608
10580
|
copyTrailingComments as copyTrailingComments2,
|
|
10609
|
-
getTokenAtPosition as
|
|
10581
|
+
getTokenAtPosition as getTokenAtPosition28
|
|
10610
10582
|
} from "@tslite/services";
|
|
10611
10583
|
var refactorName8 = "Convert to template string";
|
|
10612
|
-
var refactorDescription2 = getLocaleSpecificMessage6(
|
|
10584
|
+
var refactorDescription2 = getLocaleSpecificMessage6(Diagnostics31.Convert_to_template_string);
|
|
10613
10585
|
registerRefactor(refactorName8, { getEditsForAction: getEditsForAction4, getAvailableActions: getAvailableActions4 });
|
|
10614
10586
|
function getAvailableActions4(context) {
|
|
10615
10587
|
const { file, startPosition } = context;
|
|
@@ -10623,7 +10595,7 @@ function getAvailableActions4(context) {
|
|
|
10623
10595
|
return emptyArray14;
|
|
10624
10596
|
}
|
|
10625
10597
|
function getNodeOrParentOfParentheses(file, startPosition) {
|
|
10626
|
-
const node =
|
|
10598
|
+
const node = getTokenAtPosition28(file, startPosition);
|
|
10627
10599
|
const nestedBinary = getParentBinaryExpression(node);
|
|
10628
10600
|
const isNonStringBinary = !isStringConcatenationValid(nestedBinary);
|
|
10629
10601
|
if (isNonStringBinary && isParenthesizedExpression3(nestedBinary.parent) && isBinaryExpression4(nestedBinary.parent.parent)) {
|
|
@@ -10638,7 +10610,7 @@ function getEditsForAction4(context, actionName) {
|
|
|
10638
10610
|
case refactorDescription2:
|
|
10639
10611
|
return { edits: getEditsForToTemplateLiteral(context, node) };
|
|
10640
10612
|
default:
|
|
10641
|
-
return
|
|
10613
|
+
return Debug26.fail("invalid action");
|
|
10642
10614
|
}
|
|
10643
10615
|
}
|
|
10644
10616
|
function getEditsForToTemplateLiteral(context, node) {
|
|
@@ -10658,7 +10630,7 @@ function getEditsForToTemplateLiteral(context, node) {
|
|
|
10658
10630
|
}
|
|
10659
10631
|
}
|
|
10660
10632
|
function isNotEqualsOperator(node) {
|
|
10661
|
-
return node.operatorToken.kind !==
|
|
10633
|
+
return node.operatorToken.kind !== SyntaxKind29.EqualsToken;
|
|
10662
10634
|
}
|
|
10663
10635
|
function getParentBinaryExpression(expr) {
|
|
10664
10636
|
while (isBinaryExpression4(expr.parent) && isNotEqualsOperator(expr.parent)) {
|
|
@@ -10676,7 +10648,7 @@ function treeToArray(current) {
|
|
|
10676
10648
|
if (!leftHasString && !isStringLiteral5(current.right)) {
|
|
10677
10649
|
return { nodes: [current], operators: [], containsString: false, areOperatorsValid: true };
|
|
10678
10650
|
}
|
|
10679
|
-
const currentOperatorValid = current.operatorToken.kind ===
|
|
10651
|
+
const currentOperatorValid = current.operatorToken.kind === SyntaxKind29.PlusToken;
|
|
10680
10652
|
const areOperatorsValid = leftOperatorValid && currentOperatorValid;
|
|
10681
10653
|
nodes.push(current.right);
|
|
10682
10654
|
operators.push(current.operatorToken);
|
|
@@ -10690,7 +10662,7 @@ var copyTrailingOperatorComments = (operators, file) => (index, targetNode) => {
|
|
|
10690
10662
|
operators[index],
|
|
10691
10663
|
targetNode,
|
|
10692
10664
|
file,
|
|
10693
|
-
|
|
10665
|
+
SyntaxKind29.MultiLineCommentTrivia,
|
|
10694
10666
|
/* hasTrailingNewLine */
|
|
10695
10667
|
false
|
|
10696
10668
|
);
|
|
@@ -10703,7 +10675,7 @@ var copyCommentFromMultiNode = (nodes, file, copyOperatorComments) => (indexes,
|
|
|
10703
10675
|
nodes[index],
|
|
10704
10676
|
targetNode,
|
|
10705
10677
|
file,
|
|
10706
|
-
|
|
10678
|
+
SyntaxKind29.MultiLineCommentTrivia,
|
|
10707
10679
|
/* hasTrailingNewLine */
|
|
10708
10680
|
false
|
|
10709
10681
|
);
|
|
@@ -10750,7 +10722,7 @@ function copyCommentsWhenParenthesized(node) {
|
|
|
10750
10722
|
node,
|
|
10751
10723
|
node.expression,
|
|
10752
10724
|
file,
|
|
10753
|
-
|
|
10725
|
+
SyntaxKind29.MultiLineCommentTrivia,
|
|
10754
10726
|
/* hasTrailingNewLine */
|
|
10755
10727
|
false
|
|
10756
10728
|
);
|
|
@@ -10758,7 +10730,7 @@ function copyCommentsWhenParenthesized(node) {
|
|
|
10758
10730
|
node.expression,
|
|
10759
10731
|
node.expression,
|
|
10760
10732
|
file,
|
|
10761
|
-
|
|
10733
|
+
SyntaxKind29.MultiLineCommentTrivia,
|
|
10762
10734
|
/* hasTrailingNewLine */
|
|
10763
10735
|
false
|
|
10764
10736
|
);
|