typescript 4.2.0-dev.20210209 → 4.2.3
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/lib.es2020.intl.d.ts +2 -235
- package/lib/protocol.d.ts +63 -0
- package/lib/tsc.js +38 -18
- package/lib/tsserver.js +141 -30
- package/lib/tsserverlibrary.d.ts +62 -0
- package/lib/tsserverlibrary.js +141 -30
- package/lib/typescript.js +109 -30
- package/lib/typescriptServices.js +109 -30
- package/lib/typingsInstaller.js +44 -21
- package/package.json +2 -2
package/lib/tsserverlibrary.js
CHANGED
|
@@ -290,7 +290,7 @@ var ts;
|
|
|
290
290
|
// The following is baselined as a literal template type without intervention
|
|
291
291
|
/** The version of the TypeScript compiler release */
|
|
292
292
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
293
|
-
ts.version =
|
|
293
|
+
ts.version = "4.2.3";
|
|
294
294
|
/* @internal */
|
|
295
295
|
var Comparison;
|
|
296
296
|
(function (Comparison) {
|
|
@@ -47238,13 +47238,17 @@ var ts;
|
|
|
47238
47238
|
return result || ts.emptyArray;
|
|
47239
47239
|
}
|
|
47240
47240
|
function setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo) {
|
|
47241
|
-
|
|
47242
|
-
|
|
47243
|
-
|
|
47244
|
-
|
|
47245
|
-
|
|
47246
|
-
|
|
47247
|
-
|
|
47241
|
+
var resolved = type;
|
|
47242
|
+
resolved.members = members;
|
|
47243
|
+
resolved.properties = ts.emptyArray;
|
|
47244
|
+
resolved.callSignatures = callSignatures;
|
|
47245
|
+
resolved.constructSignatures = constructSignatures;
|
|
47246
|
+
resolved.stringIndexInfo = stringIndexInfo;
|
|
47247
|
+
resolved.numberIndexInfo = numberIndexInfo;
|
|
47248
|
+
// This can loop back to getPropertyOfType() which would crash if `callSignatures` & `constructSignatures` are not initialized.
|
|
47249
|
+
if (members !== emptySymbols)
|
|
47250
|
+
resolved.properties = getNamedMembers(members);
|
|
47251
|
+
return resolved;
|
|
47248
47252
|
}
|
|
47249
47253
|
function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo) {
|
|
47250
47254
|
return setStructuredTypeMembers(createObjectType(16 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
|
|
@@ -55871,7 +55875,7 @@ var ts;
|
|
|
55871
55875
|
}
|
|
55872
55876
|
return true;
|
|
55873
55877
|
}
|
|
55874
|
-
function removeRedundantLiteralTypes(types, includes) {
|
|
55878
|
+
function removeRedundantLiteralTypes(types, includes, reduceVoidUndefined) {
|
|
55875
55879
|
var i = types.length;
|
|
55876
55880
|
while (i > 0) {
|
|
55877
55881
|
i--;
|
|
@@ -55881,7 +55885,7 @@ var ts;
|
|
|
55881
55885
|
flags & 256 /* NumberLiteral */ && includes & 8 /* Number */ ||
|
|
55882
55886
|
flags & 2048 /* BigIntLiteral */ && includes & 64 /* BigInt */ ||
|
|
55883
55887
|
flags & 8192 /* UniqueESSymbol */ && includes & 4096 /* ESSymbol */ ||
|
|
55884
|
-
flags & 32768 /* Undefined */ && includes & 16384 /* Void */ ||
|
|
55888
|
+
reduceVoidUndefined && flags & 32768 /* Undefined */ && includes & 16384 /* Void */ ||
|
|
55885
55889
|
isFreshLiteralType(t) && containsType(types, t.regularType);
|
|
55886
55890
|
if (remove) {
|
|
55887
55891
|
ts.orderedRemoveItemAt(types, i);
|
|
@@ -55913,7 +55917,7 @@ var ts;
|
|
|
55913
55917
|
if (t.flags & 1048576 /* Union */) {
|
|
55914
55918
|
var origin = t.origin;
|
|
55915
55919
|
if (t.aliasSymbol || origin && !(origin.flags & 1048576 /* Union */)) {
|
|
55916
|
-
|
|
55920
|
+
ts.pushIfUnique(namedUnions, t);
|
|
55917
55921
|
}
|
|
55918
55922
|
else if (origin && origin.flags & 1048576 /* Union */) {
|
|
55919
55923
|
addNamedUnions(namedUnions, origin.types);
|
|
@@ -55949,7 +55953,7 @@ var ts;
|
|
|
55949
55953
|
}
|
|
55950
55954
|
if (unionReduction & (1 /* Literal */ | 2 /* Subtype */)) {
|
|
55951
55955
|
if (includes & (2944 /* Literal */ | 8192 /* UniqueESSymbol */) || includes & 16384 /* Void */ && includes & 32768 /* Undefined */) {
|
|
55952
|
-
removeRedundantLiteralTypes(typeSet, includes);
|
|
55956
|
+
removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & 2 /* Subtype */));
|
|
55953
55957
|
}
|
|
55954
55958
|
if (includes & 128 /* StringLiteral */ && includes & 134217728 /* TemplateLiteral */) {
|
|
55955
55959
|
removeStringLiteralsMatchedByTemplateLiterals(typeSet);
|
|
@@ -63970,7 +63974,16 @@ var ts;
|
|
|
63970
63974
|
var type = getTypeOfDottedName(node.expression, diagnostic);
|
|
63971
63975
|
if (type) {
|
|
63972
63976
|
var name = node.name;
|
|
63973
|
-
var prop =
|
|
63977
|
+
var prop = void 0;
|
|
63978
|
+
if (ts.isPrivateIdentifier(name)) {
|
|
63979
|
+
if (!type.symbol) {
|
|
63980
|
+
return undefined;
|
|
63981
|
+
}
|
|
63982
|
+
prop = getPropertyOfType(type, ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText));
|
|
63983
|
+
}
|
|
63984
|
+
else {
|
|
63985
|
+
prop = getPropertyOfType(type, name.escapedText);
|
|
63986
|
+
}
|
|
63974
63987
|
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
|
|
63975
63988
|
}
|
|
63976
63989
|
return undefined;
|
|
@@ -65036,10 +65049,15 @@ var ts;
|
|
|
65036
65049
|
return assignableType;
|
|
65037
65050
|
}
|
|
65038
65051
|
}
|
|
65039
|
-
// If the candidate type is a subtype of the target type, narrow to the candidate type
|
|
65040
|
-
// if the target type is
|
|
65041
|
-
//
|
|
65042
|
-
|
|
65052
|
+
// If the candidate type is a subtype of the target type, narrow to the candidate type.
|
|
65053
|
+
// Otherwise, if the target type is assignable to the candidate type, keep the target type.
|
|
65054
|
+
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
|
|
65055
|
+
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
|
|
65056
|
+
// two types.
|
|
65057
|
+
return isTypeSubtypeOf(candidate, type) ? candidate :
|
|
65058
|
+
isTypeAssignableTo(type, candidate) ? type :
|
|
65059
|
+
isTypeAssignableTo(candidate, type) ? candidate :
|
|
65060
|
+
getIntersectionType([type, candidate]);
|
|
65043
65061
|
}
|
|
65044
65062
|
function narrowTypeByCallExpression(type, callExpression, assumeTrue) {
|
|
65045
65063
|
if (hasMatchingArgument(callExpression, reference)) {
|
|
@@ -75382,7 +75400,9 @@ var ts;
|
|
|
75382
75400
|
: ts.isPropertyAccessExpression(location) ? location.name
|
|
75383
75401
|
: ts.isBinaryExpression(location) && ts.isIdentifier(location.right) ? location.right
|
|
75384
75402
|
: undefined;
|
|
75385
|
-
|
|
75403
|
+
var isPropertyExpressionCast = ts.isPropertyAccessExpression(location)
|
|
75404
|
+
&& ts.isAssertionExpression(ts.skipParentheses(location.expression));
|
|
75405
|
+
if (!testedNode || isPropertyExpressionCast) {
|
|
75386
75406
|
return;
|
|
75387
75407
|
}
|
|
75388
75408
|
var possiblyFalsy = getFalsyFlags(type);
|
|
@@ -77532,6 +77552,7 @@ var ts;
|
|
|
77532
77552
|
return true;
|
|
77533
77553
|
}
|
|
77534
77554
|
function checkAliasSymbol(node) {
|
|
77555
|
+
var _a;
|
|
77535
77556
|
var symbol = getSymbolOfNode(node);
|
|
77536
77557
|
var target = resolveAlias(symbol);
|
|
77537
77558
|
if (target !== unknownSymbol) {
|
|
@@ -77559,7 +77580,7 @@ var ts;
|
|
|
77559
77580
|
&& !(node.flags & 8388608 /* Ambient */)) {
|
|
77560
77581
|
error(node, ts.Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type);
|
|
77561
77582
|
}
|
|
77562
|
-
if (ts.isImportSpecifier(node) &&
|
|
77583
|
+
if (ts.isImportSpecifier(node) && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); }))) {
|
|
77563
77584
|
addDeprecatedSuggestion(node.name, target.declarations, symbol.escapedName);
|
|
77564
77585
|
}
|
|
77565
77586
|
}
|
|
@@ -111664,10 +111685,11 @@ var ts;
|
|
|
111664
111685
|
var redirects = host.redirectTargetsMap.get(importedPath) || ts.emptyArray;
|
|
111665
111686
|
var importedFileNames = __spreadArray(__spreadArray(__spreadArray([], (referenceRedirect ? [referenceRedirect] : ts.emptyArray)), [importedFileName]), redirects);
|
|
111666
111687
|
var targets = importedFileNames.map(function (f) { return ts.getNormalizedAbsolutePath(f, cwd); });
|
|
111688
|
+
var shouldFilterIgnoredPaths = !ts.every(targets, ts.containsIgnoredPath);
|
|
111667
111689
|
if (!preferSymlinks) {
|
|
111668
111690
|
// Symlinks inside ignored paths are already filtered out of the symlink cache,
|
|
111669
111691
|
// so we only need to remove them from the realpath filenames.
|
|
111670
|
-
var result_15 = ts.forEach(targets, function (p) { return !ts.containsIgnoredPath(p) && cb(p, referenceRedirect === p); });
|
|
111692
|
+
var result_15 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
|
|
111671
111693
|
if (result_15)
|
|
111672
111694
|
return result_15;
|
|
111673
111695
|
}
|
|
@@ -111693,13 +111715,14 @@ var ts;
|
|
|
111693
111715
|
var symlinkDirectory = symlinkDirectories_1[_i];
|
|
111694
111716
|
var option = ts.resolvePath(symlinkDirectory, relative);
|
|
111695
111717
|
var result_16 = cb(option, target === referenceRedirect);
|
|
111718
|
+
shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
|
|
111696
111719
|
if (result_16)
|
|
111697
111720
|
return result_16;
|
|
111698
111721
|
}
|
|
111699
111722
|
});
|
|
111700
111723
|
});
|
|
111701
111724
|
return result || (preferSymlinks
|
|
111702
|
-
? ts.forEach(targets, function (p) { return ts.containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect); })
|
|
111725
|
+
? ts.forEach(targets, function (p) { return shouldFilterIgnoredPaths && ts.containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect); })
|
|
111703
111726
|
: undefined);
|
|
111704
111727
|
}
|
|
111705
111728
|
moduleSpecifiers.forEachFileNameOfModule = forEachFileNameOfModule;
|
|
@@ -140149,7 +140172,7 @@ var ts;
|
|
|
140149
140172
|
}
|
|
140150
140173
|
function addFunctionDeclaration(changes, context, info) {
|
|
140151
140174
|
var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
140152
|
-
var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(251 /* FunctionDeclaration */, context, importAdder, info.call, info.token, info.modifierFlags, info.parentDeclaration);
|
|
140175
|
+
var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(251 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration);
|
|
140153
140176
|
changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
|
|
140154
140177
|
}
|
|
140155
140178
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -147530,13 +147553,13 @@ var ts;
|
|
|
147530
147553
|
return { edits: [] }; // TODO: GH#30113
|
|
147531
147554
|
}
|
|
147532
147555
|
function doChange(sourceFile, program, host, changes, functionDeclaration, groupedReferences) {
|
|
147533
|
-
var
|
|
147534
|
-
|
|
147535
|
-
|
|
147536
|
-
|
|
147537
|
-
|
|
147538
|
-
|
|
147539
|
-
|
|
147556
|
+
var signature = groupedReferences.signature;
|
|
147557
|
+
var newFunctionDeclarationParams = ts.map(createNewParameters(functionDeclaration, program, host), function (param) { return ts.getSynthesizedDeepClone(param); });
|
|
147558
|
+
if (signature) {
|
|
147559
|
+
var newSignatureParams = ts.map(createNewParameters(signature, program, host), function (param) { return ts.getSynthesizedDeepClone(param); });
|
|
147560
|
+
replaceParameters(signature, newSignatureParams);
|
|
147561
|
+
}
|
|
147562
|
+
replaceParameters(functionDeclaration, newFunctionDeclarationParams);
|
|
147540
147563
|
var functionCalls = ts.sortAndDeduplicate(groupedReferences.functionCalls, /*comparer*/ function (a, b) { return ts.compareValues(a.pos, b.pos); });
|
|
147541
147564
|
for (var _i = 0, functionCalls_1 = functionCalls; _i < functionCalls_1.length; _i++) {
|
|
147542
147565
|
var call = functionCalls_1[_i];
|
|
@@ -147545,6 +147568,15 @@ var ts;
|
|
|
147545
147568
|
changes.replaceNodeRange(ts.getSourceFileOfNode(call), ts.first(call.arguments), ts.last(call.arguments), newArgument, { leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll, trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Include });
|
|
147546
147569
|
}
|
|
147547
147570
|
}
|
|
147571
|
+
function replaceParameters(declarationOrSignature, parameterDeclarations) {
|
|
147572
|
+
changes.replaceNodeRangeWithNodes(sourceFile, ts.first(declarationOrSignature.parameters), ts.last(declarationOrSignature.parameters), parameterDeclarations, {
|
|
147573
|
+
joiner: ", ",
|
|
147574
|
+
// indentation is set to 0 because otherwise the object parameter will be indented if there is a `this` parameter
|
|
147575
|
+
indentation: 0,
|
|
147576
|
+
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
|
|
147577
|
+
trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Include
|
|
147578
|
+
});
|
|
147579
|
+
}
|
|
147548
147580
|
}
|
|
147549
147581
|
function getGroupedReferences(functionDeclaration, program, cancellationToken) {
|
|
147550
147582
|
var functionNames = getFunctionNames(functionDeclaration);
|
|
@@ -147563,12 +147595,38 @@ var ts;
|
|
|
147563
147595
|
var functionSymbols = ts.map(functionNames, getSymbolTargetAtLocation);
|
|
147564
147596
|
var classSymbols = ts.map(classNames, getSymbolTargetAtLocation);
|
|
147565
147597
|
var isConstructor = ts.isConstructorDeclaration(functionDeclaration);
|
|
147598
|
+
var contextualSymbols = ts.map(functionNames, function (name) { return getSymbolForContextualType(name, checker); });
|
|
147566
147599
|
for (var _i = 0, referenceEntries_1 = referenceEntries; _i < referenceEntries_1.length; _i++) {
|
|
147567
147600
|
var entry = referenceEntries_1[_i];
|
|
147568
|
-
if (entry.kind
|
|
147601
|
+
if (entry.kind === 0 /* Span */) {
|
|
147569
147602
|
groupedReferences.valid = false;
|
|
147570
147603
|
continue;
|
|
147571
147604
|
}
|
|
147605
|
+
/* Declarations in object literals may be implementations of method signatures which have a different symbol from the declaration
|
|
147606
|
+
For example:
|
|
147607
|
+
interface IFoo { m(a: number): void }
|
|
147608
|
+
const foo: IFoo = { m(a: number): void {} }
|
|
147609
|
+
In these cases we get the symbol for the signature from the contextual type.
|
|
147610
|
+
*/
|
|
147611
|
+
if (ts.contains(contextualSymbols, getSymbolTargetAtLocation(entry.node))) {
|
|
147612
|
+
if (isValidMethodSignature(entry.node.parent)) {
|
|
147613
|
+
groupedReferences.signature = entry.node.parent;
|
|
147614
|
+
continue;
|
|
147615
|
+
}
|
|
147616
|
+
var call = entryToFunctionCall(entry);
|
|
147617
|
+
if (call) {
|
|
147618
|
+
groupedReferences.functionCalls.push(call);
|
|
147619
|
+
continue;
|
|
147620
|
+
}
|
|
147621
|
+
}
|
|
147622
|
+
var contextualSymbol = getSymbolForContextualType(entry.node, checker);
|
|
147623
|
+
if (contextualSymbol && ts.contains(contextualSymbols, contextualSymbol)) {
|
|
147624
|
+
var decl = entryToDeclaration(entry);
|
|
147625
|
+
if (decl) {
|
|
147626
|
+
groupedReferences.declarations.push(decl);
|
|
147627
|
+
continue;
|
|
147628
|
+
}
|
|
147629
|
+
}
|
|
147572
147630
|
/* We compare symbols because in some cases find all references wil return a reference that may or may not be to the refactored function.
|
|
147573
147631
|
Example from the refactorConvertParamsToDestructuredObject_methodCallUnion.ts test:
|
|
147574
147632
|
class A { foo(a: number, b: number) { return a + b; } }
|
|
@@ -147631,6 +147689,19 @@ var ts;
|
|
|
147631
147689
|
return symbol && ts.getSymbolTarget(symbol, checker);
|
|
147632
147690
|
}
|
|
147633
147691
|
}
|
|
147692
|
+
/**
|
|
147693
|
+
* Gets the symbol for the contextual type of the node if it is not a union or intersection.
|
|
147694
|
+
*/
|
|
147695
|
+
function getSymbolForContextualType(node, checker) {
|
|
147696
|
+
var element = ts.getContainingObjectLiteralElement(node);
|
|
147697
|
+
if (element) {
|
|
147698
|
+
var contextualType = checker.getContextualTypeForObjectLiteralElement(element);
|
|
147699
|
+
var symbol = contextualType === null || contextualType === void 0 ? void 0 : contextualType.getSymbol();
|
|
147700
|
+
if (symbol && !(ts.getCheckFlags(symbol) & 6 /* Synthetic */)) {
|
|
147701
|
+
return symbol;
|
|
147702
|
+
}
|
|
147703
|
+
}
|
|
147704
|
+
}
|
|
147634
147705
|
function entryToImportOrExport(entry) {
|
|
147635
147706
|
var node = entry.node;
|
|
147636
147707
|
if (ts.isImportSpecifier(node.parent)
|
|
@@ -147738,6 +147809,9 @@ var ts;
|
|
|
147738
147809
|
}
|
|
147739
147810
|
return false;
|
|
147740
147811
|
}
|
|
147812
|
+
function isValidMethodSignature(node) {
|
|
147813
|
+
return ts.isMethodSignature(node) && (ts.isInterfaceDeclaration(node.parent) || ts.isTypeLiteralNode(node.parent));
|
|
147814
|
+
}
|
|
147741
147815
|
function isValidFunctionDeclaration(functionDeclaration, checker) {
|
|
147742
147816
|
if (!isValidParameterNodeArray(functionDeclaration.parameters, checker))
|
|
147743
147817
|
return false;
|
|
@@ -147745,6 +147819,11 @@ var ts;
|
|
|
147745
147819
|
case 251 /* FunctionDeclaration */:
|
|
147746
147820
|
return hasNameOrDefault(functionDeclaration) && isSingleImplementation(functionDeclaration, checker);
|
|
147747
147821
|
case 165 /* MethodDeclaration */:
|
|
147822
|
+
if (ts.isObjectLiteralExpression(functionDeclaration.parent)) {
|
|
147823
|
+
var contextualSymbol = getSymbolForContextualType(functionDeclaration.name, checker);
|
|
147824
|
+
// don't offer the refactor when there are multiple signatures since we won't know which ones the user wants to change
|
|
147825
|
+
return (contextualSymbol === null || contextualSymbol === void 0 ? void 0 : contextualSymbol.declarations.length) === 1 && isSingleImplementation(functionDeclaration, checker);
|
|
147826
|
+
}
|
|
147748
147827
|
return isSingleImplementation(functionDeclaration, checker);
|
|
147749
147828
|
case 166 /* Constructor */:
|
|
147750
147829
|
if (ts.isClassDeclaration(functionDeclaration.parent)) {
|
|
@@ -152660,6 +152739,34 @@ var ts;
|
|
|
152660
152739
|
ScriptTarget["ES2020"] = "ES2020";
|
|
152661
152740
|
ScriptTarget["ESNext"] = "ESNext";
|
|
152662
152741
|
})(ScriptTarget = protocol.ScriptTarget || (protocol.ScriptTarget = {}));
|
|
152742
|
+
var ClassificationType;
|
|
152743
|
+
(function (ClassificationType) {
|
|
152744
|
+
ClassificationType[ClassificationType["comment"] = 1] = "comment";
|
|
152745
|
+
ClassificationType[ClassificationType["identifier"] = 2] = "identifier";
|
|
152746
|
+
ClassificationType[ClassificationType["keyword"] = 3] = "keyword";
|
|
152747
|
+
ClassificationType[ClassificationType["numericLiteral"] = 4] = "numericLiteral";
|
|
152748
|
+
ClassificationType[ClassificationType["operator"] = 5] = "operator";
|
|
152749
|
+
ClassificationType[ClassificationType["stringLiteral"] = 6] = "stringLiteral";
|
|
152750
|
+
ClassificationType[ClassificationType["regularExpressionLiteral"] = 7] = "regularExpressionLiteral";
|
|
152751
|
+
ClassificationType[ClassificationType["whiteSpace"] = 8] = "whiteSpace";
|
|
152752
|
+
ClassificationType[ClassificationType["text"] = 9] = "text";
|
|
152753
|
+
ClassificationType[ClassificationType["punctuation"] = 10] = "punctuation";
|
|
152754
|
+
ClassificationType[ClassificationType["className"] = 11] = "className";
|
|
152755
|
+
ClassificationType[ClassificationType["enumName"] = 12] = "enumName";
|
|
152756
|
+
ClassificationType[ClassificationType["interfaceName"] = 13] = "interfaceName";
|
|
152757
|
+
ClassificationType[ClassificationType["moduleName"] = 14] = "moduleName";
|
|
152758
|
+
ClassificationType[ClassificationType["typeParameterName"] = 15] = "typeParameterName";
|
|
152759
|
+
ClassificationType[ClassificationType["typeAliasName"] = 16] = "typeAliasName";
|
|
152760
|
+
ClassificationType[ClassificationType["parameterName"] = 17] = "parameterName";
|
|
152761
|
+
ClassificationType[ClassificationType["docCommentTagName"] = 18] = "docCommentTagName";
|
|
152762
|
+
ClassificationType[ClassificationType["jsxOpenTagName"] = 19] = "jsxOpenTagName";
|
|
152763
|
+
ClassificationType[ClassificationType["jsxCloseTagName"] = 20] = "jsxCloseTagName";
|
|
152764
|
+
ClassificationType[ClassificationType["jsxSelfClosingTagName"] = 21] = "jsxSelfClosingTagName";
|
|
152765
|
+
ClassificationType[ClassificationType["jsxAttribute"] = 22] = "jsxAttribute";
|
|
152766
|
+
ClassificationType[ClassificationType["jsxText"] = 23] = "jsxText";
|
|
152767
|
+
ClassificationType[ClassificationType["jsxAttributeStringLiteralValue"] = 24] = "jsxAttributeStringLiteralValue";
|
|
152768
|
+
ClassificationType[ClassificationType["bigintLiteral"] = 25] = "bigintLiteral";
|
|
152769
|
+
})(ClassificationType = protocol.ClassificationType || (protocol.ClassificationType = {}));
|
|
152663
152770
|
})(protocol = server.protocol || (server.protocol = {}));
|
|
152664
152771
|
})(server = ts.server || (ts.server = {}));
|
|
152665
152772
|
})(ts || (ts = {}));
|
|
@@ -154609,6 +154716,10 @@ var ts;
|
|
|
154609
154716
|
Project.prototype.enablePlugin = function (pluginConfigEntry, searchPaths, pluginConfigOverrides) {
|
|
154610
154717
|
var _this = this;
|
|
154611
154718
|
this.projectService.logger.info("Enabling plugin " + pluginConfigEntry.name + " from candidate paths: " + searchPaths.join(","));
|
|
154719
|
+
if (!pluginConfigEntry.name || ts.parsePackageName(pluginConfigEntry.name).rest) {
|
|
154720
|
+
this.projectService.logger.info("Skipped loading plugin " + (pluginConfigEntry.name || JSON.stringify(pluginConfigEntry)) + " because only package name is allowed plugin name");
|
|
154721
|
+
return;
|
|
154722
|
+
}
|
|
154612
154723
|
var log = function (message) { return _this.projectService.logger.info(message); };
|
|
154613
154724
|
var errorLogs;
|
|
154614
154725
|
var logError = function (message) { (errorLogs || (errorLogs = [])).push(message); };
|
package/lib/typescript.js
CHANGED
|
@@ -290,7 +290,7 @@ var ts;
|
|
|
290
290
|
// The following is baselined as a literal template type without intervention
|
|
291
291
|
/** The version of the TypeScript compiler release */
|
|
292
292
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
293
|
-
ts.version =
|
|
293
|
+
ts.version = "4.2.3";
|
|
294
294
|
/* @internal */
|
|
295
295
|
var Comparison;
|
|
296
296
|
(function (Comparison) {
|
|
@@ -47238,13 +47238,17 @@ var ts;
|
|
|
47238
47238
|
return result || ts.emptyArray;
|
|
47239
47239
|
}
|
|
47240
47240
|
function setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo) {
|
|
47241
|
-
|
|
47242
|
-
|
|
47243
|
-
|
|
47244
|
-
|
|
47245
|
-
|
|
47246
|
-
|
|
47247
|
-
|
|
47241
|
+
var resolved = type;
|
|
47242
|
+
resolved.members = members;
|
|
47243
|
+
resolved.properties = ts.emptyArray;
|
|
47244
|
+
resolved.callSignatures = callSignatures;
|
|
47245
|
+
resolved.constructSignatures = constructSignatures;
|
|
47246
|
+
resolved.stringIndexInfo = stringIndexInfo;
|
|
47247
|
+
resolved.numberIndexInfo = numberIndexInfo;
|
|
47248
|
+
// This can loop back to getPropertyOfType() which would crash if `callSignatures` & `constructSignatures` are not initialized.
|
|
47249
|
+
if (members !== emptySymbols)
|
|
47250
|
+
resolved.properties = getNamedMembers(members);
|
|
47251
|
+
return resolved;
|
|
47248
47252
|
}
|
|
47249
47253
|
function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo) {
|
|
47250
47254
|
return setStructuredTypeMembers(createObjectType(16 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
|
|
@@ -55871,7 +55875,7 @@ var ts;
|
|
|
55871
55875
|
}
|
|
55872
55876
|
return true;
|
|
55873
55877
|
}
|
|
55874
|
-
function removeRedundantLiteralTypes(types, includes) {
|
|
55878
|
+
function removeRedundantLiteralTypes(types, includes, reduceVoidUndefined) {
|
|
55875
55879
|
var i = types.length;
|
|
55876
55880
|
while (i > 0) {
|
|
55877
55881
|
i--;
|
|
@@ -55881,7 +55885,7 @@ var ts;
|
|
|
55881
55885
|
flags & 256 /* NumberLiteral */ && includes & 8 /* Number */ ||
|
|
55882
55886
|
flags & 2048 /* BigIntLiteral */ && includes & 64 /* BigInt */ ||
|
|
55883
55887
|
flags & 8192 /* UniqueESSymbol */ && includes & 4096 /* ESSymbol */ ||
|
|
55884
|
-
flags & 32768 /* Undefined */ && includes & 16384 /* Void */ ||
|
|
55888
|
+
reduceVoidUndefined && flags & 32768 /* Undefined */ && includes & 16384 /* Void */ ||
|
|
55885
55889
|
isFreshLiteralType(t) && containsType(types, t.regularType);
|
|
55886
55890
|
if (remove) {
|
|
55887
55891
|
ts.orderedRemoveItemAt(types, i);
|
|
@@ -55913,7 +55917,7 @@ var ts;
|
|
|
55913
55917
|
if (t.flags & 1048576 /* Union */) {
|
|
55914
55918
|
var origin = t.origin;
|
|
55915
55919
|
if (t.aliasSymbol || origin && !(origin.flags & 1048576 /* Union */)) {
|
|
55916
|
-
|
|
55920
|
+
ts.pushIfUnique(namedUnions, t);
|
|
55917
55921
|
}
|
|
55918
55922
|
else if (origin && origin.flags & 1048576 /* Union */) {
|
|
55919
55923
|
addNamedUnions(namedUnions, origin.types);
|
|
@@ -55949,7 +55953,7 @@ var ts;
|
|
|
55949
55953
|
}
|
|
55950
55954
|
if (unionReduction & (1 /* Literal */ | 2 /* Subtype */)) {
|
|
55951
55955
|
if (includes & (2944 /* Literal */ | 8192 /* UniqueESSymbol */) || includes & 16384 /* Void */ && includes & 32768 /* Undefined */) {
|
|
55952
|
-
removeRedundantLiteralTypes(typeSet, includes);
|
|
55956
|
+
removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & 2 /* Subtype */));
|
|
55953
55957
|
}
|
|
55954
55958
|
if (includes & 128 /* StringLiteral */ && includes & 134217728 /* TemplateLiteral */) {
|
|
55955
55959
|
removeStringLiteralsMatchedByTemplateLiterals(typeSet);
|
|
@@ -63970,7 +63974,16 @@ var ts;
|
|
|
63970
63974
|
var type = getTypeOfDottedName(node.expression, diagnostic);
|
|
63971
63975
|
if (type) {
|
|
63972
63976
|
var name = node.name;
|
|
63973
|
-
var prop =
|
|
63977
|
+
var prop = void 0;
|
|
63978
|
+
if (ts.isPrivateIdentifier(name)) {
|
|
63979
|
+
if (!type.symbol) {
|
|
63980
|
+
return undefined;
|
|
63981
|
+
}
|
|
63982
|
+
prop = getPropertyOfType(type, ts.getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText));
|
|
63983
|
+
}
|
|
63984
|
+
else {
|
|
63985
|
+
prop = getPropertyOfType(type, name.escapedText);
|
|
63986
|
+
}
|
|
63974
63987
|
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
|
|
63975
63988
|
}
|
|
63976
63989
|
return undefined;
|
|
@@ -65036,10 +65049,15 @@ var ts;
|
|
|
65036
65049
|
return assignableType;
|
|
65037
65050
|
}
|
|
65038
65051
|
}
|
|
65039
|
-
// If the candidate type is a subtype of the target type, narrow to the candidate type
|
|
65040
|
-
// if the target type is
|
|
65041
|
-
//
|
|
65042
|
-
|
|
65052
|
+
// If the candidate type is a subtype of the target type, narrow to the candidate type.
|
|
65053
|
+
// Otherwise, if the target type is assignable to the candidate type, keep the target type.
|
|
65054
|
+
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
|
|
65055
|
+
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
|
|
65056
|
+
// two types.
|
|
65057
|
+
return isTypeSubtypeOf(candidate, type) ? candidate :
|
|
65058
|
+
isTypeAssignableTo(type, candidate) ? type :
|
|
65059
|
+
isTypeAssignableTo(candidate, type) ? candidate :
|
|
65060
|
+
getIntersectionType([type, candidate]);
|
|
65043
65061
|
}
|
|
65044
65062
|
function narrowTypeByCallExpression(type, callExpression, assumeTrue) {
|
|
65045
65063
|
if (hasMatchingArgument(callExpression, reference)) {
|
|
@@ -75382,7 +75400,9 @@ var ts;
|
|
|
75382
75400
|
: ts.isPropertyAccessExpression(location) ? location.name
|
|
75383
75401
|
: ts.isBinaryExpression(location) && ts.isIdentifier(location.right) ? location.right
|
|
75384
75402
|
: undefined;
|
|
75385
|
-
|
|
75403
|
+
var isPropertyExpressionCast = ts.isPropertyAccessExpression(location)
|
|
75404
|
+
&& ts.isAssertionExpression(ts.skipParentheses(location.expression));
|
|
75405
|
+
if (!testedNode || isPropertyExpressionCast) {
|
|
75386
75406
|
return;
|
|
75387
75407
|
}
|
|
75388
75408
|
var possiblyFalsy = getFalsyFlags(type);
|
|
@@ -77532,6 +77552,7 @@ var ts;
|
|
|
77532
77552
|
return true;
|
|
77533
77553
|
}
|
|
77534
77554
|
function checkAliasSymbol(node) {
|
|
77555
|
+
var _a;
|
|
77535
77556
|
var symbol = getSymbolOfNode(node);
|
|
77536
77557
|
var target = resolveAlias(symbol);
|
|
77537
77558
|
if (target !== unknownSymbol) {
|
|
@@ -77559,7 +77580,7 @@ var ts;
|
|
|
77559
77580
|
&& !(node.flags & 8388608 /* Ambient */)) {
|
|
77560
77581
|
error(node, ts.Diagnostics.Re_exporting_a_type_when_the_isolatedModules_flag_is_provided_requires_using_export_type);
|
|
77561
77582
|
}
|
|
77562
|
-
if (ts.isImportSpecifier(node) &&
|
|
77583
|
+
if (ts.isImportSpecifier(node) && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); }))) {
|
|
77563
77584
|
addDeprecatedSuggestion(node.name, target.declarations, symbol.escapedName);
|
|
77564
77585
|
}
|
|
77565
77586
|
}
|
|
@@ -111664,10 +111685,11 @@ var ts;
|
|
|
111664
111685
|
var redirects = host.redirectTargetsMap.get(importedPath) || ts.emptyArray;
|
|
111665
111686
|
var importedFileNames = __spreadArray(__spreadArray(__spreadArray([], (referenceRedirect ? [referenceRedirect] : ts.emptyArray)), [importedFileName]), redirects);
|
|
111666
111687
|
var targets = importedFileNames.map(function (f) { return ts.getNormalizedAbsolutePath(f, cwd); });
|
|
111688
|
+
var shouldFilterIgnoredPaths = !ts.every(targets, ts.containsIgnoredPath);
|
|
111667
111689
|
if (!preferSymlinks) {
|
|
111668
111690
|
// Symlinks inside ignored paths are already filtered out of the symlink cache,
|
|
111669
111691
|
// so we only need to remove them from the realpath filenames.
|
|
111670
|
-
var result_15 = ts.forEach(targets, function (p) { return !ts.containsIgnoredPath(p) && cb(p, referenceRedirect === p); });
|
|
111692
|
+
var result_15 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
|
|
111671
111693
|
if (result_15)
|
|
111672
111694
|
return result_15;
|
|
111673
111695
|
}
|
|
@@ -111693,13 +111715,14 @@ var ts;
|
|
|
111693
111715
|
var symlinkDirectory = symlinkDirectories_1[_i];
|
|
111694
111716
|
var option = ts.resolvePath(symlinkDirectory, relative);
|
|
111695
111717
|
var result_16 = cb(option, target === referenceRedirect);
|
|
111718
|
+
shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
|
|
111696
111719
|
if (result_16)
|
|
111697
111720
|
return result_16;
|
|
111698
111721
|
}
|
|
111699
111722
|
});
|
|
111700
111723
|
});
|
|
111701
111724
|
return result || (preferSymlinks
|
|
111702
|
-
? ts.forEach(targets, function (p) { return ts.containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect); })
|
|
111725
|
+
? ts.forEach(targets, function (p) { return shouldFilterIgnoredPaths && ts.containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect); })
|
|
111703
111726
|
: undefined);
|
|
111704
111727
|
}
|
|
111705
111728
|
moduleSpecifiers.forEachFileNameOfModule = forEachFileNameOfModule;
|
|
@@ -140149,7 +140172,7 @@ var ts;
|
|
|
140149
140172
|
}
|
|
140150
140173
|
function addFunctionDeclaration(changes, context, info) {
|
|
140151
140174
|
var importAdder = codefix.createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
|
140152
|
-
var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(251 /* FunctionDeclaration */, context, importAdder, info.call, info.token, info.modifierFlags, info.parentDeclaration);
|
|
140175
|
+
var functionDeclaration = codefix.createSignatureDeclarationFromCallExpression(251 /* FunctionDeclaration */, context, importAdder, info.call, ts.idText(info.token), info.modifierFlags, info.parentDeclaration);
|
|
140153
140176
|
changes.insertNodeAtEndOfScope(info.sourceFile, info.parentDeclaration, functionDeclaration);
|
|
140154
140177
|
}
|
|
140155
140178
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -147530,13 +147553,13 @@ var ts;
|
|
|
147530
147553
|
return { edits: [] }; // TODO: GH#30113
|
|
147531
147554
|
}
|
|
147532
147555
|
function doChange(sourceFile, program, host, changes, functionDeclaration, groupedReferences) {
|
|
147533
|
-
var
|
|
147534
|
-
|
|
147535
|
-
|
|
147536
|
-
|
|
147537
|
-
|
|
147538
|
-
|
|
147539
|
-
|
|
147556
|
+
var signature = groupedReferences.signature;
|
|
147557
|
+
var newFunctionDeclarationParams = ts.map(createNewParameters(functionDeclaration, program, host), function (param) { return ts.getSynthesizedDeepClone(param); });
|
|
147558
|
+
if (signature) {
|
|
147559
|
+
var newSignatureParams = ts.map(createNewParameters(signature, program, host), function (param) { return ts.getSynthesizedDeepClone(param); });
|
|
147560
|
+
replaceParameters(signature, newSignatureParams);
|
|
147561
|
+
}
|
|
147562
|
+
replaceParameters(functionDeclaration, newFunctionDeclarationParams);
|
|
147540
147563
|
var functionCalls = ts.sortAndDeduplicate(groupedReferences.functionCalls, /*comparer*/ function (a, b) { return ts.compareValues(a.pos, b.pos); });
|
|
147541
147564
|
for (var _i = 0, functionCalls_1 = functionCalls; _i < functionCalls_1.length; _i++) {
|
|
147542
147565
|
var call = functionCalls_1[_i];
|
|
@@ -147545,6 +147568,15 @@ var ts;
|
|
|
147545
147568
|
changes.replaceNodeRange(ts.getSourceFileOfNode(call), ts.first(call.arguments), ts.last(call.arguments), newArgument, { leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll, trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Include });
|
|
147546
147569
|
}
|
|
147547
147570
|
}
|
|
147571
|
+
function replaceParameters(declarationOrSignature, parameterDeclarations) {
|
|
147572
|
+
changes.replaceNodeRangeWithNodes(sourceFile, ts.first(declarationOrSignature.parameters), ts.last(declarationOrSignature.parameters), parameterDeclarations, {
|
|
147573
|
+
joiner: ", ",
|
|
147574
|
+
// indentation is set to 0 because otherwise the object parameter will be indented if there is a `this` parameter
|
|
147575
|
+
indentation: 0,
|
|
147576
|
+
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
|
|
147577
|
+
trailingTriviaOption: ts.textChanges.TrailingTriviaOption.Include
|
|
147578
|
+
});
|
|
147579
|
+
}
|
|
147548
147580
|
}
|
|
147549
147581
|
function getGroupedReferences(functionDeclaration, program, cancellationToken) {
|
|
147550
147582
|
var functionNames = getFunctionNames(functionDeclaration);
|
|
@@ -147563,12 +147595,38 @@ var ts;
|
|
|
147563
147595
|
var functionSymbols = ts.map(functionNames, getSymbolTargetAtLocation);
|
|
147564
147596
|
var classSymbols = ts.map(classNames, getSymbolTargetAtLocation);
|
|
147565
147597
|
var isConstructor = ts.isConstructorDeclaration(functionDeclaration);
|
|
147598
|
+
var contextualSymbols = ts.map(functionNames, function (name) { return getSymbolForContextualType(name, checker); });
|
|
147566
147599
|
for (var _i = 0, referenceEntries_1 = referenceEntries; _i < referenceEntries_1.length; _i++) {
|
|
147567
147600
|
var entry = referenceEntries_1[_i];
|
|
147568
|
-
if (entry.kind
|
|
147601
|
+
if (entry.kind === 0 /* Span */) {
|
|
147569
147602
|
groupedReferences.valid = false;
|
|
147570
147603
|
continue;
|
|
147571
147604
|
}
|
|
147605
|
+
/* Declarations in object literals may be implementations of method signatures which have a different symbol from the declaration
|
|
147606
|
+
For example:
|
|
147607
|
+
interface IFoo { m(a: number): void }
|
|
147608
|
+
const foo: IFoo = { m(a: number): void {} }
|
|
147609
|
+
In these cases we get the symbol for the signature from the contextual type.
|
|
147610
|
+
*/
|
|
147611
|
+
if (ts.contains(contextualSymbols, getSymbolTargetAtLocation(entry.node))) {
|
|
147612
|
+
if (isValidMethodSignature(entry.node.parent)) {
|
|
147613
|
+
groupedReferences.signature = entry.node.parent;
|
|
147614
|
+
continue;
|
|
147615
|
+
}
|
|
147616
|
+
var call = entryToFunctionCall(entry);
|
|
147617
|
+
if (call) {
|
|
147618
|
+
groupedReferences.functionCalls.push(call);
|
|
147619
|
+
continue;
|
|
147620
|
+
}
|
|
147621
|
+
}
|
|
147622
|
+
var contextualSymbol = getSymbolForContextualType(entry.node, checker);
|
|
147623
|
+
if (contextualSymbol && ts.contains(contextualSymbols, contextualSymbol)) {
|
|
147624
|
+
var decl = entryToDeclaration(entry);
|
|
147625
|
+
if (decl) {
|
|
147626
|
+
groupedReferences.declarations.push(decl);
|
|
147627
|
+
continue;
|
|
147628
|
+
}
|
|
147629
|
+
}
|
|
147572
147630
|
/* We compare symbols because in some cases find all references wil return a reference that may or may not be to the refactored function.
|
|
147573
147631
|
Example from the refactorConvertParamsToDestructuredObject_methodCallUnion.ts test:
|
|
147574
147632
|
class A { foo(a: number, b: number) { return a + b; } }
|
|
@@ -147631,6 +147689,19 @@ var ts;
|
|
|
147631
147689
|
return symbol && ts.getSymbolTarget(symbol, checker);
|
|
147632
147690
|
}
|
|
147633
147691
|
}
|
|
147692
|
+
/**
|
|
147693
|
+
* Gets the symbol for the contextual type of the node if it is not a union or intersection.
|
|
147694
|
+
*/
|
|
147695
|
+
function getSymbolForContextualType(node, checker) {
|
|
147696
|
+
var element = ts.getContainingObjectLiteralElement(node);
|
|
147697
|
+
if (element) {
|
|
147698
|
+
var contextualType = checker.getContextualTypeForObjectLiteralElement(element);
|
|
147699
|
+
var symbol = contextualType === null || contextualType === void 0 ? void 0 : contextualType.getSymbol();
|
|
147700
|
+
if (symbol && !(ts.getCheckFlags(symbol) & 6 /* Synthetic */)) {
|
|
147701
|
+
return symbol;
|
|
147702
|
+
}
|
|
147703
|
+
}
|
|
147704
|
+
}
|
|
147634
147705
|
function entryToImportOrExport(entry) {
|
|
147635
147706
|
var node = entry.node;
|
|
147636
147707
|
if (ts.isImportSpecifier(node.parent)
|
|
@@ -147738,6 +147809,9 @@ var ts;
|
|
|
147738
147809
|
}
|
|
147739
147810
|
return false;
|
|
147740
147811
|
}
|
|
147812
|
+
function isValidMethodSignature(node) {
|
|
147813
|
+
return ts.isMethodSignature(node) && (ts.isInterfaceDeclaration(node.parent) || ts.isTypeLiteralNode(node.parent));
|
|
147814
|
+
}
|
|
147741
147815
|
function isValidFunctionDeclaration(functionDeclaration, checker) {
|
|
147742
147816
|
if (!isValidParameterNodeArray(functionDeclaration.parameters, checker))
|
|
147743
147817
|
return false;
|
|
@@ -147745,6 +147819,11 @@ var ts;
|
|
|
147745
147819
|
case 251 /* FunctionDeclaration */:
|
|
147746
147820
|
return hasNameOrDefault(functionDeclaration) && isSingleImplementation(functionDeclaration, checker);
|
|
147747
147821
|
case 165 /* MethodDeclaration */:
|
|
147822
|
+
if (ts.isObjectLiteralExpression(functionDeclaration.parent)) {
|
|
147823
|
+
var contextualSymbol = getSymbolForContextualType(functionDeclaration.name, checker);
|
|
147824
|
+
// don't offer the refactor when there are multiple signatures since we won't know which ones the user wants to change
|
|
147825
|
+
return (contextualSymbol === null || contextualSymbol === void 0 ? void 0 : contextualSymbol.declarations.length) === 1 && isSingleImplementation(functionDeclaration, checker);
|
|
147826
|
+
}
|
|
147748
147827
|
return isSingleImplementation(functionDeclaration, checker);
|
|
147749
147828
|
case 166 /* Constructor */:
|
|
147750
147829
|
if (ts.isClassDeclaration(functionDeclaration.parent)) {
|