typescript 4.7.0-dev.20220329 → 4.7.0-dev.20220401
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/protocol.d.ts +30 -0
- package/lib/tsc.js +90 -40
- package/lib/tsserver.js +542 -240
- package/lib/tsserverlibrary.d.ts +39 -1
- package/lib/tsserverlibrary.js +542 -240
- package/lib/typescript.d.ts +9 -1
- package/lib/typescript.js +524 -238
- package/lib/typescriptServices.d.ts +9 -1
- package/lib/typescriptServices.js +524 -238
- package/lib/typingsInstaller.js +97 -42
- package/package.json +1 -1
package/lib/tsserverlibrary.js
CHANGED
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220401";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -9689,6 +9689,7 @@ var ts;
|
|
|
9689
9689
|
An_expanded_version_of_this_information_showing_all_possible_compiler_options: diag(6928, ts.DiagnosticCategory.Message, "An_expanded_version_of_this_information_showing_all_possible_compiler_options_6928", "An expanded version of this information, showing all possible compiler options"),
|
|
9690
9690
|
Compiles_the_current_project_with_additional_settings: diag(6929, ts.DiagnosticCategory.Message, "Compiles_the_current_project_with_additional_settings_6929", "Compiles the current project, with additional settings."),
|
|
9691
9691
|
true_for_ES2022_and_above_including_ESNext: diag(6930, ts.DiagnosticCategory.Message, "true_for_ES2022_and_above_including_ESNext_6930", "`true` for ES2022 and above, including ESNext."),
|
|
9692
|
+
List_of_file_name_suffixes_to_search_when_resolving_a_module: diag(6931, ts.DiagnosticCategory.Error, "List_of_file_name_suffixes_to_search_when_resolving_a_module_6931", "List of file name suffixes to search when resolving a module."),
|
|
9692
9693
|
Variable_0_implicitly_has_an_1_type: diag(7005, ts.DiagnosticCategory.Error, "Variable_0_implicitly_has_an_1_type_7005", "Variable '{0}' implicitly has an '{1}' type."),
|
|
9693
9694
|
Parameter_0_implicitly_has_an_1_type: diag(7006, ts.DiagnosticCategory.Error, "Parameter_0_implicitly_has_an_1_type_7006", "Parameter '{0}' implicitly has an '{1}' type."),
|
|
9694
9695
|
Member_0_implicitly_has_an_1_type: diag(7008, ts.DiagnosticCategory.Error, "Member_0_implicitly_has_an_1_type_7008", "Member '{0}' implicitly has an '{1}' type."),
|
|
@@ -39683,6 +39684,18 @@ var ts;
|
|
|
39683
39684
|
description: ts.Diagnostics.Allow_accessing_UMD_globals_from_modules,
|
|
39684
39685
|
defaultValueDescription: false,
|
|
39685
39686
|
},
|
|
39687
|
+
{
|
|
39688
|
+
name: "moduleSuffixes",
|
|
39689
|
+
type: "list",
|
|
39690
|
+
element: {
|
|
39691
|
+
name: "suffix",
|
|
39692
|
+
type: "string",
|
|
39693
|
+
},
|
|
39694
|
+
listPreserveFalsyValues: true,
|
|
39695
|
+
affectsModuleResolution: true,
|
|
39696
|
+
category: ts.Diagnostics.Modules,
|
|
39697
|
+
description: ts.Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module,
|
|
39698
|
+
},
|
|
39686
39699
|
// Source Maps
|
|
39687
39700
|
{
|
|
39688
39701
|
name: "sourceRoot",
|
|
@@ -41609,7 +41622,7 @@ var ts;
|
|
|
41609
41622
|
if (option.type === "list") {
|
|
41610
41623
|
var listOption_1 = option;
|
|
41611
41624
|
if (listOption_1.element.isFilePath || !ts.isString(listOption_1.element.type)) {
|
|
41612
|
-
return ts.filter(ts.map(value, function (v) { return normalizeOptionValue(listOption_1.element, basePath, v); }), function (v) { return !!v; });
|
|
41625
|
+
return ts.filter(ts.map(value, function (v) { return normalizeOptionValue(listOption_1.element, basePath, v); }), function (v) { return listOption_1.listPreserveFalsyValues ? true : !!v; });
|
|
41613
41626
|
}
|
|
41614
41627
|
return value;
|
|
41615
41628
|
}
|
|
@@ -41650,7 +41663,7 @@ var ts;
|
|
|
41650
41663
|
}
|
|
41651
41664
|
}
|
|
41652
41665
|
function convertJsonOptionOfListType(option, values, basePath, errors) {
|
|
41653
|
-
return ts.filter(ts.map(values, function (v) { return convertJsonOption(option.element, v, basePath, errors); }), function (v) { return !!v; });
|
|
41666
|
+
return ts.filter(ts.map(values, function (v) { return convertJsonOption(option.element, v, basePath, errors); }), function (v) { return option.listPreserveFalsyValues ? true : !!v; });
|
|
41654
41667
|
}
|
|
41655
41668
|
/**
|
|
41656
41669
|
* Tests for a path that ends in a recursive directory wildcard.
|
|
@@ -43276,6 +43289,15 @@ var ts;
|
|
|
43276
43289
|
}
|
|
43277
43290
|
/** Return the file if it exists. */
|
|
43278
43291
|
function tryFile(fileName, onlyRecordFailures, state) {
|
|
43292
|
+
var _a, _b;
|
|
43293
|
+
if (!((_a = state.compilerOptions.moduleSuffixes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
43294
|
+
return tryFileLookup(fileName, onlyRecordFailures, state);
|
|
43295
|
+
}
|
|
43296
|
+
var ext = (_b = ts.tryGetExtensionFromPath(fileName)) !== null && _b !== void 0 ? _b : "";
|
|
43297
|
+
var fileNameNoExtension = ext ? ts.removeExtension(fileName, ext) : fileName;
|
|
43298
|
+
return ts.forEach(state.compilerOptions.moduleSuffixes, function (suffix) { return tryFileLookup(fileNameNoExtension + suffix + ext, onlyRecordFailures, state); });
|
|
43299
|
+
}
|
|
43300
|
+
function tryFileLookup(fileName, onlyRecordFailures, state) {
|
|
43279
43301
|
if (!onlyRecordFailures) {
|
|
43280
43302
|
if (state.host.fileExists(fileName)) {
|
|
43281
43303
|
if (state.traceEnabled) {
|
|
@@ -47600,7 +47622,8 @@ var ts;
|
|
|
47600
47622
|
CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
|
|
47601
47623
|
CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
|
|
47602
47624
|
CheckMode[CheckMode["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
|
|
47603
|
-
CheckMode[CheckMode["
|
|
47625
|
+
CheckMode[CheckMode["IsForStringLiteralArgumentCompletions"] = 32] = "IsForStringLiteralArgumentCompletions";
|
|
47626
|
+
CheckMode[CheckMode["RestBindingElement"] = 64] = "RestBindingElement";
|
|
47604
47627
|
// e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
|
|
47605
47628
|
// we need to preserve generic types instead of substituting them for constraints
|
|
47606
47629
|
})(CheckMode || (CheckMode = {}));
|
|
@@ -47938,26 +47961,10 @@ var ts;
|
|
|
47938
47961
|
if (!node) {
|
|
47939
47962
|
return undefined;
|
|
47940
47963
|
}
|
|
47941
|
-
|
|
47942
|
-
|
|
47943
|
-
if (contextFlags & 4 /* Completions */ && containingCall) {
|
|
47944
|
-
var toMarkSkip = node;
|
|
47945
|
-
do {
|
|
47946
|
-
getNodeLinks(toMarkSkip).skipDirectInference = true;
|
|
47947
|
-
toMarkSkip = toMarkSkip.parent;
|
|
47948
|
-
} while (toMarkSkip && toMarkSkip !== containingCall);
|
|
47949
|
-
getNodeLinks(containingCall).resolvedSignature = undefined;
|
|
47950
|
-
}
|
|
47951
|
-
var result = getContextualType(node, contextFlags);
|
|
47952
|
-
if (contextFlags & 4 /* Completions */ && containingCall) {
|
|
47953
|
-
var toMarkSkip = node;
|
|
47954
|
-
do {
|
|
47955
|
-
getNodeLinks(toMarkSkip).skipDirectInference = undefined;
|
|
47956
|
-
toMarkSkip = toMarkSkip.parent;
|
|
47957
|
-
} while (toMarkSkip && toMarkSkip !== containingCall);
|
|
47958
|
-
getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
|
|
47964
|
+
if (contextFlags & 4 /* Completions */) {
|
|
47965
|
+
return runWithInferenceBlockedFromSourceNode(node, function () { return getContextualType(node, contextFlags); });
|
|
47959
47966
|
}
|
|
47960
|
-
return
|
|
47967
|
+
return getContextualType(node, contextFlags);
|
|
47961
47968
|
},
|
|
47962
47969
|
getContextualTypeForObjectLiteralElement: function (nodeIn) {
|
|
47963
47970
|
var node = ts.getParseTreeNode(nodeIn, ts.isObjectLiteralElementLike);
|
|
@@ -47977,6 +47984,9 @@ var ts;
|
|
|
47977
47984
|
getResolvedSignature: function (node, candidatesOutArray, argumentCount) {
|
|
47978
47985
|
return getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, 0 /* Normal */);
|
|
47979
47986
|
},
|
|
47987
|
+
getResolvedSignatureForStringLiteralCompletions: function (call, editingArgument, candidatesOutArray) {
|
|
47988
|
+
return getResolvedSignatureWorker(call, candidatesOutArray, /*argumentCount*/ undefined, 32 /* IsForStringLiteralArgumentCompletions */, editingArgument);
|
|
47989
|
+
},
|
|
47980
47990
|
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, argumentCount) {
|
|
47981
47991
|
return getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, 16 /* IsForSignatureHelp */);
|
|
47982
47992
|
},
|
|
@@ -48129,10 +48139,34 @@ var ts;
|
|
|
48129
48139
|
getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
|
|
48130
48140
|
getMemberOverrideModifierStatus: getMemberOverrideModifierStatus,
|
|
48131
48141
|
};
|
|
48132
|
-
function
|
|
48142
|
+
function runWithInferenceBlockedFromSourceNode(node, fn) {
|
|
48143
|
+
var containingCall = ts.findAncestor(node, ts.isCallLikeExpression);
|
|
48144
|
+
var containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
|
|
48145
|
+
if (containingCall) {
|
|
48146
|
+
var toMarkSkip = node;
|
|
48147
|
+
do {
|
|
48148
|
+
getNodeLinks(toMarkSkip).skipDirectInference = true;
|
|
48149
|
+
toMarkSkip = toMarkSkip.parent;
|
|
48150
|
+
} while (toMarkSkip && toMarkSkip !== containingCall);
|
|
48151
|
+
getNodeLinks(containingCall).resolvedSignature = undefined;
|
|
48152
|
+
}
|
|
48153
|
+
var result = fn();
|
|
48154
|
+
if (containingCall) {
|
|
48155
|
+
var toMarkSkip = node;
|
|
48156
|
+
do {
|
|
48157
|
+
getNodeLinks(toMarkSkip).skipDirectInference = undefined;
|
|
48158
|
+
toMarkSkip = toMarkSkip.parent;
|
|
48159
|
+
} while (toMarkSkip && toMarkSkip !== containingCall);
|
|
48160
|
+
getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
|
|
48161
|
+
}
|
|
48162
|
+
return result;
|
|
48163
|
+
}
|
|
48164
|
+
function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode, editingArgument) {
|
|
48133
48165
|
var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
|
|
48134
48166
|
apparentArgumentCount = argumentCount;
|
|
48135
|
-
var res = node ?
|
|
48167
|
+
var res = !node ? undefined :
|
|
48168
|
+
editingArgument ? runWithInferenceBlockedFromSourceNode(editingArgument, function () { return getResolvedSignature(node, candidatesOutArray, checkMode); }) :
|
|
48169
|
+
getResolvedSignature(node, candidatesOutArray, checkMode);
|
|
48136
48170
|
apparentArgumentCount = undefined;
|
|
48137
48171
|
return res;
|
|
48138
48172
|
}
|
|
@@ -52259,7 +52293,15 @@ var ts;
|
|
|
52259
52293
|
if (!ts.nodeIsSynthesized(node) && ts.getParseTreeNode(node) === node) {
|
|
52260
52294
|
return node;
|
|
52261
52295
|
}
|
|
52262
|
-
return ts.setTextRange(ts.factory.cloneNode(ts.visitEachChild(node, deepCloneOrReuseNode, ts.nullTransformationContext)), node);
|
|
52296
|
+
return ts.setTextRange(ts.factory.cloneNode(ts.visitEachChild(node, deepCloneOrReuseNode, ts.nullTransformationContext, deepCloneOrReuseNodes)), node);
|
|
52297
|
+
}
|
|
52298
|
+
function deepCloneOrReuseNodes(nodes, visitor, test, start, count) {
|
|
52299
|
+
if (nodes && nodes.length === 0) {
|
|
52300
|
+
// Ensure we explicitly make a copy of an empty array; visitNodes will not do this unless the array has elements,
|
|
52301
|
+
// which can lead to us reusing the same empty NodeArray more than once within the same AST during type noding.
|
|
52302
|
+
return ts.setTextRange(ts.factory.createNodeArray(/*nodes*/ undefined, nodes.hasTrailingComma), nodes);
|
|
52303
|
+
}
|
|
52304
|
+
return ts.visitNodes(nodes, visitor, test, start, count);
|
|
52263
52305
|
}
|
|
52264
52306
|
}
|
|
52265
52307
|
function createTypeNodeFromObjectType(type) {
|
|
@@ -55266,7 +55308,7 @@ var ts;
|
|
|
55266
55308
|
}
|
|
55267
55309
|
/** Return the inferred type for a binding element */
|
|
55268
55310
|
function getTypeForBindingElement(declaration) {
|
|
55269
|
-
var checkMode = declaration.dotDotDotToken ?
|
|
55311
|
+
var checkMode = declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
|
|
55270
55312
|
var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
|
|
55271
55313
|
return parentType && getBindingElementTypeFromParentType(declaration, parentType);
|
|
55272
55314
|
}
|
|
@@ -68394,7 +68436,7 @@ var ts;
|
|
|
68394
68436
|
for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) {
|
|
68395
68437
|
var targetProp = properties_3[_i];
|
|
68396
68438
|
var sourceProp = getPropertyOfType(source, targetProp.escapedName);
|
|
68397
|
-
if (sourceProp) {
|
|
68439
|
+
if (sourceProp && !ts.some(sourceProp.declarations, hasSkipDirectInferenceFlag)) {
|
|
68398
68440
|
inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
|
|
68399
68441
|
}
|
|
68400
68442
|
}
|
|
@@ -70868,7 +70910,7 @@ var ts;
|
|
|
70868
70910
|
// as we want the type of a rest element to be generic when possible.
|
|
70869
70911
|
var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
|
|
70870
70912
|
!((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
|
|
70871
|
-
(checkMode && checkMode &
|
|
70913
|
+
(checkMode && checkMode & 64 /* RestBindingElement */ ?
|
|
70872
70914
|
getContextualType(node, 8 /* SkipBindingPatterns */)
|
|
70873
70915
|
: getContextualType(node));
|
|
70874
70916
|
return contextualType && !isGenericType(contextualType);
|
|
@@ -70989,7 +71031,7 @@ var ts;
|
|
|
70989
71031
|
if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
|
|
70990
71032
|
var contextualSignature = getContextualSignature(func);
|
|
70991
71033
|
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
|
|
70992
|
-
var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
|
|
71034
|
+
var restType = getReducedApparentType(getTypeOfSymbol(contextualSignature.parameters[0]));
|
|
70993
71035
|
if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
|
|
70994
71036
|
var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
|
|
70995
71037
|
var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
|
|
@@ -71807,7 +71849,7 @@ var ts;
|
|
|
71807
71849
|
var parent = declaration.parent.parent;
|
|
71808
71850
|
var name = declaration.propertyName || declaration.name;
|
|
71809
71851
|
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
|
|
71810
|
-
parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ?
|
|
71852
|
+
parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
|
|
71811
71853
|
if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
|
|
71812
71854
|
return undefined;
|
|
71813
71855
|
if (parent.name.kind === 202 /* ArrayBindingPattern */) {
|
|
@@ -72294,9 +72336,14 @@ var ts;
|
|
|
72294
72336
|
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
|
|
72295
72337
|
}
|
|
72296
72338
|
// For other purposes (e.g. determining whether to produce literal types) we only
|
|
72297
|
-
// incorporate inferences made from the return type in a function call.
|
|
72339
|
+
// incorporate inferences made from the return type in a function call. We remove
|
|
72340
|
+
// the 'boolean' type from the contextual type such that contextually typed boolean
|
|
72341
|
+
// literals actually end up widening to 'boolean' (see #48363).
|
|
72298
72342
|
if (inferenceContext.returnMapper) {
|
|
72299
|
-
|
|
72343
|
+
var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
|
|
72344
|
+
return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
|
|
72345
|
+
filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
|
|
72346
|
+
type;
|
|
72300
72347
|
}
|
|
72301
72348
|
}
|
|
72302
72349
|
}
|
|
@@ -74861,7 +74908,7 @@ var ts;
|
|
|
74861
74908
|
}
|
|
74862
74909
|
for (var i = 0; i < argCount; i++) {
|
|
74863
74910
|
var arg = args[i];
|
|
74864
|
-
if (arg.kind !== 227 /* OmittedExpression */) {
|
|
74911
|
+
if (arg.kind !== 227 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
|
|
74865
74912
|
var paramType = getTypeAtPosition(signature, i);
|
|
74866
74913
|
var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
|
|
74867
74914
|
inferTypes(context.inferences, argType, paramType);
|
|
@@ -75546,7 +75593,7 @@ var ts;
|
|
|
75546
75593
|
}
|
|
75547
75594
|
}
|
|
75548
75595
|
}
|
|
75549
|
-
return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
|
|
75596
|
+
return getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
|
|
75550
75597
|
function addImplementationSuccessElaboration(failed, diagnostic) {
|
|
75551
75598
|
var _a, _b;
|
|
75552
75599
|
var oldCandidatesForArgumentError = candidatesForArgumentError;
|
|
@@ -75647,14 +75694,14 @@ var ts;
|
|
|
75647
75694
|
}
|
|
75648
75695
|
}
|
|
75649
75696
|
// No signature was applicable. We have already reported the errors for the invalid signature.
|
|
75650
|
-
function getCandidateForOverloadFailure(node, candidates, args, hasCandidatesOutArray) {
|
|
75697
|
+
function getCandidateForOverloadFailure(node, candidates, args, hasCandidatesOutArray, checkMode) {
|
|
75651
75698
|
ts.Debug.assert(candidates.length > 0); // Else should not have called this.
|
|
75652
75699
|
checkNodeDeferred(node);
|
|
75653
75700
|
// Normally we will combine overloads. Skip this if they have type parameters since that's hard to combine.
|
|
75654
75701
|
// Don't do this if there is a `candidatesOutArray`,
|
|
75655
75702
|
// because then we want the chosen best candidate to be one of the overloads, not a combination.
|
|
75656
75703
|
return hasCandidatesOutArray || candidates.length === 1 || candidates.some(function (c) { return !!c.typeParameters; })
|
|
75657
|
-
? pickLongestCandidateSignature(node, candidates, args)
|
|
75704
|
+
? pickLongestCandidateSignature(node, candidates, args, checkMode)
|
|
75658
75705
|
: createUnionOfSignaturesForOverloadFailure(candidates);
|
|
75659
75706
|
}
|
|
75660
75707
|
function createUnionOfSignaturesForOverloadFailure(candidates) {
|
|
@@ -75702,7 +75749,7 @@ var ts;
|
|
|
75702
75749
|
// This function is currently only used for erroneous overloads, so it's good enough to just use the first source.
|
|
75703
75750
|
return createSymbolWithType(ts.first(sources), type);
|
|
75704
75751
|
}
|
|
75705
|
-
function pickLongestCandidateSignature(node, candidates, args) {
|
|
75752
|
+
function pickLongestCandidateSignature(node, candidates, args, checkMode) {
|
|
75706
75753
|
// Pick the longest signature. This way we can get a contextual type for cases like:
|
|
75707
75754
|
// declare function f(a: { xa: number; xb: number; }, b: number);
|
|
75708
75755
|
// f({ |
|
|
@@ -75718,7 +75765,7 @@ var ts;
|
|
|
75718
75765
|
var typeArgumentNodes = callLikeExpressionMayHaveTypeArguments(node) ? node.typeArguments : undefined;
|
|
75719
75766
|
var instantiated = typeArgumentNodes
|
|
75720
75767
|
? createSignatureInstantiation(candidate, getTypeArgumentsFromNodes(typeArgumentNodes, typeParameters, ts.isInJSFile(node)))
|
|
75721
|
-
: inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args);
|
|
75768
|
+
: inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode);
|
|
75722
75769
|
candidates[bestIndex] = instantiated;
|
|
75723
75770
|
return instantiated;
|
|
75724
75771
|
}
|
|
@@ -75732,9 +75779,9 @@ var ts;
|
|
|
75732
75779
|
}
|
|
75733
75780
|
return typeArguments;
|
|
75734
75781
|
}
|
|
75735
|
-
function inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args) {
|
|
75782
|
+
function inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args, checkMode) {
|
|
75736
75783
|
var inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
|
|
75737
|
-
var typeArgumentTypes = inferTypeArguments(node, candidate, args, 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
|
|
75784
|
+
var typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
|
|
75738
75785
|
return createSignatureInstantiation(candidate, typeArgumentTypes);
|
|
75739
75786
|
}
|
|
75740
75787
|
function getLongestCandidateIndex(candidates, argsCount) {
|
|
@@ -81800,7 +81847,7 @@ var ts;
|
|
|
81800
81847
|
}
|
|
81801
81848
|
// check private/protected variable access
|
|
81802
81849
|
var parent = node.parent.parent;
|
|
81803
|
-
var parentCheckMode = node.dotDotDotToken ?
|
|
81850
|
+
var parentCheckMode = node.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
|
|
81804
81851
|
var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
|
|
81805
81852
|
var name = node.propertyName || node.name;
|
|
81806
81853
|
if (parentType && !ts.isBindingPattern(name)) {
|
|
@@ -111305,6 +111352,7 @@ var ts;
|
|
|
111305
111352
|
writeLine();
|
|
111306
111353
|
decreaseIndent();
|
|
111307
111354
|
}
|
|
111355
|
+
emitList(node, node.members, 2 /* PreserveLines */);
|
|
111308
111356
|
writePunctuation("}");
|
|
111309
111357
|
}
|
|
111310
111358
|
function emitLiteralType(node) {
|
|
@@ -116898,6 +116946,13 @@ var ts;
|
|
|
116898
116946
|
return "skip";
|
|
116899
116947
|
}
|
|
116900
116948
|
break;
|
|
116949
|
+
case 270 /* ImportSpecifier */:
|
|
116950
|
+
case 275 /* ExportSpecifier */:
|
|
116951
|
+
if (node.isTypeOnly) {
|
|
116952
|
+
diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, ts.isImportSpecifier(node) ? "import...type" : "export...type"));
|
|
116953
|
+
return "skip";
|
|
116954
|
+
}
|
|
116955
|
+
break;
|
|
116901
116956
|
case 265 /* ImportEqualsDeclaration */:
|
|
116902
116957
|
diagnostics.push(createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_TypeScript_files));
|
|
116903
116958
|
return "skip";
|
|
@@ -127759,6 +127814,14 @@ var ts;
|
|
|
127759
127814
|
});
|
|
127760
127815
|
}
|
|
127761
127816
|
ts.signatureToDisplayParts = signatureToDisplayParts;
|
|
127817
|
+
function nodeToDisplayParts(node, enclosingDeclaration) {
|
|
127818
|
+
var file = enclosingDeclaration.getSourceFile();
|
|
127819
|
+
return mapToDisplayParts(function (writer) {
|
|
127820
|
+
var printer = ts.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
|
|
127821
|
+
printer.writeNode(4 /* Unspecified */, node, file, writer);
|
|
127822
|
+
});
|
|
127823
|
+
}
|
|
127824
|
+
ts.nodeToDisplayParts = nodeToDisplayParts;
|
|
127762
127825
|
function isImportOrExportSpecifierName(location) {
|
|
127763
127826
|
return !!location.parent && ts.isImportOrExportSpecifier(location.parent) && location.parent.propertyName === location;
|
|
127764
127827
|
}
|
|
@@ -130455,12 +130518,13 @@ var ts;
|
|
|
130455
130518
|
}
|
|
130456
130519
|
case 208 /* CallExpression */:
|
|
130457
130520
|
case 209 /* NewExpression */:
|
|
130521
|
+
case 285 /* JsxAttribute */:
|
|
130458
130522
|
if (!isRequireCallArgument(node) && !ts.isImportCall(parent)) {
|
|
130459
|
-
var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(node, position, sourceFile);
|
|
130523
|
+
var argumentInfo = ts.SignatureHelp.getArgumentInfoForCompletions(parent.kind === 285 /* JsxAttribute */ ? parent.parent : node, position, sourceFile);
|
|
130460
130524
|
// Get string literal completions from specialized signatures of the target
|
|
130461
130525
|
// i.e. declare function f(a: 'A');
|
|
130462
130526
|
// f("/*completion position*/")
|
|
130463
|
-
return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo, typeChecker) : fromContextualType();
|
|
130527
|
+
return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) : fromContextualType();
|
|
130464
130528
|
}
|
|
130465
130529
|
// falls through (is `require("")` or `require(""` or `import("")`)
|
|
130466
130530
|
case 266 /* ImportDeclaration */:
|
|
@@ -130497,15 +130561,22 @@ var ts;
|
|
|
130497
130561
|
return type !== current && ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal) ? type.literal.text : undefined;
|
|
130498
130562
|
});
|
|
130499
130563
|
}
|
|
130500
|
-
function getStringLiteralCompletionsFromSignature(argumentInfo, checker) {
|
|
130564
|
+
function getStringLiteralCompletionsFromSignature(call, arg, argumentInfo, checker) {
|
|
130501
130565
|
var isNewIdentifier = false;
|
|
130502
130566
|
var uniques = new ts.Map();
|
|
130503
130567
|
var candidates = [];
|
|
130504
|
-
|
|
130568
|
+
var editingArgument = ts.isJsxOpeningLikeElement(call) ? ts.Debug.checkDefined(ts.findAncestor(arg.parent, ts.isJsxAttribute)) : arg;
|
|
130569
|
+
checker.getResolvedSignatureForStringLiteralCompletions(call, editingArgument, candidates);
|
|
130505
130570
|
var types = ts.flatMap(candidates, function (candidate) {
|
|
130506
130571
|
if (!ts.signatureHasRestParameter(candidate) && argumentInfo.argumentCount > candidate.parameters.length)
|
|
130507
130572
|
return;
|
|
130508
130573
|
var type = candidate.getTypeParameterAtPosition(argumentInfo.argumentIndex);
|
|
130574
|
+
if (ts.isJsxOpeningLikeElement(call)) {
|
|
130575
|
+
var propType = checker.getTypeOfPropertyOfType(type, editingArgument.name.text);
|
|
130576
|
+
if (propType) {
|
|
130577
|
+
type = propType;
|
|
130578
|
+
}
|
|
130579
|
+
}
|
|
130509
130580
|
isNewIdentifier = isNewIdentifier || !!(type.flags & 4 /* String */);
|
|
130510
130581
|
return getStringLiteralTypes(type, uniques);
|
|
130511
130582
|
});
|
|
@@ -131048,43 +131119,28 @@ var ts;
|
|
|
131048
131119
|
// Exported only for tests
|
|
131049
131120
|
Completions.moduleSpecifierResolutionLimit = 100;
|
|
131050
131121
|
Completions.moduleSpecifierResolutionCacheAttemptLimit = 1000;
|
|
131051
|
-
|
|
131052
|
-
|
|
131053
|
-
|
|
131054
|
-
|
|
131055
|
-
|
|
131056
|
-
|
|
131057
|
-
|
|
131058
|
-
|
|
131059
|
-
|
|
131060
|
-
|
|
131061
|
-
|
|
131062
|
-
|
|
131063
|
-
|
|
131064
|
-
|
|
131065
|
-
|
|
131066
|
-
|
|
131067
|
-
|
|
131068
|
-
|
|
131069
|
-
|
|
131070
|
-
|
|
131071
|
-
|
|
131072
|
-
}
|
|
131073
|
-
var SortTextId;
|
|
131074
|
-
(function (SortTextId) {
|
|
131075
|
-
SortTextId[SortTextId["LocalDeclarationPriority"] = 10] = "LocalDeclarationPriority";
|
|
131076
|
-
SortTextId[SortTextId["LocationPriority"] = 11] = "LocationPriority";
|
|
131077
|
-
SortTextId[SortTextId["OptionalMember"] = 12] = "OptionalMember";
|
|
131078
|
-
SortTextId[SortTextId["MemberDeclaredBySpreadAssignment"] = 13] = "MemberDeclaredBySpreadAssignment";
|
|
131079
|
-
SortTextId[SortTextId["SuggestedClassMembers"] = 14] = "SuggestedClassMembers";
|
|
131080
|
-
SortTextId[SortTextId["GlobalsOrKeywords"] = 15] = "GlobalsOrKeywords";
|
|
131081
|
-
SortTextId[SortTextId["AutoImportSuggestions"] = 16] = "AutoImportSuggestions";
|
|
131082
|
-
// Don't use these directly.
|
|
131083
|
-
SortTextId[SortTextId["_JavaScriptIdentifiers"] = 18] = "_JavaScriptIdentifiers";
|
|
131084
|
-
SortTextId[SortTextId["_DeprecatedStart"] = 19] = "_DeprecatedStart";
|
|
131085
|
-
SortTextId[SortTextId["_First"] = 10] = "_First";
|
|
131086
|
-
SortTextId[SortTextId["DeprecatedOffset"] = 9] = "DeprecatedOffset";
|
|
131087
|
-
})(SortTextId || (SortTextId = {}));
|
|
131122
|
+
Completions.SortText = {
|
|
131123
|
+
// Presets
|
|
131124
|
+
LocalDeclarationPriority: "10",
|
|
131125
|
+
LocationPriority: "11",
|
|
131126
|
+
OptionalMember: "12",
|
|
131127
|
+
MemberDeclaredBySpreadAssignment: "13",
|
|
131128
|
+
SuggestedClassMembers: "14",
|
|
131129
|
+
GlobalsOrKeywords: "15",
|
|
131130
|
+
AutoImportSuggestions: "16",
|
|
131131
|
+
ClassMemberSnippets: "17",
|
|
131132
|
+
JavascriptIdentifiers: "18",
|
|
131133
|
+
// Transformations
|
|
131134
|
+
Deprecated: function (sortText) {
|
|
131135
|
+
return "z" + sortText;
|
|
131136
|
+
},
|
|
131137
|
+
ObjectLiteralProperty: function (presetSortText, symbolDisplayName) {
|
|
131138
|
+
return presetSortText + "\0" + symbolDisplayName + "\0";
|
|
131139
|
+
},
|
|
131140
|
+
SortBelow: function (sortText) {
|
|
131141
|
+
return sortText + "1";
|
|
131142
|
+
},
|
|
131143
|
+
};
|
|
131088
131144
|
/**
|
|
131089
131145
|
* Special values for `CompletionInfo['source']` used to disambiguate
|
|
131090
131146
|
* completion items with the same `name`. (Each completion item must
|
|
@@ -131104,6 +131160,8 @@ var ts;
|
|
|
131104
131160
|
CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
|
|
131105
131161
|
/** A type-only import that needs to be promoted in order to be used at the completion location */
|
|
131106
131162
|
CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
|
|
131163
|
+
/** Auto-import that comes attached to an object literal method snippet */
|
|
131164
|
+
CompletionSource["ObjectLiteralMethodSnippet"] = "ObjectLiteralMethodSnippet/";
|
|
131107
131165
|
})(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
|
|
131108
131166
|
var SymbolOriginInfoKind;
|
|
131109
131167
|
(function (SymbolOriginInfoKind) {
|
|
@@ -131114,6 +131172,7 @@ var ts;
|
|
|
131114
131172
|
SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
|
|
131115
131173
|
SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
|
|
131116
131174
|
SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
|
|
131175
|
+
SymbolOriginInfoKind[SymbolOriginInfoKind["ObjectLiteralMethod"] = 128] = "ObjectLiteralMethod";
|
|
131117
131176
|
SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
|
|
131118
131177
|
SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
|
|
131119
131178
|
})(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
|
|
@@ -131144,6 +131203,9 @@ var ts;
|
|
|
131144
131203
|
function originIsTypeOnlyAlias(origin) {
|
|
131145
131204
|
return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
|
|
131146
131205
|
}
|
|
131206
|
+
function originIsObjectLiteralMethod(origin) {
|
|
131207
|
+
return !!(origin && origin.kind & 128 /* ObjectLiteralMethod */);
|
|
131208
|
+
}
|
|
131147
131209
|
var KeywordCompletionFilters;
|
|
131148
131210
|
(function (KeywordCompletionFilters) {
|
|
131149
131211
|
KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
|
|
@@ -131236,7 +131298,7 @@ var ts;
|
|
|
131236
131298
|
&& (previousToken.kind === 81 /* BreakKeyword */ || previousToken.kind === 86 /* ContinueKeyword */ || previousToken.kind === 79 /* Identifier */)) {
|
|
131237
131299
|
return getLabelCompletionAtPosition(previousToken.parent);
|
|
131238
131300
|
}
|
|
131239
|
-
var completionData = getCompletionData(program, log, sourceFile,
|
|
131301
|
+
var completionData = getCompletionData(program, log, sourceFile, compilerOptions, position, preferences, /*detailsEntryId*/ undefined, host, formatContext, cancellationToken);
|
|
131240
131302
|
if (!completionData) {
|
|
131241
131303
|
return undefined;
|
|
131242
131304
|
}
|
|
@@ -131334,7 +131396,7 @@ var ts;
|
|
|
131334
131396
|
name: ts.tokenToString(keyword),
|
|
131335
131397
|
kind: "keyword" /* keyword */,
|
|
131336
131398
|
kindModifiers: "" /* none */,
|
|
131337
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
131399
|
+
sortText: Completions.SortText.GlobalsOrKeywords,
|
|
131338
131400
|
};
|
|
131339
131401
|
}
|
|
131340
131402
|
function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
|
|
@@ -131363,7 +131425,7 @@ var ts;
|
|
|
131363
131425
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
131364
131426
|
}
|
|
131365
131427
|
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position) {
|
|
131366
|
-
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression,
|
|
131428
|
+
var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextMap = completionData.symbolToSortTextMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
131367
131429
|
// Verify if the file is JSX language variant
|
|
131368
131430
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
131369
131431
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -131374,7 +131436,7 @@ var ts;
|
|
|
131374
131436
|
var entries = ts.createSortedArray();
|
|
131375
131437
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
131376
131438
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
131377
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap,
|
|
131439
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
131378
131440
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
|
|
131379
131441
|
}
|
|
131380
131442
|
else {
|
|
@@ -131382,7 +131444,7 @@ var ts;
|
|
|
131382
131444
|
return undefined;
|
|
131383
131445
|
}
|
|
131384
131446
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
131385
|
-
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap,
|
|
131447
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
131386
131448
|
}
|
|
131387
131449
|
if (keywordFilters !== 0 /* None */) {
|
|
131388
131450
|
var entryNames_1 = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -131463,7 +131525,7 @@ var ts;
|
|
|
131463
131525
|
name: fullClosingTag,
|
|
131464
131526
|
kind: "class" /* classElement */,
|
|
131465
131527
|
kindModifiers: undefined,
|
|
131466
|
-
sortText: SortText.LocationPriority,
|
|
131528
|
+
sortText: Completions.SortText.LocationPriority,
|
|
131467
131529
|
};
|
|
131468
131530
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, optionalReplacementSpan: replacementSpan, entries: [entry] };
|
|
131469
131531
|
}
|
|
@@ -131482,7 +131544,7 @@ var ts;
|
|
|
131482
131544
|
name: realName,
|
|
131483
131545
|
kind: "warning" /* warning */,
|
|
131484
131546
|
kindModifiers: "",
|
|
131485
|
-
sortText: SortText.JavascriptIdentifiers,
|
|
131547
|
+
sortText: Completions.SortText.JavascriptIdentifiers,
|
|
131486
131548
|
isFromUncheckedFile: true
|
|
131487
131549
|
}, compareCompletionEntries);
|
|
131488
131550
|
}
|
|
@@ -131493,7 +131555,7 @@ var ts;
|
|
|
131493
131555
|
ts.isString(literal) ? ts.quote(sourceFile, preferences, literal) : JSON.stringify(literal);
|
|
131494
131556
|
}
|
|
131495
131557
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
131496
|
-
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
131558
|
+
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: Completions.SortText.LocationPriority };
|
|
131497
131559
|
}
|
|
131498
131560
|
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
131499
131561
|
var _a, _b;
|
|
@@ -131504,6 +131566,7 @@ var ts;
|
|
|
131504
131566
|
var source = getSourceFromOrigin(origin);
|
|
131505
131567
|
var sourceDisplay;
|
|
131506
131568
|
var hasAction;
|
|
131569
|
+
var labelDetails;
|
|
131507
131570
|
var typeChecker = program.getTypeChecker();
|
|
131508
131571
|
var insertQuestionDot = origin && originIsNullableMember(origin);
|
|
131509
131572
|
var useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess;
|
|
@@ -131564,12 +131627,25 @@ var ts;
|
|
|
131564
131627
|
isClassLikeMemberCompletion(symbol, location)) {
|
|
131565
131628
|
var importAdder = void 0;
|
|
131566
131629
|
(_b = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken, formatContext), insertText = _b.insertText, isSnippet = _b.isSnippet, importAdder = _b.importAdder, replacementSpan = _b.replacementSpan);
|
|
131567
|
-
sortText = SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
|
|
131630
|
+
sortText = Completions.SortText.ClassMemberSnippets; // sortText has to be lower priority than the sortText for keywords. See #47852.
|
|
131568
131631
|
if (importAdder === null || importAdder === void 0 ? void 0 : importAdder.hasFixes()) {
|
|
131569
131632
|
hasAction = true;
|
|
131570
131633
|
source = CompletionSource.ClassMemberSnippet;
|
|
131571
131634
|
}
|
|
131572
131635
|
}
|
|
131636
|
+
if (origin && originIsObjectLiteralMethod(origin)) {
|
|
131637
|
+
var importAdder = void 0;
|
|
131638
|
+
(insertText = origin.insertText, isSnippet = origin.isSnippet, importAdder = origin.importAdder, labelDetails = origin.labelDetails);
|
|
131639
|
+
if (!preferences.useLabelDetailsInCompletionEntries) {
|
|
131640
|
+
name = name + labelDetails.detail;
|
|
131641
|
+
labelDetails = undefined;
|
|
131642
|
+
}
|
|
131643
|
+
source = CompletionSource.ObjectLiteralMethodSnippet;
|
|
131644
|
+
sortText = Completions.SortText.SortBelow(sortText);
|
|
131645
|
+
if (importAdder.hasFixes()) {
|
|
131646
|
+
hasAction = true;
|
|
131647
|
+
}
|
|
131648
|
+
}
|
|
131573
131649
|
if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
|
131574
131650
|
var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
|
|
131575
131651
|
var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
|
@@ -131617,6 +131693,7 @@ var ts;
|
|
|
131617
131693
|
insertText: insertText,
|
|
131618
131694
|
replacementSpan: replacementSpan,
|
|
131619
131695
|
sourceDisplay: sourceDisplay,
|
|
131696
|
+
labelDetails: labelDetails,
|
|
131620
131697
|
isSnippet: isSnippet,
|
|
131621
131698
|
isPackageJsonImport: originIsPackageJsonImport(origin) || undefined,
|
|
131622
131699
|
isImportStatementCompletion: !!importCompletionNode || undefined,
|
|
@@ -131728,27 +131805,15 @@ var ts;
|
|
|
131728
131805
|
completionNodes.push(node);
|
|
131729
131806
|
}, body, 2 /* Property */, isAbstract);
|
|
131730
131807
|
if (completionNodes.length) {
|
|
131808
|
+
var format = 1 /* MultiLine */ | 131072 /* NoTrailingNewLine */;
|
|
131731
131809
|
replacementSpan = modifiersSpan;
|
|
131732
131810
|
// If we have access to formatting settings, we print the nodes using the emitter,
|
|
131733
131811
|
// and then format the printed text.
|
|
131734
131812
|
if (formatContext) {
|
|
131735
|
-
|
|
131736
|
-
text: printer.printSnippetList(1 /* MultiLine */ | 131072 /* NoTrailingNewLine */, ts.factory.createNodeArray(completionNodes), sourceFile),
|
|
131737
|
-
getLineAndCharacterOfPosition: function (pos) {
|
|
131738
|
-
return ts.getLineAndCharacterOfPosition(this, pos);
|
|
131739
|
-
},
|
|
131740
|
-
};
|
|
131741
|
-
var formatOptions_1 = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
131742
|
-
var changes = ts.flatMap(completionNodes, function (node) {
|
|
131743
|
-
var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
|
|
131744
|
-
return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile_1, sourceFile.languageVariant,
|
|
131745
|
-
/* indentation */ 0,
|
|
131746
|
-
/* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions_1 }));
|
|
131747
|
-
});
|
|
131748
|
-
insertText = ts.textChanges.applyChanges(syntheticFile_1.text, changes);
|
|
131813
|
+
insertText = printer.printAndFormatSnippetList(format, ts.factory.createNodeArray(completionNodes), sourceFile, formatContext);
|
|
131749
131814
|
}
|
|
131750
131815
|
else { // Otherwise, just use emitter to print the new nodes.
|
|
131751
|
-
insertText = printer.printSnippetList(
|
|
131816
|
+
insertText = printer.printSnippetList(format, ts.factory.createNodeArray(completionNodes), sourceFile);
|
|
131752
131817
|
}
|
|
131753
131818
|
}
|
|
131754
131819
|
return { insertText: insertText, isSnippet: isSnippet, importAdder: importAdder, replacementSpan: replacementSpan };
|
|
@@ -131798,12 +131863,113 @@ var ts;
|
|
|
131798
131863
|
}
|
|
131799
131864
|
return undefined;
|
|
131800
131865
|
}
|
|
131866
|
+
function getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclaration, program, host, options, preferences, formatContext) {
|
|
131867
|
+
var isSnippet = preferences.includeCompletionsWithSnippetText || undefined;
|
|
131868
|
+
var insertText = name;
|
|
131869
|
+
var sourceFile = enclosingDeclaration.getSourceFile();
|
|
131870
|
+
var importAdder = ts.codefix.createImportAdder(sourceFile, program, preferences, host);
|
|
131871
|
+
var method = createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder);
|
|
131872
|
+
if (!method) {
|
|
131873
|
+
return undefined;
|
|
131874
|
+
}
|
|
131875
|
+
var printer = createSnippetPrinter({
|
|
131876
|
+
removeComments: true,
|
|
131877
|
+
module: options.module,
|
|
131878
|
+
target: options.target,
|
|
131879
|
+
omitTrailingSemicolon: false,
|
|
131880
|
+
newLine: ts.getNewLineKind(ts.getNewLineCharacter(options, ts.maybeBind(host, host.getNewLine))),
|
|
131881
|
+
});
|
|
131882
|
+
if (formatContext) {
|
|
131883
|
+
insertText = printer.printAndFormatSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile, formatContext);
|
|
131884
|
+
}
|
|
131885
|
+
else {
|
|
131886
|
+
insertText = printer.printSnippetList(16 /* CommaDelimited */ | 64 /* AllowTrailingComma */, ts.factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile);
|
|
131887
|
+
}
|
|
131888
|
+
var signaturePrinter = ts.createPrinter({
|
|
131889
|
+
removeComments: true,
|
|
131890
|
+
module: options.module,
|
|
131891
|
+
target: options.target,
|
|
131892
|
+
omitTrailingSemicolon: true,
|
|
131893
|
+
});
|
|
131894
|
+
// The `labelDetails.detail` will be displayed right beside the method name,
|
|
131895
|
+
// so we drop the name (and modifiers) from the signature.
|
|
131896
|
+
var methodSignature = ts.factory.createMethodSignature(
|
|
131897
|
+
/*modifiers*/ undefined,
|
|
131898
|
+
/*name*/ "", method.questionToken, method.typeParameters, method.parameters, method.type);
|
|
131899
|
+
var labelDetails = { detail: signaturePrinter.printNode(4 /* Unspecified */, methodSignature, sourceFile) };
|
|
131900
|
+
return { isSnippet: isSnippet, insertText: insertText, importAdder: importAdder, labelDetails: labelDetails };
|
|
131901
|
+
}
|
|
131902
|
+
;
|
|
131903
|
+
function createObjectLiteralMethod(symbol, enclosingDeclaration, sourceFile, program, host, preferences, importAdder) {
|
|
131904
|
+
var declarations = symbol.getDeclarations();
|
|
131905
|
+
if (!(declarations && declarations.length)) {
|
|
131906
|
+
return undefined;
|
|
131907
|
+
}
|
|
131908
|
+
var checker = program.getTypeChecker();
|
|
131909
|
+
var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
|
|
131910
|
+
var declaration = declarations[0];
|
|
131911
|
+
var name = ts.getSynthesizedDeepClone(ts.getNameOfDeclaration(declaration), /*includeTrivia*/ false);
|
|
131912
|
+
var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
|
|
131913
|
+
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
131914
|
+
var builderFlags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : undefined;
|
|
131915
|
+
switch (declaration.kind) {
|
|
131916
|
+
case 166 /* PropertySignature */:
|
|
131917
|
+
case 167 /* PropertyDeclaration */:
|
|
131918
|
+
case 168 /* MethodSignature */:
|
|
131919
|
+
case 169 /* MethodDeclaration */: {
|
|
131920
|
+
var effectiveType = type.flags & 1048576 /* Union */ && type.types.length < 10
|
|
131921
|
+
? checker.getUnionType(type.types, 2 /* Subtype */)
|
|
131922
|
+
: type;
|
|
131923
|
+
if (effectiveType.flags & 1048576 /* Union */) {
|
|
131924
|
+
// Only offer the completion if there's a single function type component.
|
|
131925
|
+
var functionTypes = ts.filter(effectiveType.types, function (type) { return checker.getSignaturesOfType(type, 0 /* Call */).length > 0; });
|
|
131926
|
+
if (functionTypes.length === 1) {
|
|
131927
|
+
effectiveType = functionTypes[0];
|
|
131928
|
+
}
|
|
131929
|
+
else {
|
|
131930
|
+
return undefined;
|
|
131931
|
+
}
|
|
131932
|
+
}
|
|
131933
|
+
var signatures = checker.getSignaturesOfType(effectiveType, 0 /* Call */);
|
|
131934
|
+
if (signatures.length !== 1) {
|
|
131935
|
+
// We don't support overloads in object literals.
|
|
131936
|
+
return undefined;
|
|
131937
|
+
}
|
|
131938
|
+
var typeNode = checker.typeToTypeNode(effectiveType, enclosingDeclaration, builderFlags, ts.codefix.getNoopSymbolTrackerWithResolver({ program: program, host: host }));
|
|
131939
|
+
if (!typeNode || !ts.isFunctionTypeNode(typeNode)) {
|
|
131940
|
+
return undefined;
|
|
131941
|
+
}
|
|
131942
|
+
var importableReference = ts.codefix.tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
|
|
131943
|
+
if (importableReference) {
|
|
131944
|
+
typeNode = importableReference.typeNode;
|
|
131945
|
+
ts.codefix.importSymbols(importAdder, importableReference.symbols);
|
|
131946
|
+
}
|
|
131947
|
+
var body = void 0;
|
|
131948
|
+
if (preferences.includeCompletionsWithSnippetText) {
|
|
131949
|
+
var emptyStmt = ts.factory.createEmptyStatement();
|
|
131950
|
+
body = ts.factory.createBlock([emptyStmt], /* multiline */ true);
|
|
131951
|
+
ts.setSnippetElement(emptyStmt, { kind: 0 /* TabStop */, order: 0 });
|
|
131952
|
+
}
|
|
131953
|
+
else {
|
|
131954
|
+
body = ts.factory.createBlock([], /* multiline */ true);
|
|
131955
|
+
}
|
|
131956
|
+
return ts.factory.createMethodDeclaration(
|
|
131957
|
+
/*decorators*/ undefined,
|
|
131958
|
+
/*modifiers*/ undefined,
|
|
131959
|
+
/*asteriskToken*/ undefined, name,
|
|
131960
|
+
/*questionToken*/ undefined, typeNode.typeParameters, typeNode.parameters, typeNode.type, body);
|
|
131961
|
+
}
|
|
131962
|
+
default:
|
|
131963
|
+
return undefined;
|
|
131964
|
+
}
|
|
131965
|
+
}
|
|
131801
131966
|
function createSnippetPrinter(printerOptions) {
|
|
131802
131967
|
var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
|
|
131803
131968
|
var printer = ts.createPrinter(printerOptions, baseWriter);
|
|
131804
131969
|
var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
|
|
131805
131970
|
return {
|
|
131806
131971
|
printSnippetList: printSnippetList,
|
|
131972
|
+
printAndFormatSnippetList: printAndFormatSnippetList,
|
|
131807
131973
|
};
|
|
131808
131974
|
/* Snippet-escaping version of `printer.printList`. */
|
|
131809
131975
|
function printSnippetList(format, list, sourceFile) {
|
|
@@ -131811,6 +131977,22 @@ var ts;
|
|
|
131811
131977
|
printer.writeList(format, list, sourceFile, writer);
|
|
131812
131978
|
return writer.getText();
|
|
131813
131979
|
}
|
|
131980
|
+
function printAndFormatSnippetList(format, list, sourceFile, formatContext) {
|
|
131981
|
+
var syntheticFile = {
|
|
131982
|
+
text: printSnippetList(format, list, sourceFile),
|
|
131983
|
+
getLineAndCharacterOfPosition: function (pos) {
|
|
131984
|
+
return ts.getLineAndCharacterOfPosition(this, pos);
|
|
131985
|
+
},
|
|
131986
|
+
};
|
|
131987
|
+
var formatOptions = ts.getFormatCodeSettingsForWriting(formatContext, sourceFile);
|
|
131988
|
+
var changes = ts.flatMap(list, function (node) {
|
|
131989
|
+
var nodeWithPos = ts.textChanges.assignPositionsToNode(node);
|
|
131990
|
+
return ts.formatting.formatNodeGivenIndentation(nodeWithPos, syntheticFile, sourceFile.languageVariant,
|
|
131991
|
+
/* indentation */ 0,
|
|
131992
|
+
/* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions }));
|
|
131993
|
+
});
|
|
131994
|
+
return ts.textChanges.applyChanges(syntheticFile.text, changes);
|
|
131995
|
+
}
|
|
131814
131996
|
}
|
|
131815
131997
|
function originToCompletionEntryData(origin) {
|
|
131816
131998
|
var ambientModuleName = origin.fileName ? undefined : ts.stripQuotes(origin.moduleSymbol.name);
|
|
@@ -131908,7 +132090,7 @@ var ts;
|
|
|
131908
132090
|
return CompletionSource.TypeOnlyAlias;
|
|
131909
132091
|
}
|
|
131910
132092
|
}
|
|
131911
|
-
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap,
|
|
132093
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextMap, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
131912
132094
|
var _a;
|
|
131913
132095
|
var start = ts.timestamp();
|
|
131914
132096
|
var variableDeclaration = getVariableDeclaration(location);
|
|
@@ -131923,12 +132105,12 @@ var ts;
|
|
|
131923
132105
|
var symbol = symbols[i];
|
|
131924
132106
|
var origin = symbolToOriginInfoMap === null || symbolToOriginInfoMap === void 0 ? void 0 : symbolToOriginInfoMap[i];
|
|
131925
132107
|
var info = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind, !!jsxIdentifierExpected);
|
|
131926
|
-
if (!info || uniques.get(info.name) || kind === 1 /* Global */ &&
|
|
132108
|
+
if (!info || (uniques.get(info.name) && (!origin || !originIsObjectLiteralMethod(origin))) || kind === 1 /* Global */ && symbolToSortTextMap && !shouldIncludeSymbol(symbol, symbolToSortTextMap)) {
|
|
131927
132109
|
continue;
|
|
131928
132110
|
}
|
|
131929
132111
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
131930
|
-
var
|
|
131931
|
-
var sortText = (isDeprecated(symbol, typeChecker) ?
|
|
132112
|
+
var originalSortText = (_a = symbolToSortTextMap === null || symbolToSortTextMap === void 0 ? void 0 : symbolToSortTextMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : Completions.SortText.LocationPriority;
|
|
132113
|
+
var sortText = (isDeprecated(symbol, typeChecker) ? Completions.SortText.Deprecated(originalSortText) : originalSortText);
|
|
131932
132114
|
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
131933
132115
|
if (!entry) {
|
|
131934
132116
|
continue;
|
|
@@ -131946,7 +132128,7 @@ var ts;
|
|
|
131946
132128
|
has: function (name) { return uniques.has(name); },
|
|
131947
132129
|
add: function (name) { return uniques.set(name, true); },
|
|
131948
132130
|
};
|
|
131949
|
-
function shouldIncludeSymbol(symbol,
|
|
132131
|
+
function shouldIncludeSymbol(symbol, symbolToSortTextMap) {
|
|
131950
132132
|
var allFlags = symbol.flags;
|
|
131951
132133
|
if (!ts.isSourceFile(location)) {
|
|
131952
132134
|
// export = /**/ here we want to get all meanings, so any symbol is ok
|
|
@@ -131968,9 +132150,9 @@ var ts;
|
|
|
131968
132150
|
// Auto Imports are not available for scripts so this conditional is always false
|
|
131969
132151
|
if (!!sourceFile.externalModuleIndicator
|
|
131970
132152
|
&& !compilerOptions.allowUmdGlobalAccess
|
|
131971
|
-
&&
|
|
131972
|
-
&& (
|
|
131973
|
-
||
|
|
132153
|
+
&& symbolToSortTextMap[ts.getSymbolId(symbol)] === Completions.SortText.GlobalsOrKeywords
|
|
132154
|
+
&& (symbolToSortTextMap[ts.getSymbolId(symbolOrigin)] === Completions.SortText.AutoImportSuggestions
|
|
132155
|
+
|| symbolToSortTextMap[ts.getSymbolId(symbolOrigin)] === Completions.SortText.LocationPriority)) {
|
|
131974
132156
|
return false;
|
|
131975
132157
|
}
|
|
131976
132158
|
allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
|
|
@@ -132010,7 +132192,7 @@ var ts;
|
|
|
132010
132192
|
name: name,
|
|
132011
132193
|
kindModifiers: "" /* none */,
|
|
132012
132194
|
kind: "label" /* label */,
|
|
132013
|
-
sortText: SortText.LocationPriority
|
|
132195
|
+
sortText: Completions.SortText.LocationPriority
|
|
132014
132196
|
});
|
|
132015
132197
|
}
|
|
132016
132198
|
}
|
|
@@ -132036,7 +132218,7 @@ var ts;
|
|
|
132036
132218
|
}
|
|
132037
132219
|
}
|
|
132038
132220
|
var compilerOptions = program.getCompilerOptions();
|
|
132039
|
-
var completionData = getCompletionData(program, log, sourceFile,
|
|
132221
|
+
var completionData = getCompletionData(program, log, sourceFile, compilerOptions, position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId, host, /*formatContext*/ undefined);
|
|
132040
132222
|
if (!completionData) {
|
|
132041
132223
|
return { type: "none" };
|
|
132042
132224
|
}
|
|
@@ -132054,7 +132236,9 @@ var ts;
|
|
|
132054
132236
|
return ts.firstDefined(symbols, function (symbol, index) {
|
|
132055
132237
|
var origin = symbolToOriginInfoMap[index];
|
|
132056
132238
|
var info = getCompletionEntryDisplayNameForSymbol(symbol, ts.getEmitScriptTarget(compilerOptions), origin, completionKind, completionData.isJsxIdentifierExpected);
|
|
132057
|
-
return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & 106500 /* ClassMember */
|
|
132239
|
+
return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & 106500 /* ClassMember */
|
|
132240
|
+
|| entryId.source === CompletionSource.ObjectLiteralMethodSnippet && symbol.flags & (4 /* Property */ | 8192 /* Method */)
|
|
132241
|
+
|| getSourceFromOrigin(origin) === entryId.source)
|
|
132058
132242
|
? { type: "symbol", symbol: symbol, location: location, origin: origin, contextToken: contextToken, previousToken: previousToken, isJsxInitializer: isJsxInitializer, isTypeOnlyLocation: isTypeOnlyLocation }
|
|
132059
132243
|
: undefined;
|
|
132060
132244
|
}) || { type: "none" };
|
|
@@ -132136,6 +132320,20 @@ var ts;
|
|
|
132136
132320
|
};
|
|
132137
132321
|
}
|
|
132138
132322
|
}
|
|
132323
|
+
if (source === CompletionSource.ObjectLiteralMethodSnippet) {
|
|
132324
|
+
var enclosingDeclaration = tryGetObjectLikeCompletionContainer(contextToken);
|
|
132325
|
+
var importAdder = getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclaration, program, host, compilerOptions, preferences, formatContext).importAdder;
|
|
132326
|
+
if (importAdder.hasFixes()) {
|
|
132327
|
+
var changes = ts.textChanges.ChangeTracker.with({ host: host, formatContext: formatContext, preferences: preferences }, importAdder.writeFixes);
|
|
132328
|
+
return {
|
|
132329
|
+
sourceDisplay: undefined,
|
|
132330
|
+
codeActions: [{
|
|
132331
|
+
changes: changes,
|
|
132332
|
+
description: ts.diagnosticToString([ts.Diagnostics.Includes_imports_of_types_referenced_by_0, name]),
|
|
132333
|
+
}],
|
|
132334
|
+
};
|
|
132335
|
+
}
|
|
132336
|
+
}
|
|
132139
132337
|
if (originIsTypeOnlyAlias(origin)) {
|
|
132140
132338
|
var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
|
|
132141
132339
|
ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
|
|
@@ -132228,8 +132426,9 @@ var ts;
|
|
|
132228
132426
|
var _a;
|
|
132229
132427
|
return !!((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.kind === 305 /* SourceFile */; }));
|
|
132230
132428
|
}
|
|
132231
|
-
function getCompletionData(program, log, sourceFile,
|
|
132429
|
+
function getCompletionData(program, log, sourceFile, compilerOptions, position, preferences, detailsEntryId, host, formatContext, cancellationToken) {
|
|
132232
132430
|
var typeChecker = program.getTypeChecker();
|
|
132431
|
+
var inUncheckedFile = isUncheckedFile(sourceFile, compilerOptions);
|
|
132233
132432
|
var start = ts.timestamp();
|
|
132234
132433
|
var currentToken = ts.getTokenAtPosition(sourceFile, position); // TODO: GH#15853
|
|
132235
132434
|
// We will check for jsdoc comments with insideComment and getJsDocTagAtPosition. (TODO: that seems rather inefficient to check the same thing so many times.)
|
|
@@ -132472,7 +132671,7 @@ var ts;
|
|
|
132472
132671
|
// This also gets mutated in nested-functions after the return
|
|
132473
132672
|
var symbols = [];
|
|
132474
132673
|
var symbolToOriginInfoMap = [];
|
|
132475
|
-
var
|
|
132674
|
+
var symbolToSortTextMap = [];
|
|
132476
132675
|
var seenPropertySymbols = new ts.Map();
|
|
132477
132676
|
var isTypeOnlyLocation = isTypeOnlyCompletion();
|
|
132478
132677
|
var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
|
|
@@ -132527,7 +132726,7 @@ var ts;
|
|
|
132527
132726
|
contextToken: contextToken,
|
|
132528
132727
|
isJsxInitializer: isJsxInitializer,
|
|
132529
132728
|
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
|
|
132530
|
-
|
|
132729
|
+
symbolToSortTextMap: symbolToSortTextMap,
|
|
132531
132730
|
isTypeOnlyLocation: isTypeOnlyLocation,
|
|
132532
132731
|
isJsxIdentifierExpected: isJsxIdentifierExpected,
|
|
132533
132732
|
isRightOfOpenTag: isRightOfOpenTag,
|
|
@@ -132641,7 +132840,7 @@ var ts;
|
|
|
132641
132840
|
isNewIdentifierLocation = true;
|
|
132642
132841
|
}
|
|
132643
132842
|
var propertyAccess = node.kind === 200 /* ImportType */ ? node : node.parent;
|
|
132644
|
-
if (
|
|
132843
|
+
if (inUncheckedFile) {
|
|
132645
132844
|
// In javascript files, for union types, we don't just get the members that
|
|
132646
132845
|
// the individual types have in common, we also include all the members that
|
|
132647
132846
|
// each individual type has. This is because we're going to add all identifiers
|
|
@@ -132726,7 +132925,7 @@ var ts;
|
|
|
132726
132925
|
}
|
|
132727
132926
|
function addSymbolSortInfo(symbol) {
|
|
132728
132927
|
if (isStaticProperty(symbol)) {
|
|
132729
|
-
|
|
132928
|
+
symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.LocalDeclarationPriority;
|
|
132730
132929
|
}
|
|
132731
132930
|
}
|
|
132732
132931
|
function addSymbolOriginInfo(symbol) {
|
|
@@ -132836,7 +133035,7 @@ var ts;
|
|
|
132836
133035
|
var symbol = symbols[i];
|
|
132837
133036
|
if (!typeChecker.isArgumentsSymbol(symbol) &&
|
|
132838
133037
|
!ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
|
|
132839
|
-
|
|
133038
|
+
symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.GlobalsOrKeywords;
|
|
132840
133039
|
}
|
|
132841
133040
|
if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
|
|
132842
133041
|
var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
|
|
@@ -132854,7 +133053,7 @@ var ts;
|
|
|
132854
133053
|
var symbol = _a[_i];
|
|
132855
133054
|
symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
|
|
132856
133055
|
symbols.push(symbol);
|
|
132857
|
-
|
|
133056
|
+
symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.SuggestedClassMembers;
|
|
132858
133057
|
}
|
|
132859
133058
|
}
|
|
132860
133059
|
}
|
|
@@ -132932,7 +133131,7 @@ var ts;
|
|
|
132932
133131
|
}
|
|
132933
133132
|
return false;
|
|
132934
133133
|
}
|
|
132935
|
-
/** Mutates `symbols`, `symbolToOriginInfoMap`, and `
|
|
133134
|
+
/** Mutates `symbols`, `symbolToOriginInfoMap`, and `symbolToSortTextMap` */
|
|
132936
133135
|
function collectAutoImports() {
|
|
132937
133136
|
var _a, _b;
|
|
132938
133137
|
if (!shouldOfferImportCompletions())
|
|
@@ -133014,14 +133213,55 @@ var ts;
|
|
|
133014
133213
|
}
|
|
133015
133214
|
function pushAutoImportSymbol(symbol, origin) {
|
|
133016
133215
|
var symbolId = ts.getSymbolId(symbol);
|
|
133017
|
-
if (
|
|
133216
|
+
if (symbolToSortTextMap[symbolId] === Completions.SortText.GlobalsOrKeywords) {
|
|
133018
133217
|
// If an auto-importable symbol is available as a global, don't add the auto import
|
|
133019
133218
|
return;
|
|
133020
133219
|
}
|
|
133021
133220
|
symbolToOriginInfoMap[symbols.length] = origin;
|
|
133022
|
-
|
|
133221
|
+
symbolToSortTextMap[symbolId] = importCompletionNode ? Completions.SortText.LocationPriority : Completions.SortText.AutoImportSuggestions;
|
|
133023
133222
|
symbols.push(symbol);
|
|
133024
133223
|
}
|
|
133224
|
+
/* Mutates `symbols` and `symbolToOriginInfoMap`. */
|
|
133225
|
+
function collectObjectLiteralMethodSymbols(members, enclosingDeclaration) {
|
|
133226
|
+
// TODO: support JS files.
|
|
133227
|
+
if (ts.isInJSFile(location)) {
|
|
133228
|
+
return;
|
|
133229
|
+
}
|
|
133230
|
+
members.forEach(function (member) {
|
|
133231
|
+
if (!isObjectLiteralMethodSymbol(member)) {
|
|
133232
|
+
return;
|
|
133233
|
+
}
|
|
133234
|
+
var displayName = getCompletionEntryDisplayNameForSymbol(member, ts.getEmitScriptTarget(compilerOptions),
|
|
133235
|
+
/*origin*/ undefined, 0 /* ObjectPropertyDeclaration */,
|
|
133236
|
+
/*jsxIdentifierExpected*/ false);
|
|
133237
|
+
if (!displayName) {
|
|
133238
|
+
return;
|
|
133239
|
+
}
|
|
133240
|
+
var name = displayName.name;
|
|
133241
|
+
var entryProps = getEntryForObjectLiteralMethodCompletion(member, name, enclosingDeclaration, program, host, compilerOptions, preferences, formatContext);
|
|
133242
|
+
if (!entryProps) {
|
|
133243
|
+
return;
|
|
133244
|
+
}
|
|
133245
|
+
var origin = __assign({ kind: 128 /* ObjectLiteralMethod */ }, entryProps);
|
|
133246
|
+
symbolToOriginInfoMap[symbols.length] = origin;
|
|
133247
|
+
symbols.push(member);
|
|
133248
|
+
});
|
|
133249
|
+
}
|
|
133250
|
+
function isObjectLiteralMethodSymbol(symbol) {
|
|
133251
|
+
/*
|
|
133252
|
+
For an object type
|
|
133253
|
+
`type Foo = {
|
|
133254
|
+
bar(x: number): void;
|
|
133255
|
+
foo: (x: string) => string;
|
|
133256
|
+
}`,
|
|
133257
|
+
`bar` will have symbol flag `Method`,
|
|
133258
|
+
`foo` will have symbol flag `Property`.
|
|
133259
|
+
*/
|
|
133260
|
+
if (!(symbol.flags & (4 /* Property */ | 8192 /* Method */))) {
|
|
133261
|
+
return false;
|
|
133262
|
+
}
|
|
133263
|
+
return true;
|
|
133264
|
+
}
|
|
133025
133265
|
/**
|
|
133026
133266
|
* Finds the first node that "embraces" the position, so that one may
|
|
133027
133267
|
* accurately aggregate locals from the closest containing scope.
|
|
@@ -133155,6 +133395,7 @@ var ts;
|
|
|
133155
133395
|
* @returns true if 'symbols' was successfully populated; false otherwise.
|
|
133156
133396
|
*/
|
|
133157
133397
|
function tryGetObjectLikeCompletionSymbols() {
|
|
133398
|
+
var symbolsStartIndex = symbols.length;
|
|
133158
133399
|
var objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken);
|
|
133159
133400
|
if (!objectLikeContainer)
|
|
133160
133401
|
return 0 /* Continue */;
|
|
@@ -133219,9 +133460,16 @@ var ts;
|
|
|
133219
133460
|
}
|
|
133220
133461
|
if (typeMembers && typeMembers.length > 0) {
|
|
133221
133462
|
// Add filtered items to the completion list
|
|
133222
|
-
|
|
133463
|
+
var filteredMembers = filterObjectMembersList(typeMembers, ts.Debug.checkDefined(existingMembers));
|
|
133464
|
+
symbols = ts.concatenate(symbols, filteredMembers);
|
|
133465
|
+
setSortTextToOptionalMember();
|
|
133466
|
+
if (objectLikeContainer.kind === 205 /* ObjectLiteralExpression */
|
|
133467
|
+
&& preferences.includeCompletionsWithObjectLiteralMethodSnippets
|
|
133468
|
+
&& preferences.includeCompletionsWithInsertText) {
|
|
133469
|
+
transformObjectLiteralMembersSortText(symbolsStartIndex);
|
|
133470
|
+
collectObjectLiteralMethodSymbols(filteredMembers, objectLikeContainer);
|
|
133471
|
+
}
|
|
133223
133472
|
}
|
|
133224
|
-
setSortTextToOptionalMember();
|
|
133225
133473
|
return 1 /* Success */;
|
|
133226
133474
|
}
|
|
133227
133475
|
/**
|
|
@@ -133296,7 +133544,7 @@ var ts;
|
|
|
133296
133544
|
var _a, _b;
|
|
133297
133545
|
symbols.push(symbol);
|
|
133298
133546
|
if ((_b = (_a = localsContainer.symbol) === null || _a === void 0 ? void 0 : _a.exports) === null || _b === void 0 ? void 0 : _b.has(name)) {
|
|
133299
|
-
|
|
133547
|
+
symbolToSortTextMap[ts.getSymbolId(symbol)] = Completions.SortText.OptionalMember;
|
|
133300
133548
|
}
|
|
133301
133549
|
});
|
|
133302
133550
|
return 1 /* Success */;
|
|
@@ -133351,29 +133599,6 @@ var ts;
|
|
|
133351
133599
|
}
|
|
133352
133600
|
return 1 /* Success */;
|
|
133353
133601
|
}
|
|
133354
|
-
/**
|
|
133355
|
-
* Returns the immediate owning object literal or binding pattern of a context token,
|
|
133356
|
-
* on the condition that one exists and that the context implies completion should be given.
|
|
133357
|
-
*/
|
|
133358
|
-
function tryGetObjectLikeCompletionContainer(contextToken) {
|
|
133359
|
-
if (contextToken) {
|
|
133360
|
-
var parent = contextToken.parent;
|
|
133361
|
-
switch (contextToken.kind) {
|
|
133362
|
-
case 18 /* OpenBraceToken */: // const x = { |
|
|
133363
|
-
case 27 /* CommaToken */: // const x = { a: 0, |
|
|
133364
|
-
if (ts.isObjectLiteralExpression(parent) || ts.isObjectBindingPattern(parent)) {
|
|
133365
|
-
return parent;
|
|
133366
|
-
}
|
|
133367
|
-
break;
|
|
133368
|
-
case 41 /* AsteriskToken */:
|
|
133369
|
-
return ts.isMethodDeclaration(parent) ? ts.tryCast(parent.parent, ts.isObjectLiteralExpression) : undefined;
|
|
133370
|
-
case 79 /* Identifier */:
|
|
133371
|
-
return contextToken.text === "async" && ts.isShorthandPropertyAssignment(contextToken.parent)
|
|
133372
|
-
? contextToken.parent.parent : undefined;
|
|
133373
|
-
}
|
|
133374
|
-
}
|
|
133375
|
-
return undefined;
|
|
133376
|
-
}
|
|
133377
133602
|
function isConstructorParameterCompletion(node) {
|
|
133378
133603
|
return !!node.parent && ts.isParameter(node.parent) && ts.isConstructorDeclaration(node.parent.parent)
|
|
133379
133604
|
&& (ts.isParameterPropertyModifier(node.kind) || ts.isDeclarationName(node));
|
|
@@ -133710,7 +133935,7 @@ var ts;
|
|
|
133710
133935
|
var _a;
|
|
133711
133936
|
if (m.flags & 16777216 /* Optional */) {
|
|
133712
133937
|
var symbolId = ts.getSymbolId(m);
|
|
133713
|
-
|
|
133938
|
+
symbolToSortTextMap[symbolId] = (_a = symbolToSortTextMap[symbolId]) !== null && _a !== void 0 ? _a : Completions.SortText.OptionalMember;
|
|
133714
133939
|
}
|
|
133715
133940
|
});
|
|
133716
133941
|
}
|
|
@@ -133722,7 +133947,23 @@ var ts;
|
|
|
133722
133947
|
for (var _i = 0, contextualMemberSymbols_1 = contextualMemberSymbols; _i < contextualMemberSymbols_1.length; _i++) {
|
|
133723
133948
|
var contextualMemberSymbol = contextualMemberSymbols_1[_i];
|
|
133724
133949
|
if (membersDeclaredBySpreadAssignment.has(contextualMemberSymbol.name)) {
|
|
133725
|
-
|
|
133950
|
+
symbolToSortTextMap[ts.getSymbolId(contextualMemberSymbol)] = Completions.SortText.MemberDeclaredBySpreadAssignment;
|
|
133951
|
+
}
|
|
133952
|
+
}
|
|
133953
|
+
}
|
|
133954
|
+
function transformObjectLiteralMembersSortText(start) {
|
|
133955
|
+
var _a;
|
|
133956
|
+
for (var i = start; i < symbols.length; i++) {
|
|
133957
|
+
var symbol = symbols[i];
|
|
133958
|
+
var symbolId = ts.getSymbolId(symbol);
|
|
133959
|
+
var origin = symbolToOriginInfoMap === null || symbolToOriginInfoMap === void 0 ? void 0 : symbolToOriginInfoMap[i];
|
|
133960
|
+
var target = ts.getEmitScriptTarget(compilerOptions);
|
|
133961
|
+
var displayName = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, 0 /* ObjectPropertyDeclaration */,
|
|
133962
|
+
/*jsxIdentifierExpected*/ false);
|
|
133963
|
+
if (displayName) {
|
|
133964
|
+
var originalSortText = (_a = symbolToSortTextMap[symbolId]) !== null && _a !== void 0 ? _a : Completions.SortText.LocationPriority;
|
|
133965
|
+
var name = displayName.name;
|
|
133966
|
+
symbolToSortTextMap[symbolId] = Completions.SortText.ObjectLiteralProperty(originalSortText, name);
|
|
133726
133967
|
}
|
|
133727
133968
|
}
|
|
133728
133969
|
}
|
|
@@ -133796,6 +134037,29 @@ var ts;
|
|
|
133796
134037
|
return node.getStart(sourceFile) <= position && position <= node.getEnd();
|
|
133797
134038
|
}
|
|
133798
134039
|
}
|
|
134040
|
+
/**
|
|
134041
|
+
* Returns the immediate owning object literal or binding pattern of a context token,
|
|
134042
|
+
* on the condition that one exists and that the context implies completion should be given.
|
|
134043
|
+
*/
|
|
134044
|
+
function tryGetObjectLikeCompletionContainer(contextToken) {
|
|
134045
|
+
if (contextToken) {
|
|
134046
|
+
var parent = contextToken.parent;
|
|
134047
|
+
switch (contextToken.kind) {
|
|
134048
|
+
case 18 /* OpenBraceToken */: // const x = { |
|
|
134049
|
+
case 27 /* CommaToken */: // const x = { a: 0, |
|
|
134050
|
+
if (ts.isObjectLiteralExpression(parent) || ts.isObjectBindingPattern(parent)) {
|
|
134051
|
+
return parent;
|
|
134052
|
+
}
|
|
134053
|
+
break;
|
|
134054
|
+
case 41 /* AsteriskToken */:
|
|
134055
|
+
return ts.isMethodDeclaration(parent) ? ts.tryCast(parent.parent, ts.isObjectLiteralExpression) : undefined;
|
|
134056
|
+
case 79 /* Identifier */:
|
|
134057
|
+
return contextToken.text === "async" && ts.isShorthandPropertyAssignment(contextToken.parent)
|
|
134058
|
+
? contextToken.parent.parent : undefined;
|
|
134059
|
+
}
|
|
134060
|
+
}
|
|
134061
|
+
return undefined;
|
|
134062
|
+
}
|
|
133799
134063
|
function getRelevantTokens(position, sourceFile) {
|
|
133800
134064
|
var previousToken = ts.findPrecedingToken(position, sourceFile);
|
|
133801
134065
|
if (previousToken && position <= previousToken.end && (ts.isMemberName(previousToken) || ts.isKeyword(previousToken.kind))) {
|
|
@@ -133861,7 +134125,7 @@ var ts;
|
|
|
133861
134125
|
name: ts.tokenToString(i),
|
|
133862
134126
|
kind: "keyword" /* keyword */,
|
|
133863
134127
|
kindModifiers: "" /* none */,
|
|
133864
|
-
sortText: SortText.GlobalsOrKeywords
|
|
134128
|
+
sortText: Completions.SortText.GlobalsOrKeywords
|
|
133865
134129
|
});
|
|
133866
134130
|
}
|
|
133867
134131
|
return res;
|
|
@@ -133989,7 +134253,7 @@ var ts;
|
|
|
133989
134253
|
name: ts.tokenToString(129 /* AssertKeyword */),
|
|
133990
134254
|
kind: "keyword" /* keyword */,
|
|
133991
134255
|
kindModifiers: "" /* none */,
|
|
133992
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
134256
|
+
sortText: Completions.SortText.GlobalsOrKeywords,
|
|
133993
134257
|
});
|
|
133994
134258
|
}
|
|
133995
134259
|
}
|
|
@@ -135803,9 +136067,10 @@ var ts;
|
|
|
135803
136067
|
})(FindReferencesUse = FindAllReferences.FindReferencesUse || (FindAllReferences.FindReferencesUse = {}));
|
|
135804
136068
|
function findReferencedSymbols(program, cancellationToken, sourceFiles, sourceFile, position) {
|
|
135805
136069
|
var node = ts.getTouchingPropertyName(sourceFile, position);
|
|
135806
|
-
var
|
|
136070
|
+
var options = { use: 1 /* References */ };
|
|
136071
|
+
var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
|
|
135807
136072
|
var checker = program.getTypeChecker();
|
|
135808
|
-
var symbol = checker.getSymbolAtLocation(node);
|
|
136073
|
+
var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
|
|
135809
136074
|
return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
|
|
135810
136075
|
var definition = _a.definition, references = _a.references;
|
|
135811
136076
|
// Only include referenced symbols that have a valid definition.
|
|
@@ -136150,12 +136415,7 @@ var ts;
|
|
|
136150
136415
|
var _a, _b;
|
|
136151
136416
|
if (options === void 0) { options = {}; }
|
|
136152
136417
|
if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
|
|
136153
|
-
|
|
136154
|
-
node = ts.getAdjustedReferenceLocation(node);
|
|
136155
|
-
}
|
|
136156
|
-
else if (options.use === 2 /* Rename */) {
|
|
136157
|
-
node = ts.getAdjustedRenameLocation(node);
|
|
136158
|
-
}
|
|
136418
|
+
node = getAdjustedNode(node, options);
|
|
136159
136419
|
if (ts.isSourceFile(node)) {
|
|
136160
136420
|
var resolvedRef = ts.GoToDefinition.getReferenceAtPosition(node, position, program);
|
|
136161
136421
|
if (!(resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file)) {
|
|
@@ -136216,6 +136476,16 @@ var ts;
|
|
|
136216
136476
|
return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
|
|
136217
136477
|
}
|
|
136218
136478
|
Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
|
|
136479
|
+
function getAdjustedNode(node, options) {
|
|
136480
|
+
if (options.use === 1 /* References */) {
|
|
136481
|
+
node = ts.getAdjustedReferenceLocation(node);
|
|
136482
|
+
}
|
|
136483
|
+
else if (options.use === 2 /* Rename */) {
|
|
136484
|
+
node = ts.getAdjustedRenameLocation(node);
|
|
136485
|
+
}
|
|
136486
|
+
return node;
|
|
136487
|
+
}
|
|
136488
|
+
Core.getAdjustedNode = getAdjustedNode;
|
|
136219
136489
|
function getReferencesForFileName(fileName, program, sourceFiles, sourceFilesSet) {
|
|
136220
136490
|
var _a, _b;
|
|
136221
136491
|
if (sourceFilesSet === void 0) { sourceFilesSet = new ts.Set(sourceFiles.map(function (f) { return f.fileName; })); }
|
|
@@ -139182,7 +139452,8 @@ var ts;
|
|
|
139182
139452
|
return undefined;
|
|
139183
139453
|
}
|
|
139184
139454
|
var commentOwner = commentOwnerInfo.commentOwner, parameters = commentOwnerInfo.parameters, hasReturn = commentOwnerInfo.hasReturn;
|
|
139185
|
-
|
|
139455
|
+
var commentOwnerJSDoc = ts.hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? ts.lastOrUndefined(commentOwner.jsDoc) : undefined;
|
|
139456
|
+
if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
|
|
139186
139457
|
return undefined;
|
|
139187
139458
|
}
|
|
139188
139459
|
var indentationStr = getIndentationStringAtPosition(sourceFile, position);
|
|
@@ -147876,25 +148147,25 @@ var ts;
|
|
|
147876
148147
|
suffix: this.newLineCharacter
|
|
147877
148148
|
});
|
|
147878
148149
|
};
|
|
147879
|
-
ChangeTracker.prototype.
|
|
147880
|
-
this.insertNodeAtStartWorker(sourceFile,
|
|
148150
|
+
ChangeTracker.prototype.insertMemberAtStart = function (sourceFile, node, newElement) {
|
|
148151
|
+
this.insertNodeAtStartWorker(sourceFile, node, newElement);
|
|
147881
148152
|
};
|
|
147882
148153
|
ChangeTracker.prototype.insertNodeAtObjectStart = function (sourceFile, obj, newElement) {
|
|
147883
148154
|
this.insertNodeAtStartWorker(sourceFile, obj, newElement);
|
|
147884
148155
|
};
|
|
147885
|
-
ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile,
|
|
148156
|
+
ChangeTracker.prototype.insertNodeAtStartWorker = function (sourceFile, node, newElement) {
|
|
147886
148157
|
var _a;
|
|
147887
|
-
var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile,
|
|
147888
|
-
this.insertNodeAt(sourceFile, getMembersOrProperties(
|
|
148158
|
+
var indentation = (_a = this.guessIndentationFromExistingMembers(sourceFile, node)) !== null && _a !== void 0 ? _a : this.computeIndentationForNewMember(sourceFile, node);
|
|
148159
|
+
this.insertNodeAt(sourceFile, getMembersOrProperties(node).pos, newElement, this.getInsertNodeAtStartInsertOptions(sourceFile, node, indentation));
|
|
147889
148160
|
};
|
|
147890
148161
|
/**
|
|
147891
148162
|
* Tries to guess the indentation from the existing members of a class/interface/object. All members must be on
|
|
147892
148163
|
* new lines and must share the same indentation.
|
|
147893
148164
|
*/
|
|
147894
|
-
ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile,
|
|
148165
|
+
ChangeTracker.prototype.guessIndentationFromExistingMembers = function (sourceFile, node) {
|
|
147895
148166
|
var indentation;
|
|
147896
|
-
var lastRange =
|
|
147897
|
-
for (var _i = 0, _a = getMembersOrProperties(
|
|
148167
|
+
var lastRange = node;
|
|
148168
|
+
for (var _i = 0, _a = getMembersOrProperties(node); _i < _a.length; _i++) {
|
|
147898
148169
|
var member = _a[_i];
|
|
147899
148170
|
if (ts.rangeStartPositionsAreOnSameLine(lastRange, member, sourceFile)) {
|
|
147900
148171
|
// each indented member must be on a new line
|
|
@@ -147913,13 +148184,13 @@ var ts;
|
|
|
147913
148184
|
}
|
|
147914
148185
|
return indentation;
|
|
147915
148186
|
};
|
|
147916
|
-
ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile,
|
|
148187
|
+
ChangeTracker.prototype.computeIndentationForNewMember = function (sourceFile, node) {
|
|
147917
148188
|
var _a;
|
|
147918
|
-
var
|
|
147919
|
-
return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(
|
|
148189
|
+
var nodeStart = node.getStart(sourceFile);
|
|
148190
|
+
return ts.formatting.SmartIndenter.findFirstNonWhitespaceColumn(ts.getLineStartPositionForPosition(nodeStart, sourceFile), nodeStart, sourceFile, this.formatContext.options)
|
|
147920
148191
|
+ ((_a = this.formatContext.options.indentSize) !== null && _a !== void 0 ? _a : 4);
|
|
147921
148192
|
};
|
|
147922
|
-
ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile,
|
|
148193
|
+
ChangeTracker.prototype.getInsertNodeAtStartInsertOptions = function (sourceFile, node, indentation) {
|
|
147923
148194
|
// Rules:
|
|
147924
148195
|
// - Always insert leading newline.
|
|
147925
148196
|
// - For object literals:
|
|
@@ -147929,11 +148200,11 @@ var ts;
|
|
|
147929
148200
|
// and the node is empty (because we didn't add a trailing comma per the previous rule).
|
|
147930
148201
|
// - Only insert a trailing newline if body is single-line and there are no other insertions for the node.
|
|
147931
148202
|
// NOTE: This is handled in `finishClassesWithNodesInsertedAtStart`.
|
|
147932
|
-
var members = getMembersOrProperties(
|
|
148203
|
+
var members = getMembersOrProperties(node);
|
|
147933
148204
|
var isEmpty = members.length === 0;
|
|
147934
|
-
var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(
|
|
147935
|
-
var insertTrailingComma = ts.isObjectLiteralExpression(
|
|
147936
|
-
var insertLeadingComma = ts.isObjectLiteralExpression(
|
|
148205
|
+
var isFirstInsertion = ts.addToSeen(this.classesWithNodesInsertedAtStart, ts.getNodeId(node), { node: node, sourceFile: sourceFile });
|
|
148206
|
+
var insertTrailingComma = ts.isObjectLiteralExpression(node) && (!ts.isJsonSourceFile(sourceFile) || !isEmpty);
|
|
148207
|
+
var insertLeadingComma = ts.isObjectLiteralExpression(node) && ts.isJsonSourceFile(sourceFile) && isEmpty && !isFirstInsertion;
|
|
147937
148208
|
return {
|
|
147938
148209
|
indentation: indentation,
|
|
147939
148210
|
prefix: (insertLeadingComma ? "," : "") + this.newLineCharacter,
|
|
@@ -148227,8 +148498,8 @@ var ts;
|
|
|
148227
148498
|
var close = ts.findChildOfKind(cls, 19 /* CloseBraceToken */, sourceFile);
|
|
148228
148499
|
return [open === null || open === void 0 ? void 0 : open.end, close === null || close === void 0 ? void 0 : close.end];
|
|
148229
148500
|
}
|
|
148230
|
-
function getMembersOrProperties(
|
|
148231
|
-
return ts.isObjectLiteralExpression(
|
|
148501
|
+
function getMembersOrProperties(node) {
|
|
148502
|
+
return ts.isObjectLiteralExpression(node) ? node.properties : node.members;
|
|
148232
148503
|
}
|
|
148233
148504
|
function getNewFileText(statements, scriptKind, newLineCharacter, formatContext) {
|
|
148234
148505
|
return changesToText.newFileChangesWorker(/*oldFile*/ undefined, scriptKind, statements, newLineCharacter, formatContext);
|
|
@@ -151511,7 +151782,7 @@ var ts;
|
|
|
151511
151782
|
changeTracker.insertNodeAfter(sourceFile, constructor, newElement);
|
|
151512
151783
|
}
|
|
151513
151784
|
else {
|
|
151514
|
-
changeTracker.
|
|
151785
|
+
changeTracker.insertMemberAtStart(sourceFile, cls, newElement);
|
|
151515
151786
|
}
|
|
151516
151787
|
}
|
|
151517
151788
|
}
|
|
@@ -153295,7 +153566,7 @@ var ts;
|
|
|
153295
153566
|
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addFunctionDeclaration(t, context, info); });
|
|
153296
153567
|
return [codefix.createCodeFixAction(fixMissingFunctionDeclaration, changes, [ts.Diagnostics.Add_missing_function_declaration_0, info.token.text], fixMissingFunctionDeclaration, ts.Diagnostics.Add_all_missing_function_declarations)];
|
|
153297
153568
|
}
|
|
153298
|
-
if (info.kind ===
|
|
153569
|
+
if (info.kind === 1 /* Enum */) {
|
|
153299
153570
|
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addEnumMemberDeclaration(t, context.program.getTypeChecker(), info); });
|
|
153300
153571
|
return [codefix.createCodeFixAction(fixMissingMember, changes, [ts.Diagnostics.Add_missing_enum_member_0, info.token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members)];
|
|
153301
153572
|
}
|
|
@@ -153323,10 +153594,10 @@ var ts;
|
|
|
153323
153594
|
addJsxAttributes(changes, context, info);
|
|
153324
153595
|
}
|
|
153325
153596
|
else {
|
|
153326
|
-
if (info.kind ===
|
|
153597
|
+
if (info.kind === 1 /* Enum */) {
|
|
153327
153598
|
addEnumMemberDeclaration(changes, checker, info);
|
|
153328
153599
|
}
|
|
153329
|
-
if (info.kind ===
|
|
153600
|
+
if (info.kind === 0 /* TypeLikeDeclaration */) {
|
|
153330
153601
|
var parentDeclaration = info.parentDeclaration, token_1 = info.token;
|
|
153331
153602
|
var infos = ts.getOrUpdate(typeDeclToMembers, parentDeclaration, function () { return []; });
|
|
153332
153603
|
if (!infos.some(function (i) { return i.token.text === token_1.text; })) {
|
|
@@ -153335,11 +153606,11 @@ var ts;
|
|
|
153335
153606
|
}
|
|
153336
153607
|
}
|
|
153337
153608
|
});
|
|
153338
|
-
typeDeclToMembers.forEach(function (infos,
|
|
153339
|
-
var supers = codefix.getAllSupers(
|
|
153609
|
+
typeDeclToMembers.forEach(function (infos, declaration) {
|
|
153610
|
+
var supers = ts.isTypeLiteralNode(declaration) ? undefined : codefix.getAllSupers(declaration, checker);
|
|
153340
153611
|
var _loop_15 = function (info) {
|
|
153341
153612
|
// If some superclass added this property, don't add it again.
|
|
153342
|
-
if (supers.some(function (superClassOrInterface) {
|
|
153613
|
+
if (supers === null || supers === void 0 ? void 0 : supers.some(function (superClassOrInterface) {
|
|
153343
153614
|
var superInfos = typeDeclToMembers.get(superClassOrInterface);
|
|
153344
153615
|
return !!superInfos && superInfos.some(function (_a) {
|
|
153345
153616
|
var token = _a.token;
|
|
@@ -153353,11 +153624,11 @@ var ts;
|
|
|
153353
153624
|
addMethodDeclaration(context, changes, call, token, modifierFlags & 32 /* Static */, parentDeclaration, declSourceFile);
|
|
153354
153625
|
}
|
|
153355
153626
|
else {
|
|
153356
|
-
if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration)) {
|
|
153627
|
+
if (isJSFile && !ts.isInterfaceDeclaration(parentDeclaration) && !ts.isTypeLiteralNode(parentDeclaration)) {
|
|
153357
153628
|
addMissingMemberInJs(changes, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */));
|
|
153358
153629
|
}
|
|
153359
153630
|
else {
|
|
153360
|
-
var typeNode = getTypeNode(
|
|
153631
|
+
var typeNode = getTypeNode(checker, parentDeclaration, token);
|
|
153361
153632
|
addPropertyDeclaration(changes, declSourceFile, parentDeclaration, token.text, typeNode, modifierFlags & 32 /* Static */);
|
|
153362
153633
|
}
|
|
153363
153634
|
}
|
|
@@ -153372,8 +153643,8 @@ var ts;
|
|
|
153372
153643
|
});
|
|
153373
153644
|
var InfoKind;
|
|
153374
153645
|
(function (InfoKind) {
|
|
153375
|
-
InfoKind[InfoKind["
|
|
153376
|
-
InfoKind[InfoKind["
|
|
153646
|
+
InfoKind[InfoKind["TypeLikeDeclaration"] = 0] = "TypeLikeDeclaration";
|
|
153647
|
+
InfoKind[InfoKind["Enum"] = 1] = "Enum";
|
|
153377
153648
|
InfoKind[InfoKind["Function"] = 2] = "Function";
|
|
153378
153649
|
InfoKind[InfoKind["ObjectLiteral"] = 3] = "ObjectLiteral";
|
|
153379
153650
|
InfoKind[InfoKind["JsxAttributes"] = 4] = "JsxAttributes";
|
|
@@ -153443,20 +153714,21 @@ var ts;
|
|
|
153443
153714
|
if (!classDeclaration && ts.isPrivateIdentifier(token))
|
|
153444
153715
|
return undefined;
|
|
153445
153716
|
// Prefer to change the class instead of the interface if they are merged
|
|
153446
|
-
var
|
|
153447
|
-
if (
|
|
153448
|
-
var makeStatic = (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
|
|
153449
|
-
if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(
|
|
153717
|
+
var declaration = classDeclaration || ts.find(symbol.declarations, function (d) { return ts.isInterfaceDeclaration(d) || ts.isTypeLiteralNode(d); });
|
|
153718
|
+
if (declaration && !isSourceFileFromLibrary(program, declaration.getSourceFile())) {
|
|
153719
|
+
var makeStatic = !ts.isTypeLiteralNode(declaration) && (leftExpressionType.target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
|
|
153720
|
+
if (makeStatic && (ts.isPrivateIdentifier(token) || ts.isInterfaceDeclaration(declaration)))
|
|
153450
153721
|
return undefined;
|
|
153451
|
-
var declSourceFile =
|
|
153452
|
-
var modifierFlags =
|
|
153722
|
+
var declSourceFile = declaration.getSourceFile();
|
|
153723
|
+
var modifierFlags = ts.isTypeLiteralNode(declaration) ? 0 /* None */ :
|
|
153724
|
+
(makeStatic ? 32 /* Static */ : 0 /* None */) | (ts.startsWithUnderscore(token.text) ? 8 /* Private */ : 0 /* None */);
|
|
153453
153725
|
var isJSFile = ts.isSourceFileJS(declSourceFile);
|
|
153454
153726
|
var call = ts.tryCast(parent.parent, ts.isCallExpression);
|
|
153455
|
-
return { kind:
|
|
153727
|
+
return { kind: 0 /* TypeLikeDeclaration */, token: token, call: call, modifierFlags: modifierFlags, parentDeclaration: declaration, declSourceFile: declSourceFile, isJSFile: isJSFile };
|
|
153456
153728
|
}
|
|
153457
153729
|
var enumDeclaration = ts.find(symbol.declarations, ts.isEnumDeclaration);
|
|
153458
153730
|
if (enumDeclaration && !ts.isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
|
|
153459
|
-
return { kind:
|
|
153731
|
+
return { kind: 1 /* Enum */, token: token, parentDeclaration: enumDeclaration };
|
|
153460
153732
|
}
|
|
153461
153733
|
return undefined;
|
|
153462
153734
|
}
|
|
@@ -153469,7 +153741,7 @@ var ts;
|
|
|
153469
153741
|
}
|
|
153470
153742
|
function createActionForAddMissingMemberInJavascriptFile(context, _a) {
|
|
153471
153743
|
var parentDeclaration = _a.parentDeclaration, declSourceFile = _a.declSourceFile, modifierFlags = _a.modifierFlags, token = _a.token;
|
|
153472
|
-
if (ts.isInterfaceDeclaration(parentDeclaration)) {
|
|
153744
|
+
if (ts.isInterfaceDeclaration(parentDeclaration) || ts.isTypeLiteralNode(parentDeclaration)) {
|
|
153473
153745
|
return undefined;
|
|
153474
153746
|
}
|
|
153475
153747
|
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingMemberInJs(t, declSourceFile, parentDeclaration, token, !!(modifierFlags & 32 /* Static */)); });
|
|
@@ -153480,7 +153752,7 @@ var ts;
|
|
|
153480
153752
|
ts.isPrivateIdentifier(token) ? ts.Diagnostics.Declare_a_private_field_named_0 : ts.Diagnostics.Initialize_property_0_in_the_constructor;
|
|
153481
153753
|
return codefix.createCodeFixAction(fixMissingMember, changes, [diagnostic, token.text], fixMissingMember, ts.Diagnostics.Add_all_missing_members);
|
|
153482
153754
|
}
|
|
153483
|
-
function addMissingMemberInJs(changeTracker,
|
|
153755
|
+
function addMissingMemberInJs(changeTracker, sourceFile, classDeclaration, token, makeStatic) {
|
|
153484
153756
|
var tokenName = token.text;
|
|
153485
153757
|
if (makeStatic) {
|
|
153486
153758
|
if (classDeclaration.kind === 226 /* ClassExpression */) {
|
|
@@ -153488,7 +153760,7 @@ var ts;
|
|
|
153488
153760
|
}
|
|
153489
153761
|
var className = classDeclaration.name.getText();
|
|
153490
153762
|
var staticInitialization = initializePropertyToUndefined(ts.factory.createIdentifier(className), tokenName);
|
|
153491
|
-
changeTracker.insertNodeAfter(
|
|
153763
|
+
changeTracker.insertNodeAfter(sourceFile, classDeclaration, staticInitialization);
|
|
153492
153764
|
}
|
|
153493
153765
|
else if (ts.isPrivateIdentifier(token)) {
|
|
153494
153766
|
var property = ts.factory.createPropertyDeclaration(
|
|
@@ -153499,10 +153771,10 @@ var ts;
|
|
|
153499
153771
|
/*initializer*/ undefined);
|
|
153500
153772
|
var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
|
|
153501
153773
|
if (lastProp) {
|
|
153502
|
-
changeTracker.insertNodeAfter(
|
|
153774
|
+
changeTracker.insertNodeAfter(sourceFile, lastProp, property);
|
|
153503
153775
|
}
|
|
153504
153776
|
else {
|
|
153505
|
-
changeTracker.
|
|
153777
|
+
changeTracker.insertMemberAtStart(sourceFile, classDeclaration, property);
|
|
153506
153778
|
}
|
|
153507
153779
|
}
|
|
153508
153780
|
else {
|
|
@@ -153511,7 +153783,7 @@ var ts;
|
|
|
153511
153783
|
return;
|
|
153512
153784
|
}
|
|
153513
153785
|
var propertyInitialization = initializePropertyToUndefined(ts.factory.createThis(), tokenName);
|
|
153514
|
-
changeTracker.insertNodeAtConstructorEnd(
|
|
153786
|
+
changeTracker.insertNodeAtConstructorEnd(sourceFile, classConstructor, propertyInitialization);
|
|
153515
153787
|
}
|
|
153516
153788
|
}
|
|
153517
153789
|
function initializePropertyToUndefined(obj, propertyName) {
|
|
@@ -153533,13 +153805,13 @@ var ts;
|
|
|
153533
153805
|
actions.push(createAddIndexSignatureAction(context, declSourceFile, parentDeclaration, token.text, typeNode));
|
|
153534
153806
|
return actions;
|
|
153535
153807
|
}
|
|
153536
|
-
function getTypeNode(checker,
|
|
153808
|
+
function getTypeNode(checker, node, token) {
|
|
153537
153809
|
var typeNode;
|
|
153538
153810
|
if (token.parent.parent.kind === 221 /* BinaryExpression */) {
|
|
153539
153811
|
var binaryExpression = token.parent.parent;
|
|
153540
153812
|
var otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
|
|
153541
153813
|
var widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
|
|
153542
|
-
typeNode = checker.typeToTypeNode(widenedType,
|
|
153814
|
+
typeNode = checker.typeToTypeNode(widenedType, node, 1 /* NoTruncation */);
|
|
153543
153815
|
}
|
|
153544
153816
|
else {
|
|
153545
153817
|
var contextualType = checker.getContextualType(token.parent);
|
|
@@ -153547,24 +153819,23 @@ var ts;
|
|
|
153547
153819
|
}
|
|
153548
153820
|
return typeNode || ts.factory.createKeywordTypeNode(130 /* AnyKeyword */);
|
|
153549
153821
|
}
|
|
153550
|
-
function addPropertyDeclaration(changeTracker,
|
|
153551
|
-
var
|
|
153552
|
-
|
|
153553
|
-
|
|
153554
|
-
|
|
153555
|
-
|
|
153556
|
-
var lastProp = getNodeToInsertPropertyAfter(classDeclaration);
|
|
153822
|
+
function addPropertyDeclaration(changeTracker, sourceFile, node, tokenName, typeNode, modifierFlags) {
|
|
153823
|
+
var modifiers = modifierFlags ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags)) : undefined;
|
|
153824
|
+
var property = ts.isClassLike(node)
|
|
153825
|
+
? ts.factory.createPropertyDeclaration(/*decorators*/ undefined, modifiers, tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined)
|
|
153826
|
+
: ts.factory.createPropertySignature(/*modifiers*/ undefined, tokenName, /*questionToken*/ undefined, typeNode);
|
|
153827
|
+
var lastProp = getNodeToInsertPropertyAfter(node);
|
|
153557
153828
|
if (lastProp) {
|
|
153558
|
-
changeTracker.insertNodeAfter(
|
|
153829
|
+
changeTracker.insertNodeAfter(sourceFile, lastProp, property);
|
|
153559
153830
|
}
|
|
153560
153831
|
else {
|
|
153561
|
-
changeTracker.
|
|
153832
|
+
changeTracker.insertMemberAtStart(sourceFile, node, property);
|
|
153562
153833
|
}
|
|
153563
153834
|
}
|
|
153564
153835
|
// Gets the last of the first run of PropertyDeclarations, or undefined if the class does not start with a PropertyDeclaration.
|
|
153565
|
-
function getNodeToInsertPropertyAfter(
|
|
153836
|
+
function getNodeToInsertPropertyAfter(node) {
|
|
153566
153837
|
var res;
|
|
153567
|
-
for (var _i = 0, _a =
|
|
153838
|
+
for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
|
|
153568
153839
|
var member = _a[_i];
|
|
153569
153840
|
if (!ts.isPropertyDeclaration(member))
|
|
153570
153841
|
break;
|
|
@@ -153572,7 +153843,7 @@ var ts;
|
|
|
153572
153843
|
}
|
|
153573
153844
|
return res;
|
|
153574
153845
|
}
|
|
153575
|
-
function createAddIndexSignatureAction(context,
|
|
153846
|
+
function createAddIndexSignatureAction(context, sourceFile, node, tokenName, typeNode) {
|
|
153576
153847
|
// Index signatures cannot have the static modifier.
|
|
153577
153848
|
var stringTypeNode = ts.factory.createKeywordTypeNode(150 /* StringKeyword */);
|
|
153578
153849
|
var indexingParameter = ts.factory.createParameterDeclaration(
|
|
@@ -153584,7 +153855,7 @@ var ts;
|
|
|
153584
153855
|
var indexSignature = ts.factory.createIndexSignature(
|
|
153585
153856
|
/*decorators*/ undefined,
|
|
153586
153857
|
/*modifiers*/ undefined, [indexingParameter], typeNode);
|
|
153587
|
-
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.
|
|
153858
|
+
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return t.insertMemberAtStart(sourceFile, node, indexSignature); });
|
|
153588
153859
|
// No fixId here because code-fix-all currently only works on adding individual named properties.
|
|
153589
153860
|
return codefix.createCodeFixActionWithoutFixAll(fixMissingMember, changes, [ts.Diagnostics.Add_index_signature_for_property_0, tokenName]);
|
|
153590
153861
|
}
|
|
@@ -153607,13 +153878,14 @@ var ts;
|
|
|
153607
153878
|
}
|
|
153608
153879
|
function addMethodDeclaration(context, changes, callExpression, name, modifierFlags, parentDeclaration, sourceFile) {
|
|
153609
153880
|
var importAdder = codefix.createImportAdder(sourceFile, context.program, context.preferences, context.host);
|
|
153610
|
-
var
|
|
153611
|
-
var
|
|
153612
|
-
|
|
153613
|
-
|
|
153881
|
+
var kind = ts.isClassLike(parentDeclaration) ? 169 /* MethodDeclaration */ : 168 /* MethodSignature */;
|
|
153882
|
+
var signatureDeclaration = codefix.createSignatureDeclarationFromCallExpression(kind, context, importAdder, callExpression, name, modifierFlags, parentDeclaration);
|
|
153883
|
+
var containingMethodDeclaration = tryGetContainingMethodDeclaration(parentDeclaration, callExpression);
|
|
153884
|
+
if (containingMethodDeclaration) {
|
|
153885
|
+
changes.insertNodeAfter(sourceFile, containingMethodDeclaration, signatureDeclaration);
|
|
153614
153886
|
}
|
|
153615
153887
|
else {
|
|
153616
|
-
changes.
|
|
153888
|
+
changes.insertMemberAtStart(sourceFile, parentDeclaration, signatureDeclaration);
|
|
153617
153889
|
}
|
|
153618
153890
|
importAdder.writeFixes(changes);
|
|
153619
153891
|
}
|
|
@@ -153776,6 +154048,13 @@ var ts;
|
|
|
153776
154048
|
return ts.isIdentifierText(targetProp.name, target, 1 /* JSX */) && !((targetProp.flags & 16777216 /* Optional */ || ts.getCheckFlags(targetProp) & 48 /* Partial */) || seenNames.has(targetProp.escapedName));
|
|
153777
154049
|
});
|
|
153778
154050
|
}
|
|
154051
|
+
function tryGetContainingMethodDeclaration(node, callExpression) {
|
|
154052
|
+
if (ts.isTypeLiteralNode(node)) {
|
|
154053
|
+
return undefined;
|
|
154054
|
+
}
|
|
154055
|
+
var declaration = ts.findAncestor(callExpression, function (n) { return ts.isMethodDeclaration(n) || ts.isConstructorDeclaration(n); });
|
|
154056
|
+
return declaration && declaration.parent === node ? declaration : undefined;
|
|
154057
|
+
}
|
|
153779
154058
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
153780
154059
|
})(ts || (ts = {}));
|
|
153781
154060
|
/* @internal */
|
|
@@ -153919,7 +154198,7 @@ var ts;
|
|
|
153919
154198
|
// so duplicates cannot occur.
|
|
153920
154199
|
var abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);
|
|
153921
154200
|
var importAdder = codefix.createImportAdder(sourceFile, context.program, preferences, context.host);
|
|
153922
|
-
codefix.createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, function (member) { return changeTracker.
|
|
154201
|
+
codefix.createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, function (member) { return changeTracker.insertMemberAtStart(sourceFile, classDeclaration, member); });
|
|
153923
154202
|
importAdder.writeFixes(changeTracker);
|
|
153924
154203
|
}
|
|
153925
154204
|
function symbolPointsToNonPrivateAndAbstractMember(symbol) {
|
|
@@ -156492,13 +156771,20 @@ var ts;
|
|
|
156492
156771
|
var type = isJs || contextualType === undefined
|
|
156493
156772
|
? undefined
|
|
156494
156773
|
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
|
|
156495
|
-
|
|
156496
|
-
|
|
156497
|
-
|
|
156498
|
-
|
|
156774
|
+
switch (kind) {
|
|
156775
|
+
case 169 /* MethodDeclaration */:
|
|
156776
|
+
return ts.factory.createMethodDeclaration(
|
|
156777
|
+
/*decorators*/ undefined, modifiers, asteriskToken, name,
|
|
156778
|
+
/*questionToken*/ undefined, typeParameters, parameters, type, createStubbedMethodBody(quotePreference));
|
|
156779
|
+
case 168 /* MethodSignature */:
|
|
156780
|
+
return ts.factory.createMethodSignature(modifiers, name,
|
|
156781
|
+
/*questionToken*/ undefined, typeParameters, parameters, type);
|
|
156782
|
+
case 256 /* FunctionDeclaration */:
|
|
156783
|
+
return ts.factory.createFunctionDeclaration(
|
|
156784
|
+
/*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
|
|
156785
|
+
default:
|
|
156786
|
+
ts.Debug.fail("Unexpected kind");
|
|
156499
156787
|
}
|
|
156500
|
-
return ts.factory.createFunctionDeclaration(
|
|
156501
|
-
/*decorators*/ undefined, modifiers, asteriskToken, name, typeParameters, parameters, type, createStubbedBody(ts.Diagnostics.Function_not_implemented.message, quotePreference));
|
|
156502
156788
|
}
|
|
156503
156789
|
codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
|
|
156504
156790
|
function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
|
|
@@ -156824,7 +157110,7 @@ var ts;
|
|
|
156824
157110
|
}
|
|
156825
157111
|
}
|
|
156826
157112
|
function insertAccessor(changeTracker, file, accessor, declaration, container) {
|
|
156827
|
-
ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.
|
|
157113
|
+
ts.isParameterPropertyDeclaration(declaration, declaration.parent) ? changeTracker.insertMemberAtStart(file, container, accessor) :
|
|
156828
157114
|
ts.isPropertyAssignment(declaration) ? changeTracker.insertNodeAfterComma(file, declaration, accessor) :
|
|
156829
157115
|
changeTracker.insertNodeAfter(file, declaration, accessor);
|
|
156830
157116
|
}
|
|
@@ -175017,10 +175303,26 @@ var ts;
|
|
|
175017
175303
|
var prefix = args.prefix || "";
|
|
175018
175304
|
var entries = ts.mapDefined(completions.entries, function (entry) {
|
|
175019
175305
|
if (completions.isMemberCompletion || ts.startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
|
|
175020
|
-
var name = entry.name, kind_1 = entry.kind, kindModifiers = entry.kindModifiers, sortText = entry.sortText, insertText = entry.insertText, replacementSpan = entry.replacementSpan, hasAction = entry.hasAction, source = entry.source, sourceDisplay = entry.sourceDisplay, isSnippet = entry.isSnippet, isRecommended = entry.isRecommended, isPackageJsonImport = entry.isPackageJsonImport, isImportStatementCompletion = entry.isImportStatementCompletion, data = entry.data;
|
|
175306
|
+
var name = entry.name, kind_1 = entry.kind, kindModifiers = entry.kindModifiers, sortText = entry.sortText, insertText = entry.insertText, replacementSpan = entry.replacementSpan, hasAction = entry.hasAction, source = entry.source, sourceDisplay = entry.sourceDisplay, labelDetails = entry.labelDetails, isSnippet = entry.isSnippet, isRecommended = entry.isRecommended, isPackageJsonImport = entry.isPackageJsonImport, isImportStatementCompletion = entry.isImportStatementCompletion, data = entry.data;
|
|
175021
175307
|
var convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
|
|
175022
175308
|
// Use `hasAction || undefined` to avoid serializing `false`.
|
|
175023
|
-
return {
|
|
175309
|
+
return {
|
|
175310
|
+
name: name,
|
|
175311
|
+
kind: kind_1,
|
|
175312
|
+
kindModifiers: kindModifiers,
|
|
175313
|
+
sortText: sortText,
|
|
175314
|
+
insertText: insertText,
|
|
175315
|
+
replacementSpan: convertedSpan,
|
|
175316
|
+
isSnippet: isSnippet,
|
|
175317
|
+
hasAction: hasAction || undefined,
|
|
175318
|
+
source: source,
|
|
175319
|
+
sourceDisplay: sourceDisplay,
|
|
175320
|
+
labelDetails: labelDetails,
|
|
175321
|
+
isRecommended: isRecommended,
|
|
175322
|
+
isPackageJsonImport: isPackageJsonImport,
|
|
175323
|
+
isImportStatementCompletion: isImportStatementCompletion,
|
|
175324
|
+
data: data
|
|
175325
|
+
};
|
|
175024
175326
|
}
|
|
175025
175327
|
});
|
|
175026
175328
|
if (kind === "completions" /* Completions */) {
|