@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/typescript.js
CHANGED
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-insiders.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-insiders.20211001";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -5348,6 +5348,7 @@ var ts;
|
|
|
5348
5348
|
// module kind).
|
|
5349
5349
|
ModuleKind[ModuleKind["ES2015"] = 5] = "ES2015";
|
|
5350
5350
|
ModuleKind[ModuleKind["ES2020"] = 6] = "ES2020";
|
|
5351
|
+
ModuleKind[ModuleKind["ES2022"] = 7] = "ES2022";
|
|
5351
5352
|
ModuleKind[ModuleKind["ESNext"] = 99] = "ESNext";
|
|
5352
5353
|
// Node12+ is an amalgam of commonjs (albeit updated) and es2020+, and represents a distinct module system from es2020/esnext
|
|
5353
5354
|
ModuleKind[ModuleKind["Node12"] = 100] = "Node12";
|
|
@@ -8265,7 +8266,7 @@ var ts;
|
|
|
8265
8266
|
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."),
|
|
8266
8267
|
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."),
|
|
8267
8268
|
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."),
|
|
8268
|
-
|
|
8269
|
+
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'."),
|
|
8269
8270
|
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'."),
|
|
8270
8271
|
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."),
|
|
8271
8272
|
Dynamic_import_cannot_have_type_arguments: diag(1326, ts.DiagnosticCategory.Error, "Dynamic_import_cannot_have_type_arguments_1326", "Dynamic import cannot have type arguments."),
|
|
@@ -8283,7 +8284,7 @@ var ts;
|
|
|
8283
8284
|
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."),
|
|
8284
8285
|
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}')'?"),
|
|
8285
8286
|
Type_arguments_cannot_be_used_here: diag(1342, ts.DiagnosticCategory.Error, "Type_arguments_cannot_be_used_here_1342", "Type arguments cannot be used here."),
|
|
8286
|
-
|
|
8287
|
+
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'."),
|
|
8287
8288
|
A_label_is_not_allowed_here: diag(1344, ts.DiagnosticCategory.Error, "A_label_is_not_allowed_here_1344", "'A label is not allowed here."),
|
|
8288
8289
|
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."),
|
|
8289
8290
|
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."),
|
|
@@ -8314,7 +8315,7 @@ var ts;
|
|
|
8314
8315
|
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."),
|
|
8315
8316
|
_0_was_imported_here: diag(1376, ts.DiagnosticCategory.Message, "_0_was_imported_here_1376", "'{0}' was imported here."),
|
|
8316
8317
|
_0_was_exported_here: diag(1377, ts.DiagnosticCategory.Message, "_0_was_exported_here_1377", "'{0}' was exported here."),
|
|
8317
|
-
|
|
8318
|
+
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."),
|
|
8318
8319
|
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'."),
|
|
8319
8320
|
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'."),
|
|
8320
8321
|
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 `}`?"),
|
|
@@ -8366,7 +8367,7 @@ var ts;
|
|
|
8366
8367
|
File_redirects_to_file_0: diag(1429, ts.DiagnosticCategory.Message, "File_redirects_to_file_0_1429", "File redirects to file '{0}'"),
|
|
8367
8368
|
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:"),
|
|
8368
8369
|
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."),
|
|
8369
|
-
|
|
8370
|
+
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."),
|
|
8370
8371
|
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."),
|
|
8371
8372
|
Unexpected_keyword_or_identifier: diag(1434, ts.DiagnosticCategory.Error, "Unexpected_keyword_or_identifier_1434", "Unexpected keyword or identifier."),
|
|
8372
8373
|
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}'?"),
|
|
@@ -8392,6 +8393,8 @@ var ts;
|
|
|
8392
8393
|
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),
|
|
8393
8394
|
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),
|
|
8394
8395
|
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),
|
|
8396
|
+
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."),
|
|
8397
|
+
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."),
|
|
8395
8398
|
Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
|
|
8396
8399
|
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."),
|
|
8397
8400
|
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."),
|
|
@@ -13179,7 +13182,7 @@ var ts;
|
|
|
13179
13182
|
switch (node.kind) {
|
|
13180
13183
|
case 269 /* ImportSpecifier */:
|
|
13181
13184
|
case 274 /* ExportSpecifier */:
|
|
13182
|
-
return node.parent.parent.isTypeOnly;
|
|
13185
|
+
return node.isTypeOnly || node.parent.parent.isTypeOnly;
|
|
13183
13186
|
case 267 /* NamespaceImport */:
|
|
13184
13187
|
return node.parent.isTypeOnly;
|
|
13185
13188
|
case 266 /* ImportClause */:
|
|
@@ -19817,6 +19820,7 @@ var ts;
|
|
|
19817
19820
|
case ts.ModuleKind.AMD:
|
|
19818
19821
|
case ts.ModuleKind.ES2015:
|
|
19819
19822
|
case ts.ModuleKind.ES2020:
|
|
19823
|
+
case ts.ModuleKind.ES2022:
|
|
19820
19824
|
case ts.ModuleKind.ESNext:
|
|
19821
19825
|
return true;
|
|
19822
19826
|
default:
|
|
@@ -19990,7 +19994,8 @@ var ts;
|
|
|
19990
19994
|
var aParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(a, cwd));
|
|
19991
19995
|
var bParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(b, cwd));
|
|
19992
19996
|
var isDirectory = false;
|
|
19993
|
-
while (
|
|
19997
|
+
while (aParts.length >= 2 && bParts.length >= 2 &&
|
|
19998
|
+
!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
|
19994
19999
|
!isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) &&
|
|
19995
20000
|
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
|
|
19996
20001
|
aParts.pop();
|
|
@@ -20002,7 +20007,7 @@ var ts;
|
|
|
20002
20007
|
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
|
20003
20008
|
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
|
20004
20009
|
function isNodeModulesOrScopedPackageDirectory(s, getCanonicalFileName) {
|
|
20005
|
-
return getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@");
|
|
20010
|
+
return s !== undefined && (getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@"));
|
|
20006
20011
|
}
|
|
20007
20012
|
function stripLeadingDirectorySeparator(s) {
|
|
20008
20013
|
return ts.isAnyDirectorySeparator(s.charCodeAt(0)) ? s.slice(1) : undefined;
|
|
@@ -20633,10 +20638,6 @@ var ts;
|
|
|
20633
20638
|
|| !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
|
|
20634
20639
|
}
|
|
20635
20640
|
ts.isValidTypeOnlyAliasUseSite = isValidTypeOnlyAliasUseSite;
|
|
20636
|
-
function typeOnlyDeclarationIsExport(typeOnlyDeclaration) {
|
|
20637
|
-
return typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
20638
|
-
}
|
|
20639
|
-
ts.typeOnlyDeclarationIsExport = typeOnlyDeclarationIsExport;
|
|
20640
20641
|
function isShorthandPropertyNameUseSite(useSite) {
|
|
20641
20642
|
return ts.isIdentifier(useSite) && ts.isShorthandPropertyAssignment(useSite.parent) && useSite.parent.name === useSite;
|
|
20642
20643
|
}
|
|
@@ -20924,6 +20925,10 @@ var ts;
|
|
|
20924
20925
|
return !!declaration && (ts.isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
|
|
20925
20926
|
}
|
|
20926
20927
|
ts.isParameterOrCatchClauseVariable = isParameterOrCatchClauseVariable;
|
|
20928
|
+
function isFunctionExpressionOrArrowFunction(node) {
|
|
20929
|
+
return node.kind === 212 /* FunctionExpression */ || node.kind === 213 /* ArrowFunction */;
|
|
20930
|
+
}
|
|
20931
|
+
ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
|
|
20927
20932
|
})(ts || (ts = {}));
|
|
20928
20933
|
/* @internal */
|
|
20929
20934
|
var ts;
|
|
@@ -24658,8 +24663,9 @@ var ts;
|
|
|
24658
24663
|
: node;
|
|
24659
24664
|
}
|
|
24660
24665
|
// @api
|
|
24661
|
-
function createImportSpecifier(propertyName, name) {
|
|
24666
|
+
function createImportSpecifier(isTypeOnly, propertyName, name) {
|
|
24662
24667
|
var node = createBaseNode(269 /* ImportSpecifier */);
|
|
24668
|
+
node.isTypeOnly = isTypeOnly;
|
|
24663
24669
|
node.propertyName = propertyName;
|
|
24664
24670
|
node.name = name;
|
|
24665
24671
|
node.transformFlags |=
|
|
@@ -24669,10 +24675,11 @@ var ts;
|
|
|
24669
24675
|
return node;
|
|
24670
24676
|
}
|
|
24671
24677
|
// @api
|
|
24672
|
-
function updateImportSpecifier(node, propertyName, name) {
|
|
24673
|
-
return node.
|
|
24678
|
+
function updateImportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24679
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24680
|
+
|| node.propertyName !== propertyName
|
|
24674
24681
|
|| node.name !== name
|
|
24675
|
-
? update(createImportSpecifier(propertyName, name), node)
|
|
24682
|
+
? update(createImportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24676
24683
|
: node;
|
|
24677
24684
|
}
|
|
24678
24685
|
// @api
|
|
@@ -24733,8 +24740,9 @@ var ts;
|
|
|
24733
24740
|
: node;
|
|
24734
24741
|
}
|
|
24735
24742
|
// @api
|
|
24736
|
-
function createExportSpecifier(propertyName, name) {
|
|
24743
|
+
function createExportSpecifier(isTypeOnly, propertyName, name) {
|
|
24737
24744
|
var node = createBaseNode(274 /* ExportSpecifier */);
|
|
24745
|
+
node.isTypeOnly = isTypeOnly;
|
|
24738
24746
|
node.propertyName = asName(propertyName);
|
|
24739
24747
|
node.name = asName(name);
|
|
24740
24748
|
node.transformFlags |=
|
|
@@ -24744,10 +24752,11 @@ var ts;
|
|
|
24744
24752
|
return node;
|
|
24745
24753
|
}
|
|
24746
24754
|
// @api
|
|
24747
|
-
function updateExportSpecifier(node, propertyName, name) {
|
|
24748
|
-
return node.
|
|
24755
|
+
function updateExportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24756
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24757
|
+
|| node.propertyName !== propertyName
|
|
24749
24758
|
|| node.name !== name
|
|
24750
|
-
? update(createExportSpecifier(propertyName, name), node)
|
|
24759
|
+
? update(createExportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24751
24760
|
: node;
|
|
24752
24761
|
}
|
|
24753
24762
|
// @api
|
|
@@ -25855,7 +25864,7 @@ var ts;
|
|
|
25855
25864
|
/*decorators*/ undefined,
|
|
25856
25865
|
/*modifiers*/ undefined,
|
|
25857
25866
|
/*isTypeOnly*/ false, createNamedExports([
|
|
25858
|
-
createExportSpecifier(/*propertyName*/ undefined, exportName)
|
|
25867
|
+
createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, exportName)
|
|
25859
25868
|
]));
|
|
25860
25869
|
}
|
|
25861
25870
|
//
|
|
@@ -29122,8 +29131,8 @@ var ts;
|
|
|
29122
29131
|
// Alias the imports if the names are used somewhere in the file.
|
|
29123
29132
|
// NOTE: We don't need to care about global import collisions as this is a module.
|
|
29124
29133
|
namedBindings = nodeFactory.createNamedImports(ts.map(helperNames, function (name) { return ts.isFileLevelUniqueName(sourceFile, name)
|
|
29125
|
-
? nodeFactory.createImportSpecifier(/*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
29126
|
-
: nodeFactory.createImportSpecifier(nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
29134
|
+
? nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
29135
|
+
: nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
29127
29136
|
var parseNode = ts.getOriginalNode(sourceFile, ts.isSourceFile);
|
|
29128
29137
|
var emitNode = ts.getOrCreateEmitNode(parseNode);
|
|
29129
29138
|
emitNode.externalHelpers = true;
|
|
@@ -31544,7 +31553,6 @@ var ts;
|
|
|
31544
31553
|
case 88 /* DefaultKeyword */:
|
|
31545
31554
|
return nextTokenCanFollowDefaultKeyword();
|
|
31546
31555
|
case 124 /* StaticKeyword */:
|
|
31547
|
-
return nextTokenIsOnSameLineAndCanFollowModifier();
|
|
31548
31556
|
case 136 /* GetKeyword */:
|
|
31549
31557
|
case 148 /* SetKeyword */:
|
|
31550
31558
|
nextToken();
|
|
@@ -35787,7 +35795,7 @@ var ts;
|
|
|
35787
35795
|
}
|
|
35788
35796
|
return list && createNodeArray(list, pos);
|
|
35789
35797
|
}
|
|
35790
|
-
function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
|
|
35798
|
+
function tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
|
|
35791
35799
|
var pos = getNodePos();
|
|
35792
35800
|
var kind = token();
|
|
35793
35801
|
if (token() === 85 /* ConstKeyword */ && permitInvalidConstAsModifier) {
|
|
@@ -35800,6 +35808,9 @@ var ts;
|
|
|
35800
35808
|
else if (stopOnStartOfClassStaticBlock && token() === 124 /* StaticKeyword */ && lookAhead(nextTokenIsOpenBrace)) {
|
|
35801
35809
|
return undefined;
|
|
35802
35810
|
}
|
|
35811
|
+
else if (hasSeenStaticModifier && token() === 124 /* StaticKeyword */) {
|
|
35812
|
+
return undefined;
|
|
35813
|
+
}
|
|
35803
35814
|
else {
|
|
35804
35815
|
if (!parseAnyContextualModifier()) {
|
|
35805
35816
|
return undefined;
|
|
@@ -35816,8 +35827,10 @@ var ts;
|
|
|
35816
35827
|
*/
|
|
35817
35828
|
function parseModifiers(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock) {
|
|
35818
35829
|
var pos = getNodePos();
|
|
35819
|
-
var list, modifier;
|
|
35820
|
-
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock)) {
|
|
35830
|
+
var list, modifier, hasSeenStatic = false;
|
|
35831
|
+
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
|
|
35832
|
+
if (modifier.kind === 124 /* StaticKeyword */)
|
|
35833
|
+
hasSeenStatic = true;
|
|
35821
35834
|
list = ts.append(list, modifier);
|
|
35822
35835
|
}
|
|
35823
35836
|
return list && createNodeArray(list, pos);
|
|
@@ -36250,27 +36263,74 @@ var ts;
|
|
|
36250
36263
|
var checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36251
36264
|
var checkIdentifierStart = scanner.getTokenPos();
|
|
36252
36265
|
var checkIdentifierEnd = scanner.getTextPos();
|
|
36253
|
-
var
|
|
36266
|
+
var isTypeOnly = false;
|
|
36254
36267
|
var propertyName;
|
|
36255
|
-
var
|
|
36256
|
-
|
|
36257
|
-
|
|
36258
|
-
|
|
36259
|
-
|
|
36260
|
-
|
|
36261
|
-
|
|
36262
|
-
|
|
36268
|
+
var canParseAsKeyword = true;
|
|
36269
|
+
var name = parseIdentifierName();
|
|
36270
|
+
if (name.escapedText === "type") {
|
|
36271
|
+
// If the first token of an import specifier is 'type', there are a lot of possibilities,
|
|
36272
|
+
// especially if we see 'as' afterwards:
|
|
36273
|
+
//
|
|
36274
|
+
// import { type } from "mod"; - isTypeOnly: false, name: type
|
|
36275
|
+
// import { type as } from "mod"; - isTypeOnly: true, name: as
|
|
36276
|
+
// import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
|
|
36277
|
+
// import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
|
|
36278
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36279
|
+
// { type as ...? }
|
|
36280
|
+
var firstAs = parseIdentifierName();
|
|
36281
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36282
|
+
// { type as as ...? }
|
|
36283
|
+
var secondAs = parseIdentifierName();
|
|
36284
|
+
if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36285
|
+
// { type as as something }
|
|
36286
|
+
isTypeOnly = true;
|
|
36287
|
+
propertyName = firstAs;
|
|
36288
|
+
name = parseNameWithKeywordCheck();
|
|
36289
|
+
canParseAsKeyword = false;
|
|
36290
|
+
}
|
|
36291
|
+
else {
|
|
36292
|
+
// { type as as }
|
|
36293
|
+
propertyName = name;
|
|
36294
|
+
name = secondAs;
|
|
36295
|
+
canParseAsKeyword = false;
|
|
36296
|
+
}
|
|
36297
|
+
}
|
|
36298
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36299
|
+
// { type as something }
|
|
36300
|
+
propertyName = name;
|
|
36301
|
+
canParseAsKeyword = false;
|
|
36302
|
+
name = parseNameWithKeywordCheck();
|
|
36303
|
+
}
|
|
36304
|
+
else {
|
|
36305
|
+
// { type as }
|
|
36306
|
+
isTypeOnly = true;
|
|
36307
|
+
name = firstAs;
|
|
36308
|
+
}
|
|
36309
|
+
}
|
|
36310
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36311
|
+
// { type something ...? }
|
|
36312
|
+
isTypeOnly = true;
|
|
36313
|
+
name = parseNameWithKeywordCheck();
|
|
36314
|
+
}
|
|
36263
36315
|
}
|
|
36264
|
-
|
|
36265
|
-
|
|
36316
|
+
if (canParseAsKeyword && token() === 127 /* AsKeyword */) {
|
|
36317
|
+
propertyName = name;
|
|
36318
|
+
parseExpected(127 /* AsKeyword */);
|
|
36319
|
+
name = parseNameWithKeywordCheck();
|
|
36266
36320
|
}
|
|
36267
36321
|
if (kind === 269 /* ImportSpecifier */ && checkIdentifierIsKeyword) {
|
|
36268
36322
|
parseErrorAt(checkIdentifierStart, checkIdentifierEnd, ts.Diagnostics.Identifier_expected);
|
|
36269
36323
|
}
|
|
36270
36324
|
var node = kind === 269 /* ImportSpecifier */
|
|
36271
|
-
? factory.createImportSpecifier(propertyName, name)
|
|
36272
|
-
: factory.createExportSpecifier(propertyName, name);
|
|
36325
|
+
? factory.createImportSpecifier(isTypeOnly, propertyName, name)
|
|
36326
|
+
: factory.createExportSpecifier(isTypeOnly, propertyName, name);
|
|
36273
36327
|
return finishNode(node, pos);
|
|
36328
|
+
function parseNameWithKeywordCheck() {
|
|
36329
|
+
checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36330
|
+
checkIdentifierStart = scanner.getTokenPos();
|
|
36331
|
+
checkIdentifierEnd = scanner.getTextPos();
|
|
36332
|
+
return parseIdentifierName();
|
|
36333
|
+
}
|
|
36274
36334
|
}
|
|
36275
36335
|
function parseNamespaceExport(pos) {
|
|
36276
36336
|
return finishNode(factory.createNamespaceExport(parseIdentifierName()), pos);
|
|
@@ -38475,6 +38535,7 @@ var ts;
|
|
|
38475
38535
|
es6: ts.ModuleKind.ES2015,
|
|
38476
38536
|
es2015: ts.ModuleKind.ES2015,
|
|
38477
38537
|
es2020: ts.ModuleKind.ES2020,
|
|
38538
|
+
es2022: ts.ModuleKind.ES2022,
|
|
38478
38539
|
esnext: ts.ModuleKind.ESNext,
|
|
38479
38540
|
node12: ts.ModuleKind.Node12,
|
|
38480
38541
|
nodenext: ts.ModuleKind.NodeNext,
|
|
@@ -40182,6 +40243,44 @@ var ts;
|
|
|
40182
40243
|
}
|
|
40183
40244
|
return result;
|
|
40184
40245
|
}
|
|
40246
|
+
/**
|
|
40247
|
+
* Generate a list of the compiler options whose value is not the default.
|
|
40248
|
+
* @param options compilerOptions to be evaluated.
|
|
40249
|
+
/** @internal */
|
|
40250
|
+
function getCompilerOptionsDiffValue(options, newLine) {
|
|
40251
|
+
var compilerOptionsMap = getSerializedCompilerOption(options);
|
|
40252
|
+
return getOverwrittenDefaultOptions();
|
|
40253
|
+
function makePadding(paddingLength) {
|
|
40254
|
+
return Array(paddingLength + 1).join(" ");
|
|
40255
|
+
}
|
|
40256
|
+
function getOverwrittenDefaultOptions() {
|
|
40257
|
+
var result = [];
|
|
40258
|
+
var tab = makePadding(2);
|
|
40259
|
+
commandOptionsWithoutBuild.forEach(function (cmd) {
|
|
40260
|
+
if (!compilerOptionsMap.has(cmd.name)) {
|
|
40261
|
+
return;
|
|
40262
|
+
}
|
|
40263
|
+
var newValue = compilerOptionsMap.get(cmd.name);
|
|
40264
|
+
var defaultValue = getDefaultValueForOption(cmd);
|
|
40265
|
+
if (newValue !== defaultValue) {
|
|
40266
|
+
result.push("" + tab + cmd.name + ": " + newValue);
|
|
40267
|
+
}
|
|
40268
|
+
else if (ts.hasProperty(ts.defaultInitCompilerOptions, cmd.name)) {
|
|
40269
|
+
result.push("" + tab + cmd.name + ": " + defaultValue);
|
|
40270
|
+
}
|
|
40271
|
+
});
|
|
40272
|
+
return result.join(newLine) + newLine;
|
|
40273
|
+
}
|
|
40274
|
+
}
|
|
40275
|
+
ts.getCompilerOptionsDiffValue = getCompilerOptionsDiffValue;
|
|
40276
|
+
/**
|
|
40277
|
+
* Get the compiler options to be written into the tsconfig.json.
|
|
40278
|
+
* @param options commandlineOptions to be included in the compileOptions.
|
|
40279
|
+
*/
|
|
40280
|
+
function getSerializedCompilerOption(options) {
|
|
40281
|
+
var compilerOptions = ts.extend(options, ts.defaultInitCompilerOptions);
|
|
40282
|
+
return serializeCompilerOptions(compilerOptions);
|
|
40283
|
+
}
|
|
40185
40284
|
/**
|
|
40186
40285
|
* Generate tsconfig configuration when running command line "--init"
|
|
40187
40286
|
* @param options commandlineOptions to be generated into tsconfig.json
|
|
@@ -40189,28 +40288,8 @@ var ts;
|
|
|
40189
40288
|
*/
|
|
40190
40289
|
/* @internal */
|
|
40191
40290
|
function generateTSConfig(options, fileNames, newLine) {
|
|
40192
|
-
var
|
|
40193
|
-
var compilerOptionsMap = serializeCompilerOptions(compilerOptions);
|
|
40291
|
+
var compilerOptionsMap = getSerializedCompilerOption(options);
|
|
40194
40292
|
return writeConfigurations();
|
|
40195
|
-
function getDefaultValueForOption(option) {
|
|
40196
|
-
switch (option.type) {
|
|
40197
|
-
case "number":
|
|
40198
|
-
return 1;
|
|
40199
|
-
case "boolean":
|
|
40200
|
-
return true;
|
|
40201
|
-
case "string":
|
|
40202
|
-
return option.isFilePath ? "./" : "";
|
|
40203
|
-
case "list":
|
|
40204
|
-
return [];
|
|
40205
|
-
case "object":
|
|
40206
|
-
return {};
|
|
40207
|
-
default:
|
|
40208
|
-
var iterResult = option.type.keys().next();
|
|
40209
|
-
if (!iterResult.done)
|
|
40210
|
-
return iterResult.value;
|
|
40211
|
-
return ts.Debug.fail("Expected 'option.type' to have entries.");
|
|
40212
|
-
}
|
|
40213
|
-
}
|
|
40214
40293
|
function makePadding(paddingLength) {
|
|
40215
40294
|
return Array(paddingLength + 1).join(" ");
|
|
40216
40295
|
}
|
|
@@ -41197,6 +41276,25 @@ var ts;
|
|
|
41197
41276
|
}); // TODO: GH#18217
|
|
41198
41277
|
}
|
|
41199
41278
|
}
|
|
41279
|
+
function getDefaultValueForOption(option) {
|
|
41280
|
+
switch (option.type) {
|
|
41281
|
+
case "number":
|
|
41282
|
+
return 1;
|
|
41283
|
+
case "boolean":
|
|
41284
|
+
return true;
|
|
41285
|
+
case "string":
|
|
41286
|
+
return option.isFilePath ? "./" : "";
|
|
41287
|
+
case "list":
|
|
41288
|
+
return [];
|
|
41289
|
+
case "object":
|
|
41290
|
+
return {};
|
|
41291
|
+
default:
|
|
41292
|
+
var iterResult = option.type.keys().next();
|
|
41293
|
+
if (!iterResult.done)
|
|
41294
|
+
return iterResult.value;
|
|
41295
|
+
return ts.Debug.fail("Expected 'option.type' to have entries.");
|
|
41296
|
+
}
|
|
41297
|
+
}
|
|
41200
41298
|
})(ts || (ts = {}));
|
|
41201
41299
|
var ts;
|
|
41202
41300
|
(function (ts) {
|
|
@@ -46608,6 +46706,13 @@ var ts;
|
|
|
46608
46706
|
IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
|
|
46609
46707
|
IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
|
|
46610
46708
|
})(IntersectionState || (IntersectionState = {}));
|
|
46709
|
+
var RecursionFlags;
|
|
46710
|
+
(function (RecursionFlags) {
|
|
46711
|
+
RecursionFlags[RecursionFlags["None"] = 0] = "None";
|
|
46712
|
+
RecursionFlags[RecursionFlags["Source"] = 1] = "Source";
|
|
46713
|
+
RecursionFlags[RecursionFlags["Target"] = 2] = "Target";
|
|
46714
|
+
RecursionFlags[RecursionFlags["Both"] = 3] = "Both";
|
|
46715
|
+
})(RecursionFlags || (RecursionFlags = {}));
|
|
46611
46716
|
var MappedTypeModifiers;
|
|
46612
46717
|
(function (MappedTypeModifiers) {
|
|
46613
46718
|
MappedTypeModifiers[MappedTypeModifiers["IncludeReadonly"] = 1] = "IncludeReadonly";
|
|
@@ -46669,7 +46774,6 @@ var ts;
|
|
|
46669
46774
|
Capitalize: 2 /* Capitalize */,
|
|
46670
46775
|
Uncapitalize: 3 /* Uncapitalize */
|
|
46671
46776
|
}));
|
|
46672
|
-
var DEFAULT_TYPE_CHARS_LENGTH_TO_ADD_NEW_LINES = 30;
|
|
46673
46777
|
function SymbolLinks() {
|
|
46674
46778
|
}
|
|
46675
46779
|
function NodeLinks() {
|
|
@@ -47101,6 +47205,7 @@ var ts;
|
|
|
47101
47205
|
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias: getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
|
|
47102
47206
|
isDeclarationVisible: isDeclarationVisible,
|
|
47103
47207
|
isPropertyAccessible: isPropertyAccessible,
|
|
47208
|
+
getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
|
|
47104
47209
|
};
|
|
47105
47210
|
function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode) {
|
|
47106
47211
|
var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
|
|
@@ -47370,17 +47475,9 @@ var ts;
|
|
|
47370
47475
|
}
|
|
47371
47476
|
}
|
|
47372
47477
|
else {
|
|
47373
|
-
|
|
47374
|
-
|
|
47375
|
-
|
|
47376
|
-
var jsxPragma = file.pragmas.get("jsx");
|
|
47377
|
-
if (jsxPragma) {
|
|
47378
|
-
var chosenPragma = ts.isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
|
|
47379
|
-
file.localJsxFactory = ts.parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion);
|
|
47380
|
-
ts.visitNode(file.localJsxFactory, markAsSynthetic);
|
|
47381
|
-
if (file.localJsxFactory) {
|
|
47382
|
-
return file.localJsxNamespace = ts.getFirstIdentifier(file.localJsxFactory).escapedText;
|
|
47383
|
-
}
|
|
47478
|
+
var localJsxNamespace = getLocalJsxNamespace(file);
|
|
47479
|
+
if (localJsxNamespace) {
|
|
47480
|
+
return file.localJsxNamespace = localJsxNamespace;
|
|
47384
47481
|
}
|
|
47385
47482
|
}
|
|
47386
47483
|
}
|
|
@@ -47402,10 +47499,24 @@ var ts;
|
|
|
47402
47499
|
_jsxFactoryEntity = ts.factory.createQualifiedName(ts.factory.createIdentifier(ts.unescapeLeadingUnderscores(_jsxNamespace)), "createElement");
|
|
47403
47500
|
}
|
|
47404
47501
|
return _jsxNamespace;
|
|
47405
|
-
|
|
47406
|
-
|
|
47407
|
-
|
|
47502
|
+
}
|
|
47503
|
+
function getLocalJsxNamespace(file) {
|
|
47504
|
+
if (file.localJsxNamespace) {
|
|
47505
|
+
return file.localJsxNamespace;
|
|
47408
47506
|
}
|
|
47507
|
+
var jsxPragma = file.pragmas.get("jsx");
|
|
47508
|
+
if (jsxPragma) {
|
|
47509
|
+
var chosenPragma = ts.isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
|
|
47510
|
+
file.localJsxFactory = ts.parseIsolatedEntityName(chosenPragma.arguments.factory, languageVersion);
|
|
47511
|
+
ts.visitNode(file.localJsxFactory, markAsSynthetic);
|
|
47512
|
+
if (file.localJsxFactory) {
|
|
47513
|
+
return file.localJsxNamespace = ts.getFirstIdentifier(file.localJsxFactory).escapedText;
|
|
47514
|
+
}
|
|
47515
|
+
}
|
|
47516
|
+
}
|
|
47517
|
+
function markAsSynthetic(node) {
|
|
47518
|
+
ts.setTextRangePosEnd(node, -1, -1);
|
|
47519
|
+
return ts.visitEachChild(node, markAsSynthetic, ts.nullTransformationContext);
|
|
47409
47520
|
}
|
|
47410
47521
|
function getEmitResolver(sourceFile, cancellationToken) {
|
|
47411
47522
|
// Ensure we have all the type information in place for this file so that all the
|
|
@@ -48477,8 +48588,7 @@ var ts;
|
|
|
48477
48588
|
if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
|
|
48478
48589
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
|
|
48479
48590
|
if (typeOnlyDeclaration) {
|
|
48480
|
-
var
|
|
48481
|
-
var message = isExport
|
|
48591
|
+
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48482
48592
|
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48483
48593
|
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48484
48594
|
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
@@ -48489,7 +48599,7 @@ var ts;
|
|
|
48489
48599
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
|
|
48490
48600
|
if (!typeOnlyDeclaration)
|
|
48491
48601
|
return diagnostic;
|
|
48492
|
-
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration,
|
|
48602
|
+
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration, typeOnlyDeclaration.kind === 274 /* ExportSpecifier */ ? ts.Diagnostics._0_was_exported_here : ts.Diagnostics._0_was_imported_here, unescapedName));
|
|
48493
48603
|
}
|
|
48494
48604
|
function getIsDeferredContext(location, lastLocation) {
|
|
48495
48605
|
if (location.kind !== 213 /* ArrowFunction */ && location.kind !== 212 /* FunctionExpression */) {
|
|
@@ -48813,15 +48923,13 @@ var ts;
|
|
|
48813
48923
|
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node, resolved) {
|
|
48814
48924
|
if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly) {
|
|
48815
48925
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node));
|
|
48816
|
-
var isExport =
|
|
48926
|
+
var isExport = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
48817
48927
|
var message = isExport
|
|
48818
48928
|
? ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type
|
|
48819
48929
|
: ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type;
|
|
48820
48930
|
var relatedMessage = isExport
|
|
48821
48931
|
? ts.Diagnostics._0_was_exported_here
|
|
48822
48932
|
: ts.Diagnostics._0_was_imported_here;
|
|
48823
|
-
// Non-null assertion is safe because the optionality comes from ImportClause,
|
|
48824
|
-
// but if an ImportClause was the typeOnlyDeclaration, it had to have a `name`.
|
|
48825
48933
|
var name = ts.unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText);
|
|
48826
48934
|
ts.addRelatedInfo(error(node.moduleReference, message), ts.createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name));
|
|
48827
48935
|
}
|
|
@@ -48836,7 +48944,21 @@ var ts;
|
|
|
48836
48944
|
function isSyntacticDefault(node) {
|
|
48837
48945
|
return ((ts.isExportAssignment(node) && !node.isExportEquals) || ts.hasSyntacticModifier(node, 512 /* Default */) || ts.isExportSpecifier(node));
|
|
48838
48946
|
}
|
|
48839
|
-
function
|
|
48947
|
+
function getUsageModeForExpression(usage) {
|
|
48948
|
+
return ts.isStringLiteralLike(usage) ? ts.getModeForUsageLocation(ts.getSourceFileOfNode(usage), usage) : undefined;
|
|
48949
|
+
}
|
|
48950
|
+
function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
|
|
48951
|
+
return usageMode === ts.ModuleKind.ESNext && targetMode === ts.ModuleKind.CommonJS;
|
|
48952
|
+
}
|
|
48953
|
+
function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
|
|
48954
|
+
var usageMode = file && getUsageModeForExpression(usage);
|
|
48955
|
+
if (file && usageMode !== undefined) {
|
|
48956
|
+
var result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
|
|
48957
|
+
if (usageMode === ts.ModuleKind.ESNext || result) {
|
|
48958
|
+
return result;
|
|
48959
|
+
}
|
|
48960
|
+
// fallthrough on cjs usages so we imply defaults for interop'd imports, too
|
|
48961
|
+
}
|
|
48840
48962
|
if (!allowSyntheticDefaultImports) {
|
|
48841
48963
|
return false;
|
|
48842
48964
|
}
|
|
@@ -48878,7 +49000,7 @@ var ts;
|
|
|
48878
49000
|
exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* Default */, node, dontResolveAlias);
|
|
48879
49001
|
}
|
|
48880
49002
|
var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
48881
|
-
var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias);
|
|
49003
|
+
var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier);
|
|
48882
49004
|
if (!exportDefaultSymbol && !hasSyntheticDefault) {
|
|
48883
49005
|
if (hasExportAssignmentSymbol(moduleSymbol)) {
|
|
48884
49006
|
var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
|
|
@@ -49018,7 +49140,7 @@ var ts;
|
|
|
49018
49140
|
var symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
|
|
49019
49141
|
if (symbolFromModule === undefined && name.escapedText === "default" /* Default */) {
|
|
49020
49142
|
var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
49021
|
-
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias)) {
|
|
49143
|
+
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
|
|
49022
49144
|
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
|
|
49023
49145
|
}
|
|
49024
49146
|
}
|
|
@@ -49237,13 +49359,13 @@ var ts;
|
|
|
49237
49359
|
* and issue an error if so.
|
|
49238
49360
|
*
|
|
49239
49361
|
* @param aliasDeclaration The alias declaration not marked as type-only
|
|
49362
|
+
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49363
|
+
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49364
|
+
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49240
49365
|
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
|
|
49241
49366
|
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
|
|
49242
49367
|
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
|
|
49243
49368
|
* must still be checked for a type-only marker, overwriting the previous negative result if found.
|
|
49244
|
-
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49245
|
-
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49246
|
-
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49247
49369
|
*/
|
|
49248
49370
|
function markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration, immediateTarget, finalTarget, overwriteEmpty) {
|
|
49249
49371
|
if (!aliasDeclaration || ts.isPropertyAccessExpression(aliasDeclaration))
|
|
@@ -49709,7 +49831,7 @@ var ts;
|
|
|
49709
49831
|
sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
|
|
49710
49832
|
}
|
|
49711
49833
|
if (sigs && sigs.length) {
|
|
49712
|
-
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol);
|
|
49834
|
+
var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier);
|
|
49713
49835
|
// Create a new symbol which has the module's type less the call and construct signatures
|
|
49714
49836
|
var result = createSymbol(symbol.flags, symbol.escapedName);
|
|
49715
49837
|
result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
|
|
@@ -52376,7 +52498,7 @@ var ts;
|
|
|
52376
52498
|
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(
|
|
52377
52499
|
/*decorators*/ undefined,
|
|
52378
52500
|
/*modifiers*/ undefined,
|
|
52379
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*alias*/ undefined, id); })),
|
|
52501
|
+
/*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); })),
|
|
52380
52502
|
/*moduleSpecifier*/ undefined)], false))));
|
|
52381
52503
|
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, nsIndex), true), [ns], false), statements.slice(nsIndex + 1), true);
|
|
52382
52504
|
}
|
|
@@ -52604,7 +52726,7 @@ var ts;
|
|
|
52604
52726
|
addResult(ts.factory.createExportDeclaration(
|
|
52605
52727
|
/*decorators*/ undefined,
|
|
52606
52728
|
/*modifiers*/ undefined,
|
|
52607
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(alias, localName)])), 0 /* None */);
|
|
52729
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, alias, localName)])), 0 /* None */);
|
|
52608
52730
|
context.tracker.trackSymbol(type.symbol, context.enclosingDeclaration, 111551 /* Value */);
|
|
52609
52731
|
}
|
|
52610
52732
|
else {
|
|
@@ -52637,7 +52759,7 @@ var ts;
|
|
|
52637
52759
|
addResult(ts.factory.createExportDeclaration(
|
|
52638
52760
|
/*decorators*/ undefined,
|
|
52639
52761
|
/*modifiers*/ undefined,
|
|
52640
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(name, localName)])), 0 /* None */);
|
|
52762
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name, localName)])), 0 /* None */);
|
|
52641
52763
|
needsExportDeclaration = false;
|
|
52642
52764
|
needsPostExportDefault = false;
|
|
52643
52765
|
}
|
|
@@ -52695,7 +52817,7 @@ var ts;
|
|
|
52695
52817
|
addResult(ts.factory.createExportDeclaration(
|
|
52696
52818
|
/*decorators*/ undefined,
|
|
52697
52819
|
/*modifiers*/ undefined,
|
|
52698
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52820
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52699
52821
|
}
|
|
52700
52822
|
}
|
|
52701
52823
|
function includePrivateSymbol(symbol) {
|
|
@@ -52817,7 +52939,7 @@ var ts;
|
|
|
52817
52939
|
var target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true);
|
|
52818
52940
|
includePrivateSymbol(target || s);
|
|
52819
52941
|
var targetName = target ? getInternalSymbolName(target, ts.unescapeLeadingUnderscores(target.escapedName)) : localName;
|
|
52820
|
-
return ts.factory.createExportSpecifier(name === targetName ? undefined : targetName, name);
|
|
52942
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name === targetName ? undefined : targetName, name);
|
|
52821
52943
|
})))]);
|
|
52822
52944
|
addResult(ts.factory.createModuleDeclaration(
|
|
52823
52945
|
/*decorators*/ undefined,
|
|
@@ -52908,7 +53030,7 @@ var ts;
|
|
|
52908
53030
|
var defaultReplaced = ts.map(declarations, function (d) { return ts.isExportAssignment(d) && !d.isExportEquals && ts.isIdentifier(d.expression) ? ts.factory.createExportDeclaration(
|
|
52909
53031
|
/*decorators*/ undefined,
|
|
52910
53032
|
/*modifiers*/ undefined,
|
|
52911
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
53033
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52912
53034
|
var exportModifierStripped = ts.every(defaultReplaced, function (d) { return ts.hasSyntacticModifier(d, 1 /* Export */); }) ? ts.map(defaultReplaced, removeExportModifier) : defaultReplaced;
|
|
52913
53035
|
fakespace = ts.factory.updateModuleDeclaration(fakespace, fakespace.decorators, fakespace.modifiers, fakespace.name, ts.factory.createModuleBlock(exportModifierStripped));
|
|
52914
53036
|
addResult(fakespace, modifierFlags); // namespaces can never be default exported
|
|
@@ -53059,7 +53181,8 @@ var ts;
|
|
|
53059
53181
|
var propertyName = node.propertyName;
|
|
53060
53182
|
addResult(ts.factory.createImportDeclaration(
|
|
53061
53183
|
/*decorators*/ undefined,
|
|
53062
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
53184
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
53185
|
+
/*isTypeOnly*/ false, propertyName && ts.isIdentifier(propertyName) ? ts.factory.createIdentifier(ts.idText(propertyName)) : undefined, ts.factory.createIdentifier(localName))])), ts.factory.createStringLiteral(specifier_1),
|
|
53063
53186
|
/*importClause*/ undefined), 0 /* None */);
|
|
53064
53187
|
break;
|
|
53065
53188
|
}
|
|
@@ -53143,7 +53266,8 @@ var ts;
|
|
|
53143
53266
|
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
53144
53267
|
/*isTypeOnly*/ false,
|
|
53145
53268
|
/*importClause*/ undefined, ts.factory.createNamedImports([
|
|
53146
|
-
ts.factory.createImportSpecifier(
|
|
53269
|
+
ts.factory.createImportSpecifier(
|
|
53270
|
+
/*isTypeOnly*/ false, localName !== verbatimTargetName ? ts.factory.createIdentifier(verbatimTargetName) : undefined, ts.factory.createIdentifier(localName))
|
|
53147
53271
|
])), ts.factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)),
|
|
53148
53272
|
/*assertClause*/ undefined), 0 /* None */);
|
|
53149
53273
|
break;
|
|
@@ -53179,7 +53303,7 @@ var ts;
|
|
|
53179
53303
|
addResult(ts.factory.createExportDeclaration(
|
|
53180
53304
|
/*decorators*/ undefined,
|
|
53181
53305
|
/*modifiers*/ undefined,
|
|
53182
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53306
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53183
53307
|
}
|
|
53184
53308
|
/**
|
|
53185
53309
|
* Returns `true` if an export assignment or declaration was produced for the symbol
|
|
@@ -56674,6 +56798,23 @@ var ts;
|
|
|
56674
56798
|
function getIsLateCheckFlag(s) {
|
|
56675
56799
|
return ts.getCheckFlags(s) & 4096 /* Late */;
|
|
56676
56800
|
}
|
|
56801
|
+
function forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(type, include, stringsOnly, cb) {
|
|
56802
|
+
for (var _i = 0, _a = getPropertiesOfType(type); _i < _a.length; _i++) {
|
|
56803
|
+
var prop = _a[_i];
|
|
56804
|
+
cb(getLiteralTypeFromProperty(prop, include));
|
|
56805
|
+
}
|
|
56806
|
+
if (type.flags & 1 /* Any */) {
|
|
56807
|
+
cb(stringType);
|
|
56808
|
+
}
|
|
56809
|
+
else {
|
|
56810
|
+
for (var _b = 0, _c = getIndexInfosOfType(type); _b < _c.length; _b++) {
|
|
56811
|
+
var info = _c[_b];
|
|
56812
|
+
if (!stringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56813
|
+
cb(info.keyType);
|
|
56814
|
+
}
|
|
56815
|
+
}
|
|
56816
|
+
}
|
|
56817
|
+
}
|
|
56677
56818
|
/** Resolve the members of a mapped type { [P in K]: T } */
|
|
56678
56819
|
function resolveMappedTypeMembers(type) {
|
|
56679
56820
|
var members = ts.createSymbolTable();
|
|
@@ -56691,21 +56832,7 @@ var ts;
|
|
|
56691
56832
|
var include = keyofStringsOnly ? 128 /* StringLiteral */ : 8576 /* StringOrNumberLiteralOrUnique */;
|
|
56692
56833
|
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
56693
56834
|
// We have a { [P in keyof T]: X }
|
|
56694
|
-
|
|
56695
|
-
var prop = _a[_i];
|
|
56696
|
-
addMemberForKeyType(getLiteralTypeFromProperty(prop, include));
|
|
56697
|
-
}
|
|
56698
|
-
if (modifiersType.flags & 1 /* Any */) {
|
|
56699
|
-
addMemberForKeyType(stringType);
|
|
56700
|
-
}
|
|
56701
|
-
else {
|
|
56702
|
-
for (var _b = 0, _c = getIndexInfosOfType(modifiersType); _b < _c.length; _b++) {
|
|
56703
|
-
var info = _c[_b];
|
|
56704
|
-
if (!keyofStringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56705
|
-
addMemberForKeyType(info.keyType);
|
|
56706
|
-
}
|
|
56707
|
-
}
|
|
56708
|
-
}
|
|
56835
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
|
|
56709
56836
|
}
|
|
56710
56837
|
else {
|
|
56711
56838
|
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
@@ -57400,7 +57527,7 @@ var ts;
|
|
|
57400
57527
|
else if (type !== firstType) {
|
|
57401
57528
|
checkFlags |= 64 /* HasNonUniformType */;
|
|
57402
57529
|
}
|
|
57403
|
-
if (isLiteralType(type)) {
|
|
57530
|
+
if (isLiteralType(type) || isPatternLiteralType(type)) {
|
|
57404
57531
|
checkFlags |= 128 /* HasLiteralType */;
|
|
57405
57532
|
}
|
|
57406
57533
|
if (type.flags & 131072 /* Never */) {
|
|
@@ -59822,18 +59949,56 @@ var ts;
|
|
|
59822
59949
|
type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) :
|
|
59823
59950
|
type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false));
|
|
59824
59951
|
}
|
|
59825
|
-
|
|
59826
|
-
|
|
59827
|
-
|
|
59828
|
-
|
|
59829
|
-
|
|
59830
|
-
|
|
59831
|
-
|
|
59832
|
-
|
|
59833
|
-
var
|
|
59834
|
-
|
|
59835
|
-
|
|
59836
|
-
|
|
59952
|
+
/**
|
|
59953
|
+
* This roughly mirrors `resolveMappedTypeMembers` in the nongeneric case, except only reports a union of the keys calculated,
|
|
59954
|
+
* rather than manufacturing the properties. We can't just fetch the `constraintType` since that would ignore mappings
|
|
59955
|
+
* and mapping the `constraintType` directly ignores how mapped types map _properties_ and not keys (thus ignoring subtype
|
|
59956
|
+
* reduction in the constraintType) when possible.
|
|
59957
|
+
* @param noIndexSignatures Indicates if _string_ index signatures should be elided. (other index signatures are always reported)
|
|
59958
|
+
*/
|
|
59959
|
+
function getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) {
|
|
59960
|
+
var typeParameter = getTypeParameterFromMappedType(type);
|
|
59961
|
+
var constraintType = getConstraintTypeFromMappedType(type);
|
|
59962
|
+
var nameType = getNameTypeFromMappedType(type.target || type);
|
|
59963
|
+
if (!nameType && !noIndexSignatures) {
|
|
59964
|
+
// no mapping and no filtering required, just quickly bail to returning the constraint in the common case
|
|
59965
|
+
return constraintType;
|
|
59966
|
+
}
|
|
59967
|
+
var keyTypes = [];
|
|
59968
|
+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
59969
|
+
// We have a { [P in keyof T]: X }
|
|
59970
|
+
// `getApparentType` on the T in a generic mapped type can trigger a circularity
|
|
59971
|
+
// (conditionals and `infer` types create a circular dependency in the constraint resolution)
|
|
59972
|
+
// so we only eagerly manifest the keys if the constraint is nongeneric
|
|
59973
|
+
if (!isGenericIndexType(constraintType)) {
|
|
59974
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
|
|
59975
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */, stringsOnly, addMemberForKeyType);
|
|
59976
|
+
}
|
|
59977
|
+
else {
|
|
59978
|
+
// we have a generic index and a homomorphic mapping (but a distributive key remapping) - we need to defer the whole `keyof whatever` for later
|
|
59979
|
+
// since it's not safe to resolve the shape of modifier type
|
|
59980
|
+
return getIndexTypeForGenericType(type, stringsOnly);
|
|
59981
|
+
}
|
|
59982
|
+
}
|
|
59983
|
+
else {
|
|
59984
|
+
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
59985
|
+
}
|
|
59986
|
+
if (isGenericIndexType(constraintType)) { // include the generic component in the resulting type
|
|
59987
|
+
forEachType(constraintType, addMemberForKeyType);
|
|
59988
|
+
}
|
|
59989
|
+
// we had to pick apart the constraintType to potentially map/filter it - compare the final resulting list with the original constraintType,
|
|
59990
|
+
// so we can return the union that preserves aliases/origin data if possible
|
|
59991
|
+
var result = noIndexSignatures ? filterType(getUnionType(keyTypes), function (t) { return !(t.flags & (1 /* Any */ | 4 /* String */)); }) : getUnionType(keyTypes);
|
|
59992
|
+
if (result.flags & 1048576 /* Union */ && constraintType.flags & 1048576 /* Union */ && getTypeListId(result.types) === getTypeListId(constraintType.types)) {
|
|
59993
|
+
return constraintType;
|
|
59994
|
+
}
|
|
59995
|
+
return result;
|
|
59996
|
+
function addMemberForKeyType(keyType) {
|
|
59997
|
+
var propNameType = nameType ? instantiateType(nameType, appendTypeMapping(type.mapper, typeParameter, keyType)) : keyType;
|
|
59998
|
+
// `keyof` currently always returns `string | number` for concrete `string` index signatures - the below ternary keeps that behavior for mapped types
|
|
59999
|
+
// See `getLiteralTypeFromProperties` where there's a similar ternary to cause the same behavior.
|
|
60000
|
+
keyTypes.push(propNameType === stringType ? stringOrNumberType : propNameType);
|
|
60001
|
+
}
|
|
59837
60002
|
}
|
|
59838
60003
|
// 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
|
|
59839
60004
|
// 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
|
|
@@ -59891,7 +60056,7 @@ var ts;
|
|
|
59891
60056
|
return type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59892
60057
|
type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59893
60058
|
type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
|
|
59894
|
-
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, noIndexSignatures) :
|
|
60059
|
+
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
|
|
59895
60060
|
type === wildcardType ? wildcardType :
|
|
59896
60061
|
type.flags & 2 /* Unknown */ ? neverType :
|
|
59897
60062
|
type.flags & (1 /* Any */ | 131072 /* Never */) ? keyofConstraintType :
|
|
@@ -61756,7 +61921,7 @@ var ts;
|
|
|
61756
61921
|
return !node.typeParameters && !ts.getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== 234 /* Block */ && isContextSensitive(node.body);
|
|
61757
61922
|
}
|
|
61758
61923
|
function isContextSensitiveFunctionOrObjectLiteralMethod(func) {
|
|
61759
|
-
return (ts.isInJSFile(func) && ts.isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
|
|
61924
|
+
return (ts.isInJSFile(func) && ts.isFunctionDeclaration(func) || ts.isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) &&
|
|
61760
61925
|
isContextSensitiveFunctionLikeDeclaration(func);
|
|
61761
61926
|
}
|
|
61762
61927
|
function getTypeWithoutSignatures(type) {
|
|
@@ -62628,7 +62793,8 @@ var ts;
|
|
|
62628
62793
|
var sourceStack;
|
|
62629
62794
|
var targetStack;
|
|
62630
62795
|
var maybeCount = 0;
|
|
62631
|
-
var
|
|
62796
|
+
var sourceDepth = 0;
|
|
62797
|
+
var targetDepth = 0;
|
|
62632
62798
|
var expandingFlags = 0 /* None */;
|
|
62633
62799
|
var overflow = false;
|
|
62634
62800
|
var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
|
|
@@ -62636,12 +62802,12 @@ var ts;
|
|
|
62636
62802
|
var incompatibleStack = [];
|
|
62637
62803
|
var inPropertyCheck = false;
|
|
62638
62804
|
ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
|
|
62639
|
-
var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage);
|
|
62805
|
+
var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
|
|
62640
62806
|
if (incompatibleStack.length) {
|
|
62641
62807
|
reportIncompatibleStack();
|
|
62642
62808
|
}
|
|
62643
62809
|
if (overflow) {
|
|
62644
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "checkTypeRelatedTo_DepthLimit", { sourceId: source.id, targetId: target.id, depth:
|
|
62810
|
+
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 });
|
|
62645
62811
|
var diag = error(errorNode || currentNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
|
|
62646
62812
|
if (errorOutputContainer) {
|
|
62647
62813
|
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
|
|
@@ -62868,9 +63034,9 @@ var ts;
|
|
|
62868
63034
|
}
|
|
62869
63035
|
}
|
|
62870
63036
|
message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1;
|
|
62871
|
-
|
|
62872
|
-
|
|
62873
|
-
|
|
63037
|
+
var typeLengthLimit = 30;
|
|
63038
|
+
if (!errorInfo && compilerOptions.pretty && (sourceType.length > typeLengthLimit || targetType.length > typeLengthLimit)) {
|
|
63039
|
+
message = formatMessageForTypes(message, typeLengthLimit, sourceType, targetType);
|
|
62874
63040
|
}
|
|
62875
63041
|
}
|
|
62876
63042
|
}
|
|
@@ -62881,15 +63047,14 @@ var ts;
|
|
|
62881
63047
|
}
|
|
62882
63048
|
reportError(message, generalizedSourceType, targetType);
|
|
62883
63049
|
}
|
|
62884
|
-
|
|
62885
|
-
|
|
62886
|
-
|
|
62887
|
-
|
|
62888
|
-
|
|
62889
|
-
|
|
62890
|
-
|
|
62891
|
-
|
|
62892
|
-
.replace(".", "") });
|
|
63050
|
+
/** Move a printed type to be on its own line if it is longer than 30 characters */
|
|
63051
|
+
function formatMessageForTypes(diagnostic, typeLengthLimit, source, target) {
|
|
63052
|
+
var message = diagnostic.message;
|
|
63053
|
+
if (source.length > typeLengthLimit)
|
|
63054
|
+
message = message.replace(" '{0}' ", ":\n{0}\n\n");
|
|
63055
|
+
if (target.length > typeLengthLimit)
|
|
63056
|
+
message = message.replace(" '{1}'", ":\n{1}").replace(".", "");
|
|
63057
|
+
return __assign(__assign({}, diagnostic), { message: message });
|
|
62893
63058
|
}
|
|
62894
63059
|
function tryElaborateErrorsForPrimitivesAndObjects(source, target) {
|
|
62895
63060
|
var sourceType = symbolValueDeclarationIsContextSensitive(source.symbol) ? typeToString(source, source.symbol.valueDeclaration) : typeToString(source);
|
|
@@ -62935,13 +63100,17 @@ var ts;
|
|
|
62935
63100
|
}
|
|
62936
63101
|
return true;
|
|
62937
63102
|
}
|
|
63103
|
+
function isRelatedToWorker(source, target, reportErrors) {
|
|
63104
|
+
return isRelatedTo(source, target, 3 /* Both */, reportErrors);
|
|
63105
|
+
}
|
|
62938
63106
|
/**
|
|
62939
63107
|
* Compare two types and return
|
|
62940
63108
|
* * Ternary.True if they are related with no assumptions,
|
|
62941
63109
|
* * Ternary.Maybe if they are related with assumptions of other relationships, or
|
|
62942
63110
|
* * Ternary.False if they are not related.
|
|
62943
63111
|
*/
|
|
62944
|
-
function isRelatedTo(originalSource, originalTarget, reportErrors, headMessage, intersectionState) {
|
|
63112
|
+
function isRelatedTo(originalSource, originalTarget, recursionFlags, reportErrors, headMessage, intersectionState) {
|
|
63113
|
+
if (recursionFlags === void 0) { recursionFlags = 3 /* Both */; }
|
|
62945
63114
|
if (reportErrors === void 0) { reportErrors = false; }
|
|
62946
63115
|
if (intersectionState === void 0) { intersectionState = 0 /* None */; }
|
|
62947
63116
|
// Before normalization: if `source` is type an object type, and `target` is primitive,
|
|
@@ -62962,7 +63131,7 @@ var ts;
|
|
|
62962
63131
|
if (source === target)
|
|
62963
63132
|
return -1 /* True */;
|
|
62964
63133
|
if (relation === identityRelation) {
|
|
62965
|
-
return isIdenticalTo(source, target);
|
|
63134
|
+
return isIdenticalTo(source, target, recursionFlags);
|
|
62966
63135
|
}
|
|
62967
63136
|
// We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
|
|
62968
63137
|
// and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
|
|
@@ -63013,8 +63182,8 @@ var ts;
|
|
|
63013
63182
|
var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
|
|
63014
63183
|
var calls = getSignaturesOfType(source, 0 /* Call */);
|
|
63015
63184
|
var constructs = getSignaturesOfType(source, 1 /* Construct */);
|
|
63016
|
-
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, /*reportErrors*/ false) ||
|
|
63017
|
-
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, /*reportErrors*/ false)) {
|
|
63185
|
+
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
|
|
63186
|
+
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
|
|
63018
63187
|
reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
|
|
63019
63188
|
}
|
|
63020
63189
|
else {
|
|
@@ -63031,11 +63200,11 @@ var ts;
|
|
|
63031
63200
|
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
|
63032
63201
|
if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
|
|
63033
63202
|
result = getConstituentCount(source) * getConstituentCount(target) >= 4 ?
|
|
63034
|
-
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck
|
|
63203
|
+
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags) :
|
|
63035
63204
|
structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
|
|
63036
63205
|
}
|
|
63037
63206
|
if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
|
|
63038
|
-
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState)) {
|
|
63207
|
+
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
|
|
63039
63208
|
resetErrorInfo(saveErrorInfo);
|
|
63040
63209
|
}
|
|
63041
63210
|
}
|
|
@@ -63057,7 +63226,7 @@ var ts;
|
|
|
63057
63226
|
if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
|
|
63058
63227
|
if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
63059
63228
|
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
63060
|
-
if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63229
|
+
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63061
63230
|
resetErrorInfo(saveErrorInfo);
|
|
63062
63231
|
}
|
|
63063
63232
|
}
|
|
@@ -63081,7 +63250,7 @@ var ts;
|
|
|
63081
63250
|
if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
63082
63251
|
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 */); }))) {
|
|
63083
63252
|
inPropertyCheck = true;
|
|
63084
|
-
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck
|
|
63253
|
+
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
63085
63254
|
inPropertyCheck = false;
|
|
63086
63255
|
}
|
|
63087
63256
|
reportErrorResults(source, target, result, isComparingJsxAttributes);
|
|
@@ -63156,7 +63325,7 @@ var ts;
|
|
|
63156
63325
|
}
|
|
63157
63326
|
}
|
|
63158
63327
|
}
|
|
63159
|
-
function isIdenticalTo(source, target) {
|
|
63328
|
+
function isIdenticalTo(source, target, recursionFlags) {
|
|
63160
63329
|
if (source.flags !== target.flags)
|
|
63161
63330
|
return 0 /* False */;
|
|
63162
63331
|
if (source.flags & 67358815 /* Singleton */)
|
|
@@ -63169,7 +63338,7 @@ var ts;
|
|
|
63169
63338
|
}
|
|
63170
63339
|
return result_7;
|
|
63171
63340
|
}
|
|
63172
|
-
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None
|
|
63341
|
+
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
63173
63342
|
}
|
|
63174
63343
|
function getTypeOfPropertyInTypes(types, name) {
|
|
63175
63344
|
var appendPropType = function (propTypes, type) {
|
|
@@ -63250,7 +63419,7 @@ var ts;
|
|
|
63250
63419
|
}
|
|
63251
63420
|
return { value: true };
|
|
63252
63421
|
}
|
|
63253
|
-
if (checkTypes && !isRelatedTo(getTypeOfSymbol(prop), getTypeOfPropertyInTypes(checkTypes, prop.escapedName), reportErrors)) {
|
|
63422
|
+
if (checkTypes && !isRelatedTo(getTypeOfSymbol(prop), getTypeOfPropertyInTypes(checkTypes, prop.escapedName), 3 /* Both */, reportErrors)) {
|
|
63254
63423
|
if (reportErrors) {
|
|
63255
63424
|
reportIncompatibleError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(prop));
|
|
63256
63425
|
}
|
|
@@ -63290,7 +63459,7 @@ var ts;
|
|
|
63290
63459
|
}
|
|
63291
63460
|
var match = getMatchingUnionConstituentForType(target, source);
|
|
63292
63461
|
if (match) {
|
|
63293
|
-
var related = isRelatedTo(source, match, /*reportErrors*/ false);
|
|
63462
|
+
var related = isRelatedTo(source, match, 2 /* Target */, /*reportErrors*/ false);
|
|
63294
63463
|
if (related) {
|
|
63295
63464
|
return related;
|
|
63296
63465
|
}
|
|
@@ -63298,14 +63467,14 @@ var ts;
|
|
|
63298
63467
|
}
|
|
63299
63468
|
for (var _i = 0, targetTypes_1 = targetTypes; _i < targetTypes_1.length; _i++) {
|
|
63300
63469
|
var type = targetTypes_1[_i];
|
|
63301
|
-
var related = isRelatedTo(source, type, /*reportErrors*/ false);
|
|
63470
|
+
var related = isRelatedTo(source, type, 2 /* Target */, /*reportErrors*/ false);
|
|
63302
63471
|
if (related) {
|
|
63303
63472
|
return related;
|
|
63304
63473
|
}
|
|
63305
63474
|
}
|
|
63306
63475
|
if (reportErrors) {
|
|
63307
63476
|
var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
|
|
63308
|
-
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
|
|
63477
|
+
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
|
|
63309
63478
|
}
|
|
63310
63479
|
return 0 /* False */;
|
|
63311
63480
|
}
|
|
@@ -63314,7 +63483,7 @@ var ts;
|
|
|
63314
63483
|
var targetTypes = target.types;
|
|
63315
63484
|
for (var _i = 0, targetTypes_2 = targetTypes; _i < targetTypes_2.length; _i++) {
|
|
63316
63485
|
var targetType = targetTypes_2[_i];
|
|
63317
|
-
var related = isRelatedTo(source, targetType, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63486
|
+
var related = isRelatedTo(source, targetType, 2 /* Target */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63318
63487
|
if (!related) {
|
|
63319
63488
|
return 0 /* False */;
|
|
63320
63489
|
}
|
|
@@ -63329,7 +63498,7 @@ var ts;
|
|
|
63329
63498
|
}
|
|
63330
63499
|
var len = sourceTypes.length;
|
|
63331
63500
|
for (var i = 0; i < len; i++) {
|
|
63332
|
-
var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1, /*headMessage*/ undefined, intersectionState);
|
|
63501
|
+
var related = isRelatedTo(sourceTypes[i], target, 1 /* Source */, reportErrors && i === len - 1, /*headMessage*/ undefined, intersectionState);
|
|
63333
63502
|
if (related) {
|
|
63334
63503
|
return related;
|
|
63335
63504
|
}
|
|
@@ -63359,13 +63528,13 @@ var ts;
|
|
|
63359
63528
|
// union has a union of objects intersected with it. In such cases, if the input was, eg `("a" | "b" | "c") & (string | boolean | {} | {whatever})`,
|
|
63360
63529
|
// the result will have the structure `"a" | "b" | "c" | "a" & {} | "b" & {} | "c" & {} | "a" & {whatever} | "b" & {whatever} | "c" & {whatever}`
|
|
63361
63530
|
// - 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
|
|
63362
|
-
var related_1 = isRelatedTo(sourceType, undefinedStrippedTarget.types[i % undefinedStrippedTarget.types.length], /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
|
|
63531
|
+
var related_1 = isRelatedTo(sourceType, undefinedStrippedTarget.types[i % undefinedStrippedTarget.types.length], 3 /* Both */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
|
|
63363
63532
|
if (related_1) {
|
|
63364
63533
|
result &= related_1;
|
|
63365
63534
|
continue;
|
|
63366
63535
|
}
|
|
63367
63536
|
}
|
|
63368
|
-
var related = isRelatedTo(sourceType, target, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63537
|
+
var related = isRelatedTo(sourceType, target, 1 /* Source */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63369
63538
|
if (!related) {
|
|
63370
63539
|
return 0 /* False */;
|
|
63371
63540
|
}
|
|
@@ -63397,31 +63566,31 @@ var ts;
|
|
|
63397
63566
|
// Even an `Unmeasurable` variance works out without a structural check if the source and target are _identical_.
|
|
63398
63567
|
// We can't simply assume invariance, because `Unmeasurable` marks nonlinear relations, for example, a relation tained by
|
|
63399
63568
|
// the `-?` modifier in a mapped type (where, no matter how the inputs are related, the outputs still might not be)
|
|
63400
|
-
related = relation === identityRelation ? isRelatedTo(s, t, /*reportErrors*/ false) : compareTypesIdentical(s, t);
|
|
63569
|
+
related = relation === identityRelation ? isRelatedTo(s, t, 3 /* Both */, /*reportErrors*/ false) : compareTypesIdentical(s, t);
|
|
63401
63570
|
}
|
|
63402
63571
|
else if (variance === 1 /* Covariant */) {
|
|
63403
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63572
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63404
63573
|
}
|
|
63405
63574
|
else if (variance === 2 /* Contravariant */) {
|
|
63406
|
-
related = isRelatedTo(t, s, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63575
|
+
related = isRelatedTo(t, s, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63407
63576
|
}
|
|
63408
63577
|
else if (variance === 3 /* Bivariant */) {
|
|
63409
63578
|
// In the bivariant case we first compare contravariantly without reporting
|
|
63410
63579
|
// errors. Then, if that doesn't succeed, we compare covariantly with error
|
|
63411
63580
|
// reporting. Thus, error elaboration will be based on the the covariant check,
|
|
63412
63581
|
// which is generally easier to reason about.
|
|
63413
|
-
related = isRelatedTo(t, s, /*reportErrors*/ false);
|
|
63582
|
+
related = isRelatedTo(t, s, 3 /* Both */, /*reportErrors*/ false);
|
|
63414
63583
|
if (!related) {
|
|
63415
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63584
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63416
63585
|
}
|
|
63417
63586
|
}
|
|
63418
63587
|
else {
|
|
63419
63588
|
// In the invariant case we first compare covariantly, and only when that
|
|
63420
63589
|
// succeeds do we proceed to compare contravariantly. Thus, error elaboration
|
|
63421
63590
|
// will typically be based on the covariant check.
|
|
63422
|
-
related = isRelatedTo(s, t, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63591
|
+
related = isRelatedTo(s, t, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63423
63592
|
if (related) {
|
|
63424
|
-
related &= isRelatedTo(t, s, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63593
|
+
related &= isRelatedTo(t, s, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
63425
63594
|
}
|
|
63426
63595
|
}
|
|
63427
63596
|
if (!related) {
|
|
@@ -63437,7 +63606,7 @@ var ts;
|
|
|
63437
63606
|
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
|
|
63438
63607
|
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
|
|
63439
63608
|
// and issue an error. Otherwise, actually compare the structure of the two types.
|
|
63440
|
-
function recursiveTypeRelatedTo(source, target, reportErrors, intersectionState) {
|
|
63609
|
+
function recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags) {
|
|
63441
63610
|
if (overflow) {
|
|
63442
63611
|
return 0 /* False */;
|
|
63443
63612
|
}
|
|
@@ -63481,7 +63650,7 @@ var ts;
|
|
|
63481
63650
|
return 3 /* Maybe */;
|
|
63482
63651
|
}
|
|
63483
63652
|
}
|
|
63484
|
-
if (
|
|
63653
|
+
if (sourceDepth === 100 || targetDepth === 100) {
|
|
63485
63654
|
overflow = true;
|
|
63486
63655
|
return 0 /* False */;
|
|
63487
63656
|
}
|
|
@@ -63489,13 +63658,18 @@ var ts;
|
|
|
63489
63658
|
var maybeStart = maybeCount;
|
|
63490
63659
|
maybeKeys[maybeCount] = id;
|
|
63491
63660
|
maybeCount++;
|
|
63492
|
-
|
|
63493
|
-
|
|
63494
|
-
|
|
63661
|
+
if (recursionFlags & 1 /* Source */) {
|
|
63662
|
+
sourceStack[sourceDepth] = source;
|
|
63663
|
+
sourceDepth++;
|
|
63664
|
+
}
|
|
63665
|
+
if (recursionFlags & 2 /* Target */) {
|
|
63666
|
+
targetStack[targetDepth] = target;
|
|
63667
|
+
targetDepth++;
|
|
63668
|
+
}
|
|
63495
63669
|
var saveExpandingFlags = expandingFlags;
|
|
63496
|
-
if (!(expandingFlags & 1 /* Source */) && isDeeplyNestedType(source, sourceStack,
|
|
63670
|
+
if (!(expandingFlags & 1 /* Source */) && isDeeplyNestedType(source, sourceStack, sourceDepth))
|
|
63497
63671
|
expandingFlags |= 1 /* Source */;
|
|
63498
|
-
if (!(expandingFlags & 2 /* Target */) && isDeeplyNestedType(target, targetStack,
|
|
63672
|
+
if (!(expandingFlags & 2 /* Target */) && isDeeplyNestedType(target, targetStack, targetDepth))
|
|
63499
63673
|
expandingFlags |= 2 /* Target */;
|
|
63500
63674
|
var originalHandler;
|
|
63501
63675
|
var propagatingVarianceFlags = 0;
|
|
@@ -63512,7 +63686,8 @@ var ts;
|
|
|
63512
63686
|
sourceIdStack: sourceStack.map(function (t) { return t.id; }),
|
|
63513
63687
|
targetId: target.id,
|
|
63514
63688
|
targetIdStack: targetStack.map(function (t) { return t.id; }),
|
|
63515
|
-
depth:
|
|
63689
|
+
depth: sourceDepth,
|
|
63690
|
+
targetDepth: targetDepth
|
|
63516
63691
|
});
|
|
63517
63692
|
}
|
|
63518
63693
|
var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
|
|
@@ -63520,9 +63695,14 @@ var ts;
|
|
|
63520
63695
|
outofbandVarianceMarkerHandler = originalHandler;
|
|
63521
63696
|
}
|
|
63522
63697
|
expandingFlags = saveExpandingFlags;
|
|
63523
|
-
|
|
63698
|
+
if (recursionFlags & 1 /* Source */) {
|
|
63699
|
+
sourceDepth--;
|
|
63700
|
+
}
|
|
63701
|
+
if (recursionFlags & 2 /* Target */) {
|
|
63702
|
+
targetDepth--;
|
|
63703
|
+
}
|
|
63524
63704
|
if (result) {
|
|
63525
|
-
if (result === -1 /* True */ ||
|
|
63705
|
+
if (result === -1 /* True */ || (sourceDepth === 0 && targetDepth === 0)) {
|
|
63526
63706
|
if (result === -1 /* True */ || result === 3 /* Maybe */) {
|
|
63527
63707
|
// If result is definitely true, record all maybe keys as having succeeded. Also, record Ternary.Maybe
|
|
63528
63708
|
// results as having succeeded once we reach depth 0, but never record Ternary.Unknown results.
|
|
@@ -63576,7 +63756,7 @@ var ts;
|
|
|
63576
63756
|
if (constraints !== source.types) {
|
|
63577
63757
|
source = getIntersectionType(constraints);
|
|
63578
63758
|
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
63579
|
-
return isRelatedTo(source, target, /*reportErrors*/ false);
|
|
63759
|
+
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
63580
63760
|
}
|
|
63581
63761
|
}
|
|
63582
63762
|
}
|
|
@@ -63598,22 +63778,22 @@ var ts;
|
|
|
63598
63778
|
var flags = source.flags & target.flags;
|
|
63599
63779
|
if (relation === identityRelation && !(flags & 524288 /* Object */)) {
|
|
63600
63780
|
if (flags & 4194304 /* Index */) {
|
|
63601
|
-
return isRelatedTo(source.type, target.type, /*reportErrors*/ false);
|
|
63781
|
+
return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
|
|
63602
63782
|
}
|
|
63603
63783
|
var result_8 = 0 /* False */;
|
|
63604
63784
|
if (flags & 8388608 /* IndexedAccess */) {
|
|
63605
|
-
if (result_8 = isRelatedTo(source.objectType, target.objectType, /*reportErrors*/ false)) {
|
|
63606
|
-
if (result_8 &= isRelatedTo(source.indexType, target.indexType, /*reportErrors*/ false)) {
|
|
63785
|
+
if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63786
|
+
if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63607
63787
|
return result_8;
|
|
63608
63788
|
}
|
|
63609
63789
|
}
|
|
63610
63790
|
}
|
|
63611
63791
|
if (flags & 16777216 /* Conditional */) {
|
|
63612
63792
|
if (source.root.isDistributive === target.root.isDistributive) {
|
|
63613
|
-
if (result_8 = isRelatedTo(source.checkType, target.checkType, /*reportErrors*/ false)) {
|
|
63614
|
-
if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, /*reportErrors*/ false)) {
|
|
63615
|
-
if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), /*reportErrors*/ false)) {
|
|
63616
|
-
if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), /*reportErrors*/ false)) {
|
|
63793
|
+
if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63794
|
+
if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63795
|
+
if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
63796
|
+
if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
63617
63797
|
return result_8;
|
|
63618
63798
|
}
|
|
63619
63799
|
}
|
|
@@ -63622,7 +63802,7 @@ var ts;
|
|
|
63622
63802
|
}
|
|
63623
63803
|
}
|
|
63624
63804
|
if (flags & 33554432 /* Substitution */) {
|
|
63625
|
-
return isRelatedTo(source.substitute, target.substitute, /*reportErrors*/ false);
|
|
63805
|
+
return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
|
|
63626
63806
|
}
|
|
63627
63807
|
return 0 /* False */;
|
|
63628
63808
|
}
|
|
@@ -63647,47 +63827,71 @@ var ts;
|
|
|
63647
63827
|
}
|
|
63648
63828
|
// 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],
|
|
63649
63829
|
// and U is assignable to [...T] when U is constrained to a mutable array or tuple type.
|
|
63650
|
-
if (isSingleElementGenericTupleType(source) && !source.target.readonly && (result = isRelatedTo(getTypeArguments(source)[0], target)) ||
|
|
63651
|
-
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0]))) {
|
|
63830
|
+
if (isSingleElementGenericTupleType(source) && !source.target.readonly && (result = isRelatedTo(getTypeArguments(source)[0], target, 1 /* Source */)) ||
|
|
63831
|
+
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
|
|
63652
63832
|
return result;
|
|
63653
63833
|
}
|
|
63654
63834
|
if (target.flags & 262144 /* TypeParameter */) {
|
|
63655
63835
|
// 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].
|
|
63656
|
-
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source))) {
|
|
63836
|
+
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
|
|
63657
63837
|
if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
|
|
63658
63838
|
var templateType = getTemplateTypeFromMappedType(source);
|
|
63659
63839
|
var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source));
|
|
63660
|
-
if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) {
|
|
63840
|
+
if (result = isRelatedTo(templateType, indexedAccessType, 3 /* Both */, reportErrors)) {
|
|
63661
63841
|
return result;
|
|
63662
63842
|
}
|
|
63663
63843
|
}
|
|
63664
63844
|
}
|
|
63665
63845
|
}
|
|
63666
63846
|
else if (target.flags & 4194304 /* Index */) {
|
|
63667
|
-
var
|
|
63847
|
+
var targetType_1 = target.type;
|
|
63668
63848
|
// A keyof S is related to a keyof T if T is related to S.
|
|
63669
63849
|
if (source.flags & 4194304 /* Index */) {
|
|
63670
|
-
if (result = isRelatedTo(
|
|
63850
|
+
if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
|
|
63671
63851
|
return result;
|
|
63672
63852
|
}
|
|
63673
63853
|
}
|
|
63674
|
-
if (isTupleType(
|
|
63854
|
+
if (isTupleType(targetType_1)) {
|
|
63675
63855
|
// An index type can have a tuple type target when the tuple type contains variadic elements.
|
|
63676
63856
|
// Check if the source is related to the known keys of the tuple type.
|
|
63677
|
-
if (result = isRelatedTo(source, getKnownKeysOfTupleType(
|
|
63857
|
+
if (result = isRelatedTo(source, getKnownKeysOfTupleType(targetType_1), 2 /* Target */, reportErrors)) {
|
|
63678
63858
|
return result;
|
|
63679
63859
|
}
|
|
63680
63860
|
}
|
|
63681
63861
|
else {
|
|
63682
63862
|
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
|
|
63683
63863
|
// simplified form of T or, if T doesn't simplify, the constraint of T.
|
|
63684
|
-
var constraint = getSimplifiedTypeOrConstraint(
|
|
63864
|
+
var constraint = getSimplifiedTypeOrConstraint(targetType_1);
|
|
63685
63865
|
if (constraint) {
|
|
63686
63866
|
// We require Ternary.True here such that circular constraints don't cause
|
|
63687
63867
|
// false positives. For example, given 'T extends { [K in keyof T]: string }',
|
|
63688
63868
|
// 'keyof T' has itself as its constraint and produces a Ternary.Maybe when
|
|
63689
63869
|
// related to other types.
|
|
63690
|
-
if (isRelatedTo(source, getIndexType(constraint, target.stringsOnly), reportErrors) === -1 /* True */) {
|
|
63870
|
+
if (isRelatedTo(source, getIndexType(constraint, target.stringsOnly), 2 /* Target */, reportErrors) === -1 /* True */) {
|
|
63871
|
+
return -1 /* True */;
|
|
63872
|
+
}
|
|
63873
|
+
}
|
|
63874
|
+
else if (isGenericMappedType(targetType_1)) {
|
|
63875
|
+
// generic mapped types that don't simplify or have a constraint still have a very simple set of keys we can compare against
|
|
63876
|
+
// - their nameType or constraintType.
|
|
63877
|
+
// In many ways, this comparison is a deferred version of what `getIndexTypeForMappedType` does to actually resolve the keys for _non_-generic types
|
|
63878
|
+
var nameType_1 = getNameTypeFromMappedType(targetType_1);
|
|
63879
|
+
var constraintType = getConstraintTypeFromMappedType(targetType_1);
|
|
63880
|
+
var targetKeys = void 0;
|
|
63881
|
+
if (nameType_1 && isMappedTypeWithKeyofConstraintDeclaration(targetType_1)) {
|
|
63882
|
+
// we need to get the apparent mappings and union them with the generic mappings, since some properties may be
|
|
63883
|
+
// missing from the `constraintType` which will otherwise be mapped in the object
|
|
63884
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType_1));
|
|
63885
|
+
var mappedKeys_1 = [];
|
|
63886
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */,
|
|
63887
|
+
/*stringsOnly*/ false, function (t) { return void mappedKeys_1.push(instantiateType(nameType_1, appendTypeMapping(targetType_1.mapper, getTypeParameterFromMappedType(targetType_1), t))); });
|
|
63888
|
+
// 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)
|
|
63889
|
+
targetKeys = getUnionType(__spreadArray(__spreadArray([], mappedKeys_1, true), [nameType_1], false));
|
|
63890
|
+
}
|
|
63891
|
+
else {
|
|
63892
|
+
targetKeys = nameType_1 || constraintType;
|
|
63893
|
+
}
|
|
63894
|
+
if (isRelatedTo(source, targetKeys, 2 /* Target */, reportErrors) === -1 /* True */) {
|
|
63691
63895
|
return -1 /* True */;
|
|
63692
63896
|
}
|
|
63693
63897
|
}
|
|
@@ -63697,8 +63901,8 @@ var ts;
|
|
|
63697
63901
|
if (source.flags & 8388608 /* IndexedAccess */) {
|
|
63698
63902
|
// Relate components directly before falling back to constraint relationships
|
|
63699
63903
|
// A type S[K] is related to a type T[J] if S is related to T and K is related to J.
|
|
63700
|
-
if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) {
|
|
63701
|
-
result &= isRelatedTo(source.indexType, target.indexType, reportErrors);
|
|
63904
|
+
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
|
|
63905
|
+
result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, reportErrors);
|
|
63702
63906
|
}
|
|
63703
63907
|
if (result) {
|
|
63704
63908
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -63723,7 +63927,7 @@ var ts;
|
|
|
63723
63927
|
// create a new chain for the constraint error
|
|
63724
63928
|
resetErrorInfo(saveErrorInfo);
|
|
63725
63929
|
}
|
|
63726
|
-
if (result = isRelatedTo(source, constraint, reportErrors)) {
|
|
63930
|
+
if (result = isRelatedTo(source, constraint, 2 /* Target */, reportErrors)) {
|
|
63727
63931
|
return result;
|
|
63728
63932
|
}
|
|
63729
63933
|
// prefer the shorter chain of the constraint comparison chain, and the direct comparison chain
|
|
@@ -63763,13 +63967,14 @@ var ts;
|
|
|
63763
63967
|
// 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`.
|
|
63764
63968
|
if (includeOptional
|
|
63765
63969
|
? !(filteredByApplicability.flags & 131072 /* Never */)
|
|
63766
|
-
: isRelatedTo(targetKeys, sourceKeys)) {
|
|
63970
|
+
: isRelatedTo(targetKeys, sourceKeys, 3 /* Both */)) {
|
|
63971
|
+
var templateType_1 = getTemplateTypeFromMappedType(target);
|
|
63767
63972
|
var typeParameter = getTypeParameterFromMappedType(target);
|
|
63768
63973
|
// Fastpath: When the template type has the form `Obj[P]` where `P` is the mapped type parameter, directly compare source `S` with `Obj`
|
|
63769
63974
|
// to avoid creating the (potentially very large) number of new intermediate types made by manufacturing `S[P]`.
|
|
63770
|
-
var nonNullComponent = extractTypesOfKind(
|
|
63975
|
+
var nonNullComponent = extractTypesOfKind(templateType_1, ~98304 /* Nullable */);
|
|
63771
63976
|
if (!keysRemapped && nonNullComponent.flags & 8388608 /* IndexedAccess */ && nonNullComponent.indexType === typeParameter) {
|
|
63772
|
-
if (result = isRelatedTo(source, nonNullComponent.objectType, reportErrors)) {
|
|
63977
|
+
if (result = isRelatedTo(source, nonNullComponent.objectType, 2 /* Target */, reportErrors)) {
|
|
63773
63978
|
return result;
|
|
63774
63979
|
}
|
|
63775
63980
|
}
|
|
@@ -63789,7 +63994,7 @@ var ts;
|
|
|
63789
63994
|
: typeParameter;
|
|
63790
63995
|
var indexedAccessType = getIndexedAccessType(source, indexingType);
|
|
63791
63996
|
// Compare `S[indexingType]` to `T`, where `T` is the type of a property of the target type.
|
|
63792
|
-
if (result = isRelatedTo(indexedAccessType,
|
|
63997
|
+
if (result = isRelatedTo(indexedAccessType, templateType_1, 3 /* Both */, reportErrors)) {
|
|
63793
63998
|
return result;
|
|
63794
63999
|
}
|
|
63795
64000
|
}
|
|
@@ -63816,10 +64021,11 @@ var ts;
|
|
|
63816
64021
|
newParam.mapper = distributionMapper;
|
|
63817
64022
|
}
|
|
63818
64023
|
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
|
|
63819
|
-
var
|
|
63820
|
-
|
|
63821
|
-
|
|
63822
|
-
|
|
64024
|
+
var expanding = isDeeplyNestedType(target, targetStack, targetDepth);
|
|
64025
|
+
var localResult = expanding ? 3 /* Maybe */ : undefined;
|
|
64026
|
+
if (skipTrue || expanding || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.trueType), distributionMapper) : getTrueTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false))) {
|
|
64027
|
+
if (!skipFalse && !expanding) {
|
|
64028
|
+
localResult = (localResult || 3 /* Maybe */) & isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.falseType), distributionMapper) : getFalseTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false);
|
|
63823
64029
|
}
|
|
63824
64030
|
}
|
|
63825
64031
|
if (localResult) {
|
|
@@ -63829,6 +64035,9 @@ var ts;
|
|
|
63829
64035
|
}
|
|
63830
64036
|
else if (target.flags & 134217728 /* TemplateLiteral */) {
|
|
63831
64037
|
if (source.flags & 134217728 /* TemplateLiteral */) {
|
|
64038
|
+
if (relation === comparableRelation) {
|
|
64039
|
+
return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
|
|
64040
|
+
}
|
|
63832
64041
|
// Report unreliable variance for type variables referenced in template literal type placeholders.
|
|
63833
64042
|
// For example, `foo-${number}` is related to `foo-${string}` even though number isn't related to string.
|
|
63834
64043
|
instantiateType(source, makeFunctionTypeMapper(reportUnreliableMarkers));
|
|
@@ -63844,34 +64053,33 @@ var ts;
|
|
|
63844
64053
|
var constraint = getConstraintOfType(source);
|
|
63845
64054
|
if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
63846
64055
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
63847
|
-
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */))) {
|
|
64056
|
+
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
63848
64057
|
resetErrorInfo(saveErrorInfo);
|
|
63849
64058
|
return result;
|
|
63850
64059
|
}
|
|
63851
64060
|
}
|
|
63852
64061
|
// 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
|
|
63853
|
-
else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
64062
|
+
else if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63854
64063
|
resetErrorInfo(saveErrorInfo);
|
|
63855
64064
|
return result;
|
|
63856
64065
|
}
|
|
63857
64066
|
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
|
|
63858
|
-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
64067
|
+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
63859
64068
|
resetErrorInfo(saveErrorInfo);
|
|
63860
64069
|
return result;
|
|
63861
64070
|
}
|
|
63862
64071
|
}
|
|
63863
64072
|
}
|
|
63864
64073
|
else if (source.flags & 4194304 /* Index */) {
|
|
63865
|
-
if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) {
|
|
64074
|
+
if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
|
|
63866
64075
|
resetErrorInfo(saveErrorInfo);
|
|
63867
64076
|
return result;
|
|
63868
64077
|
}
|
|
63869
64078
|
}
|
|
63870
|
-
else if (source.flags & 134217728 /* TemplateLiteral */) {
|
|
64079
|
+
else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
|
|
63871
64080
|
if (!(target.flags & 134217728 /* TemplateLiteral */)) {
|
|
63872
|
-
var
|
|
63873
|
-
|
|
63874
|
-
if (result = isRelatedTo(constraint, target, reportErrors)) {
|
|
64081
|
+
var constraint = getBaseConstraintOfType(source);
|
|
64082
|
+
if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
63875
64083
|
resetErrorInfo(saveErrorInfo);
|
|
63876
64084
|
return result;
|
|
63877
64085
|
}
|
|
@@ -63879,14 +64087,14 @@ var ts;
|
|
|
63879
64087
|
}
|
|
63880
64088
|
else if (source.flags & 268435456 /* StringMapping */) {
|
|
63881
64089
|
if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
|
|
63882
|
-
if (result = isRelatedTo(source.type, target.type, reportErrors)) {
|
|
64090
|
+
if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
|
|
63883
64091
|
resetErrorInfo(saveErrorInfo);
|
|
63884
64092
|
return result;
|
|
63885
64093
|
}
|
|
63886
64094
|
}
|
|
63887
64095
|
else {
|
|
63888
64096
|
var constraint = getBaseConstraintOfType(source);
|
|
63889
|
-
if (constraint && (result = isRelatedTo(constraint, target, reportErrors))) {
|
|
64097
|
+
if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
63890
64098
|
resetErrorInfo(saveErrorInfo);
|
|
63891
64099
|
return result;
|
|
63892
64100
|
}
|
|
@@ -63894,27 +64102,32 @@ var ts;
|
|
|
63894
64102
|
}
|
|
63895
64103
|
else if (source.flags & 16777216 /* Conditional */) {
|
|
63896
64104
|
if (target.flags & 16777216 /* Conditional */) {
|
|
63897
|
-
//
|
|
63898
|
-
//
|
|
63899
|
-
//
|
|
63900
|
-
|
|
63901
|
-
|
|
63902
|
-
|
|
63903
|
-
|
|
63904
|
-
|
|
63905
|
-
var
|
|
63906
|
-
|
|
63907
|
-
|
|
63908
|
-
|
|
63909
|
-
|
|
63910
|
-
|
|
63911
|
-
|
|
63912
|
-
|
|
63913
|
-
|
|
63914
|
-
|
|
63915
|
-
|
|
63916
|
-
|
|
63917
|
-
|
|
64105
|
+
// If one of the conditionals under comparison seems to be infinitely expanding, stop comparing it - back out, try
|
|
64106
|
+
// the constraint, and failing that, give up trying to relate the two. This is the only way we can handle recursive conditional
|
|
64107
|
+
// types, which might expand forever.
|
|
64108
|
+
if (!isDeeplyNestedType(source, sourceStack, sourceDepth) && !isDeeplyNestedType(target, targetStack, targetDepth)) {
|
|
64109
|
+
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
|
|
64110
|
+
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
|
|
64111
|
+
// and Y1 is related to Y2.
|
|
64112
|
+
var sourceParams = source.root.inferTypeParameters;
|
|
64113
|
+
var sourceExtends = source.extendsType;
|
|
64114
|
+
var mapper = void 0;
|
|
64115
|
+
if (sourceParams) {
|
|
64116
|
+
// If the source has infer type parameters, we instantiate them in the context of the target
|
|
64117
|
+
var ctx = createInferenceContext(sourceParams, /*signature*/ undefined, 0 /* None */, isRelatedToWorker);
|
|
64118
|
+
inferTypes(ctx.inferences, target.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
64119
|
+
sourceExtends = instantiateType(sourceExtends, ctx.mapper);
|
|
64120
|
+
mapper = ctx.mapper;
|
|
64121
|
+
}
|
|
64122
|
+
if (isTypeIdenticalTo(sourceExtends, target.extendsType) &&
|
|
64123
|
+
(isRelatedTo(source.checkType, target.checkType, 3 /* Both */) || isRelatedTo(target.checkType, source.checkType, 3 /* Both */))) {
|
|
64124
|
+
if (result = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(source), mapper), getTrueTypeFromConditionalType(target), 3 /* Both */, reportErrors)) {
|
|
64125
|
+
result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, reportErrors);
|
|
64126
|
+
}
|
|
64127
|
+
if (result) {
|
|
64128
|
+
resetErrorInfo(saveErrorInfo);
|
|
64129
|
+
return result;
|
|
64130
|
+
}
|
|
63918
64131
|
}
|
|
63919
64132
|
}
|
|
63920
64133
|
}
|
|
@@ -63923,19 +64136,23 @@ var ts;
|
|
|
63923
64136
|
// more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
|
|
63924
64137
|
var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
|
|
63925
64138
|
if (distributiveConstraint) {
|
|
63926
|
-
if (result = isRelatedTo(distributiveConstraint, target, reportErrors)) {
|
|
64139
|
+
if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
|
|
63927
64140
|
resetErrorInfo(saveErrorInfo);
|
|
63928
64141
|
return result;
|
|
63929
64142
|
}
|
|
63930
64143
|
}
|
|
63931
64144
|
}
|
|
63932
|
-
//
|
|
63933
|
-
//
|
|
63934
|
-
|
|
63935
|
-
|
|
63936
|
-
|
|
63937
|
-
|
|
63938
|
-
|
|
64145
|
+
// 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
|
|
64146
|
+
// on the comparison.
|
|
64147
|
+
if (!isDeeplyNestedType(source, sourceStack, sourceDepth)) {
|
|
64148
|
+
// conditionals _can_ be related to one another via normal constraint, as, eg, `A extends B ? O : never` should be assignable to `O`
|
|
64149
|
+
// when `O` is a conditional (`never` is trivially assignable to `O`, as is `O`!).
|
|
64150
|
+
var defaultConstraint = getDefaultConstraintOfConditionalType(source);
|
|
64151
|
+
if (defaultConstraint) {
|
|
64152
|
+
if (result = isRelatedTo(defaultConstraint, target, 1 /* Source */, reportErrors)) {
|
|
64153
|
+
resetErrorInfo(saveErrorInfo);
|
|
64154
|
+
return result;
|
|
64155
|
+
}
|
|
63939
64156
|
}
|
|
63940
64157
|
}
|
|
63941
64158
|
}
|
|
@@ -63979,7 +64196,7 @@ var ts;
|
|
|
63979
64196
|
}
|
|
63980
64197
|
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
|
|
63981
64198
|
if (relation !== identityRelation) {
|
|
63982
|
-
return isRelatedTo(getIndexTypeOfType(source, numberType) || anyType, getIndexTypeOfType(target, numberType) || anyType, reportErrors);
|
|
64199
|
+
return isRelatedTo(getIndexTypeOfType(source, numberType) || anyType, getIndexTypeOfType(target, numberType) || anyType, 3 /* Both */, reportErrors);
|
|
63983
64200
|
}
|
|
63984
64201
|
else {
|
|
63985
64202
|
// By flags alone, we know that the `target` is a readonly array while the source is a normal array or tuple
|
|
@@ -64101,10 +64318,10 @@ var ts;
|
|
|
64101
64318
|
var result_11;
|
|
64102
64319
|
var targetConstraint = getConstraintTypeFromMappedType(target);
|
|
64103
64320
|
var sourceConstraint = instantiateType(getConstraintTypeFromMappedType(source), makeFunctionTypeMapper(getCombinedMappedTypeOptionality(source) < 0 ? reportUnmeasurableMarkers : reportUnreliableMarkers));
|
|
64104
|
-
if (result_11 = isRelatedTo(targetConstraint, sourceConstraint, reportErrors)) {
|
|
64321
|
+
if (result_11 = isRelatedTo(targetConstraint, sourceConstraint, 3 /* Both */, reportErrors)) {
|
|
64105
64322
|
var mapper = createTypeMapper([getTypeParameterFromMappedType(source)], [getTypeParameterFromMappedType(target)]);
|
|
64106
64323
|
if (instantiateType(getNameTypeFromMappedType(source), mapper) === instantiateType(getNameTypeFromMappedType(target), mapper)) {
|
|
64107
|
-
return result_11 & isRelatedTo(instantiateType(getTemplateTypeFromMappedType(source), mapper), getTemplateTypeFromMappedType(target), reportErrors);
|
|
64324
|
+
return result_11 & isRelatedTo(instantiateType(getTemplateTypeFromMappedType(source), mapper), getTemplateTypeFromMappedType(target), 3 /* Both */, reportErrors);
|
|
64108
64325
|
}
|
|
64109
64326
|
}
|
|
64110
64327
|
}
|
|
@@ -64236,7 +64453,7 @@ var ts;
|
|
|
64236
64453
|
var targetIsOptional = strictNullChecks && !!(ts.getCheckFlags(targetProp) & 48 /* Partial */);
|
|
64237
64454
|
var effectiveTarget = addOptionality(getNonMissingTypeOfSymbol(targetProp), /*isProperty*/ false, targetIsOptional);
|
|
64238
64455
|
var effectiveSource = getTypeOfSourceProperty(sourceProp);
|
|
64239
|
-
return isRelatedTo(effectiveSource, effectiveTarget, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64456
|
+
return isRelatedTo(effectiveSource, effectiveTarget, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64240
64457
|
}
|
|
64241
64458
|
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
|
|
64242
64459
|
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
|
|
@@ -64418,7 +64635,7 @@ var ts;
|
|
|
64418
64635
|
var targetType = targetTypeArguments[i];
|
|
64419
64636
|
var targetCheckType = sourceFlags & 8 /* Variadic */ && targetFlags & 4 /* Rest */ ? createArrayType(targetType) :
|
|
64420
64637
|
removeMissingType(targetType, !!(targetFlags & 2 /* Optional */));
|
|
64421
|
-
var related = isRelatedTo(sourceType, targetCheckType, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64638
|
+
var related = isRelatedTo(sourceType, targetCheckType, 3 /* Both */, reportErrors, /*headMessage*/ undefined, intersectionState);
|
|
64422
64639
|
if (!related) {
|
|
64423
64640
|
if (reportErrors && (targetArity > 1 || sourceArity > 1)) {
|
|
64424
64641
|
if (i < startCount || i >= targetArity - endCount || sourceArity - startCount - endCount === 1) {
|
|
@@ -64612,7 +64829,7 @@ var ts;
|
|
|
64612
64829
|
* See signatureAssignableTo, compareSignaturesIdentical
|
|
64613
64830
|
*/
|
|
64614
64831
|
function signatureRelatedTo(source, target, erase, reportErrors, incompatibleReporter) {
|
|
64615
|
-
return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, relation === strictSubtypeRelation ? 8 /* StrictArity */ : 0, reportErrors, reportError, incompatibleReporter,
|
|
64832
|
+
return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, relation === strictSubtypeRelation ? 8 /* StrictArity */ : 0, reportErrors, reportError, incompatibleReporter, isRelatedToWorker, makeFunctionTypeMapper(reportUnreliableMarkers));
|
|
64616
64833
|
}
|
|
64617
64834
|
function signaturesIdenticalTo(source, target, kind) {
|
|
64618
64835
|
var sourceSignatures = getSignaturesOfType(source, kind);
|
|
@@ -64645,7 +64862,7 @@ var ts;
|
|
|
64645
64862
|
var type = exactOptionalPropertyTypes || propType.flags & 32768 /* Undefined */ || keyType === numberType || !(prop.flags & 16777216 /* Optional */)
|
|
64646
64863
|
? propType
|
|
64647
64864
|
: getTypeWithFacts(propType, 524288 /* NEUndefined */);
|
|
64648
|
-
var related = isRelatedTo(type, targetInfo.type, reportErrors);
|
|
64865
|
+
var related = isRelatedTo(type, targetInfo.type, 3 /* Both */, reportErrors);
|
|
64649
64866
|
if (!related) {
|
|
64650
64867
|
if (reportErrors) {
|
|
64651
64868
|
reportError(ts.Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
|
|
@@ -64668,7 +64885,7 @@ var ts;
|
|
|
64668
64885
|
return result;
|
|
64669
64886
|
}
|
|
64670
64887
|
function indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors) {
|
|
64671
|
-
var related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors);
|
|
64888
|
+
var related = isRelatedTo(sourceInfo.type, targetInfo.type, 3 /* Both */, reportErrors);
|
|
64672
64889
|
if (!related && reportErrors) {
|
|
64673
64890
|
if (sourceInfo.keyType === targetInfo.keyType) {
|
|
64674
64891
|
reportError(ts.Diagnostics._0_index_signatures_are_incompatible, typeToString(sourceInfo.keyType));
|
|
@@ -64689,7 +64906,7 @@ var ts;
|
|
|
64689
64906
|
for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
|
|
64690
64907
|
var targetInfo = indexInfos_3[_i];
|
|
64691
64908
|
var related = !sourceIsPrimitive && targetHasStringIndex && targetInfo.type.flags & 1 /* Any */ ? -1 /* True */ :
|
|
64692
|
-
isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, reportErrors) :
|
|
64909
|
+
isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, 3 /* Both */, reportErrors) :
|
|
64693
64910
|
typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
|
|
64694
64911
|
if (!related) {
|
|
64695
64912
|
return 0 /* False */;
|
|
@@ -64721,7 +64938,7 @@ var ts;
|
|
|
64721
64938
|
for (var _i = 0, targetInfos_1 = targetInfos; _i < targetInfos_1.length; _i++) {
|
|
64722
64939
|
var targetInfo = targetInfos_1[_i];
|
|
64723
64940
|
var sourceInfo = getIndexInfoOfType(source, targetInfo.keyType);
|
|
64724
|
-
if (!(sourceInfo && isRelatedTo(sourceInfo.type, targetInfo.type) && sourceInfo.isReadonly === targetInfo.isReadonly)) {
|
|
64941
|
+
if (!(sourceInfo && isRelatedTo(sourceInfo.type, targetInfo.type, 3 /* Both */) && sourceInfo.isReadonly === targetInfo.isReadonly)) {
|
|
64725
64942
|
return 0 /* False */;
|
|
64726
64943
|
}
|
|
64727
64944
|
}
|
|
@@ -66135,6 +66352,17 @@ var ts;
|
|
|
66135
66352
|
function isFromInferenceBlockedSource(type) {
|
|
66136
66353
|
return !!(type.symbol && ts.some(type.symbol.declarations, hasSkipDirectInferenceFlag));
|
|
66137
66354
|
}
|
|
66355
|
+
function templateLiteralTypesDefinitelyUnrelated(source, target) {
|
|
66356
|
+
// Two template literal types with diffences in their starting or ending text spans are definitely unrelated.
|
|
66357
|
+
var sourceStart = source.texts[0];
|
|
66358
|
+
var targetStart = target.texts[0];
|
|
66359
|
+
var sourceEnd = source.texts[source.texts.length - 1];
|
|
66360
|
+
var targetEnd = target.texts[target.texts.length - 1];
|
|
66361
|
+
var startLen = Math.min(sourceStart.length, targetStart.length);
|
|
66362
|
+
var endLen = Math.min(sourceEnd.length, targetEnd.length);
|
|
66363
|
+
return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
|
|
66364
|
+
sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
|
|
66365
|
+
}
|
|
66138
66366
|
function isValidBigIntString(s) {
|
|
66139
66367
|
var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
|
|
66140
66368
|
var success = true;
|
|
@@ -67197,7 +67425,7 @@ var ts;
|
|
|
67197
67425
|
if (prop.isDiscriminantProperty === undefined) {
|
|
67198
67426
|
prop.isDiscriminantProperty =
|
|
67199
67427
|
(prop.checkFlags & 192 /* Discriminant */) === 192 /* Discriminant */ &&
|
|
67200
|
-
!
|
|
67428
|
+
!isGenericType(getTypeOfSymbol(prop));
|
|
67201
67429
|
}
|
|
67202
67430
|
return !!prop.isDiscriminantProperty;
|
|
67203
67431
|
}
|
|
@@ -67716,17 +67944,19 @@ var ts;
|
|
|
67716
67944
|
function extractTypesOfKind(type, kind) {
|
|
67717
67945
|
return filterType(type, function (t) { return (t.flags & kind) !== 0; });
|
|
67718
67946
|
}
|
|
67719
|
-
// Return a new type in which occurrences of the string and
|
|
67720
|
-
// typeWithPrimitives have been replaced with occurrences of
|
|
67721
|
-
//
|
|
67947
|
+
// Return a new type in which occurrences of the string, number and bigint primitives and placeholder template
|
|
67948
|
+
// literal types in typeWithPrimitives have been replaced with occurrences of compatible and more specific types
|
|
67949
|
+
// from typeWithLiterals. This is essentially a limited form of intersection between the two types. We avoid a
|
|
67950
|
+
// true intersection because it is more costly and, when applied to union types, generates a large number of
|
|
67951
|
+
// types we don't actually care about.
|
|
67722
67952
|
function replacePrimitivesWithLiterals(typeWithPrimitives, typeWithLiterals) {
|
|
67723
|
-
if (
|
|
67724
|
-
|
|
67725
|
-
isTypeSubsetOf(bigintType, typeWithPrimitives) && maybeTypeOfKind(typeWithLiterals, 2048 /* BigIntLiteral */)) {
|
|
67953
|
+
if (maybeTypeOfKind(typeWithPrimitives, 4 /* String */ | 134217728 /* TemplateLiteral */ | 8 /* Number */ | 64 /* BigInt */) &&
|
|
67954
|
+
maybeTypeOfKind(typeWithLiterals, 128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */ | 256 /* NumberLiteral */ | 2048 /* BigIntLiteral */)) {
|
|
67726
67955
|
return mapType(typeWithPrimitives, function (t) {
|
|
67727
|
-
return t.flags & 4 /* String */ ? extractTypesOfKind(typeWithLiterals, 4 /* String */ | 128 /* StringLiteral */) :
|
|
67728
|
-
t
|
|
67729
|
-
t.flags &
|
|
67956
|
+
return t.flags & 4 /* String */ ? extractTypesOfKind(typeWithLiterals, 4 /* String */ | 128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) :
|
|
67957
|
+
isPatternLiteralType(t) && !maybeTypeOfKind(typeWithLiterals, 4 /* String */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ? extractTypesOfKind(typeWithLiterals, 128 /* StringLiteral */) :
|
|
67958
|
+
t.flags & 8 /* Number */ ? extractTypesOfKind(typeWithLiterals, 8 /* Number */ | 256 /* NumberLiteral */) :
|
|
67959
|
+
t.flags & 64 /* BigInt */ ? extractTypesOfKind(typeWithLiterals, 64 /* BigInt */ | 2048 /* BigIntLiteral */) : t;
|
|
67730
67960
|
});
|
|
67731
67961
|
}
|
|
67732
67962
|
return typeWithPrimitives;
|
|
@@ -67807,10 +68037,10 @@ var ts;
|
|
|
67807
68037
|
isTypeAssignableToKind(getTypeOfExpression(parent.argumentExpression), 296 /* NumberLike */);
|
|
67808
68038
|
return isLengthPushOrUnshift || isElementAssignment;
|
|
67809
68039
|
}
|
|
67810
|
-
function isDeclarationWithExplicitTypeAnnotation(
|
|
67811
|
-
return (
|
|
67812
|
-
|
|
67813
|
-
|
|
68040
|
+
function isDeclarationWithExplicitTypeAnnotation(node) {
|
|
68041
|
+
return (ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)) &&
|
|
68042
|
+
!!(ts.getEffectiveTypeAnnotationNode(node) ||
|
|
68043
|
+
ts.isInJSFile(node) && ts.hasInitializer(node) && node.initializer && ts.isFunctionExpressionOrArrowFunction(node.initializer) && ts.getEffectiveReturnTypeNode(node.initializer));
|
|
67814
68044
|
}
|
|
67815
68045
|
function getExplicitTypeOfSymbol(symbol, diagnostic) {
|
|
67816
68046
|
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 512 /* ValueModule */)) {
|
|
@@ -68527,7 +68757,7 @@ var ts;
|
|
|
68527
68757
|
var narrowedPropType = narrowType(propType);
|
|
68528
68758
|
return filterType(type, function (t) {
|
|
68529
68759
|
var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
|
|
68530
|
-
return !(
|
|
68760
|
+
return !(narrowedPropType.flags & 131072 /* Never */) && isTypeComparableTo(narrowedPropType, discriminantType);
|
|
68531
68761
|
});
|
|
68532
68762
|
}
|
|
68533
68763
|
function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) {
|
|
@@ -68996,16 +69226,7 @@ var ts;
|
|
|
68996
69226
|
}
|
|
68997
69227
|
function getNarrowedType(type, candidate, assumeTrue, isRelated) {
|
|
68998
69228
|
if (!assumeTrue) {
|
|
68999
|
-
return filterType(type, function (t) {
|
|
69000
|
-
if (!isRelated(t, candidate)) {
|
|
69001
|
-
return true;
|
|
69002
|
-
}
|
|
69003
|
-
var constraint = getBaseConstraintOfType(t);
|
|
69004
|
-
if (constraint && constraint !== t) {
|
|
69005
|
-
return !isRelated(constraint, candidate);
|
|
69006
|
-
}
|
|
69007
|
-
return false;
|
|
69008
|
-
});
|
|
69229
|
+
return filterType(type, function (t) { return !isRelated(t, candidate); });
|
|
69009
69230
|
}
|
|
69010
69231
|
// If the current type is a union type, remove all constituents that couldn't be instances of
|
|
69011
69232
|
// the candidate type. If one or more constituents remain, return a union of those.
|
|
@@ -70447,9 +70668,9 @@ var ts;
|
|
|
70447
70668
|
return getTypeOfPropertyOfContextualType(type, getSymbolOfNode(element).escapedName);
|
|
70448
70669
|
}
|
|
70449
70670
|
if (element.name) {
|
|
70450
|
-
var
|
|
70671
|
+
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
70451
70672
|
// We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction.
|
|
70452
|
-
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t),
|
|
70673
|
+
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType_2)) === null || _a === void 0 ? void 0 : _a.type; }, /*noReductions*/ true);
|
|
70453
70674
|
}
|
|
70454
70675
|
}
|
|
70455
70676
|
return undefined;
|
|
@@ -70907,12 +71128,9 @@ var ts;
|
|
|
70907
71128
|
}
|
|
70908
71129
|
return !hasEffectiveRestParameter(signature) && getParameterCount(signature) < targetParameterCount;
|
|
70909
71130
|
}
|
|
70910
|
-
function isFunctionExpressionOrArrowFunction(node) {
|
|
70911
|
-
return node.kind === 212 /* FunctionExpression */ || node.kind === 213 /* ArrowFunction */;
|
|
70912
|
-
}
|
|
70913
71131
|
function getContextualSignatureForFunctionLikeDeclaration(node) {
|
|
70914
71132
|
// Only function expressions, arrow functions, and object literal methods are contextually typed.
|
|
70915
|
-
return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
|
|
71133
|
+
return ts.isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
|
|
70916
71134
|
? getContextualSignature(node)
|
|
70917
71135
|
: undefined;
|
|
70918
71136
|
}
|
|
@@ -71879,6 +72097,14 @@ var ts;
|
|
|
71879
72097
|
markAliasSymbolAsReferenced(jsxFactorySym);
|
|
71880
72098
|
}
|
|
71881
72099
|
}
|
|
72100
|
+
// For JsxFragment, mark jsx pragma as referenced via resolveName
|
|
72101
|
+
if (ts.isJsxOpeningFragment(node)) {
|
|
72102
|
+
var file = ts.getSourceFileOfNode(node);
|
|
72103
|
+
var localJsxNamespace = getLocalJsxNamespace(file);
|
|
72104
|
+
if (localJsxNamespace) {
|
|
72105
|
+
resolveName(jsxFactoryLocation, localJsxNamespace, 111551 /* Value */, jsxFactoryRefErr, localJsxNamespace, /*isUse*/ true);
|
|
72106
|
+
}
|
|
72107
|
+
}
|
|
71882
72108
|
}
|
|
71883
72109
|
if (isNodeOpeningLikeElement) {
|
|
71884
72110
|
var jsxOpeningLikeNode = node;
|
|
@@ -73551,7 +73777,7 @@ var ts;
|
|
|
73551
73777
|
return false;
|
|
73552
73778
|
var symbol = resolveName(node.expression, node.expression.escapedText, 111551 /* Value */, undefined, undefined, false);
|
|
73553
73779
|
var decl = symbol === null || symbol === void 0 ? void 0 : symbol.valueDeclaration;
|
|
73554
|
-
if (!decl || !ts.isParameter(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !ts.isNewExpression(decl.parent.parent) || !ts.isIdentifier(decl.parent.parent.expression)) {
|
|
73780
|
+
if (!decl || !ts.isParameter(decl) || !ts.isFunctionExpressionOrArrowFunction(decl.parent) || !ts.isNewExpression(decl.parent.parent) || !ts.isIdentifier(decl.parent.parent.expression)) {
|
|
73555
73781
|
return false;
|
|
73556
73782
|
}
|
|
73557
73783
|
var globalPromiseSymbol = getGlobalPromiseConstructorSymbol(/*reportErrors*/ false);
|
|
@@ -74795,18 +75021,18 @@ var ts;
|
|
|
74795
75021
|
if (moduleSymbol) {
|
|
74796
75022
|
var esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false);
|
|
74797
75023
|
if (esModuleSymbol) {
|
|
74798
|
-
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol));
|
|
75024
|
+
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
|
|
74799
75025
|
}
|
|
74800
75026
|
}
|
|
74801
75027
|
return createPromiseReturnType(node, anyType);
|
|
74802
75028
|
}
|
|
74803
|
-
function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol) {
|
|
75029
|
+
function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol, moduleSpecifier) {
|
|
74804
75030
|
var _a;
|
|
74805
75031
|
if (allowSyntheticDefaultImports && type && !isErrorType(type)) {
|
|
74806
75032
|
var synthType = type;
|
|
74807
75033
|
if (!synthType.syntheticType) {
|
|
74808
75034
|
var file = (_a = originalSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
|
|
74809
|
-
var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false);
|
|
75035
|
+
var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false, moduleSpecifier);
|
|
74810
75036
|
if (hasSyntheticDefault) {
|
|
74811
75037
|
var memberTable = ts.createSymbolTable();
|
|
74812
75038
|
var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
|
|
@@ -74968,16 +75194,14 @@ var ts;
|
|
|
74968
75194
|
}
|
|
74969
75195
|
}
|
|
74970
75196
|
function checkImportMetaProperty(node) {
|
|
74971
|
-
if (moduleKind
|
|
74972
|
-
if (
|
|
74973
|
-
|
|
74974
|
-
error(node, ts.Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
|
|
74975
|
-
}
|
|
74976
|
-
}
|
|
74977
|
-
else {
|
|
74978
|
-
error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_system_node12_or_nodenext);
|
|
75197
|
+
if (moduleKind === ts.ModuleKind.Node12 || moduleKind === ts.ModuleKind.NodeNext) {
|
|
75198
|
+
if (ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.ESNext) {
|
|
75199
|
+
error(node, ts.Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
|
|
74979
75200
|
}
|
|
74980
75201
|
}
|
|
75202
|
+
else if (moduleKind < ts.ModuleKind.ES2020 && moduleKind !== ts.ModuleKind.System) {
|
|
75203
|
+
error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
|
|
75204
|
+
}
|
|
74981
75205
|
var file = ts.getSourceFileOfNode(node);
|
|
74982
75206
|
ts.Debug.assert(!!(file.flags & 2097152 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
|
|
74983
75207
|
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
|
|
@@ -75920,9 +76144,9 @@ var ts;
|
|
|
75920
76144
|
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);
|
|
75921
76145
|
diagnostics.add(diagnostic);
|
|
75922
76146
|
}
|
|
75923
|
-
if ((moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
76147
|
+
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 */) {
|
|
75924
76148
|
span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
|
|
75925
|
-
var diagnostic = ts.createFileDiagnostic(sourceFile, span.start, span.length, ts.Diagnostics.
|
|
76149
|
+
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);
|
|
75926
76150
|
diagnostics.add(diagnostic);
|
|
75927
76151
|
}
|
|
75928
76152
|
}
|
|
@@ -77360,7 +77584,7 @@ var ts;
|
|
|
77360
77584
|
}
|
|
77361
77585
|
}
|
|
77362
77586
|
function checkParenthesizedExpression(node, checkMode) {
|
|
77363
|
-
if (ts.isJSDocTypeAssertion(node)) {
|
|
77587
|
+
if (ts.hasJSDocNodes(node) && ts.isJSDocTypeAssertion(node)) {
|
|
77364
77588
|
var type = ts.getJSDocTypeAssertionType(node);
|
|
77365
77589
|
return checkAssertionWorker(type, type, node.expression, checkMode);
|
|
77366
77590
|
}
|
|
@@ -79257,6 +79481,12 @@ var ts;
|
|
|
79257
79481
|
}
|
|
79258
79482
|
}
|
|
79259
79483
|
}
|
|
79484
|
+
function checkJSDocAccessibilityModifiers(node) {
|
|
79485
|
+
var host = ts.getJSDocHost(node);
|
|
79486
|
+
if (host && ts.isPrivateIdentifierClassElementDeclaration(host)) {
|
|
79487
|
+
error(node, ts.Diagnostics.An_accessibility_modifier_cannot_be_used_with_a_private_identifier);
|
|
79488
|
+
}
|
|
79489
|
+
}
|
|
79260
79490
|
function getIdentifierFromEntityNameExpression(node) {
|
|
79261
79491
|
switch (node.kind) {
|
|
79262
79492
|
case 79 /* Identifier */:
|
|
@@ -82592,11 +82822,15 @@ var ts;
|
|
|
82592
82822
|
}
|
|
82593
82823
|
function checkGrammarExportDeclaration(node) {
|
|
82594
82824
|
var _a;
|
|
82595
|
-
|
|
82596
|
-
|
|
82597
|
-
|
|
82825
|
+
if (node.isTypeOnly) {
|
|
82826
|
+
if (((_a = node.exportClause) === null || _a === void 0 ? void 0 : _a.kind) === 272 /* NamedExports */) {
|
|
82827
|
+
return checkGrammarNamedImportsOrExports(node.exportClause);
|
|
82828
|
+
}
|
|
82829
|
+
else {
|
|
82830
|
+
return grammarErrorOnNode(node, ts.Diagnostics.Only_named_exports_may_use_export_type);
|
|
82831
|
+
}
|
|
82598
82832
|
}
|
|
82599
|
-
return
|
|
82833
|
+
return false;
|
|
82600
82834
|
}
|
|
82601
82835
|
function checkGrammarModuleElementContext(node, errorMessage) {
|
|
82602
82836
|
var isInAppropriateContext = node.parent.kind === 303 /* SourceFile */ || node.parent.kind === 261 /* ModuleBlock */ || node.parent.kind === 260 /* ModuleDeclaration */;
|
|
@@ -82906,6 +83140,10 @@ var ts;
|
|
|
82906
83140
|
return;
|
|
82907
83141
|
case 307 /* JSDocTypeExpression */:
|
|
82908
83142
|
return checkSourceElement(node.type);
|
|
83143
|
+
case 331 /* JSDocPublicTag */:
|
|
83144
|
+
case 333 /* JSDocProtectedTag */:
|
|
83145
|
+
case 332 /* JSDocPrivateTag */:
|
|
83146
|
+
return checkJSDocAccessibilityModifiers(node);
|
|
82909
83147
|
case 193 /* IndexedAccessType */:
|
|
82910
83148
|
return checkIndexedAccessType(node);
|
|
82911
83149
|
case 194 /* MappedType */:
|
|
@@ -85601,8 +85839,8 @@ var ts;
|
|
|
85601
85839
|
if (!ts.isEffectiveExternalModule(sourceFile, compilerOptions)) {
|
|
85602
85840
|
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));
|
|
85603
85841
|
}
|
|
85604
|
-
if ((moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.System && !(moduleKind === ts.ModuleKind.NodeNext && ts.getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ts.ModuleKind.ESNext)) || languageVersion < 4 /* ES2017 */) {
|
|
85605
|
-
diagnostics.add(ts.createDiagnosticForNode(forInOrOfStatement.awaitModifier, ts.Diagnostics.
|
|
85842
|
+
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 */) {
|
|
85843
|
+
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));
|
|
85606
85844
|
}
|
|
85607
85845
|
}
|
|
85608
85846
|
}
|
|
@@ -86271,14 +86509,27 @@ var ts;
|
|
|
86271
86509
|
return ambientModulesCache;
|
|
86272
86510
|
}
|
|
86273
86511
|
function checkGrammarImportClause(node) {
|
|
86512
|
+
var _a;
|
|
86274
86513
|
if (node.isTypeOnly && node.name && node.namedBindings) {
|
|
86275
86514
|
return grammarErrorOnNode(node, ts.Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both);
|
|
86276
86515
|
}
|
|
86516
|
+
if (node.isTypeOnly && ((_a = node.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 268 /* NamedImports */) {
|
|
86517
|
+
return checkGrammarNamedImportsOrExports(node.namedBindings);
|
|
86518
|
+
}
|
|
86277
86519
|
return false;
|
|
86278
86520
|
}
|
|
86521
|
+
function checkGrammarNamedImportsOrExports(namedBindings) {
|
|
86522
|
+
return !!ts.forEach(namedBindings.elements, function (specifier) {
|
|
86523
|
+
if (specifier.isTypeOnly) {
|
|
86524
|
+
return grammarErrorOnFirstToken(specifier, specifier.kind === 269 /* ImportSpecifier */
|
|
86525
|
+
? ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement
|
|
86526
|
+
: ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement);
|
|
86527
|
+
}
|
|
86528
|
+
});
|
|
86529
|
+
}
|
|
86279
86530
|
function checkGrammarImportCallExpression(node) {
|
|
86280
86531
|
if (moduleKind === ts.ModuleKind.ES2015) {
|
|
86281
|
-
return grammarErrorOnNode(node, ts.Diagnostics.
|
|
86532
|
+
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);
|
|
86282
86533
|
}
|
|
86283
86534
|
if (node.typeArguments) {
|
|
86284
86535
|
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_cannot_have_type_arguments);
|
|
@@ -87007,7 +87258,7 @@ var ts;
|
|
|
87007
87258
|
return factory.updateNamedImports(node, nodesVisitor(node.elements, visitor, ts.isImportSpecifier));
|
|
87008
87259
|
case 269 /* ImportSpecifier */:
|
|
87009
87260
|
ts.Debug.type(node);
|
|
87010
|
-
return factory.updateImportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87261
|
+
return factory.updateImportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87011
87262
|
case 270 /* ExportAssignment */:
|
|
87012
87263
|
ts.Debug.type(node);
|
|
87013
87264
|
return factory.updateExportAssignment(node, nodesVisitor(node.decorators, visitor, ts.isDecorator), nodesVisitor(node.modifiers, visitor, ts.isModifier), nodeVisitor(node.expression, visitor, ts.isExpression));
|
|
@@ -87019,7 +87270,7 @@ var ts;
|
|
|
87019
87270
|
return factory.updateNamedExports(node, nodesVisitor(node.elements, visitor, ts.isExportSpecifier));
|
|
87020
87271
|
case 274 /* ExportSpecifier */:
|
|
87021
87272
|
ts.Debug.type(node);
|
|
87022
|
-
return factory.updateExportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87273
|
+
return factory.updateExportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87023
87274
|
// Module references
|
|
87024
87275
|
case 276 /* ExternalModuleReference */:
|
|
87025
87276
|
ts.Debug.type(node);
|
|
@@ -87392,7 +87643,7 @@ var ts;
|
|
|
87392
87643
|
}
|
|
87393
87644
|
ts.createSourceMapGenerator = createSourceMapGenerator;
|
|
87394
87645
|
// Sometimes tools can see the following line as a source mapping url comment, so we mangle it a bit (the [M])
|
|
87395
|
-
var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)
|
|
87646
|
+
var sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
|
|
87396
87647
|
var whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;
|
|
87397
87648
|
function getLineInfo(text, lineStarts) {
|
|
87398
87649
|
return {
|
|
@@ -90684,6 +90935,7 @@ var ts;
|
|
|
90684
90935
|
|| (isExternalModuleExport(node)
|
|
90685
90936
|
&& moduleKind !== ts.ModuleKind.ES2015
|
|
90686
90937
|
&& moduleKind !== ts.ModuleKind.ES2020
|
|
90938
|
+
&& moduleKind !== ts.ModuleKind.ES2022
|
|
90687
90939
|
&& moduleKind !== ts.ModuleKind.ESNext
|
|
90688
90940
|
&& moduleKind !== ts.ModuleKind.System);
|
|
90689
90941
|
}
|
|
@@ -90960,9 +91212,11 @@ var ts;
|
|
|
90960
91212
|
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90961
91213
|
}
|
|
90962
91214
|
else {
|
|
90963
|
-
// Elide named imports if all of its import specifiers are elided.
|
|
91215
|
+
// Elide named imports if all of its import specifiers are elided and settings allow.
|
|
91216
|
+
var allowEmpty = compilerOptions.preserveValueImports && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91217
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
90964
91218
|
var elements = ts.visitNodes(node.elements, visitImportSpecifier, ts.isImportSpecifier);
|
|
90965
|
-
return ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
91219
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
90966
91220
|
}
|
|
90967
91221
|
}
|
|
90968
91222
|
/**
|
|
@@ -90971,7 +91225,7 @@ var ts;
|
|
|
90971
91225
|
* @param node The import specifier node.
|
|
90972
91226
|
*/
|
|
90973
91227
|
function visitImportSpecifier(node) {
|
|
90974
|
-
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
91228
|
+
return !node.isTypeOnly && shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90975
91229
|
}
|
|
90976
91230
|
/**
|
|
90977
91231
|
* Visits an export assignment, eliding it if it does not contain a clause that resolves
|
|
@@ -91000,12 +91254,10 @@ var ts;
|
|
|
91000
91254
|
// type checker doesn't know about any exports
|
|
91001
91255
|
return node;
|
|
91002
91256
|
}
|
|
91003
|
-
if (!resolver.isValueAliasDeclaration(node)) {
|
|
91004
|
-
// Elide the export declaration if it does not export a value.
|
|
91005
|
-
return undefined;
|
|
91006
|
-
}
|
|
91007
91257
|
// Elide the export declaration if all of its named exports are elided.
|
|
91008
|
-
var
|
|
91258
|
+
var allowEmpty = !!node.moduleSpecifier && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91259
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
91260
|
+
var exportClause = ts.visitNode(node.exportClause, function (bindings) { return visitNamedExportBindings(bindings, allowEmpty); }, ts.isNamedExportBindings);
|
|
91009
91261
|
return exportClause
|
|
91010
91262
|
? factory.updateExportDeclaration(node,
|
|
91011
91263
|
/*decorators*/ undefined,
|
|
@@ -91018,16 +91270,16 @@ var ts;
|
|
|
91018
91270
|
*
|
|
91019
91271
|
* @param node The named exports node.
|
|
91020
91272
|
*/
|
|
91021
|
-
function visitNamedExports(node) {
|
|
91273
|
+
function visitNamedExports(node, allowEmpty) {
|
|
91022
91274
|
// Elide the named exports if all of its export specifiers were elided.
|
|
91023
91275
|
var elements = ts.visitNodes(node.elements, visitExportSpecifier, ts.isExportSpecifier);
|
|
91024
|
-
return ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
91276
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
91025
91277
|
}
|
|
91026
91278
|
function visitNamespaceExports(node) {
|
|
91027
91279
|
return factory.updateNamespaceExport(node, ts.visitNode(node.name, visitor, ts.isIdentifier));
|
|
91028
91280
|
}
|
|
91029
|
-
function visitNamedExportBindings(node) {
|
|
91030
|
-
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node);
|
|
91281
|
+
function visitNamedExportBindings(node, allowEmpty) {
|
|
91282
|
+
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node, allowEmpty);
|
|
91031
91283
|
}
|
|
91032
91284
|
/**
|
|
91033
91285
|
* Visits an export specifier, eliding it if it does not resolve to a value.
|
|
@@ -91036,7 +91288,7 @@ var ts;
|
|
|
91036
91288
|
*/
|
|
91037
91289
|
function visitExportSpecifier(node) {
|
|
91038
91290
|
// Elide an export specifier if it does not reference a value.
|
|
91039
|
-
return resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
91291
|
+
return !node.isTypeOnly && resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
91040
91292
|
}
|
|
91041
91293
|
/**
|
|
91042
91294
|
* Determines whether to emit an import equals declaration.
|
|
@@ -94637,7 +94889,7 @@ var ts;
|
|
|
94637
94889
|
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
|
|
94638
94890
|
}
|
|
94639
94891
|
var generatedName = factory.createUniqueName("_" + name, 16 /* Optimistic */ | 32 /* FileLevel */ | 64 /* AllowNameSubstitution */);
|
|
94640
|
-
var specifier = factory.createImportSpecifier(factory.createIdentifier(name), generatedName);
|
|
94892
|
+
var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName);
|
|
94641
94893
|
generatedName.generatedImportReference = specifier;
|
|
94642
94894
|
specifierSourceImports.set(name, specifier);
|
|
94643
94895
|
return generatedName;
|
|
@@ -104353,7 +104605,7 @@ var ts;
|
|
|
104353
104605
|
/*modifiers*/ undefined, factory.createImportClause(
|
|
104354
104606
|
/*isTypeOnly*/ false,
|
|
104355
104607
|
/*name*/ undefined, factory.createNamedImports([
|
|
104356
|
-
factory.createImportSpecifier(factory.createIdentifier("createRequire"), createRequireName)
|
|
104608
|
+
factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName)
|
|
104357
104609
|
])), factory.createStringLiteral("module"));
|
|
104358
104610
|
var requireHelperName = factory.createUniqueName("__require", 16 /* Optimistic */ | 32 /* FileLevel */);
|
|
104359
104611
|
var requireStatement = factory.createVariableStatement(
|
|
@@ -104393,7 +104645,7 @@ var ts;
|
|
|
104393
104645
|
if (ts.hasSyntacticModifier(node, 1 /* Export */)) {
|
|
104394
104646
|
statements = ts.append(statements, factory.createExportDeclaration(
|
|
104395
104647
|
/*decorators*/ undefined,
|
|
104396
|
-
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104648
|
+
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104397
104649
|
}
|
|
104398
104650
|
return statements;
|
|
104399
104651
|
}
|
|
@@ -104421,7 +104673,7 @@ var ts;
|
|
|
104421
104673
|
var exportDecl = ts.isExportNamespaceAsDefaultDeclaration(node) ? factory.createExportDefault(synthName) : factory.createExportDeclaration(
|
|
104422
104674
|
/*decorators*/ undefined,
|
|
104423
104675
|
/*modifiers*/ undefined,
|
|
104424
|
-
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(synthName, oldIdentifier)]));
|
|
104676
|
+
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, synthName, oldIdentifier)]));
|
|
104425
104677
|
ts.setOriginalNode(exportDecl, node);
|
|
104426
104678
|
return [importDecl, exportDecl];
|
|
104427
104679
|
}
|
|
@@ -105988,7 +106240,7 @@ var ts;
|
|
|
105988
106240
|
/*modifiers*/ undefined,
|
|
105989
106241
|
/*isTypeOnly*/ false, factory.createNamedExports(ts.map(exportMappings_1, function (_a) {
|
|
105990
106242
|
var gen = _a[0], exp = _a[1];
|
|
105991
|
-
return factory.createExportSpecifier(gen, exp);
|
|
106243
|
+
return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp);
|
|
105992
106244
|
}))));
|
|
105993
106245
|
}
|
|
105994
106246
|
var namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, factory.createModuleBlock(declarations), 16 /* Namespace */);
|
|
@@ -106362,6 +106614,7 @@ var ts;
|
|
|
106362
106614
|
function getModuleTransformer(moduleKind) {
|
|
106363
106615
|
switch (moduleKind) {
|
|
106364
106616
|
case ts.ModuleKind.ESNext:
|
|
106617
|
+
case ts.ModuleKind.ES2022:
|
|
106365
106618
|
case ts.ModuleKind.ES2020:
|
|
106366
106619
|
case ts.ModuleKind.ES2015:
|
|
106367
106620
|
return ts.transformECMAScriptModule;
|
|
@@ -109927,6 +110180,10 @@ var ts;
|
|
|
109927
110180
|
writePunctuation("}");
|
|
109928
110181
|
}
|
|
109929
110182
|
function emitImportOrExportSpecifier(node) {
|
|
110183
|
+
if (node.isTypeOnly) {
|
|
110184
|
+
writeKeyword("type");
|
|
110185
|
+
writeSpace();
|
|
110186
|
+
}
|
|
109930
110187
|
if (node.propertyName) {
|
|
109931
110188
|
emit(node.propertyName);
|
|
109932
110189
|
writeSpace();
|
|
@@ -118948,7 +119205,7 @@ var ts;
|
|
|
118948
119205
|
var nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);
|
|
118949
119206
|
var packageName = ts.getPackageNameFromTypesPackageName(nodeModulesDirectoryName);
|
|
118950
119207
|
// For classic resolution, only allow importing from node_modules/@types, not other node_modules
|
|
118951
|
-
return ts.getEmitModuleResolutionKind(options)
|
|
119208
|
+
return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
|
|
118952
119209
|
function tryDirectoryWithPackageJson(packageRootIndex) {
|
|
118953
119210
|
var packageRootPath = path.substring(0, packageRootIndex);
|
|
118954
119211
|
var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
|
|
@@ -124355,6 +124612,10 @@ var ts;
|
|
|
124355
124612
|
return node.kind === 151 /* TypeKeyword */;
|
|
124356
124613
|
}
|
|
124357
124614
|
ts.isTypeKeywordToken = isTypeKeywordToken;
|
|
124615
|
+
function isTypeKeywordTokenOrIdentifier(node) {
|
|
124616
|
+
return isTypeKeywordToken(node) || ts.isIdentifier(node) && node.text === "type";
|
|
124617
|
+
}
|
|
124618
|
+
ts.isTypeKeywordTokenOrIdentifier = isTypeKeywordTokenOrIdentifier;
|
|
124358
124619
|
/** True if the symbol is for an external module, as opposed to a namespace. */
|
|
124359
124620
|
function isExternalModuleSymbol(moduleSymbol) {
|
|
124360
124621
|
return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */;
|
|
@@ -127319,7 +127580,7 @@ var ts;
|
|
|
127319
127580
|
return convertPathCompletions(completion.paths);
|
|
127320
127581
|
case 1 /* Properties */: {
|
|
127321
127582
|
var entries = [];
|
|
127322
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
127583
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
127323
127584
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
127324
127585
|
}
|
|
127325
127586
|
case 2 /* Types */: {
|
|
@@ -128091,6 +128352,7 @@ var ts;
|
|
|
128091
128352
|
KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
|
|
128092
128353
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeAssertionKeywords"] = 6] = "TypeAssertionKeywords";
|
|
128093
128354
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 7] = "TypeKeywords";
|
|
128355
|
+
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeyword"] = 8] = "TypeKeyword";
|
|
128094
128356
|
KeywordCompletionFilters[KeywordCompletionFilters["Last"] = 7] = "Last";
|
|
128095
128357
|
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
|
|
128096
128358
|
var GlobalsSearch;
|
|
@@ -128192,7 +128454,7 @@ var ts;
|
|
|
128192
128454
|
case 3 /* JsDocParameterName */:
|
|
128193
128455
|
return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
|
|
128194
128456
|
case 4 /* Keywords */:
|
|
128195
|
-
return specificKeywordCompletionInfo(completionData.
|
|
128457
|
+
return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
|
|
128196
128458
|
default:
|
|
128197
128459
|
return ts.Debug.assertNever(completionData);
|
|
128198
128460
|
}
|
|
@@ -128243,25 +128505,41 @@ var ts;
|
|
|
128243
128505
|
function jsdocCompletionInfo(entries) {
|
|
128244
128506
|
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: entries };
|
|
128245
128507
|
}
|
|
128246
|
-
function
|
|
128508
|
+
function keywordToCompletionEntry(keyword) {
|
|
128509
|
+
return {
|
|
128510
|
+
name: ts.tokenToString(keyword),
|
|
128511
|
+
kind: "keyword" /* keyword */,
|
|
128512
|
+
kindModifiers: "" /* none */,
|
|
128513
|
+
sortText: SortText.GlobalsOrKeywords,
|
|
128514
|
+
};
|
|
128515
|
+
}
|
|
128516
|
+
function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
|
|
128247
128517
|
return {
|
|
128248
128518
|
isGlobalCompletion: false,
|
|
128249
128519
|
isMemberCompletion: false,
|
|
128250
|
-
isNewIdentifierLocation:
|
|
128251
|
-
entries:
|
|
128252
|
-
name: ts.tokenToString(k),
|
|
128253
|
-
kind: "keyword" /* keyword */,
|
|
128254
|
-
kindModifiers: "" /* none */,
|
|
128255
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
128256
|
-
}); }),
|
|
128520
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128521
|
+
entries: entries.slice(),
|
|
128257
128522
|
};
|
|
128258
128523
|
}
|
|
128524
|
+
function keywordCompletionData(keywordFilters, filterOutTsOnlyKeywords, isNewIdentifierLocation) {
|
|
128525
|
+
return {
|
|
128526
|
+
kind: 4 /* Keywords */,
|
|
128527
|
+
keywordCompletions: getKeywordCompletions(keywordFilters, filterOutTsOnlyKeywords),
|
|
128528
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128529
|
+
};
|
|
128530
|
+
}
|
|
128531
|
+
function keywordFiltersFromSyntaxKind(keywordCompletion) {
|
|
128532
|
+
switch (keywordCompletion) {
|
|
128533
|
+
case 151 /* TypeKeyword */: return 8 /* TypeKeyword */;
|
|
128534
|
+
default: ts.Debug.fail("Unknown mapping from SyntaxKind to KeywordCompletionFilters");
|
|
128535
|
+
}
|
|
128536
|
+
}
|
|
128259
128537
|
function getOptionalReplacementSpan(location) {
|
|
128260
128538
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
128261
128539
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
128262
128540
|
}
|
|
128263
128541
|
function completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences) {
|
|
128264
|
-
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;
|
|
128542
|
+
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;
|
|
128265
128543
|
// Verify if the file is JSX language variant
|
|
128266
128544
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
128267
128545
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -128272,7 +128550,7 @@ var ts;
|
|
|
128272
128550
|
var entries = [];
|
|
128273
128551
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
128274
128552
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
128275
|
-
/*
|
|
128553
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128276
128554
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
128277
128555
|
}
|
|
128278
128556
|
else {
|
|
@@ -128280,7 +128558,7 @@ var ts;
|
|
|
128280
128558
|
return undefined;
|
|
128281
128559
|
}
|
|
128282
128560
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
128283
|
-
/*
|
|
128561
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128284
128562
|
}
|
|
128285
128563
|
if (keywordFilters !== 0 /* None */) {
|
|
128286
128564
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -128386,10 +128664,10 @@ var ts;
|
|
|
128386
128664
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
128387
128665
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
128388
128666
|
}
|
|
128389
|
-
function createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128667
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences) {
|
|
128390
128668
|
var _a;
|
|
128391
128669
|
var insertText;
|
|
128392
|
-
var replacementSpan = ts.getReplacementSpanForContextToken(
|
|
128670
|
+
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
128393
128671
|
var data;
|
|
128394
128672
|
var isSnippet;
|
|
128395
128673
|
var sourceDisplay;
|
|
@@ -128440,7 +128718,7 @@ var ts;
|
|
|
128440
128718
|
if (originIsResolvedExport(origin)) {
|
|
128441
128719
|
sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
|
|
128442
128720
|
if (importCompletionNode) {
|
|
128443
|
-
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128721
|
+
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
|
|
128444
128722
|
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
|
|
128445
128723
|
}
|
|
128446
128724
|
}
|
|
@@ -128513,22 +128791,26 @@ var ts;
|
|
|
128513
128791
|
moduleSpecifier: originIsResolvedExport(origin) ? origin.moduleSpecifier : undefined,
|
|
128514
128792
|
};
|
|
128515
128793
|
}
|
|
128516
|
-
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128794
|
+
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences) {
|
|
128795
|
+
var _a, _b, _c;
|
|
128517
128796
|
var sourceFile = importCompletionNode.getSourceFile();
|
|
128518
|
-
var replacementSpan = ts.createTextSpanFromNode(importCompletionNode, sourceFile);
|
|
128797
|
+
var replacementSpan = ts.createTextSpanFromNode(ts.findAncestor(importCompletionNode, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration)) || importCompletionNode, sourceFile);
|
|
128519
128798
|
var quotedModuleSpecifier = ts.quote(sourceFile, preferences, origin.moduleSpecifier);
|
|
128520
128799
|
var exportKind = origin.isDefaultExport ? 1 /* Default */ :
|
|
128521
128800
|
origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ :
|
|
128522
128801
|
0 /* Named */;
|
|
128523
128802
|
var tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
|
|
128524
128803
|
var importKind = ts.codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
|
|
128525
|
-
var
|
|
128804
|
+
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);
|
|
128805
|
+
var isImportSpecifierTypeOnly = couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
128806
|
+
var topLevelTypeOnlyText = isTopLevelTypeOnly ? " " + ts.tokenToString(151 /* TypeKeyword */) + " " : " ";
|
|
128807
|
+
var importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? ts.tokenToString(151 /* TypeKeyword */) + " " : "";
|
|
128526
128808
|
var suffix = useSemicolons ? ";" : "";
|
|
128527
128809
|
switch (importKind) {
|
|
128528
|
-
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128529
|
-
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128530
|
-
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128531
|
-
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128810
|
+
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
|
|
128811
|
+
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " from " + quotedModuleSpecifier + suffix };
|
|
128812
|
+
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "* as " + escapeSnippetText(name) + " from " + quotedModuleSpecifier + suffix };
|
|
128813
|
+
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "{ " + importSpecifierTypeOnlyText + escapeSnippetText(name) + tabStop + " } from " + quotedModuleSpecifier + suffix };
|
|
128532
128814
|
}
|
|
128533
128815
|
}
|
|
128534
128816
|
function quotePropertyName(sourceFile, preferences, name) {
|
|
@@ -128552,12 +128834,11 @@ var ts;
|
|
|
128552
128834
|
return CompletionSource.ThisProperty;
|
|
128553
128835
|
}
|
|
128554
128836
|
}
|
|
128555
|
-
function getCompletionEntriesFromSymbols(symbols, entries, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128837
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128556
128838
|
var _a;
|
|
128557
128839
|
var start = ts.timestamp();
|
|
128558
128840
|
var variableDeclaration = getVariableDeclaration(location);
|
|
128559
128841
|
var useSemicolons = ts.probablyUsesSemicolons(sourceFile);
|
|
128560
|
-
var isTypeOnlyImport = !!importCompletionNode && ts.isTypeOnlyImportOrExportDeclaration(location.parent);
|
|
128561
128842
|
// Tracks unique names.
|
|
128562
128843
|
// Value is set to false for global variables or completions from external module exports, because we can have multiple of those;
|
|
128563
128844
|
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
|
|
@@ -128573,7 +128854,7 @@ var ts;
|
|
|
128573
128854
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
128574
128855
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
128575
128856
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
128576
|
-
var entry = createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128857
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences);
|
|
128577
128858
|
if (!entry) {
|
|
128578
128859
|
continue;
|
|
128579
128860
|
}
|
|
@@ -128722,7 +129003,7 @@ var ts;
|
|
|
128722
129003
|
case 3 /* JsDocParameterName */:
|
|
128723
129004
|
return ts.JsDoc.getJSDocParameterNameCompletionDetails(name);
|
|
128724
129005
|
case 4 /* Keywords */:
|
|
128725
|
-
return
|
|
129006
|
+
return ts.some(request.keywordCompletions, function (c) { return c.name === name; }) ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
|
|
128726
129007
|
default:
|
|
128727
129008
|
return ts.Debug.assertNever(request);
|
|
128728
129009
|
}
|
|
@@ -128761,7 +129042,7 @@ var ts;
|
|
|
128761
129042
|
function getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data) {
|
|
128762
129043
|
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
|
|
128763
129044
|
var _a = getRelevantTokens(position, sourceFile), contextToken = _a.contextToken, previousToken_1 = _a.previousToken;
|
|
128764
|
-
if (previousToken_1 &&
|
|
129045
|
+
if (previousToken_1 && getImportStatementCompletionInfo(contextToken || previousToken_1).replacementNode) {
|
|
128765
129046
|
// Import statement completion: 'import c|'
|
|
128766
129047
|
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
|
|
128767
129048
|
}
|
|
@@ -128924,6 +129205,7 @@ var ts;
|
|
|
128924
129205
|
start = ts.timestamp();
|
|
128925
129206
|
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
|
|
128926
129207
|
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
|
|
129208
|
+
var isJsOnlyLocation = !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile);
|
|
128927
129209
|
var tokens = getRelevantTokens(position, sourceFile);
|
|
128928
129210
|
var previousToken = tokens.previousToken;
|
|
128929
129211
|
var contextToken = tokens.contextToken;
|
|
@@ -128941,22 +129223,34 @@ var ts;
|
|
|
128941
129223
|
var isJsxIdentifierExpected = false;
|
|
128942
129224
|
var importCompletionNode;
|
|
128943
129225
|
var location = ts.getTouchingPropertyName(sourceFile, position);
|
|
129226
|
+
var keywordFilters = 0 /* None */;
|
|
129227
|
+
var isNewIdentifierLocation = false;
|
|
128944
129228
|
if (contextToken) {
|
|
128945
|
-
var
|
|
128946
|
-
|
|
128947
|
-
|
|
129229
|
+
var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
|
|
129230
|
+
isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
|
|
129231
|
+
if (importStatementCompletion.keywordCompletion) {
|
|
129232
|
+
if (importStatementCompletion.isKeywordOnlyCompletion) {
|
|
129233
|
+
return {
|
|
129234
|
+
kind: 4 /* Keywords */,
|
|
129235
|
+
keywordCompletions: [keywordToCompletionEntry(importStatementCompletion.keywordCompletion)],
|
|
129236
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
129237
|
+
};
|
|
129238
|
+
}
|
|
129239
|
+
keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletion.keywordCompletion);
|
|
128948
129240
|
}
|
|
128949
|
-
|
|
128950
|
-
|
|
128951
|
-
|
|
128952
|
-
|
|
128953
|
-
|
|
128954
|
-
importCompletionNode =
|
|
129241
|
+
if (importStatementCompletion.replacementNode && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
|
|
129242
|
+
// Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
|
|
129243
|
+
// added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
|
|
129244
|
+
// is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
|
|
129245
|
+
// to opt in with the `includeCompletionsForImportStatements` user preference.
|
|
129246
|
+
importCompletionNode = importStatementCompletion.replacementNode;
|
|
128955
129247
|
}
|
|
128956
129248
|
// Bail out if this is a known invalid completion location
|
|
128957
129249
|
if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
|
|
128958
129250
|
log("Returning an empty list because completion was requested in an invalid position.");
|
|
128959
|
-
return
|
|
129251
|
+
return keywordFilters
|
|
129252
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierDefinitionLocation())
|
|
129253
|
+
: undefined;
|
|
128960
129254
|
}
|
|
128961
129255
|
var parent = contextToken.parent;
|
|
128962
129256
|
if (contextToken.kind === 24 /* DotToken */ || contextToken.kind === 28 /* QuestionDotToken */) {
|
|
@@ -129076,10 +129370,8 @@ var ts;
|
|
|
129076
129370
|
}
|
|
129077
129371
|
var semanticStart = ts.timestamp();
|
|
129078
129372
|
var completionKind = 5 /* None */;
|
|
129079
|
-
var isNewIdentifierLocation = false;
|
|
129080
129373
|
var isNonContextualObjectLiteral = false;
|
|
129081
129374
|
var hasUnresolvedAutoImports = false;
|
|
129082
|
-
var keywordFilters = 0 /* None */;
|
|
129083
129375
|
// This also gets mutated in nested-functions after the return
|
|
129084
129376
|
var symbols = [];
|
|
129085
129377
|
var symbolToOriginInfoMap = [];
|
|
@@ -129113,7 +129405,9 @@ var ts;
|
|
|
129113
129405
|
// global symbols in scope. These results should be valid for either language as
|
|
129114
129406
|
// the set of symbols that can be referenced from this location.
|
|
129115
129407
|
if (!tryGetGlobalSymbols()) {
|
|
129116
|
-
return
|
|
129408
|
+
return keywordFilters
|
|
129409
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierLocation)
|
|
129410
|
+
: undefined;
|
|
129117
129411
|
}
|
|
129118
129412
|
}
|
|
129119
129413
|
log("getCompletionData: Semantic work: " + (ts.timestamp() - semanticStart));
|
|
@@ -129133,6 +129427,7 @@ var ts;
|
|
|
129133
129427
|
symbolToOriginInfoMap: symbolToOriginInfoMap,
|
|
129134
129428
|
recommendedCompletion: recommendedCompletion,
|
|
129135
129429
|
previousToken: previousToken,
|
|
129430
|
+
contextToken: contextToken,
|
|
129136
129431
|
isJsxInitializer: isJsxInitializer,
|
|
129137
129432
|
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
|
|
129138
129433
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
@@ -129519,8 +129814,14 @@ var ts;
|
|
|
129519
129814
|
// Asking for completion details for an item that is not an auto-import
|
|
129520
129815
|
return;
|
|
129521
129816
|
}
|
|
129817
|
+
// import { type | -> token text should be blank
|
|
129818
|
+
var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
|
|
129819
|
+
&& importCompletionNode
|
|
129820
|
+
&& couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
129821
|
+
var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
|
|
129822
|
+
previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
|
|
129823
|
+
"";
|
|
129522
129824
|
var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
129523
|
-
var lowerCaseTokenText = previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() : "";
|
|
129524
129825
|
var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
|
|
129525
129826
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
129526
129827
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
@@ -129653,6 +129954,7 @@ var ts;
|
|
|
129653
129954
|
|| containingNodeKind === 161 /* ComputedPropertyName */; // [ | /* this can become an index signature */
|
|
129654
129955
|
case 141 /* ModuleKeyword */: // module |
|
|
129655
129956
|
case 142 /* NamespaceKeyword */: // namespace |
|
|
129957
|
+
case 100 /* ImportKeyword */: // import |
|
|
129656
129958
|
return true;
|
|
129657
129959
|
case 24 /* DotToken */:
|
|
129658
129960
|
return containingNodeKind === 260 /* ModuleDeclaration */; // module A.|
|
|
@@ -129791,23 +130093,38 @@ var ts;
|
|
|
129791
130093
|
* Relevant symbols are stored in the captured 'symbols' variable.
|
|
129792
130094
|
*/
|
|
129793
130095
|
function tryGetImportOrExportClauseCompletionSymbols() {
|
|
129794
|
-
|
|
129795
|
-
|
|
129796
|
-
|
|
130096
|
+
if (!contextToken)
|
|
130097
|
+
return 0 /* Continue */;
|
|
130098
|
+
// `import { |` or `import { a as 0, | }` or `import { type | }`
|
|
130099
|
+
var namedImportsOrExports = contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */ ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) :
|
|
130100
|
+
ts.isTypeKeywordTokenOrIdentifier(contextToken) ? ts.tryCast(contextToken.parent.parent, ts.isNamedImportsOrExports) : undefined;
|
|
129797
130101
|
if (!namedImportsOrExports)
|
|
129798
130102
|
return 0 /* Continue */;
|
|
130103
|
+
// We can at least offer `type` at `import { |`
|
|
130104
|
+
if (!ts.isTypeKeywordTokenOrIdentifier(contextToken)) {
|
|
130105
|
+
keywordFilters = 8 /* TypeKeyword */;
|
|
130106
|
+
}
|
|
129799
130107
|
// try to show exported member for imported/re-exported module
|
|
129800
130108
|
var moduleSpecifier = (namedImportsOrExports.kind === 268 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
|
|
129801
|
-
if (!moduleSpecifier)
|
|
130109
|
+
if (!moduleSpecifier) {
|
|
130110
|
+
isNewIdentifierLocation = true;
|
|
129802
130111
|
return namedImportsOrExports.kind === 268 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
|
|
130112
|
+
}
|
|
129803
130113
|
var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217
|
|
129804
|
-
if (!moduleSpecifierSymbol)
|
|
130114
|
+
if (!moduleSpecifierSymbol) {
|
|
130115
|
+
isNewIdentifierLocation = true;
|
|
129805
130116
|
return 2 /* Fail */;
|
|
130117
|
+
}
|
|
129806
130118
|
completionKind = 3 /* MemberLike */;
|
|
129807
130119
|
isNewIdentifierLocation = false;
|
|
129808
130120
|
var exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
|
|
129809
130121
|
var existing = new ts.Set(namedImportsOrExports.elements.filter(function (n) { return !isCurrentlyEditingNode(n); }).map(function (n) { return (n.propertyName || n.name).escapedText; }));
|
|
129810
|
-
|
|
130122
|
+
var uniques = exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); });
|
|
130123
|
+
symbols = ts.concatenate(symbols, uniques);
|
|
130124
|
+
if (!uniques.length) {
|
|
130125
|
+
// If there's nothing else to import, don't offer `type` either
|
|
130126
|
+
keywordFilters = 0 /* None */;
|
|
130127
|
+
}
|
|
129811
130128
|
return 1 /* Success */;
|
|
129812
130129
|
}
|
|
129813
130130
|
/**
|
|
@@ -130068,6 +130385,14 @@ var ts;
|
|
|
130068
130385
|
case 136 /* GetKeyword */:
|
|
130069
130386
|
case 148 /* SetKeyword */:
|
|
130070
130387
|
return !isFromObjectTypeDeclaration(contextToken);
|
|
130388
|
+
case 79 /* Identifier */:
|
|
130389
|
+
if (containingNodeKind === 269 /* ImportSpecifier */ &&
|
|
130390
|
+
contextToken === parent.name &&
|
|
130391
|
+
contextToken.text === "type") {
|
|
130392
|
+
// import { type | }
|
|
130393
|
+
return false;
|
|
130394
|
+
}
|
|
130395
|
+
break;
|
|
130071
130396
|
case 84 /* ClassKeyword */:
|
|
130072
130397
|
case 92 /* EnumKeyword */:
|
|
130073
130398
|
case 118 /* InterfaceKeyword */:
|
|
@@ -130077,8 +130402,10 @@ var ts;
|
|
|
130077
130402
|
case 119 /* LetKeyword */:
|
|
130078
130403
|
case 85 /* ConstKeyword */:
|
|
130079
130404
|
case 137 /* InferKeyword */:
|
|
130080
|
-
case 151 /* TypeKeyword */: // type htm|
|
|
130081
130405
|
return true;
|
|
130406
|
+
case 151 /* TypeKeyword */:
|
|
130407
|
+
// import { type foo| }
|
|
130408
|
+
return containingNodeKind !== 269 /* ImportSpecifier */;
|
|
130082
130409
|
case 41 /* AsteriskToken */:
|
|
130083
130410
|
return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
|
|
130084
130411
|
}
|
|
@@ -130439,6 +130766,8 @@ var ts;
|
|
|
130439
130766
|
return ts.isTypeKeyword(kind) || kind === 85 /* ConstKeyword */;
|
|
130440
130767
|
case 7 /* TypeKeywords */:
|
|
130441
130768
|
return ts.isTypeKeyword(kind);
|
|
130769
|
+
case 8 /* TypeKeyword */:
|
|
130770
|
+
return kind === 151 /* TypeKeyword */;
|
|
130442
130771
|
default:
|
|
130443
130772
|
return ts.Debug.assertNever(keywordFilter);
|
|
130444
130773
|
}
|
|
@@ -130712,34 +131041,67 @@ var ts;
|
|
|
130712
131041
|
}
|
|
130713
131042
|
return undefined;
|
|
130714
131043
|
}
|
|
130715
|
-
function
|
|
131044
|
+
function getImportStatementCompletionInfo(contextToken) {
|
|
131045
|
+
var keywordCompletion;
|
|
131046
|
+
var isKeywordOnlyCompletion = false;
|
|
130716
131047
|
var candidate = getCandidate();
|
|
130717
|
-
return
|
|
131048
|
+
return {
|
|
131049
|
+
isKeywordOnlyCompletion: isKeywordOnlyCompletion,
|
|
131050
|
+
keywordCompletion: keywordCompletion,
|
|
131051
|
+
isNewIdentifierLocation: !!(candidate || keywordCompletion === 151 /* TypeKeyword */),
|
|
131052
|
+
replacementNode: candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile())
|
|
131053
|
+
? candidate
|
|
131054
|
+
: undefined
|
|
131055
|
+
};
|
|
130718
131056
|
function getCandidate() {
|
|
130719
131057
|
var parent = contextToken.parent;
|
|
130720
131058
|
if (ts.isImportEqualsDeclaration(parent)) {
|
|
131059
|
+
keywordCompletion = contextToken.kind === 151 /* TypeKeyword */ ? undefined : 151 /* TypeKeyword */;
|
|
130721
131060
|
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
|
|
130722
131061
|
}
|
|
131062
|
+
if (couldBeTypeOnlyImportSpecifier(parent, contextToken) && canCompleteFromNamedBindings(parent.parent)) {
|
|
131063
|
+
return parent;
|
|
131064
|
+
}
|
|
130723
131065
|
if (ts.isNamedImports(parent) || ts.isNamespaceImport(parent)) {
|
|
130724
|
-
if (
|
|
131066
|
+
if (!parent.parent.isTypeOnly && (contextToken.kind === 18 /* OpenBraceToken */ ||
|
|
131067
|
+
contextToken.kind === 100 /* ImportKeyword */ ||
|
|
131068
|
+
contextToken.kind === 27 /* CommaToken */)) {
|
|
131069
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
131070
|
+
}
|
|
131071
|
+
if (canCompleteFromNamedBindings(parent)) {
|
|
130725
131072
|
// At `import { ... } |` or `import * as Foo |`, the only possible completion is `from`
|
|
130726
|
-
|
|
130727
|
-
|
|
130728
|
-
|
|
131073
|
+
if (contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */) {
|
|
131074
|
+
isKeywordOnlyCompletion = true;
|
|
131075
|
+
keywordCompletion = 155 /* FromKeyword */;
|
|
131076
|
+
}
|
|
131077
|
+
else {
|
|
131078
|
+
return parent.parent.parent;
|
|
131079
|
+
}
|
|
130729
131080
|
}
|
|
130730
131081
|
return undefined;
|
|
130731
131082
|
}
|
|
130732
131083
|
if (ts.isImportKeyword(contextToken) && ts.isSourceFile(parent)) {
|
|
130733
131084
|
// A lone import keyword with nothing following it does not parse as a statement at all
|
|
131085
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130734
131086
|
return contextToken;
|
|
130735
131087
|
}
|
|
130736
131088
|
if (ts.isImportKeyword(contextToken) && ts.isImportDeclaration(parent)) {
|
|
130737
131089
|
// `import s| from`
|
|
131090
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130738
131091
|
return isModuleSpecifierMissingOrEmpty(parent.moduleSpecifier) ? parent : undefined;
|
|
130739
131092
|
}
|
|
130740
131093
|
return undefined;
|
|
130741
131094
|
}
|
|
130742
131095
|
}
|
|
131096
|
+
function couldBeTypeOnlyImportSpecifier(importSpecifier, contextToken) {
|
|
131097
|
+
return ts.isImportSpecifier(importSpecifier)
|
|
131098
|
+
&& (importSpecifier.isTypeOnly || contextToken === importSpecifier.name && ts.isTypeKeywordTokenOrIdentifier(contextToken));
|
|
131099
|
+
}
|
|
131100
|
+
function canCompleteFromNamedBindings(namedBindings) {
|
|
131101
|
+
return isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier)
|
|
131102
|
+
&& (ts.isNamespaceImport(namedBindings) || namedBindings.elements.length < 2)
|
|
131103
|
+
&& !namedBindings.parent.name;
|
|
131104
|
+
}
|
|
130743
131105
|
function isModuleSpecifierMissingOrEmpty(specifier) {
|
|
130744
131106
|
var _a;
|
|
130745
131107
|
if (ts.nodeIsMissing(specifier))
|
|
@@ -136879,7 +137241,7 @@ var ts;
|
|
|
136879
137241
|
else {
|
|
136880
137242
|
for (var _e = 0, defaultImports_1 = defaultImports; _e < defaultImports_1.length; _e++) {
|
|
136881
137243
|
var defaultImport = defaultImports_1[_e];
|
|
136882
|
-
newImportSpecifiers.push(ts.factory.createImportSpecifier(ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
137244
|
+
newImportSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136883
137245
|
}
|
|
136884
137246
|
}
|
|
136885
137247
|
newImportSpecifiers.push.apply(newImportSpecifiers, ts.flatMap(namedImports, function (i) { return i.importClause.namedBindings.elements; })); // TODO: GH#18217
|
|
@@ -137013,7 +137375,8 @@ var ts;
|
|
|
137013
137375
|
return ts.stableSort(specifiers, compareImportOrExportSpecifiers);
|
|
137014
137376
|
}
|
|
137015
137377
|
function compareImportOrExportSpecifiers(s1, s2) {
|
|
137016
|
-
return
|
|
137378
|
+
return ts.compareBooleans(s1.isTypeOnly, s2.isTypeOnly)
|
|
137379
|
+
|| compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
|
|
137017
137380
|
|| compareIdentifiers(s1.name, s2.name);
|
|
137018
137381
|
}
|
|
137019
137382
|
OrganizeImports.compareImportOrExportSpecifiers = compareImportOrExportSpecifiers;
|
|
@@ -139490,7 +139853,7 @@ var ts;
|
|
|
139490
139853
|
if (!typeDisplayString) {
|
|
139491
139854
|
continue;
|
|
139492
139855
|
}
|
|
139493
|
-
addTypeHints(typeDisplayString, param.end);
|
|
139856
|
+
addTypeHints(typeDisplayString, param.name.end);
|
|
139494
139857
|
}
|
|
139495
139858
|
}
|
|
139496
139859
|
function getParameterDeclarationTypeDisplayString(symbol) {
|
|
@@ -147171,7 +147534,7 @@ var ts;
|
|
|
147171
147534
|
*/
|
|
147172
147535
|
var newNodes = [
|
|
147173
147536
|
makeConst(/*modifiers*/ undefined, rename, assignment.right),
|
|
147174
|
-
makeExportDeclaration([ts.factory.createExportSpecifier(rename, text)]),
|
|
147537
|
+
makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, rename, text)]),
|
|
147175
147538
|
];
|
|
147176
147539
|
changes.replaceNodeWithNodes(sourceFile, assignment.parent, newNodes);
|
|
147177
147540
|
}
|
|
@@ -147193,7 +147556,7 @@ var ts;
|
|
|
147193
147556
|
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
|
|
147194
147557
|
}
|
|
147195
147558
|
function reExportDefault(moduleSpecifier) {
|
|
147196
|
-
return makeExportDeclaration([ts.factory.createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
147559
|
+
return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
147197
147560
|
}
|
|
147198
147561
|
function convertExportsPropertyAssignment(_a, sourceFile, changes) {
|
|
147199
147562
|
var left = _a.left, right = _a.right, parent = _a.parent;
|
|
@@ -147335,7 +147698,7 @@ var ts;
|
|
|
147335
147698
|
}
|
|
147336
147699
|
var namedBindings = namedBindingsNames.size === 0 ? undefined : ts.arrayFrom(ts.mapIterator(namedBindingsNames.entries(), function (_a) {
|
|
147337
147700
|
var propertyName = _a[0], idName = _a[1];
|
|
147338
|
-
return ts.factory.createImportSpecifier(propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
147701
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
147339
147702
|
}));
|
|
147340
147703
|
if (!namedBindings) {
|
|
147341
147704
|
// If it was unused, ensure that we at least import *something*.
|
|
@@ -147393,7 +147756,7 @@ var ts;
|
|
|
147393
147756
|
: ts.makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier, quotePreference);
|
|
147394
147757
|
}
|
|
147395
147758
|
function makeImportSpecifier(propertyName, name) {
|
|
147396
|
-
return ts.factory.createImportSpecifier(propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147759
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147397
147760
|
}
|
|
147398
147761
|
function makeConst(modifiers, name, init) {
|
|
147399
147762
|
return ts.factory.createVariableStatement(modifiers, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, /*type*/ undefined, init)], 2 /* Const */));
|
|
@@ -147718,13 +148081,13 @@ var ts;
|
|
|
147718
148081
|
codefix.registerCodeFix({
|
|
147719
148082
|
errorCodes: errorCodes,
|
|
147720
148083
|
getCodeActions: function (context) {
|
|
147721
|
-
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span;
|
|
148084
|
+
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span, program = context.program;
|
|
147722
148085
|
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
|
147723
148086
|
if (!info)
|
|
147724
148087
|
return undefined;
|
|
147725
148088
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147726
148089
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
147727
|
-
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference); });
|
|
148090
|
+
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
|
|
147728
148091
|
},
|
|
147729
148092
|
fixIds: [importFixId],
|
|
147730
148093
|
getAllCodeActions: function (context) {
|
|
@@ -147743,8 +148106,9 @@ var ts;
|
|
|
147743
148106
|
// Namespace fixes don't conflict, so just build a list.
|
|
147744
148107
|
var addToNamespace = [];
|
|
147745
148108
|
var importType = [];
|
|
147746
|
-
|
|
148109
|
+
/** Keys are import clause node IDs. */
|
|
147747
148110
|
var addToExisting = new ts.Map();
|
|
148111
|
+
/** Use `getNewImportEntry` for access */
|
|
147748
148112
|
var newImports = new ts.Map();
|
|
147749
148113
|
return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes };
|
|
147750
148114
|
function addImportFromDiagnostic(diagnostic, context) {
|
|
@@ -147753,67 +148117,66 @@ var ts;
|
|
|
147753
148117
|
return;
|
|
147754
148118
|
addImport(info);
|
|
147755
148119
|
}
|
|
147756
|
-
function addImportFromExportedSymbol(exportedSymbol,
|
|
148120
|
+
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
|
|
147757
148121
|
var moduleSymbol = ts.Debug.checkDefined(exportedSymbol.parent);
|
|
147758
148122
|
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
|
|
147759
148123
|
var checker = program.getTypeChecker();
|
|
147760
148124
|
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
|
|
147761
148125
|
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
|
|
147762
|
-
var preferTypeOnlyImport = !!usageIsTypeOnly && compilerOptions.importsNotUsedAsValues === 2 /* Error */;
|
|
147763
148126
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147764
|
-
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined,
|
|
148127
|
+
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147765
148128
|
if (fix) {
|
|
147766
148129
|
addImport({ fixes: [fix], symbolName: symbolName });
|
|
147767
148130
|
}
|
|
147768
148131
|
}
|
|
147769
148132
|
function addImport(info) {
|
|
148133
|
+
var _a, _b;
|
|
147770
148134
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147771
148135
|
var fix = ts.first(fixes);
|
|
147772
148136
|
switch (fix.kind) {
|
|
147773
148137
|
case 0 /* UseNamespace */:
|
|
147774
148138
|
addToNamespace.push(fix);
|
|
147775
148139
|
break;
|
|
147776
|
-
case 1 /*
|
|
148140
|
+
case 1 /* JsdocTypeImport */:
|
|
147777
148141
|
importType.push(fix);
|
|
147778
148142
|
break;
|
|
147779
148143
|
case 2 /* AddToExisting */: {
|
|
147780
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
148144
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147781
148145
|
var key = String(ts.getNodeId(importClauseOrBindingPattern));
|
|
147782
148146
|
var entry = addToExisting.get(key);
|
|
147783
148147
|
if (!entry) {
|
|
147784
|
-
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports:
|
|
148148
|
+
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: new ts.Map() });
|
|
147785
148149
|
}
|
|
147786
148150
|
if (importKind === 0 /* Named */) {
|
|
147787
|
-
|
|
148151
|
+
var prevValue = entry === null || entry === void 0 ? void 0 : entry.namedImports.get(symbolName);
|
|
148152
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147788
148153
|
}
|
|
147789
148154
|
else {
|
|
147790
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147791
|
-
entry.defaultImport =
|
|
148155
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
148156
|
+
entry.defaultImport = {
|
|
148157
|
+
name: symbolName,
|
|
148158
|
+
addAsTypeOnly: reduceAddAsTypeOnlyValues((_a = entry.defaultImport) === null || _a === void 0 ? void 0 : _a.addAsTypeOnly, addAsTypeOnly),
|
|
148159
|
+
};
|
|
147792
148160
|
}
|
|
147793
148161
|
break;
|
|
147794
148162
|
}
|
|
147795
148163
|
case 3 /* AddNew */: {
|
|
147796
|
-
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire,
|
|
147797
|
-
var entry =
|
|
147798
|
-
|
|
147799
|
-
newImports.set(moduleSpecifier, entry = { namedImports: [], namespaceLikeImport: undefined, typeOnly: typeOnly, useRequire: useRequire });
|
|
147800
|
-
}
|
|
147801
|
-
else {
|
|
147802
|
-
// An import clause can only be type-only if every import fix contributing to it can be type-only.
|
|
147803
|
-
entry.typeOnly = entry.typeOnly && typeOnly;
|
|
147804
|
-
}
|
|
148164
|
+
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, addAsTypeOnly = fix.addAsTypeOnly;
|
|
148165
|
+
var entry = getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly);
|
|
148166
|
+
ts.Debug.assert(entry.useRequire === useRequire, "(Add new) Tried to add an `import` and a `require` for the same module");
|
|
147805
148167
|
switch (importKind) {
|
|
147806
148168
|
case 1 /* Default */:
|
|
147807
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147808
|
-
entry.defaultImport = symbolName;
|
|
148169
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
148170
|
+
entry.defaultImport = { name: symbolName, addAsTypeOnly: reduceAddAsTypeOnlyValues((_b = entry.defaultImport) === null || _b === void 0 ? void 0 : _b.addAsTypeOnly, addAsTypeOnly) };
|
|
147809
148171
|
break;
|
|
147810
148172
|
case 0 /* Named */:
|
|
147811
|
-
|
|
148173
|
+
var prevValue = (entry.namedImports || (entry.namedImports = new ts.Map())).get(symbolName);
|
|
148174
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147812
148175
|
break;
|
|
147813
148176
|
case 3 /* CommonJS */:
|
|
147814
148177
|
case 2 /* Namespace */:
|
|
147815
148178
|
ts.Debug.assert(entry.namespaceLikeImport === undefined || entry.namespaceLikeImport.name === symbolName, "Namespacelike import shoudl be missing or match symbolName");
|
|
147816
|
-
entry.namespaceLikeImport = { importKind: importKind, name: symbolName };
|
|
148179
|
+
entry.namespaceLikeImport = { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly };
|
|
147817
148180
|
break;
|
|
147818
148181
|
}
|
|
147819
148182
|
break;
|
|
@@ -147821,6 +148184,50 @@ var ts;
|
|
|
147821
148184
|
default:
|
|
147822
148185
|
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
|
|
147823
148186
|
}
|
|
148187
|
+
function reduceAddAsTypeOnlyValues(prevValue, newValue) {
|
|
148188
|
+
// `NotAllowed` overrides `Required` because one addition of a new import might be required to be type-only
|
|
148189
|
+
// because of `--importsNotUsedAsValues=error`, but if a second addition of the same import is `NotAllowed`
|
|
148190
|
+
// to be type-only, the reason the first one was `Required` - the unused runtime dependency - is now moot.
|
|
148191
|
+
// Alternatively, if one addition is `Required` because it has no value meaning under `--preserveValueImports`
|
|
148192
|
+
// and `--isolatedModules`, it should be impossible for another addition to be `NotAllowed` since that would
|
|
148193
|
+
// mean a type is being referenced in a value location.
|
|
148194
|
+
return Math.max(prevValue !== null && prevValue !== void 0 ? prevValue : 0, newValue);
|
|
148195
|
+
}
|
|
148196
|
+
function getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly) {
|
|
148197
|
+
// A default import that requires type-only makes the whole import type-only.
|
|
148198
|
+
// (We could add `default` as a named import, but that style seems undesirable.)
|
|
148199
|
+
// Under `--preserveValueImports` and `--importsNotUsedAsValues=error`, if a
|
|
148200
|
+
// module default-exports a type but named-exports some values (weird), you would
|
|
148201
|
+
// have to use a type-only default import and non-type-only named imports. These
|
|
148202
|
+
// require two separate import declarations, so we build this into the map key.
|
|
148203
|
+
var typeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ true);
|
|
148204
|
+
var nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
|
|
148205
|
+
var typeOnlyEntry = newImports.get(typeOnlyKey);
|
|
148206
|
+
var nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
|
|
148207
|
+
var newEntry = {
|
|
148208
|
+
defaultImport: undefined,
|
|
148209
|
+
namedImports: undefined,
|
|
148210
|
+
namespaceLikeImport: undefined,
|
|
148211
|
+
useRequire: useRequire
|
|
148212
|
+
};
|
|
148213
|
+
if (importKind === 1 /* Default */ && addAsTypeOnly === 2 /* Required */) {
|
|
148214
|
+
if (typeOnlyEntry)
|
|
148215
|
+
return typeOnlyEntry;
|
|
148216
|
+
newImports.set(typeOnlyKey, newEntry);
|
|
148217
|
+
return newEntry;
|
|
148218
|
+
}
|
|
148219
|
+
if (addAsTypeOnly === 1 /* Allowed */ && (typeOnlyEntry || nonTypeOnlyEntry)) {
|
|
148220
|
+
return (typeOnlyEntry || nonTypeOnlyEntry);
|
|
148221
|
+
}
|
|
148222
|
+
if (nonTypeOnlyEntry) {
|
|
148223
|
+
return nonTypeOnlyEntry;
|
|
148224
|
+
}
|
|
148225
|
+
newImports.set(nonTypeOnlyKey, newEntry);
|
|
148226
|
+
return newEntry;
|
|
148227
|
+
}
|
|
148228
|
+
function newImportsKey(moduleSpecifier, topLevelTypeOnly) {
|
|
148229
|
+
return (topLevelTypeOnly ? 1 : 0) + "|" + moduleSpecifier;
|
|
148230
|
+
}
|
|
147824
148231
|
}
|
|
147825
148232
|
function writeFixes(changeTracker) {
|
|
147826
148233
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
@@ -147833,14 +148240,22 @@ var ts;
|
|
|
147833
148240
|
addImportType(changeTracker, sourceFile, fix, quotePreference);
|
|
147834
148241
|
}
|
|
147835
148242
|
addToExisting.forEach(function (_a) {
|
|
147836
|
-
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports
|
|
147837
|
-
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports,
|
|
148243
|
+
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports;
|
|
148244
|
+
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
148245
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
148246
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
148247
|
+
}), compilerOptions);
|
|
147838
148248
|
});
|
|
147839
148249
|
var newDeclarations;
|
|
147840
|
-
newImports.forEach(function (_a,
|
|
147841
|
-
var useRequire = _a.useRequire,
|
|
148250
|
+
newImports.forEach(function (_a, key) {
|
|
148251
|
+
var useRequire = _a.useRequire, defaultImport = _a.defaultImport, namedImports = _a.namedImports, namespaceLikeImport = _a.namespaceLikeImport;
|
|
148252
|
+
var moduleSpecifier = key.slice(2); // From `${0 | 1}|${moduleSpecifier}` format
|
|
147842
148253
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147843
|
-
|
|
148254
|
+
var declarations = getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports && ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
148255
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
148256
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
148257
|
+
}), namespaceLikeImport);
|
|
148258
|
+
newDeclarations = ts.combine(newDeclarations, declarations);
|
|
147844
148259
|
});
|
|
147845
148260
|
if (newDeclarations) {
|
|
147846
148261
|
ts.insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
|
|
@@ -147851,24 +148266,37 @@ var ts;
|
|
|
147851
148266
|
var ImportFixKind;
|
|
147852
148267
|
(function (ImportFixKind) {
|
|
147853
148268
|
ImportFixKind[ImportFixKind["UseNamespace"] = 0] = "UseNamespace";
|
|
147854
|
-
ImportFixKind[ImportFixKind["
|
|
148269
|
+
ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
|
|
147855
148270
|
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
|
|
147856
148271
|
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
|
|
147857
148272
|
})(ImportFixKind || (ImportFixKind = {}));
|
|
148273
|
+
// These should not be combined as bitflags, but are given powers of 2 values to
|
|
148274
|
+
// easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
|
|
148275
|
+
// They're also ordered in terms of increasing priority for a fix-all scenario (see
|
|
148276
|
+
// `reduceAddAsTypeOnlyValues`).
|
|
148277
|
+
var AddAsTypeOnly;
|
|
148278
|
+
(function (AddAsTypeOnly) {
|
|
148279
|
+
AddAsTypeOnly[AddAsTypeOnly["Allowed"] = 1] = "Allowed";
|
|
148280
|
+
AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
|
|
148281
|
+
AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
|
|
148282
|
+
})(AddAsTypeOnly || (AddAsTypeOnly = {}));
|
|
147858
148283
|
function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
|
|
147859
148284
|
var compilerOptions = program.getCompilerOptions();
|
|
147860
148285
|
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
|
|
147861
148286
|
? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
|
|
147862
148287
|
: getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
147863
148288
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147864
|
-
var
|
|
147865
|
-
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147866
|
-
return {
|
|
148289
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
148290
|
+
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
|
|
148291
|
+
return {
|
|
148292
|
+
moduleSpecifier: fix.moduleSpecifier,
|
|
148293
|
+
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
|
|
148294
|
+
};
|
|
147867
148295
|
}
|
|
147868
148296
|
codefix.getImportCompletionAction = getImportCompletionAction;
|
|
147869
|
-
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
148297
|
+
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147870
148298
|
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
|
|
147871
|
-
return getBestFix(getImportFixes(exportInfos, symbolName, position,
|
|
148299
|
+
return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
|
|
147872
148300
|
}
|
|
147873
148301
|
function codeFixActionToCodeAction(_a) {
|
|
147874
148302
|
var description = _a.description, changes = _a.changes, commands = _a.commands;
|
|
@@ -147926,24 +148354,21 @@ var ts;
|
|
|
147926
148354
|
function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
|
|
147927
148355
|
var _a = getNewImportFixes(program, importingFile,
|
|
147928
148356
|
/*position*/ undefined,
|
|
147929
|
-
/*
|
|
148357
|
+
/*isValidTypeOnlyUseSite*/ false,
|
|
147930
148358
|
/*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
|
|
147931
148359
|
var result = getBestFix(fixes, importingFile, program, host, preferences);
|
|
147932
148360
|
return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
|
|
147933
148361
|
}
|
|
147934
148362
|
codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
|
|
147935
|
-
function isTypeOnlyPosition(sourceFile, position) {
|
|
147936
|
-
return ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147937
|
-
}
|
|
147938
148363
|
function getImportFixes(exportInfos, symbolName,
|
|
147939
148364
|
/** undefined only for missing JSX namespace */
|
|
147940
|
-
position,
|
|
148365
|
+
position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
|
|
147941
148366
|
var checker = program.getTypeChecker();
|
|
147942
148367
|
var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
|
|
147943
148368
|
var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
|
|
147944
|
-
var addToExisting = tryAddToExistingImport(existingImports,
|
|
148369
|
+
var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
|
|
147945
148370
|
// Don't bother providing an action to add a new import if we can add to an existing one.
|
|
147946
|
-
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
148371
|
+
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147947
148372
|
return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
|
|
147948
148373
|
}
|
|
147949
148374
|
function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
|
|
@@ -147998,14 +148423,34 @@ var ts;
|
|
|
147998
148423
|
return ts.Debug.assertNever(declaration);
|
|
147999
148424
|
}
|
|
148000
148425
|
}
|
|
148001
|
-
function
|
|
148426
|
+
function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, symbol, targetFlags, checker, compilerOptions) {
|
|
148427
|
+
if (!isValidTypeOnlyUseSite) {
|
|
148428
|
+
// Can't use a type-only import if the usage is an emitting position
|
|
148429
|
+
return 4 /* NotAllowed */;
|
|
148430
|
+
}
|
|
148431
|
+
if (isForNewImportDeclaration && compilerOptions.importsNotUsedAsValues === 2 /* Error */) {
|
|
148432
|
+
// Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
|
|
148433
|
+
return 2 /* Required */;
|
|
148434
|
+
}
|
|
148435
|
+
if (compilerOptions.isolatedModules && compilerOptions.preserveValueImports &&
|
|
148436
|
+
(!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
148437
|
+
// A type-only import is required for this symbol if under these settings if the symbol will
|
|
148438
|
+
// be erased, which will happen if the target symbol is purely a type or if it was exported/imported
|
|
148439
|
+
// as type-only already somewhere between this import and the target.
|
|
148440
|
+
return 2 /* Required */;
|
|
148441
|
+
}
|
|
148442
|
+
return 1 /* Allowed */;
|
|
148443
|
+
}
|
|
148444
|
+
function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, compilerOptions) {
|
|
148002
148445
|
return ts.firstDefined(existingImports, function (_a) {
|
|
148003
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
148004
|
-
if (declaration.kind === 264 /* ImportEqualsDeclaration */)
|
|
148446
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
148447
|
+
if (importKind === 3 /* CommonJS */ || importKind === 2 /* Namespace */ || declaration.kind === 264 /* ImportEqualsDeclaration */) {
|
|
148448
|
+
// These kinds of imports are not combinable with anything
|
|
148005
148449
|
return undefined;
|
|
148450
|
+
}
|
|
148006
148451
|
if (declaration.kind === 253 /* VariableDeclaration */) {
|
|
148007
148452
|
return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 200 /* ObjectBindingPattern */
|
|
148008
|
-
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text,
|
|
148453
|
+
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, addAsTypeOnly: 4 /* NotAllowed */ }
|
|
148009
148454
|
: undefined;
|
|
148010
148455
|
}
|
|
148011
148456
|
var importClause = declaration.importClause;
|
|
@@ -148016,13 +148461,29 @@ var ts;
|
|
|
148016
148461
|
// be added to an existing type-only import is adding a named import to existing named bindings.
|
|
148017
148462
|
if (importClause.isTypeOnly && !(importKind === 0 /* Named */ && namedBindings))
|
|
148018
148463
|
return undefined;
|
|
148019
|
-
|
|
148020
|
-
|
|
148021
|
-
|
|
148464
|
+
// N.B. we don't have to figure out whether to use the main program checker
|
|
148465
|
+
// or the AutoImportProvider checker because we're adding to an existing import; the existence of
|
|
148466
|
+
// the import guarantees the symbol came from the main program.
|
|
148467
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ false, symbol, targetFlags, checker, compilerOptions);
|
|
148468
|
+
if (importKind === 1 /* Default */ && (name || // Cannot add a default import to a declaration that already has one
|
|
148469
|
+
addAsTypeOnly === 2 /* Required */ && namedBindings // Cannot add a default import as type-only if the import already has named bindings
|
|
148470
|
+
))
|
|
148471
|
+
return undefined;
|
|
148472
|
+
if (importKind === 0 /* Named */ &&
|
|
148473
|
+
(namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === 267 /* NamespaceImport */ // Cannot add a named import to a declaration that has a namespace import
|
|
148474
|
+
)
|
|
148475
|
+
return undefined;
|
|
148476
|
+
return {
|
|
148477
|
+
kind: 2 /* AddToExisting */,
|
|
148478
|
+
importClauseOrBindingPattern: importClause,
|
|
148479
|
+
importKind: importKind,
|
|
148480
|
+
moduleSpecifier: declaration.moduleSpecifier.text,
|
|
148481
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
148482
|
+
};
|
|
148022
148483
|
});
|
|
148023
148484
|
}
|
|
148024
148485
|
function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
|
|
148025
|
-
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags;
|
|
148486
|
+
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
|
|
148026
148487
|
// Can't use an es6 import for a type in JS.
|
|
148027
148488
|
if (!(targetFlags & 111551 /* Value */) && ts.isSourceFileJS(importingFile))
|
|
148028
148489
|
return ts.emptyArray;
|
|
@@ -148030,10 +148491,10 @@ var ts;
|
|
|
148030
148491
|
return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
|
|
148031
148492
|
var i = ts.importFromModuleSpecifier(moduleSpecifier);
|
|
148032
148493
|
if (ts.isRequireVariableDeclaration(i.parent)) {
|
|
148033
|
-
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind } : undefined;
|
|
148494
|
+
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
148034
148495
|
}
|
|
148035
148496
|
if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
|
|
148036
|
-
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind } : undefined;
|
|
148497
|
+
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
148037
148498
|
}
|
|
148038
148499
|
});
|
|
148039
148500
|
}
|
|
@@ -148065,44 +148526,50 @@ var ts;
|
|
|
148065
148526
|
// 5. Literally nothing to go on
|
|
148066
148527
|
return true;
|
|
148067
148528
|
}
|
|
148068
|
-
function getNewImportFixes(program, sourceFile, position,
|
|
148529
|
+
function getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
|
|
148069
148530
|
var isJs = ts.isSourceFileJS(sourceFile);
|
|
148070
148531
|
var compilerOptions = program.getCompilerOptions();
|
|
148071
148532
|
var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
|
|
148072
|
-
var
|
|
148533
|
+
var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
|
|
148073
148534
|
var getModuleSpecifiers = fromCacheOnly
|
|
148074
148535
|
? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
|
|
148075
|
-
: function (moduleSymbol) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
148536
|
+
: function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
148076
148537
|
var computedWithoutCacheCount = 0;
|
|
148077
148538
|
var fixes = ts.flatMap(moduleSymbols, function (exportInfo) {
|
|
148078
|
-
var
|
|
148539
|
+
var checker = getChecker(exportInfo.isFromPackageJson);
|
|
148540
|
+
var _a = getModuleSpecifiers(exportInfo.moduleSymbol, checker), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
|
|
148541
|
+
var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
|
|
148542
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
|
|
148079
148543
|
computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
|
|
148080
148544
|
return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
|
|
148081
148545
|
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
|
|
148082
|
-
return !
|
|
148083
|
-
? { kind: 1 /*
|
|
148546
|
+
return !importedSymbolHasValueMeaning && isJs && position !== undefined
|
|
148547
|
+
? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
|
|
148084
148548
|
: {
|
|
148085
148549
|
kind: 3 /* AddNew */,
|
|
148086
148550
|
moduleSpecifier: moduleSpecifier,
|
|
148087
148551
|
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
|
|
148088
148552
|
useRequire: useRequire,
|
|
148089
|
-
|
|
148553
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
148090
148554
|
exportInfo: exportInfo,
|
|
148091
148555
|
};
|
|
148092
148556
|
});
|
|
148093
148557
|
});
|
|
148094
148558
|
return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
|
|
148095
148559
|
}
|
|
148096
|
-
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
148097
|
-
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info,
|
|
148098
|
-
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position,
|
|
148560
|
+
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
148561
|
+
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
|
|
148562
|
+
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
|
|
148099
148563
|
}
|
|
148100
|
-
function newImportInfoFromExistingSpecifier(_a,
|
|
148101
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
148564
|
+
function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
|
|
148565
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
148102
148566
|
var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
|
|
148103
|
-
|
|
148104
|
-
|
|
148105
|
-
|
|
148567
|
+
if (moduleSpecifier) {
|
|
148568
|
+
var addAsTypeOnly = useRequire
|
|
148569
|
+
? 4 /* NotAllowed */
|
|
148570
|
+
: getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, symbol, targetFlags, checker, compilerOptions);
|
|
148571
|
+
return { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, addAsTypeOnly: addAsTypeOnly, useRequire: useRequire };
|
|
148572
|
+
}
|
|
148106
148573
|
}
|
|
148107
148574
|
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
|
|
148108
148575
|
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
|
|
@@ -148152,7 +148619,7 @@ var ts;
|
|
|
148152
148619
|
var symbolName = umdSymbol.name;
|
|
148153
148620
|
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
|
|
148154
148621
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
148155
|
-
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*
|
|
148622
|
+
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
|
148156
148623
|
return { fixes: fixes, symbolName: symbolName };
|
|
148157
148624
|
}
|
|
148158
148625
|
function getUmdSymbol(token, checker) {
|
|
@@ -148198,6 +148665,7 @@ var ts;
|
|
|
148198
148665
|
case ts.ModuleKind.System:
|
|
148199
148666
|
case ts.ModuleKind.ES2015:
|
|
148200
148667
|
case ts.ModuleKind.ES2020:
|
|
148668
|
+
case ts.ModuleKind.ES2022:
|
|
148201
148669
|
case ts.ModuleKind.ESNext:
|
|
148202
148670
|
case ts.ModuleKind.None:
|
|
148203
148671
|
// Fall back to the `import * as ns` style import.
|
|
@@ -148216,12 +148684,12 @@ var ts;
|
|
|
148216
148684
|
var symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
|
|
148217
148685
|
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
|
|
148218
148686
|
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
|
|
148219
|
-
var
|
|
148687
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
|
|
148220
148688
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
148221
148689
|
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
148222
148690
|
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
|
|
148223
148691
|
var _ = _a[0], exportInfos = _a[1];
|
|
148224
|
-
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile),
|
|
148692
|
+
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
|
|
148225
148693
|
}));
|
|
148226
148694
|
return { fixes: fixes, symbolName: symbolName };
|
|
148227
148695
|
}
|
|
@@ -148299,63 +148767,81 @@ var ts;
|
|
|
148299
148767
|
// allowSyntheticDefaultImports/esModuleInterop is enabled.
|
|
148300
148768
|
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
|
|
148301
148769
|
}
|
|
148302
|
-
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference) {
|
|
148770
|
+
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
148303
148771
|
var diag;
|
|
148304
148772
|
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
|
|
148305
|
-
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference);
|
|
148773
|
+
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
|
148306
148774
|
});
|
|
148307
148775
|
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
|
|
148308
148776
|
}
|
|
148309
|
-
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference) {
|
|
148777
|
+
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
148310
148778
|
switch (fix.kind) {
|
|
148311
148779
|
case 0 /* UseNamespace */:
|
|
148312
148780
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
148313
148781
|
return [ts.Diagnostics.Change_0_to_1, symbolName, fix.namespacePrefix + "." + symbolName];
|
|
148314
|
-
case 1 /*
|
|
148782
|
+
case 1 /* JsdocTypeImport */:
|
|
148315
148783
|
addImportType(changes, sourceFile, fix, quotePreference);
|
|
148316
148784
|
return [ts.Diagnostics.Change_0_to_1, symbolName, getImportTypePrefix(fix.moduleSpecifier, quotePreference) + symbolName];
|
|
148317
148785
|
case 2 /* AddToExisting */: {
|
|
148318
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
148319
|
-
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName : undefined, importKind === 0 /* Named */ ? [symbolName] : ts.emptyArray,
|
|
148786
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
|
|
148787
|
+
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
|
|
148320
148788
|
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
|
|
148321
|
-
return [
|
|
148789
|
+
return [
|
|
148790
|
+
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,
|
|
148791
|
+
symbolName,
|
|
148792
|
+
moduleSpecifierWithoutQuotes
|
|
148793
|
+
]; // you too!
|
|
148322
148794
|
}
|
|
148323
148795
|
case 3 /* AddNew */: {
|
|
148324
|
-
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier,
|
|
148796
|
+
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
|
|
148325
148797
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
148326
|
-
var
|
|
148327
|
-
|
|
148328
|
-
|
|
148329
|
-
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference,
|
|
148798
|
+
var defaultImport = importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148799
|
+
var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
|
|
148800
|
+
var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148801
|
+
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
|
148330
148802
|
return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
|
|
148331
148803
|
}
|
|
148332
148804
|
default:
|
|
148333
148805
|
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
|
|
148334
148806
|
}
|
|
148335
148807
|
}
|
|
148336
|
-
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports,
|
|
148808
|
+
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
|
|
148809
|
+
var _a;
|
|
148337
148810
|
if (clause.kind === 200 /* ObjectBindingPattern */) {
|
|
148338
148811
|
if (defaultImport) {
|
|
148339
|
-
addElementToBindingPattern(clause, defaultImport, "default");
|
|
148812
|
+
addElementToBindingPattern(clause, defaultImport.name, "default");
|
|
148340
148813
|
}
|
|
148341
148814
|
for (var _i = 0, namedImports_1 = namedImports; _i < namedImports_1.length; _i++) {
|
|
148342
148815
|
var specifier = namedImports_1[_i];
|
|
148343
|
-
addElementToBindingPattern(clause, specifier, /*propertyName*/ undefined);
|
|
148816
|
+
addElementToBindingPattern(clause, specifier.name, /*propertyName*/ undefined);
|
|
148344
148817
|
}
|
|
148345
148818
|
return;
|
|
148346
148819
|
}
|
|
148347
|
-
var
|
|
148820
|
+
var promoteFromTypeOnly = clause.isTypeOnly && ts.some(__spreadArray([defaultImport], namedImports, true), function (i) { return (i === null || i === void 0 ? void 0 : i.addAsTypeOnly) === 4 /* NotAllowed */; });
|
|
148821
|
+
var existingSpecifiers = clause.namedBindings && ((_a = ts.tryCast(clause.namedBindings, ts.isNamedImports)) === null || _a === void 0 ? void 0 : _a.elements);
|
|
148822
|
+
// If we are promoting from a type-only import and `--isolatedModules` and `--preserveValueImports`
|
|
148823
|
+
// are enabled, we need to make every existing import specifier type-only. It may be possible that
|
|
148824
|
+
// some of them don't strictly need to be marked type-only (if they have a value meaning and are
|
|
148825
|
+
// never used in an emitting position). These are allowed to be imported without being type-only,
|
|
148826
|
+
// but the user has clearly already signified that they don't need them to be present at runtime
|
|
148827
|
+
// by placing them in a type-only import. So, just mark each specifier as type-only.
|
|
148828
|
+
var convertExistingToTypeOnly = promoteFromTypeOnly && compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
|
|
148348
148829
|
if (defaultImport) {
|
|
148349
148830
|
ts.Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
148350
|
-
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport), { suffix: ", " });
|
|
148831
|
+
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport.name), { suffix: ", " });
|
|
148351
148832
|
}
|
|
148352
148833
|
if (namedImports.length) {
|
|
148353
|
-
var
|
|
148354
|
-
|
|
148834
|
+
var newSpecifiers = ts.stableSort(namedImports.map(function (namedImport) { return ts.factory.createImportSpecifier((!clause.isTypeOnly || promoteFromTypeOnly) && needsTypeOnly(namedImport),
|
|
148835
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(namedImport.name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
|
|
148355
148836
|
if ((existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) && ts.OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) {
|
|
148356
|
-
for (var
|
|
148357
|
-
var spec = newSpecifiers_1[
|
|
148358
|
-
|
|
148837
|
+
for (var _b = 0, newSpecifiers_1 = newSpecifiers; _b < newSpecifiers_1.length; _b++) {
|
|
148838
|
+
var spec = newSpecifiers_1[_b];
|
|
148839
|
+
// Organize imports puts type-only import specifiers last, so if we're
|
|
148840
|
+
// adding a non-type-only specifier and converting all the other ones to
|
|
148841
|
+
// type-only, there's no need to ask for the insertion index - it's 0.
|
|
148842
|
+
var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
|
|
148843
|
+
? 0
|
|
148844
|
+
: ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
|
|
148359
148845
|
var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
|
|
148360
148846
|
if (prevSpecifier) {
|
|
148361
148847
|
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
|
|
@@ -148366,8 +148852,8 @@ var ts;
|
|
|
148366
148852
|
}
|
|
148367
148853
|
}
|
|
148368
148854
|
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
|
|
148369
|
-
for (var
|
|
148370
|
-
var spec = newSpecifiers_2[
|
|
148855
|
+
for (var _c = 0, newSpecifiers_2 = newSpecifiers; _c < newSpecifiers_2.length; _c++) {
|
|
148856
|
+
var spec = newSpecifiers_2[_c];
|
|
148371
148857
|
changes.insertNodeInListAfter(sourceFile, ts.last(existingSpecifiers), spec, existingSpecifiers);
|
|
148372
148858
|
}
|
|
148373
148859
|
}
|
|
@@ -148383,8 +148869,14 @@ var ts;
|
|
|
148383
148869
|
}
|
|
148384
148870
|
}
|
|
148385
148871
|
}
|
|
148386
|
-
if (
|
|
148872
|
+
if (promoteFromTypeOnly) {
|
|
148387
148873
|
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(clause, sourceFile));
|
|
148874
|
+
if (convertExistingToTypeOnly && existingSpecifiers) {
|
|
148875
|
+
for (var _d = 0, existingSpecifiers_1 = existingSpecifiers; _d < existingSpecifiers_1.length; _d++) {
|
|
148876
|
+
var specifier = existingSpecifiers_1[_d];
|
|
148877
|
+
changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, specifier);
|
|
148878
|
+
}
|
|
148879
|
+
}
|
|
148388
148880
|
}
|
|
148389
148881
|
function addElementToBindingPattern(bindingPattern, name, propertyName) {
|
|
148390
148882
|
var element = ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, propertyName, name);
|
|
@@ -148408,44 +148900,53 @@ var ts;
|
|
|
148408
148900
|
var quote = ts.getQuoteFromPreference(quotePreference);
|
|
148409
148901
|
return "import(" + quote + moduleSpecifier + quote + ").";
|
|
148410
148902
|
}
|
|
148411
|
-
function
|
|
148412
|
-
var _a
|
|
148903
|
+
function needsTypeOnly(_a) {
|
|
148904
|
+
var addAsTypeOnly = _a.addAsTypeOnly;
|
|
148905
|
+
return addAsTypeOnly === 2 /* Required */;
|
|
148906
|
+
}
|
|
148907
|
+
function getNewImports(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
148413
148908
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
148414
148909
|
var statements;
|
|
148415
|
-
if (
|
|
148416
|
-
|
|
148910
|
+
if (defaultImport !== undefined || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148911
|
+
var topLevelTypeOnly_1 = (!defaultImport || needsTypeOnly(defaultImport)) && ts.every(namedImports, needsTypeOnly);
|
|
148912
|
+
statements = ts.combine(statements, ts.makeImport(defaultImport && ts.factory.createIdentifier(defaultImport.name), namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148913
|
+
var addAsTypeOnly = _a.addAsTypeOnly, name = _a.name;
|
|
148914
|
+
return ts.factory.createImportSpecifier(!topLevelTypeOnly_1 && addAsTypeOnly === 2 /* Required */,
|
|
148915
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(name));
|
|
148916
|
+
}), moduleSpecifier, quotePreference, topLevelTypeOnly_1));
|
|
148417
148917
|
}
|
|
148418
|
-
var namespaceLikeImport = imports.namespaceLikeImport, typeOnly = imports.typeOnly;
|
|
148419
148918
|
if (namespaceLikeImport) {
|
|
148420
148919
|
var declaration = namespaceLikeImport.importKind === 3 /* CommonJS */
|
|
148421
148920
|
? ts.factory.createImportEqualsDeclaration(
|
|
148422
148921
|
/*decorators*/ undefined,
|
|
148423
|
-
/*modifiers*/ undefined,
|
|
148922
|
+
/*modifiers*/ undefined, needsTypeOnly(namespaceLikeImport), ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
|
|
148424
148923
|
: ts.factory.createImportDeclaration(
|
|
148425
148924
|
/*decorators*/ undefined,
|
|
148426
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
148925
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(needsTypeOnly(namespaceLikeImport),
|
|
148427
148926
|
/*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier,
|
|
148428
148927
|
/*assertClause*/ undefined);
|
|
148429
148928
|
statements = ts.combine(statements, declaration);
|
|
148430
148929
|
}
|
|
148431
148930
|
return ts.Debug.checkDefined(statements);
|
|
148432
148931
|
}
|
|
148433
|
-
function getNewRequires(moduleSpecifier, quotePreference,
|
|
148434
|
-
var _a, _b;
|
|
148932
|
+
function getNewRequires(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
148435
148933
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
148436
148934
|
var statements;
|
|
148437
148935
|
// const { default: foo, bar, etc } = require('./mod');
|
|
148438
|
-
if (
|
|
148439
|
-
var bindingElements = (
|
|
148440
|
-
|
|
148441
|
-
|
|
148936
|
+
if (defaultImport || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148937
|
+
var bindingElements = (namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148938
|
+
var name = _a.name;
|
|
148939
|
+
return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name);
|
|
148940
|
+
})) || [];
|
|
148941
|
+
if (defaultImport) {
|
|
148942
|
+
bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", defaultImport.name));
|
|
148442
148943
|
}
|
|
148443
148944
|
var declaration = createConstEqualsRequireDeclaration(ts.factory.createObjectBindingPattern(bindingElements), quotedModuleSpecifier);
|
|
148444
148945
|
statements = ts.combine(statements, declaration);
|
|
148445
148946
|
}
|
|
148446
148947
|
// const foo = require('./mod');
|
|
148447
|
-
if (
|
|
148448
|
-
var declaration = createConstEqualsRequireDeclaration(
|
|
148948
|
+
if (namespaceLikeImport) {
|
|
148949
|
+
var declaration = createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier);
|
|
148449
148950
|
statements = ts.combine(statements, declaration);
|
|
148450
148951
|
}
|
|
148451
148952
|
return ts.Debug.checkDefined(statements);
|
|
@@ -149932,8 +150433,8 @@ var ts;
|
|
|
149932
150433
|
(function (codefix) {
|
|
149933
150434
|
codefix.registerCodeFix({
|
|
149934
150435
|
errorCodes: [
|
|
149935
|
-
ts.Diagnostics.
|
|
149936
|
-
ts.Diagnostics.
|
|
150436
|
+
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,
|
|
150437
|
+
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,
|
|
149937
150438
|
],
|
|
149938
150439
|
getCodeActions: function (context) {
|
|
149939
150440
|
var compilerOptions = context.program.getCompilerOptions();
|
|
@@ -152357,7 +152858,7 @@ var ts;
|
|
|
152357
152858
|
return ts.factory.createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
|
|
152358
152859
|
}
|
|
152359
152860
|
function importSymbols(importAdder, symbols) {
|
|
152360
|
-
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*
|
|
152861
|
+
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*isValidTypeOnlyUseSite*/ true); });
|
|
152361
152862
|
}
|
|
152362
152863
|
codefix.importSymbols = importSymbols;
|
|
152363
152864
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -152829,7 +153330,7 @@ var ts;
|
|
|
152829
153330
|
if (!ts.isIdentifier(element.name) || element.initializer) {
|
|
152830
153331
|
return undefined;
|
|
152831
153332
|
}
|
|
152832
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
153333
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152833
153334
|
}
|
|
152834
153335
|
if (importSpecifiers.length) {
|
|
152835
153336
|
return ts.factory.createNamedImports(importSpecifiers);
|
|
@@ -153576,10 +154077,10 @@ var ts;
|
|
|
153576
154077
|
}
|
|
153577
154078
|
}
|
|
153578
154079
|
function makeImportSpecifier(propertyName, name) {
|
|
153579
|
-
return ts.factory.createImportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
154080
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153580
154081
|
}
|
|
153581
154082
|
function makeExportSpecifier(propertyName, name) {
|
|
153582
|
-
return ts.factory.createExportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
154083
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153583
154084
|
}
|
|
153584
154085
|
})(refactor = ts.refactor || (ts.refactor = {}));
|
|
153585
154086
|
})(ts || (ts = {}));
|
|
@@ -153692,7 +154193,7 @@ var ts;
|
|
|
153692
154193
|
}
|
|
153693
154194
|
var importSpecifiers = [];
|
|
153694
154195
|
exportNameToImportName.forEach(function (name, propertyName) {
|
|
153695
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
154196
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153696
154197
|
});
|
|
153697
154198
|
var importDecl = toConvert.parent.parent;
|
|
153698
154199
|
if (usedAsNamespaceOrDefault && !allowSyntheticDefaultImports) {
|
|
@@ -153763,7 +154264,7 @@ var ts;
|
|
|
153763
154264
|
changes.replaceNode(sourceFile, toConvert, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
|
|
153764
154265
|
if (neededNamedImports.size) {
|
|
153765
154266
|
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
|
|
153766
|
-
return ts.factory.createImportSpecifier(element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
154267
|
+
return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153767
154268
|
});
|
|
153768
154269
|
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
|
|
153769
154270
|
}
|
|
@@ -156465,7 +156966,7 @@ var ts;
|
|
|
156465
156966
|
function makeImportOrRequire(defaultImport, imports, path, useEs6Imports, quotePreference) {
|
|
156466
156967
|
path = ts.ensurePathIsNonModuleName(path);
|
|
156467
156968
|
if (useEs6Imports) {
|
|
156468
|
-
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156969
|
+
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156469
156970
|
return ts.makeImportIfNecessary(defaultImport, specifiers, path, quotePreference);
|
|
156470
156971
|
}
|
|
156471
156972
|
else {
|