typescript 4.6.0-dev.20220204 → 4.6.0-dev.20220205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsc.js +54 -43
- package/lib/tsserver.js +220 -138
- package/lib/tsserverlibrary.js +220 -138
- package/lib/typescript.js +220 -138
- package/lib/typescriptServices.js +220 -138
- package/lib/typingsInstaller.js +66 -46
- 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.20220205";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -1274,11 +1274,11 @@ var ts;
|
|
|
1274
1274
|
return result;
|
|
1275
1275
|
}
|
|
1276
1276
|
ts.getAllKeys = getAllKeys;
|
|
1277
|
-
function getOwnValues(
|
|
1277
|
+
function getOwnValues(collection) {
|
|
1278
1278
|
var values = [];
|
|
1279
|
-
for (var key in
|
|
1280
|
-
if (hasOwnProperty.call(
|
|
1281
|
-
values.push(
|
|
1279
|
+
for (var key in collection) {
|
|
1280
|
+
if (hasOwnProperty.call(collection, key)) {
|
|
1281
|
+
values.push(collection[key]);
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
1284
|
return values;
|
|
@@ -8681,12 +8681,10 @@ var ts;
|
|
|
8681
8681
|
Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher: diag(2802, ts.DiagnosticCategory.Error, "Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es201_2802", "Type '{0}' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher."),
|
|
8682
8682
|
Cannot_assign_to_private_method_0_Private_methods_are_not_writable: diag(2803, ts.DiagnosticCategory.Error, "Cannot_assign_to_private_method_0_Private_methods_are_not_writable_2803", "Cannot assign to private method '{0}'. Private methods are not writable."),
|
|
8683
8683
|
Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name: diag(2804, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name_2804", "Duplicate identifier '{0}'. Static and instance elements cannot share the same private name."),
|
|
8684
|
-
Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag: diag(2805, ts.DiagnosticCategory.Error, "Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_no_2805", "Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag."),
|
|
8685
8684
|
Private_accessor_was_defined_without_a_getter: diag(2806, ts.DiagnosticCategory.Error, "Private_accessor_was_defined_without_a_getter_2806", "Private accessor was defined without a getter."),
|
|
8686
8685
|
This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0: diag(2807, ts.DiagnosticCategory.Error, "This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_o_2807", "This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'."),
|
|
8687
8686
|
A_get_accessor_must_be_at_least_as_accessible_as_the_setter: diag(2808, ts.DiagnosticCategory.Error, "A_get_accessor_must_be_at_least_as_accessible_as_the_setter_2808", "A get accessor must be at least as accessible as the setter"),
|
|
8688
8687
|
Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses: diag(2809, ts.DiagnosticCategory.Error, "Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_d_2809", "Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses."),
|
|
8689
|
-
Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnext_and_useDefineForClassFields_is_false: diag(2810, ts.DiagnosticCategory.Error, "Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnex_2810", "Property '{0}' may not be used in a static property's initializer in the same class when 'target' is 'esnext' and 'useDefineForClassFields' is 'false'."),
|
|
8690
8688
|
Initializer_for_property_0: diag(2811, ts.DiagnosticCategory.Error, "Initializer_for_property_0_2811", "Initializer for property '{0}'"),
|
|
8691
8689
|
Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom: diag(2812, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom_2812", "Property '{0}' does not exist on type '{1}'. Try changing the 'lib' compiler option to include 'dom'."),
|
|
8692
8690
|
Class_declaration_cannot_implement_overload_list_for_0: diag(2813, ts.DiagnosticCategory.Error, "Class_declaration_cannot_implement_overload_list_for_0_2813", "Class declaration cannot implement overload list for '{0}'."),
|
|
@@ -9637,6 +9635,7 @@ var ts;
|
|
|
9637
9635
|
Add_missing_attributes: diag(95167, ts.DiagnosticCategory.Message, "Add_missing_attributes_95167", "Add missing attributes"),
|
|
9638
9636
|
Add_all_missing_attributes: diag(95168, ts.DiagnosticCategory.Message, "Add_all_missing_attributes_95168", "Add all missing attributes"),
|
|
9639
9637
|
Add_undefined_to_optional_property_type: diag(95169, ts.DiagnosticCategory.Message, "Add_undefined_to_optional_property_type_95169", "Add 'undefined' to optional property type"),
|
|
9638
|
+
Convert_named_imports_to_default_import: diag(95170, ts.DiagnosticCategory.Message, "Convert_named_imports_to_default_import_95170", "Convert named imports to default import"),
|
|
9640
9639
|
No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, ts.DiagnosticCategory.Error, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."),
|
|
9641
9640
|
Classes_may_not_have_a_field_named_constructor: diag(18006, ts.DiagnosticCategory.Error, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."),
|
|
9642
9641
|
JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, ts.DiagnosticCategory.Error, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"),
|
|
@@ -72952,23 +72951,6 @@ var ts;
|
|
|
72952
72951
|
if (assignmentKind && lexicallyScopedSymbol && lexicallyScopedSymbol.valueDeclaration && ts.isMethodDeclaration(lexicallyScopedSymbol.valueDeclaration)) {
|
|
72953
72952
|
grammarErrorOnNode(right, ts.Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, ts.idText(right));
|
|
72954
72953
|
}
|
|
72955
|
-
if ((lexicallyScopedSymbol === null || lexicallyScopedSymbol === void 0 ? void 0 : lexicallyScopedSymbol.valueDeclaration) && (ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && !useDefineForClassFields)) {
|
|
72956
|
-
var lexicalClass_1 = ts.getContainingClass(lexicallyScopedSymbol.valueDeclaration);
|
|
72957
|
-
var parentStaticFieldInitializer = ts.findAncestor(node, function (n) {
|
|
72958
|
-
if (n === lexicalClass_1)
|
|
72959
|
-
return "quit";
|
|
72960
|
-
if (ts.isPropertyDeclaration(n.parent) && ts.hasStaticModifier(n.parent) && n.parent.initializer === n && n.parent.parent === lexicalClass_1) {
|
|
72961
|
-
return true;
|
|
72962
|
-
}
|
|
72963
|
-
return false;
|
|
72964
|
-
});
|
|
72965
|
-
if (parentStaticFieldInitializer) {
|
|
72966
|
-
var parentStaticFieldInitializerSymbol = getSymbolOfNode(parentStaticFieldInitializer.parent);
|
|
72967
|
-
ts.Debug.assert(parentStaticFieldInitializerSymbol, "Initializer without declaration symbol");
|
|
72968
|
-
var diagnostic = error(node, ts.Diagnostics.Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnext_and_useDefineForClassFields_is_false, ts.symbolName(lexicallyScopedSymbol));
|
|
72969
|
-
ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(parentStaticFieldInitializer.parent, ts.Diagnostics.Initializer_for_property_0, ts.symbolName(parentStaticFieldInitializerSymbol)));
|
|
72970
|
-
}
|
|
72971
|
-
}
|
|
72972
72954
|
if (isAnyLike) {
|
|
72973
72955
|
if (lexicallyScopedSymbol) {
|
|
72974
72956
|
return isErrorType(apparentType) ? errorType : apparentType;
|
|
@@ -78604,9 +78586,6 @@ var ts;
|
|
|
78604
78586
|
checkGrammarComputedPropertyName(node.name);
|
|
78605
78587
|
checkVariableLikeDeclaration(node);
|
|
78606
78588
|
setNodeLinksForPrivateIdentifierScope(node);
|
|
78607
|
-
if (ts.isPrivateIdentifier(node.name) && ts.hasStaticModifier(node) && node.initializer && languageVersion === 99 /* ESNext */ && !compilerOptions.useDefineForClassFields) {
|
|
78608
|
-
error(node.initializer, ts.Diagnostics.Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag);
|
|
78609
|
-
}
|
|
78610
78589
|
// property signatures already report "initializer not allowed in ambient context" elsewhere
|
|
78611
78590
|
if (ts.hasSyntacticModifier(node, 128 /* Abstract */) && node.kind === 166 /* PropertyDeclaration */ && node.initializer) {
|
|
78612
78591
|
error(node, ts.Diagnostics.Property_0_cannot_have_an_initializer_because_it_is_marked_abstract, ts.declarationNameToString(node.name));
|
|
@@ -92296,10 +92275,12 @@ var ts;
|
|
|
92296
92275
|
var languageVersion = ts.getEmitScriptTarget(compilerOptions);
|
|
92297
92276
|
var useDefineForClassFields = ts.getUseDefineForClassFields(compilerOptions);
|
|
92298
92277
|
var shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < 9 /* ES2022 */;
|
|
92278
|
+
// We need to transform `this` in a static initializer into a reference to the class
|
|
92279
|
+
// when targeting < ES2022 since the assignment will be moved outside of the class body.
|
|
92280
|
+
var shouldTransformThisInStaticInitializers = languageVersion < 9 /* ES2022 */;
|
|
92299
92281
|
// We don't need to transform `super` property access when targeting ES5, ES3 because
|
|
92300
92282
|
// the es2015 transformation handles those.
|
|
92301
|
-
var shouldTransformSuperInStaticInitializers =
|
|
92302
|
-
var shouldTransformThisInStaticInitializers = languageVersion <= 8 /* ES2021 */ || !useDefineForClassFields;
|
|
92283
|
+
var shouldTransformSuperInStaticInitializers = shouldTransformThisInStaticInitializers && languageVersion >= 2 /* ES2015 */;
|
|
92303
92284
|
var previousOnSubstituteNode = context.onSubstituteNode;
|
|
92304
92285
|
context.onSubstituteNode = onSubstituteNode;
|
|
92305
92286
|
var previousOnEmitNode = context.onEmitNode;
|
|
@@ -92528,6 +92509,10 @@ var ts;
|
|
|
92528
92509
|
ts.Debug.assert(!ts.some(node.decorators));
|
|
92529
92510
|
if (ts.isPrivateIdentifier(node.name)) {
|
|
92530
92511
|
if (!shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
92512
|
+
if (ts.isStatic(node)) {
|
|
92513
|
+
// static fields are left as is
|
|
92514
|
+
return ts.visitEachChild(node, visitor, context);
|
|
92515
|
+
}
|
|
92531
92516
|
// Initializer is elided as the field is initialized in transformConstructor.
|
|
92532
92517
|
return factory.updatePropertyDeclaration(node,
|
|
92533
92518
|
/*decorators*/ undefined, ts.visitNodes(node.modifiers, visitor, ts.isModifier), node.name,
|
|
@@ -92549,6 +92534,22 @@ var ts;
|
|
|
92549
92534
|
if (expr && !ts.isSimpleInlineableExpression(expr)) {
|
|
92550
92535
|
getPendingExpressions().push(expr);
|
|
92551
92536
|
}
|
|
92537
|
+
if (ts.isStatic(node) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) {
|
|
92538
|
+
var initializerStatement = transformPropertyOrClassStaticBlock(node, factory.createThis());
|
|
92539
|
+
if (initializerStatement) {
|
|
92540
|
+
var staticBlock = factory.createClassStaticBlockDeclaration(
|
|
92541
|
+
/*decorators*/ undefined,
|
|
92542
|
+
/*modifiers*/ undefined, factory.createBlock([initializerStatement]));
|
|
92543
|
+
ts.setOriginalNode(staticBlock, node);
|
|
92544
|
+
ts.setCommentRange(staticBlock, node);
|
|
92545
|
+
// Set the comment range for the statement to an empty synthetic range
|
|
92546
|
+
// and drop synthetic comments from the statement to avoid printing them twice.
|
|
92547
|
+
ts.setCommentRange(initializerStatement, { pos: -1, end: -1 });
|
|
92548
|
+
ts.setSyntheticLeadingComments(initializerStatement, undefined);
|
|
92549
|
+
ts.setSyntheticTrailingComments(initializerStatement, undefined);
|
|
92550
|
+
return staticBlock;
|
|
92551
|
+
}
|
|
92552
|
+
}
|
|
92552
92553
|
return undefined;
|
|
92553
92554
|
}
|
|
92554
92555
|
function createPrivateIdentifierAccess(info, receiver) {
|
|
@@ -92936,7 +92937,6 @@ var ts;
|
|
|
92936
92937
|
if (facts & 8 /* NeedsSubstitutionForThisInClassStaticField */) {
|
|
92937
92938
|
enableSubstitutionForClassStaticThisOrSuperReference();
|
|
92938
92939
|
}
|
|
92939
|
-
var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
|
|
92940
92940
|
// If a class has private static fields, or a static field has a `this` or `super` reference,
|
|
92941
92941
|
// then we need to allocate a temp variable to hold on to that reference.
|
|
92942
92942
|
var pendingClassReferenceAssignment;
|
|
@@ -92964,6 +92964,7 @@ var ts;
|
|
|
92964
92964
|
// From ES6 specification:
|
|
92965
92965
|
// HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using
|
|
92966
92966
|
// a lexical declaration such as a LexicalDeclaration or a ClassDeclaration.
|
|
92967
|
+
var staticProperties = ts.getStaticPropertiesAndClassStaticBlock(node);
|
|
92967
92968
|
if (ts.some(staticProperties)) {
|
|
92968
92969
|
addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node));
|
|
92969
92970
|
}
|
|
@@ -93002,7 +93003,7 @@ var ts;
|
|
|
93002
93003
|
}
|
|
93003
93004
|
var classExpression = factory.updateClassExpression(node, ts.visitNodes(node.decorators, visitor, ts.isDecorator), node.modifiers, node.name,
|
|
93004
93005
|
/*typeParameters*/ undefined, ts.visitNodes(node.heritageClauses, heritageClauseVisitor, ts.isHeritageClause), transformClassMembers(node, isDerivedClass));
|
|
93005
|
-
var hasTransformableStatics = ts.some(staticPropertiesOrClassStaticBlocks, function (p) { return ts.isClassStaticBlockDeclaration(p) || !!p.initializer ||
|
|
93006
|
+
var hasTransformableStatics = shouldTransformPrivateElementsOrClassStaticBlocks && ts.some(staticPropertiesOrClassStaticBlocks, function (p) { return ts.isClassStaticBlockDeclaration(p) || !!p.initializer || ts.isPrivateIdentifier(p.name); });
|
|
93006
93007
|
if (hasTransformableStatics || ts.some(pendingExpressions)) {
|
|
93007
93008
|
if (isDecoratedClassDeclaration) {
|
|
93008
93009
|
ts.Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration.");
|
|
@@ -93049,6 +93050,7 @@ var ts;
|
|
|
93049
93050
|
return undefined;
|
|
93050
93051
|
}
|
|
93051
93052
|
function transformClassMembers(node, isDerivedClass) {
|
|
93053
|
+
var members = [];
|
|
93052
93054
|
if (shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
93053
93055
|
// Declare private names.
|
|
93054
93056
|
for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
|
|
@@ -93061,12 +93063,20 @@ var ts;
|
|
|
93061
93063
|
createBrandCheckWeakSetForPrivateMethods();
|
|
93062
93064
|
}
|
|
93063
93065
|
}
|
|
93064
|
-
var members = [];
|
|
93065
93066
|
var constructor = transformConstructor(node, isDerivedClass);
|
|
93067
|
+
var visitedMembers = ts.visitNodes(node.members, classElementVisitor, ts.isClassElement);
|
|
93066
93068
|
if (constructor) {
|
|
93067
93069
|
members.push(constructor);
|
|
93068
93070
|
}
|
|
93069
|
-
|
|
93071
|
+
if (!shouldTransformPrivateElementsOrClassStaticBlocks && ts.some(pendingExpressions)) {
|
|
93072
|
+
members.push(factory.createClassStaticBlockDeclaration(
|
|
93073
|
+
/*decorators*/ undefined,
|
|
93074
|
+
/*modifiers*/ undefined, factory.createBlock([
|
|
93075
|
+
factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions))
|
|
93076
|
+
])));
|
|
93077
|
+
pendingExpressions = undefined;
|
|
93078
|
+
}
|
|
93079
|
+
ts.addRange(members, visitedMembers);
|
|
93070
93080
|
return ts.setTextRange(factory.createNodeArray(members), /*location*/ node.members);
|
|
93071
93081
|
}
|
|
93072
93082
|
function createBrandCheckWeakSetForPrivateMethods() {
|
|
@@ -93209,24 +93219,34 @@ var ts;
|
|
|
93209
93219
|
function addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
|
|
93210
93220
|
for (var _i = 0, properties_7 = properties; _i < properties_7.length; _i++) {
|
|
93211
93221
|
var property = properties_7[_i];
|
|
93212
|
-
|
|
93213
|
-
|
|
93214
|
-
|
|
93215
|
-
|
|
93222
|
+
if (ts.isStatic(property) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) {
|
|
93223
|
+
continue;
|
|
93224
|
+
}
|
|
93225
|
+
var statement = transformPropertyOrClassStaticBlock(property, receiver);
|
|
93226
|
+
if (!statement) {
|
|
93216
93227
|
continue;
|
|
93217
93228
|
}
|
|
93218
|
-
var statement = factory.createExpressionStatement(expression);
|
|
93219
|
-
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
93220
|
-
ts.setCommentRange(statement, property);
|
|
93221
|
-
ts.setOriginalNode(statement, property);
|
|
93222
|
-
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
93223
|
-
// `statement` and `expression` have a copy of the synthesized comments.
|
|
93224
|
-
// Drop the comments from expression to avoid printing them twice.
|
|
93225
|
-
ts.setSyntheticLeadingComments(expression, undefined);
|
|
93226
|
-
ts.setSyntheticTrailingComments(expression, undefined);
|
|
93227
93229
|
statements.push(statement);
|
|
93228
93230
|
}
|
|
93229
93231
|
}
|
|
93232
|
+
function transformPropertyOrClassStaticBlock(property, receiver) {
|
|
93233
|
+
var expression = ts.isClassStaticBlockDeclaration(property) ?
|
|
93234
|
+
transformClassStaticBlockDeclaration(property) :
|
|
93235
|
+
transformProperty(property, receiver);
|
|
93236
|
+
if (!expression) {
|
|
93237
|
+
return undefined;
|
|
93238
|
+
}
|
|
93239
|
+
var statement = factory.createExpressionStatement(expression);
|
|
93240
|
+
ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
|
|
93241
|
+
ts.setCommentRange(statement, property);
|
|
93242
|
+
ts.setOriginalNode(statement, property);
|
|
93243
|
+
// `setOriginalNode` *copies* the `emitNode` from `property`, so now both
|
|
93244
|
+
// `statement` and `expression` have a copy of the synthesized comments.
|
|
93245
|
+
// Drop the comments from expression to avoid printing them twice.
|
|
93246
|
+
ts.setSyntheticLeadingComments(expression, undefined);
|
|
93247
|
+
ts.setSyntheticTrailingComments(expression, undefined);
|
|
93248
|
+
return statement;
|
|
93249
|
+
}
|
|
93230
93250
|
/**
|
|
93231
93251
|
* Generates assignment expressions for property initializers.
|
|
93232
93252
|
*
|
|
@@ -126689,15 +126709,35 @@ var ts;
|
|
|
126689
126709
|
return ts.isArray(valueOrArray) ? ts.first(valueOrArray) : valueOrArray;
|
|
126690
126710
|
}
|
|
126691
126711
|
ts.firstOrOnly = firstOrOnly;
|
|
126712
|
+
function getNamesForExportedSymbol(symbol, scriptTarget) {
|
|
126713
|
+
if (needsNameFromDeclaration(symbol)) {
|
|
126714
|
+
var fromDeclaration = getDefaultLikeExportNameFromDeclaration(symbol);
|
|
126715
|
+
if (fromDeclaration)
|
|
126716
|
+
return fromDeclaration;
|
|
126717
|
+
var fileNameCase = ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, /*preferCapitalized*/ false);
|
|
126718
|
+
var capitalized = ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, /*preferCapitalized*/ true);
|
|
126719
|
+
if (fileNameCase === capitalized)
|
|
126720
|
+
return fileNameCase;
|
|
126721
|
+
return [fileNameCase, capitalized];
|
|
126722
|
+
}
|
|
126723
|
+
return symbol.name;
|
|
126724
|
+
}
|
|
126725
|
+
ts.getNamesForExportedSymbol = getNamesForExportedSymbol;
|
|
126692
126726
|
function getNameForExportedSymbol(symbol, scriptTarget, preferCapitalized) {
|
|
126693
|
-
if (
|
|
126727
|
+
if (needsNameFromDeclaration(symbol)) {
|
|
126694
126728
|
// Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
|
|
126695
|
-
return
|
|
126729
|
+
return getDefaultLikeExportNameFromDeclaration(symbol)
|
|
126696
126730
|
|| ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, !!preferCapitalized);
|
|
126697
126731
|
}
|
|
126698
126732
|
return symbol.name;
|
|
126699
126733
|
}
|
|
126700
126734
|
ts.getNameForExportedSymbol = getNameForExportedSymbol;
|
|
126735
|
+
function needsNameFromDeclaration(symbol) {
|
|
126736
|
+
return !(symbol.flags & 33554432 /* Transient */) && (symbol.escapedName === "export=" /* ExportEquals */ || symbol.escapedName === "default" /* Default */);
|
|
126737
|
+
}
|
|
126738
|
+
function getDefaultLikeExportNameFromDeclaration(symbol) {
|
|
126739
|
+
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; });
|
|
126740
|
+
}
|
|
126701
126741
|
function getSymbolParentOrFail(symbol) {
|
|
126702
126742
|
var _a;
|
|
126703
126743
|
return ts.Debug.checkDefined(symbol.parent, "Symbol parent was undefined. Flags: " + ts.Debug.formatSymbolFlags(symbol.flags) + ". " +
|
|
@@ -126867,9 +126907,11 @@ var ts;
|
|
|
126867
126907
|
// 3. Otherwise, we have a default/namespace import that can be imported by any name, and
|
|
126868
126908
|
// `symbolTableKey` will be something undesirable like `export=` or `default`, so we try to
|
|
126869
126909
|
// get a better name.
|
|
126870
|
-
var
|
|
126910
|
+
var names = exportKind === 0 /* Named */ || ts.isExternalModuleSymbol(namedSymbol)
|
|
126871
126911
|
? ts.unescapeLeadingUnderscores(symbolTableKey)
|
|
126872
|
-
: ts.
|
|
126912
|
+
: ts.getNamesForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined);
|
|
126913
|
+
var symbolName = typeof names === "string" ? names : names[0];
|
|
126914
|
+
var capitalizedSymbolName = typeof names === "string" ? undefined : names[1];
|
|
126873
126915
|
var moduleName = ts.stripQuotes(moduleSymbol.name);
|
|
126874
126916
|
var id = exportInfoId++;
|
|
126875
126917
|
var target = ts.skipAlias(symbol, checker);
|
|
@@ -126877,10 +126919,11 @@ var ts;
|
|
|
126877
126919
|
var storedModuleSymbol = moduleSymbol.flags & 33554432 /* Transient */ ? undefined : moduleSymbol;
|
|
126878
126920
|
if (!storedSymbol || !storedModuleSymbol)
|
|
126879
126921
|
symbols.set(id, [symbol, moduleSymbol]);
|
|
126880
|
-
exportInfo.add(key(
|
|
126922
|
+
exportInfo.add(key(symbolName, symbol, ts.isExternalModuleNameRelative(moduleName) ? undefined : moduleName, checker), {
|
|
126881
126923
|
id: id,
|
|
126882
126924
|
symbolTableKey: symbolTableKey,
|
|
126883
|
-
symbolName:
|
|
126925
|
+
symbolName: symbolName,
|
|
126926
|
+
capitalizedSymbolName: capitalizedSymbolName,
|
|
126884
126927
|
moduleName: moduleName,
|
|
126885
126928
|
moduleFile: moduleFile,
|
|
126886
126929
|
moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName,
|
|
@@ -126898,21 +126941,18 @@ var ts;
|
|
|
126898
126941
|
var result = exportInfo.get(key);
|
|
126899
126942
|
return result === null || result === void 0 ? void 0 : result.map(rehydrateCachedInfo);
|
|
126900
126943
|
},
|
|
126901
|
-
|
|
126944
|
+
search: function (importingFile, preferCapitalized, matches, action) {
|
|
126902
126945
|
if (importingFile !== usableByFileName)
|
|
126903
126946
|
return;
|
|
126904
126947
|
exportInfo.forEach(function (info, key) {
|
|
126905
126948
|
var _a = parseKey(key), symbolName = _a.symbolName, ambientModuleName = _a.ambientModuleName;
|
|
126906
|
-
var
|
|
126907
|
-
|
|
126908
|
-
|
|
126909
|
-
|
|
126910
|
-
|
|
126911
|
-
|
|
126912
|
-
|
|
126913
|
-
? ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined, /*preferCapitalized*/ true)
|
|
126914
|
-
: symbolName;
|
|
126915
|
-
}, !!ambientModuleName, key);
|
|
126949
|
+
var name = preferCapitalized && info[0].capitalizedSymbolName || symbolName;
|
|
126950
|
+
if (matches(name, info[0].targetFlags)) {
|
|
126951
|
+
var rehydrated = info.map(rehydrateCachedInfo);
|
|
126952
|
+
var filtered = rehydrated.filter(function (r, i) { return isNotShadowedByDeeperNodeModulesPackage(r, info[i].packageName); });
|
|
126953
|
+
if (filtered.length) {
|
|
126954
|
+
action(filtered, name, !!ambientModuleName, key);
|
|
126955
|
+
}
|
|
126916
126956
|
}
|
|
126917
126957
|
});
|
|
126918
126958
|
},
|
|
@@ -131028,44 +131068,47 @@ var ts;
|
|
|
131028
131068
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
131029
131069
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
131030
131070
|
resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
|
|
131031
|
-
exportInfo.
|
|
131032
|
-
|
|
131071
|
+
exportInfo.search(sourceFile.path,
|
|
131072
|
+
/*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
|
|
131033
131073
|
if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
|
|
131034
|
-
return;
|
|
131074
|
+
return false;
|
|
131035
131075
|
if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
|
|
131036
|
-
return;
|
|
131037
|
-
|
|
131038
|
-
|
|
131039
|
-
|
|
131040
|
-
|
|
131041
|
-
return;
|
|
131076
|
+
return false;
|
|
131077
|
+
if (!isTypeOnlyLocation && !importCompletionNode && !(targetFlags & 111551 /* Value */))
|
|
131078
|
+
return false;
|
|
131079
|
+
if (isTypeOnlyLocation && !(targetFlags & (1536 /* Module */ | 788968 /* Type */)))
|
|
131080
|
+
return false;
|
|
131042
131081
|
// Do not try to auto-import something with a lowercase first letter for a JSX tag
|
|
131043
131082
|
var firstChar = symbolName.charCodeAt(0);
|
|
131044
131083
|
if (isRightOfOpenTag && (firstChar < 65 /* A */ || firstChar > 90 /* Z */))
|
|
131084
|
+
return false;
|
|
131085
|
+
if (detailsEntryId)
|
|
131086
|
+
return true;
|
|
131087
|
+
return charactersFuzzyMatchInString(symbolName, lowerCaseTokenText);
|
|
131088
|
+
}, function (info, symbolName, isFromAmbientModule, exportMapKey) {
|
|
131089
|
+
if (detailsEntryId && !ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); })) {
|
|
131045
131090
|
return;
|
|
131046
|
-
var isCompletionDetailsMatch = detailsEntryId && ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); });
|
|
131047
|
-
if (isCompletionDetailsMatch || !detailsEntryId && charactersFuzzyMatchInString(symbolName, lowerCaseTokenText)) {
|
|
131048
|
-
var defaultExportInfo = ts.find(info, isImportableExportInfo);
|
|
131049
|
-
if (!defaultExportInfo) {
|
|
131050
|
-
return;
|
|
131051
|
-
}
|
|
131052
|
-
// If we don't need to resolve module specifiers, we can use any re-export that is importable at all
|
|
131053
|
-
// (We need to ensure that at least one is importable to show a completion.)
|
|
131054
|
-
var _a = context.tryResolve(info, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo_1 = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
|
|
131055
|
-
var isDefaultExport = exportInfo_1.exportKind === 1 /* Default */;
|
|
131056
|
-
var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo_1.symbol) || exportInfo_1.symbol;
|
|
131057
|
-
pushAutoImportSymbol(symbol, {
|
|
131058
|
-
kind: moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
|
|
131059
|
-
moduleSpecifier: moduleSpecifier,
|
|
131060
|
-
symbolName: symbolName,
|
|
131061
|
-
exportMapKey: exportMapKey,
|
|
131062
|
-
exportName: exportInfo_1.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : exportInfo_1.symbol.name,
|
|
131063
|
-
fileName: exportInfo_1.moduleFileName,
|
|
131064
|
-
isDefaultExport: isDefaultExport,
|
|
131065
|
-
moduleSymbol: exportInfo_1.moduleSymbol,
|
|
131066
|
-
isFromPackageJson: exportInfo_1.isFromPackageJson,
|
|
131067
|
-
});
|
|
131068
131091
|
}
|
|
131092
|
+
var defaultExportInfo = ts.find(info, isImportableExportInfo);
|
|
131093
|
+
if (!defaultExportInfo) {
|
|
131094
|
+
return;
|
|
131095
|
+
}
|
|
131096
|
+
// If we don't need to resolve module specifiers, we can use any re-export that is importable at all
|
|
131097
|
+
// (We need to ensure that at least one is importable to show a completion.)
|
|
131098
|
+
var _a = context.tryResolve(info, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
|
|
131099
|
+
var isDefaultExport = exportInfo.exportKind === 1 /* Default */;
|
|
131100
|
+
var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo.symbol) || exportInfo.symbol;
|
|
131101
|
+
pushAutoImportSymbol(symbol, {
|
|
131102
|
+
kind: moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
|
|
131103
|
+
moduleSpecifier: moduleSpecifier,
|
|
131104
|
+
symbolName: symbolName,
|
|
131105
|
+
exportMapKey: exportMapKey,
|
|
131106
|
+
exportName: exportInfo.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : exportInfo.symbol.name,
|
|
131107
|
+
fileName: exportInfo.moduleFileName,
|
|
131108
|
+
isDefaultExport: isDefaultExport,
|
|
131109
|
+
moduleSymbol: exportInfo.moduleSymbol,
|
|
131110
|
+
isFromPackageJson: exportInfo.isFromPackageJson,
|
|
131111
|
+
});
|
|
131069
131112
|
});
|
|
131070
131113
|
hasUnresolvedAutoImports = context.resolutionLimitExceeded();
|
|
131071
131114
|
});
|
|
@@ -137004,7 +137047,27 @@ var ts;
|
|
|
137004
137047
|
case 326 /* JSDocAugmentsTag */:
|
|
137005
137048
|
return withNode(tag.class);
|
|
137006
137049
|
case 342 /* JSDocTemplateTag */:
|
|
137007
|
-
|
|
137050
|
+
var templateTag = tag;
|
|
137051
|
+
var displayParts_3 = [];
|
|
137052
|
+
if (templateTag.constraint) {
|
|
137053
|
+
displayParts_3.push(ts.textPart(templateTag.constraint.getText()));
|
|
137054
|
+
}
|
|
137055
|
+
if (ts.length(templateTag.typeParameters)) {
|
|
137056
|
+
if (ts.length(displayParts_3)) {
|
|
137057
|
+
displayParts_3.push(ts.spacePart());
|
|
137058
|
+
}
|
|
137059
|
+
var lastTypeParameter_1 = templateTag.typeParameters[templateTag.typeParameters.length - 1];
|
|
137060
|
+
ts.forEach(templateTag.typeParameters, function (tp) {
|
|
137061
|
+
displayParts_3.push(namePart(tp.getText()));
|
|
137062
|
+
if (lastTypeParameter_1 !== tp) {
|
|
137063
|
+
displayParts_3.push.apply(displayParts_3, [ts.punctuationPart(27 /* CommaToken */), ts.spacePart()]);
|
|
137064
|
+
}
|
|
137065
|
+
});
|
|
137066
|
+
}
|
|
137067
|
+
if (comment) {
|
|
137068
|
+
displayParts_3.push.apply(displayParts_3, __spreadArray([ts.spacePart()], getDisplayPartsFromComment(comment, checker), true));
|
|
137069
|
+
}
|
|
137070
|
+
return displayParts_3;
|
|
137008
137071
|
case 341 /* JSDocTypeTag */:
|
|
137009
137072
|
return withNode(tag.typeExpression);
|
|
137010
137073
|
case 343 /* JSDocTypedefTag */:
|
|
@@ -140430,12 +140493,12 @@ var ts;
|
|
|
140430
140493
|
: { invocation: info.invocation.node, argumentCount: info.argumentCount, argumentIndex: info.argumentIndex };
|
|
140431
140494
|
}
|
|
140432
140495
|
SignatureHelp.getArgumentInfoForCompletions = getArgumentInfoForCompletions;
|
|
140433
|
-
function getArgumentOrParameterListInfo(node, sourceFile) {
|
|
140496
|
+
function getArgumentOrParameterListInfo(node, position, sourceFile) {
|
|
140434
140497
|
var info = getArgumentOrParameterListAndIndex(node, sourceFile);
|
|
140435
140498
|
if (!info)
|
|
140436
140499
|
return undefined;
|
|
140437
140500
|
var list = info.list, argumentIndex = info.argumentIndex;
|
|
140438
|
-
var argumentCount = getArgumentCount(list);
|
|
140501
|
+
var argumentCount = getArgumentCount(list, /*ignoreTrailingComma*/ ts.isInString(sourceFile, position, node));
|
|
140439
140502
|
if (argumentIndex !== 0) {
|
|
140440
140503
|
ts.Debug.assertLessThan(argumentIndex, argumentCount);
|
|
140441
140504
|
}
|
|
@@ -140481,7 +140544,7 @@ var ts;
|
|
|
140481
140544
|
// Case 3:
|
|
140482
140545
|
// foo<T#, U#>(a#, #b#) -> The token is buried inside a list, and should give signature help
|
|
140483
140546
|
// Find out if 'node' is an argument, a type argument, or neither
|
|
140484
|
-
var info = getArgumentOrParameterListInfo(node, sourceFile);
|
|
140547
|
+
var info = getArgumentOrParameterListInfo(node, position, sourceFile);
|
|
140485
140548
|
if (!info)
|
|
140486
140549
|
return undefined;
|
|
140487
140550
|
var list = info.list, argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
|
|
@@ -140550,8 +140613,8 @@ var ts;
|
|
|
140550
140613
|
function countBinaryExpressionParameters(b) {
|
|
140551
140614
|
return ts.isBinaryExpression(b.left) ? countBinaryExpressionParameters(b.left) + 1 : 2;
|
|
140552
140615
|
}
|
|
140553
|
-
function tryGetParameterInfo(startingToken,
|
|
140554
|
-
var info = getContextualSignatureLocationInfo(startingToken, sourceFile, checker);
|
|
140616
|
+
function tryGetParameterInfo(startingToken, position, sourceFile, checker) {
|
|
140617
|
+
var info = getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker);
|
|
140555
140618
|
if (!info)
|
|
140556
140619
|
return undefined;
|
|
140557
140620
|
var contextualType = info.contextualType, argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
|
|
@@ -140563,7 +140626,7 @@ var ts;
|
|
|
140563
140626
|
var invocation = { kind: 2 /* Contextual */, signature: ts.first(signatures), node: startingToken, symbol: chooseBetterSymbol(nonNullableContextualType.symbol) };
|
|
140564
140627
|
return { isTypeParameterList: false, invocation: invocation, argumentsSpan: argumentsSpan, argumentIndex: argumentIndex, argumentCount: argumentCount };
|
|
140565
140628
|
}
|
|
140566
|
-
function getContextualSignatureLocationInfo(startingToken, sourceFile, checker) {
|
|
140629
|
+
function getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker) {
|
|
140567
140630
|
if (startingToken.kind !== 20 /* OpenParenToken */ && startingToken.kind !== 27 /* CommaToken */)
|
|
140568
140631
|
return undefined;
|
|
140569
140632
|
var parent = startingToken.parent;
|
|
@@ -140572,7 +140635,7 @@ var ts;
|
|
|
140572
140635
|
case 168 /* MethodDeclaration */:
|
|
140573
140636
|
case 212 /* FunctionExpression */:
|
|
140574
140637
|
case 213 /* ArrowFunction */:
|
|
140575
|
-
var info = getArgumentOrParameterListInfo(startingToken, sourceFile);
|
|
140638
|
+
var info = getArgumentOrParameterListInfo(startingToken, position, sourceFile);
|
|
140576
140639
|
if (!info)
|
|
140577
140640
|
return undefined;
|
|
140578
140641
|
var argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
|
|
@@ -140619,7 +140682,7 @@ var ts;
|
|
|
140619
140682
|
}
|
|
140620
140683
|
return argumentIndex;
|
|
140621
140684
|
}
|
|
140622
|
-
function getArgumentCount(argumentsList) {
|
|
140685
|
+
function getArgumentCount(argumentsList, ignoreTrailingComma) {
|
|
140623
140686
|
// The argument count for a list is normally the number of non-comma children it has.
|
|
140624
140687
|
// For example, if you have "Foo(a,b)" then there will be three children of the arg
|
|
140625
140688
|
// list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
|
|
@@ -140633,7 +140696,7 @@ var ts;
|
|
|
140633
140696
|
// arg count of 3.
|
|
140634
140697
|
var listChildren = argumentsList.getChildren();
|
|
140635
140698
|
var argumentCount = ts.countWhere(listChildren, function (arg) { return arg.kind !== 27 /* CommaToken */; });
|
|
140636
|
-
if (listChildren.length > 0 && ts.last(listChildren).kind === 27 /* CommaToken */) {
|
|
140699
|
+
if (!ignoreTrailingComma && listChildren.length > 0 && ts.last(listChildren).kind === 27 /* CommaToken */) {
|
|
140637
140700
|
argumentCount++;
|
|
140638
140701
|
}
|
|
140639
140702
|
return argumentCount;
|
|
@@ -155632,51 +155695,53 @@ var ts;
|
|
|
155632
155695
|
(function (ts) {
|
|
155633
155696
|
var refactor;
|
|
155634
155697
|
(function (refactor) {
|
|
155698
|
+
var _a;
|
|
155635
155699
|
var refactorName = "Convert import";
|
|
155636
|
-
var
|
|
155637
|
-
|
|
155638
|
-
|
|
155639
|
-
|
|
155640
|
-
|
|
155641
|
-
|
|
155642
|
-
|
|
155643
|
-
|
|
155644
|
-
|
|
155645
|
-
|
|
155700
|
+
var actions = (_a = {},
|
|
155701
|
+
_a[0 /* Named */] = {
|
|
155702
|
+
name: "Convert namespace import to named imports",
|
|
155703
|
+
description: ts.Diagnostics.Convert_namespace_import_to_named_imports.message,
|
|
155704
|
+
kind: "refactor.rewrite.import.named",
|
|
155705
|
+
},
|
|
155706
|
+
_a[2 /* Namespace */] = {
|
|
155707
|
+
name: "Convert named imports to namespace import",
|
|
155708
|
+
description: ts.Diagnostics.Convert_named_imports_to_namespace_import.message,
|
|
155709
|
+
kind: "refactor.rewrite.import.namespace",
|
|
155710
|
+
},
|
|
155711
|
+
_a[1 /* Default */] = {
|
|
155712
|
+
name: "Convert named imports to default import",
|
|
155713
|
+
description: ts.Diagnostics.Convert_named_imports_to_default_import.message,
|
|
155714
|
+
kind: "refactor.rewrite.import.default",
|
|
155715
|
+
},
|
|
155716
|
+
_a);
|
|
155646
155717
|
refactor.registerRefactor(refactorName, {
|
|
155647
|
-
kinds:
|
|
155648
|
-
namespaceToNamedAction.kind,
|
|
155649
|
-
namedToNamespaceAction.kind
|
|
155650
|
-
],
|
|
155718
|
+
kinds: ts.getOwnValues(actions).map(function (a) { return a.kind; }),
|
|
155651
155719
|
getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
|
|
155652
|
-
var info =
|
|
155720
|
+
var info = getImportConversionInfo(context, context.triggerReason === "invoked");
|
|
155653
155721
|
if (!info)
|
|
155654
155722
|
return ts.emptyArray;
|
|
155655
155723
|
if (!refactor.isRefactorErrorInfo(info)) {
|
|
155656
|
-
var
|
|
155657
|
-
var action = namespaceImport ? namespaceToNamedAction : namedToNamespaceAction;
|
|
155724
|
+
var action = actions[info.convertTo];
|
|
155658
155725
|
return [{ name: refactorName, description: action.description, actions: [action] }];
|
|
155659
155726
|
}
|
|
155660
155727
|
if (context.preferences.provideRefactorNotApplicableReason) {
|
|
155661
|
-
return
|
|
155662
|
-
|
|
155663
|
-
|
|
155664
|
-
|
|
155665
|
-
|
|
155666
|
-
];
|
|
155728
|
+
return ts.getOwnValues(actions).map(function (action) { return ({
|
|
155729
|
+
name: refactorName,
|
|
155730
|
+
description: action.description,
|
|
155731
|
+
actions: [__assign(__assign({}, action), { notApplicableReason: info.error })]
|
|
155732
|
+
}); });
|
|
155667
155733
|
}
|
|
155668
155734
|
return ts.emptyArray;
|
|
155669
155735
|
},
|
|
155670
155736
|
getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
|
|
155671
|
-
ts.Debug.assert(
|
|
155672
|
-
var info =
|
|
155737
|
+
ts.Debug.assert(ts.some(ts.getOwnValues(actions), function (action) { return action.name === actionName; }), "Unexpected action name");
|
|
155738
|
+
var info = getImportConversionInfo(context);
|
|
155673
155739
|
ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
|
|
155674
155740
|
var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, t, info); });
|
|
155675
155741
|
return { edits: edits, renameFilename: undefined, renameLocation: undefined };
|
|
155676
155742
|
}
|
|
155677
155743
|
});
|
|
155678
|
-
|
|
155679
|
-
function getImportToConvert(context, considerPartialSpans) {
|
|
155744
|
+
function getImportConversionInfo(context, considerPartialSpans) {
|
|
155680
155745
|
if (considerPartialSpans === void 0) { considerPartialSpans = true; }
|
|
155681
155746
|
var file = context.file;
|
|
155682
155747
|
var span = ts.getRefactorContextSpan(context);
|
|
@@ -155695,15 +155760,23 @@ var ts;
|
|
|
155695
155760
|
if (!importClause.namedBindings) {
|
|
155696
155761
|
return { error: ts.getLocaleSpecificMessage(ts.Diagnostics.Could_not_find_namespace_import_or_named_imports) };
|
|
155697
155762
|
}
|
|
155698
|
-
|
|
155763
|
+
if (importClause.namedBindings.kind === 267 /* NamespaceImport */) {
|
|
155764
|
+
return { convertTo: 0 /* Named */, import: importClause.namedBindings };
|
|
155765
|
+
}
|
|
155766
|
+
var compilerOptions = context.program.getCompilerOptions();
|
|
155767
|
+
var shouldUseDefault = ts.getAllowSyntheticDefaultImports(compilerOptions)
|
|
155768
|
+
&& isExportEqualsModule(importClause.parent.moduleSpecifier, context.program.getTypeChecker());
|
|
155769
|
+
return shouldUseDefault
|
|
155770
|
+
? { convertTo: 1 /* Default */, import: importClause.namedBindings }
|
|
155771
|
+
: { convertTo: 2 /* Namespace */, import: importClause.namedBindings };
|
|
155699
155772
|
}
|
|
155700
|
-
function doChange(sourceFile, program, changes,
|
|
155773
|
+
function doChange(sourceFile, program, changes, info) {
|
|
155701
155774
|
var checker = program.getTypeChecker();
|
|
155702
|
-
if (
|
|
155703
|
-
doChangeNamespaceToNamed(sourceFile, checker, changes,
|
|
155775
|
+
if (info.convertTo === 0 /* Named */) {
|
|
155776
|
+
doChangeNamespaceToNamed(sourceFile, checker, changes, info.import, ts.getAllowSyntheticDefaultImports(program.getCompilerOptions()));
|
|
155704
155777
|
}
|
|
155705
155778
|
else {
|
|
155706
|
-
|
|
155779
|
+
doChangeNamedToNamespaceOrDefault(sourceFile, checker, changes, info.import, info.convertTo === 1 /* Default */);
|
|
155707
155780
|
}
|
|
155708
155781
|
}
|
|
155709
155782
|
function doChangeNamespaceToNamed(sourceFile, checker, changes, toConvert, allowSyntheticDefaultImports) {
|
|
@@ -155753,7 +155826,7 @@ var ts;
|
|
|
155753
155826
|
function getLeftOfPropertyAccessOrQualifiedName(propertyAccessOrQualifiedName) {
|
|
155754
155827
|
return ts.isPropertyAccessExpression(propertyAccessOrQualifiedName) ? propertyAccessOrQualifiedName.expression : propertyAccessOrQualifiedName.left;
|
|
155755
155828
|
}
|
|
155756
|
-
function
|
|
155829
|
+
function doChangeNamedToNamespaceOrDefault(sourceFile, checker, changes, toConvert, shouldUseDefault) {
|
|
155757
155830
|
var importDecl = toConvert.parent.parent;
|
|
155758
155831
|
var moduleSpecifier = importDecl.moduleSpecifier;
|
|
155759
155832
|
var toConvertSymbols = new ts.Set();
|
|
@@ -155804,7 +155877,9 @@ var ts;
|
|
|
155804
155877
|
var element = _a[_i];
|
|
155805
155878
|
_loop_17(element);
|
|
155806
155879
|
}
|
|
155807
|
-
changes.replaceNode(sourceFile, toConvert,
|
|
155880
|
+
changes.replaceNode(sourceFile, toConvert, shouldUseDefault
|
|
155881
|
+
? ts.factory.createIdentifier(namespaceImportName)
|
|
155882
|
+
: ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
|
|
155808
155883
|
if (neededNamedImports.size) {
|
|
155809
155884
|
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
|
|
155810
155885
|
return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
@@ -155812,6 +155887,13 @@ var ts;
|
|
|
155812
155887
|
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
|
|
155813
155888
|
}
|
|
155814
155889
|
}
|
|
155890
|
+
function isExportEqualsModule(moduleSpecifier, checker) {
|
|
155891
|
+
var externalModule = checker.resolveExternalModuleName(moduleSpecifier);
|
|
155892
|
+
if (!externalModule)
|
|
155893
|
+
return false;
|
|
155894
|
+
var exportEquals = checker.resolveExternalModuleSymbol(externalModule);
|
|
155895
|
+
return externalModule !== exportEquals;
|
|
155896
|
+
}
|
|
155815
155897
|
function updateImport(old, defaultImportName, elements) {
|
|
155816
155898
|
return ts.factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? ts.factory.createNamedImports(elements) : undefined), old.moduleSpecifier, /*assertClause*/ undefined);
|
|
155817
155899
|
}
|