@typescript-deploys/pr-build 4.5.0-pr-46071-5 → 4.5.0-pr-46071-13
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 +17 -4
- package/lib/de/diagnosticMessages.generated.json +19 -5
- package/lib/es/diagnosticMessages.generated.json +17 -4
- package/lib/fr/diagnosticMessages.generated.json +17 -4
- package/lib/it/diagnosticMessages.generated.json +17 -4
- package/lib/ja/diagnosticMessages.generated.json +17 -4
- package/lib/ko/diagnosticMessages.generated.json +17 -4
- package/lib/lib.dom.d.ts +669 -1896
- package/lib/lib.dom.iterable.d.ts +16 -48
- package/lib/lib.es5.d.ts +10 -10
- package/lib/lib.webworker.d.ts +183 -520
- package/lib/lib.webworker.iterable.d.ts +10 -30
- package/lib/pl/diagnosticMessages.generated.json +17 -4
- package/lib/pt-br/diagnosticMessages.generated.json +17 -4
- package/lib/ru/diagnosticMessages.generated.json +17 -4
- package/lib/tr/diagnosticMessages.generated.json +17 -4
- package/lib/tsc.js +522 -322
- package/lib/tsserver.js +1015 -514
- package/lib/tsserverlibrary.d.ts +11 -8
- package/lib/tsserverlibrary.js +1015 -514
- package/lib/typescript.d.ts +11 -8
- package/lib/typescript.js +1015 -514
- package/lib/typescriptServices.d.ts +11 -8
- package/lib/typescriptServices.js +1015 -514
- package/lib/typingsInstaller.js +588 -331
- package/lib/zh-cn/diagnosticMessages.generated.json +17 -4
- package/lib/zh-tw/diagnosticMessages.generated.json +17 -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-insiders.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-insiders.20211001";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -5154,6 +5154,7 @@ var ts;
|
|
|
5154
5154
|
// module kind).
|
|
5155
5155
|
ModuleKind[ModuleKind["ES2015"] = 5] = "ES2015";
|
|
5156
5156
|
ModuleKind[ModuleKind["ES2020"] = 6] = "ES2020";
|
|
5157
|
+
ModuleKind[ModuleKind["ES2022"] = 7] = "ES2022";
|
|
5157
5158
|
ModuleKind[ModuleKind["ESNext"] = 99] = "ESNext";
|
|
5158
5159
|
// Node12+ is an amalgam of commonjs (albeit updated) and es2020+, and represents a distinct module system from es2020/esnext
|
|
5159
5160
|
ModuleKind[ModuleKind["Node12"] = 100] = "Node12";
|
|
@@ -8071,7 +8072,7 @@ var ts;
|
|
|
8071
8072
|
Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: diag(1320, ts.DiagnosticCategory.Error, "Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member_1320", "Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member."),
|
|
8072
8073
|
Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: diag(1321, ts.DiagnosticCategory.Error, "Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321", "Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member."),
|
|
8073
8074
|
Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: diag(1322, ts.DiagnosticCategory.Error, "Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_con_1322", "Type of iterated elements of a 'yield*' operand must either be a valid promise or must not contain a callable 'then' member."),
|
|
8074
|
-
|
|
8075
|
+
Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node12_or_nodenext: diag(1323, ts.DiagnosticCategory.Error, "Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd__1323", "Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'."),
|
|
8075
8076
|
Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext: diag(1324, ts.DiagnosticCategory.Error, "Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_1324", "Dynamic imports only support a second argument when the '--module' option is set to 'esnext'."),
|
|
8076
8077
|
Argument_of_dynamic_import_cannot_be_spread_element: diag(1325, ts.DiagnosticCategory.Error, "Argument_of_dynamic_import_cannot_be_spread_element_1325", "Argument of dynamic import cannot be spread element."),
|
|
8077
8078
|
Dynamic_import_cannot_have_type_arguments: diag(1326, ts.DiagnosticCategory.Error, "Dynamic_import_cannot_have_type_arguments_1326", "Dynamic import cannot have type arguments."),
|
|
@@ -8089,7 +8090,7 @@ var ts;
|
|
|
8089
8090
|
Module_0_does_not_refer_to_a_value_but_is_used_as_a_value_here: diag(1339, ts.DiagnosticCategory.Error, "Module_0_does_not_refer_to_a_value_but_is_used_as_a_value_here_1339", "Module '{0}' does not refer to a value, but is used as a value here."),
|
|
8090
8091
|
Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0: diag(1340, ts.DiagnosticCategory.Error, "Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0_1340", "Module '{0}' does not refer to a type, but is used as a type here. Did you mean 'typeof import('{0}')'?"),
|
|
8091
8092
|
Type_arguments_cannot_be_used_here: diag(1342, ts.DiagnosticCategory.Error, "Type_arguments_cannot_be_used_here_1342", "Type arguments cannot be used here."),
|
|
8092
|
-
|
|
8093
|
+
The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext: diag(1343, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system__1343", "The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'."),
|
|
8093
8094
|
A_label_is_not_allowed_here: diag(1344, ts.DiagnosticCategory.Error, "A_label_is_not_allowed_here_1344", "'A label is not allowed here."),
|
|
8094
8095
|
An_expression_of_type_void_cannot_be_tested_for_truthiness: diag(1345, ts.DiagnosticCategory.Error, "An_expression_of_type_void_cannot_be_tested_for_truthiness_1345", "An expression of type 'void' cannot be tested for truthiness."),
|
|
8095
8096
|
This_parameter_is_not_allowed_with_use_strict_directive: diag(1346, ts.DiagnosticCategory.Error, "This_parameter_is_not_allowed_with_use_strict_directive_1346", "This parameter is not allowed with 'use strict' directive."),
|
|
@@ -8120,7 +8121,7 @@ var ts;
|
|
|
8120
8121
|
await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(1375, ts.DiagnosticCategory.Error, "await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_fi_1375", "'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
|
|
8121
8122
|
_0_was_imported_here: diag(1376, ts.DiagnosticCategory.Message, "_0_was_imported_here_1376", "'{0}' was imported here."),
|
|
8122
8123
|
_0_was_exported_here: diag(1377, ts.DiagnosticCategory.Message, "_0_was_exported_here_1377", "'{0}' was exported here."),
|
|
8123
|
-
|
|
8124
|
+
Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(1378, ts.DiagnosticCategory.Error, "Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_o_1378", "Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
|
|
8124
8125
|
An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type: diag(1379, ts.DiagnosticCategory.Error, "An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type_1379", "An import alias cannot reference a declaration that was exported using 'export type'."),
|
|
8125
8126
|
An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type: diag(1380, ts.DiagnosticCategory.Error, "An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type_1380", "An import alias cannot reference a declaration that was imported using 'import type'."),
|
|
8126
8127
|
Unexpected_token_Did_you_mean_or_rbrace: diag(1381, ts.DiagnosticCategory.Error, "Unexpected_token_Did_you_mean_or_rbrace_1381", "Unexpected token. Did you mean `{'}'}` or `}`?"),
|
|
@@ -8172,7 +8173,7 @@ var ts;
|
|
|
8172
8173
|
File_redirects_to_file_0: diag(1429, ts.DiagnosticCategory.Message, "File_redirects_to_file_0_1429", "File redirects to file '{0}'"),
|
|
8173
8174
|
The_file_is_in_the_program_because_Colon: diag(1430, ts.DiagnosticCategory.Message, "The_file_is_in_the_program_because_Colon_1430", "The file is in the program because:"),
|
|
8174
8175
|
for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(1431, ts.DiagnosticCategory.Error, "for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_1431", "'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
|
|
8175
|
-
|
|
8176
|
+
Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(1432, ts.DiagnosticCategory.Error, "Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or__1432", "Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
|
|
8176
8177
|
Decorators_may_not_be_applied_to_this_parameters: diag(1433, ts.DiagnosticCategory.Error, "Decorators_may_not_be_applied_to_this_parameters_1433", "Decorators may not be applied to 'this' parameters."),
|
|
8177
8178
|
Unexpected_keyword_or_identifier: diag(1434, ts.DiagnosticCategory.Error, "Unexpected_keyword_or_identifier_1434", "Unexpected keyword or identifier."),
|
|
8178
8179
|
Unknown_keyword_or_identifier_Did_you_mean_0: diag(1435, ts.DiagnosticCategory.Error, "Unknown_keyword_or_identifier_Did_you_mean_0_1435", "Unknown keyword or identifier. Did you mean '{0}'?"),
|
|
@@ -8198,6 +8199,8 @@ var ts;
|
|
|
8198
8199
|
Construct_signature_return_types_0_and_1_are_incompatible: diag(2203, ts.DiagnosticCategory.Error, "Construct_signature_return_types_0_and_1_are_incompatible_2203", "Construct signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8199
8200
|
Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2204, ts.DiagnosticCategory.Error, "Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2204", "Call signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8200
8201
|
Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2205, ts.DiagnosticCategory.Error, "Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2205", "Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
8202
|
+
The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement: diag(2206, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206", "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
|
|
8203
|
+
The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement: diag(2207, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207", "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
|
|
8201
8204
|
Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
|
|
8202
8205
|
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
|
|
8203
8206
|
Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
|
|
@@ -12985,7 +12988,7 @@ var ts;
|
|
|
12985
12988
|
switch (node.kind) {
|
|
12986
12989
|
case 269 /* ImportSpecifier */:
|
|
12987
12990
|
case 274 /* ExportSpecifier */:
|
|
12988
|
-
return node.parent.parent.isTypeOnly;
|
|
12991
|
+
return node.isTypeOnly || node.parent.parent.isTypeOnly;
|
|
12989
12992
|
case 267 /* NamespaceImport */:
|
|
12990
12993
|
return node.parent.isTypeOnly;
|
|
12991
12994
|
case 266 /* ImportClause */:
|
|
@@ -19623,6 +19626,7 @@ var ts;
|
|
|
19623
19626
|
case ts.ModuleKind.AMD:
|
|
19624
19627
|
case ts.ModuleKind.ES2015:
|
|
19625
19628
|
case ts.ModuleKind.ES2020:
|
|
19629
|
+
case ts.ModuleKind.ES2022:
|
|
19626
19630
|
case ts.ModuleKind.ESNext:
|
|
19627
19631
|
return true;
|
|
19628
19632
|
default:
|
|
@@ -19796,7 +19800,8 @@ var ts;
|
|
|
19796
19800
|
var aParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(a, cwd));
|
|
19797
19801
|
var bParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(b, cwd));
|
|
19798
19802
|
var isDirectory = false;
|
|
19799
|
-
while (
|
|
19803
|
+
while (aParts.length >= 2 && bParts.length >= 2 &&
|
|
19804
|
+
!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
|
19800
19805
|
!isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) &&
|
|
19801
19806
|
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
|
|
19802
19807
|
aParts.pop();
|
|
@@ -19808,7 +19813,7 @@ var ts;
|
|
|
19808
19813
|
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
|
19809
19814
|
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
|
19810
19815
|
function isNodeModulesOrScopedPackageDirectory(s, getCanonicalFileName) {
|
|
19811
|
-
return getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@");
|
|
19816
|
+
return s !== undefined && (getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@"));
|
|
19812
19817
|
}
|
|
19813
19818
|
function stripLeadingDirectorySeparator(s) {
|
|
19814
19819
|
return ts.isAnyDirectorySeparator(s.charCodeAt(0)) ? s.slice(1) : undefined;
|
|
@@ -20439,10 +20444,6 @@ var ts;
|
|
|
20439
20444
|
|| !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
|
|
20440
20445
|
}
|
|
20441
20446
|
ts.isValidTypeOnlyAliasUseSite = isValidTypeOnlyAliasUseSite;
|
|
20442
|
-
function typeOnlyDeclarationIsExport(typeOnlyDeclaration) {
|
|
20443
|
-
return typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
20444
|
-
}
|
|
20445
|
-
ts.typeOnlyDeclarationIsExport = typeOnlyDeclarationIsExport;
|
|
20446
20447
|
function isShorthandPropertyNameUseSite(useSite) {
|
|
20447
20448
|
return ts.isIdentifier(useSite) && ts.isShorthandPropertyAssignment(useSite.parent) && useSite.parent.name === useSite;
|
|
20448
20449
|
}
|
|
@@ -20730,6 +20731,10 @@ var ts;
|
|
|
20730
20731
|
return !!declaration && (ts.isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
|
|
20731
20732
|
}
|
|
20732
20733
|
ts.isParameterOrCatchClauseVariable = isParameterOrCatchClauseVariable;
|
|
20734
|
+
function isFunctionExpressionOrArrowFunction(node) {
|
|
20735
|
+
return node.kind === 212 /* FunctionExpression */ || node.kind === 213 /* ArrowFunction */;
|
|
20736
|
+
}
|
|
20737
|
+
ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
|
|
20733
20738
|
})(ts || (ts = {}));
|
|
20734
20739
|
/* @internal */
|
|
20735
20740
|
var ts;
|
|
@@ -24464,8 +24469,9 @@ var ts;
|
|
|
24464
24469
|
: node;
|
|
24465
24470
|
}
|
|
24466
24471
|
// @api
|
|
24467
|
-
function createImportSpecifier(propertyName, name) {
|
|
24472
|
+
function createImportSpecifier(isTypeOnly, propertyName, name) {
|
|
24468
24473
|
var node = createBaseNode(269 /* ImportSpecifier */);
|
|
24474
|
+
node.isTypeOnly = isTypeOnly;
|
|
24469
24475
|
node.propertyName = propertyName;
|
|
24470
24476
|
node.name = name;
|
|
24471
24477
|
node.transformFlags |=
|
|
@@ -24475,10 +24481,11 @@ var ts;
|
|
|
24475
24481
|
return node;
|
|
24476
24482
|
}
|
|
24477
24483
|
// @api
|
|
24478
|
-
function updateImportSpecifier(node, propertyName, name) {
|
|
24479
|
-
return node.
|
|
24484
|
+
function updateImportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24485
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24486
|
+
|| node.propertyName !== propertyName
|
|
24480
24487
|
|| node.name !== name
|
|
24481
|
-
? update(createImportSpecifier(propertyName, name), node)
|
|
24488
|
+
? update(createImportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24482
24489
|
: node;
|
|
24483
24490
|
}
|
|
24484
24491
|
// @api
|
|
@@ -24539,8 +24546,9 @@ var ts;
|
|
|
24539
24546
|
: node;
|
|
24540
24547
|
}
|
|
24541
24548
|
// @api
|
|
24542
|
-
function createExportSpecifier(propertyName, name) {
|
|
24549
|
+
function createExportSpecifier(isTypeOnly, propertyName, name) {
|
|
24543
24550
|
var node = createBaseNode(274 /* ExportSpecifier */);
|
|
24551
|
+
node.isTypeOnly = isTypeOnly;
|
|
24544
24552
|
node.propertyName = asName(propertyName);
|
|
24545
24553
|
node.name = asName(name);
|
|
24546
24554
|
node.transformFlags |=
|
|
@@ -24550,10 +24558,11 @@ var ts;
|
|
|
24550
24558
|
return node;
|
|
24551
24559
|
}
|
|
24552
24560
|
// @api
|
|
24553
|
-
function updateExportSpecifier(node, propertyName, name) {
|
|
24554
|
-
return node.
|
|
24561
|
+
function updateExportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24562
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24563
|
+
|| node.propertyName !== propertyName
|
|
24555
24564
|
|| node.name !== name
|
|
24556
|
-
? update(createExportSpecifier(propertyName, name), node)
|
|
24565
|
+
? update(createExportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24557
24566
|
: node;
|
|
24558
24567
|
}
|
|
24559
24568
|
// @api
|
|
@@ -25661,7 +25670,7 @@ var ts;
|
|
|
25661
25670
|
/*decorators*/ undefined,
|
|
25662
25671
|
/*modifiers*/ undefined,
|
|
25663
25672
|
/*isTypeOnly*/ false, createNamedExports([
|
|
25664
|
-
createExportSpecifier(/*propertyName*/ undefined, exportName)
|
|
25673
|
+
createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, exportName)
|
|
25665
25674
|
]));
|
|
25666
25675
|
}
|
|
25667
25676
|
//
|
|
@@ -28928,8 +28937,8 @@ var ts;
|
|
|
28928
28937
|
// Alias the imports if the names are used somewhere in the file.
|
|
28929
28938
|
// NOTE: We don't need to care about global import collisions as this is a module.
|
|
28930
28939
|
namedBindings = nodeFactory.createNamedImports(ts.map(helperNames, function (name) { return ts.isFileLevelUniqueName(sourceFile, name)
|
|
28931
|
-
? nodeFactory.createImportSpecifier(/*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
28932
|
-
: nodeFactory.createImportSpecifier(nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
28940
|
+
? nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
28941
|
+
: nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
28933
28942
|
var parseNode = ts.getOriginalNode(sourceFile, ts.isSourceFile);
|
|
28934
28943
|
var emitNode = ts.getOrCreateEmitNode(parseNode);
|
|
28935
28944
|
emitNode.externalHelpers = true;
|
|
@@ -31350,7 +31359,6 @@ var ts;
|
|
|
31350
31359
|
case 88 /* DefaultKeyword */:
|
|
31351
31360
|
return nextTokenCanFollowDefaultKeyword();
|
|
31352
31361
|
case 124 /* StaticKeyword */:
|
|
31353
|
-
return nextTokenIsOnSameLineAndCanFollowModifier();
|
|
31354
31362
|
case 136 /* GetKeyword */:
|
|
31355
31363
|
case 148 /* SetKeyword */:
|
|
31356
31364
|
nextToken();
|
|
@@ -35593,7 +35601,7 @@ var ts;
|
|
|
35593
35601
|
}
|
|
35594
35602
|
return list && createNodeArray(list, pos);
|
|
35595
35603
|
}
|
|
35596
|
-
function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
|
|
35604
|
+
function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
|
|
35597
35605
|
var pos = getNodePos();
|
|
35598
35606
|
var kind = token();
|
|
35599
35607
|
if (token() === 85 /* ConstKeyword */ && permitInvalidConstAsModifier) {
|
|
@@ -35606,6 +35614,9 @@ var ts;
|
|
|
35606
35614
|
else if (stopOnStartOfClassStaticBlock && token() === 124 /* StaticKeyword */ && lookAhead(nextTokenIsOpenBrace)) {
|
|
35607
35615
|
return undefined;
|
|
35608
35616
|
}
|
|
35617
|
+
else if (hasSeenStaticModifier && token() === 124 /* StaticKeyword */) {
|
|
35618
|
+
return undefined;
|
|
35619
|
+
}
|
|
35609
35620
|
else {
|
|
35610
35621
|
if (!parseAnyContextualModifier()) {
|
|
35611
35622
|
return undefined;
|
|
@@ -35622,8 +35633,10 @@ var ts;
|
|
|
35622
35633
|
*/
|
|
35623
35634
|
function parseModifiers(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
|
|
35624
35635
|
var pos = getNodePos();
|
|
35625
|
-
var list, modifier;
|
|
35626
|
-
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock)) {
|
|
35636
|
+
var list, modifier, hasSeenStatic = false;
|
|
35637
|
+
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
|
|
35638
|
+
if (modifier.kind === 124 /* StaticKeyword */)
|
|
35639
|
+
hasSeenStatic = true;
|
|
35627
35640
|
list = ts.append(list, modifier);
|
|
35628
35641
|
}
|
|
35629
35642
|
return list && createNodeArray(list, pos);
|
|
@@ -36056,27 +36069,74 @@ var ts;
|
|
|
36056
36069
|
var checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36057
36070
|
var checkIdentifierStart = scanner.getTokenPos();
|
|
36058
36071
|
var checkIdentifierEnd = scanner.getTextPos();
|
|
36059
|
-
var
|
|
36072
|
+
var isTypeOnly = false;
|
|
36060
36073
|
var propertyName;
|
|
36061
|
-
var
|
|
36062
|
-
|
|
36063
|
-
|
|
36064
|
-
|
|
36065
|
-
|
|
36066
|
-
|
|
36067
|
-
|
|
36068
|
-
|
|
36074
|
+
var canParseAsKeyword = true;
|
|
36075
|
+
var name = parseIdentifierName();
|
|
36076
|
+
if (name.escapedText === "type") {
|
|
36077
|
+
// If the first token of an import specifier is 'type', there are a lot of possibilities,
|
|
36078
|
+
// especially if we see 'as' afterwards:
|
|
36079
|
+
//
|
|
36080
|
+
// import { type } from "mod"; - isTypeOnly: false, name: type
|
|
36081
|
+
// import { type as } from "mod"; - isTypeOnly: true, name: as
|
|
36082
|
+
// import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
|
|
36083
|
+
// import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
|
|
36084
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36085
|
+
// { type as ...? }
|
|
36086
|
+
var firstAs = parseIdentifierName();
|
|
36087
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36088
|
+
// { type as as ...? }
|
|
36089
|
+
var secondAs = parseIdentifierName();
|
|
36090
|
+
if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36091
|
+
// { type as as something }
|
|
36092
|
+
isTypeOnly = true;
|
|
36093
|
+
propertyName = firstAs;
|
|
36094
|
+
name = parseNameWithKeywordCheck();
|
|
36095
|
+
canParseAsKeyword = false;
|
|
36096
|
+
}
|
|
36097
|
+
else {
|
|
36098
|
+
// { type as as }
|
|
36099
|
+
propertyName = name;
|
|
36100
|
+
name = secondAs;
|
|
36101
|
+
canParseAsKeyword = false;
|
|
36102
|
+
}
|
|
36103
|
+
}
|
|
36104
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36105
|
+
// { type as something }
|
|
36106
|
+
propertyName = name;
|
|
36107
|
+
canParseAsKeyword = false;
|
|
36108
|
+
name = parseNameWithKeywordCheck();
|
|
36109
|
+
}
|
|
36110
|
+
else {
|
|
36111
|
+
// { type as }
|
|
36112
|
+
isTypeOnly = true;
|
|
36113
|
+
name = firstAs;
|
|
36114
|
+
}
|
|
36115
|
+
}
|
|
36116
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36117
|
+
// { type something ...? }
|
|
36118
|
+
isTypeOnly = true;
|
|
36119
|
+
name = parseNameWithKeywordCheck();
|
|
36120
|
+
}
|
|
36069
36121
|
}
|
|
36070
|
-
|
|
36071
|
-
|
|
36122
|
+
if (canParseAsKeyword && token() === 127 /* AsKeyword */) {
|
|
36123
|
+
propertyName = name;
|
|
36124
|
+
parseExpected(127 /* AsKeyword */);
|
|
36125
|
+
name = parseNameWithKeywordCheck();
|
|
36072
36126
|
}
|
|
36073
36127
|
if (kind === 269 /* ImportSpecifier */ && checkIdentifierIsKeyword) {
|
|
36074
36128
|
parseErrorAt(checkIdentifierStart, checkIdentifierEnd, ts.Diagnostics.Identifier_expected);
|
|
36075
36129
|
}
|
|
36076
36130
|
var node = kind === 269 /* ImportSpecifier */
|
|
36077
|
-
? factory.createImportSpecifier(propertyName, name)
|
|
36078
|
-
: factory.createExportSpecifier(propertyName, name);
|
|
36131
|
+
? factory.createImportSpecifier(isTypeOnly, propertyName, name)
|
|
36132
|
+
: factory.createExportSpecifier(isTypeOnly, propertyName, name);
|
|
36079
36133
|
return finishNode(node, pos);
|
|
36134
|
+
function parseNameWithKeywordCheck() {
|
|
36135
|
+
checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36136
|
+
checkIdentifierStart = scanner.getTokenPos();
|
|
36137
|
+
checkIdentifierEnd = scanner.getTextPos();
|
|
36138
|
+
return parseIdentifierName();
|
|
36139
|
+
}
|
|
36080
36140
|
}
|
|
36081
36141
|
function parseNamespaceExport(pos) {
|
|
36082
36142
|
return finishNode(factory.createNamespaceExport(parseIdentifierName()), pos);
|
|
@@ -38281,6 +38341,7 @@ var ts;
|
|
|
38281
38341
|
es6: ts.ModuleKind.ES2015,
|
|
38282
38342
|
es2015: ts.ModuleKind.ES2015,
|
|
38283
38343
|
es2020: ts.ModuleKind.ES2020,
|
|
38344
|
+
es2022: ts.ModuleKind.ES2022,
|
|
38284
38345
|
esnext: ts.ModuleKind.ESNext,
|
|
38285
38346
|
node12: ts.ModuleKind.Node12,
|
|
38286
38347
|
nodenext: ts.ModuleKind.NodeNext,
|
|
@@ -39988,6 +40049,44 @@ var ts;
|
|
|
39988
40049
|
}
|
|
39989
40050
|
return result;
|
|
39990
40051
|
}
|
|
40052
|
+
/**
|
|
40053
|
+
* Generate a list of the compiler options whose value is not the default.
|
|
40054
|
+
* @param options compilerOptions to be evaluated.
|
|
40055
|
+
/** @internal */
|
|
40056
|
+
function getCompilerOptionsDiffValue(options, newLine) {
|
|
40057
|
+
var compilerOptionsMap = getSerializedCompilerOption(options);
|
|
40058
|
+
return getOverwrittenDefaultOptions();
|
|
40059
|
+
function makePadding(paddingLength) {
|
|
40060
|
+
return Array(paddingLength + 1).join(" ");
|
|
40061
|
+
}
|
|
40062
|
+
function getOverwrittenDefaultOptions() {
|
|
40063
|
+
var result = [];
|
|
40064
|
+
var tab = makePadding(2);
|
|
40065
|
+
commandOptionsWithoutBuild.forEach(function (cmd) {
|
|
40066
|
+
if (!compilerOptionsMap.has(cmd.name)) {
|
|
40067
|
+
return;
|
|
40068
|
+
}
|
|
40069
|
+
var newValue = compilerOptionsMap.get(cmd.name);
|
|
40070
|
+
var defaultValue = getDefaultValueForOption(cmd);
|
|
40071
|
+
if (newValue !== defaultValue) {
|
|
40072
|
+
result.push("" + tab + cmd.name + ": " + newValue);
|
|
40073
|
+
}
|
|
40074
|
+
else if (ts.hasProperty(ts.defaultInitCompilerOptions, cmd.name)) {
|
|
40075
|
+
result.push("" + tab + cmd.name + ": " + defaultValue);
|
|
40076
|
+
}
|
|
40077
|
+
});
|
|
40078
|
+
return result.join(newLine) + newLine;
|
|
40079
|
+
}
|
|
40080
|
+
}
|
|
40081
|
+
ts.getCompilerOptionsDiffValue = getCompilerOptionsDiffValue;
|
|
40082
|
+
/**
|
|
40083
|
+
* Get the compiler options to be written into the tsconfig.json.
|
|
40084
|
+
* @param options commandlineOptions to be included in the compileOptions.
|
|
40085
|
+
*/
|
|
40086
|
+
function getSerializedCompilerOption(options) {
|
|
40087
|
+
var compilerOptions = ts.extend(options, ts.defaultInitCompilerOptions);
|
|
40088
|
+
return serializeCompilerOptions(compilerOptions);
|
|
40089
|
+
}
|
|
39991
40090
|
/**
|
|
39992
40091
|
* Generate tsconfig configuration when running command line "--init"
|
|
39993
40092
|
* @param options commandlineOptions to be generated into tsconfig.json
|
|
@@ -39995,28 +40094,8 @@ var ts;
|
|
|
39995
40094
|
*/
|
|
39996
40095
|
/* @internal */
|
|
39997
40096
|
function generateTSConfig(options, fileNames, newLine) {
|
|
39998
|
-
var
|
|
39999
|
-
var compilerOptionsMap = serializeCompilerOptions(compilerOptions);
|
|
40097
|
+
var compilerOptionsMap = getSerializedCompilerOption(options);
|
|
40000
40098
|
return writeConfigurations();
|
|
40001
|
-
function getDefaultValueForOption(option) {
|
|
40002
|
-
switch (option.type) {
|
|
40003
|
-
case "number":
|
|
40004
|
-
return 1;
|
|
40005
|
-
case "boolean":
|
|
40006
|
-
return true;
|
|
40007
|
-
case "string":
|
|
40008
|
-
return option.isFilePath ? "./" : "";
|
|
40009
|
-
case "list":
|
|
40010
|
-
return [];
|
|
40011
|
-
case "object":
|
|
40012
|
-
return {};
|
|
40013
|
-
default:
|
|
40014
|
-
var iterResult = option.type.keys().next();
|
|
40015
|
-
if (!iterResult.done)
|
|
40016
|
-
return iterResult.value;
|
|
40017
|
-
return ts.Debug.fail("Expected 'option.type' to have entries.");
|
|
40018
|
-
}
|
|
40019
|
-
}
|
|
40020
40099
|
function makePadding(paddingLength) {
|
|
40021
40100
|
return Array(paddingLength + 1).join(" ");
|
|
40022
40101
|
}
|
|
@@ -41003,6 +41082,25 @@ var ts;
|
|
|
41003
41082
|
}); // TODO: GH#18217
|
|
41004
41083
|
}
|
|
41005
41084
|
}
|
|
41085
|
+
function getDefaultValueForOption(option) {
|
|
41086
|
+
switch (option.type) {
|
|
41087
|
+
case "number":
|
|
41088
|
+
return 1;
|
|
41089
|
+
case "boolean":
|
|
41090
|
+
return true;
|
|
41091
|
+
case "string":
|
|
41092
|
+
return option.isFilePath ? "./" : "";
|
|
41093
|
+
case "list":
|
|
41094
|
+
return [];
|
|
41095
|
+
case "object":
|
|
41096
|
+
return {};
|
|
41097
|
+
default:
|
|
41098
|
+
var iterResult = option.type.keys().next();
|
|
41099
|
+
if (!iterResult.done)
|
|
41100
|
+
return iterResult.value;
|
|
41101
|
+
return ts.Debug.fail("Expected 'option.type' to have entries.");
|
|
41102
|
+
}
|
|
41103
|
+
}
|
|
41006
41104
|
})(ts || (ts = {}));
|
|
41007
41105
|
var ts;
|
|
41008
41106
|
(function (ts) {
|
|
@@ -46414,6 +46512,13 @@ var ts;
|
|
|
46414
46512
|
IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
|
|
46415
46513
|
IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
|
|
46416
46514
|
})(IntersectionState || (IntersectionState = {}));
|
|
46515
|
+
var RecursionFlags;
|
|
46516
|
+
(function (RecursionFlags) {
|
|
46517
|
+
RecursionFlags[RecursionFlags["None"] = 0] = "None";
|
|
46518
|
+
RecursionFlags[RecursionFlags["Source"] = 1] = "Source";
|
|
46519
|
+
RecursionFlags[RecursionFlags["Target"] = 2] = "Target";
|
|
46520
|
+
RecursionFlags[RecursionFlags["Both"] = 3] = "Both";
|
|
46521
|
+
})(RecursionFlags || (RecursionFlags = {}));
|
|
46417
46522
|
var MappedTypeModifiers;
|
|
46418
46523
|
(function (MappedTypeModifiers) {
|
|
46419
46524
|
MappedTypeModifiers[MappedTypeModifiers["IncludeReadonly"] = 1] = "IncludeReadonly";
|
|
@@ -46475,7 +46580,6 @@ var ts;
|
|
|
46475
46580
|
Capitalize: 2 /* Capitalize */,
|
|
46476
46581
|
Uncapitalize: 3 /* Uncapitalize */
|
|
46477
46582
|
}));
|
|
46478
|
-
var DEFAULT_TYPE_CHARS_LENGTH_TO_ADD_NEW_LINES = 30;
|
|
46479
46583
|
function SymbolLinks() {
|
|
46480
46584
|
}
|
|
46481
46585
|
function NodeLinks() {
|
|
@@ -46907,6 +47011,7 @@ var ts;
|
|
|
46907
47011
|
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias: getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
|
|
46908
47012
|
isDeclarationVisible: isDeclarationVisible,
|
|
46909
47013
|
isPropertyAccessible: isPropertyAccessible,
|
|
47014
|
+
getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
|
|
46910
47015
|
};
|
|
46911
47016
|
function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode) {
|
|
46912
47017
|
var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
|
|
@@ -47176,17 +47281,9 @@ var ts;
|
|
|
47176
47281
|
}
|
|
47177
47282
|
}
|
|
47178
47283
|
else {
|
|
47179
|
-
|
|
47180
|
-
|
|
47181
|
-
|
|
47182
|
-
var jsxPragma = file.pragmas.get("jsx");
|
|
47183
|
-
if (jsxPragma) {
|
|
47184
|
-
var chosenPragma = ts.isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
|
|
47185
|
-
file.localJsxFactory = ts.parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion);
|
|
47186
|
-
ts.visitNode(file.localJsxFactory, markAsSynthetic);
|
|
47187
|
-
if (file.localJsxFactory) {
|
|
47188
|
-
return file.localJsxNamespace = ts.getFirstIdentifier(file.localJsxFactory).escapedText;
|
|
47189
|
-
}
|
|
47284
|
+
var localJsxNamespace = getLocalJsxNamespace(file);
|
|
47285
|
+
if (localJsxNamespace) {
|
|
47286
|
+
return file.localJsxNamespace = localJsxNamespace;
|
|
47190
47287
|
}
|
|
47191
47288
|
}
|
|
47192
47289
|
}
|
|
@@ -47208,10 +47305,24 @@ var ts;
|
|
|
47208
47305
|
_jsxFactoryEntity = ts.factory.createQualifiedName(ts.factory.createIdentifier(ts.unescapeLeadingUnderscores(_jsxNamespace)), "createElement");
|
|
47209
47306
|
}
|
|
47210
47307
|
return _jsxNamespace;
|
|
47211
|
-
|
|
47212
|
-
|
|
47213
|
-
|
|
47308
|
+
}
|
|
47309
|
+
function getLocalJsxNamespace(file) {
|
|
47310
|
+
if (file.localJsxNamespace) {
|
|
47311
|
+
return file.localJsxNamespace;
|
|
47214
47312
|
}
|
|
47313
|
+
var jsxPragma = file.pragmas.get("jsx");
|
|
47314
|
+
if (jsxPragma) {
|
|
47315
|
+
var chosenPragma = ts.isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
|
|
47316
|
+
file.localJsxFactory = ts.parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion);
|
|
47317
|
+
ts.visitNode(file.localJsxFactory, markAsSynthetic);
|
|
47318
|
+
if (file.localJsxFactory) {
|
|
47319
|
+
return file.localJsxNamespace = ts.getFirstIdentifier(file.localJsxFactory).escapedText;
|
|
47320
|
+
}
|
|
47321
|
+
}
|
|
47322
|
+
}
|
|
47323
|
+
function markAsSynthetic(node) {
|
|
47324
|
+
ts.setTextRangePosEnd(node, -1, -1);
|
|
47325
|
+
return ts.visitEachChild(node, markAsSynthetic, ts.nullTransformationContext);
|
|
47215
47326
|
}
|
|
47216
47327
|
function getEmitResolver(sourceFile, cancellationToken) {
|
|
47217
47328
|
// Ensure we have all the type information in place for this file so that all the
|
|
@@ -48283,8 +48394,7 @@ var ts;
|
|
|
48283
48394
|
if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
|
|
48284
48395
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
|
|
48285
48396
|
if (typeOnlyDeclaration) {
|
|
48286
|
-
var
|
|
48287
|
-
var message = isExport
|
|
48397
|
+
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48288
48398
|
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48289
48399
|
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48290
48400
|
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
@@ -48295,7 +48405,7 @@ var ts;
|
|
|
48295
48405
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
|
|
48296
48406
|
if (!typeOnlyDeclaration)
|
|
48297
48407
|
return diagnostic;
|
|
48298
|
-
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration,
|
|
48408
|
+
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration, typeOnlyDeclaration.kind === 274 /* ExportSpecifier */ ? ts.Diagnostics._0_was_exported_here : ts.Diagnostics._0_was_imported_here, unescapedName));
|
|
48299
48409
|
}
|
|
48300
48410
|
function getIsDeferredContext(location, lastLocation) {
|
|
48301
48411
|
if (location.kind !== 213 /* ArrowFunction */ && location.kind !== 212 /* FunctionExpression */) {
|
|
@@ -48619,15 +48729,13 @@ var ts;
|
|
|
48619
48729
|
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node, resolved) {
|
|
48620
48730
|
if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly) {
|
|
48621
48731
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node));
|
|
48622
|
-
var isExport =
|
|
48732
|
+
var isExport = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
48623
48733
|
var message = isExport
|
|
48624
48734
|
? ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type
|
|
48625
48735
|
: ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type;
|
|
48626
48736
|
var relatedMessage = isExport
|
|
48627
48737
|
? ts.Diagnostics._0_was_exported_here
|
|
48628
48738
|
: ts.Diagnostics._0_was_imported_here;
|
|
48629
|
-
// Non-null assertion is safe because the optionality comes from ImportClause,
|
|
48630
|
-
// but if an ImportClause was the typeOnlyDeclaration, it had to have a `name`.
|
|
48631
48739
|
var name = ts.unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText);
|
|
48632
48740
|
ts.addRelatedInfo(error(node.moduleReference, message), ts.createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name));
|
|
48633
48741
|
}
|
|
@@ -48642,7 +48750,21 @@ var ts;
|
|
|
48642
48750
|
function isSyntacticDefault(node) {
|
|
48643
48751
|
return ((ts.isExportAssignment(node) && !node.isExportEquals) || ts.hasSyntacticModifier(node, 512 /* Default */) || ts.isExportSpecifier(node));
|
|
48644
48752
|
}
|
|
48645
|
-
function
|
|
48753
|
+
function getUsageModeForExpression(usage) {
|
|
48754
|
+
return ts.isStringLiteralLike(usage) ? ts.getModeForUsageLocation(ts.getSourceFileOfNode(usage), usage) : undefined;
|
|
48755
|
+
}
|
|
48756
|
+
function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
|
|
48757
|
+
return usageMode === ts.ModuleKind.ESNext && targetMode === ts.ModuleKind.CommonJS;
|
|
48758
|
+
}
|
|
48759
|
+
function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
|
|
48760
|
+
var usageMode = file && getUsageModeForExpression(usage);
|
|
48761
|
+
if (file && usageMode !== undefined) {
|
|
48762
|
+
var result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
|
|
48763
|
+
if (usageMode === ts.ModuleKind.ESNext || result) {
|
|
48764
|
+
return result;
|
|
48765
|
+
}
|
|
48766
|
+
// fallthrough on cjs usages so we imply defaults for interop'd imports, too
|
|
48767
|
+
}
|
|
48646
48768
|
if (!allowSyntheticDefaultImports) {
|
|
48647
48769
|
return false;
|
|
48648
48770
|
}
|
|
@@ -48684,7 +48806,7 @@ var ts;
|
|
|
48684
48806
|
exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* Default */, node, dontResolveAlias);
|
|
48685
48807
|
}
|
|
48686
48808
|
var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
48687
|
-
var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias);
|
|
48809
|
+
var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier);
|
|
48688
48810
|
if (!exportDefaultSymbol && !hasSyntheticDefault) {
|
|
48689
48811
|
if (hasExportAssignmentSymbol(moduleSymbol)) {
|
|
48690
48812
|
var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
|
|
@@ -48824,7 +48946,7 @@ var ts;
|
|
|
48824
48946
|
var symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
|
|
48825
48947
|
if (symbolFromModule === undefined && name.escapedText === "default" /* Default */) {
|
|
48826
48948
|
var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
48827
|
-
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias)) {
|
|
48949
|
+
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
|
|
48828
48950
|
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
|
|
48829
48951
|
}
|
|
48830
48952
|
}
|
|
@@ -49043,13 +49165,13 @@ var ts;
|
|
|
49043
49165
|
* and issue an error if so.
|
|
49044
49166
|
*
|
|
49045
49167
|
* @param aliasDeclaration The alias declaration not marked as type-only
|
|
49168
|
+
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49169
|
+
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49170
|
+
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49046
49171
|
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
|
|
49047
49172
|
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
|
|
49048
49173
|
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
|
|
49049
49174
|
* must still be checked for a type-only marker, overwriting the previous negative result if found.
|
|
49050
|
-
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49051
|
-
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49052
|
-
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49053
49175
|
*/
|
|
49054
49176
|
function markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration, immediateTarget, finalTarget, overwriteEmpty) {
|
|
49055
49177
|
if (!aliasDeclaration || ts.isPropertyAccessExpression(aliasDeclaration))
|
|
@@ -49515,7 +49637,7 @@ var ts;
|
|
|
49515
49637
|
sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
|
|
49516
49638
|
}
|
|
49517
49639
|
if (sigs && sigs.length) {
|
|
49518
|
-
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol);
|
|
49640
|
+
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier);
|
|
49519
49641
|
// Create a new symbol which has the module's type less the call and construct signatures
|
|
49520
49642
|
var result = createSymbol(symbol.flags, symbol.escapedName);
|
|
49521
49643
|
result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
|
|
@@ -52182,7 +52304,7 @@ var ts;
|
|
|
52182
52304
|
ns = ts.factory.updateModuleDeclaration(ns, ns.decorators, ns.modifiers, ns.name, body = ts.factory.updateModuleBlock(body, ts.factory.createNodeArray(__spreadArray(__spreadArray([], ns.body.statements, true), [ts.factory.createExportDeclaration(
|
|
52183
52305
|
/*decorators*/ undefined,
|
|
52184
52306
|
/*modifiers*/ undefined,
|
|
52185
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*alias*/ undefined, id); })),
|
|
52307
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*alias*/ undefined, id); })),
|
|
52186
52308
|
/*moduleSpecifier*/ undefined)], false))));
|
|
52187
52309
|
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, nsIndex), true), [ns], false), statements.slice(nsIndex + 1), true);
|
|
52188
52310
|
}
|
|
@@ -52410,7 +52532,7 @@ var ts;
|
|
|
52410
52532
|
addResult(ts.factory.createExportDeclaration(
|
|
52411
52533
|
/*decorators*/ undefined,
|
|
52412
52534
|
/*modifiers*/ undefined,
|
|
52413
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(alias, localName)])), 0 /* None */);
|
|
52535
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, alias, localName)])), 0 /* None */);
|
|
52414
52536
|
context.tracker.trackSymbol(type.symbol, context.enclosingDeclaration, 111551 /* Value */);
|
|
52415
52537
|
}
|
|
52416
52538
|
else {
|
|
@@ -52443,7 +52565,7 @@ var ts;
|
|
|
52443
52565
|
addResult(ts.factory.createExportDeclaration(
|
|
52444
52566
|
/*decorators*/ undefined,
|
|
52445
52567
|
/*modifiers*/ undefined,
|
|
52446
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(name, localName)])), 0 /* None */);
|
|
52568
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name, localName)])), 0 /* None */);
|
|
52447
52569
|
needsExportDeclaration = false;
|
|
52448
52570
|
needsPostExportDefault = false;
|
|
52449
52571
|
}
|
|
@@ -52501,7 +52623,7 @@ var ts;
|
|
|
52501
52623
|
addResult(ts.factory.createExportDeclaration(
|
|
52502
52624
|
/*decorators*/ undefined,
|
|
52503
52625
|
/*modifiers*/ undefined,
|
|
52504
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52626
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52505
52627
|
}
|
|
52506
52628
|
}
|
|
52507
52629
|
function includePrivateSymbol(symbol) {
|
|
@@ -52623,7 +52745,7 @@ var ts;
|
|
|
52623
52745
|
var target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true);
|
|
52624
52746
|
includePrivateSymbol(target || s);
|
|
52625
52747
|
var targetName = target ? getInternalSymbolName(target, ts.unescapeLeadingUnderscores(target.escapedName)) : localName;
|
|
52626
|
-
return ts.factory.createExportSpecifier(name === targetName ? undefined : targetName, name);
|
|
52748
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name === targetName ? undefined : targetName, name);
|
|
52627
52749
|
})))]);
|
|
52628
52750
|
addResult(ts.factory.createModuleDeclaration(
|
|
52629
52751
|
/*decorators*/ undefined,
|
|
@@ -52714,7 +52836,7 @@ var ts;
|
|
|
52714
52836
|
var defaultReplaced = ts.map(declarations, function (d) { return ts.isExportAssignment(d) && !d.isExportEquals && ts.isIdentifier(d.expression) ? ts.factory.createExportDeclaration(
|
|
52715
52837
|
/*decorators*/ undefined,
|
|
52716
52838
|
/*modifiers*/ undefined,
|
|
52717
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52839
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52718
52840
|
var exportModifierStripped = ts.every(defaultReplaced, function (d) { return ts.hasSyntacticModifier(d, 1 /* Export */); }) ? ts.map(defaultReplaced, removeExportModifier) : defaultReplaced;
|
|
52719
52841
|
fakespace = ts.factory.updateModuleDeclaration(fakespace, fakespace.decorators, fakespace.modifiers, fakespace.name, ts.factory.createModuleBlock(exportModifierStripped));
|
|
52720
52842
|
addResult(fakespace, modifierFlags); // namespaces can never be default exported
|
|
@@ -52865,7 +52987,8 @@ var ts;
|
|
|
52865
52987
|
var propertyName = node.propertyName;
|
|
52866
52988
|
addResult(ts.factory.createImportDeclaration(
|
|
52867
52989
|
/*decorators*/ undefined,
|
|
52868
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
52990
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
52991
|
+
/*isTypeOnly*/ false, propertyName && ts.isIdentifier(propertyName) ? ts.factory.createIdentifier(ts.idText(propertyName)) : undefined, ts.factory.createIdentifier(localName))])), ts.factory.createStringLiteral(specifier_1),
|
|
52869
52992
|
/*importClause*/ undefined), 0 /* None */);
|
|
52870
52993
|
break;
|
|
52871
52994
|
}
|
|
@@ -52949,7 +53072,8 @@ var ts;
|
|
|
52949
53072
|
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
52950
53073
|
/*isTypeOnly*/ false,
|
|
52951
53074
|
/*importClause*/ undefined, ts.factory.createNamedImports([
|
|
52952
|
-
ts.factory.createImportSpecifier(
|
|
53075
|
+
ts.factory.createImportSpecifier(
|
|
53076
|
+
/*isTypeOnly*/ false, localName !== verbatimTargetName ? ts.factory.createIdentifier(verbatimTargetName) : undefined, ts.factory.createIdentifier(localName))
|
|
52953
53077
|
])), ts.factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)),
|
|
52954
53078
|
/*assertClause*/ undefined), 0 /* None */);
|
|
52955
53079
|
break;
|
|
@@ -52985,7 +53109,7 @@ var ts;
|
|
|
52985
53109
|
addResult(ts.factory.createExportDeclaration(
|
|
52986
53110
|
/*decorators*/ undefined,
|
|
52987
53111
|
/*modifiers*/ undefined,
|
|
52988
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53112
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
52989
53113
|
}
|
|
52990
53114
|
/**
|
|
52991
53115
|
* Returns `true` if an export assignment or declaration was produced for the symbol
|
|
@@ -56480,6 +56604,23 @@ var ts;
|
|
|
56480
56604
|
function getIsLateCheckFlag(s) {
|
|
56481
56605
|
return ts.getCheckFlags(s) & 4096 /* Late */;
|
|
56482
56606
|
}
|
|
56607
|
+
function forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(type, include, stringsOnly, cb) {
|
|
56608
|
+
for (var _i = 0, _a = getPropertiesOfType(type); _i < _a.length; _i++) {
|
|
56609
|
+
var prop = _a[_i];
|
|
56610
|
+
cb(getLiteralTypeFromProperty(prop, include));
|
|
56611
|
+
}
|
|
56612
|
+
if (type.flags & 1 /* Any */) {
|
|
56613
|
+
cb(stringType);
|
|
56614
|
+
}
|
|
56615
|
+
else {
|
|
56616
|
+
for (var _b = 0, _c = getIndexInfosOfType(type); _b < _c.length; _b++) {
|
|
56617
|
+
var info = _c[_b];
|
|
56618
|
+
if (!stringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56619
|
+
cb(info.keyType);
|
|
56620
|
+
}
|
|
56621
|
+
}
|
|
56622
|
+
}
|
|
56623
|
+
}
|
|
56483
56624
|
/** Resolve the members of a mapped type { [P in K]: T } */
|
|
56484
56625
|
function resolveMappedTypeMembers(type) {
|
|
56485
56626
|
var members = ts.createSymbolTable();
|
|
@@ -56497,21 +56638,7 @@ var ts;
|
|
|
56497
56638
|
var include = keyofStringsOnly ? 128 /* StringLiteral */ : 8576 /* StringOrNumberLiteralOrUnique */;
|
|
56498
56639
|
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
56499
56640
|
// We have a { [P in keyof T]: X }
|
|
56500
|
-
|
|
56501
|
-
var prop = _a[_i];
|
|
56502
|
-
addMemberForKeyType(getLiteralTypeFromProperty(prop, include));
|
|
56503
|
-
}
|
|
56504
|
-
if (modifiersType.flags & 1 /* Any */) {
|
|
56505
|
-
addMemberForKeyType(stringType);
|
|
56506
|
-
}
|
|
56507
|
-
else {
|
|
56508
|
-
for (var _b = 0, _c = getIndexInfosOfType(modifiersType); _b < _c.length; _b++) {
|
|
56509
|
-
var info = _c[_b];
|
|
56510
|
-
if (!keyofStringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56511
|
-
addMemberForKeyType(info.keyType);
|
|
56512
|
-
}
|
|
56513
|
-
}
|
|
56514
|
-
}
|
|
56641
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
|
|
56515
56642
|
}
|
|
56516
56643
|
else {
|
|
56517
56644
|
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
@@ -57206,7 +57333,7 @@ var ts;
|
|
|
57206
57333
|
else if (type !== firstType) {
|
|
57207
57334
|
checkFlags |= 64 /* HasNonUniformType */;
|
|
57208
57335
|
}
|
|
57209
|
-
if (isLiteralType(type)) {
|
|
57336
|
+
if (isLiteralType(type) || isPatternLiteralType(type)) {
|
|
57210
57337
|
checkFlags |= 128 /* HasLiteralType */;
|
|
57211
57338
|
}
|
|
57212
57339
|
if (type.flags & 131072 /* Never */) {
|
|
@@ -59628,18 +59755,56 @@ var ts;
|
|
|
59628
59755
|
type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) :
|
|
59629
59756
|
type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false));
|
|
59630
59757
|
}
|
|
59631
|
-
|
|
59632
|
-
|
|
59633
|
-
|
|
59634
|
-
|
|
59635
|
-
|
|
59636
|
-
|
|
59637
|
-
|
|
59638
|
-
|
|
59639
|
-
var
|
|
59640
|
-
|
|
59641
|
-
|
|
59642
|
-
|
|
59758
|
+
/**
|
|
59759
|
+
* This roughly mirrors `resolveMappedTypeMembers` in the nongeneric case, except only reports a union of the keys calculated,
|
|
59760
|
+
* rather than manufacturing the properties. We can't just fetch the `constraintType` since that would ignore mappings
|
|
59761
|
+
* and mapping the `constraintType` directly ignores how mapped types map _properties_ and not keys (thus ignoring subtype
|
|
59762
|
+
* reduction in the constraintType) when possible.
|
|
59763
|
+
* @param noIndexSignatures Indicates if _string_ index signatures should be elided. (other index signatures are always reported)
|
|
59764
|
+
*/
|
|
59765
|
+
function getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) {
|
|
59766
|
+
var typeParameter = getTypeParameterFromMappedType(type);
|
|
59767
|
+
var constraintType = getConstraintTypeFromMappedType(type);
|
|
59768
|
+
var nameType = getNameTypeFromMappedType(type.target || type);
|
|
59769
|
+
if (!nameType && !noIndexSignatures) {
|
|
59770
|
+
// no mapping and no filtering required, just quickly bail to returning the constraint in the common case
|
|
59771
|
+
return constraintType;
|
|
59772
|
+
}
|
|
59773
|
+
var keyTypes = [];
|
|
59774
|
+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
59775
|
+
// We have a { [P in keyof T]: X }
|
|
59776
|
+
// `getApparentType` on the T in a generic mapped type can trigger a circularity
|
|
59777
|
+
// (conditionals and `infer` types create a circular dependency in the constraint resolution)
|
|
59778
|
+
// so we only eagerly manifest the keys if the constraint is nongeneric
|
|
59779
|
+
if (!isGenericIndexType(constraintType)) {
|
|
59780
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
|
|
59781
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */, stringsOnly, addMemberForKeyType);
|
|
59782
|
+
}
|
|
59783
|
+
else {
|
|
59784
|
+
// we have a generic index and a homomorphic mapping (but a distributive key remapping) - we need to defer the whole `keyof whatever` for later
|
|
59785
|
+
// since it's not safe to resolve the shape of modifier type
|
|
59786
|
+
return getIndexTypeForGenericType(type, stringsOnly);
|
|
59787
|
+
}
|
|
59788
|
+
}
|
|
59789
|
+
else {
|
|
59790
|
+
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
59791
|
+
}
|
|
59792
|
+
if (isGenericIndexType(constraintType)) { // include the generic component in the resulting type
|
|
59793
|
+
forEachType(constraintType, addMemberForKeyType);
|
|
59794
|
+
}
|
|
59795
|
+
// we had to pick apart the constraintType to potentially map/filter it - compare the final resulting list with the original constraintType,
|
|
59796
|
+
// so we can return the union that preserves aliases/origin data if possible
|
|
59797
|
+
var result = noIndexSignatures ? filterType(getUnionType(keyTypes), function (t) { return !(t.flags & (1 /* Any */ | 4 /* String */)); }) : getUnionType(keyTypes);
|
|
59798
|
+
if (result.flags & 1048576 /* Union */ && constraintType.flags & 1048576 /* Union */ && getTypeListId(result.types) === getTypeListId(constraintType.types)) {
|
|
59799
|
+
return constraintType;
|
|
59800
|
+
}
|
|
59801
|
+
return result;
|
|
59802
|
+
function addMemberForKeyType(keyType) {
|
|
59803
|
+
var propNameType = nameType ? instantiateType(nameType, appendTypeMapping(type.mapper, typeParameter, keyType)) : keyType;
|
|
59804
|
+
// `keyof` currently always returns `string | number` for concrete `string` index signatures - the below ternary keeps that behavior for mapped types
|
|
59805
|
+
// See `getLiteralTypeFromProperties` where there's a similar ternary to cause the same behavior.
|
|
59806
|
+
keyTypes.push(propNameType === stringType ? stringOrNumberType : propNameType);
|
|
59807
|
+
}
|
|
59643
59808
|
}
|
|
59644
59809
|
// Ordinarily we reduce a keyof M, where M is a mapped type { [P in K as N<P>]: X }, to simply N<K>. This however presumes
|
|
59645
59810
|
// that N distributes over union types, i.e. that N<A | B | C> is equivalent to N<A> | N<B> | N<C>. Specifically, we only
|
|
@@ -59697,7 +59862,7 @@ var ts;
|
|
|
59697
59862
|
return type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59698
59863
|
type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59699
59864
|
type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
|
|
59700
|
-
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, noIndexSignatures) :
|
|
59865
|
+
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
|
|
59701
59866
|
type === wildcardType ? wildcardType :
|
|
59702
59867
|
type.flags & 2 /* Unknown */ ? neverType :
|
|
59703
59868
|
type.flags & (1 /* Any */ | 131072 /* Never */) ? keyofConstraintType :
|
|
@@ -61562,7 +61727,7 @@ var ts;
|
|
|
61562
61727
|
return !node.typeParameters && !ts.getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== 234 /* Block */ && isContextSensitive(node.body);
|
|
61563
61728
|
}
|
|
61564
61729
|
function isContextSensitiveFunctionOrObjectLiteralMethod(func) {
|
|
61565
|
-
return (ts.isInJSFile(func) && ts.isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
|
|
61730
|
+
return (ts.isInJSFile(func) && ts.isFunctionDeclaration(func) || ts.isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
|
|
61566
61731
|
isContextSensitiveFunctionLikeDeclaration(func);
|
|
61567
61732
|
}
|
|
61568
61733
|
function getTypeWithoutSignatures(type) {
|
|
@@ -62434,7 +62599,8 @@ var ts;
|
|
|
62434
62599
|
var sourceStack;
|
|
62435
62600
|
var targetStack;
|
|
62436
62601
|
var maybeCount = 0;
|
|
62437
|
-
var
|
|
62602
|
+
var sourceDepth = 0;
|
|
62603
|
+
var targetDepth = 0;
|
|
62438
62604
|
var expandingFlags = 0 /* None */;
|
|
62439
62605
|
var overflow = false;
|
|
62440
62606
|
var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
|
|
@@ -62442,12 +62608,12 @@ var ts;
|
|
|
62442
62608
|
var incompatibleStack = [];
|
|
62443
62609
|
var inPropertyCheck = false;
|
|
62444
62610
|
ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
|
|
62445
|
-
var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage);
|
|
62611
|
+
var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
|
|
62446
62612
|
if (incompatibleStack.length) {
|
|
62447
62613
|
reportIncompatibleStack();
|
|
62448
62614
|
}
|
|
62449
62615
|
if (overflow) {
|
|
62450
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth:
|
|
62616
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth: sourceDepth, targetDepth: targetDepth });
|
|
62451
62617
|
var diag = error(errorNode || currentNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
|
|
62452
62618
|
if (errorOutputContainer) {
|
|
62453
62619
|
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
|
|
@@ -62674,9 +62840,9 @@ var ts;
|
|
|
62674
62840
|
}
|
|
62675
62841
|
}
|
|
62676
62842
|
message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1;
|
|
62677
|
-
|
|
62678
|
-
|
|
62679
|
-
|
|
62843
|
+
var typeLengthLimit = 30;
|
|
62844
|
+
if (!errorInfo && compilerOptions.pretty && (sourceType.length > typeLengthLimit || targetType.length > typeLengthLimit)) {
|
|
62845
|
+
message = formatMessageForTypes(message, typeLengthLimit, sourceType, targetType);
|
|
62680
62846
|
}
|
|
62681
62847
|
}
|
|
62682
62848
|
}
|
|
@@ -62687,15 +62853,14 @@ var ts;
|
|
|
62687
62853
|
}
|
|
62688
62854
|
reportError(message, generalizedSourceType, targetType);
|
|
62689
62855
|
}
|
|
62690
|
-
|
|
62691
|
-
|
|
62692
|
-
|
|
62693
|
-
|
|
62694
|
-
|
|
62695
|
-
|
|
62696
|
-
|
|
62697
|
-
|
|
62698
|
-
.replace(".", "") });
|
|
62856
|
+
/** Move a printed type to be on its own line if it is longer than 30 characters */
|
|
62857
|
+
function formatMessageForTypes(diagnostic, typeLengthLimit, source, target) {
|
|
62858
|
+
var message = diagnostic.message;
|
|
62859
|
+
if (source.length > typeLengthLimit)
|
|
62860
|
+
message = message.replace(" '{0}' ", ":\n{0}\n\n");
|
|
62861
|
+
if (target.length > typeLengthLimit)
|
|
62862
|
+
message = message.replace(" '{1}'", ":\n{1}").replace(".", "");
|
|
62863
|
+
return __assign(__assign({}, diagnostic), { message: message });
|
|
62699
62864
|
}
|
|
62700
62865
|
function tryElaborateErrorsForPrimitivesAndObjects(source, target) {
|
|
62701
62866
|
var sourceType = symbolValueDeclarationIsContextSensitive(source.symbol) ? typeToString(source, source.symbol.valueDeclaration) : typeToString(source);
|
|
@@ -62741,13 +62906,17 @@ var ts;
|
|
|
62741
62906
|
}
|
|
62742
62907
|
return true;
|
|
62743
62908
|
}
|
|
62909
|
+
function isRelatedToWorker(source, target, reportErrors) {
|
|
62910
|
+
return isRelatedTo(source, target, 3 /* Both */, reportErrors);
|
|
62911
|
+
}
|
|
62744
62912
|
/**
|
|
62745
62913
|
* Compare two types and return
|
|
62746
62914
|
* * Ternary.True if they are related with no assumptions,
|
|
62747
62915
|
* * Ternary.Maybe if they are related with assumptions of other relationships, or
|
|
62748
62916
|
* * Ternary.False if they are not related.
|
|
62749
62917
|
*/
|
|
62750
|
-
function isRelatedTo(originalSource, originalTarget, reportErrors, headMessage, intersectionState) {
|
|
62918
|
+
function isRelatedTo(originalSource, originalTarget, recursionFlags, reportErrors, headMessage, intersectionState) {
|
|
62919
|
+
if (recursionFlags === void 0) { recursionFlags = 3 /* Both */; }
|
|
62751
62920
|
if (reportErrors === void 0) { reportErrors = false; }
|
|
62752
62921
|
if (intersectionState === void 0) { intersectionState = 0 /* None */; }
|
|
62753
62922
|
// Before normalization: if `source` is type an object type, and `target` is primitive,
|
|
@@ -62768,7 +62937,7 @@ var ts;
|
|
|
62768
62937
|
if (source === target)
|
|
62769
62938
|
return -1 /* True */;
|
|
62770
62939
|
if (relation === identityRelation) {
|
|
62771
|
-
return isIdenticalTo(source, target);
|
|
62940
|
+
return isIdenticalTo(source, target, recursionFlags);
|
|
62772
62941
|
}
|
|
62773
62942
|
// We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
|
|
62774
62943
|
// and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
|
|
@@ -62819,8 +62988,8 @@ var ts;
|
|
|
62819
62988
|
var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
|
|
62820
62989
|
var calls = getSignaturesOfType(source, 0 /* Call */);
|
|
62821
62990
|
var constructs = getSignaturesOfType(source, 1 /* Construct */);
|
|
62822
|
-
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, /*reportErrors*/ false) ||
|
|
62823
|
-
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, /*reportErrors*/ false)) {
|
|
62991
|
+
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
|
|
62992
|
+
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
|
|
62824
62993
|
reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
|
|
62825
62994
|
}
|
|
62826
62995
|
else {
|
|
@@ -62837,11 +63006,11 @@ var ts;
|
|
|
62837
63006
|
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
|
62838
63007
|
if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
|
|
62839
63008
|
result = getConstituentCount(source) * getConstituentCount(target) >= 4 ?
|
|
62840
|
-
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck
|
|
63009
|
+
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags) :
|
|
62841
63010
|
structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
|
|
62842
63011
|
}
|
|
62843
63012
|
if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
|
|
62844
|
-
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState)) {
|
|
63013
|
+
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
|
|
62845
63014
|
resetErrorInfo(saveErrorInfo);
|
|
62846
63015
|
}
|
|
62847
63016
|
}
|
|
@@ -62863,7 +63032,7 @@ var ts;
|
|
|
62863
63032
|
if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
|
|
62864
63033
|
if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
62865
63034
|
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
62866
|
-
if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63035
|
+
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
62867
63036
|
resetErrorInfo(saveErrorInfo);
|
|
62868
63037
|
}
|
|
62869
63038
|
}
|
|
@@ -62887,7 +63056,7 @@ var ts;
|
|
|
62887
63056
|
if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
62888
63057
|
isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
|
|
62889
63058
|
inPropertyCheck = true;
|
|
62890
|
-
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck
|
|
63059
|
+
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
62891
63060
|
inPropertyCheck = false;
|
|
62892
63061
|
}
|
|
62893
63062
|
reportErrorResults(source, target, result, isComparingJsxAttributes);
|
|
@@ -62962,7 +63131,7 @@ var ts;
|
|
|
62962
63131
|
}
|
|
62963
63132
|
}
|
|
62964
63133
|
}
|
|
62965
|
-
function isIdenticalTo(source, target) {
|
|
63134
|
+
function isIdenticalTo(source, target, recursionFlags) {
|
|
62966
63135
|
if (source.flags !== target.flags)
|
|
62967
63136
|
return 0 /* False */;
|
|
62968
63137
|
if (source.flags & 67358815 /* Singleton */)
|
|
@@ -62975,7 +63144,7 @@ var ts;
|
|
|
62975
63144
|
}
|
|
62976
63145
|
return result_7;
|
|
62977
63146
|
}
|
|
62978
|
-
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None
|
|
63147
|
+
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
62979
63148
|
}
|
|
62980
63149
|
function getTypeOfPropertyInTypes(types, name) {
|
|
62981
63150
|
var appendPropType = function (propTypes, type) {
|
|
@@ -63056,7 +63225,7 @@ var ts;
|
|
|
63056
63225
|
}
|
|
63057
63226
|
return { value: true };
|
|
63058
63227
|
}
|
|
63059
|
-
if (checkTypes && !isRelatedTo(getTypeOfSymbol(prop), getTypeOfPropertyInTypes(checkTypes, prop.escapedName), reportErrors)) {
|
|
63228
|
+
if (checkTypes && !isRelatedTo(getTypeOfSymbol(prop), getTypeOfPropertyInTypes(checkTypes, prop.escapedName), 3 /* Both */, reportErrors)) {
|
|
63060
63229
|
if (reportErrors) {
|
|
63061
63230
|
reportIncompatibleError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(prop));
|
|
63062
63231
|
}
|
|
@@ -63096,7 +63265,7 @@ var ts;
|
|
|
63096
63265
|
}
|
|
63097
63266
|
var match = getMatchingUnionConstituentForType(target, source);
|
|
63098
63267
|
if (match) {
|
|
63099
|
-
var related = isRelatedTo(source, match, /*reportErrors*/ false);
|
|
63268
|
+
var related = isRelatedTo(source, match, 2 /* Target */, /*reportErrors*/ false);
|
|
63100
63269
|
if (related) {
|
|
63101
63270
|
return related;
|
|
63102
63271
|
}
|
|
@@ -63104,14 +63273,14 @@ var ts;
|
|
|
63104
63273
|
}
|
|
63105
63274
|
for (var _i = 0, targetTypes_1 = targetTypes; _i < targetTypes_1.length; _i++) {
|
|
63106
63275
|
var type = targetTypes_1[_i];
|
|
63107
|
-
var related = isRelatedTo(source, type, /*reportErrors*/ false);
|
|
63276
|
+
var related = isRelatedTo(source, type, 2 /* Target */, /*reportErrors*/ false);
|
|
63108
63277
|
if (related) {
|
|
63109
63278
|
return related;
|
|
63110
63279
|
}
|
|
63111
63280
|
}
|
|
63112
63281
|
if (reportErrors) {
|
|
63113
63282
|
var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
|
|
63114
|
-
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
|
|
63283
|
+
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
|
|
63115
63284
|
}
|
|
63116
63285
|
return 0 /* False */;
|
|
63117
63286
|
}
|
|
@@ -63120,7 +63289,7 @@ var ts;
|
|
|
63120
63289
|
var targetTypes = target.types;
|
|
63121
63290
|
for (var _i = 0, targetTypes_2 = targetTypes; _i < targetTypes_2.length; _i++) {
|
|
63122
63291
|
var targetType = targetTypes_2[_i];
|
|
63123
|
-
var related = isRelatedTo(source, targetType, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63292
|
+
var related = isRelatedTo(source, targetType, 2 /* Target */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63124
63293
|
if (!related) {
|
|
63125
63294
|
return 0 /* False */;
|
|
63126
63295
|
}
|
|
@@ -63135,7 +63304,7 @@ var ts;
|
|
|
63135
63304
|
}
|
|
63136
63305
|
var len = sourceTypes.length;
|
|
63137
63306
|
for (var i = 0; i < len; i++) {
|
|
63138
|
-
var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1, /*headMessage*/ undefined, intersectionState);
|
|
63307
|
+
var related = isRelatedTo(sourceTypes[i], target, 1 /* Source */, reportErrors && i === len - 1, /*headMessage*/ undefined, intersectionState);
|
|
63139
63308
|
if (related) {
|
|
63140
63309
|
return related;
|
|
63141
63310
|
}
|
|
@@ -63165,13 +63334,13 @@ var ts;
|
|
|
63165
63334
|
// union has a union of objects intersected with it. In such cases, if the input was, eg `("a" | "b" | "c") & (string | boolean | {} | {whatever})`,
|
|
63166
63335
|
// the result will have the structure `"a" | "b" | "c" | "a" & {} | "b" & {} | "c" & {} | "a" & {whatever} | "b" & {whatever} | "c" & {whatever}`
|
|
63167
63336
|
// - the resulting union has a length which is a multiple of the original union, and the elements correspond modulo the length of the original union
|
|
63168
|
-
var related_1 = isRelatedTo(sourceType, undefinedStrippedTarget.types[i % undefinedStrippedTarget.types.length], /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
|
|
63337
|
+
var related_1 = isRelatedTo(sourceType, undefinedStrippedTarget.types[i % undefinedStrippedTarget.types.length], 3 /* Both */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
|
|
63169
63338
|
if (related_1) {
|
|
63170
63339
|
result &= related_1;
|
|
63171
63340
|
continue;
|
|
63172
63341
|
}
|
|
63173
63342
|
}
|
|
63174
|
-
var related = isRelatedTo(sourceType, target, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63343
|
+
var related = isRelatedTo(sourceType, target, 1 /* Source */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63175
63344
|
if (!related) {
|
|
63176
63345
|
return 0 /* False */;
|
|
63177
63346
|
}
|
|
@@ -63203,31 +63372,31 @@ var ts;
|
|
|
63203
63372
|
// Even an `Unmeasurable` variance works out without a structural check if the source and target are _identical_.
|
|
63204
63373
|
// We can't simply assume invariance, because `Unmeasurable` marks nonlinear relations, for example, a relation tained by
|
|
63205
63374
|
// the `-?` modifier in a mapped type (where, no matter how the inputs are related, the outputs still might not be)
|
|
63206
|
-
related = relation === identityRelation ? isRelatedTo(s, t, /*reportErrors*/ false) : compareTypesIdentical(s, t);
|
|
63375
|
+
related = relation === identityRelation ? isRelatedTo(s, t, 3 /* Both */, /*reportErrors*/ false) : compareTypesIdentical(s, t);
|
|
63207
63376
|
}
|
|
63208
63377
|
else if (variance === 1 /* Covariant */) {
|
|
63209
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63378
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63210
63379
|
}
|
|
63211
63380
|
else if (variance === 2 /* Contravariant */) {
|
|
63212
|
-
related = isRelatedTo(t, s, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63381
|
+
related = isRelatedTo(t, s, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63213
63382
|
}
|
|
63214
63383
|
else if (variance === 3 /* Bivariant */) {
|
|
63215
63384
|
// In the bivariant case we first compare contravariantly without reporting
|
|
63216
63385
|
// errors. Then, if that doesn't succeed, we compare covariantly with error
|
|
63217
63386
|
// reporting. Thus, error elaboration will be based on the the covariant check,
|
|
63218
63387
|
// which is generally easier to reason about.
|
|
63219
|
-
related = isRelatedTo(t, s, /*reportErrors*/ false);
|
|
63388
|
+
related = isRelatedTo(t, s, 3 /* Both */, /*reportErrors*/ false);
|
|
63220
63389
|
if (!related) {
|
|
63221
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63390
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63222
63391
|
}
|
|
63223
63392
|
}
|
|
63224
63393
|
else {
|
|
63225
63394
|
// In the invariant case we first compare covariantly, and only when that
|
|
63226
63395
|
// succeeds do we proceed to compare contravariantly. Thus, error elaboration
|
|
63227
63396
|
// will typically be based on the covariant check.
|
|
63228
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63397
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63229
63398
|
if (related) {
|
|
63230
|
-
related &= isRelatedTo(t, s, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63399
|
+
related &= isRelatedTo(t, s, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63231
63400
|
}
|
|
63232
63401
|
}
|
|
63233
63402
|
if (!related) {
|
|
@@ -63243,7 +63412,7 @@ var ts;
|
|
|
63243
63412
|
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
|
|
63244
63413
|
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
|
|
63245
63414
|
// and issue an error. Otherwise, actually compare the structure of the two types.
|
|
63246
|
-
function recursiveTypeRelatedTo(source, target, reportErrors, intersectionState) {
|
|
63415
|
+
function recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags) {
|
|
63247
63416
|
if (overflow) {
|
|
63248
63417
|
return 0 /* False */;
|
|
63249
63418
|
}
|
|
@@ -63287,7 +63456,7 @@ var ts;
|
|
|
63287
63456
|
return 3 /* Maybe */;
|
|
63288
63457
|
}
|
|
63289
63458
|
}
|
|
63290
|
-
if (
|
|
63459
|
+
if (sourceDepth === 100 || targetDepth === 100) {
|
|
63291
63460
|
overflow = true;
|
|
63292
63461
|
return 0 /* False */;
|
|
63293
63462
|
}
|
|
@@ -63295,13 +63464,18 @@ var ts;
|
|
|
63295
63464
|
var maybeStart = maybeCount;
|
|
63296
63465
|
maybeKeys[maybeCount] = id;
|
|
63297
63466
|
maybeCount++;
|
|
63298
|
-
|
|
63299
|
-
|
|
63300
|
-
|
|
63467
|
+
if (recursionFlags & 1 /* Source */) {
|
|
63468
|
+
sourceStack[sourceDepth] = source;
|
|
63469
|
+
sourceDepth++;
|
|
63470
|
+
}
|
|
63471
|
+
if (recursionFlags & 2 /* Target */) {
|
|
63472
|
+
targetStack[targetDepth] = target;
|
|
63473
|
+
targetDepth++;
|
|
63474
|
+
}
|
|
63301
63475
|
var saveExpandingFlags = expandingFlags;
|
|
63302
|
-
if (!(expandingFlags & 1 /* Source */) && isDeeplyNestedType(source, sourceStack,
|
|
63476
|
+
if (!(expandingFlags & 1 /* Source */) && isDeeplyNestedType(source, sourceStack, sourceDepth))
|
|
63303
63477
|
expandingFlags |= 1 /* Source */;
|
|
63304
|
-
if (!(expandingFlags & 2 /* Target */) && isDeeplyNestedType(target, targetStack,
|
|
63478
|
+
if (!(expandingFlags & 2 /* Target */) && isDeeplyNestedType(target, targetStack, targetDepth))
|
|
63305
63479
|
expandingFlags |= 2 /* Target */;
|
|
63306
63480
|
var originalHandler;
|
|
63307
63481
|
var propagatingVarianceFlags = 0;
|
|
@@ -63318,7 +63492,8 @@ var ts;
|
|
|
63318
63492
|
sourceIdStack: sourceStack.map(function (t) { return t.id; }),
|
|
63319
63493
|
targetId: target.id,
|
|
63320
63494
|
targetIdStack: targetStack.map(function (t) { return t.id; }),
|
|
63321
|
-
depth:
|
|
63495
|
+
depth: sourceDepth,
|
|
63496
|
+
targetDepth: targetDepth
|
|
63322
63497
|
});
|
|
63323
63498
|
}
|
|
63324
63499
|
var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
|
|
@@ -63326,9 +63501,14 @@ var ts;
|
|
|
63326
63501
|
outofbandVarianceMarkerHandler = originalHandler;
|
|
63327
63502
|
}
|
|
63328
63503
|
expandingFlags = saveExpandingFlags;
|
|
63329
|
-
|
|
63504
|
+
if (recursionFlags & 1 /* Source */) {
|
|
63505
|
+
sourceDepth--;
|
|
63506
|
+
}
|
|
63507
|
+
if (recursionFlags & 2 /* Target */) {
|
|
63508
|
+
targetDepth--;
|
|
63509
|
+
}
|
|
63330
63510
|
if (result) {
|
|
63331
|
-
if (result === -1 /* True */ ||
|
|
63511
|
+
if (result === -1 /* True */ || (sourceDepth === 0 && targetDepth === 0)) {
|
|
63332
63512
|
if (result === -1 /* True */ || result === 3 /* Maybe */) {
|
|
63333
63513
|
// If result is definitely true, record all maybe keys as having succeeded. Also, record Ternary.Maybe
|
|
63334
63514
|
// results as having succeeded once we reach depth 0, but never record Ternary.Unknown results.
|
|
@@ -63382,7 +63562,7 @@ var ts;
|
|
|
63382
63562
|
if (constraints !== source.types) {
|
|
63383
63563
|
source = getIntersectionType(constraints);
|
|
63384
63564
|
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
63385
|
-
return isRelatedTo(source, target, /*reportErrors*/ false);
|
|
63565
|
+
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
63386
63566
|
}
|
|
63387
63567
|
}
|
|
63388
63568
|
}
|
|
@@ -63404,22 +63584,22 @@ var ts;
|
|
|
63404
63584
|
var flags = source.flags & target.flags;
|
|
63405
63585
|
if (relation === identityRelation && !(flags & 524288 /* Object */)) {
|
|
63406
63586
|
if (flags & 4194304 /* Index */) {
|
|
63407
|
-
return isRelatedTo(source.type, target.type, /*reportErrors*/ false);
|
|
63587
|
+
return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
|
|
63408
63588
|
}
|
|
63409
63589
|
var result_8 = 0 /* False */;
|
|
63410
63590
|
if (flags & 8388608 /* IndexedAccess */) {
|
|
63411
|
-
if (result_8 = isRelatedTo(source.objectType, target.objectType, /*reportErrors*/ false)) {
|
|
63412
|
-
if (result_8 &= isRelatedTo(source.indexType, target.indexType, /*reportErrors*/ false)) {
|
|
63591
|
+
if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63592
|
+
if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63413
63593
|
return result_8;
|
|
63414
63594
|
}
|
|
63415
63595
|
}
|
|
63416
63596
|
}
|
|
63417
63597
|
if (flags & 16777216 /* Conditional */) {
|
|
63418
63598
|
if (source.root.isDistributive === target.root.isDistributive) {
|
|
63419
|
-
if (result_8 = isRelatedTo(source.checkType, target.checkType, /*reportErrors*/ false)) {
|
|
63420
|
-
if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, /*reportErrors*/ false)) {
|
|
63421
|
-
if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), /*reportErrors*/ false)) {
|
|
63422
|
-
if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), /*reportErrors*/ false)) {
|
|
63599
|
+
if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63600
|
+
if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63601
|
+
if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
63602
|
+
if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
63423
63603
|
return result_8;
|
|
63424
63604
|
}
|
|
63425
63605
|
}
|
|
@@ -63428,7 +63608,7 @@ var ts;
|
|
|
63428
63608
|
}
|
|
63429
63609
|
}
|
|
63430
63610
|
if (flags & 33554432 /* Substitution */) {
|
|
63431
|
-
return isRelatedTo(source.substitute, target.substitute, /*reportErrors*/ false);
|
|
63611
|
+
return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
|
|
63432
63612
|
}
|
|
63433
63613
|
return 0 /* False */;
|
|
63434
63614
|
}
|
|
@@ -63453,47 +63633,71 @@ var ts;
|
|
|
63453
63633
|
}
|
|
63454
63634
|
// For a generic type T and a type U that is assignable to T, [...U] is assignable to T, U is assignable to readonly [...T],
|
|
63455
63635
|
// and U is assignable to [...T] when U is constrained to a mutable array or tuple type.
|
|
63456
|
-
if (isSingleElementGenericTupleType(source) && !source.target.readonly && (result = isRelatedTo(getTypeArguments(source)[0], target)) ||
|
|
63457
|
-
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0]))) {
|
|
63636
|
+
if (isSingleElementGenericTupleType(source) && !source.target.readonly && (result = isRelatedTo(getTypeArguments(source)[0], target, 1 /* Source */)) ||
|
|
63637
|
+
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
|
|
63458
63638
|
return result;
|
|
63459
63639
|
}
|
|
63460
63640
|
if (target.flags & 262144 /* TypeParameter */) {
|
|
63461
63641
|
// A source type { [P in Q]: X } is related to a target type T if keyof T is related to Q and X is related to T[Q].
|
|
63462
|
-
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source))) {
|
|
63642
|
+
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
|
|
63463
63643
|
if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
|
|
63464
63644
|
var templateType = getTemplateTypeFromMappedType(source);
|
|
63465
63645
|
var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source));
|
|
63466
|
-
if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) {
|
|
63646
|
+
if (result = isRelatedTo(templateType, indexedAccessType, 3 /* Both */, reportErrors)) {
|
|
63467
63647
|
return result;
|
|
63468
63648
|
}
|
|
63469
63649
|
}
|
|
63470
63650
|
}
|
|
63471
63651
|
}
|
|
63472
63652
|
else if (target.flags & 4194304 /* Index */) {
|
|
63473
|
-
var
|
|
63653
|
+
var targetType_1 = target.type;
|
|
63474
63654
|
// A keyof S is related to a keyof T if T is related to S.
|
|
63475
63655
|
if (source.flags & 4194304 /* Index */) {
|
|
63476
|
-
if (result = isRelatedTo(
|
|
63656
|
+
if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63477
63657
|
return result;
|
|
63478
63658
|
}
|
|
63479
63659
|
}
|
|
63480
|
-
if (isTupleType(
|
|
63660
|
+
if (isTupleType(targetType_1)) {
|
|
63481
63661
|
// An index type can have a tuple type target when the tuple type contains variadic elements.
|
|
63482
63662
|
// Check if the source is related to the known keys of the tuple type.
|
|
63483
|
-
if (result = isRelatedTo(source, getKnownKeysOfTupleType(
|
|
63663
|
+
if (result = isRelatedTo(source, getKnownKeysOfTupleType(targetType_1), 2 /* Target */, reportErrors)) {
|
|
63484
63664
|
return result;
|
|
63485
63665
|
}
|
|
63486
63666
|
}
|
|
63487
63667
|
else {
|
|
63488
63668
|
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
|
|
63489
63669
|
// simplified form of T or, if T doesn't simplify, the constraint of T.
|
|
63490
|
-
var constraint = getSimplifiedTypeOrConstraint(
|
|
63670
|
+
var constraint = getSimplifiedTypeOrConstraint(targetType_1);
|
|
63491
63671
|
if (constraint) {
|
|
63492
63672
|
// We require Ternary.True here such that circular constraints don't cause
|
|
63493
63673
|
// false positives. For example, given 'T extends { [K in keyof T]: string }',
|
|
63494
63674
|
// 'keyof T' has itself as its constraint and produces a Ternary.Maybe when
|
|
63495
63675
|
// related to other types.
|
|
63496
|
-
if (isRelatedTo(source, getIndexType(constraint, target.stringsOnly), reportErrors) === -1 /* True */) {
|
|
63676
|
+
if (isRelatedTo(source, getIndexType(constraint, target.stringsOnly), 2 /* Target */, reportErrors) === -1 /* True */) {
|
|
63677
|
+
return -1 /* True */;
|
|
63678
|
+
}
|
|
63679
|
+
}
|
|
63680
|
+
else if (isGenericMappedType(targetType_1)) {
|
|
63681
|
+
// generic mapped types that don't simplify or have a constraint still have a very simple set of keys we can compare against
|
|
63682
|
+
// - their nameType or constraintType.
|
|
63683
|
+
// In many ways, this comparison is a deferred version of what `getIndexTypeForMappedType` does to actually resolve the keys for _non_-generic types
|
|
63684
|
+
var nameType_1 = getNameTypeFromMappedType(targetType_1);
|
|
63685
|
+
var constraintType = getConstraintTypeFromMappedType(targetType_1);
|
|
63686
|
+
var targetKeys = void 0;
|
|
63687
|
+
if (nameType_1 && isMappedTypeWithKeyofConstraintDeclaration(targetType_1)) {
|
|
63688
|
+
// we need to get the apparent mappings and union them with the generic mappings, since some properties may be
|
|
63689
|
+
// missing from the `constraintType` which will otherwise be mapped in the object
|
|
63690
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType_1));
|
|
63691
|
+
var mappedKeys_1 = [];
|
|
63692
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */,
|
|
63693
|
+
/*stringsOnly*/ false, function (t) { return void mappedKeys_1.push(instantiateType(nameType_1, appendTypeMapping(targetType_1.mapper, getTypeParameterFromMappedType(targetType_1), t))); });
|
|
63694
|
+
// We still need to include the non-apparent (and thus still generic) keys in the target side of the comparison (in case they're in the source side)
|
|
63695
|
+
targetKeys = getUnionType(__spreadArray(__spreadArray([], mappedKeys_1, true), [nameType_1], false));
|
|
63696
|
+
}
|
|
63697
|
+
else {
|
|
63698
|
+
targetKeys = nameType_1 || constraintType;
|
|
63699
|
+
}
|
|
63700
|
+
if (isRelatedTo(source, targetKeys, 2 /* Target */, reportErrors) === -1 /* True */) {
|
|
63497
63701
|
return -1 /* True */;
|
|
63498
63702
|
}
|
|
63499
63703
|
}
|
|
@@ -63503,8 +63707,8 @@ var ts;
|
|
|
63503
63707
|
if (source.flags & 8388608 /* IndexedAccess */) {
|
|
63504
63708
|
// Relate components directly before falling back to constraint relationships
|
|
63505
63709
|
// A type S[K] is related to a type T[J] if S is related to T and K is related to J.
|
|
63506
|
-
if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) {
|
|
63507
|
-
result &= isRelatedTo(source.indexType, target.indexType, reportErrors);
|
|
63710
|
+
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
|
|
63711
|
+
result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, reportErrors);
|
|
63508
63712
|
}
|
|
63509
63713
|
if (result) {
|
|
63510
63714
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -63529,7 +63733,7 @@ var ts;
|
|
|
63529
63733
|
// create a new chain for the constraint error
|
|
63530
63734
|
resetErrorInfo(saveErrorInfo);
|
|
63531
63735
|
}
|
|
63532
|
-
if (result = isRelatedTo(source, constraint, reportErrors)) {
|
|
63736
|
+
if (result = isRelatedTo(source, constraint, 2 /* Target */, reportErrors)) {
|
|
63533
63737
|
return result;
|
|
63534
63738
|
}
|
|
63535
63739
|
// prefer the shorter chain of the constraint comparison chain, and the direct comparison chain
|
|
@@ -63569,13 +63773,14 @@ var ts;
|
|
|
63569
63773
|
// A source type `S` is related to a target type `{ [P in Q as R]?: T }` if some constituent `R'` of `R` is related to `keyof S` and `S[R']` is related to `T`.
|
|
63570
63774
|
if (includeOptional
|
|
63571
63775
|
? !(filteredByApplicability.flags & 131072 /* Never */)
|
|
63572
|
-
: isRelatedTo(targetKeys, sourceKeys)) {
|
|
63776
|
+
: isRelatedTo(targetKeys, sourceKeys, 3 /* Both */)) {
|
|
63777
|
+
var templateType_1 = getTemplateTypeFromMappedType(target);
|
|
63573
63778
|
var typeParameter = getTypeParameterFromMappedType(target);
|
|
63574
63779
|
// Fastpath: When the template type has the form `Obj[P]` where `P` is the mapped type parameter, directly compare source `S` with `Obj`
|
|
63575
63780
|
// to avoid creating the (potentially very large) number of new intermediate types made by manufacturing `S[P]`.
|
|
63576
|
-
var nonNullComponent = extractTypesOfKind(
|
|
63781
|
+
var nonNullComponent = extractTypesOfKind(templateType_1, ~98304 /* Nullable */);
|
|
63577
63782
|
if (!keysRemapped && nonNullComponent.flags & 8388608 /* IndexedAccess */ && nonNullComponent.indexType === typeParameter) {
|
|
63578
|
-
if (result = isRelatedTo(source, nonNullComponent.objectType, reportErrors)) {
|
|
63783
|
+
if (result = isRelatedTo(source, nonNullComponent.objectType, 2 /* Target */, reportErrors)) {
|
|
63579
63784
|
return result;
|
|
63580
63785
|
}
|
|
63581
63786
|
}
|
|
@@ -63595,7 +63800,7 @@ var ts;
|
|
|
63595
63800
|
: typeParameter;
|
|
63596
63801
|
var indexedAccessType = getIndexedAccessType(source, indexingType);
|
|
63597
63802
|
// Compare `S[indexingType]` to `T`, where `T` is the type of a property of the target type.
|
|
63598
|
-
if (result = isRelatedTo(indexedAccessType,
|
|
63803
|
+
if (result = isRelatedTo(indexedAccessType, templateType_1, 3 /* Both */, reportErrors)) {
|
|
63599
63804
|
return result;
|
|
63600
63805
|
}
|
|
63601
63806
|
}
|
|
@@ -63622,10 +63827,11 @@ var ts;
|
|
|
63622
63827
|
newParam.mapper = distributionMapper;
|
|
63623
63828
|
}
|
|
63624
63829
|
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
|
|
63625
|
-
var
|
|
63626
|
-
|
|
63627
|
-
|
|
63628
|
-
|
|
63830
|
+
var expanding = isDeeplyNestedType(target, targetStack, targetDepth);
|
|
63831
|
+
var localResult = expanding ? 3 /* Maybe */ : undefined;
|
|
63832
|
+
if (skipTrue || expanding || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.trueType), distributionMapper) : getTrueTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false))) {
|
|
63833
|
+
if (!skipFalse && !expanding) {
|
|
63834
|
+
localResult = (localResult || 3 /* Maybe */) & isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.falseType), distributionMapper) : getFalseTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false);
|
|
63629
63835
|
}
|
|
63630
63836
|
}
|
|
63631
63837
|
if (localResult) {
|
|
@@ -63635,6 +63841,9 @@ var ts;
|
|
|
63635
63841
|
}
|
|
63636
63842
|
else if (target.flags & 134217728 /* TemplateLiteral */) {
|
|
63637
63843
|
if (source.flags & 134217728 /* TemplateLiteral */) {
|
|
63844
|
+
if (relation === comparableRelation) {
|
|
63845
|
+
return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
|
|
63846
|
+
}
|
|
63638
63847
|
// Report unreliable variance for type variables referenced in template literal type placeholders.
|
|
63639
63848
|
// For example, `foo-${number}` is related to `foo-${string}` even though number isn't related to string.
|
|
63640
63849
|
instantiateType(source, makeFunctionTypeMapper(reportUnreliableMarkers));
|
|
@@ -63650,34 +63859,33 @@ var ts;
|
|
|
63650
63859
|
var constraint = getConstraintOfType(source);
|
|
63651
63860
|
if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
63652
63861
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
63653
|
-
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */))) {
|
|
63862
|
+
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
63654
63863
|
resetErrorInfo(saveErrorInfo);
|
|
63655
63864
|
return result;
|
|
63656
63865
|
}
|
|
63657
63866
|
}
|
|
63658
63867
|
// hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
|
|
63659
|
-
else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63868
|
+
else if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63660
63869
|
resetErrorInfo(saveErrorInfo);
|
|
63661
63870
|
return result;
|
|
63662
63871
|
}
|
|
63663
63872
|
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
|
|
63664
|
-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
63873
|
+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
63665
63874
|
resetErrorInfo(saveErrorInfo);
|
|
63666
63875
|
return result;
|
|
63667
63876
|
}
|
|
63668
63877
|
}
|
|
63669
63878
|
}
|
|
63670
63879
|
else if (source.flags & 4194304 /* Index */) {
|
|
63671
|
-
if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) {
|
|
63880
|
+
if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
|
|
63672
63881
|
resetErrorInfo(saveErrorInfo);
|
|
63673
63882
|
return result;
|
|
63674
63883
|
}
|
|
63675
63884
|
}
|
|
63676
|
-
else if (source.flags & 134217728 /* TemplateLiteral */) {
|
|
63885
|
+
else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
|
|
63677
63886
|
if (!(target.flags & 134217728 /* TemplateLiteral */)) {
|
|
63678
|
-
var
|
|
63679
|
-
|
|
63680
|
-
if (result = isRelatedTo(constraint, target, reportErrors)) {
|
|
63887
|
+
var constraint = getBaseConstraintOfType(source);
|
|
63888
|
+
if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
63681
63889
|
resetErrorInfo(saveErrorInfo);
|
|
63682
63890
|
return result;
|
|
63683
63891
|
}
|
|
@@ -63685,14 +63893,14 @@ var ts;
|
|
|
63685
63893
|
}
|
|
63686
63894
|
else if (source.flags & 268435456 /* StringMapping */) {
|
|
63687
63895
|
if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
|
|
63688
|
-
if (result = isRelatedTo(source.type, target.type, reportErrors)) {
|
|
63896
|
+
if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
|
|
63689
63897
|
resetErrorInfo(saveErrorInfo);
|
|
63690
63898
|
return result;
|
|
63691
63899
|
}
|
|
63692
63900
|
}
|
|
63693
63901
|
else {
|
|
63694
63902
|
var constraint = getBaseConstraintOfType(source);
|
|
63695
|
-
if (constraint && (result = isRelatedTo(constraint, target, reportErrors))) {
|
|
63903
|
+
if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
63696
63904
|
resetErrorInfo(saveErrorInfo);
|
|
63697
63905
|
return result;
|
|
63698
63906
|
}
|
|
@@ -63700,27 +63908,32 @@ var ts;
|
|
|
63700
63908
|
}
|
|
63701
63909
|
else if (source.flags & 16777216 /* Conditional */) {
|
|
63702
63910
|
if (target.flags & 16777216 /* Conditional */) {
|
|
63703
|
-
//
|
|
63704
|
-
//
|
|
63705
|
-
//
|
|
63706
|
-
|
|
63707
|
-
|
|
63708
|
-
|
|
63709
|
-
|
|
63710
|
-
|
|
63711
|
-
var
|
|
63712
|
-
|
|
63713
|
-
|
|
63714
|
-
|
|
63715
|
-
|
|
63716
|
-
|
|
63717
|
-
|
|
63718
|
-
|
|
63719
|
-
|
|
63720
|
-
|
|
63721
|
-
|
|
63722
|
-
|
|
63723
|
-
|
|
63911
|
+
// If one of the conditionals under comparison seems to be infinitely expanding, stop comparing it - back out, try
|
|
63912
|
+
// the constraint, and failing that, give up trying to relate the two. This is the only way we can handle recursive conditional
|
|
63913
|
+
// types, which might expand forever.
|
|
63914
|
+
if (!isDeeplyNestedType(source, sourceStack, sourceDepth) && !isDeeplyNestedType(target, targetStack, targetDepth)) {
|
|
63915
|
+
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
|
|
63916
|
+
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
|
|
63917
|
+
// and Y1 is related to Y2.
|
|
63918
|
+
var sourceParams = source.root.inferTypeParameters;
|
|
63919
|
+
var sourceExtends = source.extendsType;
|
|
63920
|
+
var mapper = void 0;
|
|
63921
|
+
if (sourceParams) {
|
|
63922
|
+
// If the source has infer type parameters, we instantiate them in the context of the target
|
|
63923
|
+
var ctx = createInferenceContext(sourceParams, /*signature*/ undefined, 0 /* None */, isRelatedToWorker);
|
|
63924
|
+
inferTypes(ctx.inferences, target.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
63925
|
+
sourceExtends = instantiateType(sourceExtends, ctx.mapper);
|
|
63926
|
+
mapper = ctx.mapper;
|
|
63927
|
+
}
|
|
63928
|
+
if (isTypeIdenticalTo(sourceExtends, target.extendsType) &&
|
|
63929
|
+
(isRelatedTo(source.checkType, target.checkType, 3 /* Both */) || isRelatedTo(target.checkType, source.checkType, 3 /* Both */))) {
|
|
63930
|
+
if (result = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(source), mapper), getTrueTypeFromConditionalType(target), 3 /* Both */, reportErrors)) {
|
|
63931
|
+
result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, reportErrors);
|
|
63932
|
+
}
|
|
63933
|
+
if (result) {
|
|
63934
|
+
resetErrorInfo(saveErrorInfo);
|
|
63935
|
+
return result;
|
|
63936
|
+
}
|
|
63724
63937
|
}
|
|
63725
63938
|
}
|
|
63726
63939
|
}
|
|
@@ -63729,19 +63942,23 @@ var ts;
|
|
|
63729
63942
|
// more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
|
|
63730
63943
|
var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
|
|
63731
63944
|
if (distributiveConstraint) {
|
|
63732
|
-
if (result = isRelatedTo(distributiveConstraint, target, reportErrors)) {
|
|
63945
|
+
if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
|
|
63733
63946
|
resetErrorInfo(saveErrorInfo);
|
|
63734
63947
|
return result;
|
|
63735
63948
|
}
|
|
63736
63949
|
}
|
|
63737
63950
|
}
|
|
63738
|
-
//
|
|
63739
|
-
//
|
|
63740
|
-
|
|
63741
|
-
|
|
63742
|
-
|
|
63743
|
-
|
|
63744
|
-
|
|
63951
|
+
// We'll repeatedly decompose source side conditionals if they're recursive - check if we've already recured on the constraint a lot and, if so, bail
|
|
63952
|
+
// on the comparison.
|
|
63953
|
+
if (!isDeeplyNestedType(source, sourceStack, sourceDepth)) {
|
|
63954
|
+
// conditionals _can_ be related to one another via normal constraint, as, eg, `A extends B ? O : never` should be assignable to `O`
|
|
63955
|
+
// when `O` is a conditional (`never` is trivially assignable to `O`, as is `O`!).
|
|
63956
|
+
var defaultConstraint = getDefaultConstraintOfConditionalType(source);
|
|
63957
|
+
if (defaultConstraint) {
|
|
63958
|
+
if (result = isRelatedTo(defaultConstraint, target, 1 /* Source */, reportErrors)) {
|
|
63959
|
+
resetErrorInfo(saveErrorInfo);
|
|
63960
|
+
return result;
|
|
63961
|
+
}
|
|
63745
63962
|
}
|
|
63746
63963
|
}
|
|
63747
63964
|
}
|
|
@@ -63785,7 +64002,7 @@ var ts;
|
|
|
63785
64002
|
}
|
|
63786
64003
|
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
|
|
63787
64004
|
if (relation !== identityRelation) {
|
|
63788
|
-
return isRelatedTo(getIndexTypeOfType(source, numberType) || anyType, getIndexTypeOfType(target, numberType) || anyType, reportErrors);
|
|
64005
|
+
return isRelatedTo(getIndexTypeOfType(source, numberType) || anyType, getIndexTypeOfType(target, numberType) || anyType, 3 /* Both */, reportErrors);
|
|
63789
64006
|
}
|
|
63790
64007
|
else {
|
|
63791
64008
|
// By flags alone, we know that the `target` is a readonly array while the source is a normal array or tuple
|
|
@@ -63907,10 +64124,10 @@ var ts;
|
|
|
63907
64124
|
var result_11;
|
|
63908
64125
|
var targetConstraint = getConstraintTypeFromMappedType(target);
|
|
63909
64126
|
var sourceConstraint = instantiateType(getConstraintTypeFromMappedType(source), makeFunctionTypeMapper(getCombinedMappedTypeOptionality(source) < 0 ? reportUnmeasurableMarkers : reportUnreliableMarkers));
|
|
63910
|
-
if (result_11 = isRelatedTo(targetConstraint, sourceConstraint, reportErrors)) {
|
|
64127
|
+
if (result_11 = isRelatedTo(targetConstraint, sourceConstraint, 3 /* Both */, reportErrors)) {
|
|
63911
64128
|
var mapper = createTypeMapper([getTypeParameterFromMappedType(source)], [getTypeParameterFromMappedType(target)]);
|
|
63912
64129
|
if (instantiateType(getNameTypeFromMappedType(source), mapper) === instantiateType(getNameTypeFromMappedType(target), mapper)) {
|
|
63913
|
-
return result_11 & isRelatedTo(instantiateType(getTemplateTypeFromMappedType(source), mapper), getTemplateTypeFromMappedType(target), reportErrors);
|
|
64130
|
+
return result_11 & isRelatedTo(instantiateType(getTemplateTypeFromMappedType(source), mapper), getTemplateTypeFromMappedType(target), 3 /* Both */, reportErrors);
|
|
63914
64131
|
}
|
|
63915
64132
|
}
|
|
63916
64133
|
}
|
|
@@ -64042,7 +64259,7 @@ var ts;
|
|
|
64042
64259
|
var targetIsOptional = strictNullChecks && !!(ts.getCheckFlags(targetProp) & 48 /* Partial */);
|
|
64043
64260
|
var effectiveTarget = addOptionality(getNonMissingTypeOfSymbol(targetProp), /*isProperty*/ false, targetIsOptional);
|
|
64044
64261
|
var effectiveSource = getTypeOfSourceProperty(sourceProp);
|
|
64045
|
-
return isRelatedTo(effectiveSource, effectiveTarget, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64262
|
+
return isRelatedTo(effectiveSource, effectiveTarget, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64046
64263
|
}
|
|
64047
64264
|
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
|
|
64048
64265
|
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
|
|
@@ -64224,7 +64441,7 @@ var ts;
|
|
|
64224
64441
|
var targetType = targetTypeArguments[i];
|
|
64225
64442
|
var targetCheckType = sourceFlags & 8 /* Variadic */ && targetFlags & 4 /* Rest */ ? createArrayType(targetType) :
|
|
64226
64443
|
removeMissingType(targetType, !!(targetFlags & 2 /* Optional */));
|
|
64227
|
-
var related = isRelatedTo(sourceType, targetCheckType, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64444
|
+
var related = isRelatedTo(sourceType, targetCheckType, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64228
64445
|
if (!related) {
|
|
64229
64446
|
if (reportErrors && (targetArity > 1 || sourceArity > 1)) {
|
|
64230
64447
|
if (i < startCount || i >= targetArity - endCount || sourceArity - startCount - endCount === 1) {
|
|
@@ -64418,7 +64635,7 @@ var ts;
|
|
|
64418
64635
|
* See signatureAssignableTo, compareSignaturesIdentical
|
|
64419
64636
|
*/
|
|
64420
64637
|
function signatureRelatedTo(source, target, erase, reportErrors, incompatibleReporter) {
|
|
64421
|
-
return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, relation === strictSubtypeRelation ? 8 /* StrictArity */ : 0, reportErrors, reportError, incompatibleReporter,
|
|
64638
|
+
return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, relation === strictSubtypeRelation ? 8 /* StrictArity */ : 0, reportErrors, reportError, incompatibleReporter, isRelatedToWorker, makeFunctionTypeMapper(reportUnreliableMarkers));
|
|
64422
64639
|
}
|
|
64423
64640
|
function signaturesIdenticalTo(source, target, kind) {
|
|
64424
64641
|
var sourceSignatures = getSignaturesOfType(source, kind);
|
|
@@ -64451,7 +64668,7 @@ var ts;
|
|
|
64451
64668
|
var type = exactOptionalPropertyTypes || propType.flags & 32768 /* Undefined */ || keyType === numberType || !(prop.flags & 16777216 /* Optional */)
|
|
64452
64669
|
? propType
|
|
64453
64670
|
: getTypeWithFacts(propType, 524288 /* NEUndefined */);
|
|
64454
|
-
var related = isRelatedTo(type, targetInfo.type, reportErrors);
|
|
64671
|
+
var related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors);
|
|
64455
64672
|
if (!related) {
|
|
64456
64673
|
if (reportErrors) {
|
|
64457
64674
|
reportError(ts.Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
|
|
@@ -64474,7 +64691,7 @@ var ts;
|
|
|
64474
64691
|
return result;
|
|
64475
64692
|
}
|
|
64476
64693
|
function indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors) {
|
|
64477
|
-
var related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors);
|
|
64694
|
+
var related = isRelatedTo(sourceInfo.type, targetInfo.type, 3 /* Both */, reportErrors);
|
|
64478
64695
|
if (!related && reportErrors) {
|
|
64479
64696
|
if (sourceInfo.keyType === targetInfo.keyType) {
|
|
64480
64697
|
reportError(ts.Diagnostics._0_index_signatures_are_incompatible, typeToString(sourceInfo.keyType));
|
|
@@ -64495,7 +64712,7 @@ var ts;
|
|
|
64495
64712
|
for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
|
|
64496
64713
|
var targetInfo = indexInfos_3[_i];
|
|
64497
64714
|
var related = !sourceIsPrimitive && targetHasStringIndex && targetInfo.type.flags & 1 /* Any */ ? -1 /* True */ :
|
|
64498
|
-
isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, reportErrors) :
|
|
64715
|
+
isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, 3 /* Both */, reportErrors) :
|
|
64499
64716
|
typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
|
|
64500
64717
|
if (!related) {
|
|
64501
64718
|
return 0 /* False */;
|
|
@@ -64527,7 +64744,7 @@ var ts;
|
|
|
64527
64744
|
for (var _i = 0, targetInfos_1 = targetInfos; _i < targetInfos_1.length; _i++) {
|
|
64528
64745
|
var targetInfo = targetInfos_1[_i];
|
|
64529
64746
|
var sourceInfo = getIndexInfoOfType(source, targetInfo.keyType);
|
|
64530
|
-
if (!(sourceInfo && isRelatedTo(sourceInfo.type, targetInfo.type) && sourceInfo.isReadonly === targetInfo.isReadonly)) {
|
|
64747
|
+
if (!(sourceInfo && isRelatedTo(sourceInfo.type, targetInfo.type, 3 /* Both */) && sourceInfo.isReadonly === targetInfo.isReadonly)) {
|
|
64531
64748
|
return 0 /* False */;
|
|
64532
64749
|
}
|
|
64533
64750
|
}
|
|
@@ -65941,6 +66158,17 @@ var ts;
|
|
|
65941
66158
|
function isFromInferenceBlockedSource(type) {
|
|
65942
66159
|
return !!(type.symbol && ts.some(type.symbol.declarations, hasSkipDirectInferenceFlag));
|
|
65943
66160
|
}
|
|
66161
|
+
function templateLiteralTypesDefinitelyUnrelated(source, target) {
|
|
66162
|
+
// Two template literal types with diffences in their starting or ending text spans are definitely unrelated.
|
|
66163
|
+
var sourceStart = source.texts[0];
|
|
66164
|
+
var targetStart = target.texts[0];
|
|
66165
|
+
var sourceEnd = source.texts[source.texts.length - 1];
|
|
66166
|
+
var targetEnd = target.texts[target.texts.length - 1];
|
|
66167
|
+
var startLen = Math.min(sourceStart.length, targetStart.length);
|
|
66168
|
+
var endLen = Math.min(sourceEnd.length, targetEnd.length);
|
|
66169
|
+
return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
|
|
66170
|
+
sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
|
|
66171
|
+
}
|
|
65944
66172
|
function isValidBigIntString(s) {
|
|
65945
66173
|
var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
|
|
65946
66174
|
var success = true;
|
|
@@ -67003,7 +67231,7 @@ var ts;
|
|
|
67003
67231
|
if (prop.isDiscriminantProperty === undefined) {
|
|
67004
67232
|
prop.isDiscriminantProperty =
|
|
67005
67233
|
(prop.checkFlags & 192 /* Discriminant */) === 192 /* Discriminant */ &&
|
|
67006
|
-
!
|
|
67234
|
+
!isGenericType(getTypeOfSymbol(prop));
|
|
67007
67235
|
}
|
|
67008
67236
|
return !!prop.isDiscriminantProperty;
|
|
67009
67237
|
}
|
|
@@ -67522,17 +67750,19 @@ var ts;
|
|
|
67522
67750
|
function extractTypesOfKind(type, kind) {
|
|
67523
67751
|
return filterType(type, function (t) { return (t.flags & kind) !== 0; });
|
|
67524
67752
|
}
|
|
67525
|
-
// Return a new type in which occurrences of the string and
|
|
67526
|
-
// typeWithPrimitives have been replaced with occurrences of
|
|
67527
|
-
//
|
|
67753
|
+
// Return a new type in which occurrences of the string, number and bigint primitives and placeholder template
|
|
67754
|
+
// literal types in typeWithPrimitives have been replaced with occurrences of compatible and more specific types
|
|
67755
|
+
// from typeWithLiterals. This is essentially a limited form of intersection between the two types. We avoid a
|
|
67756
|
+
// true intersection because it is more costly and, when applied to union types, generates a large number of
|
|
67757
|
+
// types we don't actually care about.
|
|
67528
67758
|
function replacePrimitivesWithLiterals(typeWithPrimitives, typeWithLiterals) {
|
|
67529
|
-
if (
|
|
67530
|
-
|
|
67531
|
-
isTypeSubsetOf(bigintType, typeWithPrimitives) && maybeTypeOfKind(typeWithLiterals, 2048 /* BigIntLiteral */)) {
|
|
67759
|
+
if (maybeTypeOfKind(typeWithPrimitives, 4 /* String */ | 134217728 /* TemplateLiteral */ | 8 /* Number */ | 64 /* BigInt */) &&
|
|
67760
|
+
maybeTypeOfKind(typeWithLiterals, 128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 256 /* NumberLiteral */ | 2048 /* BigIntLiteral */)) {
|
|
67532
67761
|
return mapType(typeWithPrimitives, function (t) {
|
|
67533
|
-
return t.flags & 4 /* String */ ? extractTypesOfKind(typeWithLiterals, 4 /* String */ | 128 /* StringLiteral */) :
|
|
67534
|
-
t
|
|
67535
|
-
t.flags &
|
|
67762
|
+
return t.flags & 4 /* String */ ? extractTypesOfKind(typeWithLiterals, 4 /* String */ | 128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) :
|
|
67763
|
+
isPatternLiteralType(t) && !maybeTypeOfKind(typeWithLiterals, 4 /* String */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ? extractTypesOfKind(typeWithLiterals, 128 /* StringLiteral */) :
|
|
67764
|
+
t.flags & 8 /* Number */ ? extractTypesOfKind(typeWithLiterals, 8 /* Number */ | 256 /* NumberLiteral */) :
|
|
67765
|
+
t.flags & 64 /* BigInt */ ? extractTypesOfKind(typeWithLiterals, 64 /* BigInt */ | 2048 /* BigIntLiteral */) : t;
|
|
67536
67766
|
});
|
|
67537
67767
|
}
|
|
67538
67768
|
return typeWithPrimitives;
|
|
@@ -67613,10 +67843,10 @@ var ts;
|
|
|
67613
67843
|
isTypeAssignableToKind(getTypeOfExpression(parent.argumentExpression), 296 /* NumberLike */);
|
|
67614
67844
|
return isLengthPushOrUnshift || isElementAssignment;
|
|
67615
67845
|
}
|
|
67616
|
-
function isDeclarationWithExplicitTypeAnnotation(
|
|
67617
|
-
return (
|
|
67618
|
-
|
|
67619
|
-
|
|
67846
|
+
function isDeclarationWithExplicitTypeAnnotation(node) {
|
|
67847
|
+
return (ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)) &&
|
|
67848
|
+
!!(ts.getEffectiveTypeAnnotationNode(node) ||
|
|
67849
|
+
ts.isInJSFile(node) && ts.hasInitializer(node) && node.initializer && ts.isFunctionExpressionOrArrowFunction(node.initializer) && ts.getEffectiveReturnTypeNode(node.initializer));
|
|
67620
67850
|
}
|
|
67621
67851
|
function getExplicitTypeOfSymbol(symbol, diagnostic) {
|
|
67622
67852
|
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 512 /* ValueModule */)) {
|
|
@@ -68333,7 +68563,7 @@ var ts;
|
|
|
68333
68563
|
var narrowedPropType = narrowType(propType);
|
|
68334
68564
|
return filterType(type, function (t) {
|
|
68335
68565
|
var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
|
|
68336
|
-
return !(
|
|
68566
|
+
return !(narrowedPropType.flags & 131072 /* Never */) && isTypeComparableTo(narrowedPropType, discriminantType);
|
|
68337
68567
|
});
|
|
68338
68568
|
}
|
|
68339
68569
|
function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) {
|
|
@@ -68802,16 +69032,7 @@ var ts;
|
|
|
68802
69032
|
}
|
|
68803
69033
|
function getNarrowedType(type, candidate, assumeTrue, isRelated) {
|
|
68804
69034
|
if (!assumeTrue) {
|
|
68805
|
-
return filterType(type, function (t) {
|
|
68806
|
-
if (!isRelated(t, candidate)) {
|
|
68807
|
-
return true;
|
|
68808
|
-
}
|
|
68809
|
-
var constraint = getBaseConstraintOfType(t);
|
|
68810
|
-
if (constraint && constraint !== t) {
|
|
68811
|
-
return !isRelated(constraint, candidate);
|
|
68812
|
-
}
|
|
68813
|
-
return false;
|
|
68814
|
-
});
|
|
69035
|
+
return filterType(type, function (t) { return !isRelated(t, candidate); });
|
|
68815
69036
|
}
|
|
68816
69037
|
// If the current type is a union type, remove all constituents that couldn't be instances of
|
|
68817
69038
|
// the candidate type. If one or more constituents remain, return a union of those.
|
|
@@ -70253,9 +70474,9 @@ var ts;
|
|
|
70253
70474
|
return getTypeOfPropertyOfContextualType(type, getSymbolOfNode(element).escapedName);
|
|
70254
70475
|
}
|
|
70255
70476
|
if (element.name) {
|
|
70256
|
-
var
|
|
70477
|
+
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
70257
70478
|
// We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction.
|
|
70258
|
-
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t),
|
|
70479
|
+
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType_2)) === null || _a === void 0 ? void 0 : _a.type; }, /*noReductions*/ true);
|
|
70259
70480
|
}
|
|
70260
70481
|
}
|
|
70261
70482
|
return undefined;
|
|
@@ -70713,12 +70934,9 @@ var ts;
|
|
|
70713
70934
|
}
|
|
70714
70935
|
return !hasEffectiveRestParameter(signature) && getParameterCount(signature) < targetParameterCount;
|
|
70715
70936
|
}
|
|
70716
|
-
function isFunctionExpressionOrArrowFunction(node) {
|
|
70717
|
-
return node.kind === 212 /* FunctionExpression */ || node.kind === 213 /* ArrowFunction */;
|
|
70718
|
-
}
|
|
70719
70937
|
function getContextualSignatureForFunctionLikeDeclaration(node) {
|
|
70720
70938
|
// Only function expressions, arrow functions, and object literal methods are contextually typed.
|
|
70721
|
-
return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
|
|
70939
|
+
return ts.isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
|
|
70722
70940
|
? getContextualSignature(node)
|
|
70723
70941
|
: undefined;
|
|
70724
70942
|
}
|
|
@@ -71685,6 +71903,14 @@ var ts;
|
|
|
71685
71903
|
markAliasSymbolAsReferenced(jsxFactorySym);
|
|
71686
71904
|
}
|
|
71687
71905
|
}
|
|
71906
|
+
// For JsxFragment, mark jsx pragma as referenced via resolveName
|
|
71907
|
+
if (ts.isJsxOpeningFragment(node)) {
|
|
71908
|
+
var file = ts.getSourceFileOfNode(node);
|
|
71909
|
+
var localJsxNamespace = getLocalJsxNamespace(file);
|
|
71910
|
+
if (localJsxNamespace) {
|
|
71911
|
+
resolveName(jsxFactoryLocation, localJsxNamespace, 111551 /* Value */, jsxFactoryRefErr, localJsxNamespace, /*isUse*/ true);
|
|
71912
|
+
}
|
|
71913
|
+
}
|
|
71688
71914
|
}
|
|
71689
71915
|
if (isNodeOpeningLikeElement) {
|
|
71690
71916
|
var jsxOpeningLikeNode = node;
|
|
@@ -73357,7 +73583,7 @@ var ts;
|
|
|
73357
73583
|
return false;
|
|
73358
73584
|
var symbol = resolveName(node.expression, node.expression.escapedText, 111551 /* Value */, undefined, undefined, false);
|
|
73359
73585
|
var decl = symbol === null || symbol === void 0 ? void 0 : symbol.valueDeclaration;
|
|
73360
|
-
if (!decl || !ts.isParameter(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !ts.isNewExpression(decl.parent.parent) || !ts.isIdentifier(decl.parent.parent.expression)) {
|
|
73586
|
+
if (!decl || !ts.isParameter(decl) || !ts.isFunctionExpressionOrArrowFunction(decl.parent) || !ts.isNewExpression(decl.parent.parent) || !ts.isIdentifier(decl.parent.parent.expression)) {
|
|
73361
73587
|
return false;
|
|
73362
73588
|
}
|
|
73363
73589
|
var globalPromiseSymbol = getGlobalPromiseConstructorSymbol(/*reportErrors*/ false);
|
|
@@ -74601,18 +74827,18 @@ var ts;
|
|
|
74601
74827
|
if (moduleSymbol) {
|
|
74602
74828
|
var esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false);
|
|
74603
74829
|
if (esModuleSymbol) {
|
|
74604
|
-
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol));
|
|
74830
|
+
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
|
|
74605
74831
|
}
|
|
74606
74832
|
}
|
|
74607
74833
|
return createPromiseReturnType(node, anyType);
|
|
74608
74834
|
}
|
|
74609
|
-
function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol) {
|
|
74835
|
+
function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol, moduleSpecifier) {
|
|
74610
74836
|
var _a;
|
|
74611
74837
|
if (allowSyntheticDefaultImports && type && !isErrorType(type)) {
|
|
74612
74838
|
var synthType = type;
|
|
74613
74839
|
if (!synthType.syntheticType) {
|
|
74614
74840
|
var file = (_a = originalSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
74615
|
-
var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false);
|
|
74841
|
+
var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false, moduleSpecifier);
|
|
74616
74842
|
if (hasSyntheticDefault) {
|
|
74617
74843
|
var memberTable = ts.createSymbolTable();
|
|
74618
74844
|
var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
|
|
@@ -74774,16 +75000,14 @@ var ts;
|
|
|
74774
75000
|
}
|
|
74775
75001
|
}
|
|
74776
75002
|
function checkImportMetaProperty(node) {
|
|
74777
|
-
if (moduleKind
|
|
74778
|
-
if (
|
|
74779
|
-
|
|
74780
|
-
error(node, ts.Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
|
|
74781
|
-
}
|
|
74782
|
-
}
|
|
74783
|
-
else {
|
|
74784
|
-
error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_system_node12_or_nodenext);
|
|
75003
|
+
if (moduleKind === ts.ModuleKind.Node12 || moduleKind === ts.ModuleKind.NodeNext) {
|
|
75004
|
+
if (ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.ESNext) {
|
|
75005
|
+
error(node, ts.Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
|
|
74785
75006
|
}
|
|
74786
75007
|
}
|
|
75008
|
+
else if (moduleKind < ts.ModuleKind.ES2020 && moduleKind !== ts.ModuleKind.System) {
|
|
75009
|
+
error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
|
|
75010
|
+
}
|
|
74787
75011
|
var file = ts.getSourceFileOfNode(node);
|
|
74788
75012
|
ts.Debug.assert(!!(file.flags & 2097152 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
|
|
74789
75013
|
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
|
|
@@ -75726,9 +75950,9 @@ var ts;
|
|
|
75726
75950
|
var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module);
|
|
75727
75951
|
diagnostics.add(diagnostic);
|
|
75728
75952
|
}
|
|
75729
|
-
if ((moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
75953
|
+
if ((moduleKind !== ts.ModuleKind.ES2022 && moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
75730
75954
|
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
75731
|
-
var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.
|
|
75955
|
+
var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
|
|
75732
75956
|
diagnostics.add(diagnostic);
|
|
75733
75957
|
}
|
|
75734
75958
|
}
|
|
@@ -77166,7 +77390,7 @@ var ts;
|
|
|
77166
77390
|
}
|
|
77167
77391
|
}
|
|
77168
77392
|
function checkParenthesizedExpression(node, checkMode) {
|
|
77169
|
-
if (ts.isJSDocTypeAssertion(node)) {
|
|
77393
|
+
if (ts.hasJSDocNodes(node) && ts.isJSDocTypeAssertion(node)) {
|
|
77170
77394
|
var type = ts.getJSDocTypeAssertionType(node);
|
|
77171
77395
|
return checkAssertionWorker(type, type, node.expression, checkMode);
|
|
77172
77396
|
}
|
|
@@ -79063,6 +79287,12 @@ var ts;
|
|
|
79063
79287
|
}
|
|
79064
79288
|
}
|
|
79065
79289
|
}
|
|
79290
|
+
function checkJSDocAccessibilityModifiers(node) {
|
|
79291
|
+
var host = ts.getJSDocHost(node);
|
|
79292
|
+
if (host && ts.isPrivateIdentifierClassElementDeclaration(host)) {
|
|
79293
|
+
error(node, ts.Diagnostics.An_accessibility_modifier_cannot_be_used_with_a_private_identifier);
|
|
79294
|
+
}
|
|
79295
|
+
}
|
|
79066
79296
|
function getIdentifierFromEntityNameExpression(node) {
|
|
79067
79297
|
switch (node.kind) {
|
|
79068
79298
|
case 79 /* Identifier */:
|
|
@@ -82398,11 +82628,15 @@ var ts;
|
|
|
82398
82628
|
}
|
|
82399
82629
|
function checkGrammarExportDeclaration(node) {
|
|
82400
82630
|
var _a;
|
|
82401
|
-
|
|
82402
|
-
|
|
82403
|
-
|
|
82631
|
+
if (node.isTypeOnly) {
|
|
82632
|
+
if (((_a = node.exportClause) === null || _a === void 0 ? void 0 : _a.kind) === 272 /* NamedExports */) {
|
|
82633
|
+
return checkGrammarNamedImportsOrExports(node.exportClause);
|
|
82634
|
+
}
|
|
82635
|
+
else {
|
|
82636
|
+
return grammarErrorOnNode(node, ts.Diagnostics.Only_named_exports_may_use_export_type);
|
|
82637
|
+
}
|
|
82404
82638
|
}
|
|
82405
|
-
return
|
|
82639
|
+
return false;
|
|
82406
82640
|
}
|
|
82407
82641
|
function checkGrammarModuleElementContext(node, errorMessage) {
|
|
82408
82642
|
var isInAppropriateContext = node.parent.kind === 303 /* SourceFile */ || node.parent.kind === 261 /* ModuleBlock */ || node.parent.kind === 260 /* ModuleDeclaration */;
|
|
@@ -82712,6 +82946,10 @@ var ts;
|
|
|
82712
82946
|
return;
|
|
82713
82947
|
case 307 /* JSDocTypeExpression */:
|
|
82714
82948
|
return checkSourceElement(node.type);
|
|
82949
|
+
case 331 /* JSDocPublicTag */:
|
|
82950
|
+
case 333 /* JSDocProtectedTag */:
|
|
82951
|
+
case 332 /* JSDocPrivateTag */:
|
|
82952
|
+
return checkJSDocAccessibilityModifiers(node);
|
|
82715
82953
|
case 193 /* IndexedAccessType */:
|
|
82716
82954
|
return checkIndexedAccessType(node);
|
|
82717
82955
|
case 194 /* MappedType */:
|
|
@@ -85407,8 +85645,8 @@ var ts;
|
|
|
85407
85645
|
if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
|
|
85408
85646
|
diagnostics.add(ts.createDiagnosticForNode(forInOrOfStatement.awaitModifier, ts.Diagnostics.for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module));
|
|
85409
85647
|
}
|
|
85410
|
-
if ((moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
85411
|
-
diagnostics.add(ts.createDiagnosticForNode(forInOrOfStatement.awaitModifier, ts.Diagnostics.
|
|
85648
|
+
if ((moduleKind !== ts.ModuleKind.ES2022 && moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
85649
|
+
diagnostics.add(ts.createDiagnosticForNode(forInOrOfStatement.awaitModifier, ts.Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher));
|
|
85412
85650
|
}
|
|
85413
85651
|
}
|
|
85414
85652
|
}
|
|
@@ -86077,14 +86315,27 @@ var ts;
|
|
|
86077
86315
|
return ambientModulesCache;
|
|
86078
86316
|
}
|
|
86079
86317
|
function checkGrammarImportClause(node) {
|
|
86318
|
+
var _a;
|
|
86080
86319
|
if (node.isTypeOnly && node.name && node.namedBindings) {
|
|
86081
86320
|
return grammarErrorOnNode(node, ts.Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both);
|
|
86082
86321
|
}
|
|
86322
|
+
if (node.isTypeOnly && ((_a = node.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 268 /* NamedImports */) {
|
|
86323
|
+
return checkGrammarNamedImportsOrExports(node.namedBindings);
|
|
86324
|
+
}
|
|
86083
86325
|
return false;
|
|
86084
86326
|
}
|
|
86327
|
+
function checkGrammarNamedImportsOrExports(namedBindings) {
|
|
86328
|
+
return !!ts.forEach(namedBindings.elements, function (specifier) {
|
|
86329
|
+
if (specifier.isTypeOnly) {
|
|
86330
|
+
return grammarErrorOnFirstToken(specifier, specifier.kind === 269 /* ImportSpecifier */
|
|
86331
|
+
? ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement
|
|
86332
|
+
: ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement);
|
|
86333
|
+
}
|
|
86334
|
+
});
|
|
86335
|
+
}
|
|
86085
86336
|
function checkGrammarImportCallExpression(node) {
|
|
86086
86337
|
if (moduleKind === ts.ModuleKind.ES2015) {
|
|
86087
|
-
return grammarErrorOnNode(node, ts.Diagnostics.
|
|
86338
|
+
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node12_or_nodenext);
|
|
86088
86339
|
}
|
|
86089
86340
|
if (node.typeArguments) {
|
|
86090
86341
|
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_cannot_have_type_arguments);
|
|
@@ -86813,7 +87064,7 @@ var ts;
|
|
|
86813
87064
|
return factory.updateNamedImports(node, nodesVisitor(node.elements, visitor, ts.isImportSpecifier));
|
|
86814
87065
|
case 269 /* ImportSpecifier */:
|
|
86815
87066
|
ts.Debug.type(node);
|
|
86816
|
-
return factory.updateImportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87067
|
+
return factory.updateImportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86817
87068
|
case 270 /* ExportAssignment */:
|
|
86818
87069
|
ts.Debug.type(node);
|
|
86819
87070
|
return factory.updateExportAssignment(node, nodesVisitor(node.decorators, visitor, ts.isDecorator), nodesVisitor(node.modifiers, visitor, ts.isModifier), nodeVisitor(node.expression, visitor, ts.isExpression));
|
|
@@ -86825,7 +87076,7 @@ var ts;
|
|
|
86825
87076
|
return factory.updateNamedExports(node, nodesVisitor(node.elements, visitor, ts.isExportSpecifier));
|
|
86826
87077
|
case 274 /* ExportSpecifier */:
|
|
86827
87078
|
ts.Debug.type(node);
|
|
86828
|
-
return factory.updateExportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87079
|
+
return factory.updateExportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86829
87080
|
// Module references
|
|
86830
87081
|
case 276 /* ExternalModuleReference */:
|
|
86831
87082
|
ts.Debug.type(node);
|
|
@@ -87198,7 +87449,7 @@ var ts;
|
|
|
87198
87449
|
}
|
|
87199
87450
|
ts.createSourceMapGenerator = createSourceMapGenerator;
|
|
87200
87451
|
// Sometimes tools can see the following line as a source mapping url comment, so we mangle it a bit (the [M])
|
|
87201
|
-
var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)
|
|
87452
|
+
var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
|
|
87202
87453
|
var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;
|
|
87203
87454
|
function getLineInfo(text, lineStarts) {
|
|
87204
87455
|
return {
|
|
@@ -90490,6 +90741,7 @@ var ts;
|
|
|
90490
90741
|
|| (isExternalModuleExport(node)
|
|
90491
90742
|
&& moduleKind !== ts.ModuleKind.ES2015
|
|
90492
90743
|
&& moduleKind !== ts.ModuleKind.ES2020
|
|
90744
|
+
&& moduleKind !== ts.ModuleKind.ES2022
|
|
90493
90745
|
&& moduleKind !== ts.ModuleKind.ESNext
|
|
90494
90746
|
&& moduleKind !== ts.ModuleKind.System);
|
|
90495
90747
|
}
|
|
@@ -90766,9 +91018,11 @@ var ts;
|
|
|
90766
91018
|
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90767
91019
|
}
|
|
90768
91020
|
else {
|
|
90769
|
-
// Elide named imports if all of its import specifiers are elided.
|
|
91021
|
+
// Elide named imports if all of its import specifiers are elided and settings allow.
|
|
91022
|
+
var allowEmpty = compilerOptions.preserveValueImports && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91023
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
90770
91024
|
var elements = ts.visitNodes(node.elements, visitImportSpecifier, ts.isImportSpecifier);
|
|
90771
|
-
return ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
91025
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
90772
91026
|
}
|
|
90773
91027
|
}
|
|
90774
91028
|
/**
|
|
@@ -90777,7 +91031,7 @@ var ts;
|
|
|
90777
91031
|
* @param node The import specifier node.
|
|
90778
91032
|
*/
|
|
90779
91033
|
function visitImportSpecifier(node) {
|
|
90780
|
-
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
91034
|
+
return !node.isTypeOnly && shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90781
91035
|
}
|
|
90782
91036
|
/**
|
|
90783
91037
|
* Visits an export assignment, eliding it if it does not contain a clause that resolves
|
|
@@ -90806,12 +91060,10 @@ var ts;
|
|
|
90806
91060
|
// type checker doesn't know about any exports
|
|
90807
91061
|
return node;
|
|
90808
91062
|
}
|
|
90809
|
-
if (!resolver.isValueAliasDeclaration(node)) {
|
|
90810
|
-
// Elide the export declaration if it does not export a value.
|
|
90811
|
-
return undefined;
|
|
90812
|
-
}
|
|
90813
91063
|
// Elide the export declaration if all of its named exports are elided.
|
|
90814
|
-
var
|
|
91064
|
+
var allowEmpty = !!node.moduleSpecifier && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91065
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
91066
|
+
var exportClause = ts.visitNode(node.exportClause, function (bindings) { return visitNamedExportBindings(bindings, allowEmpty); }, ts.isNamedExportBindings);
|
|
90815
91067
|
return exportClause
|
|
90816
91068
|
? factory.updateExportDeclaration(node,
|
|
90817
91069
|
/*decorators*/ undefined,
|
|
@@ -90824,16 +91076,16 @@ var ts;
|
|
|
90824
91076
|
*
|
|
90825
91077
|
* @param node The named exports node.
|
|
90826
91078
|
*/
|
|
90827
|
-
function visitNamedExports(node) {
|
|
91079
|
+
function visitNamedExports(node, allowEmpty) {
|
|
90828
91080
|
// Elide the named exports if all of its export specifiers were elided.
|
|
90829
91081
|
var elements = ts.visitNodes(node.elements, visitExportSpecifier, ts.isExportSpecifier);
|
|
90830
|
-
return ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
91082
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
90831
91083
|
}
|
|
90832
91084
|
function visitNamespaceExports(node) {
|
|
90833
91085
|
return factory.updateNamespaceExport(node, ts.visitNode(node.name, visitor, ts.isIdentifier));
|
|
90834
91086
|
}
|
|
90835
|
-
function visitNamedExportBindings(node) {
|
|
90836
|
-
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node);
|
|
91087
|
+
function visitNamedExportBindings(node, allowEmpty) {
|
|
91088
|
+
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node, allowEmpty);
|
|
90837
91089
|
}
|
|
90838
91090
|
/**
|
|
90839
91091
|
* Visits an export specifier, eliding it if it does not resolve to a value.
|
|
@@ -90842,7 +91094,7 @@ var ts;
|
|
|
90842
91094
|
*/
|
|
90843
91095
|
function visitExportSpecifier(node) {
|
|
90844
91096
|
// Elide an export specifier if it does not reference a value.
|
|
90845
|
-
return resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
91097
|
+
return !node.isTypeOnly && resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
90846
91098
|
}
|
|
90847
91099
|
/**
|
|
90848
91100
|
* Determines whether to emit an import equals declaration.
|
|
@@ -94443,7 +94695,7 @@ var ts;
|
|
|
94443
94695
|
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
|
|
94444
94696
|
}
|
|
94445
94697
|
var generatedName = factory.createUniqueName("_" + name, 16 /* Optimistic */ | 32 /* FileLevel */ | 64 /* AllowNameSubstitution */);
|
|
94446
|
-
var specifier = factory.createImportSpecifier(factory.createIdentifier(name), generatedName);
|
|
94698
|
+
var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName);
|
|
94447
94699
|
generatedName.generatedImportReference = specifier;
|
|
94448
94700
|
specifierSourceImports.set(name, specifier);
|
|
94449
94701
|
return generatedName;
|
|
@@ -104159,7 +104411,7 @@ var ts;
|
|
|
104159
104411
|
/*modifiers*/ undefined, factory.createImportClause(
|
|
104160
104412
|
/*isTypeOnly*/ false,
|
|
104161
104413
|
/*name*/ undefined, factory.createNamedImports([
|
|
104162
|
-
factory.createImportSpecifier(factory.createIdentifier("createRequire"), createRequireName)
|
|
104414
|
+
factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName)
|
|
104163
104415
|
])), factory.createStringLiteral("module"));
|
|
104164
104416
|
var requireHelperName = factory.createUniqueName("__require", 16 /* Optimistic */ | 32 /* FileLevel */);
|
|
104165
104417
|
var requireStatement = factory.createVariableStatement(
|
|
@@ -104199,7 +104451,7 @@ var ts;
|
|
|
104199
104451
|
if (ts.hasSyntacticModifier(node, 1 /* Export */)) {
|
|
104200
104452
|
statements = ts.append(statements, factory.createExportDeclaration(
|
|
104201
104453
|
/*decorators*/ undefined,
|
|
104202
|
-
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104454
|
+
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104203
104455
|
}
|
|
104204
104456
|
return statements;
|
|
104205
104457
|
}
|
|
@@ -104227,7 +104479,7 @@ var ts;
|
|
|
104227
104479
|
var exportDecl = ts.isExportNamespaceAsDefaultDeclaration(node) ? factory.createExportDefault(synthName) : factory.createExportDeclaration(
|
|
104228
104480
|
/*decorators*/ undefined,
|
|
104229
104481
|
/*modifiers*/ undefined,
|
|
104230
|
-
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(synthName, oldIdentifier)]));
|
|
104482
|
+
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, synthName, oldIdentifier)]));
|
|
104231
104483
|
ts.setOriginalNode(exportDecl, node);
|
|
104232
104484
|
return [importDecl, exportDecl];
|
|
104233
104485
|
}
|
|
@@ -105794,7 +106046,7 @@ var ts;
|
|
|
105794
106046
|
/*modifiers*/ undefined,
|
|
105795
106047
|
/*isTypeOnly*/ false, factory.createNamedExports(ts.map(exportMappings_1, function (_a) {
|
|
105796
106048
|
var gen = _a[0], exp = _a[1];
|
|
105797
|
-
return factory.createExportSpecifier(gen, exp);
|
|
106049
|
+
return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp);
|
|
105798
106050
|
}))));
|
|
105799
106051
|
}
|
|
105800
106052
|
var namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, factory.createModuleBlock(declarations), 16 /* Namespace */);
|
|
@@ -106168,6 +106420,7 @@ var ts;
|
|
|
106168
106420
|
function getModuleTransformer(moduleKind) {
|
|
106169
106421
|
switch (moduleKind) {
|
|
106170
106422
|
case ts.ModuleKind.ESNext:
|
|
106423
|
+
case ts.ModuleKind.ES2022:
|
|
106171
106424
|
case ts.ModuleKind.ES2020:
|
|
106172
106425
|
case ts.ModuleKind.ES2015:
|
|
106173
106426
|
return ts.transformECMAScriptModule;
|
|
@@ -109733,6 +109986,10 @@ var ts;
|
|
|
109733
109986
|
writePunctuation("}");
|
|
109734
109987
|
}
|
|
109735
109988
|
function emitImportOrExportSpecifier(node) {
|
|
109989
|
+
if (node.isTypeOnly) {
|
|
109990
|
+
writeKeyword("type");
|
|
109991
|
+
writeSpace();
|
|
109992
|
+
}
|
|
109736
109993
|
if (node.propertyName) {
|
|
109737
109994
|
emit(node.propertyName);
|
|
109738
109995
|
writeSpace();
|
|
@@ -118754,7 +119011,7 @@ var ts;
|
|
|
118754
119011
|
var nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);
|
|
118755
119012
|
var packageName = ts.getPackageNameFromTypesPackageName(nodeModulesDirectoryName);
|
|
118756
119013
|
// For classic resolution, only allow importing from node_modules/@types, not other node_modules
|
|
118757
|
-
return ts.getEmitModuleResolutionKind(options)
|
|
119014
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
|
|
118758
119015
|
function tryDirectoryWithPackageJson(packageRootIndex) {
|
|
118759
119016
|
var packageRootPath = path.substring(0, packageRootIndex);
|
|
118760
119017
|
var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
|
|
@@ -123773,6 +124030,10 @@ var ts;
|
|
|
123773
124030
|
return node.kind === 151 /* TypeKeyword */;
|
|
123774
124031
|
}
|
|
123775
124032
|
ts.isTypeKeywordToken = isTypeKeywordToken;
|
|
124033
|
+
function isTypeKeywordTokenOrIdentifier(node) {
|
|
124034
|
+
return isTypeKeywordToken(node) || ts.isIdentifier(node) && node.text === "type";
|
|
124035
|
+
}
|
|
124036
|
+
ts.isTypeKeywordTokenOrIdentifier = isTypeKeywordTokenOrIdentifier;
|
|
123776
124037
|
/** True if the symbol is for an external module, as opposed to a namespace. */
|
|
123777
124038
|
function isExternalModuleSymbol(moduleSymbol) {
|
|
123778
124039
|
return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */;
|
|
@@ -126737,7 +126998,7 @@ var ts;
|
|
|
126737
126998
|
return convertPathCompletions(completion.paths);
|
|
126738
126999
|
case 1 /* Properties */: {
|
|
126739
127000
|
var entries = [];
|
|
126740
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
127001
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
126741
127002
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
126742
127003
|
}
|
|
126743
127004
|
case 2 /* Types */: {
|
|
@@ -127509,6 +127770,7 @@ var ts;
|
|
|
127509
127770
|
KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
|
|
127510
127771
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeAssertionKeywords"] = 6] = "TypeAssertionKeywords";
|
|
127511
127772
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 7] = "TypeKeywords";
|
|
127773
|
+
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeyword"] = 8] = "TypeKeyword";
|
|
127512
127774
|
KeywordCompletionFilters[KeywordCompletionFilters["Last"] = 7] = "Last";
|
|
127513
127775
|
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
|
|
127514
127776
|
var GlobalsSearch;
|
|
@@ -127610,7 +127872,7 @@ var ts;
|
|
|
127610
127872
|
case 3 /* JsDocParameterName */:
|
|
127611
127873
|
return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
|
|
127612
127874
|
case 4 /* Keywords */:
|
|
127613
|
-
return specificKeywordCompletionInfo(completionData.
|
|
127875
|
+
return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
|
|
127614
127876
|
default:
|
|
127615
127877
|
return ts.Debug.assertNever(completionData);
|
|
127616
127878
|
}
|
|
@@ -127661,25 +127923,41 @@ var ts;
|
|
|
127661
127923
|
function jsdocCompletionInfo(entries) {
|
|
127662
127924
|
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: entries };
|
|
127663
127925
|
}
|
|
127664
|
-
function
|
|
127926
|
+
function keywordToCompletionEntry(keyword) {
|
|
127927
|
+
return {
|
|
127928
|
+
name: ts.tokenToString(keyword),
|
|
127929
|
+
kind: "keyword" /* keyword */,
|
|
127930
|
+
kindModifiers: "" /* none */,
|
|
127931
|
+
sortText: SortText.GlobalsOrKeywords,
|
|
127932
|
+
};
|
|
127933
|
+
}
|
|
127934
|
+
function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
|
|
127665
127935
|
return {
|
|
127666
127936
|
isGlobalCompletion: false,
|
|
127667
127937
|
isMemberCompletion: false,
|
|
127668
|
-
isNewIdentifierLocation:
|
|
127669
|
-
entries:
|
|
127670
|
-
name: ts.tokenToString(k),
|
|
127671
|
-
kind: "keyword" /* keyword */,
|
|
127672
|
-
kindModifiers: "" /* none */,
|
|
127673
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
127674
|
-
}); }),
|
|
127938
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
127939
|
+
entries: entries.slice(),
|
|
127675
127940
|
};
|
|
127676
127941
|
}
|
|
127942
|
+
function keywordCompletionData(keywordFilters, filterOutTsOnlyKeywords, isNewIdentifierLocation) {
|
|
127943
|
+
return {
|
|
127944
|
+
kind: 4 /* Keywords */,
|
|
127945
|
+
keywordCompletions: getKeywordCompletions(keywordFilters, filterOutTsOnlyKeywords),
|
|
127946
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
127947
|
+
};
|
|
127948
|
+
}
|
|
127949
|
+
function keywordFiltersFromSyntaxKind(keywordCompletion) {
|
|
127950
|
+
switch (keywordCompletion) {
|
|
127951
|
+
case 151 /* TypeKeyword */: return 8 /* TypeKeyword */;
|
|
127952
|
+
default: ts.Debug.fail("Unknown mapping from SyntaxKind to KeywordCompletionFilters");
|
|
127953
|
+
}
|
|
127954
|
+
}
|
|
127677
127955
|
function getOptionalReplacementSpan(location) {
|
|
127678
127956
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
127679
127957
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
127680
127958
|
}
|
|
127681
127959
|
function completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences) {
|
|
127682
|
-
var symbols = completionData.symbols, 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, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
127960
|
+
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, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
|
|
127683
127961
|
// Verify if the file is JSX language variant
|
|
127684
127962
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
127685
127963
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -127690,7 +127968,7 @@ var ts;
|
|
|
127690
127968
|
var entries = [];
|
|
127691
127969
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
127692
127970
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
127693
|
-
/*
|
|
127971
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
127694
127972
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
127695
127973
|
}
|
|
127696
127974
|
else {
|
|
@@ -127698,7 +127976,7 @@ var ts;
|
|
|
127698
127976
|
return undefined;
|
|
127699
127977
|
}
|
|
127700
127978
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
127701
|
-
/*
|
|
127979
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
127702
127980
|
}
|
|
127703
127981
|
if (keywordFilters !== 0 /* None */) {
|
|
127704
127982
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -127804,10 +128082,10 @@ var ts;
|
|
|
127804
128082
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
127805
128083
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
127806
128084
|
}
|
|
127807
|
-
function createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128085
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences) {
|
|
127808
128086
|
var _a;
|
|
127809
128087
|
var insertText;
|
|
127810
|
-
var replacementSpan = ts.getReplacementSpanForContextToken(
|
|
128088
|
+
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
127811
128089
|
var data;
|
|
127812
128090
|
var isSnippet;
|
|
127813
128091
|
var sourceDisplay;
|
|
@@ -127858,7 +128136,7 @@ var ts;
|
|
|
127858
128136
|
if (originIsResolvedExport(origin)) {
|
|
127859
128137
|
sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
|
|
127860
128138
|
if (importCompletionNode) {
|
|
127861
|
-
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128139
|
+
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
|
|
127862
128140
|
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
|
|
127863
128141
|
}
|
|
127864
128142
|
}
|
|
@@ -127931,22 +128209,26 @@ var ts;
|
|
|
127931
128209
|
moduleSpecifier: originIsResolvedExport(origin) ? origin.moduleSpecifier : undefined,
|
|
127932
128210
|
};
|
|
127933
128211
|
}
|
|
127934
|
-
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128212
|
+
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences) {
|
|
128213
|
+
var _a, _b, _c;
|
|
127935
128214
|
var sourceFile = importCompletionNode.getSourceFile();
|
|
127936
|
-
var replacementSpan = ts.createTextSpanFromNode(importCompletionNode, sourceFile);
|
|
128215
|
+
var replacementSpan = ts.createTextSpanFromNode(ts.findAncestor(importCompletionNode, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration)) || importCompletionNode, sourceFile);
|
|
127937
128216
|
var quotedModuleSpecifier = ts.quote(sourceFile, preferences, origin.moduleSpecifier);
|
|
127938
128217
|
var exportKind = origin.isDefaultExport ? 1 /* Default */ :
|
|
127939
128218
|
origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ :
|
|
127940
128219
|
0 /* Named */;
|
|
127941
128220
|
var tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
|
|
127942
128221
|
var importKind = ts.codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
|
|
127943
|
-
var
|
|
128222
|
+
var isTopLevelTypeOnly = ((_b = (_a = ts.tryCast(importCompletionNode, ts.isImportDeclaration)) === null || _a === void 0 ? void 0 : _a.importClause) === null || _b === void 0 ? void 0 : _b.isTypeOnly) || ((_c = ts.tryCast(importCompletionNode, ts.isImportEqualsDeclaration)) === null || _c === void 0 ? void 0 : _c.isTypeOnly);
|
|
128223
|
+
var isImportSpecifierTypeOnly = couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
128224
|
+
var topLevelTypeOnlyText = isTopLevelTypeOnly ? " " + ts.tokenToString(151 /* TypeKeyword */) + " " : " ";
|
|
128225
|
+
var importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? ts.tokenToString(151 /* TypeKeyword */) + " " : "";
|
|
127944
128226
|
var suffix = useSemicolons ? ";" : "";
|
|
127945
128227
|
switch (importKind) {
|
|
127946
|
-
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127947
|
-
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127948
|
-
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
127949
|
-
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128228
|
+
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
|
|
128229
|
+
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " from " + quotedModuleSpecifier + suffix };
|
|
128230
|
+
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "* as " + escapeSnippetText(name) + " from " + quotedModuleSpecifier + suffix };
|
|
128231
|
+
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "{ " + importSpecifierTypeOnlyText + escapeSnippetText(name) + tabStop + " } from " + quotedModuleSpecifier + suffix };
|
|
127950
128232
|
}
|
|
127951
128233
|
}
|
|
127952
128234
|
function quotePropertyName(sourceFile, preferences, name) {
|
|
@@ -127970,12 +128252,11 @@ var ts;
|
|
|
127970
128252
|
return CompletionSource.ThisProperty;
|
|
127971
128253
|
}
|
|
127972
128254
|
}
|
|
127973
|
-
function getCompletionEntriesFromSymbols(symbols, entries, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128255
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
127974
128256
|
var _a;
|
|
127975
128257
|
var start = ts.timestamp();
|
|
127976
128258
|
var variableDeclaration = getVariableDeclaration(location);
|
|
127977
128259
|
var useSemicolons = ts.probablyUsesSemicolons(sourceFile);
|
|
127978
|
-
var isTypeOnlyImport = !!importCompletionNode && ts.isTypeOnlyImportOrExportDeclaration(location.parent);
|
|
127979
128260
|
// Tracks unique names.
|
|
127980
128261
|
// Value is set to false for global variables or completions from external module exports, because we can have multiple of those;
|
|
127981
128262
|
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
|
|
@@ -127991,7 +128272,7 @@ var ts;
|
|
|
127991
128272
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
127992
128273
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
127993
128274
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
127994
|
-
var entry = createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128275
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences);
|
|
127995
128276
|
if (!entry) {
|
|
127996
128277
|
continue;
|
|
127997
128278
|
}
|
|
@@ -128140,7 +128421,7 @@ var ts;
|
|
|
128140
128421
|
case 3 /* JsDocParameterName */:
|
|
128141
128422
|
return ts.JsDoc.getJSDocParameterNameCompletionDetails(name);
|
|
128142
128423
|
case 4 /* Keywords */:
|
|
128143
|
-
return
|
|
128424
|
+
return ts.some(request.keywordCompletions, function (c) { return c.name === name; }) ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
|
|
128144
128425
|
default:
|
|
128145
128426
|
return ts.Debug.assertNever(request);
|
|
128146
128427
|
}
|
|
@@ -128179,7 +128460,7 @@ var ts;
|
|
|
128179
128460
|
function getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data) {
|
|
128180
128461
|
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
|
|
128181
128462
|
var _a = getRelevantTokens(position, sourceFile), contextToken = _a.contextToken, previousToken_1 = _a.previousToken;
|
|
128182
|
-
if (previousToken_1 &&
|
|
128463
|
+
if (previousToken_1 && getImportStatementCompletionInfo(contextToken || previousToken_1).replacementNode) {
|
|
128183
128464
|
// Import statement completion: 'import c|'
|
|
128184
128465
|
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
|
|
128185
128466
|
}
|
|
@@ -128342,6 +128623,7 @@ var ts;
|
|
|
128342
128623
|
start = ts.timestamp();
|
|
128343
128624
|
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
|
|
128344
128625
|
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
|
|
128626
|
+
var isJsOnlyLocation = !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile);
|
|
128345
128627
|
var tokens = getRelevantTokens(position, sourceFile);
|
|
128346
128628
|
var previousToken = tokens.previousToken;
|
|
128347
128629
|
var contextToken = tokens.contextToken;
|
|
@@ -128359,22 +128641,34 @@ var ts;
|
|
|
128359
128641
|
var isJsxIdentifierExpected = false;
|
|
128360
128642
|
var importCompletionNode;
|
|
128361
128643
|
var location = ts.getTouchingPropertyName(sourceFile, position);
|
|
128644
|
+
var keywordFilters = 0 /* None */;
|
|
128645
|
+
var isNewIdentifierLocation = false;
|
|
128362
128646
|
if (contextToken) {
|
|
128363
|
-
var
|
|
128364
|
-
|
|
128365
|
-
|
|
128647
|
+
var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
|
|
128648
|
+
isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
|
|
128649
|
+
if (importStatementCompletion.keywordCompletion) {
|
|
128650
|
+
if (importStatementCompletion.isKeywordOnlyCompletion) {
|
|
128651
|
+
return {
|
|
128652
|
+
kind: 4 /* Keywords */,
|
|
128653
|
+
keywordCompletions: [keywordToCompletionEntry(importStatementCompletion.keywordCompletion)],
|
|
128654
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128655
|
+
};
|
|
128656
|
+
}
|
|
128657
|
+
keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletion.keywordCompletion);
|
|
128366
128658
|
}
|
|
128367
|
-
|
|
128368
|
-
|
|
128369
|
-
|
|
128370
|
-
|
|
128371
|
-
|
|
128372
|
-
importCompletionNode =
|
|
128659
|
+
if (importStatementCompletion.replacementNode && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
|
|
128660
|
+
// Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
|
|
128661
|
+
// added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
|
|
128662
|
+
// is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
|
|
128663
|
+
// to opt in with the `includeCompletionsForImportStatements` user preference.
|
|
128664
|
+
importCompletionNode = importStatementCompletion.replacementNode;
|
|
128373
128665
|
}
|
|
128374
128666
|
// Bail out if this is a known invalid completion location
|
|
128375
128667
|
if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
|
|
128376
128668
|
log("Returning an empty list because completion was requested in an invalid position.");
|
|
128377
|
-
return
|
|
128669
|
+
return keywordFilters
|
|
128670
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierDefinitionLocation())
|
|
128671
|
+
: undefined;
|
|
128378
128672
|
}
|
|
128379
128673
|
var parent = contextToken.parent;
|
|
128380
128674
|
if (contextToken.kind === 24 /* DotToken */ || contextToken.kind === 28 /* QuestionDotToken */) {
|
|
@@ -128494,10 +128788,8 @@ var ts;
|
|
|
128494
128788
|
}
|
|
128495
128789
|
var semanticStart = ts.timestamp();
|
|
128496
128790
|
var completionKind = 5 /* None */;
|
|
128497
|
-
var isNewIdentifierLocation = false;
|
|
128498
128791
|
var isNonContextualObjectLiteral = false;
|
|
128499
128792
|
var hasUnresolvedAutoImports = false;
|
|
128500
|
-
var keywordFilters = 0 /* None */;
|
|
128501
128793
|
// This also gets mutated in nested-functions after the return
|
|
128502
128794
|
var symbols = [];
|
|
128503
128795
|
var symbolToOriginInfoMap = [];
|
|
@@ -128531,7 +128823,9 @@ var ts;
|
|
|
128531
128823
|
// global symbols in scope. These results should be valid for either language as
|
|
128532
128824
|
// the set of symbols that can be referenced from this location.
|
|
128533
128825
|
if (!tryGetGlobalSymbols()) {
|
|
128534
|
-
return
|
|
128826
|
+
return keywordFilters
|
|
128827
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierLocation)
|
|
128828
|
+
: undefined;
|
|
128535
128829
|
}
|
|
128536
128830
|
}
|
|
128537
128831
|
log("getCompletionData: Semantic work: " + (ts.timestamp() - semanticStart));
|
|
@@ -128551,6 +128845,7 @@ var ts;
|
|
|
128551
128845
|
symbolToOriginInfoMap: symbolToOriginInfoMap,
|
|
128552
128846
|
recommendedCompletion: recommendedCompletion,
|
|
128553
128847
|
previousToken: previousToken,
|
|
128848
|
+
contextToken: contextToken,
|
|
128554
128849
|
isJsxInitializer: isJsxInitializer,
|
|
128555
128850
|
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
|
|
128556
128851
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
@@ -128937,8 +129232,14 @@ var ts;
|
|
|
128937
129232
|
// Asking for completion details for an item that is not an auto-import
|
|
128938
129233
|
return;
|
|
128939
129234
|
}
|
|
129235
|
+
// import { type | -> token text should be blank
|
|
129236
|
+
var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
|
|
129237
|
+
&& importCompletionNode
|
|
129238
|
+
&& couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
129239
|
+
var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
|
|
129240
|
+
previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
|
|
129241
|
+
"";
|
|
128940
129242
|
var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
128941
|
-
var lowerCaseTokenText = previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() : "";
|
|
128942
129243
|
var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
|
|
128943
129244
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
128944
129245
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
@@ -129071,6 +129372,7 @@ var ts;
|
|
|
129071
129372
|
|| containingNodeKind === 161 /* ComputedPropertyName */; // [ | /* this can become an index signature */
|
|
129072
129373
|
case 141 /* ModuleKeyword */: // module |
|
|
129073
129374
|
case 142 /* NamespaceKeyword */: // namespace |
|
|
129375
|
+
case 100 /* ImportKeyword */: // import |
|
|
129074
129376
|
return true;
|
|
129075
129377
|
case 24 /* DotToken */:
|
|
129076
129378
|
return containingNodeKind === 260 /* ModuleDeclaration */; // module A.|
|
|
@@ -129209,23 +129511,38 @@ var ts;
|
|
|
129209
129511
|
* Relevant symbols are stored in the captured 'symbols' variable.
|
|
129210
129512
|
*/
|
|
129211
129513
|
function tryGetImportOrExportClauseCompletionSymbols() {
|
|
129212
|
-
|
|
129213
|
-
|
|
129214
|
-
|
|
129514
|
+
if (!contextToken)
|
|
129515
|
+
return 0 /* Continue */;
|
|
129516
|
+
// `import { |` or `import { a as 0, | }` or `import { type | }`
|
|
129517
|
+
var namedImportsOrExports = contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */ ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) :
|
|
129518
|
+
ts.isTypeKeywordTokenOrIdentifier(contextToken) ? ts.tryCast(contextToken.parent.parent, ts.isNamedImportsOrExports) : undefined;
|
|
129215
129519
|
if (!namedImportsOrExports)
|
|
129216
129520
|
return 0 /* Continue */;
|
|
129521
|
+
// We can at least offer `type` at `import { |`
|
|
129522
|
+
if (!ts.isTypeKeywordTokenOrIdentifier(contextToken)) {
|
|
129523
|
+
keywordFilters = 8 /* TypeKeyword */;
|
|
129524
|
+
}
|
|
129217
129525
|
// try to show exported member for imported/re-exported module
|
|
129218
129526
|
var moduleSpecifier = (namedImportsOrExports.kind === 268 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
|
|
129219
|
-
if (!moduleSpecifier)
|
|
129527
|
+
if (!moduleSpecifier) {
|
|
129528
|
+
isNewIdentifierLocation = true;
|
|
129220
129529
|
return namedImportsOrExports.kind === 268 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
|
|
129530
|
+
}
|
|
129221
129531
|
var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217
|
|
129222
|
-
if (!moduleSpecifierSymbol)
|
|
129532
|
+
if (!moduleSpecifierSymbol) {
|
|
129533
|
+
isNewIdentifierLocation = true;
|
|
129223
129534
|
return 2 /* Fail */;
|
|
129535
|
+
}
|
|
129224
129536
|
completionKind = 3 /* MemberLike */;
|
|
129225
129537
|
isNewIdentifierLocation = false;
|
|
129226
129538
|
var exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
|
|
129227
129539
|
var existing = new ts.Set(namedImportsOrExports.elements.filter(function (n) { return !isCurrentlyEditingNode(n); }).map(function (n) { return (n.propertyName || n.name).escapedText; }));
|
|
129228
|
-
|
|
129540
|
+
var uniques = exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); });
|
|
129541
|
+
symbols = ts.concatenate(symbols, uniques);
|
|
129542
|
+
if (!uniques.length) {
|
|
129543
|
+
// If there's nothing else to import, don't offer `type` either
|
|
129544
|
+
keywordFilters = 0 /* None */;
|
|
129545
|
+
}
|
|
129229
129546
|
return 1 /* Success */;
|
|
129230
129547
|
}
|
|
129231
129548
|
/**
|
|
@@ -129486,6 +129803,14 @@ var ts;
|
|
|
129486
129803
|
case 136 /* GetKeyword */:
|
|
129487
129804
|
case 148 /* SetKeyword */:
|
|
129488
129805
|
return !isFromObjectTypeDeclaration(contextToken);
|
|
129806
|
+
case 79 /* Identifier */:
|
|
129807
|
+
if (containingNodeKind === 269 /* ImportSpecifier */ &&
|
|
129808
|
+
contextToken === parent.name &&
|
|
129809
|
+
contextToken.text === "type") {
|
|
129810
|
+
// import { type | }
|
|
129811
|
+
return false;
|
|
129812
|
+
}
|
|
129813
|
+
break;
|
|
129489
129814
|
case 84 /* ClassKeyword */:
|
|
129490
129815
|
case 92 /* EnumKeyword */:
|
|
129491
129816
|
case 118 /* InterfaceKeyword */:
|
|
@@ -129495,8 +129820,10 @@ var ts;
|
|
|
129495
129820
|
case 119 /* LetKeyword */:
|
|
129496
129821
|
case 85 /* ConstKeyword */:
|
|
129497
129822
|
case 137 /* InferKeyword */:
|
|
129498
|
-
case 151 /* TypeKeyword */: // type htm|
|
|
129499
129823
|
return true;
|
|
129824
|
+
case 151 /* TypeKeyword */:
|
|
129825
|
+
// import { type foo| }
|
|
129826
|
+
return containingNodeKind !== 269 /* ImportSpecifier */;
|
|
129500
129827
|
case 41 /* AsteriskToken */:
|
|
129501
129828
|
return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
|
|
129502
129829
|
}
|
|
@@ -129857,6 +130184,8 @@ var ts;
|
|
|
129857
130184
|
return ts.isTypeKeyword(kind) || kind === 85 /* ConstKeyword */;
|
|
129858
130185
|
case 7 /* TypeKeywords */:
|
|
129859
130186
|
return ts.isTypeKeyword(kind);
|
|
130187
|
+
case 8 /* TypeKeyword */:
|
|
130188
|
+
return kind === 151 /* TypeKeyword */;
|
|
129860
130189
|
default:
|
|
129861
130190
|
return ts.Debug.assertNever(keywordFilter);
|
|
129862
130191
|
}
|
|
@@ -130130,34 +130459,67 @@ var ts;
|
|
|
130130
130459
|
}
|
|
130131
130460
|
return undefined;
|
|
130132
130461
|
}
|
|
130133
|
-
function
|
|
130462
|
+
function getImportStatementCompletionInfo(contextToken) {
|
|
130463
|
+
var keywordCompletion;
|
|
130464
|
+
var isKeywordOnlyCompletion = false;
|
|
130134
130465
|
var candidate = getCandidate();
|
|
130135
|
-
return
|
|
130466
|
+
return {
|
|
130467
|
+
isKeywordOnlyCompletion: isKeywordOnlyCompletion,
|
|
130468
|
+
keywordCompletion: keywordCompletion,
|
|
130469
|
+
isNewIdentifierLocation: !!(candidate || keywordCompletion === 151 /* TypeKeyword */),
|
|
130470
|
+
replacementNode: candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile())
|
|
130471
|
+
? candidate
|
|
130472
|
+
: undefined
|
|
130473
|
+
};
|
|
130136
130474
|
function getCandidate() {
|
|
130137
130475
|
var parent = contextToken.parent;
|
|
130138
130476
|
if (ts.isImportEqualsDeclaration(parent)) {
|
|
130477
|
+
keywordCompletion = contextToken.kind === 151 /* TypeKeyword */ ? undefined : 151 /* TypeKeyword */;
|
|
130139
130478
|
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
|
|
130140
130479
|
}
|
|
130480
|
+
if (couldBeTypeOnlyImportSpecifier(parent, contextToken) && canCompleteFromNamedBindings(parent.parent)) {
|
|
130481
|
+
return parent;
|
|
130482
|
+
}
|
|
130141
130483
|
if (ts.isNamedImports(parent) || ts.isNamespaceImport(parent)) {
|
|
130142
|
-
if (
|
|
130484
|
+
if (!parent.parent.isTypeOnly && (contextToken.kind === 18 /* OpenBraceToken */ ||
|
|
130485
|
+
contextToken.kind === 100 /* ImportKeyword */ ||
|
|
130486
|
+
contextToken.kind === 27 /* CommaToken */)) {
|
|
130487
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130488
|
+
}
|
|
130489
|
+
if (canCompleteFromNamedBindings(parent)) {
|
|
130143
130490
|
// At `import { ... } |` or `import * as Foo |`, the only possible completion is `from`
|
|
130144
|
-
|
|
130145
|
-
|
|
130146
|
-
|
|
130491
|
+
if (contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */) {
|
|
130492
|
+
isKeywordOnlyCompletion = true;
|
|
130493
|
+
keywordCompletion = 155 /* FromKeyword */;
|
|
130494
|
+
}
|
|
130495
|
+
else {
|
|
130496
|
+
return parent.parent.parent;
|
|
130497
|
+
}
|
|
130147
130498
|
}
|
|
130148
130499
|
return undefined;
|
|
130149
130500
|
}
|
|
130150
130501
|
if (ts.isImportKeyword(contextToken) && ts.isSourceFile(parent)) {
|
|
130151
130502
|
// A lone import keyword with nothing following it does not parse as a statement at all
|
|
130503
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130152
130504
|
return contextToken;
|
|
130153
130505
|
}
|
|
130154
130506
|
if (ts.isImportKeyword(contextToken) && ts.isImportDeclaration(parent)) {
|
|
130155
130507
|
// `import s| from`
|
|
130508
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130156
130509
|
return isModuleSpecifierMissingOrEmpty(parent.moduleSpecifier) ? parent : undefined;
|
|
130157
130510
|
}
|
|
130158
130511
|
return undefined;
|
|
130159
130512
|
}
|
|
130160
130513
|
}
|
|
130514
|
+
function couldBeTypeOnlyImportSpecifier(importSpecifier, contextToken) {
|
|
130515
|
+
return ts.isImportSpecifier(importSpecifier)
|
|
130516
|
+
&& (importSpecifier.isTypeOnly || contextToken === importSpecifier.name && ts.isTypeKeywordTokenOrIdentifier(contextToken));
|
|
130517
|
+
}
|
|
130518
|
+
function canCompleteFromNamedBindings(namedBindings) {
|
|
130519
|
+
return isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier)
|
|
130520
|
+
&& (ts.isNamespaceImport(namedBindings) || namedBindings.elements.length < 2)
|
|
130521
|
+
&& !namedBindings.parent.name;
|
|
130522
|
+
}
|
|
130161
130523
|
function isModuleSpecifierMissingOrEmpty(specifier) {
|
|
130162
130524
|
var _a;
|
|
130163
130525
|
if (ts.nodeIsMissing(specifier))
|
|
@@ -136297,7 +136659,7 @@ var ts;
|
|
|
136297
136659
|
else {
|
|
136298
136660
|
for (var _e = 0, defaultImports_1 = defaultImports; _e < defaultImports_1.length; _e++) {
|
|
136299
136661
|
var defaultImport = defaultImports_1[_e];
|
|
136300
|
-
newImportSpecifiers.push(ts.factory.createImportSpecifier(ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136662
|
+
newImportSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136301
136663
|
}
|
|
136302
136664
|
}
|
|
136303
136665
|
newImportSpecifiers.push.apply(newImportSpecifiers, ts.flatMap(namedImports, function (i) { return i.importClause.namedBindings.elements; })); // TODO: GH#18217
|
|
@@ -136431,7 +136793,8 @@ var ts;
|
|
|
136431
136793
|
return ts.stableSort(specifiers, compareImportOrExportSpecifiers);
|
|
136432
136794
|
}
|
|
136433
136795
|
function compareImportOrExportSpecifiers(s1, s2) {
|
|
136434
|
-
return
|
|
136796
|
+
return ts.compareBooleans(s1.isTypeOnly, s2.isTypeOnly)
|
|
136797
|
+
|| compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
|
|
136435
136798
|
|| compareIdentifiers(s1.name, s2.name);
|
|
136436
136799
|
}
|
|
136437
136800
|
OrganizeImports.compareImportOrExportSpecifiers = compareImportOrExportSpecifiers;
|
|
@@ -138908,7 +139271,7 @@ var ts;
|
|
|
138908
139271
|
if (!typeDisplayString) {
|
|
138909
139272
|
continue;
|
|
138910
139273
|
}
|
|
138911
|
-
addTypeHints(typeDisplayString, param.end);
|
|
139274
|
+
addTypeHints(typeDisplayString, param.name.end);
|
|
138912
139275
|
}
|
|
138913
139276
|
}
|
|
138914
139277
|
function getParameterDeclarationTypeDisplayString(symbol) {
|
|
@@ -146589,7 +146952,7 @@ var ts;
|
|
|
146589
146952
|
*/
|
|
146590
146953
|
var newNodes = [
|
|
146591
146954
|
makeConst(/*modifiers*/ undefined, rename, assignment.right),
|
|
146592
|
-
makeExportDeclaration([ts.factory.createExportSpecifier(rename, text)]),
|
|
146955
|
+
makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, rename, text)]),
|
|
146593
146956
|
];
|
|
146594
146957
|
changes.replaceNodeWithNodes(sourceFile, assignment.parent, newNodes);
|
|
146595
146958
|
}
|
|
@@ -146611,7 +146974,7 @@ var ts;
|
|
|
146611
146974
|
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
|
|
146612
146975
|
}
|
|
146613
146976
|
function reExportDefault(moduleSpecifier) {
|
|
146614
|
-
return makeExportDeclaration([ts.factory.createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
146977
|
+
return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
146615
146978
|
}
|
|
146616
146979
|
function convertExportsPropertyAssignment(_a, sourceFile, changes) {
|
|
146617
146980
|
var left = _a.left, right = _a.right, parent = _a.parent;
|
|
@@ -146753,7 +147116,7 @@ var ts;
|
|
|
146753
147116
|
}
|
|
146754
147117
|
var namedBindings = namedBindingsNames.size === 0 ? undefined : ts.arrayFrom(ts.mapIterator(namedBindingsNames.entries(), function (_a) {
|
|
146755
147118
|
var propertyName = _a[0], idName = _a[1];
|
|
146756
|
-
return ts.factory.createImportSpecifier(propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
147119
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
146757
147120
|
}));
|
|
146758
147121
|
if (!namedBindings) {
|
|
146759
147122
|
// If it was unused, ensure that we at least import *something*.
|
|
@@ -146811,7 +147174,7 @@ var ts;
|
|
|
146811
147174
|
: ts.makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier, quotePreference);
|
|
146812
147175
|
}
|
|
146813
147176
|
function makeImportSpecifier(propertyName, name) {
|
|
146814
|
-
return ts.factory.createImportSpecifier(propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147177
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
146815
147178
|
}
|
|
146816
147179
|
function makeConst(modifiers, name, init) {
|
|
146817
147180
|
return ts.factory.createVariableStatement(modifiers, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, /*type*/ undefined, init)], 2 /* Const */));
|
|
@@ -147136,13 +147499,13 @@ var ts;
|
|
|
147136
147499
|
codefix.registerCodeFix({
|
|
147137
147500
|
errorCodes: errorCodes,
|
|
147138
147501
|
getCodeActions: function (context) {
|
|
147139
|
-
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span;
|
|
147502
|
+
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span, program = context.program;
|
|
147140
147503
|
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
|
147141
147504
|
if (!info)
|
|
147142
147505
|
return undefined;
|
|
147143
147506
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147144
147507
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
147145
|
-
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference); });
|
|
147508
|
+
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
|
|
147146
147509
|
},
|
|
147147
147510
|
fixIds: [importFixId],
|
|
147148
147511
|
getAllCodeActions: function (context) {
|
|
@@ -147161,8 +147524,9 @@ var ts;
|
|
|
147161
147524
|
// Namespace fixes don't conflict, so just build a list.
|
|
147162
147525
|
var addToNamespace = [];
|
|
147163
147526
|
var importType = [];
|
|
147164
|
-
|
|
147527
|
+
/** Keys are import clause node IDs. */
|
|
147165
147528
|
var addToExisting = new ts.Map();
|
|
147529
|
+
/** Use `getNewImportEntry` for access */
|
|
147166
147530
|
var newImports = new ts.Map();
|
|
147167
147531
|
return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes };
|
|
147168
147532
|
function addImportFromDiagnostic(diagnostic, context) {
|
|
@@ -147171,67 +147535,66 @@ var ts;
|
|
|
147171
147535
|
return;
|
|
147172
147536
|
addImport(info);
|
|
147173
147537
|
}
|
|
147174
|
-
function addImportFromExportedSymbol(exportedSymbol,
|
|
147538
|
+
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
|
|
147175
147539
|
var moduleSymbol = ts.Debug.checkDefined(exportedSymbol.parent);
|
|
147176
147540
|
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
|
|
147177
147541
|
var checker = program.getTypeChecker();
|
|
147178
147542
|
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
|
|
147179
147543
|
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
|
|
147180
|
-
var preferTypeOnlyImport = !!usageIsTypeOnly && compilerOptions.importsNotUsedAsValues === 2 /* Error */;
|
|
147181
147544
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147182
|
-
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined,
|
|
147545
|
+
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147183
147546
|
if (fix) {
|
|
147184
147547
|
addImport({ fixes: [fix], symbolName: symbolName });
|
|
147185
147548
|
}
|
|
147186
147549
|
}
|
|
147187
147550
|
function addImport(info) {
|
|
147551
|
+
var _a, _b;
|
|
147188
147552
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147189
147553
|
var fix = ts.first(fixes);
|
|
147190
147554
|
switch (fix.kind) {
|
|
147191
147555
|
case 0 /* UseNamespace */:
|
|
147192
147556
|
addToNamespace.push(fix);
|
|
147193
147557
|
break;
|
|
147194
|
-
case 1 /*
|
|
147558
|
+
case 1 /* JsdocTypeImport */:
|
|
147195
147559
|
importType.push(fix);
|
|
147196
147560
|
break;
|
|
147197
147561
|
case 2 /* AddToExisting */: {
|
|
147198
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
147562
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147199
147563
|
var key = String(ts.getNodeId(importClauseOrBindingPattern));
|
|
147200
147564
|
var entry = addToExisting.get(key);
|
|
147201
147565
|
if (!entry) {
|
|
147202
|
-
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports:
|
|
147566
|
+
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: new ts.Map() });
|
|
147203
147567
|
}
|
|
147204
147568
|
if (importKind === 0 /* Named */) {
|
|
147205
|
-
|
|
147569
|
+
var prevValue = entry === null || entry === void 0 ? void 0 : entry.namedImports.get(symbolName);
|
|
147570
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147206
147571
|
}
|
|
147207
147572
|
else {
|
|
147208
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147209
|
-
entry.defaultImport =
|
|
147573
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147574
|
+
entry.defaultImport = {
|
|
147575
|
+
name: symbolName,
|
|
147576
|
+
addAsTypeOnly: reduceAddAsTypeOnlyValues((_a = entry.defaultImport) === null || _a === void 0 ? void 0 : _a.addAsTypeOnly, addAsTypeOnly),
|
|
147577
|
+
};
|
|
147210
147578
|
}
|
|
147211
147579
|
break;
|
|
147212
147580
|
}
|
|
147213
147581
|
case 3 /* AddNew */: {
|
|
147214
|
-
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire,
|
|
147215
|
-
var entry =
|
|
147216
|
-
|
|
147217
|
-
newImports.set(moduleSpecifier, entry = { namedImports: [], namespaceLikeImport: undefined, typeOnly: typeOnly, useRequire: useRequire });
|
|
147218
|
-
}
|
|
147219
|
-
else {
|
|
147220
|
-
// An import clause can only be type-only if every import fix contributing to it can be type-only.
|
|
147221
|
-
entry.typeOnly = entry.typeOnly && typeOnly;
|
|
147222
|
-
}
|
|
147582
|
+
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147583
|
+
var entry = getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly);
|
|
147584
|
+
ts.Debug.assert(entry.useRequire === useRequire, "(Add new) Tried to add an `import` and a `require` for the same module");
|
|
147223
147585
|
switch (importKind) {
|
|
147224
147586
|
case 1 /* Default */:
|
|
147225
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147226
|
-
entry.defaultImport = symbolName;
|
|
147587
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147588
|
+
entry.defaultImport = { name: symbolName, addAsTypeOnly: reduceAddAsTypeOnlyValues((_b = entry.defaultImport) === null || _b === void 0 ? void 0 : _b.addAsTypeOnly, addAsTypeOnly) };
|
|
147227
147589
|
break;
|
|
147228
147590
|
case 0 /* Named */:
|
|
147229
|
-
|
|
147591
|
+
var prevValue = (entry.namedImports || (entry.namedImports = new ts.Map())).get(symbolName);
|
|
147592
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147230
147593
|
break;
|
|
147231
147594
|
case 3 /* CommonJS */:
|
|
147232
147595
|
case 2 /* Namespace */:
|
|
147233
147596
|
ts.Debug.assert(entry.namespaceLikeImport === undefined || entry.namespaceLikeImport.name === symbolName, "Namespacelike import shoudl be missing or match symbolName");
|
|
147234
|
-
entry.namespaceLikeImport = { importKind: importKind, name: symbolName };
|
|
147597
|
+
entry.namespaceLikeImport = { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly };
|
|
147235
147598
|
break;
|
|
147236
147599
|
}
|
|
147237
147600
|
break;
|
|
@@ -147239,6 +147602,50 @@ var ts;
|
|
|
147239
147602
|
default:
|
|
147240
147603
|
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
|
|
147241
147604
|
}
|
|
147605
|
+
function reduceAddAsTypeOnlyValues(prevValue, newValue) {
|
|
147606
|
+
// `NotAllowed` overrides `Required` because one addition of a new import might be required to be type-only
|
|
147607
|
+
// because of `--importsNotUsedAsValues=error`, but if a second addition of the same import is `NotAllowed`
|
|
147608
|
+
// to be type-only, the reason the first one was `Required` - the unused runtime dependency - is now moot.
|
|
147609
|
+
// Alternatively, if one addition is `Required` because it has no value meaning under `--preserveValueImports`
|
|
147610
|
+
// and `--isolatedModules`, it should be impossible for another addition to be `NotAllowed` since that would
|
|
147611
|
+
// mean a type is being referenced in a value location.
|
|
147612
|
+
return Math.max(prevValue !== null && prevValue !== void 0 ? prevValue : 0, newValue);
|
|
147613
|
+
}
|
|
147614
|
+
function getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly) {
|
|
147615
|
+
// A default import that requires type-only makes the whole import type-only.
|
|
147616
|
+
// (We could add `default` as a named import, but that style seems undesirable.)
|
|
147617
|
+
// Under `--preserveValueImports` and `--importsNotUsedAsValues=error`, if a
|
|
147618
|
+
// module default-exports a type but named-exports some values (weird), you would
|
|
147619
|
+
// have to use a type-only default import and non-type-only named imports. These
|
|
147620
|
+
// require two separate import declarations, so we build this into the map key.
|
|
147621
|
+
var typeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ true);
|
|
147622
|
+
var nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
|
|
147623
|
+
var typeOnlyEntry = newImports.get(typeOnlyKey);
|
|
147624
|
+
var nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
|
|
147625
|
+
var newEntry = {
|
|
147626
|
+
defaultImport: undefined,
|
|
147627
|
+
namedImports: undefined,
|
|
147628
|
+
namespaceLikeImport: undefined,
|
|
147629
|
+
useRequire: useRequire
|
|
147630
|
+
};
|
|
147631
|
+
if (importKind === 1 /* Default */ && addAsTypeOnly === 2 /* Required */) {
|
|
147632
|
+
if (typeOnlyEntry)
|
|
147633
|
+
return typeOnlyEntry;
|
|
147634
|
+
newImports.set(typeOnlyKey, newEntry);
|
|
147635
|
+
return newEntry;
|
|
147636
|
+
}
|
|
147637
|
+
if (addAsTypeOnly === 1 /* Allowed */ && (typeOnlyEntry || nonTypeOnlyEntry)) {
|
|
147638
|
+
return (typeOnlyEntry || nonTypeOnlyEntry);
|
|
147639
|
+
}
|
|
147640
|
+
if (nonTypeOnlyEntry) {
|
|
147641
|
+
return nonTypeOnlyEntry;
|
|
147642
|
+
}
|
|
147643
|
+
newImports.set(nonTypeOnlyKey, newEntry);
|
|
147644
|
+
return newEntry;
|
|
147645
|
+
}
|
|
147646
|
+
function newImportsKey(moduleSpecifier, topLevelTypeOnly) {
|
|
147647
|
+
return (topLevelTypeOnly ? 1 : 0) + "|" + moduleSpecifier;
|
|
147648
|
+
}
|
|
147242
147649
|
}
|
|
147243
147650
|
function writeFixes(changeTracker) {
|
|
147244
147651
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
@@ -147251,14 +147658,22 @@ var ts;
|
|
|
147251
147658
|
addImportType(changeTracker, sourceFile, fix, quotePreference);
|
|
147252
147659
|
}
|
|
147253
147660
|
addToExisting.forEach(function (_a) {
|
|
147254
|
-
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports
|
|
147255
|
-
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports,
|
|
147661
|
+
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports;
|
|
147662
|
+
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
147663
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
147664
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
147665
|
+
}), compilerOptions);
|
|
147256
147666
|
});
|
|
147257
147667
|
var newDeclarations;
|
|
147258
|
-
newImports.forEach(function (_a,
|
|
147259
|
-
var useRequire = _a.useRequire,
|
|
147668
|
+
newImports.forEach(function (_a, key) {
|
|
147669
|
+
var useRequire = _a.useRequire, defaultImport = _a.defaultImport, namedImports = _a.namedImports, namespaceLikeImport = _a.namespaceLikeImport;
|
|
147670
|
+
var moduleSpecifier = key.slice(2); // From `${0 | 1}|${moduleSpecifier}` format
|
|
147260
147671
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147261
|
-
|
|
147672
|
+
var declarations = getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports && ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
147673
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
147674
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
147675
|
+
}), namespaceLikeImport);
|
|
147676
|
+
newDeclarations = ts.combine(newDeclarations, declarations);
|
|
147262
147677
|
});
|
|
147263
147678
|
if (newDeclarations) {
|
|
147264
147679
|
ts.insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
|
|
@@ -147269,24 +147684,37 @@ var ts;
|
|
|
147269
147684
|
var ImportFixKind;
|
|
147270
147685
|
(function (ImportFixKind) {
|
|
147271
147686
|
ImportFixKind[ImportFixKind["UseNamespace"] = 0] = "UseNamespace";
|
|
147272
|
-
ImportFixKind[ImportFixKind["
|
|
147687
|
+
ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
|
|
147273
147688
|
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
|
|
147274
147689
|
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
|
|
147275
147690
|
})(ImportFixKind || (ImportFixKind = {}));
|
|
147691
|
+
// These should not be combined as bitflags, but are given powers of 2 values to
|
|
147692
|
+
// easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
|
|
147693
|
+
// They're also ordered in terms of increasing priority for a fix-all scenario (see
|
|
147694
|
+
// `reduceAddAsTypeOnlyValues`).
|
|
147695
|
+
var AddAsTypeOnly;
|
|
147696
|
+
(function (AddAsTypeOnly) {
|
|
147697
|
+
AddAsTypeOnly[AddAsTypeOnly["Allowed"] = 1] = "Allowed";
|
|
147698
|
+
AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
|
|
147699
|
+
AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
|
|
147700
|
+
})(AddAsTypeOnly || (AddAsTypeOnly = {}));
|
|
147276
147701
|
function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
|
|
147277
147702
|
var compilerOptions = program.getCompilerOptions();
|
|
147278
147703
|
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
|
|
147279
147704
|
? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
|
|
147280
147705
|
: getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
147281
147706
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147282
|
-
var
|
|
147283
|
-
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147284
|
-
return {
|
|
147707
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147708
|
+
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
|
|
147709
|
+
return {
|
|
147710
|
+
moduleSpecifier: fix.moduleSpecifier,
|
|
147711
|
+
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
|
|
147712
|
+
};
|
|
147285
147713
|
}
|
|
147286
147714
|
codefix.getImportCompletionAction = getImportCompletionAction;
|
|
147287
|
-
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147715
|
+
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147288
147716
|
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
|
|
147289
|
-
return getBestFix(getImportFixes(exportInfos, symbolName, position,
|
|
147717
|
+
return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
|
|
147290
147718
|
}
|
|
147291
147719
|
function codeFixActionToCodeAction(_a) {
|
|
147292
147720
|
var description = _a.description, changes = _a.changes, commands = _a.commands;
|
|
@@ -147344,24 +147772,21 @@ var ts;
|
|
|
147344
147772
|
function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
|
|
147345
147773
|
var _a = getNewImportFixes(program, importingFile,
|
|
147346
147774
|
/*position*/ undefined,
|
|
147347
|
-
/*
|
|
147775
|
+
/*isValidTypeOnlyUseSite*/ false,
|
|
147348
147776
|
/*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
|
|
147349
147777
|
var result = getBestFix(fixes, importingFile, program, host, preferences);
|
|
147350
147778
|
return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
|
|
147351
147779
|
}
|
|
147352
147780
|
codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
|
|
147353
|
-
function isTypeOnlyPosition(sourceFile, position) {
|
|
147354
|
-
return ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147355
|
-
}
|
|
147356
147781
|
function getImportFixes(exportInfos, symbolName,
|
|
147357
147782
|
/** undefined only for missing JSX namespace */
|
|
147358
|
-
position,
|
|
147783
|
+
position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
|
|
147359
147784
|
var checker = program.getTypeChecker();
|
|
147360
147785
|
var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
|
|
147361
147786
|
var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
|
|
147362
|
-
var addToExisting = tryAddToExistingImport(existingImports,
|
|
147787
|
+
var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
|
|
147363
147788
|
// Don't bother providing an action to add a new import if we can add to an existing one.
|
|
147364
|
-
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
147789
|
+
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147365
147790
|
return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
|
|
147366
147791
|
}
|
|
147367
147792
|
function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
|
|
@@ -147416,14 +147841,34 @@ var ts;
|
|
|
147416
147841
|
return ts.Debug.assertNever(declaration);
|
|
147417
147842
|
}
|
|
147418
147843
|
}
|
|
147419
|
-
function
|
|
147844
|
+
function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, symbol, targetFlags, checker, compilerOptions) {
|
|
147845
|
+
if (!isValidTypeOnlyUseSite) {
|
|
147846
|
+
// Can't use a type-only import if the usage is an emitting position
|
|
147847
|
+
return 4 /* NotAllowed */;
|
|
147848
|
+
}
|
|
147849
|
+
if (isForNewImportDeclaration && compilerOptions.importsNotUsedAsValues === 2 /* Error */) {
|
|
147850
|
+
// Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
|
|
147851
|
+
return 2 /* Required */;
|
|
147852
|
+
}
|
|
147853
|
+
if (compilerOptions.isolatedModules && compilerOptions.preserveValueImports &&
|
|
147854
|
+
(!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
147855
|
+
// A type-only import is required for this symbol if under these settings if the symbol will
|
|
147856
|
+
// be erased, which will happen if the target symbol is purely a type or if it was exported/imported
|
|
147857
|
+
// as type-only already somewhere between this import and the target.
|
|
147858
|
+
return 2 /* Required */;
|
|
147859
|
+
}
|
|
147860
|
+
return 1 /* Allowed */;
|
|
147861
|
+
}
|
|
147862
|
+
function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, compilerOptions) {
|
|
147420
147863
|
return ts.firstDefined(existingImports, function (_a) {
|
|
147421
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
147422
|
-
if (declaration.kind === 264 /* ImportEqualsDeclaration */)
|
|
147864
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
147865
|
+
if (importKind === 3 /* CommonJS */ || importKind === 2 /* Namespace */ || declaration.kind === 264 /* ImportEqualsDeclaration */) {
|
|
147866
|
+
// These kinds of imports are not combinable with anything
|
|
147423
147867
|
return undefined;
|
|
147868
|
+
}
|
|
147424
147869
|
if (declaration.kind === 253 /* VariableDeclaration */) {
|
|
147425
147870
|
return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 200 /* ObjectBindingPattern */
|
|
147426
|
-
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text,
|
|
147871
|
+
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, addAsTypeOnly: 4 /* NotAllowed */ }
|
|
147427
147872
|
: undefined;
|
|
147428
147873
|
}
|
|
147429
147874
|
var importClause = declaration.importClause;
|
|
@@ -147434,13 +147879,29 @@ var ts;
|
|
|
147434
147879
|
// be added to an existing type-only import is adding a named import to existing named bindings.
|
|
147435
147880
|
if (importClause.isTypeOnly && !(importKind === 0 /* Named */ && namedBindings))
|
|
147436
147881
|
return undefined;
|
|
147437
|
-
|
|
147438
|
-
|
|
147439
|
-
|
|
147882
|
+
// N.B. we don't have to figure out whether to use the main program checker
|
|
147883
|
+
// or the AutoImportProvider checker because we're adding to an existing import; the existence of
|
|
147884
|
+
// the import guarantees the symbol came from the main program.
|
|
147885
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ false, symbol, targetFlags, checker, compilerOptions);
|
|
147886
|
+
if (importKind === 1 /* Default */ && (name || // Cannot add a default import to a declaration that already has one
|
|
147887
|
+
addAsTypeOnly === 2 /* Required */ && namedBindings // Cannot add a default import as type-only if the import already has named bindings
|
|
147888
|
+
))
|
|
147889
|
+
return undefined;
|
|
147890
|
+
if (importKind === 0 /* Named */ &&
|
|
147891
|
+
(namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === 267 /* NamespaceImport */ // Cannot add a named import to a declaration that has a namespace import
|
|
147892
|
+
)
|
|
147893
|
+
return undefined;
|
|
147894
|
+
return {
|
|
147895
|
+
kind: 2 /* AddToExisting */,
|
|
147896
|
+
importClauseOrBindingPattern: importClause,
|
|
147897
|
+
importKind: importKind,
|
|
147898
|
+
moduleSpecifier: declaration.moduleSpecifier.text,
|
|
147899
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
147900
|
+
};
|
|
147440
147901
|
});
|
|
147441
147902
|
}
|
|
147442
147903
|
function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
|
|
147443
|
-
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags;
|
|
147904
|
+
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
|
|
147444
147905
|
// Can't use an es6 import for a type in JS.
|
|
147445
147906
|
if (!(targetFlags & 111551 /* Value */) && ts.isSourceFileJS(importingFile))
|
|
147446
147907
|
return ts.emptyArray;
|
|
@@ -147448,10 +147909,10 @@ var ts;
|
|
|
147448
147909
|
return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
|
|
147449
147910
|
var i = ts.importFromModuleSpecifier(moduleSpecifier);
|
|
147450
147911
|
if (ts.isRequireVariableDeclaration(i.parent)) {
|
|
147451
|
-
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind } : undefined;
|
|
147912
|
+
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
147452
147913
|
}
|
|
147453
147914
|
if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
|
|
147454
|
-
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind } : undefined;
|
|
147915
|
+
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
147455
147916
|
}
|
|
147456
147917
|
});
|
|
147457
147918
|
}
|
|
@@ -147483,44 +147944,50 @@ var ts;
|
|
|
147483
147944
|
// 5. Literally nothing to go on
|
|
147484
147945
|
return true;
|
|
147485
147946
|
}
|
|
147486
|
-
function getNewImportFixes(program, sourceFile, position,
|
|
147947
|
+
function getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
|
|
147487
147948
|
var isJs = ts.isSourceFileJS(sourceFile);
|
|
147488
147949
|
var compilerOptions = program.getCompilerOptions();
|
|
147489
147950
|
var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
|
|
147490
|
-
var
|
|
147951
|
+
var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
|
|
147491
147952
|
var getModuleSpecifiers = fromCacheOnly
|
|
147492
147953
|
? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
|
|
147493
|
-
: function (moduleSymbol) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
147954
|
+
: function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
147494
147955
|
var computedWithoutCacheCount = 0;
|
|
147495
147956
|
var fixes = ts.flatMap(moduleSymbols, function (exportInfo) {
|
|
147496
|
-
var
|
|
147957
|
+
var checker = getChecker(exportInfo.isFromPackageJson);
|
|
147958
|
+
var _a = getModuleSpecifiers(exportInfo.moduleSymbol, checker), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
|
|
147959
|
+
var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
|
|
147960
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
|
|
147497
147961
|
computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
|
|
147498
147962
|
return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
|
|
147499
147963
|
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
|
|
147500
|
-
return !
|
|
147501
|
-
? { kind: 1 /*
|
|
147964
|
+
return !importedSymbolHasValueMeaning && isJs && position !== undefined
|
|
147965
|
+
? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
|
|
147502
147966
|
: {
|
|
147503
147967
|
kind: 3 /* AddNew */,
|
|
147504
147968
|
moduleSpecifier: moduleSpecifier,
|
|
147505
147969
|
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
|
|
147506
147970
|
useRequire: useRequire,
|
|
147507
|
-
|
|
147971
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
147508
147972
|
exportInfo: exportInfo,
|
|
147509
147973
|
};
|
|
147510
147974
|
});
|
|
147511
147975
|
});
|
|
147512
147976
|
return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
|
|
147513
147977
|
}
|
|
147514
|
-
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
147515
|
-
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info,
|
|
147516
|
-
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position,
|
|
147978
|
+
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147979
|
+
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
|
|
147980
|
+
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
|
|
147517
147981
|
}
|
|
147518
|
-
function newImportInfoFromExistingSpecifier(_a,
|
|
147519
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
147982
|
+
function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
|
|
147983
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
147520
147984
|
var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
|
|
147521
|
-
|
|
147522
|
-
|
|
147523
|
-
|
|
147985
|
+
if (moduleSpecifier) {
|
|
147986
|
+
var addAsTypeOnly = useRequire
|
|
147987
|
+
? 4 /* NotAllowed */
|
|
147988
|
+
: getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, symbol, targetFlags, checker, compilerOptions);
|
|
147989
|
+
return { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, addAsTypeOnly: addAsTypeOnly, useRequire: useRequire };
|
|
147990
|
+
}
|
|
147524
147991
|
}
|
|
147525
147992
|
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
|
|
147526
147993
|
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
|
|
@@ -147570,7 +148037,7 @@ var ts;
|
|
|
147570
148037
|
var symbolName = umdSymbol.name;
|
|
147571
148038
|
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
|
|
147572
148039
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147573
|
-
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*
|
|
148040
|
+
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
|
147574
148041
|
return { fixes: fixes, symbolName: symbolName };
|
|
147575
148042
|
}
|
|
147576
148043
|
function getUmdSymbol(token, checker) {
|
|
@@ -147616,6 +148083,7 @@ var ts;
|
|
|
147616
148083
|
case ts.ModuleKind.System:
|
|
147617
148084
|
case ts.ModuleKind.ES2015:
|
|
147618
148085
|
case ts.ModuleKind.ES2020:
|
|
148086
|
+
case ts.ModuleKind.ES2022:
|
|
147619
148087
|
case ts.ModuleKind.ESNext:
|
|
147620
148088
|
case ts.ModuleKind.None:
|
|
147621
148089
|
// Fall back to the `import * as ns` style import.
|
|
@@ -147634,12 +148102,12 @@ var ts;
|
|
|
147634
148102
|
var symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
|
|
147635
148103
|
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
|
|
147636
148104
|
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
|
|
147637
|
-
var
|
|
148105
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
|
|
147638
148106
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147639
148107
|
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
147640
148108
|
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
|
|
147641
148109
|
var _ = _a[0], exportInfos = _a[1];
|
|
147642
|
-
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile),
|
|
148110
|
+
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
|
|
147643
148111
|
}));
|
|
147644
148112
|
return { fixes: fixes, symbolName: symbolName };
|
|
147645
148113
|
}
|
|
@@ -147717,63 +148185,81 @@ var ts;
|
|
|
147717
148185
|
// allowSyntheticDefaultImports/esModuleInterop is enabled.
|
|
147718
148186
|
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
|
|
147719
148187
|
}
|
|
147720
|
-
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference) {
|
|
148188
|
+
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
147721
148189
|
var diag;
|
|
147722
148190
|
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
|
|
147723
|
-
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference);
|
|
148191
|
+
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
|
147724
148192
|
});
|
|
147725
148193
|
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
|
|
147726
148194
|
}
|
|
147727
|
-
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference) {
|
|
148195
|
+
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
147728
148196
|
switch (fix.kind) {
|
|
147729
148197
|
case 0 /* UseNamespace */:
|
|
147730
148198
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
147731
148199
|
return [ts.Diagnostics.Change_0_to_1, symbolName, fix.namespacePrefix + "." + symbolName];
|
|
147732
|
-
case 1 /*
|
|
148200
|
+
case 1 /* JsdocTypeImport */:
|
|
147733
148201
|
addImportType(changes, sourceFile, fix, quotePreference);
|
|
147734
148202
|
return [ts.Diagnostics.Change_0_to_1, symbolName, getImportTypePrefix(fix.moduleSpecifier, quotePreference) + symbolName];
|
|
147735
148203
|
case 2 /* AddToExisting */: {
|
|
147736
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
147737
|
-
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName : undefined, importKind === 0 /* Named */ ? [symbolName] : ts.emptyArray,
|
|
148204
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
|
|
148205
|
+
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
|
|
147738
148206
|
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
|
|
147739
|
-
return [
|
|
148207
|
+
return [
|
|
148208
|
+
importKind === 1 /* Default */ ? ts.Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : ts.Diagnostics.Add_0_to_existing_import_declaration_from_1,
|
|
148209
|
+
symbolName,
|
|
148210
|
+
moduleSpecifierWithoutQuotes
|
|
148211
|
+
]; // you too!
|
|
147740
148212
|
}
|
|
147741
148213
|
case 3 /* AddNew */: {
|
|
147742
|
-
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier,
|
|
148214
|
+
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
|
|
147743
148215
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147744
|
-
var
|
|
147745
|
-
|
|
147746
|
-
|
|
147747
|
-
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference,
|
|
148216
|
+
var defaultImport = importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148217
|
+
var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
|
|
148218
|
+
var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148219
|
+
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
|
147748
148220
|
return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
|
|
147749
148221
|
}
|
|
147750
148222
|
default:
|
|
147751
148223
|
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
|
|
147752
148224
|
}
|
|
147753
148225
|
}
|
|
147754
|
-
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports,
|
|
148226
|
+
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
|
|
148227
|
+
var _a;
|
|
147755
148228
|
if (clause.kind === 200 /* ObjectBindingPattern */) {
|
|
147756
148229
|
if (defaultImport) {
|
|
147757
|
-
addElementToBindingPattern(clause, defaultImport, "default");
|
|
148230
|
+
addElementToBindingPattern(clause, defaultImport.name, "default");
|
|
147758
148231
|
}
|
|
147759
148232
|
for (var _i = 0, namedImports_1 = namedImports; _i < namedImports_1.length; _i++) {
|
|
147760
148233
|
var specifier = namedImports_1[_i];
|
|
147761
|
-
addElementToBindingPattern(clause, specifier, /*propertyName*/ undefined);
|
|
148234
|
+
addElementToBindingPattern(clause, specifier.name, /*propertyName*/ undefined);
|
|
147762
148235
|
}
|
|
147763
148236
|
return;
|
|
147764
148237
|
}
|
|
147765
|
-
var
|
|
148238
|
+
var promoteFromTypeOnly = clause.isTypeOnly && ts.some(__spreadArray([defaultImport], namedImports, true), function (i) { return (i === null || i === void 0 ? void 0 : i.addAsTypeOnly) === 4 /* NotAllowed */; });
|
|
148239
|
+
var existingSpecifiers = clause.namedBindings && ((_a = ts.tryCast(clause.namedBindings, ts.isNamedImports)) === null || _a === void 0 ? void 0 : _a.elements);
|
|
148240
|
+
// If we are promoting from a type-only import and `--isolatedModules` and `--preserveValueImports`
|
|
148241
|
+
// are enabled, we need to make every existing import specifier type-only. It may be possible that
|
|
148242
|
+
// some of them don't strictly need to be marked type-only (if they have a value meaning and are
|
|
148243
|
+
// never used in an emitting position). These are allowed to be imported without being type-only,
|
|
148244
|
+
// but the user has clearly already signified that they don't need them to be present at runtime
|
|
148245
|
+
// by placing them in a type-only import. So, just mark each specifier as type-only.
|
|
148246
|
+
var convertExistingToTypeOnly = promoteFromTypeOnly && compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
|
|
147766
148247
|
if (defaultImport) {
|
|
147767
148248
|
ts.Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
147768
|
-
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport), { suffix: ", " });
|
|
148249
|
+
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport.name), { suffix: ", " });
|
|
147769
148250
|
}
|
|
147770
148251
|
if (namedImports.length) {
|
|
147771
|
-
var
|
|
147772
|
-
|
|
148252
|
+
var newSpecifiers = ts.stableSort(namedImports.map(function (namedImport) { return ts.factory.createImportSpecifier((!clause.isTypeOnly || promoteFromTypeOnly) && needsTypeOnly(namedImport),
|
|
148253
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(namedImport.name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
|
|
147773
148254
|
if ((existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) && ts.OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) {
|
|
147774
|
-
for (var
|
|
147775
|
-
var spec = newSpecifiers_1[
|
|
147776
|
-
|
|
148255
|
+
for (var _b = 0, newSpecifiers_1 = newSpecifiers; _b < newSpecifiers_1.length; _b++) {
|
|
148256
|
+
var spec = newSpecifiers_1[_b];
|
|
148257
|
+
// Organize imports puts type-only import specifiers last, so if we're
|
|
148258
|
+
// adding a non-type-only specifier and converting all the other ones to
|
|
148259
|
+
// type-only, there's no need to ask for the insertion index - it's 0.
|
|
148260
|
+
var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
|
|
148261
|
+
? 0
|
|
148262
|
+
: ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
|
|
147777
148263
|
var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
|
|
147778
148264
|
if (prevSpecifier) {
|
|
147779
148265
|
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
|
|
@@ -147784,8 +148270,8 @@ var ts;
|
|
|
147784
148270
|
}
|
|
147785
148271
|
}
|
|
147786
148272
|
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
|
|
147787
|
-
for (var
|
|
147788
|
-
var spec = newSpecifiers_2[
|
|
148273
|
+
for (var _c = 0, newSpecifiers_2 = newSpecifiers; _c < newSpecifiers_2.length; _c++) {
|
|
148274
|
+
var spec = newSpecifiers_2[_c];
|
|
147789
148275
|
changes.insertNodeInListAfter(sourceFile, ts.last(existingSpecifiers), spec, existingSpecifiers);
|
|
147790
148276
|
}
|
|
147791
148277
|
}
|
|
@@ -147801,8 +148287,14 @@ var ts;
|
|
|
147801
148287
|
}
|
|
147802
148288
|
}
|
|
147803
148289
|
}
|
|
147804
|
-
if (
|
|
148290
|
+
if (promoteFromTypeOnly) {
|
|
147805
148291
|
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(clause, sourceFile));
|
|
148292
|
+
if (convertExistingToTypeOnly && existingSpecifiers) {
|
|
148293
|
+
for (var _d = 0, existingSpecifiers_1 = existingSpecifiers; _d < existingSpecifiers_1.length; _d++) {
|
|
148294
|
+
var specifier = existingSpecifiers_1[_d];
|
|
148295
|
+
changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, specifier);
|
|
148296
|
+
}
|
|
148297
|
+
}
|
|
147806
148298
|
}
|
|
147807
148299
|
function addElementToBindingPattern(bindingPattern, name, propertyName) {
|
|
147808
148300
|
var element = ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, propertyName, name);
|
|
@@ -147826,44 +148318,53 @@ var ts;
|
|
|
147826
148318
|
var quote = ts.getQuoteFromPreference(quotePreference);
|
|
147827
148319
|
return "import(" + quote + moduleSpecifier + quote + ").";
|
|
147828
148320
|
}
|
|
147829
|
-
function
|
|
147830
|
-
var _a
|
|
148321
|
+
function needsTypeOnly(_a) {
|
|
148322
|
+
var addAsTypeOnly = _a.addAsTypeOnly;
|
|
148323
|
+
return addAsTypeOnly === 2 /* Required */;
|
|
148324
|
+
}
|
|
148325
|
+
function getNewImports(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
147831
148326
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
147832
148327
|
var statements;
|
|
147833
|
-
if (
|
|
147834
|
-
|
|
148328
|
+
if (defaultImport !== undefined || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148329
|
+
var topLevelTypeOnly_1 = (!defaultImport || needsTypeOnly(defaultImport)) && ts.every(namedImports, needsTypeOnly);
|
|
148330
|
+
statements = ts.combine(statements, ts.makeImport(defaultImport && ts.factory.createIdentifier(defaultImport.name), namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148331
|
+
var addAsTypeOnly = _a.addAsTypeOnly, name = _a.name;
|
|
148332
|
+
return ts.factory.createImportSpecifier(!topLevelTypeOnly_1 && addAsTypeOnly === 2 /* Required */,
|
|
148333
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(name));
|
|
148334
|
+
}), moduleSpecifier, quotePreference, topLevelTypeOnly_1));
|
|
147835
148335
|
}
|
|
147836
|
-
var namespaceLikeImport = imports.namespaceLikeImport, typeOnly = imports.typeOnly;
|
|
147837
148336
|
if (namespaceLikeImport) {
|
|
147838
148337
|
var declaration = namespaceLikeImport.importKind === 3 /* CommonJS */
|
|
147839
148338
|
? ts.factory.createImportEqualsDeclaration(
|
|
147840
148339
|
/*decorators*/ undefined,
|
|
147841
|
-
/*modifiers*/ undefined,
|
|
148340
|
+
/*modifiers*/ undefined, needsTypeOnly(namespaceLikeImport), ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
|
|
147842
148341
|
: ts.factory.createImportDeclaration(
|
|
147843
148342
|
/*decorators*/ undefined,
|
|
147844
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
148343
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(needsTypeOnly(namespaceLikeImport),
|
|
147845
148344
|
/*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier,
|
|
147846
148345
|
/*assertClause*/ undefined);
|
|
147847
148346
|
statements = ts.combine(statements, declaration);
|
|
147848
148347
|
}
|
|
147849
148348
|
return ts.Debug.checkDefined(statements);
|
|
147850
148349
|
}
|
|
147851
|
-
function getNewRequires(moduleSpecifier, quotePreference,
|
|
147852
|
-
var _a, _b;
|
|
148350
|
+
function getNewRequires(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
147853
148351
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
147854
148352
|
var statements;
|
|
147855
148353
|
// const { default: foo, bar, etc } = require('./mod');
|
|
147856
|
-
if (
|
|
147857
|
-
var bindingElements = (
|
|
147858
|
-
|
|
147859
|
-
|
|
148354
|
+
if (defaultImport || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148355
|
+
var bindingElements = (namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148356
|
+
var name = _a.name;
|
|
148357
|
+
return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name);
|
|
148358
|
+
})) || [];
|
|
148359
|
+
if (defaultImport) {
|
|
148360
|
+
bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", defaultImport.name));
|
|
147860
148361
|
}
|
|
147861
148362
|
var declaration = createConstEqualsRequireDeclaration(ts.factory.createObjectBindingPattern(bindingElements), quotedModuleSpecifier);
|
|
147862
148363
|
statements = ts.combine(statements, declaration);
|
|
147863
148364
|
}
|
|
147864
148365
|
// const foo = require('./mod');
|
|
147865
|
-
if (
|
|
147866
|
-
var declaration = createConstEqualsRequireDeclaration(
|
|
148366
|
+
if (namespaceLikeImport) {
|
|
148367
|
+
var declaration = createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier);
|
|
147867
148368
|
statements = ts.combine(statements, declaration);
|
|
147868
148369
|
}
|
|
147869
148370
|
return ts.Debug.checkDefined(statements);
|
|
@@ -149350,8 +149851,8 @@ var ts;
|
|
|
149350
149851
|
(function (codefix) {
|
|
149351
149852
|
codefix.registerCodeFix({
|
|
149352
149853
|
errorCodes: [
|
|
149353
|
-
ts.Diagnostics.
|
|
149354
|
-
ts.Diagnostics.
|
|
149854
|
+
ts.Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
|
|
149855
|
+
ts.Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
|
|
149355
149856
|
],
|
|
149356
149857
|
getCodeActions: function (context) {
|
|
149357
149858
|
var compilerOptions = context.program.getCompilerOptions();
|
|
@@ -151775,7 +152276,7 @@ var ts;
|
|
|
151775
152276
|
return ts.factory.createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
|
|
151776
152277
|
}
|
|
151777
152278
|
function importSymbols(importAdder, symbols) {
|
|
151778
|
-
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*
|
|
152279
|
+
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*isValidTypeOnlyUseSite*/ true); });
|
|
151779
152280
|
}
|
|
151780
152281
|
codefix.importSymbols = importSymbols;
|
|
151781
152282
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -152247,7 +152748,7 @@ var ts;
|
|
|
152247
152748
|
if (!ts.isIdentifier(element.name) || element.initializer) {
|
|
152248
152749
|
return undefined;
|
|
152249
152750
|
}
|
|
152250
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152751
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152251
152752
|
}
|
|
152252
152753
|
if (importSpecifiers.length) {
|
|
152253
152754
|
return ts.factory.createNamedImports(importSpecifiers);
|
|
@@ -152994,10 +153495,10 @@ var ts;
|
|
|
152994
153495
|
}
|
|
152995
153496
|
}
|
|
152996
153497
|
function makeImportSpecifier(propertyName, name) {
|
|
152997
|
-
return ts.factory.createImportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153498
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
152998
153499
|
}
|
|
152999
153500
|
function makeExportSpecifier(propertyName, name) {
|
|
153000
|
-
return ts.factory.createExportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153501
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153001
153502
|
}
|
|
153002
153503
|
})(refactor = ts.refactor || (ts.refactor = {}));
|
|
153003
153504
|
})(ts || (ts = {}));
|
|
@@ -153110,7 +153611,7 @@ var ts;
|
|
|
153110
153611
|
}
|
|
153111
153612
|
var importSpecifiers = [];
|
|
153112
153613
|
exportNameToImportName.forEach(function (name, propertyName) {
|
|
153113
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153614
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153114
153615
|
});
|
|
153115
153616
|
var importDecl = toConvert.parent.parent;
|
|
153116
153617
|
if (usedAsNamespaceOrDefault && !allowSyntheticDefaultImports) {
|
|
@@ -153181,7 +153682,7 @@ var ts;
|
|
|
153181
153682
|
changes.replaceNode(sourceFile, toConvert, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
|
|
153182
153683
|
if (neededNamedImports.size) {
|
|
153183
153684
|
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
|
|
153184
|
-
return ts.factory.createImportSpecifier(element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153685
|
+
return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153185
153686
|
});
|
|
153186
153687
|
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
|
|
153187
153688
|
}
|
|
@@ -155883,7 +156384,7 @@ var ts;
|
|
|
155883
156384
|
function makeImportOrRequire(defaultImport, imports, path, useEs6Imports, quotePreference) {
|
|
155884
156385
|
path = ts.ensurePathIsNonModuleName(path);
|
|
155885
156386
|
if (useEs6Imports) {
|
|
155886
|
-
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156387
|
+
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
155887
156388
|
return ts.makeImportIfNecessary(defaultImport, specifiers, path, quotePreference);
|
|
155888
156389
|
}
|
|
155889
156390
|
else {
|