@typescript-deploys/pr-build 4.6.0-pr-47590-5 → 4.7.0-pr-47904-2
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 +9 -3
- package/lib/de/diagnosticMessages.generated.json +4 -0
- package/lib/es/diagnosticMessages.generated.json +4 -0
- package/lib/fr/diagnosticMessages.generated.json +9 -3
- package/lib/it/diagnosticMessages.generated.json +9 -3
- package/lib/ja/diagnosticMessages.generated.json +4 -0
- package/lib/ko/diagnosticMessages.generated.json +4 -0
- package/lib/lib.esnext.intl.d.ts +4 -1
- package/lib/pl/diagnosticMessages.generated.json +9 -3
- package/lib/protocol.d.ts +7 -0
- package/lib/pt-br/diagnosticMessages.generated.json +4 -0
- package/lib/ru/diagnosticMessages.generated.json +4 -0
- package/lib/tr/diagnosticMessages.generated.json +4 -0
- package/lib/tsc.js +411 -350
- package/lib/tsserver.js +599 -441
- package/lib/tsserverlibrary.d.ts +30 -24
- package/lib/tsserverlibrary.js +599 -441
- package/lib/typescript.d.ts +22 -23
- package/lib/typescript.js +597 -439
- package/lib/typescriptServices.d.ts +22 -23
- package/lib/typescriptServices.js +597 -439
- package/lib/typingsInstaller.js +518 -427
- package/lib/zh-cn/diagnosticMessages.generated.json +4 -0
- package/lib/zh-tw/diagnosticMessages.generated.json +9 -3
- package/package.json +1 -1
package/lib/tsserver.js
CHANGED
|
@@ -96,11 +96,11 @@ var ts;
|
|
|
96
96
|
(function (ts) {
|
|
97
97
|
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
|
|
98
98
|
// If changing the text in this section, be sure to test `configurePrerelease` too.
|
|
99
|
-
ts.versionMajorMinor = "4.
|
|
99
|
+
ts.versionMajorMinor = "4.7";
|
|
100
100
|
// The following is baselined as a literal template type without intervention
|
|
101
101
|
/** The version of the TypeScript compiler release */
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
103
|
-
ts.version = ts.versionMajorMinor + ".0-insiders.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-insiders.20220215";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -4840,6 +4840,8 @@ var ts;
|
|
|
4840
4840
|
TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
|
|
4841
4841
|
TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
|
|
4842
4842
|
/* @internal */
|
|
4843
|
+
TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
|
|
4844
|
+
/* @internal */
|
|
4843
4845
|
TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
|
|
4844
4846
|
TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
|
|
4845
4847
|
TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
|
|
@@ -5572,6 +5574,8 @@ var ts;
|
|
|
5572
5574
|
BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
|
|
5573
5575
|
BundleFileSectionKind["Reference"] = "reference";
|
|
5574
5576
|
BundleFileSectionKind["Type"] = "type";
|
|
5577
|
+
BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
|
|
5578
|
+
BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
|
|
5575
5579
|
BundleFileSectionKind["Lib"] = "lib";
|
|
5576
5580
|
BundleFileSectionKind["Prepend"] = "prepend";
|
|
5577
5581
|
BundleFileSectionKind["Text"] = "text";
|
|
@@ -5688,7 +5692,8 @@ var ts;
|
|
|
5688
5692
|
{ name: "types", optional: true, captureSpan: true },
|
|
5689
5693
|
{ name: "lib", optional: true, captureSpan: true },
|
|
5690
5694
|
{ name: "path", optional: true, captureSpan: true },
|
|
5691
|
-
{ name: "no-default-lib", optional: true }
|
|
5695
|
+
{ name: "no-default-lib", optional: true },
|
|
5696
|
+
{ name: "resolution-mode", optional: true }
|
|
5692
5697
|
],
|
|
5693
5698
|
kind: 1 /* TripleSlashXML */
|
|
5694
5699
|
},
|
|
@@ -7636,18 +7641,6 @@ var ts;
|
|
|
7636
7641
|
return getCanonicalFileName(nonCanonicalizedPath);
|
|
7637
7642
|
}
|
|
7638
7643
|
ts.toPath = toPath;
|
|
7639
|
-
function normalizePathAndParts(path) {
|
|
7640
|
-
path = normalizeSlashes(path);
|
|
7641
|
-
var _a = reducePathComponents(getPathComponents(path)), root = _a[0], parts = _a.slice(1);
|
|
7642
|
-
if (parts.length) {
|
|
7643
|
-
var joinedParts = root + parts.join(ts.directorySeparator);
|
|
7644
|
-
return { path: hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(joinedParts) : joinedParts, parts: parts };
|
|
7645
|
-
}
|
|
7646
|
-
else {
|
|
7647
|
-
return { path: root, parts: parts };
|
|
7648
|
-
}
|
|
7649
|
-
}
|
|
7650
|
-
ts.normalizePathAndParts = normalizePathAndParts;
|
|
7651
7644
|
function removeTrailingDirectorySeparator(path) {
|
|
7652
7645
|
if (hasTrailingDirectorySeparator(path)) {
|
|
7653
7646
|
return path.substr(0, path.length - 1);
|
|
@@ -8081,6 +8074,8 @@ var ts;
|
|
|
8081
8074
|
Property_0_cannot_have_an_initializer_because_it_is_marked_abstract: diag(1267, ts.DiagnosticCategory.Error, "Property_0_cannot_have_an_initializer_because_it_is_marked_abstract_1267", "Property '{0}' cannot have an initializer because it is marked abstract."),
|
|
8082
8075
|
An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type: diag(1268, ts.DiagnosticCategory.Error, "An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type_1268", "An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type."),
|
|
8083
8076
|
Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided: diag(1269, ts.DiagnosticCategory.Error, "Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided_1269", "Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided."),
|
|
8077
|
+
Decorator_function_return_type_0_is_not_assignable_to_type_1: diag(1270, ts.DiagnosticCategory.Error, "Decorator_function_return_type_0_is_not_assignable_to_type_1_1270", "Decorator function return type '{0}' is not assignable to type '{1}'."),
|
|
8078
|
+
Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any: diag(1271, ts.DiagnosticCategory.Error, "Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any_1271", "Decorator function return type is '{0}' but is expected to be 'void' or 'any'."),
|
|
8084
8079
|
with_statements_are_not_allowed_in_an_async_function_block: diag(1300, ts.DiagnosticCategory.Error, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
|
|
8085
8080
|
await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, ts.DiagnosticCategory.Error, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
|
|
8086
8081
|
Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern: diag(1312, ts.DiagnosticCategory.Error, "Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_1312", "Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern."),
|
|
@@ -8214,6 +8209,8 @@ var ts;
|
|
|
8214
8209
|
Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."),
|
|
8215
8210
|
Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"),
|
|
8216
8211
|
Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"),
|
|
8212
|
+
Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node12` or `nodenext`."),
|
|
8213
|
+
resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."),
|
|
8217
8214
|
The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
|
|
8218
8215
|
Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
|
|
8219
8216
|
catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
|
|
@@ -11751,8 +11748,6 @@ var ts;
|
|
|
11751
11748
|
case 39 /* singleQuote */:
|
|
11752
11749
|
tokenValue = scanString(/*jsxAttributeString*/ true);
|
|
11753
11750
|
return token = 10 /* StringLiteral */;
|
|
11754
|
-
case 96 /* backtick */:
|
|
11755
|
-
return token = scanTemplateAndSetTokenValue(/*isTaggedTemplate*/ false);
|
|
11756
11751
|
default:
|
|
11757
11752
|
// If this scans anything other than `{`, it's a parse error.
|
|
11758
11753
|
return scan();
|
|
@@ -13760,11 +13755,6 @@ var ts;
|
|
|
13760
13755
|
|| kind === 287 /* JsxExpression */;
|
|
13761
13756
|
}
|
|
13762
13757
|
ts.isStringLiteralOrJsxExpression = isStringLiteralOrJsxExpression;
|
|
13763
|
-
/* @internal */
|
|
13764
|
-
function isStringLiteralOrTemplateExpressionOrJsxExpression(node) {
|
|
13765
|
-
return node.kind === 222 /* TemplateExpression */ || isStringLiteralOrJsxExpression(node);
|
|
13766
|
-
}
|
|
13767
|
-
ts.isStringLiteralOrTemplateExpressionOrJsxExpression = isStringLiteralOrTemplateExpressionOrJsxExpression;
|
|
13768
13758
|
function isJsxOpeningLikeElement(node) {
|
|
13769
13759
|
var kind = node.kind;
|
|
13770
13760
|
return kind === 279 /* JsxOpeningElement */
|
|
@@ -14104,7 +14094,11 @@ var ts;
|
|
|
14104
14094
|
ts.Debug.assert(names.length === newResolutions.length);
|
|
14105
14095
|
for (var i = 0; i < names.length; i++) {
|
|
14106
14096
|
var newResolution = newResolutions[i];
|
|
14107
|
-
var
|
|
14097
|
+
var entry = names[i];
|
|
14098
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
14099
|
+
var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
|
|
14100
|
+
var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
|
|
14101
|
+
var oldResolution = oldResolutions && oldResolutions.get(name, mode);
|
|
14108
14102
|
var changed = oldResolution
|
|
14109
14103
|
? !newResolution || !comparer(oldResolution, newResolution)
|
|
14110
14104
|
: newResolution;
|
|
@@ -26699,7 +26693,13 @@ var ts;
|
|
|
26699
26693
|
referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
|
|
26700
26694
|
break;
|
|
26701
26695
|
case "type" /* Type */:
|
|
26702
|
-
typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
|
|
26696
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
|
|
26697
|
+
break;
|
|
26698
|
+
case "type-import" /* TypeResolutionModeImport */:
|
|
26699
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
|
|
26700
|
+
break;
|
|
26701
|
+
case "type-require" /* TypeResolutionModeRequire */:
|
|
26702
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
|
|
26703
26703
|
break;
|
|
26704
26704
|
case "lib" /* Lib */:
|
|
26705
26705
|
libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
|
|
@@ -26758,6 +26758,8 @@ var ts;
|
|
|
26758
26758
|
case "no-default-lib" /* NoDefaultLib */:
|
|
26759
26759
|
case "reference" /* Reference */:
|
|
26760
26760
|
case "type" /* Type */:
|
|
26761
|
+
case "type-import" /* TypeResolutionModeImport */:
|
|
26762
|
+
case "type-require" /* TypeResolutionModeRequire */:
|
|
26761
26763
|
case "lib" /* Lib */:
|
|
26762
26764
|
syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
|
|
26763
26765
|
break;
|
|
@@ -34462,26 +34464,15 @@ var ts;
|
|
|
34462
34464
|
}
|
|
34463
34465
|
return finishNode(factory.createJsxExpression(dotDotDotToken, expression), pos);
|
|
34464
34466
|
}
|
|
34465
|
-
function parseJsxAttributeValue() {
|
|
34466
|
-
if (token() !== 63 /* EqualsToken */) {
|
|
34467
|
-
return undefined;
|
|
34468
|
-
}
|
|
34469
|
-
var jsxAttributeValueToken = scanJsxAttributeValue();
|
|
34470
|
-
if (jsxAttributeValueToken === 10 /* StringLiteral */ || jsxAttributeValueToken === 14 /* NoSubstitutionTemplateLiteral */) {
|
|
34471
|
-
return parseLiteralNode();
|
|
34472
|
-
}
|
|
34473
|
-
if (jsxAttributeValueToken === 15 /* TemplateHead */) {
|
|
34474
|
-
return parseTemplateExpression(/*isTaggedTemplate*/ false);
|
|
34475
|
-
}
|
|
34476
|
-
return parseJsxExpression(/*inExpressionContext*/ true);
|
|
34477
|
-
}
|
|
34478
34467
|
function parseJsxAttribute() {
|
|
34479
34468
|
if (token() === 18 /* OpenBraceToken */) {
|
|
34480
34469
|
return parseJsxSpreadAttribute();
|
|
34481
34470
|
}
|
|
34482
34471
|
scanJsxIdentifier();
|
|
34483
34472
|
var pos = getNodePos();
|
|
34484
|
-
return finishNode(factory.createJsxAttribute(parseIdentifierName(),
|
|
34473
|
+
return finishNode(factory.createJsxAttribute(parseIdentifierName(), token() !== 63 /* EqualsToken */ ? undefined :
|
|
34474
|
+
scanJsxAttributeValue() === 10 /* StringLiteral */ ? parseLiteralNode() :
|
|
34475
|
+
parseJsxExpression(/*inExpressionContext*/ true)), pos);
|
|
34485
34476
|
}
|
|
34486
34477
|
function parseJsxSpreadAttribute() {
|
|
34487
34478
|
var pos = getNodePos();
|
|
@@ -35107,11 +35098,12 @@ var ts;
|
|
|
35107
35098
|
}
|
|
35108
35099
|
function parseCaseClause() {
|
|
35109
35100
|
var pos = getNodePos();
|
|
35101
|
+
var hasJSDoc = hasPrecedingJSDocComment();
|
|
35110
35102
|
parseExpected(82 /* CaseKeyword */);
|
|
35111
35103
|
var expression = allowInAnd(parseExpression);
|
|
35112
35104
|
parseExpected(58 /* ColonToken */);
|
|
35113
35105
|
var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
|
|
35114
|
-
return finishNode(factory.createCaseClause(expression, statements), pos);
|
|
35106
|
+
return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
|
|
35115
35107
|
}
|
|
35116
35108
|
function parseDefaultClause() {
|
|
35117
35109
|
var pos = getNodePos();
|
|
@@ -38001,6 +37993,19 @@ var ts;
|
|
|
38001
37993
|
return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
|
|
38002
37994
|
}
|
|
38003
37995
|
ts.isDeclarationFileName = isDeclarationFileName;
|
|
37996
|
+
function parseResolutionMode(mode, pos, end, reportDiagnostic) {
|
|
37997
|
+
if (!mode) {
|
|
37998
|
+
return undefined;
|
|
37999
|
+
}
|
|
38000
|
+
if (mode === "import") {
|
|
38001
|
+
return ts.ModuleKind.ESNext;
|
|
38002
|
+
}
|
|
38003
|
+
if (mode === "require") {
|
|
38004
|
+
return ts.ModuleKind.CommonJS;
|
|
38005
|
+
}
|
|
38006
|
+
reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
|
|
38007
|
+
return undefined;
|
|
38008
|
+
}
|
|
38004
38009
|
/*@internal*/
|
|
38005
38010
|
function processCommentPragmas(context, sourceText) {
|
|
38006
38011
|
var pragmas = [];
|
|
@@ -38043,12 +38048,13 @@ var ts;
|
|
|
38043
38048
|
var typeReferenceDirectives_1 = context.typeReferenceDirectives;
|
|
38044
38049
|
var libReferenceDirectives_1 = context.libReferenceDirectives;
|
|
38045
38050
|
ts.forEach(ts.toArray(entryOrList), function (arg) {
|
|
38046
|
-
var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
|
|
38051
|
+
var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
|
|
38047
38052
|
if (arg.arguments["no-default-lib"]) {
|
|
38048
38053
|
context.hasNoDefaultLib = true;
|
|
38049
38054
|
}
|
|
38050
38055
|
else if (types) {
|
|
38051
|
-
|
|
38056
|
+
var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
|
|
38057
|
+
typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
|
|
38052
38058
|
}
|
|
38053
38059
|
else if (lib) {
|
|
38054
38060
|
libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
|
|
@@ -41626,14 +41632,14 @@ var ts;
|
|
|
41626
41632
|
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
|
41627
41633
|
* is assumed to be the same as root directory of the project.
|
|
41628
41634
|
*/
|
|
41629
|
-
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
|
|
41635
|
+
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
|
|
41630
41636
|
var traceEnabled = isTraceEnabled(options, host);
|
|
41631
41637
|
if (redirectedReference) {
|
|
41632
41638
|
options = redirectedReference.commandLine.options;
|
|
41633
41639
|
}
|
|
41634
41640
|
var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
|
|
41635
41641
|
var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
|
|
41636
|
-
var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/
|
|
41642
|
+
var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
|
|
41637
41643
|
if (result) {
|
|
41638
41644
|
if (traceEnabled) {
|
|
41639
41645
|
trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
|
|
@@ -41668,7 +41674,18 @@ var ts;
|
|
|
41668
41674
|
}
|
|
41669
41675
|
var failedLookupLocations = [];
|
|
41670
41676
|
var features = getDefaultNodeResolutionFeatures(options);
|
|
41671
|
-
|
|
41677
|
+
// Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
|
|
41678
|
+
// setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
|
|
41679
|
+
// set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
|
|
41680
|
+
// are present in a non-modal project; while in theory we'd like to either ignore the mode or provide faithful modern resolution, depending on what we feel is best,
|
|
41681
|
+
// in practice, not every cache has the options available to intelligently make the choice to ignore the mode request, and it's unclear how modern "faithful modern
|
|
41682
|
+
// resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
|
|
41683
|
+
// context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
|
|
41684
|
+
if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
|
|
41685
|
+
features |= NodeResolutionFeatures.EsmMode;
|
|
41686
|
+
}
|
|
41687
|
+
var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
|
|
41688
|
+
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
|
|
41672
41689
|
var resolved = primaryLookup();
|
|
41673
41690
|
var primary = true;
|
|
41674
41691
|
if (!resolved) {
|
|
@@ -41688,7 +41705,7 @@ var ts;
|
|
|
41688
41705
|
};
|
|
41689
41706
|
}
|
|
41690
41707
|
result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
|
|
41691
|
-
perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/
|
|
41708
|
+
perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
|
|
41692
41709
|
if (traceEnabled)
|
|
41693
41710
|
traceResult(result);
|
|
41694
41711
|
return result;
|
|
@@ -41739,7 +41756,7 @@ var ts;
|
|
|
41739
41756
|
result_4 = searchResult && searchResult.value;
|
|
41740
41757
|
}
|
|
41741
41758
|
else {
|
|
41742
|
-
var candidate =
|
|
41759
|
+
var candidate = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName).path;
|
|
41743
41760
|
result_4 = nodeLoadModuleByRelativeName(Extensions.DtsOnly, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true);
|
|
41744
41761
|
}
|
|
41745
41762
|
return resolvedTypeScriptOnly(result_4);
|
|
@@ -41974,7 +41991,11 @@ var ts;
|
|
|
41974
41991
|
ts.Debug.assert(keys.length === values.length);
|
|
41975
41992
|
var map = createModeAwareCache();
|
|
41976
41993
|
for (var i = 0; i < keys.length; ++i) {
|
|
41977
|
-
|
|
41994
|
+
var entry = keys[i];
|
|
41995
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
41996
|
+
var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
|
|
41997
|
+
var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
|
|
41998
|
+
map.set(name, mode, values[i]);
|
|
41978
41999
|
}
|
|
41979
42000
|
return map;
|
|
41980
42001
|
}
|
|
@@ -42442,13 +42463,25 @@ var ts;
|
|
|
42442
42463
|
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
|
|
42443
42464
|
}
|
|
42444
42465
|
else {
|
|
42445
|
-
var _a =
|
|
42466
|
+
var _a = normalizePathForCJSResolution(containingDirectory, moduleName), candidate = _a.path, parts = _a.parts;
|
|
42446
42467
|
var resolved_2 = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
|
|
42447
42468
|
// Treat explicit "node_modules" import as an external library import.
|
|
42448
42469
|
return resolved_2 && toSearchResult({ resolved: resolved_2, isExternalLibraryImport: ts.contains(parts, "node_modules") });
|
|
42449
42470
|
}
|
|
42450
42471
|
}
|
|
42451
42472
|
}
|
|
42473
|
+
// If you import from "." inside a containing directory "/foo", the result of `normalizePath`
|
|
42474
|
+
// would be "/foo", but this loses the information that `foo` is a directory and we intended
|
|
42475
|
+
// to look inside of it. The Node CommonJS resolution algorithm doesn't call this out
|
|
42476
|
+
// (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
|
|
42477
|
+
// in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
|
|
42478
|
+
function normalizePathForCJSResolution(containingDirectory, moduleName) {
|
|
42479
|
+
var combined = ts.combinePaths(containingDirectory, moduleName);
|
|
42480
|
+
var parts = ts.getPathComponents(combined);
|
|
42481
|
+
var lastPart = ts.lastOrUndefined(parts);
|
|
42482
|
+
var path = lastPart === "." || lastPart === ".." ? ts.ensureTrailingDirectorySeparator(ts.normalizePath(combined)) : ts.normalizePath(combined);
|
|
42483
|
+
return { path: path, parts: parts };
|
|
42484
|
+
}
|
|
42452
42485
|
function realPath(path, host, traceEnabled) {
|
|
42453
42486
|
if (!host.realpath) {
|
|
42454
42487
|
return path;
|
|
@@ -42490,7 +42523,13 @@ var ts;
|
|
|
42490
42523
|
onlyRecordFailures = true;
|
|
42491
42524
|
}
|
|
42492
42525
|
}
|
|
42493
|
-
|
|
42526
|
+
// esm mode relative imports shouldn't do any directory lookups (either inside `package.json`
|
|
42527
|
+
// files or implicit `index.js`es). This is a notable depature from cjs norms, where `./foo/pkg`
|
|
42528
|
+
// could have been redirected by `./foo/pkg/package.json` to an arbitrary location!
|
|
42529
|
+
if (!(state.features & NodeResolutionFeatures.EsmMode)) {
|
|
42530
|
+
return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
|
|
42531
|
+
}
|
|
42532
|
+
return undefined;
|
|
42494
42533
|
}
|
|
42495
42534
|
/*@internal*/
|
|
42496
42535
|
ts.nodeModulesPathPart = "/node_modules/";
|
|
@@ -42857,7 +42896,16 @@ var ts;
|
|
|
42857
42896
|
// Even if extensions is DtsOnly, we can still look up a .ts file as a result of package.json "types"
|
|
42858
42897
|
var nextExtensions = extensions === Extensions.DtsOnly ? Extensions.TypeScript : extensions;
|
|
42859
42898
|
// Don't do package.json lookup recursively, because Node.js' package lookup doesn't.
|
|
42860
|
-
|
|
42899
|
+
// Disable `EsmMode` for the resolution of the package path for cjs-mode packages (so the `main` field can omit extensions)
|
|
42900
|
+
// (technically it only emits a deprecation warning in esm packages right now, but that's probably
|
|
42901
|
+
// enough to mean we don't need to support it)
|
|
42902
|
+
var features = state.features;
|
|
42903
|
+
if ((jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.type) !== "module") {
|
|
42904
|
+
state.features &= ~NodeResolutionFeatures.EsmMode;
|
|
42905
|
+
}
|
|
42906
|
+
var result = nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
|
|
42907
|
+
state.features = features;
|
|
42908
|
+
return result;
|
|
42861
42909
|
};
|
|
42862
42910
|
var onlyRecordFailuresForPackageFile = packageFile ? !ts.directoryProbablyExists(ts.getDirectoryPath(packageFile), state.host) : undefined;
|
|
42863
42911
|
var onlyRecordFailuresForIndex = onlyRecordFailures || !ts.directoryProbablyExists(candidate, state.host);
|
|
@@ -43202,6 +43250,14 @@ var ts;
|
|
|
43202
43250
|
}
|
|
43203
43251
|
var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
|
|
43204
43252
|
loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths);
|
|
43253
|
+
if (!pathAndExtension && packageInfo
|
|
43254
|
+
&& packageInfo.packageJsonContent.exports === undefined
|
|
43255
|
+
&& packageInfo.packageJsonContent.main === undefined
|
|
43256
|
+
&& state.features & NodeResolutionFeatures.EsmMode) {
|
|
43257
|
+
// EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
|
|
43258
|
+
// a default `index.js` entrypoint if no `main` or `exports` are present
|
|
43259
|
+
pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state);
|
|
43260
|
+
}
|
|
43205
43261
|
return withPackageId(packageInfo, pathAndExtension);
|
|
43206
43262
|
};
|
|
43207
43263
|
if (rest !== "") { // If "rest" is empty, we just did this search above.
|
|
@@ -45968,12 +46024,14 @@ var ts;
|
|
|
45968
46024
|
}
|
|
45969
46025
|
}
|
|
45970
46026
|
function setCommonJsModuleIndicator(node) {
|
|
45971
|
-
if (file.externalModuleIndicator) {
|
|
46027
|
+
if (file.externalModuleIndicator && file.commonJsModuleIndicator) {
|
|
45972
46028
|
return false;
|
|
45973
46029
|
}
|
|
45974
|
-
if (
|
|
46030
|
+
if (file.commonJsModuleIndicator === undefined) {
|
|
45975
46031
|
file.commonJsModuleIndicator = node;
|
|
45976
|
-
|
|
46032
|
+
if (file.externalModuleIndicator === undefined) {
|
|
46033
|
+
bindSourceFileAsExternalModule();
|
|
46034
|
+
}
|
|
45977
46035
|
}
|
|
45978
46036
|
return true;
|
|
45979
46037
|
}
|
|
@@ -46959,8 +47017,7 @@ var ts;
|
|
|
46959
47017
|
IntersectionState[IntersectionState["Source"] = 1] = "Source";
|
|
46960
47018
|
IntersectionState[IntersectionState["Target"] = 2] = "Target";
|
|
46961
47019
|
IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
|
|
46962
|
-
IntersectionState[IntersectionState["
|
|
46963
|
-
IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
|
|
47020
|
+
IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
|
|
46964
47021
|
})(IntersectionState || (IntersectionState = {}));
|
|
46965
47022
|
var RecursionFlags;
|
|
46966
47023
|
(function (RecursionFlags) {
|
|
@@ -50419,8 +50476,15 @@ var ts;
|
|
|
50419
50476
|
return res;
|
|
50420
50477
|
}
|
|
50421
50478
|
var candidates = ts.mapDefined(symbol.declarations, function (d) {
|
|
50422
|
-
if (!ts.isAmbientModule(d) && d.parent
|
|
50423
|
-
|
|
50479
|
+
if (!ts.isAmbientModule(d) && d.parent) {
|
|
50480
|
+
// direct children of a module
|
|
50481
|
+
if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
|
|
50482
|
+
return getSymbolOfNode(d.parent);
|
|
50483
|
+
}
|
|
50484
|
+
// export ='d member of an ambient module
|
|
50485
|
+
if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
|
|
50486
|
+
return getSymbolOfNode(d.parent.parent);
|
|
50487
|
+
}
|
|
50424
50488
|
}
|
|
50425
50489
|
if (ts.isClassExpression(d) && ts.isBinaryExpression(d.parent) && d.parent.operatorToken.kind === 63 /* EqualsToken */ && ts.isAccessExpression(d.parent.left) && ts.isEntityNameExpression(d.parent.left.expression)) {
|
|
50426
50490
|
if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
|
|
@@ -58674,13 +58738,15 @@ var ts;
|
|
|
58674
58738
|
return signature;
|
|
58675
58739
|
}
|
|
58676
58740
|
function getOrCreateTypeFromSignature(signature) {
|
|
58741
|
+
var _a;
|
|
58677
58742
|
// There are two ways to declare a construct signature, one is by declaring a class constructor
|
|
58678
58743
|
// using the constructor keyword, and the other is declaring a bare construct signature in an
|
|
58679
58744
|
// object type literal or interface (using the new keyword). Each way of declaring a constructor
|
|
58680
58745
|
// will result in a different declaration kind.
|
|
58681
58746
|
if (!signature.isolatedSignatureType) {
|
|
58682
|
-
var kind =
|
|
58683
|
-
|
|
58747
|
+
var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
|
|
58748
|
+
// If declaration is undefined, it is likely to be the signature of the default constructor.
|
|
58749
|
+
var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
|
|
58684
58750
|
var type = createObjectType(16 /* Anonymous */);
|
|
58685
58751
|
type.members = emptySymbols;
|
|
58686
58752
|
type.properties = ts.emptyArray;
|
|
@@ -63155,9 +63221,11 @@ var ts;
|
|
|
63155
63221
|
isEnumTypeRelatedTo(getParentOfSymbol(source.symbol), getParentOfSymbol(target.symbol), errorReporter))
|
|
63156
63222
|
return true;
|
|
63157
63223
|
}
|
|
63158
|
-
|
|
63224
|
+
// In non-strictNullChecks mode, `undefined` and `null` are assignable to anything except `never`.
|
|
63225
|
+
// Since unions and intersections may reduce to `never`, we exclude them here.
|
|
63226
|
+
if (s & 32768 /* Undefined */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & (32768 /* Undefined */ | 16384 /* Void */)))
|
|
63159
63227
|
return true;
|
|
63160
|
-
if (s & 65536 /* Null */ && (!strictNullChecks || t & 65536 /* Null */))
|
|
63228
|
+
if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
|
|
63161
63229
|
return true;
|
|
63162
63230
|
if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
|
|
63163
63231
|
return true;
|
|
@@ -63246,11 +63314,11 @@ var ts;
|
|
|
63246
63314
|
var overflow = false;
|
|
63247
63315
|
var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
|
|
63248
63316
|
var lastSkippedInfo;
|
|
63249
|
-
var incompatibleStack
|
|
63317
|
+
var incompatibleStack;
|
|
63250
63318
|
var inPropertyCheck = false;
|
|
63251
63319
|
ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
|
|
63252
63320
|
var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
|
|
63253
|
-
if (incompatibleStack
|
|
63321
|
+
if (incompatibleStack) {
|
|
63254
63322
|
reportIncompatibleStack();
|
|
63255
63323
|
}
|
|
63256
63324
|
if (overflow) {
|
|
@@ -63307,19 +63375,19 @@ var ts;
|
|
|
63307
63375
|
return {
|
|
63308
63376
|
errorInfo: errorInfo,
|
|
63309
63377
|
lastSkippedInfo: lastSkippedInfo,
|
|
63310
|
-
incompatibleStack: incompatibleStack.slice(),
|
|
63378
|
+
incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
|
|
63311
63379
|
overrideNextErrorInfo: overrideNextErrorInfo,
|
|
63312
|
-
relatedInfo:
|
|
63380
|
+
relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
|
|
63313
63381
|
};
|
|
63314
63382
|
}
|
|
63315
63383
|
function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
|
|
63316
63384
|
overrideNextErrorInfo++; // Suppress the next relation error
|
|
63317
63385
|
lastSkippedInfo = undefined; // Reset skipped info cache
|
|
63318
|
-
incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
|
|
63386
|
+
(incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
|
|
63319
63387
|
}
|
|
63320
63388
|
function reportIncompatibleStack() {
|
|
63321
|
-
var stack = incompatibleStack;
|
|
63322
|
-
incompatibleStack =
|
|
63389
|
+
var stack = incompatibleStack || [];
|
|
63390
|
+
incompatibleStack = undefined;
|
|
63323
63391
|
var info = lastSkippedInfo;
|
|
63324
63392
|
lastSkippedInfo = undefined;
|
|
63325
63393
|
if (stack.length === 1) {
|
|
@@ -63425,7 +63493,7 @@ var ts;
|
|
|
63425
63493
|
}
|
|
63426
63494
|
function reportError(message, arg0, arg1, arg2, arg3) {
|
|
63427
63495
|
ts.Debug.assert(!!errorNode);
|
|
63428
|
-
if (incompatibleStack
|
|
63496
|
+
if (incompatibleStack)
|
|
63429
63497
|
reportIncompatibleStack();
|
|
63430
63498
|
if (message.elidedInCompatabilityPyramid)
|
|
63431
63499
|
return;
|
|
@@ -63441,7 +63509,7 @@ var ts;
|
|
|
63441
63509
|
}
|
|
63442
63510
|
}
|
|
63443
63511
|
function reportRelationError(message, source, target) {
|
|
63444
|
-
if (incompatibleStack
|
|
63512
|
+
if (incompatibleStack)
|
|
63445
63513
|
reportIncompatibleStack();
|
|
63446
63514
|
var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
|
|
63447
63515
|
var generalizedSource = source;
|
|
@@ -63553,7 +63621,9 @@ var ts;
|
|
|
63553
63621
|
if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
|
|
63554
63622
|
return -1 /* True */;
|
|
63555
63623
|
}
|
|
63556
|
-
|
|
63624
|
+
if (reportErrors) {
|
|
63625
|
+
reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
|
|
63626
|
+
}
|
|
63557
63627
|
return 0 /* False */;
|
|
63558
63628
|
}
|
|
63559
63629
|
// Normalize the source and target types: Turn fresh literal types into regular literal types,
|
|
@@ -63565,7 +63635,12 @@ var ts;
|
|
|
63565
63635
|
if (source === target)
|
|
63566
63636
|
return -1 /* True */;
|
|
63567
63637
|
if (relation === identityRelation) {
|
|
63568
|
-
|
|
63638
|
+
if (source.flags !== target.flags)
|
|
63639
|
+
return 0 /* False */;
|
|
63640
|
+
if (source.flags & 67358815 /* Singleton */)
|
|
63641
|
+
return -1 /* True */;
|
|
63642
|
+
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63643
|
+
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
63569
63644
|
}
|
|
63570
63645
|
// We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
|
|
63571
63646
|
// and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
|
|
@@ -63575,163 +63650,130 @@ var ts;
|
|
|
63575
63650
|
if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
|
|
63576
63651
|
return -1 /* True */;
|
|
63577
63652
|
}
|
|
63578
|
-
//
|
|
63579
|
-
// If so,
|
|
63580
|
-
|
|
63581
|
-
|
|
63582
|
-
|
|
63583
|
-
|
|
63584
|
-
|
|
63585
|
-
|
|
63586
|
-
|
|
63587
|
-
|
|
63588
|
-
|
|
63589
|
-
|
|
63590
|
-
if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
|
|
63591
|
-
target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
|
|
63592
|
-
}
|
|
63593
|
-
if (source === nullStrippedTarget)
|
|
63594
|
-
return -1 /* True */;
|
|
63653
|
+
// See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
|
|
63654
|
+
// plus a single non-nullable type. If so, remove null and/or undefined from the target type.
|
|
63655
|
+
if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
|
|
63656
|
+
var types = target.types;
|
|
63657
|
+
var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
|
|
63658
|
+
types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
|
|
63659
|
+
undefined;
|
|
63660
|
+
if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
|
|
63661
|
+
target = getNormalizedType(candidate, /*writing*/ true);
|
|
63662
|
+
if (source === target)
|
|
63663
|
+
return -1 /* True */;
|
|
63664
|
+
}
|
|
63595
63665
|
}
|
|
63596
63666
|
if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
|
|
63597
63667
|
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
|
|
63598
63668
|
return -1 /* True */;
|
|
63599
|
-
|
|
63600
|
-
|
|
63601
|
-
|
|
63602
|
-
|
|
63669
|
+
if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
|
|
63670
|
+
var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
|
|
63671
|
+
if (isPerformingExcessPropertyChecks) {
|
|
63672
|
+
if (hasExcessProperties(source, target, reportErrors)) {
|
|
63673
|
+
if (reportErrors) {
|
|
63674
|
+
reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
|
|
63675
|
+
}
|
|
63676
|
+
return 0 /* False */;
|
|
63677
|
+
}
|
|
63678
|
+
}
|
|
63679
|
+
var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
|
|
63680
|
+
source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
|
|
63681
|
+
target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
|
|
63682
|
+
(getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
|
|
63683
|
+
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
|
|
63684
|
+
if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
|
|
63603
63685
|
if (reportErrors) {
|
|
63604
|
-
|
|
63686
|
+
var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
|
|
63687
|
+
var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
|
|
63688
|
+
var calls = getSignaturesOfType(source, 0 /* Call */);
|
|
63689
|
+
var constructs = getSignaturesOfType(source, 1 /* Construct */);
|
|
63690
|
+
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
|
|
63691
|
+
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
|
|
63692
|
+
reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
|
|
63693
|
+
}
|
|
63694
|
+
else {
|
|
63695
|
+
reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
|
|
63696
|
+
}
|
|
63605
63697
|
}
|
|
63606
63698
|
return 0 /* False */;
|
|
63607
63699
|
}
|
|
63608
|
-
|
|
63609
|
-
|
|
63610
|
-
|
|
63611
|
-
|
|
63612
|
-
|
|
63613
|
-
|
|
63614
|
-
|
|
63615
|
-
|
|
63616
|
-
|
|
63617
|
-
|
|
63618
|
-
|
|
63619
|
-
|
|
63620
|
-
|
|
63621
|
-
|
|
63622
|
-
|
|
63623
|
-
|
|
63624
|
-
|
|
63625
|
-
|
|
63700
|
+
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63701
|
+
var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
|
|
63702
|
+
target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
|
|
63703
|
+
var result_7 = skipCaching ?
|
|
63704
|
+
unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
|
|
63705
|
+
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
|
|
63706
|
+
// For certain combinations involving intersections and optional, excess, or mismatched properties we need
|
|
63707
|
+
// an extra property check where the intersection is viewed as a single object. The following are motivating
|
|
63708
|
+
// examples that all should be errors, but aren't without this extra property check:
|
|
63709
|
+
//
|
|
63710
|
+
// let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
|
|
63711
|
+
//
|
|
63712
|
+
// declare let wrong: { a: { y: string } };
|
|
63713
|
+
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
|
|
63714
|
+
//
|
|
63715
|
+
// function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
|
|
63716
|
+
// x = y; // Mismatched property in source intersection
|
|
63717
|
+
// }
|
|
63718
|
+
//
|
|
63719
|
+
// We suppress recursive intersection property checks because they can generate lots of work when relating
|
|
63720
|
+
// recursive intersections that are structurally similar but not exactly identical. See #37854.
|
|
63721
|
+
if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
63722
|
+
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 */); }))) {
|
|
63723
|
+
inPropertyCheck = true;
|
|
63724
|
+
result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
63725
|
+
inPropertyCheck = false;
|
|
63726
|
+
}
|
|
63727
|
+
if (result_7) {
|
|
63728
|
+
return result_7;
|
|
63626
63729
|
}
|
|
63627
|
-
return 0 /* False */;
|
|
63628
|
-
}
|
|
63629
|
-
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63630
|
-
var result = 0 /* False */;
|
|
63631
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
63632
|
-
if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
|
|
63633
|
-
// We skip caching when source or target is a union with no more than three constituents.
|
|
63634
|
-
result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
|
|
63635
63730
|
}
|
|
63636
|
-
|
|
63637
|
-
|
|
63731
|
+
if (reportErrors) {
|
|
63732
|
+
reportErrorResults(originalSource, originalTarget, source, target, headMessage);
|
|
63638
63733
|
}
|
|
63639
|
-
|
|
63640
|
-
|
|
63641
|
-
|
|
63734
|
+
return 0 /* False */;
|
|
63735
|
+
}
|
|
63736
|
+
function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
|
|
63737
|
+
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
63738
|
+
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
63739
|
+
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
63740
|
+
target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
|
|
63741
|
+
var maybeSuppress = overrideNextErrorInfo > 0;
|
|
63742
|
+
if (maybeSuppress) {
|
|
63743
|
+
overrideNextErrorInfo--;
|
|
63744
|
+
}
|
|
63745
|
+
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
63746
|
+
var currentError = errorInfo;
|
|
63747
|
+
tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
|
|
63748
|
+
if (errorInfo !== currentError) {
|
|
63749
|
+
maybeSuppress = !!errorInfo;
|
|
63750
|
+
}
|
|
63751
|
+
}
|
|
63752
|
+
if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
|
|
63753
|
+
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
63754
|
+
}
|
|
63755
|
+
else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
|
|
63756
|
+
reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
|
|
63757
|
+
}
|
|
63758
|
+
else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
|
|
63759
|
+
var targetTypes = target.types;
|
|
63760
|
+
var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
|
|
63761
|
+
var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
|
|
63762
|
+
if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
|
|
63763
|
+
(ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
|
|
63764
|
+
// do not report top error
|
|
63765
|
+
return;
|
|
63642
63766
|
}
|
|
63643
63767
|
}
|
|
63644
|
-
|
|
63645
|
-
|
|
63646
|
-
// the constituents. When an intersection type contains instantiable types with union type
|
|
63647
|
-
// constraints, there are situations where we need to examine the combined constraint. One is
|
|
63648
|
-
// when the target is a union type. Another is when the intersection contains types belonging
|
|
63649
|
-
// to one of the disjoint domains. For example, given type variables T and U, each with the
|
|
63650
|
-
// constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
|
|
63651
|
-
// we need to check this constraint against a union on the target side. Also, given a type
|
|
63652
|
-
// variable V constrained to 'string | number', 'V & number' has a combined constraint of
|
|
63653
|
-
// 'string & number | number & number' which reduces to just 'number'.
|
|
63654
|
-
// This also handles type parameters, as a type parameter with a union constraint compared against a union
|
|
63655
|
-
// needs to have its constraint hoisted into an intersection with said type parameter, this way
|
|
63656
|
-
// the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
|
|
63657
|
-
// For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
|
|
63658
|
-
var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
|
|
63659
|
-
if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
|
|
63660
|
-
if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
63661
|
-
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
63662
|
-
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63663
|
-
resetErrorInfo(saveErrorInfo);
|
|
63664
|
-
}
|
|
63665
|
-
}
|
|
63666
|
-
}
|
|
63768
|
+
else {
|
|
63769
|
+
errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
|
|
63667
63770
|
}
|
|
63668
|
-
|
|
63669
|
-
|
|
63670
|
-
|
|
63671
|
-
|
|
63672
|
-
// let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
|
|
63673
|
-
//
|
|
63674
|
-
// declare let wrong: { a: { y: string } };
|
|
63675
|
-
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
|
|
63676
|
-
//
|
|
63677
|
-
// function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
|
|
63678
|
-
// x = y; // Mismatched property in source intersection
|
|
63679
|
-
// }
|
|
63680
|
-
//
|
|
63681
|
-
// We suppress recursive intersection property checks because they can generate lots of work when relating
|
|
63682
|
-
// recursive intersections that are structurally similar but not exactly identical. See #37854.
|
|
63683
|
-
if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
63684
|
-
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 */); }))) {
|
|
63685
|
-
inPropertyCheck = true;
|
|
63686
|
-
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
63687
|
-
inPropertyCheck = false;
|
|
63688
|
-
}
|
|
63689
|
-
reportErrorResults(source, target, result, isComparingJsxAttributes);
|
|
63690
|
-
return result;
|
|
63691
|
-
function reportErrorResults(source, target, result, isComparingJsxAttributes) {
|
|
63692
|
-
if (!result && reportErrors) {
|
|
63693
|
-
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
63694
|
-
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
63695
|
-
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
63696
|
-
target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
|
|
63697
|
-
var maybeSuppress = overrideNextErrorInfo > 0;
|
|
63698
|
-
if (maybeSuppress) {
|
|
63699
|
-
overrideNextErrorInfo--;
|
|
63700
|
-
}
|
|
63701
|
-
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
63702
|
-
var currentError = errorInfo;
|
|
63703
|
-
tryElaborateArrayLikeErrors(source, target, reportErrors);
|
|
63704
|
-
if (errorInfo !== currentError) {
|
|
63705
|
-
maybeSuppress = !!errorInfo;
|
|
63706
|
-
}
|
|
63707
|
-
}
|
|
63708
|
-
if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
|
|
63709
|
-
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
63710
|
-
}
|
|
63711
|
-
else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
|
|
63712
|
-
reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
|
|
63713
|
-
}
|
|
63714
|
-
else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
|
|
63715
|
-
var targetTypes = target.types;
|
|
63716
|
-
var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
|
|
63717
|
-
var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
|
|
63718
|
-
if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
|
|
63719
|
-
(ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
|
|
63720
|
-
// do not report top error
|
|
63721
|
-
return result;
|
|
63722
|
-
}
|
|
63723
|
-
}
|
|
63724
|
-
else {
|
|
63725
|
-
errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
|
|
63726
|
-
}
|
|
63727
|
-
if (!headMessage && maybeSuppress) {
|
|
63728
|
-
lastSkippedInfo = [source, target];
|
|
63729
|
-
// Used by, eg, missing property checking to replace the top-level message with a more informative one
|
|
63730
|
-
return result;
|
|
63731
|
-
}
|
|
63732
|
-
reportRelationError(headMessage, source, target);
|
|
63733
|
-
}
|
|
63771
|
+
if (!headMessage && maybeSuppress) {
|
|
63772
|
+
lastSkippedInfo = [source, target];
|
|
63773
|
+
// Used by, eg, missing property checking to replace the top-level message with a more informative one
|
|
63774
|
+
return;
|
|
63734
63775
|
}
|
|
63776
|
+
reportRelationError(headMessage, source, target);
|
|
63735
63777
|
}
|
|
63736
63778
|
function traceUnionsOrIntersectionsTooLarge(source, target) {
|
|
63737
63779
|
if (!ts.tracing) {
|
|
@@ -63758,21 +63800,6 @@ var ts;
|
|
|
63758
63800
|
}
|
|
63759
63801
|
}
|
|
63760
63802
|
}
|
|
63761
|
-
function isIdenticalTo(source, target, recursionFlags) {
|
|
63762
|
-
if (source.flags !== target.flags)
|
|
63763
|
-
return 0 /* False */;
|
|
63764
|
-
if (source.flags & 67358815 /* Singleton */)
|
|
63765
|
-
return -1 /* True */;
|
|
63766
|
-
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63767
|
-
if (source.flags & 3145728 /* UnionOrIntersection */) {
|
|
63768
|
-
var result_7 = eachTypeRelatedToSomeType(source, target);
|
|
63769
|
-
if (result_7) {
|
|
63770
|
-
result_7 &= eachTypeRelatedToSomeType(target, source);
|
|
63771
|
-
}
|
|
63772
|
-
return result_7;
|
|
63773
|
-
}
|
|
63774
|
-
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
63775
|
-
}
|
|
63776
63803
|
function getTypeOfPropertyInTypes(types, name) {
|
|
63777
63804
|
var appendPropType = function (propTypes, type) {
|
|
63778
63805
|
var _a;
|
|
@@ -63871,6 +63898,41 @@ var ts;
|
|
|
63871
63898
|
function shouldCheckAsExcessProperty(prop, container) {
|
|
63872
63899
|
return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
|
|
63873
63900
|
}
|
|
63901
|
+
function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
|
|
63902
|
+
// Note that these checks are specifically ordered to produce correct results. In particular,
|
|
63903
|
+
// we need to deconstruct unions before intersections (because unions are always at the top),
|
|
63904
|
+
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
|
63905
|
+
if (source.flags & 1048576 /* Union */) {
|
|
63906
|
+
return relation === comparableRelation ?
|
|
63907
|
+
someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
|
|
63908
|
+
eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
|
|
63909
|
+
}
|
|
63910
|
+
if (target.flags & 1048576 /* Union */) {
|
|
63911
|
+
return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
|
|
63912
|
+
}
|
|
63913
|
+
if (target.flags & 2097152 /* Intersection */) {
|
|
63914
|
+
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
|
|
63915
|
+
}
|
|
63916
|
+
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
|
|
63917
|
+
// constraints of all non-primitive types in the source into a new intersection. We do this because the
|
|
63918
|
+
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
|
|
63919
|
+
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
|
|
63920
|
+
// appear to be comparable to '2'.
|
|
63921
|
+
if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
|
|
63922
|
+
var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
|
|
63923
|
+
if (constraints !== source.types) {
|
|
63924
|
+
source = getIntersectionType(constraints);
|
|
63925
|
+
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
63926
|
+
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
63927
|
+
}
|
|
63928
|
+
}
|
|
63929
|
+
}
|
|
63930
|
+
// Check to see if any constituents of the intersection are immediately related to the target.
|
|
63931
|
+
// Don't report errors though. Elaborating on whether a source constituent is related to the target is
|
|
63932
|
+
// not actually useful and leads to some confusing error messages. Instead, we rely on the caller
|
|
63933
|
+
// checking whether the full intersection viewed as an object is related to the target.
|
|
63934
|
+
return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
|
|
63935
|
+
}
|
|
63874
63936
|
function eachTypeRelatedToSomeType(source, target) {
|
|
63875
63937
|
var result = -1 /* True */;
|
|
63876
63938
|
var sourceTypes = source.types;
|
|
@@ -63906,8 +63968,11 @@ var ts;
|
|
|
63906
63968
|
}
|
|
63907
63969
|
}
|
|
63908
63970
|
if (reportErrors) {
|
|
63971
|
+
// Elaborate only if we can find a best matching type in the target union
|
|
63909
63972
|
var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
|
|
63910
|
-
|
|
63973
|
+
if (bestMatchingType) {
|
|
63974
|
+
isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
|
|
63975
|
+
}
|
|
63911
63976
|
}
|
|
63912
63977
|
return 0 /* False */;
|
|
63913
63978
|
}
|
|
@@ -64043,7 +64108,7 @@ var ts;
|
|
|
64043
64108
|
if (overflow) {
|
|
64044
64109
|
return 0 /* False */;
|
|
64045
64110
|
}
|
|
64046
|
-
var keyIntersectionState = intersectionState | (inPropertyCheck ?
|
|
64111
|
+
var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
|
|
64047
64112
|
var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
|
|
64048
64113
|
var entry = relation.get(id);
|
|
64049
64114
|
if (entry !== undefined) {
|
|
@@ -64111,6 +64176,7 @@ var ts;
|
|
|
64111
64176
|
return originalHandler(onlyUnreliable);
|
|
64112
64177
|
};
|
|
64113
64178
|
}
|
|
64179
|
+
var result;
|
|
64114
64180
|
if (expandingFlags === 3 /* Both */) {
|
|
64115
64181
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
|
|
64116
64182
|
sourceId: source.id,
|
|
@@ -64120,8 +64186,13 @@ var ts;
|
|
|
64120
64186
|
depth: sourceDepth,
|
|
64121
64187
|
targetDepth: targetDepth
|
|
64122
64188
|
});
|
|
64189
|
+
result = 3 /* Maybe */;
|
|
64190
|
+
}
|
|
64191
|
+
else {
|
|
64192
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
|
|
64193
|
+
result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
|
|
64194
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
64123
64195
|
}
|
|
64124
|
-
var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
|
|
64125
64196
|
if (outofbandVarianceMarkerHandler) {
|
|
64126
64197
|
outofbandVarianceMarkerHandler = originalHandler;
|
|
64127
64198
|
}
|
|
@@ -64153,98 +64224,97 @@ var ts;
|
|
|
64153
64224
|
return result;
|
|
64154
64225
|
}
|
|
64155
64226
|
function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
|
|
64156
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
|
|
64157
|
-
var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
|
|
64158
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
64159
|
-
return result;
|
|
64160
|
-
}
|
|
64161
|
-
function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
|
|
64162
64227
|
if (intersectionState & 4 /* PropertyCheck */) {
|
|
64163
64228
|
return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
|
|
64164
64229
|
}
|
|
64165
|
-
|
|
64166
|
-
|
|
64167
|
-
|
|
64168
|
-
|
|
64169
|
-
|
|
64170
|
-
|
|
64171
|
-
|
|
64172
|
-
|
|
64173
|
-
|
|
64174
|
-
|
|
64175
|
-
|
|
64176
|
-
|
|
64177
|
-
if (target.flags & 2097152 /* Intersection */) {
|
|
64178
|
-
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
|
|
64179
|
-
}
|
|
64180
|
-
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
|
|
64181
|
-
// constraints of all non-primitive types in the source into a new intersection. We do this because the
|
|
64182
|
-
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
|
|
64183
|
-
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
|
|
64184
|
-
// appear to be comparable to '2'.
|
|
64185
|
-
if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
|
|
64186
|
-
var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
|
|
64187
|
-
if (constraints !== source.types) {
|
|
64188
|
-
source = getIntersectionType(constraints);
|
|
64189
|
-
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
64190
|
-
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
64191
|
-
}
|
|
64230
|
+
var result;
|
|
64231
|
+
var originalErrorInfo;
|
|
64232
|
+
var varianceCheckFailed = false;
|
|
64233
|
+
var saveErrorInfo = captureErrorCalculationState();
|
|
64234
|
+
var sourceFlags = source.flags;
|
|
64235
|
+
var targetFlags = target.flags;
|
|
64236
|
+
if (relation === identityRelation) {
|
|
64237
|
+
// We've already checked that source.flags and target.flags are identical
|
|
64238
|
+
if (sourceFlags & 3145728 /* UnionOrIntersection */) {
|
|
64239
|
+
var result_8 = eachTypeRelatedToSomeType(source, target);
|
|
64240
|
+
if (result_8) {
|
|
64241
|
+
result_8 &= eachTypeRelatedToSomeType(target, source);
|
|
64192
64242
|
}
|
|
64243
|
+
return result_8;
|
|
64193
64244
|
}
|
|
64194
|
-
|
|
64195
|
-
//
|
|
64196
|
-
// Don't report errors though. Checking whether a constituent is related to the source is not actually
|
|
64197
|
-
// useful and leads to some confusing error messages. Instead it is better to let the below checks
|
|
64198
|
-
// take care of this, or to not elaborate at all. For instance,
|
|
64199
|
-
//
|
|
64200
|
-
// - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
|
|
64201
|
-
//
|
|
64202
|
-
// - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
|
|
64203
|
-
// than to report that 'D' is not assignable to 'A' or 'B'.
|
|
64204
|
-
//
|
|
64205
|
-
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
|
|
64206
|
-
// breaking the intersection apart.
|
|
64207
|
-
return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
|
|
64208
|
-
}
|
|
64209
|
-
var flags = source.flags & target.flags;
|
|
64210
|
-
if (relation === identityRelation && !(flags & 524288 /* Object */)) {
|
|
64211
|
-
if (flags & 4194304 /* Index */) {
|
|
64245
|
+
if (sourceFlags & 4194304 /* Index */) {
|
|
64212
64246
|
return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
|
|
64213
64247
|
}
|
|
64214
|
-
|
|
64215
|
-
|
|
64216
|
-
|
|
64217
|
-
|
|
64218
|
-
return result_8;
|
|
64248
|
+
if (sourceFlags & 8388608 /* IndexedAccess */) {
|
|
64249
|
+
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64250
|
+
if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64251
|
+
return result;
|
|
64219
64252
|
}
|
|
64220
64253
|
}
|
|
64221
64254
|
}
|
|
64222
|
-
if (
|
|
64255
|
+
if (sourceFlags & 16777216 /* Conditional */) {
|
|
64223
64256
|
if (source.root.isDistributive === target.root.isDistributive) {
|
|
64224
|
-
if (
|
|
64225
|
-
if (
|
|
64226
|
-
if (
|
|
64227
|
-
if (
|
|
64228
|
-
return
|
|
64257
|
+
if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64258
|
+
if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64259
|
+
if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
64260
|
+
if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
64261
|
+
return result;
|
|
64229
64262
|
}
|
|
64230
64263
|
}
|
|
64231
64264
|
}
|
|
64232
64265
|
}
|
|
64233
64266
|
}
|
|
64234
64267
|
}
|
|
64235
|
-
if (
|
|
64268
|
+
if (sourceFlags & 33554432 /* Substitution */) {
|
|
64236
64269
|
return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
|
|
64237
64270
|
}
|
|
64238
|
-
|
|
64271
|
+
if (!(sourceFlags & 524288 /* Object */)) {
|
|
64272
|
+
return 0 /* False */;
|
|
64273
|
+
}
|
|
64274
|
+
}
|
|
64275
|
+
else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
|
|
64276
|
+
if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
|
|
64277
|
+
return result;
|
|
64278
|
+
}
|
|
64279
|
+
if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
|
|
64280
|
+
// The combined constraint of an intersection type is the intersection of the constraints of
|
|
64281
|
+
// the constituents. When an intersection type contains instantiable types with union type
|
|
64282
|
+
// constraints, there are situations where we need to examine the combined constraint. One is
|
|
64283
|
+
// when the target is a union type. Another is when the intersection contains types belonging
|
|
64284
|
+
// to one of the disjoint domains. For example, given type variables T and U, each with the
|
|
64285
|
+
// constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
|
|
64286
|
+
// we need to check this constraint against a union on the target side. Also, given a type
|
|
64287
|
+
// variable V constrained to 'string | number', 'V & number' has a combined constraint of
|
|
64288
|
+
// 'string & number | number & number' which reduces to just 'number'.
|
|
64289
|
+
// This also handles type parameters, as a type parameter with a union constraint compared against a union
|
|
64290
|
+
// needs to have its constraint hoisted into an intersection with said type parameter, this way
|
|
64291
|
+
// the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
|
|
64292
|
+
// For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
|
|
64293
|
+
var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
|
|
64294
|
+
if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
64295
|
+
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
64296
|
+
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
64297
|
+
resetErrorInfo(saveErrorInfo);
|
|
64298
|
+
return result;
|
|
64299
|
+
}
|
|
64300
|
+
}
|
|
64301
|
+
}
|
|
64302
|
+
// The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
|
|
64303
|
+
// Source is instantiable (e.g. source has union or intersection constraint).
|
|
64304
|
+
// Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
|
|
64305
|
+
// Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
|
|
64306
|
+
// Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
|
|
64307
|
+
// Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
|
|
64308
|
+
if (!(sourceFlags & 465829888 /* Instantiable */ ||
|
|
64309
|
+
sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
|
|
64310
|
+
sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
|
|
64311
|
+
return 0 /* False */;
|
|
64312
|
+
}
|
|
64239
64313
|
}
|
|
64240
|
-
var result;
|
|
64241
|
-
var originalErrorInfo;
|
|
64242
|
-
var varianceCheckFailed = false;
|
|
64243
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
64244
64314
|
// We limit alias variance probing to only object and conditional types since their alias behavior
|
|
64245
64315
|
// is more predictable than other, interned types, which may or may not have an alias depending on
|
|
64246
64316
|
// the order in which things were checked.
|
|
64247
|
-
if (
|
|
64317
|
+
if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
|
|
64248
64318
|
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
|
|
64249
64319
|
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
|
|
64250
64320
|
var variances = getAliasVariances(source.aliasSymbol);
|
|
@@ -64262,7 +64332,7 @@ var ts;
|
|
|
64262
64332
|
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
|
|
64263
64333
|
return result;
|
|
64264
64334
|
}
|
|
64265
|
-
if (
|
|
64335
|
+
if (targetFlags & 262144 /* TypeParameter */) {
|
|
64266
64336
|
// 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].
|
|
64267
64337
|
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
|
|
64268
64338
|
if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
|
|
@@ -64274,10 +64344,10 @@ var ts;
|
|
|
64274
64344
|
}
|
|
64275
64345
|
}
|
|
64276
64346
|
}
|
|
64277
|
-
else if (
|
|
64347
|
+
else if (targetFlags & 4194304 /* Index */) {
|
|
64278
64348
|
var targetType_1 = target.type;
|
|
64279
64349
|
// A keyof S is related to a keyof T if T is related to S.
|
|
64280
|
-
if (
|
|
64350
|
+
if (sourceFlags & 4194304 /* Index */) {
|
|
64281
64351
|
if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64282
64352
|
return result;
|
|
64283
64353
|
}
|
|
@@ -64328,8 +64398,8 @@ var ts;
|
|
|
64328
64398
|
}
|
|
64329
64399
|
}
|
|
64330
64400
|
}
|
|
64331
|
-
else if (
|
|
64332
|
-
if (
|
|
64401
|
+
else if (targetFlags & 8388608 /* IndexedAccess */) {
|
|
64402
|
+
if (sourceFlags & 8388608 /* IndexedAccess */) {
|
|
64333
64403
|
// Relate components directly before falling back to constraint relationships
|
|
64334
64404
|
// A type S[K] is related to a type T[J] if S is related to T and K is related to J.
|
|
64335
64405
|
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
|
|
@@ -64435,7 +64505,7 @@ var ts;
|
|
|
64435
64505
|
}
|
|
64436
64506
|
}
|
|
64437
64507
|
}
|
|
64438
|
-
else if (
|
|
64508
|
+
else if (targetFlags & 16777216 /* Conditional */) {
|
|
64439
64509
|
// If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
|
|
64440
64510
|
// conditional type and bail out with a Ternary.Maybe result.
|
|
64441
64511
|
if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
|
|
@@ -64460,8 +64530,8 @@ var ts;
|
|
|
64460
64530
|
}
|
|
64461
64531
|
}
|
|
64462
64532
|
}
|
|
64463
|
-
else if (
|
|
64464
|
-
if (
|
|
64533
|
+
else if (targetFlags & 134217728 /* TemplateLiteral */) {
|
|
64534
|
+
if (sourceFlags & 134217728 /* TemplateLiteral */) {
|
|
64465
64535
|
if (relation === comparableRelation) {
|
|
64466
64536
|
return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
|
|
64467
64537
|
}
|
|
@@ -64473,11 +64543,11 @@ var ts;
|
|
|
64473
64543
|
return -1 /* True */;
|
|
64474
64544
|
}
|
|
64475
64545
|
}
|
|
64476
|
-
if (
|
|
64477
|
-
// IndexedAccess comparisons are handled above in the `
|
|
64478
|
-
if (!(
|
|
64546
|
+
if (sourceFlags & 8650752 /* TypeVariable */) {
|
|
64547
|
+
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
|
|
64548
|
+
if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
|
|
64479
64549
|
var constraint = getConstraintOfType(source);
|
|
64480
|
-
if (!constraint || (
|
|
64550
|
+
if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
64481
64551
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
64482
64552
|
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
64483
64553
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64490,7 +64560,7 @@ var ts;
|
|
|
64490
64560
|
return result;
|
|
64491
64561
|
}
|
|
64492
64562
|
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
|
|
64493
|
-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(
|
|
64563
|
+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
64494
64564
|
resetErrorInfo(saveErrorInfo);
|
|
64495
64565
|
return result;
|
|
64496
64566
|
}
|
|
@@ -64507,14 +64577,14 @@ var ts;
|
|
|
64507
64577
|
}
|
|
64508
64578
|
}
|
|
64509
64579
|
}
|
|
64510
|
-
else if (
|
|
64580
|
+
else if (sourceFlags & 4194304 /* Index */) {
|
|
64511
64581
|
if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
|
|
64512
64582
|
resetErrorInfo(saveErrorInfo);
|
|
64513
64583
|
return result;
|
|
64514
64584
|
}
|
|
64515
64585
|
}
|
|
64516
|
-
else if (
|
|
64517
|
-
if (!(
|
|
64586
|
+
else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
|
|
64587
|
+
if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
|
|
64518
64588
|
var constraint = getBaseConstraintOfType(source);
|
|
64519
64589
|
if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
64520
64590
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64522,8 +64592,8 @@ var ts;
|
|
|
64522
64592
|
}
|
|
64523
64593
|
}
|
|
64524
64594
|
}
|
|
64525
|
-
else if (
|
|
64526
|
-
if (
|
|
64595
|
+
else if (sourceFlags & 268435456 /* StringMapping */) {
|
|
64596
|
+
if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
|
|
64527
64597
|
if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
|
|
64528
64598
|
resetErrorInfo(saveErrorInfo);
|
|
64529
64599
|
return result;
|
|
@@ -64537,14 +64607,14 @@ var ts;
|
|
|
64537
64607
|
}
|
|
64538
64608
|
}
|
|
64539
64609
|
}
|
|
64540
|
-
else if (
|
|
64610
|
+
else if (sourceFlags & 16777216 /* Conditional */) {
|
|
64541
64611
|
// If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
|
|
64542
64612
|
// conditional type and bail out with a Ternary.Maybe result.
|
|
64543
64613
|
if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
|
|
64544
64614
|
resetErrorInfo(saveErrorInfo);
|
|
64545
64615
|
return 3 /* Maybe */;
|
|
64546
64616
|
}
|
|
64547
|
-
if (
|
|
64617
|
+
if (targetFlags & 16777216 /* Conditional */) {
|
|
64548
64618
|
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
|
|
64549
64619
|
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
|
|
64550
64620
|
// and Y1 is related to Y2.
|
|
@@ -64604,15 +64674,21 @@ var ts;
|
|
|
64604
64674
|
}
|
|
64605
64675
|
return 0 /* False */;
|
|
64606
64676
|
}
|
|
64607
|
-
var sourceIsPrimitive = !!(
|
|
64677
|
+
var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
|
|
64608
64678
|
if (relation !== identityRelation) {
|
|
64609
64679
|
source = getApparentType(source);
|
|
64680
|
+
sourceFlags = source.flags;
|
|
64610
64681
|
}
|
|
64611
64682
|
else if (isGenericMappedType(source)) {
|
|
64612
64683
|
return 0 /* False */;
|
|
64613
64684
|
}
|
|
64614
64685
|
if (ts.getObjectFlags(source) & 4 /* Reference */ && ts.getObjectFlags(target) & 4 /* Reference */ && source.target === target.target &&
|
|
64615
64686
|
!isTupleType(source) && !(ts.getObjectFlags(source) & 4096 /* MarkerType */ || ts.getObjectFlags(target) & 4096 /* MarkerType */)) {
|
|
64687
|
+
// When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
|
|
64688
|
+
// and an empty array literal wouldn't be assignable to a `never[]` without this check.
|
|
64689
|
+
if (isEmptyArrayLiteralType(source)) {
|
|
64690
|
+
return -1 /* True */;
|
|
64691
|
+
}
|
|
64616
64692
|
// We have type references to the same generic type, and the type references are not marker
|
|
64617
64693
|
// type references (which are intended by be compared structurally). Obtain the variance
|
|
64618
64694
|
// information for the type parameters and relate the type arguments accordingly.
|
|
@@ -64648,7 +64724,7 @@ var ts;
|
|
|
64648
64724
|
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
|
|
64649
64725
|
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
|
|
64650
64726
|
// relates to X. Thus, we include intersection types on the source side here.
|
|
64651
|
-
if (
|
|
64727
|
+
if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
|
|
64652
64728
|
// Report structural errors only if we haven't reported any errors yet
|
|
64653
64729
|
var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
|
|
64654
64730
|
result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
|
|
@@ -64672,7 +64748,7 @@ var ts;
|
|
|
64672
64748
|
// there exists a constituent of T for every combination of the discriminants of S
|
|
64673
64749
|
// with respect to T. We do not report errors here, as we will use the existing
|
|
64674
64750
|
// error result from checking each constituent of the union.
|
|
64675
|
-
if (
|
|
64751
|
+
if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
|
|
64676
64752
|
var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
|
|
64677
64753
|
if (objectOnlyTarget.flags & 1048576 /* Union */) {
|
|
64678
64754
|
var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
|
|
@@ -64919,6 +64995,15 @@ var ts;
|
|
|
64919
64995
|
}
|
|
64920
64996
|
return 0 /* False */;
|
|
64921
64997
|
}
|
|
64998
|
+
// Ensure {readonly a: whatever} is not a subtype of {a: whatever},
|
|
64999
|
+
// while {a: whatever} is a subtype of {readonly a: whatever}.
|
|
65000
|
+
// This ensures the subtype relationship is ordered, and preventing declaration order
|
|
65001
|
+
// from deciding which type "wins" in union subtype reduction.
|
|
65002
|
+
// They're still assignable to one another, since `readonly` doesn't affect assignability.
|
|
65003
|
+
if ((relation === subtypeRelation || relation === strictSubtypeRelation) &&
|
|
65004
|
+
!!(sourcePropFlags & 64 /* Readonly */) && !(targetPropFlags & 64 /* Readonly */)) {
|
|
65005
|
+
return 0 /* False */;
|
|
65006
|
+
}
|
|
64922
65007
|
// If the target comes from a partial union prop, allow `undefined` in the target type
|
|
64923
65008
|
var related = isPropertySymbolTypeRelated(sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState);
|
|
64924
65009
|
if (!related) {
|
|
@@ -65187,7 +65272,6 @@ var ts;
|
|
|
65187
65272
|
}
|
|
65188
65273
|
}
|
|
65189
65274
|
var result = -1 /* True */;
|
|
65190
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
65191
65275
|
var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
|
|
65192
65276
|
var sourceObjectFlags = ts.getObjectFlags(source);
|
|
65193
65277
|
var targetObjectFlags = ts.getObjectFlags(target);
|
|
@@ -65228,6 +65312,7 @@ var ts;
|
|
|
65228
65312
|
else {
|
|
65229
65313
|
outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
|
|
65230
65314
|
var t = targetSignatures_1[_i];
|
|
65315
|
+
var saveErrorInfo = captureErrorCalculationState();
|
|
65231
65316
|
// Only elaborate errors from the first failure
|
|
65232
65317
|
var shouldElaborateErrors = reportErrors;
|
|
65233
65318
|
for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
|
|
@@ -68398,9 +68483,6 @@ var ts;
|
|
|
68398
68483
|
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
|
|
68399
68484
|
mapType(type, mapper);
|
|
68400
68485
|
}
|
|
68401
|
-
function getConstituentCount(type) {
|
|
68402
|
-
return type.flags & 1048576 /* Union */ ? type.types.length : 1;
|
|
68403
|
-
}
|
|
68404
68486
|
function extractTypesOfKind(type, kind) {
|
|
68405
68487
|
return filterType(type, function (t) { return (t.flags & kind) !== 0; });
|
|
68406
68488
|
}
|
|
@@ -76066,21 +76148,22 @@ var ts;
|
|
|
76066
76148
|
if (links.type === unknownType) {
|
|
76067
76149
|
links.type = getTypeFromBindingPattern(declaration.name);
|
|
76068
76150
|
}
|
|
76069
|
-
assignBindingElementTypes(declaration.name);
|
|
76151
|
+
assignBindingElementTypes(declaration.name, links.type);
|
|
76070
76152
|
}
|
|
76071
76153
|
}
|
|
76072
76154
|
}
|
|
76073
76155
|
// When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
|
|
76074
76156
|
// the destructured type into the contained binding elements.
|
|
76075
|
-
function assignBindingElementTypes(pattern) {
|
|
76157
|
+
function assignBindingElementTypes(pattern, parentType) {
|
|
76076
76158
|
for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
|
|
76077
76159
|
var element = _a[_i];
|
|
76078
76160
|
if (!ts.isOmittedExpression(element)) {
|
|
76161
|
+
var type = getBindingElementTypeFromParentType(element, parentType);
|
|
76079
76162
|
if (element.name.kind === 79 /* Identifier */) {
|
|
76080
|
-
getSymbolLinks(getSymbolOfNode(element)).type =
|
|
76163
|
+
getSymbolLinks(getSymbolOfNode(element)).type = type;
|
|
76081
76164
|
}
|
|
76082
76165
|
else {
|
|
76083
|
-
assignBindingElementTypes(element.name);
|
|
76166
|
+
assignBindingElementTypes(element.name, type);
|
|
76084
76167
|
}
|
|
76085
76168
|
}
|
|
76086
76169
|
}
|
|
@@ -79821,28 +79904,24 @@ var ts;
|
|
|
79821
79904
|
if (returnType.flags & 1 /* Any */) {
|
|
79822
79905
|
return;
|
|
79823
79906
|
}
|
|
79907
|
+
var headMessage;
|
|
79824
79908
|
var expectedReturnType;
|
|
79825
|
-
var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
|
79826
|
-
var errorInfo;
|
|
79827
79909
|
switch (node.parent.kind) {
|
|
79828
79910
|
case 256 /* ClassDeclaration */:
|
|
79911
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
|
|
79829
79912
|
var classSymbol = getSymbolOfNode(node.parent);
|
|
79830
79913
|
var classConstructorType = getTypeOfSymbol(classSymbol);
|
|
79831
79914
|
expectedReturnType = getUnionType([classConstructorType, voidType]);
|
|
79832
79915
|
break;
|
|
79833
|
-
case 163 /* Parameter */:
|
|
79834
|
-
expectedReturnType = voidType;
|
|
79835
|
-
errorInfo = ts.chainDiagnosticMessages(
|
|
79836
|
-
/*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
|
|
79837
|
-
break;
|
|
79838
79916
|
case 166 /* PropertyDeclaration */:
|
|
79917
|
+
case 163 /* Parameter */:
|
|
79918
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
|
|
79839
79919
|
expectedReturnType = voidType;
|
|
79840
|
-
errorInfo = ts.chainDiagnosticMessages(
|
|
79841
|
-
/*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
|
|
79842
79920
|
break;
|
|
79843
79921
|
case 168 /* MethodDeclaration */:
|
|
79844
79922
|
case 171 /* GetAccessor */:
|
|
79845
79923
|
case 172 /* SetAccessor */:
|
|
79924
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
|
|
79846
79925
|
var methodType = getTypeOfNode(node.parent);
|
|
79847
79926
|
var descriptorType = createTypedPropertyDescriptorType(methodType);
|
|
79848
79927
|
expectedReturnType = getUnionType([descriptorType, voidType]);
|
|
@@ -79850,7 +79929,7 @@ var ts;
|
|
|
79850
79929
|
default:
|
|
79851
79930
|
return ts.Debug.fail();
|
|
79852
79931
|
}
|
|
79853
|
-
checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage
|
|
79932
|
+
checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
|
|
79854
79933
|
}
|
|
79855
79934
|
/**
|
|
79856
79935
|
* If a TypeNode can be resolved to a value symbol imported from an external module, it is
|
|
@@ -85398,7 +85477,7 @@ var ts;
|
|
|
85398
85477
|
if (resolvedTypeReferenceDirectives) {
|
|
85399
85478
|
// populate reverse mapping: file path -> type reference directive that was resolved to this file
|
|
85400
85479
|
fileToDirective = new ts.Map();
|
|
85401
|
-
resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
|
|
85480
|
+
resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
|
|
85402
85481
|
if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
|
|
85403
85482
|
return;
|
|
85404
85483
|
}
|
|
@@ -85406,7 +85485,7 @@ var ts;
|
|
|
85406
85485
|
if (file) {
|
|
85407
85486
|
// Add the transitive closure of path references loaded by this file (as long as they are not)
|
|
85408
85487
|
// part of an existing type reference.
|
|
85409
|
-
addReferencedFilesToTypeDirective(file, key);
|
|
85488
|
+
addReferencedFilesToTypeDirective(file, key, mode);
|
|
85410
85489
|
}
|
|
85411
85490
|
});
|
|
85412
85491
|
}
|
|
@@ -85600,16 +85679,16 @@ var ts;
|
|
|
85600
85679
|
}
|
|
85601
85680
|
return false;
|
|
85602
85681
|
}
|
|
85603
|
-
function addReferencedFilesToTypeDirective(file, key) {
|
|
85682
|
+
function addReferencedFilesToTypeDirective(file, key, mode) {
|
|
85604
85683
|
if (fileToDirective.has(file.path))
|
|
85605
85684
|
return;
|
|
85606
|
-
fileToDirective.set(file.path, key);
|
|
85685
|
+
fileToDirective.set(file.path, [key, mode]);
|
|
85607
85686
|
for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
|
|
85608
|
-
var
|
|
85687
|
+
var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
|
|
85609
85688
|
var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
|
|
85610
85689
|
var referencedFile = host.getSourceFile(resolvedFile);
|
|
85611
85690
|
if (referencedFile) {
|
|
85612
|
-
addReferencedFilesToTypeDirective(referencedFile, key);
|
|
85691
|
+
addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
|
|
85613
85692
|
}
|
|
85614
85693
|
}
|
|
85615
85694
|
}
|
|
@@ -87314,28 +87393,27 @@ var ts;
|
|
|
87314
87393
|
}
|
|
87315
87394
|
function findMostOverlappyType(source, unionTarget) {
|
|
87316
87395
|
var bestMatch;
|
|
87317
|
-
|
|
87318
|
-
|
|
87319
|
-
var
|
|
87320
|
-
|
|
87321
|
-
|
|
87322
|
-
|
|
87323
|
-
|
|
87324
|
-
|
|
87325
|
-
|
|
87326
|
-
|
|
87327
|
-
|
|
87328
|
-
|
|
87329
|
-
|
|
87330
|
-
|
|
87331
|
-
|
|
87332
|
-
|
|
87333
|
-
|
|
87334
|
-
|
|
87335
|
-
|
|
87336
|
-
|
|
87337
|
-
|
|
87338
|
-
matchingCount = 1;
|
|
87396
|
+
if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
|
|
87397
|
+
var matchingCount = 0;
|
|
87398
|
+
for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
|
|
87399
|
+
var target = _a[_i];
|
|
87400
|
+
if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
|
|
87401
|
+
var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
|
|
87402
|
+
if (overlap.flags & 4194304 /* Index */) {
|
|
87403
|
+
// perfect overlap of keys
|
|
87404
|
+
return target;
|
|
87405
|
+
}
|
|
87406
|
+
else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
|
|
87407
|
+
// We only want to account for literal types otherwise.
|
|
87408
|
+
// If we have a union of index types, it seems likely that we
|
|
87409
|
+
// needed to elaborate between two generic mapped types anyway.
|
|
87410
|
+
var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
|
|
87411
|
+
if (len >= matchingCount) {
|
|
87412
|
+
bestMatch = target;
|
|
87413
|
+
matchingCount = len;
|
|
87414
|
+
}
|
|
87415
|
+
}
|
|
87416
|
+
}
|
|
87339
87417
|
}
|
|
87340
87418
|
}
|
|
87341
87419
|
return bestMatch;
|
|
@@ -88021,7 +88099,7 @@ var ts;
|
|
|
88021
88099
|
return factory.updateJsxFragment(node, nodeVisitor(node.openingFragment, visitor, ts.isJsxOpeningFragment), nodesVisitor(node.children, visitor, ts.isJsxChild), nodeVisitor(node.closingFragment, visitor, ts.isJsxClosingFragment));
|
|
88022
88100
|
case 284 /* JsxAttribute */:
|
|
88023
88101
|
ts.Debug.type(node);
|
|
88024
|
-
return factory.updateJsxAttribute(node, nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.initializer, visitor, ts.
|
|
88102
|
+
return factory.updateJsxAttribute(node, nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.initializer, visitor, ts.isStringLiteralOrJsxExpression));
|
|
88025
88103
|
case 285 /* JsxAttributes */:
|
|
88026
88104
|
ts.Debug.type(node);
|
|
88027
88105
|
return factory.updateJsxAttributes(node, nodesVisitor(node.properties, visitor, ts.isJsxAttributeLike));
|
|
@@ -96083,9 +96161,6 @@ var ts;
|
|
|
96083
96161
|
var literal = factory.createStringLiteral(tryDecodeEntities(node.text) || node.text, singleQuote);
|
|
96084
96162
|
return ts.setTextRange(literal, node);
|
|
96085
96163
|
}
|
|
96086
|
-
else if (node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 222 /* TemplateExpression */) {
|
|
96087
|
-
return node;
|
|
96088
|
-
}
|
|
96089
96164
|
else if (node.kind === 287 /* JsxExpression */) {
|
|
96090
96165
|
if (node.expression === undefined) {
|
|
96091
96166
|
return factory.createTrue();
|
|
@@ -96860,8 +96935,6 @@ var ts;
|
|
|
96860
96935
|
return visitReturnStatement(node);
|
|
96861
96936
|
case 216 /* VoidExpression */:
|
|
96862
96937
|
return visitVoidExpression(node);
|
|
96863
|
-
case 284 /* JsxAttribute */:
|
|
96864
|
-
return visitJsxAttribute(node);
|
|
96865
96938
|
default:
|
|
96866
96939
|
return ts.visitEachChild(node, visitor, context);
|
|
96867
96940
|
}
|
|
@@ -96892,13 +96965,6 @@ var ts;
|
|
|
96892
96965
|
}
|
|
96893
96966
|
return ts.visitEachChild(node, visitor, context);
|
|
96894
96967
|
}
|
|
96895
|
-
function visitJsxAttribute(node) {
|
|
96896
|
-
if (node.initializer && ts.isTemplateExpression(node.initializer)) {
|
|
96897
|
-
return factory.createJsxAttribute(ts.visitNode(node.name, visitor, ts.isIdentifier), factory.createJsxExpression(
|
|
96898
|
-
/* dotDotDotToken */ undefined, ts.visitNode(node.initializer, visitor, ts.isExpression)));
|
|
96899
|
-
}
|
|
96900
|
-
return ts.visitEachChild(node, visitor, context);
|
|
96901
|
-
}
|
|
96902
96968
|
function visitCaseBlock(node) {
|
|
96903
96969
|
var ancestorFacts = enterSubtree(7104 /* BlockScopeExcludes */, 0 /* BlockScopeIncludes */);
|
|
96904
96970
|
var updated = ts.visitEachChild(node, visitor, context);
|
|
@@ -106390,7 +106456,7 @@ var ts;
|
|
|
106390
106456
|
var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
|
|
106391
106457
|
hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
|
|
106392
106458
|
collectReferences(sourceFile, refs);
|
|
106393
|
-
recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
|
|
106459
|
+
recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
|
|
106394
106460
|
collectLibs(sourceFile, libs);
|
|
106395
106461
|
return sourceFile;
|
|
106396
106462
|
}
|
|
@@ -106445,9 +106511,10 @@ var ts;
|
|
|
106445
106511
|
return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
|
|
106446
106512
|
}
|
|
106447
106513
|
function getFileReferencesForUsedTypeReferences() {
|
|
106448
|
-
return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()),
|
|
106514
|
+
return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
|
|
106449
106515
|
}
|
|
106450
|
-
function
|
|
106516
|
+
function getFileReferenceForSpecifierModeTuple(_a) {
|
|
106517
|
+
var typeName = _a[0], mode = _a[1];
|
|
106451
106518
|
// Elide type references for which we have imports
|
|
106452
106519
|
if (emittedImports) {
|
|
106453
106520
|
for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
|
|
@@ -106463,7 +106530,7 @@ var ts;
|
|
|
106463
106530
|
}
|
|
106464
106531
|
}
|
|
106465
106532
|
}
|
|
106466
|
-
return { fileName: typeName, pos: -1, end: -1 };
|
|
106533
|
+
return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
|
|
106467
106534
|
}
|
|
106468
106535
|
function mapReferencesIntoArray(references, outputFilePath) {
|
|
106469
106536
|
return function (file) {
|
|
@@ -106483,7 +106550,7 @@ var ts;
|
|
|
106483
106550
|
// If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
|
|
106484
106551
|
// via a non-relative name, emit a type reference directive to that non-relative name, rather than
|
|
106485
106552
|
// a relative path to the declaration file
|
|
106486
|
-
recordTypeReferenceDirectivesIfNecessary([specifier]);
|
|
106553
|
+
recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
|
|
106487
106554
|
return;
|
|
106488
106555
|
}
|
|
106489
106556
|
var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
|
|
@@ -111595,9 +111662,12 @@ var ts;
|
|
|
111595
111662
|
for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
|
|
111596
111663
|
var directive = types_24[_d];
|
|
111597
111664
|
var pos = writer.getTextPos();
|
|
111598
|
-
|
|
111665
|
+
var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
|
|
111666
|
+
? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
|
|
111667
|
+
: "";
|
|
111668
|
+
writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
|
|
111599
111669
|
if (bundleFileInfo)
|
|
111600
|
-
bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
|
|
111670
|
+
bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: !directive.resolutionMode ? "type" /* Type */ : directive.resolutionMode === ts.ModuleKind.ESNext ? "type-import" /* TypeResolutionModeImport */ : "type-require" /* TypeResolutionModeRequire */, data: directive.fileName });
|
|
111601
111671
|
writeLine();
|
|
111602
111672
|
}
|
|
111603
111673
|
for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
|
|
@@ -114204,7 +114274,7 @@ var ts;
|
|
|
114204
114274
|
}
|
|
114205
114275
|
ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
|
|
114206
114276
|
/* @internal */
|
|
114207
|
-
function
|
|
114277
|
+
function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
|
|
114208
114278
|
if (names.length === 0) {
|
|
114209
114279
|
return [];
|
|
114210
114280
|
}
|
|
@@ -114213,19 +114283,28 @@ var ts;
|
|
|
114213
114283
|
for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
|
|
114214
114284
|
var name = names_2[_i];
|
|
114215
114285
|
var result = void 0;
|
|
114216
|
-
|
|
114217
|
-
|
|
114286
|
+
var mode = getModeForFileReference(name, containingFileMode);
|
|
114287
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
114288
|
+
var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
|
|
114289
|
+
var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
|
|
114290
|
+
if (cache.has(cacheKey)) {
|
|
114291
|
+
result = cache.get(cacheKey);
|
|
114218
114292
|
}
|
|
114219
114293
|
else {
|
|
114220
|
-
cache.set(
|
|
114294
|
+
cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
|
|
114221
114295
|
}
|
|
114222
114296
|
resolutions.push(result);
|
|
114223
114297
|
}
|
|
114224
114298
|
return resolutions;
|
|
114225
114299
|
}
|
|
114226
|
-
ts.
|
|
114300
|
+
ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
|
|
114227
114301
|
;
|
|
114228
114302
|
/* @internal */
|
|
114303
|
+
function getModeForFileReference(ref, containingFileMode) {
|
|
114304
|
+
return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
|
|
114305
|
+
}
|
|
114306
|
+
ts.getModeForFileReference = getModeForFileReference;
|
|
114307
|
+
/* @internal */
|
|
114229
114308
|
function getModeForResolutionAtIndex(file, index) {
|
|
114230
114309
|
if (file.impliedNodeFormat === undefined)
|
|
114231
114310
|
return undefined;
|
|
@@ -114328,7 +114407,7 @@ var ts;
|
|
|
114328
114407
|
var _d, _e, _f, _g;
|
|
114329
114408
|
var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
|
|
114330
114409
|
var kind = ref.kind, index = ref.index;
|
|
114331
|
-
var pos, end, packageId;
|
|
114410
|
+
var pos, end, packageId, resolutionMode;
|
|
114332
114411
|
switch (kind) {
|
|
114333
114412
|
case ts.FileIncludeKind.Import:
|
|
114334
114413
|
var importLiteral = getModuleNameStringLiteralAt(file, index);
|
|
@@ -114342,8 +114421,8 @@ var ts;
|
|
|
114342
114421
|
(_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
|
|
114343
114422
|
break;
|
|
114344
114423
|
case ts.FileIncludeKind.TypeReferenceDirective:
|
|
114345
|
-
(_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
|
|
114346
|
-
packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
|
|
114424
|
+
(_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
|
|
114425
|
+
packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), resolutionMode || file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
|
|
114347
114426
|
break;
|
|
114348
114427
|
case ts.FileIncludeKind.LibReferenceDirective:
|
|
114349
114428
|
(_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
|
|
@@ -114587,7 +114666,7 @@ var ts;
|
|
|
114587
114666
|
var fileReasons = ts.createMultiMap();
|
|
114588
114667
|
var cachedBindAndCheckDiagnosticsForFile = {};
|
|
114589
114668
|
var cachedDeclarationDiagnosticsForFile = {};
|
|
114590
|
-
var resolvedTypeReferenceDirectives =
|
|
114669
|
+
var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
|
|
114591
114670
|
var fileProcessingDiagnostics;
|
|
114592
114671
|
// The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
|
|
114593
114672
|
// This works as imported modules are discovered recursively in a depth first manner, specifically:
|
|
@@ -114640,12 +114719,12 @@ var ts;
|
|
|
114640
114719
|
}
|
|
114641
114720
|
var actualResolveTypeReferenceDirectiveNamesWorker;
|
|
114642
114721
|
if (host.resolveTypeReferenceDirectives) {
|
|
114643
|
-
actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
|
|
114722
|
+
actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
|
|
114644
114723
|
}
|
|
114645
114724
|
else {
|
|
114646
114725
|
typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
|
|
114647
|
-
var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
|
|
114648
|
-
actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return
|
|
114726
|
+
var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
|
|
114727
|
+
actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
|
|
114649
114728
|
}
|
|
114650
114729
|
// Map from a stringified PackageId to the source file with that id.
|
|
114651
114730
|
// Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
|
|
@@ -114742,7 +114821,8 @@ var ts;
|
|
|
114742
114821
|
var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
|
|
114743
114822
|
var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
|
|
114744
114823
|
for (var i = 0; i < typeReferences.length; i++) {
|
|
114745
|
-
|
|
114824
|
+
// under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
|
|
114825
|
+
processTypeReferenceDirective(typeReferences[i], /*mode*/ undefined, resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
|
|
114746
114826
|
}
|
|
114747
114827
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
114748
114828
|
}
|
|
@@ -114902,9 +114982,10 @@ var ts;
|
|
|
114902
114982
|
return [];
|
|
114903
114983
|
var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
|
|
114904
114984
|
var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
|
|
114985
|
+
var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
|
|
114905
114986
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
|
|
114906
114987
|
ts.performance.mark("beforeResolveTypeReference");
|
|
114907
|
-
var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
|
|
114988
|
+
var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
|
|
114908
114989
|
ts.performance.mark("afterResolveTypeReference");
|
|
114909
114990
|
ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
|
|
114910
114991
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
@@ -115296,8 +115377,7 @@ var ts;
|
|
|
115296
115377
|
else {
|
|
115297
115378
|
newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
|
|
115298
115379
|
}
|
|
115299
|
-
|
|
115300
|
-
var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
|
|
115380
|
+
var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
|
|
115301
115381
|
var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
|
|
115302
115382
|
// ensure that types resolutions are still correct
|
|
115303
115383
|
var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
|
|
@@ -116376,8 +116456,7 @@ var ts;
|
|
|
116376
116456
|
});
|
|
116377
116457
|
}
|
|
116378
116458
|
function processTypeReferenceDirectives(file) {
|
|
116379
|
-
|
|
116380
|
-
var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
|
|
116459
|
+
var typeDirectives = file.typeReferenceDirectives;
|
|
116381
116460
|
if (!typeDirectives) {
|
|
116382
116461
|
return;
|
|
116383
116462
|
}
|
|
@@ -116388,17 +116467,21 @@ var ts;
|
|
|
116388
116467
|
// store resolved type directive on the file
|
|
116389
116468
|
var fileName = ts.toFileNameLowerCase(ref.fileName);
|
|
116390
116469
|
ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
|
|
116391
|
-
|
|
116470
|
+
var mode = ref.resolutionMode || file.impliedNodeFormat;
|
|
116471
|
+
if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
|
|
116472
|
+
programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
|
|
116473
|
+
}
|
|
116474
|
+
processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
|
|
116392
116475
|
}
|
|
116393
116476
|
}
|
|
116394
|
-
function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
|
|
116477
|
+
function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
|
|
116395
116478
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolveModuleNamesReusingOldState, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : undefined });
|
|
116396
|
-
processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
|
|
116479
|
+
processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
|
|
116397
116480
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
116398
116481
|
}
|
|
116399
|
-
function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
|
|
116482
|
+
function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
|
|
116400
116483
|
// If we already found this library as a primary reference - nothing to do
|
|
116401
|
-
var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
|
|
116484
|
+
var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
|
|
116402
116485
|
if (previousResolution && previousResolution.primary) {
|
|
116403
116486
|
return;
|
|
116404
116487
|
}
|
|
@@ -116437,7 +116520,7 @@ var ts;
|
|
|
116437
116520
|
addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
|
|
116438
116521
|
}
|
|
116439
116522
|
if (saveResolution) {
|
|
116440
|
-
resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
|
|
116523
|
+
resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
|
|
116441
116524
|
}
|
|
116442
116525
|
}
|
|
116443
116526
|
function pathForLibFile(libFileName) {
|
|
@@ -119255,9 +119338,9 @@ var ts;
|
|
|
119255
119338
|
});
|
|
119256
119339
|
hasChangedAutomaticTypeDirectiveNames = false;
|
|
119257
119340
|
}
|
|
119258
|
-
function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
|
|
119341
|
+
function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
|
|
119259
119342
|
var _a;
|
|
119260
|
-
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
|
|
119343
|
+
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
|
|
119261
119344
|
// return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
|
|
119262
119345
|
if (!resolutionHost.getGlobalCache) {
|
|
119263
119346
|
return primaryResult;
|
|
@@ -119278,12 +119361,12 @@ var ts;
|
|
|
119278
119361
|
// Default return the result from the first pass
|
|
119279
119362
|
return primaryResult;
|
|
119280
119363
|
}
|
|
119281
|
-
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
|
|
119282
|
-
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
|
|
119364
|
+
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
|
|
119365
|
+
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
|
|
119283
119366
|
}
|
|
119284
119367
|
function resolveNamesWithLocalCache(_a) {
|
|
119285
119368
|
var _b, _c, _d;
|
|
119286
|
-
var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile;
|
|
119369
|
+
var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile, containingSourceFileMode = _a.containingSourceFileMode;
|
|
119287
119370
|
var path = resolutionHost.toPath(containingFile);
|
|
119288
119371
|
var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
|
|
119289
119372
|
var dirPath = ts.getDirectoryPath(path);
|
|
@@ -119305,8 +119388,15 @@ var ts;
|
|
|
119305
119388
|
var seenNamesInFile = ts.createModeAwareCache();
|
|
119306
119389
|
var i = 0;
|
|
119307
119390
|
for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
|
|
119308
|
-
var
|
|
119309
|
-
var
|
|
119391
|
+
var entry = names_4[_i];
|
|
119392
|
+
var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
|
|
119393
|
+
// Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
|
|
119394
|
+
// they require calculating the mode for a given import from it's position in the resolution table, since a given
|
|
119395
|
+
// import's syntax may override the file's default mode.
|
|
119396
|
+
// Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
|
|
119397
|
+
// a default file mode override if applicable.
|
|
119398
|
+
var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
|
|
119399
|
+
containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
|
|
119310
119400
|
i++;
|
|
119311
119401
|
var resolution = resolutionsInFile.get(name, mode);
|
|
119312
119402
|
// Resolution is valid if it is present and not invalidated
|
|
@@ -119335,7 +119425,7 @@ var ts;
|
|
|
119335
119425
|
}
|
|
119336
119426
|
}
|
|
119337
119427
|
else {
|
|
119338
|
-
resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
|
|
119428
|
+
resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
|
|
119339
119429
|
perDirectoryResolution.set(name, mode, resolution);
|
|
119340
119430
|
if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
|
|
119341
119431
|
resolutionHost.onDiscoveredSymlink();
|
|
@@ -119399,7 +119489,7 @@ var ts;
|
|
|
119399
119489
|
return oldResult.resolvedFileName === newResult.resolvedFileName;
|
|
119400
119490
|
}
|
|
119401
119491
|
}
|
|
119402
|
-
function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
|
|
119492
|
+
function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
|
|
119403
119493
|
return resolveNamesWithLocalCache({
|
|
119404
119494
|
names: typeDirectiveNames,
|
|
119405
119495
|
containingFile: containingFile,
|
|
@@ -119409,6 +119499,7 @@ var ts;
|
|
|
119409
119499
|
loader: resolveTypeReferenceDirective,
|
|
119410
119500
|
getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
|
|
119411
119501
|
shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
|
|
119502
|
+
containingSourceFileMode: containingFileMode
|
|
119412
119503
|
});
|
|
119413
119504
|
}
|
|
119414
119505
|
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
|
|
@@ -121317,7 +121408,7 @@ var ts;
|
|
|
121317
121408
|
}
|
|
121318
121409
|
return host.resolveTypeReferenceDirectives.apply(host, args);
|
|
121319
121410
|
}) :
|
|
121320
|
-
(function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
|
|
121411
|
+
(function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
|
|
121321
121412
|
var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
|
|
121322
121413
|
builderProgram = readBuilderProgram(compilerOptions, compilerHost);
|
|
121323
121414
|
synchronizeProgram();
|
|
@@ -122053,9 +122144,9 @@ var ts;
|
|
|
122053
122144
|
compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
|
|
122054
122145
|
}
|
|
122055
122146
|
if (!compilerHost.resolveTypeReferenceDirectives) {
|
|
122056
|
-
var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
|
|
122057
|
-
compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
|
|
122058
|
-
return ts.
|
|
122147
|
+
var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
|
|
122148
|
+
compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
|
|
122149
|
+
return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
|
|
122059
122150
|
};
|
|
122060
122151
|
}
|
|
122061
122152
|
var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;
|
|
@@ -126964,6 +127055,10 @@ var ts;
|
|
|
126964
127055
|
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
126965
127056
|
}
|
|
126966
127057
|
ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
|
|
127058
|
+
function jsxModeNeedsExplicitImport(jsx) {
|
|
127059
|
+
return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
|
|
127060
|
+
}
|
|
127061
|
+
ts.jsxModeNeedsExplicitImport = jsxModeNeedsExplicitImport;
|
|
126967
127062
|
// #endregion
|
|
126968
127063
|
})(ts || (ts = {}));
|
|
126969
127064
|
/*@internal*/
|
|
@@ -128908,9 +129003,18 @@ var ts;
|
|
|
128908
129003
|
return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath);
|
|
128909
129004
|
}
|
|
128910
129005
|
}
|
|
129006
|
+
function isEmitResolutionKindUsingNodeModules(compilerOptions) {
|
|
129007
|
+
return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ||
|
|
129008
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
|
|
129009
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
|
|
129010
|
+
}
|
|
129011
|
+
function isEmitModuleResolutionRespectingExportMaps(compilerOptions) {
|
|
129012
|
+
return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
|
|
129013
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
|
|
129014
|
+
}
|
|
128911
129015
|
function getSupportedExtensionsForModuleResolution(compilerOptions) {
|
|
128912
129016
|
var extensions = ts.getSupportedExtensions(compilerOptions);
|
|
128913
|
-
return
|
|
129017
|
+
return isEmitResolutionKindUsingNodeModules(compilerOptions) ?
|
|
128914
129018
|
ts.getSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, extensions) :
|
|
128915
129019
|
extensions;
|
|
128916
129020
|
}
|
|
@@ -129073,7 +129177,7 @@ var ts;
|
|
|
129073
129177
|
result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
|
|
129074
129178
|
}
|
|
129075
129179
|
getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
|
|
129076
|
-
if (
|
|
129180
|
+
if (isEmitResolutionKindUsingNodeModules(compilerOptions)) {
|
|
129077
129181
|
// If looking for a global package name, don't just include everything in `node_modules` because that includes dependencies' own dependencies.
|
|
129078
129182
|
// (But do if we didn't find anything, e.g. 'package.json' missing.)
|
|
129079
129183
|
var foundGlobal = false;
|
|
@@ -129090,12 +129194,68 @@ var ts;
|
|
|
129090
129194
|
}
|
|
129091
129195
|
}
|
|
129092
129196
|
if (!foundGlobal) {
|
|
129093
|
-
|
|
129197
|
+
var ancestorLookup = function (ancestor) {
|
|
129094
129198
|
var nodeModules = ts.combinePaths(ancestor, "node_modules");
|
|
129095
129199
|
if (ts.tryDirectoryExists(host, nodeModules)) {
|
|
129096
129200
|
getCompletionEntriesForDirectoryFragment(fragment, nodeModules, extensionOptions, host, /*exclude*/ undefined, result);
|
|
129097
129201
|
}
|
|
129098
|
-
}
|
|
129202
|
+
};
|
|
129203
|
+
if (fragmentDirectory && isEmitModuleResolutionRespectingExportMaps(compilerOptions)) {
|
|
129204
|
+
var nodeModulesDirectoryLookup_1 = ancestorLookup;
|
|
129205
|
+
ancestorLookup = function (ancestor) {
|
|
129206
|
+
var components = ts.getPathComponents(fragment);
|
|
129207
|
+
components.shift(); // shift off empty root
|
|
129208
|
+
var packagePath = components.shift();
|
|
129209
|
+
if (!packagePath) {
|
|
129210
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129211
|
+
}
|
|
129212
|
+
if (ts.startsWith(packagePath, "@")) {
|
|
129213
|
+
var subName = components.shift();
|
|
129214
|
+
if (!subName) {
|
|
129215
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129216
|
+
}
|
|
129217
|
+
packagePath = ts.combinePaths(packagePath, subName);
|
|
129218
|
+
}
|
|
129219
|
+
var packageFile = ts.combinePaths(ancestor, "node_modules", packagePath, "package.json");
|
|
129220
|
+
if (ts.tryFileExists(host, packageFile)) {
|
|
129221
|
+
var packageJson = ts.readJson(packageFile, host);
|
|
129222
|
+
var exports = packageJson.exports;
|
|
129223
|
+
if (exports) {
|
|
129224
|
+
if (typeof exports !== "object" || exports === null) { // eslint-disable-line no-null/no-null
|
|
129225
|
+
return; // null exports or entrypoint only, no sub-modules available
|
|
129226
|
+
}
|
|
129227
|
+
var keys = ts.getOwnKeys(exports);
|
|
129228
|
+
var fragmentSubpath_1 = components.join("/");
|
|
129229
|
+
var processedKeys = ts.mapDefined(keys, function (k) {
|
|
129230
|
+
if (k === ".")
|
|
129231
|
+
return undefined;
|
|
129232
|
+
if (!ts.startsWith(k, "./"))
|
|
129233
|
+
return undefined;
|
|
129234
|
+
var subpath = k.substring(2);
|
|
129235
|
+
if (!ts.startsWith(subpath, fragmentSubpath_1))
|
|
129236
|
+
return undefined;
|
|
129237
|
+
// subpath is a valid export (barring conditions, which we don't currently check here)
|
|
129238
|
+
if (!ts.stringContains(subpath, "*")) {
|
|
129239
|
+
return subpath;
|
|
129240
|
+
}
|
|
129241
|
+
// pattern export - only return everything up to the `*`, so the user can autocomplete, then
|
|
129242
|
+
// keep filling in the pattern (we could speculatively return a list of options by hitting disk,
|
|
129243
|
+
// but conditions will make that somewhat awkward, as each condition may have a different set of possible
|
|
129244
|
+
// options for the `*`.
|
|
129245
|
+
return subpath.slice(0, subpath.indexOf("*"));
|
|
129246
|
+
});
|
|
129247
|
+
ts.forEach(processedKeys, function (k) {
|
|
129248
|
+
if (k) {
|
|
129249
|
+
result.push(nameAndKind(k, "external module name" /* externalModuleName */, /*extension*/ undefined));
|
|
129250
|
+
}
|
|
129251
|
+
});
|
|
129252
|
+
return;
|
|
129253
|
+
}
|
|
129254
|
+
}
|
|
129255
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129256
|
+
};
|
|
129257
|
+
}
|
|
129258
|
+
ts.forEachAncestorDirectory(scriptPath, ancestorLookup);
|
|
129099
129259
|
}
|
|
129100
129260
|
}
|
|
129101
129261
|
return result;
|
|
@@ -133560,7 +133720,7 @@ var ts;
|
|
|
133560
133720
|
}
|
|
133561
133721
|
for (var _c = 0, _d = referencingFile.typeReferenceDirectives; _c < _d.length; _c++) {
|
|
133562
133722
|
var ref = _d[_c];
|
|
133563
|
-
var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName);
|
|
133723
|
+
var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName, ref.resolutionMode || referencingFile.impliedNodeFormat);
|
|
133564
133724
|
if (referenced !== undefined && referenced.resolvedFileName === searchSourceFile.fileName) {
|
|
133565
133725
|
refs.push({ kind: "reference", referencingFile: referencingFile, ref: ref });
|
|
133566
133726
|
}
|
|
@@ -136782,7 +136942,7 @@ var ts;
|
|
|
136782
136942
|
}
|
|
136783
136943
|
var typeReferenceDirective = findReferenceInPosition(sourceFile.typeReferenceDirectives, position);
|
|
136784
136944
|
if (typeReferenceDirective) {
|
|
136785
|
-
var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName);
|
|
136945
|
+
var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName, typeReferenceDirective.resolutionMode || sourceFile.impliedNodeFormat);
|
|
136786
136946
|
var file = reference && program.getSourceFile(reference.resolvedFileName); // TODO:GH#18217
|
|
136787
136947
|
return file && { reference: typeReferenceDirective, fileName: file.fileName, file: file, unverified: false };
|
|
136788
136948
|
}
|
|
@@ -138588,6 +138748,7 @@ var ts;
|
|
|
138588
138748
|
return oldImports;
|
|
138589
138749
|
}
|
|
138590
138750
|
var typeChecker = program.getTypeChecker();
|
|
138751
|
+
var compilerOptions = program.getCompilerOptions();
|
|
138591
138752
|
var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
|
|
138592
138753
|
var jsxFragmentFactory = typeChecker.getJsxFragmentFactory(sourceFile);
|
|
138593
138754
|
var jsxElementsPresent = !!(sourceFile.transformFlags & 2 /* ContainsJsx */);
|
|
@@ -138644,7 +138805,7 @@ var ts;
|
|
|
138644
138805
|
return usedImports;
|
|
138645
138806
|
function isDeclarationUsed(identifier) {
|
|
138646
138807
|
// The JSX factory symbol is always used if JSX elements are present - even if they are not allowed.
|
|
138647
|
-
return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) ||
|
|
138808
|
+
return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx) ||
|
|
138648
138809
|
ts.FindAllReferences.Core.isSymbolReferencedInFile(identifier, typeChecker, sourceFile);
|
|
138649
138810
|
}
|
|
138650
138811
|
}
|
|
@@ -150335,12 +150496,9 @@ var ts;
|
|
|
150335
150496
|
return undefined;
|
|
150336
150497
|
return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
|
|
150337
150498
|
}
|
|
150338
|
-
function jsxModeNeedsExplicitImport(jsx) {
|
|
150339
|
-
return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
|
|
150340
|
-
}
|
|
150341
150499
|
function getSymbolName(sourceFile, checker, symbolToken, compilerOptions) {
|
|
150342
150500
|
var parent = symbolToken.parent;
|
|
150343
|
-
if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
|
|
150501
|
+
if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
|
|
150344
150502
|
var jsxNamespace = checker.getJsxNamespace(sourceFile);
|
|
150345
150503
|
if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
|
|
150346
150504
|
return jsxNamespace;
|
|
@@ -163606,7 +163764,7 @@ var ts;
|
|
|
163606
163764
|
if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) {
|
|
163607
163765
|
this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
|
|
163608
163766
|
var typeDirectivesForFile = JSON.parse(_this.shimHost.getTypeReferenceDirectiveResolutionsForFile(containingFile)); // TODO: GH#18217
|
|
163609
|
-
return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, name); });
|
|
163767
|
+
return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, ts.isString(name) ? name : name.fileName.toLowerCase()); });
|
|
163610
163768
|
};
|
|
163611
163769
|
}
|
|
163612
163770
|
}
|
|
@@ -166305,8 +166463,8 @@ var ts;
|
|
|
166305
166463
|
Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
|
|
166306
166464
|
return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
|
|
166307
166465
|
};
|
|
166308
|
-
Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference) {
|
|
166309
|
-
return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference);
|
|
166466
|
+
Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
|
|
166467
|
+
return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode);
|
|
166310
166468
|
};
|
|
166311
166469
|
Project.prototype.directoryExists = function (path) {
|
|
166312
166470
|
return this.directoryStructureHost.directoryExists(path); // TODO: GH#18217
|