@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/typescript.js
CHANGED
|
@@ -290,11 +290,11 @@ var ts;
|
|
|
290
290
|
(function (ts) {
|
|
291
291
|
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
|
|
292
292
|
// If changing the text in this section, be sure to test `configurePrerelease` too.
|
|
293
|
-
ts.versionMajorMinor = "4.
|
|
293
|
+
ts.versionMajorMinor = "4.7";
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-insiders.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-insiders.20220215";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -5034,6 +5034,8 @@ var ts;
|
|
|
5034
5034
|
TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
|
|
5035
5035
|
TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
|
|
5036
5036
|
/* @internal */
|
|
5037
|
+
TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
|
|
5038
|
+
/* @internal */
|
|
5037
5039
|
TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
|
|
5038
5040
|
TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
|
|
5039
5041
|
TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
|
|
@@ -5766,6 +5768,8 @@ var ts;
|
|
|
5766
5768
|
BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
|
|
5767
5769
|
BundleFileSectionKind["Reference"] = "reference";
|
|
5768
5770
|
BundleFileSectionKind["Type"] = "type";
|
|
5771
|
+
BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
|
|
5772
|
+
BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
|
|
5769
5773
|
BundleFileSectionKind["Lib"] = "lib";
|
|
5770
5774
|
BundleFileSectionKind["Prepend"] = "prepend";
|
|
5771
5775
|
BundleFileSectionKind["Text"] = "text";
|
|
@@ -5882,7 +5886,8 @@ var ts;
|
|
|
5882
5886
|
{ name: "types", optional: true, captureSpan: true },
|
|
5883
5887
|
{ name: "lib", optional: true, captureSpan: true },
|
|
5884
5888
|
{ name: "path", optional: true, captureSpan: true },
|
|
5885
|
-
{ name: "no-default-lib", optional: true }
|
|
5889
|
+
{ name: "no-default-lib", optional: true },
|
|
5890
|
+
{ name: "resolution-mode", optional: true }
|
|
5886
5891
|
],
|
|
5887
5892
|
kind: 1 /* TripleSlashXML */
|
|
5888
5893
|
},
|
|
@@ -7830,18 +7835,6 @@ var ts;
|
|
|
7830
7835
|
return getCanonicalFileName(nonCanonicalizedPath);
|
|
7831
7836
|
}
|
|
7832
7837
|
ts.toPath = toPath;
|
|
7833
|
-
function normalizePathAndParts(path) {
|
|
7834
|
-
path = normalizeSlashes(path);
|
|
7835
|
-
var _a = reducePathComponents(getPathComponents(path)), root = _a[0], parts = _a.slice(1);
|
|
7836
|
-
if (parts.length) {
|
|
7837
|
-
var joinedParts = root + parts.join(ts.directorySeparator);
|
|
7838
|
-
return { path: hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(joinedParts) : joinedParts, parts: parts };
|
|
7839
|
-
}
|
|
7840
|
-
else {
|
|
7841
|
-
return { path: root, parts: parts };
|
|
7842
|
-
}
|
|
7843
|
-
}
|
|
7844
|
-
ts.normalizePathAndParts = normalizePathAndParts;
|
|
7845
7838
|
function removeTrailingDirectorySeparator(path) {
|
|
7846
7839
|
if (hasTrailingDirectorySeparator(path)) {
|
|
7847
7840
|
return path.substr(0, path.length - 1);
|
|
@@ -8275,6 +8268,8 @@ var ts;
|
|
|
8275
8268
|
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."),
|
|
8276
8269
|
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."),
|
|
8277
8270
|
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."),
|
|
8271
|
+
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}'."),
|
|
8272
|
+
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'."),
|
|
8278
8273
|
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."),
|
|
8279
8274
|
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."),
|
|
8280
8275
|
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."),
|
|
@@ -8408,6 +8403,8 @@ var ts;
|
|
|
8408
8403
|
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."),
|
|
8409
8404
|
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"),
|
|
8410
8405
|
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"),
|
|
8406
|
+
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`."),
|
|
8407
|
+
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`."),
|
|
8411
8408
|
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."),
|
|
8412
8409
|
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."),
|
|
8413
8410
|
catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
|
|
@@ -11945,8 +11942,6 @@ var ts;
|
|
|
11945
11942
|
case 39 /* singleQuote */:
|
|
11946
11943
|
tokenValue = scanString(/*jsxAttributeString*/ true);
|
|
11947
11944
|
return token = 10 /* StringLiteral */;
|
|
11948
|
-
case 96 /* backtick */:
|
|
11949
|
-
return token = scanTemplateAndSetTokenValue(/*isTaggedTemplate*/ false);
|
|
11950
11945
|
default:
|
|
11951
11946
|
// If this scans anything other than `{`, it's a parse error.
|
|
11952
11947
|
return scan();
|
|
@@ -13954,11 +13949,6 @@ var ts;
|
|
|
13954
13949
|
|| kind === 287 /* JsxExpression */;
|
|
13955
13950
|
}
|
|
13956
13951
|
ts.isStringLiteralOrJsxExpression = isStringLiteralOrJsxExpression;
|
|
13957
|
-
/* @internal */
|
|
13958
|
-
function isStringLiteralOrTemplateExpressionOrJsxExpression(node) {
|
|
13959
|
-
return node.kind === 222 /* TemplateExpression */ || isStringLiteralOrJsxExpression(node);
|
|
13960
|
-
}
|
|
13961
|
-
ts.isStringLiteralOrTemplateExpressionOrJsxExpression = isStringLiteralOrTemplateExpressionOrJsxExpression;
|
|
13962
13952
|
function isJsxOpeningLikeElement(node) {
|
|
13963
13953
|
var kind = node.kind;
|
|
13964
13954
|
return kind === 279 /* JsxOpeningElement */
|
|
@@ -14298,7 +14288,11 @@ var ts;
|
|
|
14298
14288
|
ts.Debug.assert(names.length === newResolutions.length);
|
|
14299
14289
|
for (var i = 0; i < names.length; i++) {
|
|
14300
14290
|
var newResolution = newResolutions[i];
|
|
14301
|
-
var
|
|
14291
|
+
var entry = names[i];
|
|
14292
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
14293
|
+
var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
|
|
14294
|
+
var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
|
|
14295
|
+
var oldResolution = oldResolutions && oldResolutions.get(name, mode);
|
|
14302
14296
|
var changed = oldResolution
|
|
14303
14297
|
? !newResolution || !comparer(oldResolution, newResolution)
|
|
14304
14298
|
: newResolution;
|
|
@@ -26893,7 +26887,13 @@ var ts;
|
|
|
26893
26887
|
referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
|
|
26894
26888
|
break;
|
|
26895
26889
|
case "type" /* Type */:
|
|
26896
|
-
typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
|
|
26890
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
|
|
26891
|
+
break;
|
|
26892
|
+
case "type-import" /* TypeResolutionModeImport */:
|
|
26893
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
|
|
26894
|
+
break;
|
|
26895
|
+
case "type-require" /* TypeResolutionModeRequire */:
|
|
26896
|
+
typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
|
|
26897
26897
|
break;
|
|
26898
26898
|
case "lib" /* Lib */:
|
|
26899
26899
|
libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
|
|
@@ -26952,6 +26952,8 @@ var ts;
|
|
|
26952
26952
|
case "no-default-lib" /* NoDefaultLib */:
|
|
26953
26953
|
case "reference" /* Reference */:
|
|
26954
26954
|
case "type" /* Type */:
|
|
26955
|
+
case "type-import" /* TypeResolutionModeImport */:
|
|
26956
|
+
case "type-require" /* TypeResolutionModeRequire */:
|
|
26955
26957
|
case "lib" /* Lib */:
|
|
26956
26958
|
syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
|
|
26957
26959
|
break;
|
|
@@ -34656,26 +34658,15 @@ var ts;
|
|
|
34656
34658
|
}
|
|
34657
34659
|
return finishNode(factory.createJsxExpression(dotDotDotToken, expression), pos);
|
|
34658
34660
|
}
|
|
34659
|
-
function parseJsxAttributeValue() {
|
|
34660
|
-
if (token() !== 63 /* EqualsToken */) {
|
|
34661
|
-
return undefined;
|
|
34662
|
-
}
|
|
34663
|
-
var jsxAttributeValueToken = scanJsxAttributeValue();
|
|
34664
|
-
if (jsxAttributeValueToken === 10 /* StringLiteral */ || jsxAttributeValueToken === 14 /* NoSubstitutionTemplateLiteral */) {
|
|
34665
|
-
return parseLiteralNode();
|
|
34666
|
-
}
|
|
34667
|
-
if (jsxAttributeValueToken === 15 /* TemplateHead */) {
|
|
34668
|
-
return parseTemplateExpression(/*isTaggedTemplate*/ false);
|
|
34669
|
-
}
|
|
34670
|
-
return parseJsxExpression(/*inExpressionContext*/ true);
|
|
34671
|
-
}
|
|
34672
34661
|
function parseJsxAttribute() {
|
|
34673
34662
|
if (token() === 18 /* OpenBraceToken */) {
|
|
34674
34663
|
return parseJsxSpreadAttribute();
|
|
34675
34664
|
}
|
|
34676
34665
|
scanJsxIdentifier();
|
|
34677
34666
|
var pos = getNodePos();
|
|
34678
|
-
return finishNode(factory.createJsxAttribute(parseIdentifierName(),
|
|
34667
|
+
return finishNode(factory.createJsxAttribute(parseIdentifierName(), token() !== 63 /* EqualsToken */ ? undefined :
|
|
34668
|
+
scanJsxAttributeValue() === 10 /* StringLiteral */ ? parseLiteralNode() :
|
|
34669
|
+
parseJsxExpression(/*inExpressionContext*/ true)), pos);
|
|
34679
34670
|
}
|
|
34680
34671
|
function parseJsxSpreadAttribute() {
|
|
34681
34672
|
var pos = getNodePos();
|
|
@@ -35301,11 +35292,12 @@ var ts;
|
|
|
35301
35292
|
}
|
|
35302
35293
|
function parseCaseClause() {
|
|
35303
35294
|
var pos = getNodePos();
|
|
35295
|
+
var hasJSDoc = hasPrecedingJSDocComment();
|
|
35304
35296
|
parseExpected(82 /* CaseKeyword */);
|
|
35305
35297
|
var expression = allowInAnd(parseExpression);
|
|
35306
35298
|
parseExpected(58 /* ColonToken */);
|
|
35307
35299
|
var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
|
|
35308
|
-
return finishNode(factory.createCaseClause(expression, statements), pos);
|
|
35300
|
+
return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
|
|
35309
35301
|
}
|
|
35310
35302
|
function parseDefaultClause() {
|
|
35311
35303
|
var pos = getNodePos();
|
|
@@ -38195,6 +38187,19 @@ var ts;
|
|
|
38195
38187
|
return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
|
|
38196
38188
|
}
|
|
38197
38189
|
ts.isDeclarationFileName = isDeclarationFileName;
|
|
38190
|
+
function parseResolutionMode(mode, pos, end, reportDiagnostic) {
|
|
38191
|
+
if (!mode) {
|
|
38192
|
+
return undefined;
|
|
38193
|
+
}
|
|
38194
|
+
if (mode === "import") {
|
|
38195
|
+
return ts.ModuleKind.ESNext;
|
|
38196
|
+
}
|
|
38197
|
+
if (mode === "require") {
|
|
38198
|
+
return ts.ModuleKind.CommonJS;
|
|
38199
|
+
}
|
|
38200
|
+
reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
|
|
38201
|
+
return undefined;
|
|
38202
|
+
}
|
|
38198
38203
|
/*@internal*/
|
|
38199
38204
|
function processCommentPragmas(context, sourceText) {
|
|
38200
38205
|
var pragmas = [];
|
|
@@ -38237,12 +38242,13 @@ var ts;
|
|
|
38237
38242
|
var typeReferenceDirectives_1 = context.typeReferenceDirectives;
|
|
38238
38243
|
var libReferenceDirectives_1 = context.libReferenceDirectives;
|
|
38239
38244
|
ts.forEach(ts.toArray(entryOrList), function (arg) {
|
|
38240
|
-
var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
|
|
38245
|
+
var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
|
|
38241
38246
|
if (arg.arguments["no-default-lib"]) {
|
|
38242
38247
|
context.hasNoDefaultLib = true;
|
|
38243
38248
|
}
|
|
38244
38249
|
else if (types) {
|
|
38245
|
-
|
|
38250
|
+
var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
|
|
38251
|
+
typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
|
|
38246
38252
|
}
|
|
38247
38253
|
else if (lib) {
|
|
38248
38254
|
libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
|
|
@@ -41820,14 +41826,14 @@ var ts;
|
|
|
41820
41826
|
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
|
41821
41827
|
* is assumed to be the same as root directory of the project.
|
|
41822
41828
|
*/
|
|
41823
|
-
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
|
|
41829
|
+
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
|
|
41824
41830
|
var traceEnabled = isTraceEnabled(options, host);
|
|
41825
41831
|
if (redirectedReference) {
|
|
41826
41832
|
options = redirectedReference.commandLine.options;
|
|
41827
41833
|
}
|
|
41828
41834
|
var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
|
|
41829
41835
|
var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
|
|
41830
|
-
var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/
|
|
41836
|
+
var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
|
|
41831
41837
|
if (result) {
|
|
41832
41838
|
if (traceEnabled) {
|
|
41833
41839
|
trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
|
|
@@ -41862,7 +41868,18 @@ var ts;
|
|
|
41862
41868
|
}
|
|
41863
41869
|
var failedLookupLocations = [];
|
|
41864
41870
|
var features = getDefaultNodeResolutionFeatures(options);
|
|
41865
|
-
|
|
41871
|
+
// Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
|
|
41872
|
+
// setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
|
|
41873
|
+
// set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
|
|
41874
|
+
// 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,
|
|
41875
|
+
// 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
|
|
41876
|
+
// resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
|
|
41877
|
+
// context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
|
|
41878
|
+
if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
|
|
41879
|
+
features |= NodeResolutionFeatures.EsmMode;
|
|
41880
|
+
}
|
|
41881
|
+
var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
|
|
41882
|
+
var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
|
|
41866
41883
|
var resolved = primaryLookup();
|
|
41867
41884
|
var primary = true;
|
|
41868
41885
|
if (!resolved) {
|
|
@@ -41882,7 +41899,7 @@ var ts;
|
|
|
41882
41899
|
};
|
|
41883
41900
|
}
|
|
41884
41901
|
result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
|
|
41885
|
-
perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/
|
|
41902
|
+
perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
|
|
41886
41903
|
if (traceEnabled)
|
|
41887
41904
|
traceResult(result);
|
|
41888
41905
|
return result;
|
|
@@ -41933,7 +41950,7 @@ var ts;
|
|
|
41933
41950
|
result_4 = searchResult && searchResult.value;
|
|
41934
41951
|
}
|
|
41935
41952
|
else {
|
|
41936
|
-
var candidate =
|
|
41953
|
+
var candidate = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName).path;
|
|
41937
41954
|
result_4 = nodeLoadModuleByRelativeName(Extensions.DtsOnly, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true);
|
|
41938
41955
|
}
|
|
41939
41956
|
return resolvedTypeScriptOnly(result_4);
|
|
@@ -42168,7 +42185,11 @@ var ts;
|
|
|
42168
42185
|
ts.Debug.assert(keys.length === values.length);
|
|
42169
42186
|
var map = createModeAwareCache();
|
|
42170
42187
|
for (var i = 0; i < keys.length; ++i) {
|
|
42171
|
-
|
|
42188
|
+
var entry = keys[i];
|
|
42189
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
42190
|
+
var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
|
|
42191
|
+
var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
|
|
42192
|
+
map.set(name, mode, values[i]);
|
|
42172
42193
|
}
|
|
42173
42194
|
return map;
|
|
42174
42195
|
}
|
|
@@ -42636,13 +42657,25 @@ var ts;
|
|
|
42636
42657
|
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
|
|
42637
42658
|
}
|
|
42638
42659
|
else {
|
|
42639
|
-
var _a =
|
|
42660
|
+
var _a = normalizePathForCJSResolution(containingDirectory, moduleName), candidate = _a.path, parts = _a.parts;
|
|
42640
42661
|
var resolved_2 = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
|
|
42641
42662
|
// Treat explicit "node_modules" import as an external library import.
|
|
42642
42663
|
return resolved_2 && toSearchResult({ resolved: resolved_2, isExternalLibraryImport: ts.contains(parts, "node_modules") });
|
|
42643
42664
|
}
|
|
42644
42665
|
}
|
|
42645
42666
|
}
|
|
42667
|
+
// If you import from "." inside a containing directory "/foo", the result of `normalizePath`
|
|
42668
|
+
// would be "/foo", but this loses the information that `foo` is a directory and we intended
|
|
42669
|
+
// to look inside of it. The Node CommonJS resolution algorithm doesn't call this out
|
|
42670
|
+
// (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
|
|
42671
|
+
// in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
|
|
42672
|
+
function normalizePathForCJSResolution(containingDirectory, moduleName) {
|
|
42673
|
+
var combined = ts.combinePaths(containingDirectory, moduleName);
|
|
42674
|
+
var parts = ts.getPathComponents(combined);
|
|
42675
|
+
var lastPart = ts.lastOrUndefined(parts);
|
|
42676
|
+
var path = lastPart === "." || lastPart === ".." ? ts.ensureTrailingDirectorySeparator(ts.normalizePath(combined)) : ts.normalizePath(combined);
|
|
42677
|
+
return { path: path, parts: parts };
|
|
42678
|
+
}
|
|
42646
42679
|
function realPath(path, host, traceEnabled) {
|
|
42647
42680
|
if (!host.realpath) {
|
|
42648
42681
|
return path;
|
|
@@ -42684,7 +42717,13 @@ var ts;
|
|
|
42684
42717
|
onlyRecordFailures = true;
|
|
42685
42718
|
}
|
|
42686
42719
|
}
|
|
42687
|
-
|
|
42720
|
+
// esm mode relative imports shouldn't do any directory lookups (either inside `package.json`
|
|
42721
|
+
// files or implicit `index.js`es). This is a notable depature from cjs norms, where `./foo/pkg`
|
|
42722
|
+
// could have been redirected by `./foo/pkg/package.json` to an arbitrary location!
|
|
42723
|
+
if (!(state.features & NodeResolutionFeatures.EsmMode)) {
|
|
42724
|
+
return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
|
|
42725
|
+
}
|
|
42726
|
+
return undefined;
|
|
42688
42727
|
}
|
|
42689
42728
|
/*@internal*/
|
|
42690
42729
|
ts.nodeModulesPathPart = "/node_modules/";
|
|
@@ -43051,7 +43090,16 @@ var ts;
|
|
|
43051
43090
|
// Even if extensions is DtsOnly, we can still look up a .ts file as a result of package.json "types"
|
|
43052
43091
|
var nextExtensions = extensions === Extensions.DtsOnly ? Extensions.TypeScript : extensions;
|
|
43053
43092
|
// Don't do package.json lookup recursively, because Node.js' package lookup doesn't.
|
|
43054
|
-
|
|
43093
|
+
// Disable `EsmMode` for the resolution of the package path for cjs-mode packages (so the `main` field can omit extensions)
|
|
43094
|
+
// (technically it only emits a deprecation warning in esm packages right now, but that's probably
|
|
43095
|
+
// enough to mean we don't need to support it)
|
|
43096
|
+
var features = state.features;
|
|
43097
|
+
if ((jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.type) !== "module") {
|
|
43098
|
+
state.features &= ~NodeResolutionFeatures.EsmMode;
|
|
43099
|
+
}
|
|
43100
|
+
var result = nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
|
|
43101
|
+
state.features = features;
|
|
43102
|
+
return result;
|
|
43055
43103
|
};
|
|
43056
43104
|
var onlyRecordFailuresForPackageFile = packageFile ? !ts.directoryProbablyExists(ts.getDirectoryPath(packageFile), state.host) : undefined;
|
|
43057
43105
|
var onlyRecordFailuresForIndex = onlyRecordFailures || !ts.directoryProbablyExists(candidate, state.host);
|
|
@@ -43396,6 +43444,14 @@ var ts;
|
|
|
43396
43444
|
}
|
|
43397
43445
|
var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
|
|
43398
43446
|
loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths);
|
|
43447
|
+
if (!pathAndExtension && packageInfo
|
|
43448
|
+
&& packageInfo.packageJsonContent.exports === undefined
|
|
43449
|
+
&& packageInfo.packageJsonContent.main === undefined
|
|
43450
|
+
&& state.features & NodeResolutionFeatures.EsmMode) {
|
|
43451
|
+
// EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
|
|
43452
|
+
// a default `index.js` entrypoint if no `main` or `exports` are present
|
|
43453
|
+
pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state);
|
|
43454
|
+
}
|
|
43399
43455
|
return withPackageId(packageInfo, pathAndExtension);
|
|
43400
43456
|
};
|
|
43401
43457
|
if (rest !== "") { // If "rest" is empty, we just did this search above.
|
|
@@ -46162,12 +46218,14 @@ var ts;
|
|
|
46162
46218
|
}
|
|
46163
46219
|
}
|
|
46164
46220
|
function setCommonJsModuleIndicator(node) {
|
|
46165
|
-
if (file.externalModuleIndicator) {
|
|
46221
|
+
if (file.externalModuleIndicator && file.commonJsModuleIndicator) {
|
|
46166
46222
|
return false;
|
|
46167
46223
|
}
|
|
46168
|
-
if (
|
|
46224
|
+
if (file.commonJsModuleIndicator === undefined) {
|
|
46169
46225
|
file.commonJsModuleIndicator = node;
|
|
46170
|
-
|
|
46226
|
+
if (file.externalModuleIndicator === undefined) {
|
|
46227
|
+
bindSourceFileAsExternalModule();
|
|
46228
|
+
}
|
|
46171
46229
|
}
|
|
46172
46230
|
return true;
|
|
46173
46231
|
}
|
|
@@ -47153,8 +47211,7 @@ var ts;
|
|
|
47153
47211
|
IntersectionState[IntersectionState["Source"] = 1] = "Source";
|
|
47154
47212
|
IntersectionState[IntersectionState["Target"] = 2] = "Target";
|
|
47155
47213
|
IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
|
|
47156
|
-
IntersectionState[IntersectionState["
|
|
47157
|
-
IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
|
|
47214
|
+
IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
|
|
47158
47215
|
})(IntersectionState || (IntersectionState = {}));
|
|
47159
47216
|
var RecursionFlags;
|
|
47160
47217
|
(function (RecursionFlags) {
|
|
@@ -50613,8 +50670,15 @@ var ts;
|
|
|
50613
50670
|
return res;
|
|
50614
50671
|
}
|
|
50615
50672
|
var candidates = ts.mapDefined(symbol.declarations, function (d) {
|
|
50616
|
-
if (!ts.isAmbientModule(d) && d.parent
|
|
50617
|
-
|
|
50673
|
+
if (!ts.isAmbientModule(d) && d.parent) {
|
|
50674
|
+
// direct children of a module
|
|
50675
|
+
if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
|
|
50676
|
+
return getSymbolOfNode(d.parent);
|
|
50677
|
+
}
|
|
50678
|
+
// export ='d member of an ambient module
|
|
50679
|
+
if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
|
|
50680
|
+
return getSymbolOfNode(d.parent.parent);
|
|
50681
|
+
}
|
|
50618
50682
|
}
|
|
50619
50683
|
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)) {
|
|
50620
50684
|
if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
|
|
@@ -58868,13 +58932,15 @@ var ts;
|
|
|
58868
58932
|
return signature;
|
|
58869
58933
|
}
|
|
58870
58934
|
function getOrCreateTypeFromSignature(signature) {
|
|
58935
|
+
var _a;
|
|
58871
58936
|
// There are two ways to declare a construct signature, one is by declaring a class constructor
|
|
58872
58937
|
// using the constructor keyword, and the other is declaring a bare construct signature in an
|
|
58873
58938
|
// object type literal or interface (using the new keyword). Each way of declaring a constructor
|
|
58874
58939
|
// will result in a different declaration kind.
|
|
58875
58940
|
if (!signature.isolatedSignatureType) {
|
|
58876
|
-
var kind =
|
|
58877
|
-
|
|
58941
|
+
var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
|
|
58942
|
+
// If declaration is undefined, it is likely to be the signature of the default constructor.
|
|
58943
|
+
var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
|
|
58878
58944
|
var type = createObjectType(16 /* Anonymous */);
|
|
58879
58945
|
type.members = emptySymbols;
|
|
58880
58946
|
type.properties = ts.emptyArray;
|
|
@@ -63349,9 +63415,11 @@ var ts;
|
|
|
63349
63415
|
isEnumTypeRelatedTo(getParentOfSymbol(source.symbol), getParentOfSymbol(target.symbol), errorReporter))
|
|
63350
63416
|
return true;
|
|
63351
63417
|
}
|
|
63352
|
-
|
|
63418
|
+
// In non-strictNullChecks mode, `undefined` and `null` are assignable to anything except `never`.
|
|
63419
|
+
// Since unions and intersections may reduce to `never`, we exclude them here.
|
|
63420
|
+
if (s & 32768 /* Undefined */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & (32768 /* Undefined */ | 16384 /* Void */)))
|
|
63353
63421
|
return true;
|
|
63354
|
-
if (s & 65536 /* Null */ && (!strictNullChecks || t & 65536 /* Null */))
|
|
63422
|
+
if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
|
|
63355
63423
|
return true;
|
|
63356
63424
|
if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
|
|
63357
63425
|
return true;
|
|
@@ -63440,11 +63508,11 @@ var ts;
|
|
|
63440
63508
|
var overflow = false;
|
|
63441
63509
|
var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
|
|
63442
63510
|
var lastSkippedInfo;
|
|
63443
|
-
var incompatibleStack
|
|
63511
|
+
var incompatibleStack;
|
|
63444
63512
|
var inPropertyCheck = false;
|
|
63445
63513
|
ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
|
|
63446
63514
|
var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
|
|
63447
|
-
if (incompatibleStack
|
|
63515
|
+
if (incompatibleStack) {
|
|
63448
63516
|
reportIncompatibleStack();
|
|
63449
63517
|
}
|
|
63450
63518
|
if (overflow) {
|
|
@@ -63501,19 +63569,19 @@ var ts;
|
|
|
63501
63569
|
return {
|
|
63502
63570
|
errorInfo: errorInfo,
|
|
63503
63571
|
lastSkippedInfo: lastSkippedInfo,
|
|
63504
|
-
incompatibleStack: incompatibleStack.slice(),
|
|
63572
|
+
incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
|
|
63505
63573
|
overrideNextErrorInfo: overrideNextErrorInfo,
|
|
63506
|
-
relatedInfo:
|
|
63574
|
+
relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
|
|
63507
63575
|
};
|
|
63508
63576
|
}
|
|
63509
63577
|
function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
|
|
63510
63578
|
overrideNextErrorInfo++; // Suppress the next relation error
|
|
63511
63579
|
lastSkippedInfo = undefined; // Reset skipped info cache
|
|
63512
|
-
incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
|
|
63580
|
+
(incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
|
|
63513
63581
|
}
|
|
63514
63582
|
function reportIncompatibleStack() {
|
|
63515
|
-
var stack = incompatibleStack;
|
|
63516
|
-
incompatibleStack =
|
|
63583
|
+
var stack = incompatibleStack || [];
|
|
63584
|
+
incompatibleStack = undefined;
|
|
63517
63585
|
var info = lastSkippedInfo;
|
|
63518
63586
|
lastSkippedInfo = undefined;
|
|
63519
63587
|
if (stack.length === 1) {
|
|
@@ -63619,7 +63687,7 @@ var ts;
|
|
|
63619
63687
|
}
|
|
63620
63688
|
function reportError(message, arg0, arg1, arg2, arg3) {
|
|
63621
63689
|
ts.Debug.assert(!!errorNode);
|
|
63622
|
-
if (incompatibleStack
|
|
63690
|
+
if (incompatibleStack)
|
|
63623
63691
|
reportIncompatibleStack();
|
|
63624
63692
|
if (message.elidedInCompatabilityPyramid)
|
|
63625
63693
|
return;
|
|
@@ -63635,7 +63703,7 @@ var ts;
|
|
|
63635
63703
|
}
|
|
63636
63704
|
}
|
|
63637
63705
|
function reportRelationError(message, source, target) {
|
|
63638
|
-
if (incompatibleStack
|
|
63706
|
+
if (incompatibleStack)
|
|
63639
63707
|
reportIncompatibleStack();
|
|
63640
63708
|
var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
|
|
63641
63709
|
var generalizedSource = source;
|
|
@@ -63747,7 +63815,9 @@ var ts;
|
|
|
63747
63815
|
if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
|
|
63748
63816
|
return -1 /* True */;
|
|
63749
63817
|
}
|
|
63750
|
-
|
|
63818
|
+
if (reportErrors) {
|
|
63819
|
+
reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
|
|
63820
|
+
}
|
|
63751
63821
|
return 0 /* False */;
|
|
63752
63822
|
}
|
|
63753
63823
|
// Normalize the source and target types: Turn fresh literal types into regular literal types,
|
|
@@ -63759,7 +63829,12 @@ var ts;
|
|
|
63759
63829
|
if (source === target)
|
|
63760
63830
|
return -1 /* True */;
|
|
63761
63831
|
if (relation === identityRelation) {
|
|
63762
|
-
|
|
63832
|
+
if (source.flags !== target.flags)
|
|
63833
|
+
return 0 /* False */;
|
|
63834
|
+
if (source.flags & 67358815 /* Singleton */)
|
|
63835
|
+
return -1 /* True */;
|
|
63836
|
+
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63837
|
+
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
63763
63838
|
}
|
|
63764
63839
|
// We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
|
|
63765
63840
|
// and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
|
|
@@ -63769,163 +63844,130 @@ var ts;
|
|
|
63769
63844
|
if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
|
|
63770
63845
|
return -1 /* True */;
|
|
63771
63846
|
}
|
|
63772
|
-
//
|
|
63773
|
-
// If so,
|
|
63774
|
-
|
|
63775
|
-
|
|
63776
|
-
|
|
63777
|
-
|
|
63778
|
-
|
|
63779
|
-
|
|
63780
|
-
|
|
63781
|
-
|
|
63782
|
-
|
|
63783
|
-
|
|
63784
|
-
if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
|
|
63785
|
-
target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
|
|
63786
|
-
}
|
|
63787
|
-
if (source === nullStrippedTarget)
|
|
63788
|
-
return -1 /* True */;
|
|
63847
|
+
// See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
|
|
63848
|
+
// plus a single non-nullable type. If so, remove null and/or undefined from the target type.
|
|
63849
|
+
if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
|
|
63850
|
+
var types = target.types;
|
|
63851
|
+
var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
|
|
63852
|
+
types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
|
|
63853
|
+
undefined;
|
|
63854
|
+
if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
|
|
63855
|
+
target = getNormalizedType(candidate, /*writing*/ true);
|
|
63856
|
+
if (source === target)
|
|
63857
|
+
return -1 /* True */;
|
|
63858
|
+
}
|
|
63789
63859
|
}
|
|
63790
63860
|
if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
|
|
63791
63861
|
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
|
|
63792
63862
|
return -1 /* True */;
|
|
63793
|
-
|
|
63794
|
-
|
|
63795
|
-
|
|
63796
|
-
|
|
63863
|
+
if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
|
|
63864
|
+
var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
|
|
63865
|
+
if (isPerformingExcessPropertyChecks) {
|
|
63866
|
+
if (hasExcessProperties(source, target, reportErrors)) {
|
|
63867
|
+
if (reportErrors) {
|
|
63868
|
+
reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
|
|
63869
|
+
}
|
|
63870
|
+
return 0 /* False */;
|
|
63871
|
+
}
|
|
63872
|
+
}
|
|
63873
|
+
var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
|
|
63874
|
+
source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
|
|
63875
|
+
target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
|
|
63876
|
+
(getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
|
|
63877
|
+
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
|
|
63878
|
+
if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
|
|
63797
63879
|
if (reportErrors) {
|
|
63798
|
-
|
|
63880
|
+
var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
|
|
63881
|
+
var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
|
|
63882
|
+
var calls = getSignaturesOfType(source, 0 /* Call */);
|
|
63883
|
+
var constructs = getSignaturesOfType(source, 1 /* Construct */);
|
|
63884
|
+
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
|
|
63885
|
+
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
|
|
63886
|
+
reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
|
|
63887
|
+
}
|
|
63888
|
+
else {
|
|
63889
|
+
reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
|
|
63890
|
+
}
|
|
63799
63891
|
}
|
|
63800
63892
|
return 0 /* False */;
|
|
63801
63893
|
}
|
|
63802
|
-
|
|
63803
|
-
|
|
63804
|
-
|
|
63805
|
-
|
|
63806
|
-
|
|
63807
|
-
|
|
63808
|
-
|
|
63809
|
-
|
|
63810
|
-
|
|
63811
|
-
|
|
63812
|
-
|
|
63813
|
-
|
|
63814
|
-
|
|
63815
|
-
|
|
63816
|
-
|
|
63817
|
-
|
|
63818
|
-
|
|
63819
|
-
|
|
63894
|
+
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63895
|
+
var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
|
|
63896
|
+
target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
|
|
63897
|
+
var result_7 = skipCaching ?
|
|
63898
|
+
unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
|
|
63899
|
+
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
|
|
63900
|
+
// For certain combinations involving intersections and optional, excess, or mismatched properties we need
|
|
63901
|
+
// an extra property check where the intersection is viewed as a single object. The following are motivating
|
|
63902
|
+
// examples that all should be errors, but aren't without this extra property check:
|
|
63903
|
+
//
|
|
63904
|
+
// let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
|
|
63905
|
+
//
|
|
63906
|
+
// declare let wrong: { a: { y: string } };
|
|
63907
|
+
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
|
|
63908
|
+
//
|
|
63909
|
+
// function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
|
|
63910
|
+
// x = y; // Mismatched property in source intersection
|
|
63911
|
+
// }
|
|
63912
|
+
//
|
|
63913
|
+
// We suppress recursive intersection property checks because they can generate lots of work when relating
|
|
63914
|
+
// recursive intersections that are structurally similar but not exactly identical. See #37854.
|
|
63915
|
+
if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
63916
|
+
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 */); }))) {
|
|
63917
|
+
inPropertyCheck = true;
|
|
63918
|
+
result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
63919
|
+
inPropertyCheck = false;
|
|
63920
|
+
}
|
|
63921
|
+
if (result_7) {
|
|
63922
|
+
return result_7;
|
|
63820
63923
|
}
|
|
63821
|
-
return 0 /* False */;
|
|
63822
|
-
}
|
|
63823
|
-
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63824
|
-
var result = 0 /* False */;
|
|
63825
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
63826
|
-
if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
|
|
63827
|
-
// We skip caching when source or target is a union with no more than three constituents.
|
|
63828
|
-
result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
|
|
63829
63924
|
}
|
|
63830
|
-
|
|
63831
|
-
|
|
63925
|
+
if (reportErrors) {
|
|
63926
|
+
reportErrorResults(originalSource, originalTarget, source, target, headMessage);
|
|
63832
63927
|
}
|
|
63833
|
-
|
|
63834
|
-
|
|
63835
|
-
|
|
63928
|
+
return 0 /* False */;
|
|
63929
|
+
}
|
|
63930
|
+
function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
|
|
63931
|
+
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
63932
|
+
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
63933
|
+
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
63934
|
+
target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
|
|
63935
|
+
var maybeSuppress = overrideNextErrorInfo > 0;
|
|
63936
|
+
if (maybeSuppress) {
|
|
63937
|
+
overrideNextErrorInfo--;
|
|
63938
|
+
}
|
|
63939
|
+
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
63940
|
+
var currentError = errorInfo;
|
|
63941
|
+
tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
|
|
63942
|
+
if (errorInfo !== currentError) {
|
|
63943
|
+
maybeSuppress = !!errorInfo;
|
|
63944
|
+
}
|
|
63945
|
+
}
|
|
63946
|
+
if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
|
|
63947
|
+
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
63948
|
+
}
|
|
63949
|
+
else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
|
|
63950
|
+
reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
|
|
63951
|
+
}
|
|
63952
|
+
else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
|
|
63953
|
+
var targetTypes = target.types;
|
|
63954
|
+
var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
|
|
63955
|
+
var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
|
|
63956
|
+
if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
|
|
63957
|
+
(ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
|
|
63958
|
+
// do not report top error
|
|
63959
|
+
return;
|
|
63836
63960
|
}
|
|
63837
63961
|
}
|
|
63838
|
-
|
|
63839
|
-
|
|
63840
|
-
// the constituents. When an intersection type contains instantiable types with union type
|
|
63841
|
-
// constraints, there are situations where we need to examine the combined constraint. One is
|
|
63842
|
-
// when the target is a union type. Another is when the intersection contains types belonging
|
|
63843
|
-
// to one of the disjoint domains. For example, given type variables T and U, each with the
|
|
63844
|
-
// constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
|
|
63845
|
-
// we need to check this constraint against a union on the target side. Also, given a type
|
|
63846
|
-
// variable V constrained to 'string | number', 'V & number' has a combined constraint of
|
|
63847
|
-
// 'string & number | number & number' which reduces to just 'number'.
|
|
63848
|
-
// This also handles type parameters, as a type parameter with a union constraint compared against a union
|
|
63849
|
-
// needs to have its constraint hoisted into an intersection with said type parameter, this way
|
|
63850
|
-
// the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
|
|
63851
|
-
// For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
|
|
63852
|
-
var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
|
|
63853
|
-
if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
|
|
63854
|
-
if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
63855
|
-
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
63856
|
-
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
63857
|
-
resetErrorInfo(saveErrorInfo);
|
|
63858
|
-
}
|
|
63859
|
-
}
|
|
63860
|
-
}
|
|
63962
|
+
else {
|
|
63963
|
+
errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
|
|
63861
63964
|
}
|
|
63862
|
-
|
|
63863
|
-
|
|
63864
|
-
|
|
63865
|
-
|
|
63866
|
-
// let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
|
|
63867
|
-
//
|
|
63868
|
-
// declare let wrong: { a: { y: string } };
|
|
63869
|
-
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
|
|
63870
|
-
//
|
|
63871
|
-
// function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
|
|
63872
|
-
// x = y; // Mismatched property in source intersection
|
|
63873
|
-
// }
|
|
63874
|
-
//
|
|
63875
|
-
// We suppress recursive intersection property checks because they can generate lots of work when relating
|
|
63876
|
-
// recursive intersections that are structurally similar but not exactly identical. See #37854.
|
|
63877
|
-
if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
|
|
63878
|
-
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 */); }))) {
|
|
63879
|
-
inPropertyCheck = true;
|
|
63880
|
-
result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
|
|
63881
|
-
inPropertyCheck = false;
|
|
63882
|
-
}
|
|
63883
|
-
reportErrorResults(source, target, result, isComparingJsxAttributes);
|
|
63884
|
-
return result;
|
|
63885
|
-
function reportErrorResults(source, target, result, isComparingJsxAttributes) {
|
|
63886
|
-
if (!result && reportErrors) {
|
|
63887
|
-
var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
|
|
63888
|
-
var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
|
|
63889
|
-
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
|
|
63890
|
-
target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
|
|
63891
|
-
var maybeSuppress = overrideNextErrorInfo > 0;
|
|
63892
|
-
if (maybeSuppress) {
|
|
63893
|
-
overrideNextErrorInfo--;
|
|
63894
|
-
}
|
|
63895
|
-
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
63896
|
-
var currentError = errorInfo;
|
|
63897
|
-
tryElaborateArrayLikeErrors(source, target, reportErrors);
|
|
63898
|
-
if (errorInfo !== currentError) {
|
|
63899
|
-
maybeSuppress = !!errorInfo;
|
|
63900
|
-
}
|
|
63901
|
-
}
|
|
63902
|
-
if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
|
|
63903
|
-
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
63904
|
-
}
|
|
63905
|
-
else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
|
|
63906
|
-
reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
|
|
63907
|
-
}
|
|
63908
|
-
else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
|
|
63909
|
-
var targetTypes = target.types;
|
|
63910
|
-
var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
|
|
63911
|
-
var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
|
|
63912
|
-
if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
|
|
63913
|
-
(ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
|
|
63914
|
-
// do not report top error
|
|
63915
|
-
return result;
|
|
63916
|
-
}
|
|
63917
|
-
}
|
|
63918
|
-
else {
|
|
63919
|
-
errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
|
|
63920
|
-
}
|
|
63921
|
-
if (!headMessage && maybeSuppress) {
|
|
63922
|
-
lastSkippedInfo = [source, target];
|
|
63923
|
-
// Used by, eg, missing property checking to replace the top-level message with a more informative one
|
|
63924
|
-
return result;
|
|
63925
|
-
}
|
|
63926
|
-
reportRelationError(headMessage, source, target);
|
|
63927
|
-
}
|
|
63965
|
+
if (!headMessage && maybeSuppress) {
|
|
63966
|
+
lastSkippedInfo = [source, target];
|
|
63967
|
+
// Used by, eg, missing property checking to replace the top-level message with a more informative one
|
|
63968
|
+
return;
|
|
63928
63969
|
}
|
|
63970
|
+
reportRelationError(headMessage, source, target);
|
|
63929
63971
|
}
|
|
63930
63972
|
function traceUnionsOrIntersectionsTooLarge(source, target) {
|
|
63931
63973
|
if (!ts.tracing) {
|
|
@@ -63952,21 +63994,6 @@ var ts;
|
|
|
63952
63994
|
}
|
|
63953
63995
|
}
|
|
63954
63996
|
}
|
|
63955
|
-
function isIdenticalTo(source, target, recursionFlags) {
|
|
63956
|
-
if (source.flags !== target.flags)
|
|
63957
|
-
return 0 /* False */;
|
|
63958
|
-
if (source.flags & 67358815 /* Singleton */)
|
|
63959
|
-
return -1 /* True */;
|
|
63960
|
-
traceUnionsOrIntersectionsTooLarge(source, target);
|
|
63961
|
-
if (source.flags & 3145728 /* UnionOrIntersection */) {
|
|
63962
|
-
var result_7 = eachTypeRelatedToSomeType(source, target);
|
|
63963
|
-
if (result_7) {
|
|
63964
|
-
result_7 &= eachTypeRelatedToSomeType(target, source);
|
|
63965
|
-
}
|
|
63966
|
-
return result_7;
|
|
63967
|
-
}
|
|
63968
|
-
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
|
|
63969
|
-
}
|
|
63970
63997
|
function getTypeOfPropertyInTypes(types, name) {
|
|
63971
63998
|
var appendPropType = function (propTypes, type) {
|
|
63972
63999
|
var _a;
|
|
@@ -64065,6 +64092,41 @@ var ts;
|
|
|
64065
64092
|
function shouldCheckAsExcessProperty(prop, container) {
|
|
64066
64093
|
return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
|
|
64067
64094
|
}
|
|
64095
|
+
function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
|
|
64096
|
+
// Note that these checks are specifically ordered to produce correct results. In particular,
|
|
64097
|
+
// we need to deconstruct unions before intersections (because unions are always at the top),
|
|
64098
|
+
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
|
64099
|
+
if (source.flags & 1048576 /* Union */) {
|
|
64100
|
+
return relation === comparableRelation ?
|
|
64101
|
+
someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
|
|
64102
|
+
eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
|
|
64103
|
+
}
|
|
64104
|
+
if (target.flags & 1048576 /* Union */) {
|
|
64105
|
+
return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
|
|
64106
|
+
}
|
|
64107
|
+
if (target.flags & 2097152 /* Intersection */) {
|
|
64108
|
+
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
|
|
64109
|
+
}
|
|
64110
|
+
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
|
|
64111
|
+
// constraints of all non-primitive types in the source into a new intersection. We do this because the
|
|
64112
|
+
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
|
|
64113
|
+
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
|
|
64114
|
+
// appear to be comparable to '2'.
|
|
64115
|
+
if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
|
|
64116
|
+
var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
|
|
64117
|
+
if (constraints !== source.types) {
|
|
64118
|
+
source = getIntersectionType(constraints);
|
|
64119
|
+
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
64120
|
+
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
64121
|
+
}
|
|
64122
|
+
}
|
|
64123
|
+
}
|
|
64124
|
+
// Check to see if any constituents of the intersection are immediately related to the target.
|
|
64125
|
+
// Don't report errors though. Elaborating on whether a source constituent is related to the target is
|
|
64126
|
+
// not actually useful and leads to some confusing error messages. Instead, we rely on the caller
|
|
64127
|
+
// checking whether the full intersection viewed as an object is related to the target.
|
|
64128
|
+
return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
|
|
64129
|
+
}
|
|
64068
64130
|
function eachTypeRelatedToSomeType(source, target) {
|
|
64069
64131
|
var result = -1 /* True */;
|
|
64070
64132
|
var sourceTypes = source.types;
|
|
@@ -64100,8 +64162,11 @@ var ts;
|
|
|
64100
64162
|
}
|
|
64101
64163
|
}
|
|
64102
64164
|
if (reportErrors) {
|
|
64165
|
+
// Elaborate only if we can find a best matching type in the target union
|
|
64103
64166
|
var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
|
|
64104
|
-
|
|
64167
|
+
if (bestMatchingType) {
|
|
64168
|
+
isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
|
|
64169
|
+
}
|
|
64105
64170
|
}
|
|
64106
64171
|
return 0 /* False */;
|
|
64107
64172
|
}
|
|
@@ -64237,7 +64302,7 @@ var ts;
|
|
|
64237
64302
|
if (overflow) {
|
|
64238
64303
|
return 0 /* False */;
|
|
64239
64304
|
}
|
|
64240
|
-
var keyIntersectionState = intersectionState | (inPropertyCheck ?
|
|
64305
|
+
var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
|
|
64241
64306
|
var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
|
|
64242
64307
|
var entry = relation.get(id);
|
|
64243
64308
|
if (entry !== undefined) {
|
|
@@ -64305,6 +64370,7 @@ var ts;
|
|
|
64305
64370
|
return originalHandler(onlyUnreliable);
|
|
64306
64371
|
};
|
|
64307
64372
|
}
|
|
64373
|
+
var result;
|
|
64308
64374
|
if (expandingFlags === 3 /* Both */) {
|
|
64309
64375
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
|
|
64310
64376
|
sourceId: source.id,
|
|
@@ -64314,8 +64380,13 @@ var ts;
|
|
|
64314
64380
|
depth: sourceDepth,
|
|
64315
64381
|
targetDepth: targetDepth
|
|
64316
64382
|
});
|
|
64383
|
+
result = 3 /* Maybe */;
|
|
64384
|
+
}
|
|
64385
|
+
else {
|
|
64386
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
|
|
64387
|
+
result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
|
|
64388
|
+
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
64317
64389
|
}
|
|
64318
|
-
var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
|
|
64319
64390
|
if (outofbandVarianceMarkerHandler) {
|
|
64320
64391
|
outofbandVarianceMarkerHandler = originalHandler;
|
|
64321
64392
|
}
|
|
@@ -64347,98 +64418,97 @@ var ts;
|
|
|
64347
64418
|
return result;
|
|
64348
64419
|
}
|
|
64349
64420
|
function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
|
|
64350
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
|
|
64351
|
-
var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
|
|
64352
|
-
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
64353
|
-
return result;
|
|
64354
|
-
}
|
|
64355
|
-
function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
|
|
64356
64421
|
if (intersectionState & 4 /* PropertyCheck */) {
|
|
64357
64422
|
return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
|
|
64358
64423
|
}
|
|
64359
|
-
|
|
64360
|
-
|
|
64361
|
-
|
|
64362
|
-
|
|
64363
|
-
|
|
64364
|
-
|
|
64365
|
-
|
|
64366
|
-
|
|
64367
|
-
|
|
64368
|
-
|
|
64369
|
-
|
|
64370
|
-
|
|
64371
|
-
if (target.flags & 2097152 /* Intersection */) {
|
|
64372
|
-
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
|
|
64373
|
-
}
|
|
64374
|
-
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
|
|
64375
|
-
// constraints of all non-primitive types in the source into a new intersection. We do this because the
|
|
64376
|
-
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
|
|
64377
|
-
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
|
|
64378
|
-
// appear to be comparable to '2'.
|
|
64379
|
-
if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
|
|
64380
|
-
var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
|
|
64381
|
-
if (constraints !== source.types) {
|
|
64382
|
-
source = getIntersectionType(constraints);
|
|
64383
|
-
if (!(source.flags & 2097152 /* Intersection */)) {
|
|
64384
|
-
return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
|
|
64385
|
-
}
|
|
64424
|
+
var result;
|
|
64425
|
+
var originalErrorInfo;
|
|
64426
|
+
var varianceCheckFailed = false;
|
|
64427
|
+
var saveErrorInfo = captureErrorCalculationState();
|
|
64428
|
+
var sourceFlags = source.flags;
|
|
64429
|
+
var targetFlags = target.flags;
|
|
64430
|
+
if (relation === identityRelation) {
|
|
64431
|
+
// We've already checked that source.flags and target.flags are identical
|
|
64432
|
+
if (sourceFlags & 3145728 /* UnionOrIntersection */) {
|
|
64433
|
+
var result_8 = eachTypeRelatedToSomeType(source, target);
|
|
64434
|
+
if (result_8) {
|
|
64435
|
+
result_8 &= eachTypeRelatedToSomeType(target, source);
|
|
64386
64436
|
}
|
|
64437
|
+
return result_8;
|
|
64387
64438
|
}
|
|
64388
|
-
|
|
64389
|
-
//
|
|
64390
|
-
// Don't report errors though. Checking whether a constituent is related to the source is not actually
|
|
64391
|
-
// useful and leads to some confusing error messages. Instead it is better to let the below checks
|
|
64392
|
-
// take care of this, or to not elaborate at all. For instance,
|
|
64393
|
-
//
|
|
64394
|
-
// - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
|
|
64395
|
-
//
|
|
64396
|
-
// - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
|
|
64397
|
-
// than to report that 'D' is not assignable to 'A' or 'B'.
|
|
64398
|
-
//
|
|
64399
|
-
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
|
|
64400
|
-
// breaking the intersection apart.
|
|
64401
|
-
return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
|
|
64402
|
-
}
|
|
64403
|
-
var flags = source.flags & target.flags;
|
|
64404
|
-
if (relation === identityRelation && !(flags & 524288 /* Object */)) {
|
|
64405
|
-
if (flags & 4194304 /* Index */) {
|
|
64439
|
+
if (sourceFlags & 4194304 /* Index */) {
|
|
64406
64440
|
return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
|
|
64407
64441
|
}
|
|
64408
|
-
|
|
64409
|
-
|
|
64410
|
-
|
|
64411
|
-
|
|
64412
|
-
return result_8;
|
|
64442
|
+
if (sourceFlags & 8388608 /* IndexedAccess */) {
|
|
64443
|
+
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64444
|
+
if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64445
|
+
return result;
|
|
64413
64446
|
}
|
|
64414
64447
|
}
|
|
64415
64448
|
}
|
|
64416
|
-
if (
|
|
64449
|
+
if (sourceFlags & 16777216 /* Conditional */) {
|
|
64417
64450
|
if (source.root.isDistributive === target.root.isDistributive) {
|
|
64418
|
-
if (
|
|
64419
|
-
if (
|
|
64420
|
-
if (
|
|
64421
|
-
if (
|
|
64422
|
-
return
|
|
64451
|
+
if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64452
|
+
if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64453
|
+
if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
64454
|
+
if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
|
|
64455
|
+
return result;
|
|
64423
64456
|
}
|
|
64424
64457
|
}
|
|
64425
64458
|
}
|
|
64426
64459
|
}
|
|
64427
64460
|
}
|
|
64428
64461
|
}
|
|
64429
|
-
if (
|
|
64462
|
+
if (sourceFlags & 33554432 /* Substitution */) {
|
|
64430
64463
|
return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
|
|
64431
64464
|
}
|
|
64432
|
-
|
|
64465
|
+
if (!(sourceFlags & 524288 /* Object */)) {
|
|
64466
|
+
return 0 /* False */;
|
|
64467
|
+
}
|
|
64468
|
+
}
|
|
64469
|
+
else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
|
|
64470
|
+
if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
|
|
64471
|
+
return result;
|
|
64472
|
+
}
|
|
64473
|
+
if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
|
|
64474
|
+
// The combined constraint of an intersection type is the intersection of the constraints of
|
|
64475
|
+
// the constituents. When an intersection type contains instantiable types with union type
|
|
64476
|
+
// constraints, there are situations where we need to examine the combined constraint. One is
|
|
64477
|
+
// when the target is a union type. Another is when the intersection contains types belonging
|
|
64478
|
+
// to one of the disjoint domains. For example, given type variables T and U, each with the
|
|
64479
|
+
// constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
|
|
64480
|
+
// we need to check this constraint against a union on the target side. Also, given a type
|
|
64481
|
+
// variable V constrained to 'string | number', 'V & number' has a combined constraint of
|
|
64482
|
+
// 'string & number | number & number' which reduces to just 'number'.
|
|
64483
|
+
// This also handles type parameters, as a type parameter with a union constraint compared against a union
|
|
64484
|
+
// needs to have its constraint hoisted into an intersection with said type parameter, this way
|
|
64485
|
+
// the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
|
|
64486
|
+
// For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
|
|
64487
|
+
var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
|
|
64488
|
+
if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
|
|
64489
|
+
// TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
|
|
64490
|
+
if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
|
|
64491
|
+
resetErrorInfo(saveErrorInfo);
|
|
64492
|
+
return result;
|
|
64493
|
+
}
|
|
64494
|
+
}
|
|
64495
|
+
}
|
|
64496
|
+
// The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
|
|
64497
|
+
// Source is instantiable (e.g. source has union or intersection constraint).
|
|
64498
|
+
// Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
|
|
64499
|
+
// Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
|
|
64500
|
+
// Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
|
|
64501
|
+
// Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
|
|
64502
|
+
if (!(sourceFlags & 465829888 /* Instantiable */ ||
|
|
64503
|
+
sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
|
|
64504
|
+
sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
|
|
64505
|
+
return 0 /* False */;
|
|
64506
|
+
}
|
|
64433
64507
|
}
|
|
64434
|
-
var result;
|
|
64435
|
-
var originalErrorInfo;
|
|
64436
|
-
var varianceCheckFailed = false;
|
|
64437
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
64438
64508
|
// We limit alias variance probing to only object and conditional types since their alias behavior
|
|
64439
64509
|
// is more predictable than other, interned types, which may or may not have an alias depending on
|
|
64440
64510
|
// the order in which things were checked.
|
|
64441
|
-
if (
|
|
64511
|
+
if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
|
|
64442
64512
|
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
|
|
64443
64513
|
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
|
|
64444
64514
|
var variances = getAliasVariances(source.aliasSymbol);
|
|
@@ -64456,7 +64526,7 @@ var ts;
|
|
|
64456
64526
|
isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
|
|
64457
64527
|
return result;
|
|
64458
64528
|
}
|
|
64459
|
-
if (
|
|
64529
|
+
if (targetFlags & 262144 /* TypeParameter */) {
|
|
64460
64530
|
// 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].
|
|
64461
64531
|
if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
|
|
64462
64532
|
if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
|
|
@@ -64468,10 +64538,10 @@ var ts;
|
|
|
64468
64538
|
}
|
|
64469
64539
|
}
|
|
64470
64540
|
}
|
|
64471
|
-
else if (
|
|
64541
|
+
else if (targetFlags & 4194304 /* Index */) {
|
|
64472
64542
|
var targetType_1 = target.type;
|
|
64473
64543
|
// A keyof S is related to a keyof T if T is related to S.
|
|
64474
|
-
if (
|
|
64544
|
+
if (sourceFlags & 4194304 /* Index */) {
|
|
64475
64545
|
if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
|
|
64476
64546
|
return result;
|
|
64477
64547
|
}
|
|
@@ -64522,8 +64592,8 @@ var ts;
|
|
|
64522
64592
|
}
|
|
64523
64593
|
}
|
|
64524
64594
|
}
|
|
64525
|
-
else if (
|
|
64526
|
-
if (
|
|
64595
|
+
else if (targetFlags & 8388608 /* IndexedAccess */) {
|
|
64596
|
+
if (sourceFlags & 8388608 /* IndexedAccess */) {
|
|
64527
64597
|
// Relate components directly before falling back to constraint relationships
|
|
64528
64598
|
// A type S[K] is related to a type T[J] if S is related to T and K is related to J.
|
|
64529
64599
|
if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
|
|
@@ -64629,7 +64699,7 @@ var ts;
|
|
|
64629
64699
|
}
|
|
64630
64700
|
}
|
|
64631
64701
|
}
|
|
64632
|
-
else if (
|
|
64702
|
+
else if (targetFlags & 16777216 /* Conditional */) {
|
|
64633
64703
|
// If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
|
|
64634
64704
|
// conditional type and bail out with a Ternary.Maybe result.
|
|
64635
64705
|
if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
|
|
@@ -64654,8 +64724,8 @@ var ts;
|
|
|
64654
64724
|
}
|
|
64655
64725
|
}
|
|
64656
64726
|
}
|
|
64657
|
-
else if (
|
|
64658
|
-
if (
|
|
64727
|
+
else if (targetFlags & 134217728 /* TemplateLiteral */) {
|
|
64728
|
+
if (sourceFlags & 134217728 /* TemplateLiteral */) {
|
|
64659
64729
|
if (relation === comparableRelation) {
|
|
64660
64730
|
return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
|
|
64661
64731
|
}
|
|
@@ -64667,11 +64737,11 @@ var ts;
|
|
|
64667
64737
|
return -1 /* True */;
|
|
64668
64738
|
}
|
|
64669
64739
|
}
|
|
64670
|
-
if (
|
|
64671
|
-
// IndexedAccess comparisons are handled above in the `
|
|
64672
|
-
if (!(
|
|
64740
|
+
if (sourceFlags & 8650752 /* TypeVariable */) {
|
|
64741
|
+
// IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
|
|
64742
|
+
if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
|
|
64673
64743
|
var constraint = getConstraintOfType(source);
|
|
64674
|
-
if (!constraint || (
|
|
64744
|
+
if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
|
|
64675
64745
|
// A type variable with no constraint is not related to the non-primitive object type.
|
|
64676
64746
|
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
|
|
64677
64747
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64684,7 +64754,7 @@ var ts;
|
|
|
64684
64754
|
return result;
|
|
64685
64755
|
}
|
|
64686
64756
|
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
|
|
64687
|
-
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(
|
|
64757
|
+
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
|
|
64688
64758
|
resetErrorInfo(saveErrorInfo);
|
|
64689
64759
|
return result;
|
|
64690
64760
|
}
|
|
@@ -64701,14 +64771,14 @@ var ts;
|
|
|
64701
64771
|
}
|
|
64702
64772
|
}
|
|
64703
64773
|
}
|
|
64704
|
-
else if (
|
|
64774
|
+
else if (sourceFlags & 4194304 /* Index */) {
|
|
64705
64775
|
if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
|
|
64706
64776
|
resetErrorInfo(saveErrorInfo);
|
|
64707
64777
|
return result;
|
|
64708
64778
|
}
|
|
64709
64779
|
}
|
|
64710
|
-
else if (
|
|
64711
|
-
if (!(
|
|
64780
|
+
else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
|
|
64781
|
+
if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
|
|
64712
64782
|
var constraint = getBaseConstraintOfType(source);
|
|
64713
64783
|
if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
|
|
64714
64784
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64716,8 +64786,8 @@ var ts;
|
|
|
64716
64786
|
}
|
|
64717
64787
|
}
|
|
64718
64788
|
}
|
|
64719
|
-
else if (
|
|
64720
|
-
if (
|
|
64789
|
+
else if (sourceFlags & 268435456 /* StringMapping */) {
|
|
64790
|
+
if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
|
|
64721
64791
|
if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
|
|
64722
64792
|
resetErrorInfo(saveErrorInfo);
|
|
64723
64793
|
return result;
|
|
@@ -64731,14 +64801,14 @@ var ts;
|
|
|
64731
64801
|
}
|
|
64732
64802
|
}
|
|
64733
64803
|
}
|
|
64734
|
-
else if (
|
|
64804
|
+
else if (sourceFlags & 16777216 /* Conditional */) {
|
|
64735
64805
|
// If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
|
|
64736
64806
|
// conditional type and bail out with a Ternary.Maybe result.
|
|
64737
64807
|
if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
|
|
64738
64808
|
resetErrorInfo(saveErrorInfo);
|
|
64739
64809
|
return 3 /* Maybe */;
|
|
64740
64810
|
}
|
|
64741
|
-
if (
|
|
64811
|
+
if (targetFlags & 16777216 /* Conditional */) {
|
|
64742
64812
|
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
|
|
64743
64813
|
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
|
|
64744
64814
|
// and Y1 is related to Y2.
|
|
@@ -64798,15 +64868,21 @@ var ts;
|
|
|
64798
64868
|
}
|
|
64799
64869
|
return 0 /* False */;
|
|
64800
64870
|
}
|
|
64801
|
-
var sourceIsPrimitive = !!(
|
|
64871
|
+
var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
|
|
64802
64872
|
if (relation !== identityRelation) {
|
|
64803
64873
|
source = getApparentType(source);
|
|
64874
|
+
sourceFlags = source.flags;
|
|
64804
64875
|
}
|
|
64805
64876
|
else if (isGenericMappedType(source)) {
|
|
64806
64877
|
return 0 /* False */;
|
|
64807
64878
|
}
|
|
64808
64879
|
if (ts.getObjectFlags(source) & 4 /* Reference */ && ts.getObjectFlags(target) & 4 /* Reference */ && source.target === target.target &&
|
|
64809
64880
|
!isTupleType(source) && !(ts.getObjectFlags(source) & 4096 /* MarkerType */ || ts.getObjectFlags(target) & 4096 /* MarkerType */)) {
|
|
64881
|
+
// When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
|
|
64882
|
+
// and an empty array literal wouldn't be assignable to a `never[]` without this check.
|
|
64883
|
+
if (isEmptyArrayLiteralType(source)) {
|
|
64884
|
+
return -1 /* True */;
|
|
64885
|
+
}
|
|
64810
64886
|
// We have type references to the same generic type, and the type references are not marker
|
|
64811
64887
|
// type references (which are intended by be compared structurally). Obtain the variance
|
|
64812
64888
|
// information for the type parameters and relate the type arguments accordingly.
|
|
@@ -64842,7 +64918,7 @@ var ts;
|
|
|
64842
64918
|
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
|
|
64843
64919
|
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
|
|
64844
64920
|
// relates to X. Thus, we include intersection types on the source side here.
|
|
64845
|
-
if (
|
|
64921
|
+
if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
|
|
64846
64922
|
// Report structural errors only if we haven't reported any errors yet
|
|
64847
64923
|
var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
|
|
64848
64924
|
result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
|
|
@@ -64866,7 +64942,7 @@ var ts;
|
|
|
64866
64942
|
// there exists a constituent of T for every combination of the discriminants of S
|
|
64867
64943
|
// with respect to T. We do not report errors here, as we will use the existing
|
|
64868
64944
|
// error result from checking each constituent of the union.
|
|
64869
|
-
if (
|
|
64945
|
+
if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
|
|
64870
64946
|
var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
|
|
64871
64947
|
if (objectOnlyTarget.flags & 1048576 /* Union */) {
|
|
64872
64948
|
var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
|
|
@@ -65113,6 +65189,15 @@ var ts;
|
|
|
65113
65189
|
}
|
|
65114
65190
|
return 0 /* False */;
|
|
65115
65191
|
}
|
|
65192
|
+
// Ensure {readonly a: whatever} is not a subtype of {a: whatever},
|
|
65193
|
+
// while {a: whatever} is a subtype of {readonly a: whatever}.
|
|
65194
|
+
// This ensures the subtype relationship is ordered, and preventing declaration order
|
|
65195
|
+
// from deciding which type "wins" in union subtype reduction.
|
|
65196
|
+
// They're still assignable to one another, since `readonly` doesn't affect assignability.
|
|
65197
|
+
if ((relation === subtypeRelation || relation === strictSubtypeRelation) &&
|
|
65198
|
+
!!(sourcePropFlags & 64 /* Readonly */) && !(targetPropFlags & 64 /* Readonly */)) {
|
|
65199
|
+
return 0 /* False */;
|
|
65200
|
+
}
|
|
65116
65201
|
// If the target comes from a partial union prop, allow `undefined` in the target type
|
|
65117
65202
|
var related = isPropertySymbolTypeRelated(sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState);
|
|
65118
65203
|
if (!related) {
|
|
@@ -65381,7 +65466,6 @@ var ts;
|
|
|
65381
65466
|
}
|
|
65382
65467
|
}
|
|
65383
65468
|
var result = -1 /* True */;
|
|
65384
|
-
var saveErrorInfo = captureErrorCalculationState();
|
|
65385
65469
|
var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
|
|
65386
65470
|
var sourceObjectFlags = ts.getObjectFlags(source);
|
|
65387
65471
|
var targetObjectFlags = ts.getObjectFlags(target);
|
|
@@ -65422,6 +65506,7 @@ var ts;
|
|
|
65422
65506
|
else {
|
|
65423
65507
|
outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
|
|
65424
65508
|
var t = targetSignatures_1[_i];
|
|
65509
|
+
var saveErrorInfo = captureErrorCalculationState();
|
|
65425
65510
|
// Only elaborate errors from the first failure
|
|
65426
65511
|
var shouldElaborateErrors = reportErrors;
|
|
65427
65512
|
for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
|
|
@@ -68592,9 +68677,6 @@ var ts;
|
|
|
68592
68677
|
getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
|
|
68593
68678
|
mapType(type, mapper);
|
|
68594
68679
|
}
|
|
68595
|
-
function getConstituentCount(type) {
|
|
68596
|
-
return type.flags & 1048576 /* Union */ ? type.types.length : 1;
|
|
68597
|
-
}
|
|
68598
68680
|
function extractTypesOfKind(type, kind) {
|
|
68599
68681
|
return filterType(type, function (t) { return (t.flags & kind) !== 0; });
|
|
68600
68682
|
}
|
|
@@ -76260,21 +76342,22 @@ var ts;
|
|
|
76260
76342
|
if (links.type === unknownType) {
|
|
76261
76343
|
links.type = getTypeFromBindingPattern(declaration.name);
|
|
76262
76344
|
}
|
|
76263
|
-
assignBindingElementTypes(declaration.name);
|
|
76345
|
+
assignBindingElementTypes(declaration.name, links.type);
|
|
76264
76346
|
}
|
|
76265
76347
|
}
|
|
76266
76348
|
}
|
|
76267
76349
|
// When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
|
|
76268
76350
|
// the destructured type into the contained binding elements.
|
|
76269
|
-
function assignBindingElementTypes(pattern) {
|
|
76351
|
+
function assignBindingElementTypes(pattern, parentType) {
|
|
76270
76352
|
for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
|
|
76271
76353
|
var element = _a[_i];
|
|
76272
76354
|
if (!ts.isOmittedExpression(element)) {
|
|
76355
|
+
var type = getBindingElementTypeFromParentType(element, parentType);
|
|
76273
76356
|
if (element.name.kind === 79 /* Identifier */) {
|
|
76274
|
-
getSymbolLinks(getSymbolOfNode(element)).type =
|
|
76357
|
+
getSymbolLinks(getSymbolOfNode(element)).type = type;
|
|
76275
76358
|
}
|
|
76276
76359
|
else {
|
|
76277
|
-
assignBindingElementTypes(element.name);
|
|
76360
|
+
assignBindingElementTypes(element.name, type);
|
|
76278
76361
|
}
|
|
76279
76362
|
}
|
|
76280
76363
|
}
|
|
@@ -80015,28 +80098,24 @@ var ts;
|
|
|
80015
80098
|
if (returnType.flags & 1 /* Any */) {
|
|
80016
80099
|
return;
|
|
80017
80100
|
}
|
|
80101
|
+
var headMessage;
|
|
80018
80102
|
var expectedReturnType;
|
|
80019
|
-
var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
|
80020
|
-
var errorInfo;
|
|
80021
80103
|
switch (node.parent.kind) {
|
|
80022
80104
|
case 256 /* ClassDeclaration */:
|
|
80105
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
|
|
80023
80106
|
var classSymbol = getSymbolOfNode(node.parent);
|
|
80024
80107
|
var classConstructorType = getTypeOfSymbol(classSymbol);
|
|
80025
80108
|
expectedReturnType = getUnionType([classConstructorType, voidType]);
|
|
80026
80109
|
break;
|
|
80027
|
-
case 163 /* Parameter */:
|
|
80028
|
-
expectedReturnType = voidType;
|
|
80029
|
-
errorInfo = ts.chainDiagnosticMessages(
|
|
80030
|
-
/*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
|
|
80031
|
-
break;
|
|
80032
80110
|
case 166 /* PropertyDeclaration */:
|
|
80111
|
+
case 163 /* Parameter */:
|
|
80112
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
|
|
80033
80113
|
expectedReturnType = voidType;
|
|
80034
|
-
errorInfo = ts.chainDiagnosticMessages(
|
|
80035
|
-
/*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
|
|
80036
80114
|
break;
|
|
80037
80115
|
case 168 /* MethodDeclaration */:
|
|
80038
80116
|
case 171 /* GetAccessor */:
|
|
80039
80117
|
case 172 /* SetAccessor */:
|
|
80118
|
+
headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
|
|
80040
80119
|
var methodType = getTypeOfNode(node.parent);
|
|
80041
80120
|
var descriptorType = createTypedPropertyDescriptorType(methodType);
|
|
80042
80121
|
expectedReturnType = getUnionType([descriptorType, voidType]);
|
|
@@ -80044,7 +80123,7 @@ var ts;
|
|
|
80044
80123
|
default:
|
|
80045
80124
|
return ts.Debug.fail();
|
|
80046
80125
|
}
|
|
80047
|
-
checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage
|
|
80126
|
+
checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
|
|
80048
80127
|
}
|
|
80049
80128
|
/**
|
|
80050
80129
|
* If a TypeNode can be resolved to a value symbol imported from an external module, it is
|
|
@@ -85592,7 +85671,7 @@ var ts;
|
|
|
85592
85671
|
if (resolvedTypeReferenceDirectives) {
|
|
85593
85672
|
// populate reverse mapping: file path -> type reference directive that was resolved to this file
|
|
85594
85673
|
fileToDirective = new ts.Map();
|
|
85595
|
-
resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
|
|
85674
|
+
resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
|
|
85596
85675
|
if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
|
|
85597
85676
|
return;
|
|
85598
85677
|
}
|
|
@@ -85600,7 +85679,7 @@ var ts;
|
|
|
85600
85679
|
if (file) {
|
|
85601
85680
|
// Add the transitive closure of path references loaded by this file (as long as they are not)
|
|
85602
85681
|
// part of an existing type reference.
|
|
85603
|
-
addReferencedFilesToTypeDirective(file, key);
|
|
85682
|
+
addReferencedFilesToTypeDirective(file, key, mode);
|
|
85604
85683
|
}
|
|
85605
85684
|
});
|
|
85606
85685
|
}
|
|
@@ -85794,16 +85873,16 @@ var ts;
|
|
|
85794
85873
|
}
|
|
85795
85874
|
return false;
|
|
85796
85875
|
}
|
|
85797
|
-
function addReferencedFilesToTypeDirective(file, key) {
|
|
85876
|
+
function addReferencedFilesToTypeDirective(file, key, mode) {
|
|
85798
85877
|
if (fileToDirective.has(file.path))
|
|
85799
85878
|
return;
|
|
85800
|
-
fileToDirective.set(file.path, key);
|
|
85879
|
+
fileToDirective.set(file.path, [key, mode]);
|
|
85801
85880
|
for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
|
|
85802
|
-
var
|
|
85881
|
+
var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
|
|
85803
85882
|
var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
|
|
85804
85883
|
var referencedFile = host.getSourceFile(resolvedFile);
|
|
85805
85884
|
if (referencedFile) {
|
|
85806
|
-
addReferencedFilesToTypeDirective(referencedFile, key);
|
|
85885
|
+
addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
|
|
85807
85886
|
}
|
|
85808
85887
|
}
|
|
85809
85888
|
}
|
|
@@ -87508,28 +87587,27 @@ var ts;
|
|
|
87508
87587
|
}
|
|
87509
87588
|
function findMostOverlappyType(source, unionTarget) {
|
|
87510
87589
|
var bestMatch;
|
|
87511
|
-
|
|
87512
|
-
|
|
87513
|
-
var
|
|
87514
|
-
|
|
87515
|
-
|
|
87516
|
-
|
|
87517
|
-
|
|
87518
|
-
|
|
87519
|
-
|
|
87520
|
-
|
|
87521
|
-
|
|
87522
|
-
|
|
87523
|
-
|
|
87524
|
-
|
|
87525
|
-
|
|
87526
|
-
|
|
87527
|
-
|
|
87528
|
-
|
|
87529
|
-
|
|
87530
|
-
|
|
87531
|
-
|
|
87532
|
-
matchingCount = 1;
|
|
87590
|
+
if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
|
|
87591
|
+
var matchingCount = 0;
|
|
87592
|
+
for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
|
|
87593
|
+
var target = _a[_i];
|
|
87594
|
+
if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
|
|
87595
|
+
var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
|
|
87596
|
+
if (overlap.flags & 4194304 /* Index */) {
|
|
87597
|
+
// perfect overlap of keys
|
|
87598
|
+
return target;
|
|
87599
|
+
}
|
|
87600
|
+
else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
|
|
87601
|
+
// We only want to account for literal types otherwise.
|
|
87602
|
+
// If we have a union of index types, it seems likely that we
|
|
87603
|
+
// needed to elaborate between two generic mapped types anyway.
|
|
87604
|
+
var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
|
|
87605
|
+
if (len >= matchingCount) {
|
|
87606
|
+
bestMatch = target;
|
|
87607
|
+
matchingCount = len;
|
|
87608
|
+
}
|
|
87609
|
+
}
|
|
87610
|
+
}
|
|
87533
87611
|
}
|
|
87534
87612
|
}
|
|
87535
87613
|
return bestMatch;
|
|
@@ -88215,7 +88293,7 @@ var ts;
|
|
|
88215
88293
|
return factory.updateJsxFragment(node, nodeVisitor(node.openingFragment, visitor, ts.isJsxOpeningFragment), nodesVisitor(node.children, visitor, ts.isJsxChild), nodeVisitor(node.closingFragment, visitor, ts.isJsxClosingFragment));
|
|
88216
88294
|
case 284 /* JsxAttribute */:
|
|
88217
88295
|
ts.Debug.type(node);
|
|
88218
|
-
return factory.updateJsxAttribute(node, nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.initializer, visitor, ts.
|
|
88296
|
+
return factory.updateJsxAttribute(node, nodeVisitor(node.name, visitor, ts.isIdentifier), nodeVisitor(node.initializer, visitor, ts.isStringLiteralOrJsxExpression));
|
|
88219
88297
|
case 285 /* JsxAttributes */:
|
|
88220
88298
|
ts.Debug.type(node);
|
|
88221
88299
|
return factory.updateJsxAttributes(node, nodesVisitor(node.properties, visitor, ts.isJsxAttributeLike));
|
|
@@ -96277,9 +96355,6 @@ var ts;
|
|
|
96277
96355
|
var literal = factory.createStringLiteral(tryDecodeEntities(node.text) || node.text, singleQuote);
|
|
96278
96356
|
return ts.setTextRange(literal, node);
|
|
96279
96357
|
}
|
|
96280
|
-
else if (node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 222 /* TemplateExpression */) {
|
|
96281
|
-
return node;
|
|
96282
|
-
}
|
|
96283
96358
|
else if (node.kind === 287 /* JsxExpression */) {
|
|
96284
96359
|
if (node.expression === undefined) {
|
|
96285
96360
|
return factory.createTrue();
|
|
@@ -97054,8 +97129,6 @@ var ts;
|
|
|
97054
97129
|
return visitReturnStatement(node);
|
|
97055
97130
|
case 216 /* VoidExpression */:
|
|
97056
97131
|
return visitVoidExpression(node);
|
|
97057
|
-
case 284 /* JsxAttribute */:
|
|
97058
|
-
return visitJsxAttribute(node);
|
|
97059
97132
|
default:
|
|
97060
97133
|
return ts.visitEachChild(node, visitor, context);
|
|
97061
97134
|
}
|
|
@@ -97086,13 +97159,6 @@ var ts;
|
|
|
97086
97159
|
}
|
|
97087
97160
|
return ts.visitEachChild(node, visitor, context);
|
|
97088
97161
|
}
|
|
97089
|
-
function visitJsxAttribute(node) {
|
|
97090
|
-
if (node.initializer && ts.isTemplateExpression(node.initializer)) {
|
|
97091
|
-
return factory.createJsxAttribute(ts.visitNode(node.name, visitor, ts.isIdentifier), factory.createJsxExpression(
|
|
97092
|
-
/* dotDotDotToken */ undefined, ts.visitNode(node.initializer, visitor, ts.isExpression)));
|
|
97093
|
-
}
|
|
97094
|
-
return ts.visitEachChild(node, visitor, context);
|
|
97095
|
-
}
|
|
97096
97162
|
function visitCaseBlock(node) {
|
|
97097
97163
|
var ancestorFacts = enterSubtree(7104 /* BlockScopeExcludes */, 0 /* BlockScopeIncludes */);
|
|
97098
97164
|
var updated = ts.visitEachChild(node, visitor, context);
|
|
@@ -106584,7 +106650,7 @@ var ts;
|
|
|
106584
106650
|
var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
|
|
106585
106651
|
hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
|
|
106586
106652
|
collectReferences(sourceFile, refs);
|
|
106587
|
-
recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
|
|
106653
|
+
recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
|
|
106588
106654
|
collectLibs(sourceFile, libs);
|
|
106589
106655
|
return sourceFile;
|
|
106590
106656
|
}
|
|
@@ -106639,9 +106705,10 @@ var ts;
|
|
|
106639
106705
|
return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
|
|
106640
106706
|
}
|
|
106641
106707
|
function getFileReferencesForUsedTypeReferences() {
|
|
106642
|
-
return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()),
|
|
106708
|
+
return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
|
|
106643
106709
|
}
|
|
106644
|
-
function
|
|
106710
|
+
function getFileReferenceForSpecifierModeTuple(_a) {
|
|
106711
|
+
var typeName = _a[0], mode = _a[1];
|
|
106645
106712
|
// Elide type references for which we have imports
|
|
106646
106713
|
if (emittedImports) {
|
|
106647
106714
|
for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
|
|
@@ -106657,7 +106724,7 @@ var ts;
|
|
|
106657
106724
|
}
|
|
106658
106725
|
}
|
|
106659
106726
|
}
|
|
106660
|
-
return { fileName: typeName, pos: -1, end: -1 };
|
|
106727
|
+
return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
|
|
106661
106728
|
}
|
|
106662
106729
|
function mapReferencesIntoArray(references, outputFilePath) {
|
|
106663
106730
|
return function (file) {
|
|
@@ -106677,7 +106744,7 @@ var ts;
|
|
|
106677
106744
|
// If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
|
|
106678
106745
|
// via a non-relative name, emit a type reference directive to that non-relative name, rather than
|
|
106679
106746
|
// a relative path to the declaration file
|
|
106680
|
-
recordTypeReferenceDirectivesIfNecessary([specifier]);
|
|
106747
|
+
recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
|
|
106681
106748
|
return;
|
|
106682
106749
|
}
|
|
106683
106750
|
var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
|
|
@@ -111789,9 +111856,12 @@ var ts;
|
|
|
111789
111856
|
for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
|
|
111790
111857
|
var directive = types_24[_d];
|
|
111791
111858
|
var pos = writer.getTextPos();
|
|
111792
|
-
|
|
111859
|
+
var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
|
|
111860
|
+
? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
|
|
111861
|
+
: "";
|
|
111862
|
+
writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
|
|
111793
111863
|
if (bundleFileInfo)
|
|
111794
|
-
bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
|
|
111864
|
+
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 });
|
|
111795
111865
|
writeLine();
|
|
111796
111866
|
}
|
|
111797
111867
|
for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
|
|
@@ -114398,7 +114468,7 @@ var ts;
|
|
|
114398
114468
|
}
|
|
114399
114469
|
ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
|
|
114400
114470
|
/* @internal */
|
|
114401
|
-
function
|
|
114471
|
+
function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
|
|
114402
114472
|
if (names.length === 0) {
|
|
114403
114473
|
return [];
|
|
114404
114474
|
}
|
|
@@ -114407,19 +114477,28 @@ var ts;
|
|
|
114407
114477
|
for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
|
|
114408
114478
|
var name = names_2[_i];
|
|
114409
114479
|
var result = void 0;
|
|
114410
|
-
|
|
114411
|
-
|
|
114480
|
+
var mode = getModeForFileReference(name, containingFileMode);
|
|
114481
|
+
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
|
|
114482
|
+
var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
|
|
114483
|
+
var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
|
|
114484
|
+
if (cache.has(cacheKey)) {
|
|
114485
|
+
result = cache.get(cacheKey);
|
|
114412
114486
|
}
|
|
114413
114487
|
else {
|
|
114414
|
-
cache.set(
|
|
114488
|
+
cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
|
|
114415
114489
|
}
|
|
114416
114490
|
resolutions.push(result);
|
|
114417
114491
|
}
|
|
114418
114492
|
return resolutions;
|
|
114419
114493
|
}
|
|
114420
|
-
ts.
|
|
114494
|
+
ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
|
|
114421
114495
|
;
|
|
114422
114496
|
/* @internal */
|
|
114497
|
+
function getModeForFileReference(ref, containingFileMode) {
|
|
114498
|
+
return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
|
|
114499
|
+
}
|
|
114500
|
+
ts.getModeForFileReference = getModeForFileReference;
|
|
114501
|
+
/* @internal */
|
|
114423
114502
|
function getModeForResolutionAtIndex(file, index) {
|
|
114424
114503
|
if (file.impliedNodeFormat === undefined)
|
|
114425
114504
|
return undefined;
|
|
@@ -114522,7 +114601,7 @@ var ts;
|
|
|
114522
114601
|
var _d, _e, _f, _g;
|
|
114523
114602
|
var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
|
|
114524
114603
|
var kind = ref.kind, index = ref.index;
|
|
114525
|
-
var pos, end, packageId;
|
|
114604
|
+
var pos, end, packageId, resolutionMode;
|
|
114526
114605
|
switch (kind) {
|
|
114527
114606
|
case ts.FileIncludeKind.Import:
|
|
114528
114607
|
var importLiteral = getModuleNameStringLiteralAt(file, index);
|
|
@@ -114536,8 +114615,8 @@ var ts;
|
|
|
114536
114615
|
(_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
|
|
114537
114616
|
break;
|
|
114538
114617
|
case ts.FileIncludeKind.TypeReferenceDirective:
|
|
114539
|
-
(_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
|
|
114540
|
-
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;
|
|
114618
|
+
(_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
|
|
114619
|
+
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;
|
|
114541
114620
|
break;
|
|
114542
114621
|
case ts.FileIncludeKind.LibReferenceDirective:
|
|
114543
114622
|
(_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
|
|
@@ -114781,7 +114860,7 @@ var ts;
|
|
|
114781
114860
|
var fileReasons = ts.createMultiMap();
|
|
114782
114861
|
var cachedBindAndCheckDiagnosticsForFile = {};
|
|
114783
114862
|
var cachedDeclarationDiagnosticsForFile = {};
|
|
114784
|
-
var resolvedTypeReferenceDirectives =
|
|
114863
|
+
var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
|
|
114785
114864
|
var fileProcessingDiagnostics;
|
|
114786
114865
|
// The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
|
|
114787
114866
|
// This works as imported modules are discovered recursively in a depth first manner, specifically:
|
|
@@ -114834,12 +114913,12 @@ var ts;
|
|
|
114834
114913
|
}
|
|
114835
114914
|
var actualResolveTypeReferenceDirectiveNamesWorker;
|
|
114836
114915
|
if (host.resolveTypeReferenceDirectives) {
|
|
114837
|
-
actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
|
|
114916
|
+
actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
|
|
114838
114917
|
}
|
|
114839
114918
|
else {
|
|
114840
114919
|
typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
|
|
114841
|
-
var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
|
|
114842
|
-
actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return
|
|
114920
|
+
var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
|
|
114921
|
+
actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
|
|
114843
114922
|
}
|
|
114844
114923
|
// Map from a stringified PackageId to the source file with that id.
|
|
114845
114924
|
// Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
|
|
@@ -114936,7 +115015,8 @@ var ts;
|
|
|
114936
115015
|
var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
|
|
114937
115016
|
var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
|
|
114938
115017
|
for (var i = 0; i < typeReferences.length; i++) {
|
|
114939
|
-
|
|
115018
|
+
// under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
|
|
115019
|
+
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 });
|
|
114940
115020
|
}
|
|
114941
115021
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
114942
115022
|
}
|
|
@@ -115096,9 +115176,10 @@ var ts;
|
|
|
115096
115176
|
return [];
|
|
115097
115177
|
var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
|
|
115098
115178
|
var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
|
|
115179
|
+
var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
|
|
115099
115180
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
|
|
115100
115181
|
ts.performance.mark("beforeResolveTypeReference");
|
|
115101
|
-
var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
|
|
115182
|
+
var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
|
|
115102
115183
|
ts.performance.mark("afterResolveTypeReference");
|
|
115103
115184
|
ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
|
|
115104
115185
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
@@ -115490,8 +115571,7 @@ var ts;
|
|
|
115490
115571
|
else {
|
|
115491
115572
|
newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
|
|
115492
115573
|
}
|
|
115493
|
-
|
|
115494
|
-
var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
|
|
115574
|
+
var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
|
|
115495
115575
|
var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
|
|
115496
115576
|
// ensure that types resolutions are still correct
|
|
115497
115577
|
var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
|
|
@@ -116570,8 +116650,7 @@ var ts;
|
|
|
116570
116650
|
});
|
|
116571
116651
|
}
|
|
116572
116652
|
function processTypeReferenceDirectives(file) {
|
|
116573
|
-
|
|
116574
|
-
var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
|
|
116653
|
+
var typeDirectives = file.typeReferenceDirectives;
|
|
116575
116654
|
if (!typeDirectives) {
|
|
116576
116655
|
return;
|
|
116577
116656
|
}
|
|
@@ -116582,17 +116661,21 @@ var ts;
|
|
|
116582
116661
|
// store resolved type directive on the file
|
|
116583
116662
|
var fileName = ts.toFileNameLowerCase(ref.fileName);
|
|
116584
116663
|
ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
|
|
116585
|
-
|
|
116664
|
+
var mode = ref.resolutionMode || file.impliedNodeFormat;
|
|
116665
|
+
if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
|
|
116666
|
+
programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
|
|
116667
|
+
}
|
|
116668
|
+
processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
|
|
116586
116669
|
}
|
|
116587
116670
|
}
|
|
116588
|
-
function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
|
|
116671
|
+
function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
|
|
116589
116672
|
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 });
|
|
116590
|
-
processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
|
|
116673
|
+
processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
|
|
116591
116674
|
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
|
|
116592
116675
|
}
|
|
116593
|
-
function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
|
|
116676
|
+
function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
|
|
116594
116677
|
// If we already found this library as a primary reference - nothing to do
|
|
116595
|
-
var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
|
|
116678
|
+
var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
|
|
116596
116679
|
if (previousResolution && previousResolution.primary) {
|
|
116597
116680
|
return;
|
|
116598
116681
|
}
|
|
@@ -116631,7 +116714,7 @@ var ts;
|
|
|
116631
116714
|
addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
|
|
116632
116715
|
}
|
|
116633
116716
|
if (saveResolution) {
|
|
116634
|
-
resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
|
|
116717
|
+
resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
|
|
116635
116718
|
}
|
|
116636
116719
|
}
|
|
116637
116720
|
function pathForLibFile(libFileName) {
|
|
@@ -119449,9 +119532,9 @@ var ts;
|
|
|
119449
119532
|
});
|
|
119450
119533
|
hasChangedAutomaticTypeDirectiveNames = false;
|
|
119451
119534
|
}
|
|
119452
|
-
function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
|
|
119535
|
+
function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
|
|
119453
119536
|
var _a;
|
|
119454
|
-
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
|
|
119537
|
+
var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
|
|
119455
119538
|
// return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
|
|
119456
119539
|
if (!resolutionHost.getGlobalCache) {
|
|
119457
119540
|
return primaryResult;
|
|
@@ -119472,12 +119555,12 @@ var ts;
|
|
|
119472
119555
|
// Default return the result from the first pass
|
|
119473
119556
|
return primaryResult;
|
|
119474
119557
|
}
|
|
119475
|
-
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
|
|
119476
|
-
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
|
|
119558
|
+
function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
|
|
119559
|
+
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
|
|
119477
119560
|
}
|
|
119478
119561
|
function resolveNamesWithLocalCache(_a) {
|
|
119479
119562
|
var _b, _c, _d;
|
|
119480
|
-
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;
|
|
119563
|
+
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;
|
|
119481
119564
|
var path = resolutionHost.toPath(containingFile);
|
|
119482
119565
|
var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
|
|
119483
119566
|
var dirPath = ts.getDirectoryPath(path);
|
|
@@ -119499,8 +119582,15 @@ var ts;
|
|
|
119499
119582
|
var seenNamesInFile = ts.createModeAwareCache();
|
|
119500
119583
|
var i = 0;
|
|
119501
119584
|
for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
|
|
119502
|
-
var
|
|
119503
|
-
var
|
|
119585
|
+
var entry = names_4[_i];
|
|
119586
|
+
var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
|
|
119587
|
+
// Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
|
|
119588
|
+
// they require calculating the mode for a given import from it's position in the resolution table, since a given
|
|
119589
|
+
// import's syntax may override the file's default mode.
|
|
119590
|
+
// Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
|
|
119591
|
+
// a default file mode override if applicable.
|
|
119592
|
+
var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
|
|
119593
|
+
containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
|
|
119504
119594
|
i++;
|
|
119505
119595
|
var resolution = resolutionsInFile.get(name, mode);
|
|
119506
119596
|
// Resolution is valid if it is present and not invalidated
|
|
@@ -119529,7 +119619,7 @@ var ts;
|
|
|
119529
119619
|
}
|
|
119530
119620
|
}
|
|
119531
119621
|
else {
|
|
119532
|
-
resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
|
|
119622
|
+
resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
|
|
119533
119623
|
perDirectoryResolution.set(name, mode, resolution);
|
|
119534
119624
|
if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
|
|
119535
119625
|
resolutionHost.onDiscoveredSymlink();
|
|
@@ -119593,7 +119683,7 @@ var ts;
|
|
|
119593
119683
|
return oldResult.resolvedFileName === newResult.resolvedFileName;
|
|
119594
119684
|
}
|
|
119595
119685
|
}
|
|
119596
|
-
function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
|
|
119686
|
+
function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
|
|
119597
119687
|
return resolveNamesWithLocalCache({
|
|
119598
119688
|
names: typeDirectiveNames,
|
|
119599
119689
|
containingFile: containingFile,
|
|
@@ -119603,6 +119693,7 @@ var ts;
|
|
|
119603
119693
|
loader: resolveTypeReferenceDirective,
|
|
119604
119694
|
getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
|
|
119605
119695
|
shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
|
|
119696
|
+
containingSourceFileMode: containingFileMode
|
|
119606
119697
|
});
|
|
119607
119698
|
}
|
|
119608
119699
|
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
|
|
@@ -121511,7 +121602,7 @@ var ts;
|
|
|
121511
121602
|
}
|
|
121512
121603
|
return host.resolveTypeReferenceDirectives.apply(host, args);
|
|
121513
121604
|
}) :
|
|
121514
|
-
(function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
|
|
121605
|
+
(function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
|
|
121515
121606
|
var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
|
|
121516
121607
|
builderProgram = readBuilderProgram(compilerOptions, compilerHost);
|
|
121517
121608
|
synchronizeProgram();
|
|
@@ -122247,9 +122338,9 @@ var ts;
|
|
|
122247
122338
|
compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
|
|
122248
122339
|
}
|
|
122249
122340
|
if (!compilerHost.resolveTypeReferenceDirectives) {
|
|
122250
|
-
var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
|
|
122251
|
-
compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
|
|
122252
|
-
return ts.
|
|
122341
|
+
var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
|
|
122342
|
+
compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
|
|
122343
|
+
return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
|
|
122253
122344
|
};
|
|
122254
122345
|
}
|
|
122255
122346
|
var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;
|
|
@@ -127575,6 +127666,10 @@ var ts;
|
|
|
127575
127666
|
return __assign(__assign({}, options), { semicolons: shouldRemoveSemicolons ? ts.SemicolonPreference.Remove : ts.SemicolonPreference.Ignore });
|
|
127576
127667
|
}
|
|
127577
127668
|
ts.getFormatCodeSettingsForWriting = getFormatCodeSettingsForWriting;
|
|
127669
|
+
function jsxModeNeedsExplicitImport(jsx) {
|
|
127670
|
+
return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
|
|
127671
|
+
}
|
|
127672
|
+
ts.jsxModeNeedsExplicitImport = jsxModeNeedsExplicitImport;
|
|
127578
127673
|
// #endregion
|
|
127579
127674
|
})(ts || (ts = {}));
|
|
127580
127675
|
/*@internal*/
|
|
@@ -129519,9 +129614,18 @@ var ts;
|
|
|
129519
129614
|
return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, scriptPath);
|
|
129520
129615
|
}
|
|
129521
129616
|
}
|
|
129617
|
+
function isEmitResolutionKindUsingNodeModules(compilerOptions) {
|
|
129618
|
+
return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeJs ||
|
|
129619
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
|
|
129620
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
|
|
129621
|
+
}
|
|
129622
|
+
function isEmitModuleResolutionRespectingExportMaps(compilerOptions) {
|
|
129623
|
+
return ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node12 ||
|
|
129624
|
+
ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext;
|
|
129625
|
+
}
|
|
129522
129626
|
function getSupportedExtensionsForModuleResolution(compilerOptions) {
|
|
129523
129627
|
var extensions = ts.getSupportedExtensions(compilerOptions);
|
|
129524
|
-
return
|
|
129628
|
+
return isEmitResolutionKindUsingNodeModules(compilerOptions) ?
|
|
129525
129629
|
ts.getSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, extensions) :
|
|
129526
129630
|
extensions;
|
|
129527
129631
|
}
|
|
@@ -129684,7 +129788,7 @@ var ts;
|
|
|
129684
129788
|
result.push(nameAndKind(ambientName, "external module name" /* externalModuleName */, /*extension*/ undefined));
|
|
129685
129789
|
}
|
|
129686
129790
|
getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
|
|
129687
|
-
if (
|
|
129791
|
+
if (isEmitResolutionKindUsingNodeModules(compilerOptions)) {
|
|
129688
129792
|
// If looking for a global package name, don't just include everything in `node_modules` because that includes dependencies' own dependencies.
|
|
129689
129793
|
// (But do if we didn't find anything, e.g. 'package.json' missing.)
|
|
129690
129794
|
var foundGlobal = false;
|
|
@@ -129701,12 +129805,68 @@ var ts;
|
|
|
129701
129805
|
}
|
|
129702
129806
|
}
|
|
129703
129807
|
if (!foundGlobal) {
|
|
129704
|
-
|
|
129808
|
+
var ancestorLookup = function (ancestor) {
|
|
129705
129809
|
var nodeModules = ts.combinePaths(ancestor, "node_modules");
|
|
129706
129810
|
if (ts.tryDirectoryExists(host, nodeModules)) {
|
|
129707
129811
|
getCompletionEntriesForDirectoryFragment(fragment, nodeModules, extensionOptions, host, /*exclude*/ undefined, result);
|
|
129708
129812
|
}
|
|
129709
|
-
}
|
|
129813
|
+
};
|
|
129814
|
+
if (fragmentDirectory && isEmitModuleResolutionRespectingExportMaps(compilerOptions)) {
|
|
129815
|
+
var nodeModulesDirectoryLookup_1 = ancestorLookup;
|
|
129816
|
+
ancestorLookup = function (ancestor) {
|
|
129817
|
+
var components = ts.getPathComponents(fragment);
|
|
129818
|
+
components.shift(); // shift off empty root
|
|
129819
|
+
var packagePath = components.shift();
|
|
129820
|
+
if (!packagePath) {
|
|
129821
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129822
|
+
}
|
|
129823
|
+
if (ts.startsWith(packagePath, "@")) {
|
|
129824
|
+
var subName = components.shift();
|
|
129825
|
+
if (!subName) {
|
|
129826
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129827
|
+
}
|
|
129828
|
+
packagePath = ts.combinePaths(packagePath, subName);
|
|
129829
|
+
}
|
|
129830
|
+
var packageFile = ts.combinePaths(ancestor, "node_modules", packagePath, "package.json");
|
|
129831
|
+
if (ts.tryFileExists(host, packageFile)) {
|
|
129832
|
+
var packageJson = ts.readJson(packageFile, host);
|
|
129833
|
+
var exports = packageJson.exports;
|
|
129834
|
+
if (exports) {
|
|
129835
|
+
if (typeof exports !== "object" || exports === null) { // eslint-disable-line no-null/no-null
|
|
129836
|
+
return; // null exports or entrypoint only, no sub-modules available
|
|
129837
|
+
}
|
|
129838
|
+
var keys = ts.getOwnKeys(exports);
|
|
129839
|
+
var fragmentSubpath_1 = components.join("/");
|
|
129840
|
+
var processedKeys = ts.mapDefined(keys, function (k) {
|
|
129841
|
+
if (k === ".")
|
|
129842
|
+
return undefined;
|
|
129843
|
+
if (!ts.startsWith(k, "./"))
|
|
129844
|
+
return undefined;
|
|
129845
|
+
var subpath = k.substring(2);
|
|
129846
|
+
if (!ts.startsWith(subpath, fragmentSubpath_1))
|
|
129847
|
+
return undefined;
|
|
129848
|
+
// subpath is a valid export (barring conditions, which we don't currently check here)
|
|
129849
|
+
if (!ts.stringContains(subpath, "*")) {
|
|
129850
|
+
return subpath;
|
|
129851
|
+
}
|
|
129852
|
+
// pattern export - only return everything up to the `*`, so the user can autocomplete, then
|
|
129853
|
+
// keep filling in the pattern (we could speculatively return a list of options by hitting disk,
|
|
129854
|
+
// but conditions will make that somewhat awkward, as each condition may have a different set of possible
|
|
129855
|
+
// options for the `*`.
|
|
129856
|
+
return subpath.slice(0, subpath.indexOf("*"));
|
|
129857
|
+
});
|
|
129858
|
+
ts.forEach(processedKeys, function (k) {
|
|
129859
|
+
if (k) {
|
|
129860
|
+
result.push(nameAndKind(k, "external module name" /* externalModuleName */, /*extension*/ undefined));
|
|
129861
|
+
}
|
|
129862
|
+
});
|
|
129863
|
+
return;
|
|
129864
|
+
}
|
|
129865
|
+
}
|
|
129866
|
+
return nodeModulesDirectoryLookup_1(ancestor);
|
|
129867
|
+
};
|
|
129868
|
+
}
|
|
129869
|
+
ts.forEachAncestorDirectory(scriptPath, ancestorLookup);
|
|
129710
129870
|
}
|
|
129711
129871
|
}
|
|
129712
129872
|
return result;
|
|
@@ -134171,7 +134331,7 @@ var ts;
|
|
|
134171
134331
|
}
|
|
134172
134332
|
for (var _c = 0, _d = referencingFile.typeReferenceDirectives; _c < _d.length; _c++) {
|
|
134173
134333
|
var ref = _d[_c];
|
|
134174
|
-
var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName);
|
|
134334
|
+
var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName, ref.resolutionMode || referencingFile.impliedNodeFormat);
|
|
134175
134335
|
if (referenced !== undefined && referenced.resolvedFileName === searchSourceFile.fileName) {
|
|
134176
134336
|
refs.push({ kind: "reference", referencingFile: referencingFile, ref: ref });
|
|
134177
134337
|
}
|
|
@@ -137393,7 +137553,7 @@ var ts;
|
|
|
137393
137553
|
}
|
|
137394
137554
|
var typeReferenceDirective = findReferenceInPosition(sourceFile.typeReferenceDirectives, position);
|
|
137395
137555
|
if (typeReferenceDirective) {
|
|
137396
|
-
var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName);
|
|
137556
|
+
var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName, typeReferenceDirective.resolutionMode || sourceFile.impliedNodeFormat);
|
|
137397
137557
|
var file = reference && program.getSourceFile(reference.resolvedFileName); // TODO:GH#18217
|
|
137398
137558
|
return file && { reference: typeReferenceDirective, fileName: file.fileName, file: file, unverified: false };
|
|
137399
137559
|
}
|
|
@@ -139199,6 +139359,7 @@ var ts;
|
|
|
139199
139359
|
return oldImports;
|
|
139200
139360
|
}
|
|
139201
139361
|
var typeChecker = program.getTypeChecker();
|
|
139362
|
+
var compilerOptions = program.getCompilerOptions();
|
|
139202
139363
|
var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
|
|
139203
139364
|
var jsxFragmentFactory = typeChecker.getJsxFragmentFactory(sourceFile);
|
|
139204
139365
|
var jsxElementsPresent = !!(sourceFile.transformFlags & 2 /* ContainsJsx */);
|
|
@@ -139255,7 +139416,7 @@ var ts;
|
|
|
139255
139416
|
return usedImports;
|
|
139256
139417
|
function isDeclarationUsed(identifier) {
|
|
139257
139418
|
// The JSX factory symbol is always used if JSX elements are present - even if they are not allowed.
|
|
139258
|
-
return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) ||
|
|
139419
|
+
return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx) ||
|
|
139259
139420
|
ts.FindAllReferences.Core.isSymbolReferencedInFile(identifier, typeChecker, sourceFile);
|
|
139260
139421
|
}
|
|
139261
139422
|
}
|
|
@@ -150946,12 +151107,9 @@ var ts;
|
|
|
150946
151107
|
return undefined;
|
|
150947
151108
|
return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
|
|
150948
151109
|
}
|
|
150949
|
-
function jsxModeNeedsExplicitImport(jsx) {
|
|
150950
|
-
return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
|
|
150951
|
-
}
|
|
150952
151110
|
function getSymbolName(sourceFile, checker, symbolToken, compilerOptions) {
|
|
150953
151111
|
var parent = symbolToken.parent;
|
|
150954
|
-
if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
|
|
151112
|
+
if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && ts.jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
|
|
150955
151113
|
var jsxNamespace = checker.getJsxNamespace(sourceFile);
|
|
150956
151114
|
if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
|
|
150957
151115
|
return jsxNamespace;
|
|
@@ -164217,7 +164375,7 @@ var ts;
|
|
|
164217
164375
|
if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) {
|
|
164218
164376
|
this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
|
|
164219
164377
|
var typeDirectivesForFile = JSON.parse(_this.shimHost.getTypeReferenceDirectiveResolutionsForFile(containingFile)); // TODO: GH#18217
|
|
164220
|
-
return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, name); });
|
|
164378
|
+
return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, ts.isString(name) ? name : name.fileName.toLowerCase()); });
|
|
164221
164379
|
};
|
|
164222
164380
|
}
|
|
164223
164381
|
}
|