typescript 4.6.0-dev.20220126 → 4.6.0-dev.20220130
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/cs/diagnosticMessages.generated.json +22 -8
- package/lib/de/diagnosticMessages.generated.json +19 -4
- package/lib/es/diagnosticMessages.generated.json +22 -8
- package/lib/fr/diagnosticMessages.generated.json +22 -8
- package/lib/it/diagnosticMessages.generated.json +22 -8
- package/lib/ja/diagnosticMessages.generated.json +22 -8
- package/lib/ko/diagnosticMessages.generated.json +22 -8
- package/lib/lib.dom.d.ts +72 -0
- package/lib/lib.dom.iterable.d.ts +4 -0
- package/lib/lib.webworker.d.ts +48 -0
- package/lib/pl/diagnosticMessages.generated.json +19 -4
- package/lib/pt-br/diagnosticMessages.generated.json +22 -8
- package/lib/ru/diagnosticMessages.generated.json +22 -8
- package/lib/tr/diagnosticMessages.generated.json +19 -4
- package/lib/tsc.js +82 -79
- package/lib/tsserver.js +429 -177
- package/lib/tsserverlibrary.d.ts +7 -3
- package/lib/tsserverlibrary.js +429 -177
- package/lib/typescript.d.ts +7 -3
- package/lib/typescript.js +429 -177
- package/lib/typescriptServices.d.ts +7 -3
- package/lib/typescriptServices.js +429 -177
- package/lib/typingsInstaller.js +93 -90
- package/lib/zh-cn/diagnosticMessages.generated.json +22 -8
- package/lib/zh-tw/diagnosticMessages.generated.json +19 -4
- package/package.json +1 -1
package/lib/tsserver.js
CHANGED
|
@@ -100,7 +100,7 @@ var ts;
|
|
|
100
100
|
// The following is baselined as a literal template type without intervention
|
|
101
101
|
/** The version of the TypeScript compiler release */
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
103
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220130";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -7855,7 +7855,7 @@ var ts;
|
|
|
7855
7855
|
}
|
|
7856
7856
|
})(ts || (ts = {}));
|
|
7857
7857
|
// <auto-generated />
|
|
7858
|
-
// generated from './
|
|
7858
|
+
// generated from './diagnosticMessages.json' in 'src/compiler'
|
|
7859
7859
|
/* @internal */
|
|
7860
7860
|
var ts;
|
|
7861
7861
|
(function (ts) {
|
|
@@ -9443,9 +9443,8 @@ var ts;
|
|
|
9443
9443
|
Remove_variable_statement: diag(90010, ts.DiagnosticCategory.Message, "Remove_variable_statement_90010", "Remove variable statement"),
|
|
9444
9444
|
Remove_template_tag: diag(90011, ts.DiagnosticCategory.Message, "Remove_template_tag_90011", "Remove template tag"),
|
|
9445
9445
|
Remove_type_parameters: diag(90012, ts.DiagnosticCategory.Message, "Remove_type_parameters_90012", "Remove type parameters"),
|
|
9446
|
-
|
|
9446
|
+
Import_0_from_1: diag(90013, ts.DiagnosticCategory.Message, "Import_0_from_1_90013", "Import '{0}' from \"{1}\""),
|
|
9447
9447
|
Change_0_to_1: diag(90014, ts.DiagnosticCategory.Message, "Change_0_to_1_90014", "Change '{0}' to '{1}'"),
|
|
9448
|
-
Add_0_to_existing_import_declaration_from_1: diag(90015, ts.DiagnosticCategory.Message, "Add_0_to_existing_import_declaration_from_1_90015", "Add '{0}' to existing import declaration from \"{1}\""),
|
|
9449
9448
|
Declare_property_0: diag(90016, ts.DiagnosticCategory.Message, "Declare_property_0_90016", "Declare property '{0}'"),
|
|
9450
9449
|
Add_index_signature_for_property_0: diag(90017, ts.DiagnosticCategory.Message, "Add_index_signature_for_property_0_90017", "Add index signature for property '{0}'"),
|
|
9451
9450
|
Disable_checking_for_this_file: diag(90018, ts.DiagnosticCategory.Message, "Disable_checking_for_this_file_90018", "Disable checking for this file"),
|
|
@@ -9462,8 +9461,6 @@ var ts;
|
|
|
9462
9461
|
Add_async_modifier_to_containing_function: diag(90029, ts.DiagnosticCategory.Message, "Add_async_modifier_to_containing_function_90029", "Add async modifier to containing function"),
|
|
9463
9462
|
Replace_infer_0_with_unknown: diag(90030, ts.DiagnosticCategory.Message, "Replace_infer_0_with_unknown_90030", "Replace 'infer {0}' with 'unknown'"),
|
|
9464
9463
|
Replace_all_unused_infer_with_unknown: diag(90031, ts.DiagnosticCategory.Message, "Replace_all_unused_infer_with_unknown_90031", "Replace all unused 'infer' with 'unknown'"),
|
|
9465
|
-
Import_default_0_from_module_1: diag(90032, ts.DiagnosticCategory.Message, "Import_default_0_from_module_1_90032", "Import default '{0}' from module \"{1}\""),
|
|
9466
|
-
Add_default_import_0_to_existing_import_declaration_from_1: diag(90033, ts.DiagnosticCategory.Message, "Add_default_import_0_to_existing_import_declaration_from_1_90033", "Add default import '{0}' to existing import declaration from \"{1}\""),
|
|
9467
9464
|
Add_parameter_name: diag(90034, ts.DiagnosticCategory.Message, "Add_parameter_name_90034", "Add parameter name"),
|
|
9468
9465
|
Declare_private_property_0: diag(90035, ts.DiagnosticCategory.Message, "Declare_private_property_0_90035", "Declare private property '{0}'"),
|
|
9469
9466
|
Replace_0_with_Promise_1: diag(90036, ts.DiagnosticCategory.Message, "Replace_0_with_Promise_1_90036", "Replace '{0}' with 'Promise<{1}>'"),
|
|
@@ -9473,6 +9470,10 @@ var ts;
|
|
|
9473
9470
|
Remove_unused_declarations_for_Colon_0: diag(90041, ts.DiagnosticCategory.Message, "Remove_unused_declarations_for_Colon_0_90041", "Remove unused declarations for: '{0}'"),
|
|
9474
9471
|
Declare_a_private_field_named_0: diag(90053, ts.DiagnosticCategory.Message, "Declare_a_private_field_named_0_90053", "Declare a private field named '{0}'."),
|
|
9475
9472
|
Includes_imports_of_types_referenced_by_0: diag(90054, ts.DiagnosticCategory.Message, "Includes_imports_of_types_referenced_by_0_90054", "Includes imports of types referenced by '{0}'"),
|
|
9473
|
+
Remove_type_from_import_declaration_from_0: diag(90055, ts.DiagnosticCategory.Message, "Remove_type_from_import_declaration_from_0_90055", "Remove 'type' from import declaration from \"{0}\""),
|
|
9474
|
+
Remove_type_from_import_of_0_from_1: diag(90056, ts.DiagnosticCategory.Message, "Remove_type_from_import_of_0_from_1_90056", "Remove 'type' from import of '{0}' from \"{1}\""),
|
|
9475
|
+
Add_import_from_0: diag(90057, ts.DiagnosticCategory.Message, "Add_import_from_0_90057", "Add import from \"{0}\""),
|
|
9476
|
+
Update_import_from_0: diag(90058, ts.DiagnosticCategory.Message, "Update_import_from_0_90058", "Update import from \"{0}\""),
|
|
9476
9477
|
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
|
|
9477
9478
|
Convert_0_to_1_in_0: diag(95003, ts.DiagnosticCategory.Message, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
|
|
9478
9479
|
Extract_to_0_in_1: diag(95004, ts.DiagnosticCategory.Message, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
|
|
@@ -14902,6 +14903,15 @@ var ts;
|
|
|
14902
14903
|
};
|
|
14903
14904
|
}
|
|
14904
14905
|
ts.createDiagnosticForFileFromMessageChain = createDiagnosticForFileFromMessageChain;
|
|
14906
|
+
function createDiagnosticMessageChainFromDiagnostic(diagnostic) {
|
|
14907
|
+
return typeof diagnostic.messageText === "string" ? {
|
|
14908
|
+
code: diagnostic.code,
|
|
14909
|
+
category: diagnostic.category,
|
|
14910
|
+
messageText: diagnostic.messageText,
|
|
14911
|
+
next: diagnostic.next,
|
|
14912
|
+
} : diagnostic.messageText;
|
|
14913
|
+
}
|
|
14914
|
+
ts.createDiagnosticMessageChainFromDiagnostic = createDiagnosticMessageChainFromDiagnostic;
|
|
14905
14915
|
function createDiagnosticForRange(sourceFile, range, message) {
|
|
14906
14916
|
return {
|
|
14907
14917
|
file: sourceFile,
|
|
@@ -20862,6 +20872,59 @@ var ts;
|
|
|
20862
20872
|
return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
|
|
20863
20873
|
}
|
|
20864
20874
|
ts.isThisTypeParameter = isThisTypeParameter;
|
|
20875
|
+
function getNodeModulePathParts(fullPath) {
|
|
20876
|
+
// If fullPath can't be valid module file within node_modules, returns undefined.
|
|
20877
|
+
// Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
|
|
20878
|
+
// Returns indices: ^ ^ ^ ^
|
|
20879
|
+
var topLevelNodeModulesIndex = 0;
|
|
20880
|
+
var topLevelPackageNameIndex = 0;
|
|
20881
|
+
var packageRootIndex = 0;
|
|
20882
|
+
var fileNameIndex = 0;
|
|
20883
|
+
var States;
|
|
20884
|
+
(function (States) {
|
|
20885
|
+
States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
|
|
20886
|
+
States[States["NodeModules"] = 1] = "NodeModules";
|
|
20887
|
+
States[States["Scope"] = 2] = "Scope";
|
|
20888
|
+
States[States["PackageContent"] = 3] = "PackageContent";
|
|
20889
|
+
})(States || (States = {}));
|
|
20890
|
+
var partStart = 0;
|
|
20891
|
+
var partEnd = 0;
|
|
20892
|
+
var state = 0 /* BeforeNodeModules */;
|
|
20893
|
+
while (partEnd >= 0) {
|
|
20894
|
+
partStart = partEnd;
|
|
20895
|
+
partEnd = fullPath.indexOf("/", partStart + 1);
|
|
20896
|
+
switch (state) {
|
|
20897
|
+
case 0 /* BeforeNodeModules */:
|
|
20898
|
+
if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
|
|
20899
|
+
topLevelNodeModulesIndex = partStart;
|
|
20900
|
+
topLevelPackageNameIndex = partEnd;
|
|
20901
|
+
state = 1 /* NodeModules */;
|
|
20902
|
+
}
|
|
20903
|
+
break;
|
|
20904
|
+
case 1 /* NodeModules */:
|
|
20905
|
+
case 2 /* Scope */:
|
|
20906
|
+
if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
|
|
20907
|
+
state = 2 /* Scope */;
|
|
20908
|
+
}
|
|
20909
|
+
else {
|
|
20910
|
+
packageRootIndex = partEnd;
|
|
20911
|
+
state = 3 /* PackageContent */;
|
|
20912
|
+
}
|
|
20913
|
+
break;
|
|
20914
|
+
case 3 /* PackageContent */:
|
|
20915
|
+
if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
|
|
20916
|
+
state = 1 /* NodeModules */;
|
|
20917
|
+
}
|
|
20918
|
+
else {
|
|
20919
|
+
state = 3 /* PackageContent */;
|
|
20920
|
+
}
|
|
20921
|
+
break;
|
|
20922
|
+
}
|
|
20923
|
+
}
|
|
20924
|
+
fileNameIndex = partStart;
|
|
20925
|
+
return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
|
|
20926
|
+
}
|
|
20927
|
+
ts.getNodeModulePathParts = getNodeModulePathParts;
|
|
20865
20928
|
})(ts || (ts = {}));
|
|
20866
20929
|
/* @internal */
|
|
20867
20930
|
var ts;
|
|
@@ -48756,24 +48819,19 @@ var ts;
|
|
|
48756
48819
|
error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
|
|
48757
48820
|
}
|
|
48758
48821
|
}
|
|
48759
|
-
if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */) {
|
|
48760
|
-
|
|
48822
|
+
if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
|
|
48823
|
+
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
|
|
48824
|
+
if (typeOnlyDeclaration) {
|
|
48825
|
+
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48826
|
+
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48827
|
+
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48828
|
+
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
48829
|
+
addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
|
|
48830
|
+
}
|
|
48761
48831
|
}
|
|
48762
48832
|
}
|
|
48763
48833
|
return result;
|
|
48764
48834
|
}
|
|
48765
|
-
function checkSymbolUsageInExpressionContext(symbol, name, useSite) {
|
|
48766
|
-
if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
|
|
48767
|
-
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
|
|
48768
|
-
if (typeOnlyDeclaration) {
|
|
48769
|
-
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48770
|
-
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48771
|
-
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48772
|
-
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
48773
|
-
addTypeOnlyDeclarationRelatedInfo(error(useSite, message, unescapedName), typeOnlyDeclaration, unescapedName);
|
|
48774
|
-
}
|
|
48775
|
-
}
|
|
48776
|
-
}
|
|
48777
48835
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
|
|
48778
48836
|
if (!typeOnlyDeclaration)
|
|
48779
48837
|
return diagnostic;
|
|
@@ -52535,7 +52593,8 @@ var ts;
|
|
|
52535
52593
|
includePrivateSymbol === null || includePrivateSymbol === void 0 ? void 0 : includePrivateSymbol(sym);
|
|
52536
52594
|
}
|
|
52537
52595
|
if (ts.isIdentifier(node)) {
|
|
52538
|
-
var
|
|
52596
|
+
var type = getDeclaredTypeOfSymbol(sym);
|
|
52597
|
+
var name = sym.flags & 262144 /* TypeParameter */ && !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration) ? typeParameterToName(type, context) : ts.factory.cloneNode(node);
|
|
52539
52598
|
name.symbol = sym; // for quickinfo, which uses identifier symbol information
|
|
52540
52599
|
return { introducesError: introducesError, node: ts.setEmitFlags(ts.setOriginalNode(name, node), 16777216 /* NoAsciiEscaping */) };
|
|
52541
52600
|
}
|
|
@@ -74427,7 +74486,7 @@ var ts;
|
|
|
74427
74486
|
}
|
|
74428
74487
|
var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
|
|
74429
74488
|
ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
|
|
74430
|
-
var chain = ts.chainDiagnosticMessages(ts.map(diags_3,
|
|
74489
|
+
var chain = ts.chainDiagnosticMessages(ts.map(diags_3, ts.createDiagnosticMessageChainFromDiagnostic), ts.Diagnostics.No_overload_matches_this_call);
|
|
74431
74490
|
// The below is a spread to guarantee we get a new (mutable) array - our `flatMap` helper tries to do "smart" optimizations where it reuses input
|
|
74432
74491
|
// arrays and the emptyArray singleton where possible, which is decidedly not what we want while we're still constructing this diagnostic
|
|
74433
74492
|
var related = __spreadArray([], ts.flatMap(diags_3, function (d) { return d.relatedInformation; }), true);
|
|
@@ -82806,16 +82865,15 @@ var ts;
|
|
|
82806
82865
|
return ts.nodeIsMissing(expr) ? 0 : evaluateEnumMember(expr, getSymbolOfNode(member.parent), identifier.escapedText);
|
|
82807
82866
|
case 206 /* ElementAccessExpression */:
|
|
82808
82867
|
case 205 /* PropertyAccessExpression */:
|
|
82809
|
-
|
|
82810
|
-
|
|
82811
|
-
var type = getTypeOfExpression(ex.expression);
|
|
82868
|
+
if (isConstantMemberAccess(expr)) {
|
|
82869
|
+
var type = getTypeOfExpression(expr.expression);
|
|
82812
82870
|
if (type.symbol && type.symbol.flags & 384 /* Enum */) {
|
|
82813
82871
|
var name = void 0;
|
|
82814
|
-
if (
|
|
82815
|
-
name =
|
|
82872
|
+
if (expr.kind === 205 /* PropertyAccessExpression */) {
|
|
82873
|
+
name = expr.name.escapedText;
|
|
82816
82874
|
}
|
|
82817
82875
|
else {
|
|
82818
|
-
name = ts.escapeLeadingUnderscores(ts.cast(
|
|
82876
|
+
name = ts.escapeLeadingUnderscores(ts.cast(expr.argumentExpression, ts.isLiteralExpression).text);
|
|
82819
82877
|
}
|
|
82820
82878
|
return evaluateEnumMember(expr, type.symbol, name);
|
|
82821
82879
|
}
|
|
@@ -82843,6 +82901,10 @@ var ts;
|
|
|
82843
82901
|
}
|
|
82844
82902
|
}
|
|
82845
82903
|
function isConstantMemberAccess(node) {
|
|
82904
|
+
var type = getTypeOfExpression(node);
|
|
82905
|
+
if (type === errorType) {
|
|
82906
|
+
return false;
|
|
82907
|
+
}
|
|
82846
82908
|
return node.kind === 79 /* Identifier */ ||
|
|
82847
82909
|
node.kind === 205 /* PropertyAccessExpression */ && isConstantMemberAccess(node.expression) ||
|
|
82848
82910
|
node.kind === 206 /* ElementAccessExpression */ && isConstantMemberAccess(node.expression) &&
|
|
@@ -85666,7 +85728,7 @@ var ts;
|
|
|
85666
85728
|
if (quickResult !== undefined) {
|
|
85667
85729
|
return quickResult;
|
|
85668
85730
|
}
|
|
85669
|
-
var lastStatic, lastDeclare, lastAsync,
|
|
85731
|
+
var lastStatic, lastDeclare, lastAsync, lastOverride;
|
|
85670
85732
|
var flags = 0 /* None */;
|
|
85671
85733
|
for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
|
|
85672
85734
|
var modifier = _a[_i];
|
|
@@ -85770,7 +85832,6 @@ var ts;
|
|
|
85770
85832
|
return grammarErrorOnNode(modifier, ts.Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature);
|
|
85771
85833
|
}
|
|
85772
85834
|
flags |= 64 /* Readonly */;
|
|
85773
|
-
lastReadonly = modifier;
|
|
85774
85835
|
break;
|
|
85775
85836
|
case 93 /* ExportKeyword */:
|
|
85776
85837
|
if (flags & 1 /* Export */) {
|
|
@@ -85883,18 +85944,12 @@ var ts;
|
|
|
85883
85944
|
if (flags & 32 /* Static */) {
|
|
85884
85945
|
return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
|
|
85885
85946
|
}
|
|
85886
|
-
if (flags & 128 /* Abstract */) {
|
|
85887
|
-
return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); // TODO: GH#18217
|
|
85888
|
-
}
|
|
85889
85947
|
if (flags & 16384 /* Override */) {
|
|
85890
85948
|
return grammarErrorOnNode(lastOverride, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "override"); // TODO: GH#18217
|
|
85891
85949
|
}
|
|
85892
|
-
|
|
85950
|
+
if (flags & 256 /* Async */) {
|
|
85893
85951
|
return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
|
|
85894
85952
|
}
|
|
85895
|
-
else if (flags & 64 /* Readonly */) {
|
|
85896
|
-
return grammarErrorOnNode(lastReadonly, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly");
|
|
85897
|
-
}
|
|
85898
85953
|
return false;
|
|
85899
85954
|
}
|
|
85900
85955
|
else if ((node.kind === 265 /* ImportDeclaration */ || node.kind === 264 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) {
|
|
@@ -120035,7 +120090,7 @@ var ts;
|
|
|
120035
120090
|
if (!host.fileExists || !host.readFile) {
|
|
120036
120091
|
return undefined;
|
|
120037
120092
|
}
|
|
120038
|
-
var parts = getNodeModulePathParts(path);
|
|
120093
|
+
var parts = ts.getNodeModulePathParts(path);
|
|
120039
120094
|
if (!parts) {
|
|
120040
120095
|
return undefined;
|
|
120041
120096
|
}
|
|
@@ -120158,58 +120213,6 @@ var ts;
|
|
|
120158
120213
|
}
|
|
120159
120214
|
}
|
|
120160
120215
|
}
|
|
120161
|
-
function getNodeModulePathParts(fullPath) {
|
|
120162
|
-
// If fullPath can't be valid module file within node_modules, returns undefined.
|
|
120163
|
-
// Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
|
|
120164
|
-
// Returns indices: ^ ^ ^ ^
|
|
120165
|
-
var topLevelNodeModulesIndex = 0;
|
|
120166
|
-
var topLevelPackageNameIndex = 0;
|
|
120167
|
-
var packageRootIndex = 0;
|
|
120168
|
-
var fileNameIndex = 0;
|
|
120169
|
-
var States;
|
|
120170
|
-
(function (States) {
|
|
120171
|
-
States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
|
|
120172
|
-
States[States["NodeModules"] = 1] = "NodeModules";
|
|
120173
|
-
States[States["Scope"] = 2] = "Scope";
|
|
120174
|
-
States[States["PackageContent"] = 3] = "PackageContent";
|
|
120175
|
-
})(States || (States = {}));
|
|
120176
|
-
var partStart = 0;
|
|
120177
|
-
var partEnd = 0;
|
|
120178
|
-
var state = 0 /* BeforeNodeModules */;
|
|
120179
|
-
while (partEnd >= 0) {
|
|
120180
|
-
partStart = partEnd;
|
|
120181
|
-
partEnd = fullPath.indexOf("/", partStart + 1);
|
|
120182
|
-
switch (state) {
|
|
120183
|
-
case 0 /* BeforeNodeModules */:
|
|
120184
|
-
if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
|
|
120185
|
-
topLevelNodeModulesIndex = partStart;
|
|
120186
|
-
topLevelPackageNameIndex = partEnd;
|
|
120187
|
-
state = 1 /* NodeModules */;
|
|
120188
|
-
}
|
|
120189
|
-
break;
|
|
120190
|
-
case 1 /* NodeModules */:
|
|
120191
|
-
case 2 /* Scope */:
|
|
120192
|
-
if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
|
|
120193
|
-
state = 2 /* Scope */;
|
|
120194
|
-
}
|
|
120195
|
-
else {
|
|
120196
|
-
packageRootIndex = partEnd;
|
|
120197
|
-
state = 3 /* PackageContent */;
|
|
120198
|
-
}
|
|
120199
|
-
break;
|
|
120200
|
-
case 3 /* PackageContent */:
|
|
120201
|
-
if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
|
|
120202
|
-
state = 1 /* NodeModules */;
|
|
120203
|
-
}
|
|
120204
|
-
else {
|
|
120205
|
-
state = 3 /* PackageContent */;
|
|
120206
|
-
}
|
|
120207
|
-
break;
|
|
120208
|
-
}
|
|
120209
|
-
}
|
|
120210
|
-
fileNameIndex = partStart;
|
|
120211
|
-
return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
|
|
120212
|
-
}
|
|
120213
120216
|
function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
|
|
120214
120217
|
return ts.firstDefined(rootDirs, function (rootDir) {
|
|
120215
120218
|
var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
|
|
@@ -126556,11 +126559,11 @@ var ts;
|
|
|
126556
126559
|
return ts.isArray(valueOrArray) ? ts.first(valueOrArray) : valueOrArray;
|
|
126557
126560
|
}
|
|
126558
126561
|
ts.firstOrOnly = firstOrOnly;
|
|
126559
|
-
function getNameForExportedSymbol(symbol, scriptTarget) {
|
|
126562
|
+
function getNameForExportedSymbol(symbol, scriptTarget, preferCapitalized) {
|
|
126560
126563
|
if (!(symbol.flags & 33554432 /* Transient */) && (symbol.escapedName === "export=" /* ExportEquals */ || symbol.escapedName === "default" /* Default */)) {
|
|
126561
126564
|
// Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
|
|
126562
126565
|
return ts.firstDefined(symbol.declarations, function (d) { var _a; return ts.isExportAssignment(d) ? (_a = ts.tryCast(ts.skipOuterExpressions(d.expression), ts.isIdentifier)) === null || _a === void 0 ? void 0 : _a.text : undefined; })
|
|
126563
|
-
|| ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget);
|
|
126566
|
+
|| ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, !!preferCapitalized);
|
|
126564
126567
|
}
|
|
126565
126568
|
return symbol.name;
|
|
126566
126569
|
}
|
|
@@ -126679,6 +126682,17 @@ var ts;
|
|
|
126679
126682
|
var exportInfoId = 1;
|
|
126680
126683
|
var exportInfo = ts.createMultiMap();
|
|
126681
126684
|
var symbols = new ts.Map();
|
|
126685
|
+
/**
|
|
126686
|
+
* Key: node_modules package name (no @types).
|
|
126687
|
+
* Value: path to deepest node_modules folder seen that is
|
|
126688
|
+
* both visible to `usableByFileName` and contains the package.
|
|
126689
|
+
*
|
|
126690
|
+
* Later, we can see if a given SymbolExportInfo is shadowed by
|
|
126691
|
+
* a another installation of the same package in a deeper
|
|
126692
|
+
* node_modules folder by seeing if its path starts with the
|
|
126693
|
+
* value stored here.
|
|
126694
|
+
*/
|
|
126695
|
+
var packages = new ts.Map();
|
|
126682
126696
|
var usableByFileName;
|
|
126683
126697
|
var cache = {
|
|
126684
126698
|
isUsableByFile: function (importingFile) { return importingFile === usableByFileName; },
|
|
@@ -126688,11 +126702,32 @@ var ts;
|
|
|
126688
126702
|
symbols.clear();
|
|
126689
126703
|
usableByFileName = undefined;
|
|
126690
126704
|
},
|
|
126691
|
-
add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson,
|
|
126705
|
+
add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson, checker) {
|
|
126692
126706
|
if (importingFile !== usableByFileName) {
|
|
126693
126707
|
cache.clear();
|
|
126694
126708
|
usableByFileName = importingFile;
|
|
126695
126709
|
}
|
|
126710
|
+
var packageName;
|
|
126711
|
+
if (moduleFile) {
|
|
126712
|
+
var nodeModulesPathParts = ts.getNodeModulePathParts(moduleFile.fileName);
|
|
126713
|
+
if (nodeModulesPathParts) {
|
|
126714
|
+
var topLevelNodeModulesIndex = nodeModulesPathParts.topLevelNodeModulesIndex, topLevelPackageNameIndex = nodeModulesPathParts.topLevelPackageNameIndex, packageRootIndex = nodeModulesPathParts.packageRootIndex;
|
|
126715
|
+
packageName = ts.unmangleScopedPackageName(ts.getPackageNameFromTypesPackageName(moduleFile.fileName.substring(topLevelPackageNameIndex + 1, packageRootIndex)));
|
|
126716
|
+
if (ts.startsWith(importingFile, moduleFile.path.substring(0, topLevelNodeModulesIndex))) {
|
|
126717
|
+
var prevDeepestNodeModulesPath = packages.get(packageName);
|
|
126718
|
+
var nodeModulesPath = moduleFile.fileName.substring(0, topLevelPackageNameIndex);
|
|
126719
|
+
if (prevDeepestNodeModulesPath) {
|
|
126720
|
+
var prevDeepestNodeModulesIndex = prevDeepestNodeModulesPath.indexOf(ts.nodeModulesPathPart);
|
|
126721
|
+
if (topLevelNodeModulesIndex > prevDeepestNodeModulesIndex) {
|
|
126722
|
+
packages.set(packageName, nodeModulesPath);
|
|
126723
|
+
}
|
|
126724
|
+
}
|
|
126725
|
+
else {
|
|
126726
|
+
packages.set(packageName, nodeModulesPath);
|
|
126727
|
+
}
|
|
126728
|
+
}
|
|
126729
|
+
}
|
|
126730
|
+
}
|
|
126696
126731
|
var isDefault = exportKind === 1 /* Default */;
|
|
126697
126732
|
var namedSymbol = isDefault && ts.getLocalSymbolForExportDefault(symbol) || symbol;
|
|
126698
126733
|
// 1. A named export must be imported by its key in `moduleSymbol.exports` or `moduleSymbol.members`.
|
|
@@ -126704,7 +126739,7 @@ var ts;
|
|
|
126704
126739
|
// get a better name.
|
|
126705
126740
|
var importedName = exportKind === 0 /* Named */ || ts.isExternalModuleSymbol(namedSymbol)
|
|
126706
126741
|
? ts.unescapeLeadingUnderscores(symbolTableKey)
|
|
126707
|
-
: ts.getNameForExportedSymbol(namedSymbol, scriptTarget);
|
|
126742
|
+
: ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined);
|
|
126708
126743
|
var moduleName = ts.stripQuotes(moduleSymbol.name);
|
|
126709
126744
|
var id = exportInfoId++;
|
|
126710
126745
|
var target = ts.skipAlias(symbol, checker);
|
|
@@ -126719,6 +126754,7 @@ var ts;
|
|
|
126719
126754
|
moduleName: moduleName,
|
|
126720
126755
|
moduleFile: moduleFile,
|
|
126721
126756
|
moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName,
|
|
126757
|
+
packageName: packageName,
|
|
126722
126758
|
exportKind: exportKind,
|
|
126723
126759
|
targetFlags: target.flags,
|
|
126724
126760
|
isFromPackageJson: isFromPackageJson,
|
|
@@ -126737,7 +126773,17 @@ var ts;
|
|
|
126737
126773
|
return;
|
|
126738
126774
|
exportInfo.forEach(function (info, key) {
|
|
126739
126775
|
var _a = parseKey(key), symbolName = _a.symbolName, ambientModuleName = _a.ambientModuleName;
|
|
126740
|
-
|
|
126776
|
+
var rehydrated = info.map(rehydrateCachedInfo);
|
|
126777
|
+
var filtered = rehydrated.filter(function (r, i) { return isNotShadowedByDeeperNodeModulesPackage(r, info[i].packageName); });
|
|
126778
|
+
if (filtered.length) {
|
|
126779
|
+
action(filtered, function (preferCapitalized) {
|
|
126780
|
+
var _a = rehydrated[0], symbol = _a.symbol, exportKind = _a.exportKind;
|
|
126781
|
+
var namedSymbol = exportKind === 1 /* Default */ && ts.getLocalSymbolForExportDefault(symbol) || symbol;
|
|
126782
|
+
return preferCapitalized
|
|
126783
|
+
? ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined, /*preferCapitalized*/ true)
|
|
126784
|
+
: symbolName;
|
|
126785
|
+
}, !!ambientModuleName, key);
|
|
126786
|
+
}
|
|
126741
126787
|
});
|
|
126742
126788
|
},
|
|
126743
126789
|
releaseSymbols: function () {
|
|
@@ -126837,6 +126883,12 @@ var ts;
|
|
|
126837
126883
|
}
|
|
126838
126884
|
return true;
|
|
126839
126885
|
}
|
|
126886
|
+
function isNotShadowedByDeeperNodeModulesPackage(info, packageName) {
|
|
126887
|
+
if (!packageName || !info.moduleFileName)
|
|
126888
|
+
return true;
|
|
126889
|
+
var packageDeepestNodeModulesPath = packages.get(packageName);
|
|
126890
|
+
return !packageDeepestNodeModulesPath || ts.startsWith(info.moduleFileName, packageDeepestNodeModulesPath);
|
|
126891
|
+
}
|
|
126840
126892
|
}
|
|
126841
126893
|
ts.createCacheableExportInfoMap = createCacheableExportInfoMap;
|
|
126842
126894
|
function isImportableFile(program, from, to, preferences, packageJsonFilter, moduleSpecifierResolutionHost, moduleSpecifierCache) {
|
|
@@ -126919,7 +126971,6 @@ var ts;
|
|
|
126919
126971
|
}
|
|
126920
126972
|
(_d = host.log) === null || _d === void 0 ? void 0 : _d.call(host, "getExportInfoMap: cache miss or empty; calculating new results");
|
|
126921
126973
|
var compilerOptions = program.getCompilerOptions();
|
|
126922
|
-
var scriptTarget = ts.getEmitScriptTarget(compilerOptions);
|
|
126923
126974
|
var moduleCount = 0;
|
|
126924
126975
|
forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
|
|
126925
126976
|
if (++moduleCount % 100 === 0)
|
|
@@ -126930,11 +126981,11 @@ var ts;
|
|
|
126930
126981
|
// Note: I think we shouldn't actually see resolved module symbols here, but weird merges
|
|
126931
126982
|
// can cause it to happen: see 'completionsImport_mergedReExport.ts'
|
|
126932
126983
|
if (defaultInfo && isImportableSymbol(defaultInfo.symbol, checker)) {
|
|
126933
|
-
cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson,
|
|
126984
|
+
cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, checker);
|
|
126934
126985
|
}
|
|
126935
126986
|
checker.forEachExportAndPropertyOfModule(moduleSymbol, function (exported, key) {
|
|
126936
126987
|
if (exported !== (defaultInfo === null || defaultInfo === void 0 ? void 0 : defaultInfo.symbol) && isImportableSymbol(exported, checker) && ts.addToSeen(seenExports, key)) {
|
|
126937
|
-
cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson,
|
|
126988
|
+
cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, checker);
|
|
126938
126989
|
}
|
|
126939
126990
|
});
|
|
126940
126991
|
});
|
|
@@ -129008,6 +129059,8 @@ var ts;
|
|
|
129008
129059
|
CompletionSource["ThisProperty"] = "ThisProperty/";
|
|
129009
129060
|
/** Auto-import that comes attached to a class member snippet */
|
|
129010
129061
|
CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
|
|
129062
|
+
/** A type-only import that needs to be promoted in order to be used at the completion location */
|
|
129063
|
+
CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
|
|
129011
129064
|
})(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
|
|
129012
129065
|
var SymbolOriginInfoKind;
|
|
129013
129066
|
(function (SymbolOriginInfoKind) {
|
|
@@ -129017,6 +129070,7 @@ var ts;
|
|
|
129017
129070
|
SymbolOriginInfoKind[SymbolOriginInfoKind["Promise"] = 8] = "Promise";
|
|
129018
129071
|
SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
|
|
129019
129072
|
SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
|
|
129073
|
+
SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
|
|
129020
129074
|
SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
|
|
129021
129075
|
SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
|
|
129022
129076
|
})(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
|
|
@@ -129044,6 +129098,9 @@ var ts;
|
|
|
129044
129098
|
function originIsNullableMember(origin) {
|
|
129045
129099
|
return !!(origin.kind & 16 /* Nullable */);
|
|
129046
129100
|
}
|
|
129101
|
+
function originIsTypeOnlyAlias(origin) {
|
|
129102
|
+
return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
|
|
129103
|
+
}
|
|
129047
129104
|
var KeywordCompletionFilters;
|
|
129048
129105
|
(function (KeywordCompletionFilters) {
|
|
129049
129106
|
KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
|
|
@@ -129142,7 +129199,7 @@ var ts;
|
|
|
129142
129199
|
}
|
|
129143
129200
|
switch (completionData.kind) {
|
|
129144
129201
|
case 0 /* Data */:
|
|
129145
|
-
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
|
|
129202
|
+
var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position);
|
|
129146
129203
|
if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
|
|
129147
129204
|
incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
|
|
129148
129205
|
}
|
|
@@ -129262,7 +129319,7 @@ var ts;
|
|
|
129262
129319
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
129263
129320
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
129264
129321
|
}
|
|
129265
|
-
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
|
|
129322
|
+
function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position) {
|
|
129266
129323
|
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, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
129267
129324
|
// Verify if the file is JSX language variant
|
|
129268
129325
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
@@ -129275,7 +129332,7 @@ var ts;
|
|
|
129275
129332
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
129276
129333
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
129277
129334
|
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
129278
|
-
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
|
|
129335
|
+
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
|
|
129279
129336
|
}
|
|
129280
129337
|
else {
|
|
129281
129338
|
if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === 0 /* None */) {
|
|
@@ -129285,16 +129342,23 @@ var ts;
|
|
|
129285
129342
|
/*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
|
|
129286
129343
|
}
|
|
129287
129344
|
if (keywordFilters !== 0 /* None */) {
|
|
129288
|
-
var
|
|
129345
|
+
var entryNames_1 = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
129289
129346
|
for (var _i = 0, _a = getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile)); _i < _a.length; _i++) {
|
|
129290
129347
|
var keywordEntry = _a[_i];
|
|
129291
|
-
if (!
|
|
129348
|
+
if (!entryNames_1.has(keywordEntry.name)) {
|
|
129292
129349
|
ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
|
|
129293
129350
|
}
|
|
129294
129351
|
}
|
|
129295
129352
|
}
|
|
129296
|
-
|
|
129297
|
-
|
|
129353
|
+
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
129354
|
+
for (var _b = 0, _c = getContextualKeywords(contextToken, position); _b < _c.length; _b++) {
|
|
129355
|
+
var keywordEntry = _c[_b];
|
|
129356
|
+
if (!entryNames.has(keywordEntry.name)) {
|
|
129357
|
+
ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
|
|
129358
|
+
}
|
|
129359
|
+
}
|
|
129360
|
+
for (var _d = 0, literals_1 = literals; _d < literals_1.length; _d++) {
|
|
129361
|
+
var literal = literals_1[_d];
|
|
129298
129362
|
ts.insertSorted(entries, createCompletionEntryForLiteral(sourceFile, preferences, literal), compareCompletionEntries, /*allowDuplicates*/ true);
|
|
129299
129363
|
}
|
|
129300
129364
|
return {
|
|
@@ -129448,6 +129512,9 @@ var ts;
|
|
|
129448
129512
|
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
|
|
129449
129513
|
}
|
|
129450
129514
|
}
|
|
129515
|
+
if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
|
|
129516
|
+
hasAction = true;
|
|
129517
|
+
}
|
|
129451
129518
|
if (preferences.includeCompletionsWithClassMemberSnippets &&
|
|
129452
129519
|
preferences.includeCompletionsWithInsertText &&
|
|
129453
129520
|
completionKind === 3 /* MemberLike */ &&
|
|
@@ -129792,6 +129859,9 @@ var ts;
|
|
|
129792
129859
|
if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 1 /* ThisType */) {
|
|
129793
129860
|
return CompletionSource.ThisProperty;
|
|
129794
129861
|
}
|
|
129862
|
+
if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
|
|
129863
|
+
return CompletionSource.TypeOnlyAlias;
|
|
129864
|
+
}
|
|
129795
129865
|
}
|
|
129796
129866
|
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
|
|
129797
129867
|
var _a;
|
|
@@ -129819,7 +129889,7 @@ var ts;
|
|
|
129819
129889
|
continue;
|
|
129820
129890
|
}
|
|
129821
129891
|
/** True for locals; false for globals, module exports from other files, `this.` completions. */
|
|
129822
|
-
var shouldShadowLaterSymbols = !origin && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
|
|
129892
|
+
var shouldShadowLaterSymbols = (!origin || originIsTypeOnlyAlias(origin)) && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
|
|
129823
129893
|
uniques.set(name, shouldShadowLaterSymbols);
|
|
129824
129894
|
ts.insertSorted(entries, entry, compareCompletionEntries, /*allowDuplicates*/ true);
|
|
129825
129895
|
}
|
|
@@ -129832,6 +129902,7 @@ var ts;
|
|
|
129832
129902
|
add: function (name) { return uniques.set(name, true); },
|
|
129833
129903
|
};
|
|
129834
129904
|
function shouldIncludeSymbol(symbol, symbolToSortTextIdMap) {
|
|
129905
|
+
var allFlags = symbol.flags;
|
|
129835
129906
|
if (!ts.isSourceFile(location)) {
|
|
129836
129907
|
// export = /**/ here we want to get all meanings, so any symbol is ok
|
|
129837
129908
|
if (ts.isExportAssignment(location.parent)) {
|
|
@@ -129857,11 +129928,10 @@ var ts;
|
|
|
129857
129928
|
|| symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 11 /* LocationPriority */)) {
|
|
129858
129929
|
return false;
|
|
129859
129930
|
}
|
|
129860
|
-
|
|
129861
|
-
symbol = symbolOrigin;
|
|
129931
|
+
allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
|
|
129862
129932
|
// import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
|
|
129863
129933
|
if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) {
|
|
129864
|
-
return !!(
|
|
129934
|
+
return !!(allFlags & 1920 /* Namespace */);
|
|
129865
129935
|
}
|
|
129866
129936
|
if (isTypeOnlyLocation) {
|
|
129867
129937
|
// It's a type, but you can reach it by namespace.type as well
|
|
@@ -129869,7 +129939,7 @@ var ts;
|
|
|
129869
129939
|
}
|
|
129870
129940
|
}
|
|
129871
129941
|
// expressions are value space (which includes the value namespaces)
|
|
129872
|
-
return !!(
|
|
129942
|
+
return !!(allFlags & 111551 /* Value */);
|
|
129873
129943
|
}
|
|
129874
129944
|
}
|
|
129875
129945
|
Completions.getCompletionEntriesFromSymbols = getCompletionEntriesFromSymbols;
|
|
@@ -130003,8 +130073,7 @@ var ts;
|
|
|
130003
130073
|
Completions.createCompletionDetails = createCompletionDetails;
|
|
130004
130074
|
function getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source) {
|
|
130005
130075
|
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
|
|
130006
|
-
|
|
130007
|
-
if (previousToken_2 && getImportStatementCompletionInfo(contextToken_3 || previousToken_2).replacementNode) {
|
|
130076
|
+
if (previousToken && getImportStatementCompletionInfo(contextToken || previousToken).replacementNode) {
|
|
130008
130077
|
// Import statement completion: 'import c|'
|
|
130009
130078
|
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
|
|
130010
130079
|
}
|
|
@@ -130022,13 +130091,19 @@ var ts;
|
|
|
130022
130091
|
};
|
|
130023
130092
|
}
|
|
130024
130093
|
}
|
|
130094
|
+
if (originIsTypeOnlyAlias(origin)) {
|
|
130095
|
+
var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
|
|
130096
|
+
ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
|
|
130097
|
+
return { codeActions: [codeAction_1], sourceDisplay: undefined };
|
|
130098
|
+
}
|
|
130025
130099
|
if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
|
|
130026
130100
|
return { codeActions: undefined, sourceDisplay: undefined };
|
|
130027
130101
|
}
|
|
130028
130102
|
var checker = origin.isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker();
|
|
130029
130103
|
var moduleSymbol = origin.moduleSymbol;
|
|
130030
130104
|
var targetSymbol = checker.getMergedSymbol(ts.skipAlias(symbol.exportSymbol || symbol, checker));
|
|
130031
|
-
var
|
|
130105
|
+
var isJsxOpeningTagName = (contextToken === null || contextToken === void 0 ? void 0 : contextToken.kind) === 29 /* LessThanToken */ && ts.isJsxOpeningLikeElement(contextToken.parent);
|
|
130106
|
+
var _a = ts.codefix.getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, ts.getNameForExportedSymbol(symbol, ts.getEmitScriptTarget(compilerOptions), isJsxOpeningTagName), isJsxOpeningTagName, host, program, formatContext, previousToken && ts.isIdentifier(previousToken) ? previousToken.getStart(sourceFile) : position, preferences), moduleSpecifier = _a.moduleSpecifier, codeAction = _a.codeAction;
|
|
130032
130107
|
ts.Debug.assert(!(data === null || data === void 0 ? void 0 : data.moduleSpecifier) || moduleSpecifier === data.moduleSpecifier);
|
|
130033
130108
|
return { sourceDisplay: [ts.textPart(moduleSpecifier)], codeActions: [codeAction] };
|
|
130034
130109
|
}
|
|
@@ -130698,21 +130773,29 @@ var ts;
|
|
|
130698
130773
|
var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
|
|
130699
130774
|
isInSnippetScope = isSnippetScope(scopeNode);
|
|
130700
130775
|
var symbolMeanings = (isTypeOnlyLocation ? 0 /* None */ : 111551 /* Value */) | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */;
|
|
130776
|
+
var typeOnlyAliasNeedsPromotion = previousToken && !ts.isValidTypeOnlyAliasUseSite(previousToken);
|
|
130701
130777
|
symbols = ts.concatenate(symbols, typeChecker.getSymbolsInScope(scopeNode, symbolMeanings));
|
|
130702
130778
|
ts.Debug.assertEachIsDefined(symbols, "getSymbolsInScope() should all be defined");
|
|
130703
|
-
for (var
|
|
130704
|
-
var symbol =
|
|
130779
|
+
for (var i = 0; i < symbols.length; i++) {
|
|
130780
|
+
var symbol = symbols[i];
|
|
130705
130781
|
if (!typeChecker.isArgumentsSymbol(symbol) &&
|
|
130706
130782
|
!ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
|
|
130707
130783
|
symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 15 /* GlobalsOrKeywords */;
|
|
130708
130784
|
}
|
|
130785
|
+
if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
|
|
130786
|
+
var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
|
|
130787
|
+
if (typeOnlyAliasDeclaration) {
|
|
130788
|
+
var origin = { kind: 64 /* TypeOnlyAlias */, declaration: typeOnlyAliasDeclaration };
|
|
130789
|
+
symbolToOriginInfoMap[i] = origin;
|
|
130790
|
+
}
|
|
130791
|
+
}
|
|
130709
130792
|
}
|
|
130710
130793
|
// Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
|
|
130711
130794
|
if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 303 /* SourceFile */) {
|
|
130712
130795
|
var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
|
|
130713
130796
|
if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
|
|
130714
|
-
for (var
|
|
130715
|
-
var symbol =
|
|
130797
|
+
for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
|
|
130798
|
+
var symbol = _a[_i];
|
|
130716
130799
|
symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
|
|
130717
130800
|
symbols.push(symbol);
|
|
130718
130801
|
symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 14 /* SuggestedClassMembers */;
|
|
@@ -130815,7 +130898,8 @@ var ts;
|
|
|
130815
130898
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
130816
130899
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
130817
130900
|
resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
|
|
130818
|
-
exportInfo.forEach(sourceFile.path, function (info,
|
|
130901
|
+
exportInfo.forEach(sourceFile.path, function (info, getSymbolName, isFromAmbientModule, exportMapKey) {
|
|
130902
|
+
var symbolName = getSymbolName(/*preferCapitalized*/ isRightOfOpenTag);
|
|
130819
130903
|
if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
|
|
130820
130904
|
return;
|
|
130821
130905
|
if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
|
|
@@ -130825,6 +130909,10 @@ var ts;
|
|
|
130825
130909
|
return;
|
|
130826
130910
|
if (isTypeOnlyLocation && !(info[0].targetFlags & (1536 /* Module */ | 788968 /* Type */)))
|
|
130827
130911
|
return;
|
|
130912
|
+
// Do not try to auto-import something with a lowercase first letter for a JSX tag
|
|
130913
|
+
var firstChar = symbolName.charCodeAt(0);
|
|
130914
|
+
if (isRightOfOpenTag && (firstChar < 65 /* A */ || firstChar > 90 /* Z */))
|
|
130915
|
+
return;
|
|
130828
130916
|
var isCompletionDetailsMatch = detailsEntryId && ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); });
|
|
130829
130917
|
if (isCompletionDetailsMatch || !detailsEntryId && charactersFuzzyMatchInString(symbolName, lowerCaseTokenText)) {
|
|
130830
130918
|
var defaultExportInfo = ts.find(info, isImportableExportInfo);
|
|
@@ -130901,16 +130989,19 @@ var ts;
|
|
|
130901
130989
|
return true;
|
|
130902
130990
|
}
|
|
130903
130991
|
if (contextToken.kind === 31 /* GreaterThanToken */ && contextToken.parent) {
|
|
130992
|
+
// <Component<string> /**/ />
|
|
130993
|
+
// <Component<string> /**/ ><Component>
|
|
130994
|
+
// - contextToken: GreaterThanToken (before cursor)
|
|
130995
|
+
// - location: JsxSelfClosingElement or JsxOpeningElement
|
|
130996
|
+
// - contextToken.parent === location
|
|
130997
|
+
if (location === contextToken.parent && (location.kind === 279 /* JsxOpeningElement */ || location.kind === 278 /* JsxSelfClosingElement */)) {
|
|
130998
|
+
return false;
|
|
130999
|
+
}
|
|
130904
131000
|
if (contextToken.parent.kind === 279 /* JsxOpeningElement */) {
|
|
130905
|
-
//
|
|
130906
|
-
//
|
|
130907
|
-
//
|
|
130908
|
-
//
|
|
130909
|
-
// - different parents (JSXOpeningElement, JSXElement)
|
|
130910
|
-
// 2. <Component<string> /**/>
|
|
130911
|
-
// - contextToken: GreaterThanToken (before cursor)
|
|
130912
|
-
// - location: GreaterThanToken (after cursor)
|
|
130913
|
-
// - same parent (JSXOpeningElement)
|
|
131001
|
+
// <div>/**/
|
|
131002
|
+
// - contextToken: GreaterThanToken (before cursor)
|
|
131003
|
+
// - location: JSXElement
|
|
131004
|
+
// - different parents (JSXOpeningElement, JSXElement)
|
|
130914
131005
|
return location.parent.kind !== 279 /* JsxOpeningElement */;
|
|
130915
131006
|
}
|
|
130916
131007
|
if (contextToken.parent.kind === 280 /* JsxClosingElement */ || contextToken.parent.kind === 278 /* JsxSelfClosingElement */) {
|
|
@@ -131817,6 +131908,34 @@ var ts;
|
|
|
131817
131908
|
function keywordForNode(node) {
|
|
131818
131909
|
return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* Unknown */ : node.kind;
|
|
131819
131910
|
}
|
|
131911
|
+
function getContextualKeywords(contextToken, position) {
|
|
131912
|
+
var entries = [];
|
|
131913
|
+
/**
|
|
131914
|
+
* An `AssertClause` can come after an import declaration:
|
|
131915
|
+
* import * from "foo" |
|
|
131916
|
+
* import "foo" |
|
|
131917
|
+
* or after a re-export declaration that has a module specifier:
|
|
131918
|
+
* export { foo } from "foo" |
|
|
131919
|
+
* Source: https://tc39.es/proposal-import-assertions/
|
|
131920
|
+
*/
|
|
131921
|
+
if (contextToken) {
|
|
131922
|
+
var file = contextToken.getSourceFile();
|
|
131923
|
+
var parent = contextToken.parent;
|
|
131924
|
+
var tokenLine = file.getLineAndCharacterOfPosition(contextToken.end).line;
|
|
131925
|
+
var currentLine = file.getLineAndCharacterOfPosition(position).line;
|
|
131926
|
+
if ((ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent) && parent.moduleSpecifier)
|
|
131927
|
+
&& contextToken === parent.moduleSpecifier
|
|
131928
|
+
&& tokenLine === currentLine) {
|
|
131929
|
+
entries.push({
|
|
131930
|
+
name: ts.tokenToString(129 /* AssertKeyword */),
|
|
131931
|
+
kind: "keyword" /* keyword */,
|
|
131932
|
+
kindModifiers: "" /* none */,
|
|
131933
|
+
sortText: SortText.GlobalsOrKeywords,
|
|
131934
|
+
});
|
|
131935
|
+
}
|
|
131936
|
+
}
|
|
131937
|
+
return entries;
|
|
131938
|
+
}
|
|
131820
131939
|
/** Get the corresponding JSDocTag node if the position is in a jsDoc comment */
|
|
131821
131940
|
function getJsDocTagAtPosition(node, position) {
|
|
131822
131941
|
return ts.findAncestor(node, function (n) {
|
|
@@ -132111,10 +132230,14 @@ var ts;
|
|
|
132111
132230
|
/** True if symbol is a type or a module containing at least one type. */
|
|
132112
132231
|
function symbolCanBeReferencedAtTypeLocation(symbol, checker, seenModules) {
|
|
132113
132232
|
if (seenModules === void 0) { seenModules = new ts.Map(); }
|
|
132114
|
-
|
|
132115
|
-
|
|
132116
|
-
|
|
132117
|
-
|
|
132233
|
+
// Since an alias can be merged with a local declaration, we need to test both the alias and its target.
|
|
132234
|
+
// This code used to just test the result of `skipAlias`, but that would ignore any locally introduced meanings.
|
|
132235
|
+
return nonAliasCanBeReferencedAtTypeLocation(symbol) || nonAliasCanBeReferencedAtTypeLocation(ts.skipAlias(symbol.exportSymbol || symbol, checker));
|
|
132236
|
+
function nonAliasCanBeReferencedAtTypeLocation(symbol) {
|
|
132237
|
+
return !!(symbol.flags & 788968 /* Type */) || checker.isUnknownSymbol(symbol) ||
|
|
132238
|
+
!!(symbol.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(symbol)) &&
|
|
132239
|
+
checker.getExportsOfModule(symbol).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
|
|
132240
|
+
}
|
|
132118
132241
|
}
|
|
132119
132242
|
function isDeprecated(symbol, checker) {
|
|
132120
132243
|
var declarations = ts.skipAlias(symbol, checker).declarations;
|
|
@@ -134368,8 +134491,8 @@ var ts;
|
|
|
134368
134491
|
var sourceId = ts.getNodeId(sourceFile);
|
|
134369
134492
|
var seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = new ts.Set());
|
|
134370
134493
|
var anyNewSymbols = false;
|
|
134371
|
-
for (var _i = 0,
|
|
134372
|
-
var sym =
|
|
134494
|
+
for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
|
|
134495
|
+
var sym = symbols_1[_i];
|
|
134373
134496
|
anyNewSymbols = ts.tryAddToSet(seenSymbols, ts.getSymbolId(sym)) || anyNewSymbols;
|
|
134374
134497
|
}
|
|
134375
134498
|
return anyNewSymbols;
|
|
@@ -145240,6 +145363,7 @@ var ts;
|
|
|
145240
145363
|
ChangeTracker.prototype.delete = function (sourceFile, node) {
|
|
145241
145364
|
this.deletedNodes.push({ sourceFile: sourceFile, node: node });
|
|
145242
145365
|
};
|
|
145366
|
+
/** Stop! Consider using `delete` instead, which has logic for deleting nodes from delimited lists. */
|
|
145243
145367
|
ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) {
|
|
145244
145368
|
if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; }
|
|
145245
145369
|
this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
|
|
@@ -145643,6 +145767,15 @@ var ts;
|
|
|
145643
145767
|
ChangeTracker.prototype.insertExportModifier = function (sourceFile, node) {
|
|
145644
145768
|
this.insertText(sourceFile, node.getStart(sourceFile), "export ");
|
|
145645
145769
|
};
|
|
145770
|
+
ChangeTracker.prototype.insertImportSpecifierAtIndex = function (sourceFile, importSpecifier, namedImports, index) {
|
|
145771
|
+
var prevSpecifier = namedImports.elements[index - 1];
|
|
145772
|
+
if (prevSpecifier) {
|
|
145773
|
+
this.insertNodeInListAfter(sourceFile, prevSpecifier, importSpecifier);
|
|
145774
|
+
}
|
|
145775
|
+
else {
|
|
145776
|
+
this.insertNodeBefore(sourceFile, namedImports.elements[0], importSpecifier, !ts.positionsAreOnSameLine(namedImports.elements[0].getStart(), namedImports.parent.parent.getStart(), sourceFile));
|
|
145777
|
+
}
|
|
145778
|
+
};
|
|
145646
145779
|
/**
|
|
145647
145780
|
* This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
|
|
145648
145781
|
* i.e. arguments in arguments lists, parameters in parameter lists etc.
|
|
@@ -149145,7 +149278,8 @@ var ts;
|
|
|
149145
149278
|
ts.Diagnostics.Cannot_find_namespace_0.code,
|
|
149146
149279
|
ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code,
|
|
149147
149280
|
ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code,
|
|
149148
|
-
ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
|
|
149281
|
+
ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code,
|
|
149282
|
+
ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code,
|
|
149149
149283
|
];
|
|
149150
149284
|
codefix.registerCodeFix({
|
|
149151
149285
|
errorCodes: errorCodes,
|
|
@@ -149154,9 +149288,10 @@ var ts;
|
|
|
149154
149288
|
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
|
149155
149289
|
if (!info)
|
|
149156
149290
|
return undefined;
|
|
149157
|
-
var fixes = info.fixes, symbolName = info.symbolName;
|
|
149291
|
+
var fixes = info.fixes, symbolName = info.symbolName, errorIdentifierText = info.errorIdentifierText;
|
|
149158
149292
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
149159
|
-
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix,
|
|
149293
|
+
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix,
|
|
149294
|
+
/*includeSymbolNameInDescription*/ symbolName !== errorIdentifierText, quotePreference, program.getCompilerOptions()); });
|
|
149160
149295
|
},
|
|
149161
149296
|
fixIds: [importFixId],
|
|
149162
149297
|
getAllCodeActions: function (context) {
|
|
@@ -149191,11 +149326,11 @@ var ts;
|
|
|
149191
149326
|
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
|
|
149192
149327
|
var checker = program.getTypeChecker();
|
|
149193
149328
|
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
|
|
149194
|
-
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
|
|
149329
|
+
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
|
|
149195
149330
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
149196
149331
|
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
149197
149332
|
if (fix) {
|
|
149198
|
-
addImport({ fixes: [fix], symbolName: symbolName });
|
|
149333
|
+
addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
|
|
149199
149334
|
}
|
|
149200
149335
|
}
|
|
149201
149336
|
function addImport(info) {
|
|
@@ -149250,6 +149385,9 @@ var ts;
|
|
|
149250
149385
|
}
|
|
149251
149386
|
break;
|
|
149252
149387
|
}
|
|
149388
|
+
case 4 /* PromoteTypeOnly */:
|
|
149389
|
+
// Excluding from fix-all
|
|
149390
|
+
break;
|
|
149253
149391
|
default:
|
|
149254
149392
|
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
|
|
149255
149393
|
}
|
|
@@ -149341,6 +149479,7 @@ var ts;
|
|
|
149341
149479
|
ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
|
|
149342
149480
|
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
|
|
149343
149481
|
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
|
|
149482
|
+
ImportFixKind[ImportFixKind["PromoteTypeOnly"] = 4] = "PromoteTypeOnly";
|
|
149344
149483
|
})(ImportFixKind || (ImportFixKind = {}));
|
|
149345
149484
|
// These should not be combined as bitflags, but are given powers of 2 values to
|
|
149346
149485
|
// easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
|
|
@@ -149352,20 +149491,29 @@ var ts;
|
|
|
149352
149491
|
AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
|
|
149353
149492
|
AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
|
|
149354
149493
|
})(AddAsTypeOnly || (AddAsTypeOnly = {}));
|
|
149355
|
-
function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
|
|
149494
|
+
function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, isJsxTagName, host, program, formatContext, position, preferences) {
|
|
149356
149495
|
var compilerOptions = program.getCompilerOptions();
|
|
149357
149496
|
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
|
|
149358
149497
|
? [getSymbolExportInfoForSymbol(targetSymbol, moduleSymbol, program, host)]
|
|
149359
|
-
: getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
149498
|
+
: getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
149360
149499
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
149361
149500
|
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
149362
149501
|
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
|
|
149363
149502
|
return {
|
|
149364
149503
|
moduleSpecifier: fix.moduleSpecifier,
|
|
149365
|
-
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
|
|
149504
|
+
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
|
|
149505
|
+
/*includeSymbolNameInDescription*/ false, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
|
|
149366
149506
|
};
|
|
149367
149507
|
}
|
|
149368
149508
|
codefix.getImportCompletionAction = getImportCompletionAction;
|
|
149509
|
+
function getPromoteTypeOnlyCompletionAction(sourceFile, symbolToken, program, host, formatContext, preferences) {
|
|
149510
|
+
var compilerOptions = program.getCompilerOptions();
|
|
149511
|
+
var symbolName = getSymbolName(sourceFile, program.getTypeChecker(), symbolToken, compilerOptions);
|
|
149512
|
+
var fix = getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program);
|
|
149513
|
+
var includeSymbolNameInDescription = symbolName !== symbolToken.text;
|
|
149514
|
+
return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
|
|
149515
|
+
}
|
|
149516
|
+
codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
|
|
149369
149517
|
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
149370
149518
|
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
|
|
149371
149519
|
var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
@@ -149395,7 +149543,7 @@ var ts;
|
|
|
149395
149543
|
}
|
|
149396
149544
|
}
|
|
149397
149545
|
}
|
|
149398
|
-
function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, host, program, preferences, useAutoImportProvider) {
|
|
149546
|
+
function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, isJsxTagName, host, program, preferences, useAutoImportProvider) {
|
|
149399
149547
|
var result = [];
|
|
149400
149548
|
var compilerOptions = program.getCompilerOptions();
|
|
149401
149549
|
var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
|
|
@@ -149408,7 +149556,7 @@ var ts;
|
|
|
149408
149556
|
return;
|
|
149409
149557
|
}
|
|
149410
149558
|
var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
|
|
149411
|
-
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
|
|
149559
|
+
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
|
|
149412
149560
|
result.push({ symbol: defaultInfo.symbol, moduleSymbol: moduleSymbol, moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName, exportKind: defaultInfo.exportKind, targetFlags: ts.skipAlias(defaultInfo.symbol, checker).flags, isFromPackageJson: isFromPackageJson });
|
|
149413
149561
|
}
|
|
149414
149562
|
for (var _i = 0, _a = checker.getExportsAndPropertiesOfModule(moduleSymbol); _i < _a.length; _i++) {
|
|
@@ -149646,9 +149794,21 @@ var ts;
|
|
|
149646
149794
|
}
|
|
149647
149795
|
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
|
|
149648
149796
|
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
|
|
149649
|
-
var info
|
|
149650
|
-
|
|
149651
|
-
|
|
149797
|
+
var info;
|
|
149798
|
+
if (errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) {
|
|
149799
|
+
info = getFixesInfoForUMDImport(context, symbolToken);
|
|
149800
|
+
}
|
|
149801
|
+
else if (!ts.isIdentifier(symbolToken)) {
|
|
149802
|
+
return undefined;
|
|
149803
|
+
}
|
|
149804
|
+
else if (errorCode === ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code) {
|
|
149805
|
+
var symbolName_1 = getSymbolName(context.sourceFile, context.program.getTypeChecker(), symbolToken, context.program.getCompilerOptions());
|
|
149806
|
+
var fix = getTypeOnlyPromotionFix(context.sourceFile, symbolToken, symbolName_1, context.program);
|
|
149807
|
+
return fix && { fixes: [fix], symbolName: symbolName_1, errorIdentifierText: symbolToken.text };
|
|
149808
|
+
}
|
|
149809
|
+
else {
|
|
149810
|
+
info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
|
|
149811
|
+
}
|
|
149652
149812
|
var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
|
|
149653
149813
|
return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
|
|
149654
149814
|
}
|
|
@@ -149689,6 +149849,7 @@ var ts;
|
|
|
149689
149849
|
return 0 /* EqualTo */;
|
|
149690
149850
|
}
|
|
149691
149851
|
function getFixesInfoForUMDImport(_a, token) {
|
|
149852
|
+
var _b;
|
|
149692
149853
|
var sourceFile = _a.sourceFile, program = _a.program, host = _a.host, preferences = _a.preferences;
|
|
149693
149854
|
var checker = program.getTypeChecker();
|
|
149694
149855
|
var umdSymbol = getUmdSymbol(token, checker);
|
|
@@ -149699,7 +149860,7 @@ var ts;
|
|
|
149699
149860
|
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
|
|
149700
149861
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
149701
149862
|
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
|
149702
|
-
return { fixes: fixes, symbolName: symbolName };
|
|
149863
|
+
return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
|
|
149703
149864
|
}
|
|
149704
149865
|
function getUmdSymbol(token, checker) {
|
|
149705
149866
|
// try the identifier to see if it is the umd symbol
|
|
@@ -149765,12 +149926,22 @@ var ts;
|
|
|
149765
149926
|
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
|
|
149766
149927
|
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
|
|
149767
149928
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
149768
|
-
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
149929
|
+
var exportInfos = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
149769
149930
|
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
|
|
149770
149931
|
var _ = _a[0], exportInfos = _a[1];
|
|
149771
149932
|
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
|
|
149772
149933
|
}));
|
|
149773
|
-
return { fixes: fixes, symbolName: symbolName };
|
|
149934
|
+
return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
|
|
149935
|
+
}
|
|
149936
|
+
function getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program) {
|
|
149937
|
+
var checker = program.getTypeChecker();
|
|
149938
|
+
var symbol = checker.resolveName(symbolName, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
|
|
149939
|
+
if (!symbol)
|
|
149940
|
+
return undefined;
|
|
149941
|
+
var typeOnlyAliasDeclaration = checker.getTypeOnlyAliasDeclaration(symbol);
|
|
149942
|
+
if (!typeOnlyAliasDeclaration || ts.getSourceFileOfNode(typeOnlyAliasDeclaration) !== sourceFile)
|
|
149943
|
+
return undefined;
|
|
149944
|
+
return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
|
|
149774
149945
|
}
|
|
149775
149946
|
function jsxModeNeedsExplicitImport(jsx) {
|
|
149776
149947
|
return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
|
|
@@ -149779,14 +149950,20 @@ var ts;
|
|
|
149779
149950
|
var parent = symbolToken.parent;
|
|
149780
149951
|
if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
|
|
149781
149952
|
var jsxNamespace = checker.getJsxNamespace(sourceFile);
|
|
149782
|
-
if (
|
|
149953
|
+
if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
|
|
149783
149954
|
return jsxNamespace;
|
|
149784
149955
|
}
|
|
149785
149956
|
}
|
|
149786
149957
|
return symbolToken.text;
|
|
149787
149958
|
}
|
|
149959
|
+
function needsJsxNamespaceFix(jsxNamespace, symbolToken, checker) {
|
|
149960
|
+
if (ts.isIntrinsicJsxName(symbolToken.text))
|
|
149961
|
+
return true; // If we were triggered by a matching error code on an intrinsic, the error must have been about missing the JSX factory
|
|
149962
|
+
var namespaceSymbol = checker.resolveName(jsxNamespace, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
|
|
149963
|
+
return !namespaceSymbol || ts.some(namespaceSymbol.declarations, ts.isTypeOnlyImportOrExportDeclaration) && !(namespaceSymbol.flags & 111551 /* Value */);
|
|
149964
|
+
}
|
|
149788
149965
|
// Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
|
|
149789
|
-
function getExportInfos(symbolName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
|
|
149966
|
+
function getExportInfos(symbolName, isJsxTagName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
|
|
149790
149967
|
var _a;
|
|
149791
149968
|
// For each original symbol, keep all re-exports of that symbol together so we can call `getCodeActionsForImport` on the whole group at once.
|
|
149792
149969
|
// Maps symbol id to info for modules providing that symbol (original export + re-exports).
|
|
@@ -149809,7 +149986,7 @@ var ts;
|
|
|
149809
149986
|
cancellationToken.throwIfCancellationRequested();
|
|
149810
149987
|
var compilerOptions = program.getCompilerOptions();
|
|
149811
149988
|
var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
|
|
149812
|
-
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
|
|
149989
|
+
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
|
|
149813
149990
|
addSymbol(moduleSymbol, sourceFile, defaultInfo.symbol, defaultInfo.exportKind, program, isFromPackageJson);
|
|
149814
149991
|
}
|
|
149815
149992
|
// check exports with the same name
|
|
@@ -149849,14 +150026,14 @@ var ts;
|
|
|
149849
150026
|
// allowSyntheticDefaultImports/esModuleInterop is enabled.
|
|
149850
150027
|
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
|
|
149851
150028
|
}
|
|
149852
|
-
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
150029
|
+
function codeActionForFix(context, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
|
|
149853
150030
|
var diag;
|
|
149854
150031
|
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
|
|
149855
|
-
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
|
150032
|
+
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions);
|
|
149856
150033
|
});
|
|
149857
150034
|
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
|
|
149858
150035
|
}
|
|
149859
|
-
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
150036
|
+
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
|
|
149860
150037
|
switch (fix.kind) {
|
|
149861
150038
|
case 0 /* UseNamespace */:
|
|
149862
150039
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
@@ -149868,11 +150045,9 @@ var ts;
|
|
|
149868
150045
|
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
|
|
149869
150046
|
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
|
|
149870
150047
|
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
|
|
149871
|
-
return
|
|
149872
|
-
|
|
149873
|
-
|
|
149874
|
-
moduleSpecifierWithoutQuotes
|
|
149875
|
-
]; // you too!
|
|
150048
|
+
return includeSymbolNameInDescription
|
|
150049
|
+
? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifierWithoutQuotes]
|
|
150050
|
+
: [ts.Diagnostics.Update_import_from_0, moduleSpecifierWithoutQuotes];
|
|
149876
150051
|
}
|
|
149877
150052
|
case 3 /* AddNew */: {
|
|
149878
150053
|
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
|
|
@@ -149881,12 +150056,84 @@ var ts;
|
|
|
149881
150056
|
var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
|
|
149882
150057
|
var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
149883
150058
|
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
|
149884
|
-
return
|
|
150059
|
+
return includeSymbolNameInDescription
|
|
150060
|
+
? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifier]
|
|
150061
|
+
: [ts.Diagnostics.Add_import_from_0, moduleSpecifier];
|
|
150062
|
+
}
|
|
150063
|
+
case 4 /* PromoteTypeOnly */: {
|
|
150064
|
+
var typeOnlyAliasDeclaration = fix.typeOnlyAliasDeclaration;
|
|
150065
|
+
var promotedDeclaration = promoteFromTypeOnly(changes, typeOnlyAliasDeclaration, compilerOptions, sourceFile);
|
|
150066
|
+
return promotedDeclaration.kind === 269 /* ImportSpecifier */
|
|
150067
|
+
? [ts.Diagnostics.Remove_type_from_import_of_0_from_1, symbolName, getModuleSpecifierText(promotedDeclaration.parent.parent)]
|
|
150068
|
+
: [ts.Diagnostics.Remove_type_from_import_declaration_from_0, getModuleSpecifierText(promotedDeclaration)];
|
|
149885
150069
|
}
|
|
149886
150070
|
default:
|
|
149887
150071
|
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
|
|
149888
150072
|
}
|
|
149889
150073
|
}
|
|
150074
|
+
function getModuleSpecifierText(promotedDeclaration) {
|
|
150075
|
+
var _a, _b;
|
|
150076
|
+
return promotedDeclaration.kind === 264 /* ImportEqualsDeclaration */
|
|
150077
|
+
? ((_b = ts.tryCast((_a = ts.tryCast(promotedDeclaration.moduleReference, ts.isExternalModuleReference)) === null || _a === void 0 ? void 0 : _a.expression, ts.isStringLiteralLike)) === null || _b === void 0 ? void 0 : _b.text) || promotedDeclaration.moduleReference.getText()
|
|
150078
|
+
: ts.cast(promotedDeclaration.parent.moduleSpecifier, ts.isStringLiteral).text;
|
|
150079
|
+
}
|
|
150080
|
+
function promoteFromTypeOnly(changes, aliasDeclaration, compilerOptions, sourceFile) {
|
|
150081
|
+
// See comment in `doAddExistingFix` on constant with the same name.
|
|
150082
|
+
var convertExistingToTypeOnly = compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
|
|
150083
|
+
switch (aliasDeclaration.kind) {
|
|
150084
|
+
case 269 /* ImportSpecifier */:
|
|
150085
|
+
if (aliasDeclaration.isTypeOnly) {
|
|
150086
|
+
if (aliasDeclaration.parent.elements.length > 1 && ts.OrganizeImports.importSpecifiersAreSorted(aliasDeclaration.parent.elements)) {
|
|
150087
|
+
changes.delete(sourceFile, aliasDeclaration);
|
|
150088
|
+
var newSpecifier = ts.factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
|
|
150089
|
+
var insertionIndex = ts.OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier);
|
|
150090
|
+
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
|
|
150091
|
+
}
|
|
150092
|
+
else {
|
|
150093
|
+
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken());
|
|
150094
|
+
}
|
|
150095
|
+
return aliasDeclaration;
|
|
150096
|
+
}
|
|
150097
|
+
else {
|
|
150098
|
+
ts.Debug.assert(aliasDeclaration.parent.parent.isTypeOnly);
|
|
150099
|
+
promoteImportClause(aliasDeclaration.parent.parent);
|
|
150100
|
+
return aliasDeclaration.parent.parent;
|
|
150101
|
+
}
|
|
150102
|
+
case 266 /* ImportClause */:
|
|
150103
|
+
promoteImportClause(aliasDeclaration);
|
|
150104
|
+
return aliasDeclaration;
|
|
150105
|
+
case 267 /* NamespaceImport */:
|
|
150106
|
+
promoteImportClause(aliasDeclaration.parent);
|
|
150107
|
+
return aliasDeclaration.parent;
|
|
150108
|
+
case 264 /* ImportEqualsDeclaration */:
|
|
150109
|
+
changes.deleteRange(sourceFile, aliasDeclaration.getChildAt(1));
|
|
150110
|
+
return aliasDeclaration;
|
|
150111
|
+
default:
|
|
150112
|
+
ts.Debug.failBadSyntaxKind(aliasDeclaration);
|
|
150113
|
+
}
|
|
150114
|
+
function promoteImportClause(importClause) {
|
|
150115
|
+
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(importClause, sourceFile));
|
|
150116
|
+
if (convertExistingToTypeOnly) {
|
|
150117
|
+
var namedImports = ts.tryCast(importClause.namedBindings, ts.isNamedImports);
|
|
150118
|
+
if (namedImports && namedImports.elements.length > 1) {
|
|
150119
|
+
if (ts.OrganizeImports.importSpecifiersAreSorted(namedImports.elements) &&
|
|
150120
|
+
aliasDeclaration.kind === 269 /* ImportSpecifier */ &&
|
|
150121
|
+
namedImports.elements.indexOf(aliasDeclaration) !== 0) {
|
|
150122
|
+
// The import specifier being promoted will be the only non-type-only,
|
|
150123
|
+
// import in the NamedImports, so it should be moved to the front.
|
|
150124
|
+
changes.delete(sourceFile, aliasDeclaration);
|
|
150125
|
+
changes.insertImportSpecifierAtIndex(sourceFile, aliasDeclaration, namedImports, 0);
|
|
150126
|
+
}
|
|
150127
|
+
for (var _i = 0, _a = namedImports.elements; _i < _a.length; _i++) {
|
|
150128
|
+
var element = _a[_i];
|
|
150129
|
+
if (element !== aliasDeclaration && !element.isTypeOnly) {
|
|
150130
|
+
changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, element);
|
|
150131
|
+
}
|
|
150132
|
+
}
|
|
150133
|
+
}
|
|
150134
|
+
}
|
|
150135
|
+
}
|
|
150136
|
+
}
|
|
149890
150137
|
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
|
|
149891
150138
|
var _a;
|
|
149892
150139
|
if (clause.kind === 200 /* ObjectBindingPattern */) {
|
|
@@ -149924,13 +150171,7 @@ var ts;
|
|
|
149924
150171
|
var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
|
|
149925
150172
|
? 0
|
|
149926
150173
|
: ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
|
|
149927
|
-
|
|
149928
|
-
if (prevSpecifier) {
|
|
149929
|
-
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
|
|
149930
|
-
}
|
|
149931
|
-
else {
|
|
149932
|
-
changes.insertNodeBefore(sourceFile, existingSpecifiers[0], spec, !ts.positionsAreOnSameLine(existingSpecifiers[0].getStart(), clause.parent.getStart(), sourceFile));
|
|
149933
|
-
}
|
|
150174
|
+
changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
|
|
149934
150175
|
}
|
|
149935
150176
|
}
|
|
149936
150177
|
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
|
|
@@ -150045,17 +150286,20 @@ var ts;
|
|
|
150045
150286
|
var declarations = _a.declarations;
|
|
150046
150287
|
return ts.some(declarations, function (decl) { return !!(ts.getMeaningFromDeclaration(decl) & meaning); });
|
|
150047
150288
|
}
|
|
150048
|
-
function moduleSymbolToValidIdentifier(moduleSymbol, target) {
|
|
150049
|
-
return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);
|
|
150289
|
+
function moduleSymbolToValidIdentifier(moduleSymbol, target, forceCapitalize) {
|
|
150290
|
+
return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target, forceCapitalize);
|
|
150050
150291
|
}
|
|
150051
150292
|
codefix.moduleSymbolToValidIdentifier = moduleSymbolToValidIdentifier;
|
|
150052
|
-
function moduleSpecifierToValidIdentifier(moduleSpecifier, target) {
|
|
150293
|
+
function moduleSpecifierToValidIdentifier(moduleSpecifier, target, forceCapitalize) {
|
|
150053
150294
|
var baseName = ts.getBaseFileName(ts.removeSuffix(moduleSpecifier, "/index"));
|
|
150054
150295
|
var res = "";
|
|
150055
150296
|
var lastCharWasValid = true;
|
|
150056
150297
|
var firstCharCode = baseName.charCodeAt(0);
|
|
150057
150298
|
if (ts.isIdentifierStart(firstCharCode, target)) {
|
|
150058
150299
|
res += String.fromCharCode(firstCharCode);
|
|
150300
|
+
if (forceCapitalize) {
|
|
150301
|
+
res = res.toUpperCase();
|
|
150302
|
+
}
|
|
150059
150303
|
}
|
|
150060
150304
|
else {
|
|
150061
150305
|
lastCharWasValid = false;
|
|
@@ -157674,14 +157918,22 @@ var ts;
|
|
|
157674
157918
|
var result = [];
|
|
157675
157919
|
return visitor(selection) ? undefined : result;
|
|
157676
157920
|
function visitor(node) {
|
|
157677
|
-
var _a;
|
|
157678
157921
|
if (ts.isTypeReferenceNode(node)) {
|
|
157679
157922
|
if (ts.isIdentifier(node.typeName)) {
|
|
157680
|
-
var
|
|
157681
|
-
var
|
|
157682
|
-
|
|
157683
|
-
|
|
157684
|
-
|
|
157923
|
+
var typeName = node.typeName;
|
|
157924
|
+
var symbol = checker.resolveName(typeName.text, typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
|
|
157925
|
+
for (var _i = 0, _a = (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) || ts.emptyArray; _i < _a.length; _i++) {
|
|
157926
|
+
var decl = _a[_i];
|
|
157927
|
+
if (ts.isTypeParameterDeclaration(decl) && decl.getSourceFile() === file) {
|
|
157928
|
+
// skip extraction if the type node is in the range of the type parameter declaration.
|
|
157929
|
+
// function foo<T extends { a?: /**/T }>(): void;
|
|
157930
|
+
if (decl.name.escapedText === typeName.escapedText && rangeContainsSkipTrivia(decl, selection, file)) {
|
|
157931
|
+
return true;
|
|
157932
|
+
}
|
|
157933
|
+
if (rangeContainsSkipTrivia(statement, decl, file) && !rangeContainsSkipTrivia(selection, decl, file)) {
|
|
157934
|
+
ts.pushIfUnique(result, decl);
|
|
157935
|
+
break;
|
|
157936
|
+
}
|
|
157685
157937
|
}
|
|
157686
157938
|
}
|
|
157687
157939
|
}
|