typescript 4.8.0-dev.20220802 → 4.8.0-dev.20220805

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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220802";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220805";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -8556,7 +8556,7 @@ var ts;
8556
8556
  File_is_CommonJS_module_because_0_does_not_have_field_type: diag(1460, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_0_does_not_have_field_type_1460", "File is CommonJS module because '{0}' does not have field \"type\""),
8557
8557
  File_is_CommonJS_module_because_package_json_was_not_found: diag(1461, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_package_json_was_not_found_1461", "File is CommonJS module because 'package.json' was not found"),
8558
8558
  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."),
8559
- 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."),
8559
+ Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_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 with 'require'. Use an ECMAScript import instead."),
8560
8560
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8561
8561
  An_import_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1473, ts.DiagnosticCategory.Error, "An_import_declaration_can_only_be_used_at_the_top_level_of_a_module_1473", "An import declaration can only be used at the top level of a module."),
8562
8562
  An_export_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1474, ts.DiagnosticCategory.Error, "An_export_declaration_can_only_be_used_at_the_top_level_of_a_module_1474", "An export declaration can only be used at the top level of a module."),
@@ -8564,6 +8564,11 @@ var ts;
8564
8564
  auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
8565
8565
  An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
8566
8566
  Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
8567
+ The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead: diag(1479, ts.DiagnosticCategory.Error, "The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_reference_1479", "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"{0}\")' call instead."),
8568
+ To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module: diag(1480, ts.DiagnosticCategory.Message, "To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_packag_1480", "To convert this file to an ECMAScript module, change its file extension to '{0}' or create a local package.json file with `{ \"type\": \"module\" }`."),
8569
+ To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1: diag(1481, ts.DiagnosticCategory.Message, "To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Co_1481", "To convert this file to an ECMAScript module, change its file extension to '{0}', or add the field `\"type\": \"module\"` to '{1}'."),
8570
+ To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0: diag(1482, ts.DiagnosticCategory.Message, "To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0_1482", "To convert this file to an ECMAScript module, add the field `\"type\": \"module\"` to '{0}'."),
8571
+ To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module: diag(1483, ts.DiagnosticCategory.Message, "To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module_1483", "To convert this file to an ECMAScript module, create a local package.json file with `{ \"type\": \"module\" }`."),
8567
8572
  The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
8568
8573
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
8569
8574
  Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
@@ -21858,7 +21863,7 @@ var ts;
21858
21863
  * Wraps an expression in parentheses if it is needed in order to use the expression for
21859
21864
  * property or element access.
21860
21865
  */
21861
- function parenthesizeLeftSideOfAccess(expression) {
21866
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
21862
21867
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
21863
21868
  // to parenthesize the expression before a dot. The known exception is:
21864
21869
  //
@@ -21867,7 +21872,8 @@ var ts;
21867
21872
  //
21868
21873
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
21869
21874
  if (ts.isLeftHandSideExpression(emittedExpression)
21870
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
21875
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
21876
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
21871
21877
  // TODO(rbuckton): Verify whether this assertion holds.
21872
21878
  return expression;
21873
21879
  }
@@ -23274,7 +23280,7 @@ var ts;
23274
23280
  // @api
23275
23281
  function createDecorator(expression) {
23276
23282
  var node = createBaseNode(165 /* Decorator */);
23277
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23283
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23278
23284
  node.transformFlags |=
23279
23285
  propagateChildFlags(node.expression) |
23280
23286
  1 /* ContainsTypeScript */ |
@@ -24075,7 +24081,7 @@ var ts;
24075
24081
  // @api
24076
24082
  function createPropertyAccessExpression(expression, name) {
24077
24083
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24078
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24084
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24079
24085
  node.name = asName(name);
24080
24086
  node.transformFlags =
24081
24087
  propagateChildFlags(node.expression) |
@@ -24105,7 +24111,7 @@ var ts;
24105
24111
  function createPropertyAccessChain(expression, questionDotToken, name) {
24106
24112
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24107
24113
  node.flags |= 32 /* OptionalChain */;
24108
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24114
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24109
24115
  node.questionDotToken = questionDotToken;
24110
24116
  node.name = asName(name);
24111
24117
  node.transformFlags |=
@@ -24131,7 +24137,7 @@ var ts;
24131
24137
  // @api
24132
24138
  function createElementAccessExpression(expression, index) {
24133
24139
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24134
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24140
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24135
24141
  node.argumentExpression = asExpression(index);
24136
24142
  node.transformFlags |=
24137
24143
  propagateChildFlags(node.expression) |
@@ -24159,7 +24165,7 @@ var ts;
24159
24165
  function createElementAccessChain(expression, questionDotToken, index) {
24160
24166
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24161
24167
  node.flags |= 32 /* OptionalChain */;
24162
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24168
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24163
24169
  node.questionDotToken = questionDotToken;
24164
24170
  node.argumentExpression = asExpression(index);
24165
24171
  node.transformFlags |=
@@ -24183,7 +24189,7 @@ var ts;
24183
24189
  // @api
24184
24190
  function createCallExpression(expression, typeArguments, argumentsArray) {
24185
24191
  var node = createBaseExpression(208 /* CallExpression */);
24186
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24192
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24187
24193
  node.typeArguments = asNodeArray(typeArguments);
24188
24194
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24189
24195
  node.transformFlags |=
@@ -24216,7 +24222,7 @@ var ts;
24216
24222
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24217
24223
  var node = createBaseExpression(208 /* CallExpression */);
24218
24224
  node.flags |= 32 /* OptionalChain */;
24219
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24225
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24220
24226
  node.questionDotToken = questionDotToken;
24221
24227
  node.typeArguments = asNodeArray(typeArguments);
24222
24228
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24271,7 +24277,7 @@ var ts;
24271
24277
  // @api
24272
24278
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24273
24279
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24274
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24280
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24275
24281
  node.typeArguments = asNodeArray(typeArguments);
24276
24282
  node.template = template;
24277
24283
  node.transformFlags |=
@@ -24709,7 +24715,7 @@ var ts;
24709
24715
  // @api
24710
24716
  function createExpressionWithTypeArguments(expression, typeArguments) {
24711
24717
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24712
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24718
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24713
24719
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24714
24720
  node.transformFlags |=
24715
24721
  propagateChildFlags(node.expression) |
@@ -24745,7 +24751,7 @@ var ts;
24745
24751
  // @api
24746
24752
  function createNonNullExpression(expression) {
24747
24753
  var node = createBaseExpression(230 /* NonNullExpression */);
24748
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24754
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24749
24755
  node.transformFlags |=
24750
24756
  propagateChildFlags(node.expression) |
24751
24757
  1 /* ContainsTypeScript */;
@@ -24764,7 +24770,7 @@ var ts;
24764
24770
  function createNonNullChain(expression) {
24765
24771
  var node = createBaseExpression(230 /* NonNullExpression */);
24766
24772
  node.flags |= 32 /* OptionalChain */;
24767
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24773
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24768
24774
  node.transformFlags |=
24769
24775
  propagateChildFlags(node.expression) |
24770
24776
  1 /* ContainsTypeScript */;
@@ -26968,7 +26974,7 @@ var ts;
26968
26974
  }
26969
26975
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
26970
26976
  thisArg = createVoidZero();
26971
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
26977
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
26972
26978
  }
26973
26979
  else if (ts.isPropertyAccessExpression(callee)) {
26974
26980
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -26997,7 +27003,7 @@ var ts;
26997
27003
  else {
26998
27004
  // for `a()` target is `a` and thisArg is `void 0`
26999
27005
  thisArg = createVoidZero();
27000
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27006
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27001
27007
  }
27002
27008
  return { target: target, thisArg: thisArg };
27003
27009
  }
@@ -51672,7 +51678,40 @@ var ts;
51672
51678
  // An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
51673
51679
  // normal mode restrictions
51674
51680
  if (isSyncImport && sourceFile.impliedNodeFormat === ts.ModuleKind.ESNext && !ts.getResolutionModeOverrideForClause(overrideClause)) {
51675
- error(errorNode, ts.Diagnostics.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, moduleReference);
51681
+ if (ts.findAncestor(location, ts.isImportEqualsDeclaration)) {
51682
+ // ImportEquals in a ESM file resolving to another ESM file
51683
+ error(errorNode, ts.Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead, moduleReference);
51684
+ }
51685
+ else {
51686
+ // CJS file resolving to an ESM file
51687
+ var diagnosticDetails = void 0;
51688
+ var ext = ts.tryGetExtensionFromPath(currentSourceFile.fileName);
51689
+ if (ext === ".ts" /* Ts */ || ext === ".js" /* Js */ || ext === ".tsx" /* Tsx */ || ext === ".jsx" /* Jsx */) {
51690
+ var scope = currentSourceFile.packageJsonScope;
51691
+ var targetExt = ext === ".ts" /* Ts */ ? ".mts" /* Mts */ : ext === ".js" /* Js */ ? ".mjs" /* Mjs */ : undefined;
51692
+ if (scope && !scope.packageJsonContent.type) {
51693
+ if (targetExt) {
51694
+ diagnosticDetails = ts.chainDiagnosticMessages(
51695
+ /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json"));
51696
+ }
51697
+ else {
51698
+ diagnosticDetails = ts.chainDiagnosticMessages(
51699
+ /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0, ts.combinePaths(scope.packageDirectory, "package.json"));
51700
+ }
51701
+ }
51702
+ else {
51703
+ if (targetExt) {
51704
+ diagnosticDetails = ts.chainDiagnosticMessages(
51705
+ /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module, targetExt);
51706
+ }
51707
+ else {
51708
+ diagnosticDetails = ts.chainDiagnosticMessages(
51709
+ /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module);
51710
+ }
51711
+ }
51712
+ }
51713
+ diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, ts.chainDiagnosticMessages(diagnosticDetails, ts.Diagnostics.The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead, moduleReference)));
51714
+ }
51676
51715
  }
51677
51716
  }
51678
51717
  // merged symbol is module declaration symbol combined with all augmentations
@@ -66178,6 +66217,26 @@ var ts;
66178
66217
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66179
66218
  var saveErrorInfo = captureErrorCalculationState();
66180
66219
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66220
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66221
+ // The combined constraint of an intersection type is the intersection of the constraints of
66222
+ // the constituents. When an intersection type contains instantiable types with union type
66223
+ // constraints, there are situations where we need to examine the combined constraint. One is
66224
+ // when the target is a union type. Another is when the intersection contains types belonging
66225
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66226
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66227
+ // we need to check this constraint against a union on the target side. Also, given a type
66228
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66229
+ // 'string & number | number & number' which reduces to just 'number'.
66230
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66231
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66232
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66233
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66234
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66235
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66236
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66237
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66238
+ }
66239
+ }
66181
66240
  if (result) {
66182
66241
  resetErrorInfo(saveErrorInfo);
66183
66242
  }
@@ -66235,28 +66294,6 @@ var ts;
66235
66294
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66236
66295
  return result;
66237
66296
  }
66238
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66239
- // The combined constraint of an intersection type is the intersection of the constraints of
66240
- // the constituents. When an intersection type contains instantiable types with union type
66241
- // constraints, there are situations where we need to examine the combined constraint. One is
66242
- // when the target is a union type. Another is when the intersection contains types belonging
66243
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66244
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66245
- // we need to check this constraint against a union on the target side. Also, given a type
66246
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66247
- // 'string & number | number & number' which reduces to just 'number'.
66248
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66249
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66250
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66251
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66252
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66253
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66254
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66255
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66256
- return result;
66257
- }
66258
- }
66259
- }
66260
66297
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66261
66298
  // Source is instantiable (e.g. source has union or intersection constraint).
66262
66299
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -83991,17 +84028,28 @@ var ts;
83991
84028
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
83992
84029
  */
83993
84030
  function getIterationTypesOfIterable(type, use, errorNode) {
84031
+ var _a, _b;
83994
84032
  if (isTypeAny(type)) {
83995
84033
  return anyIterationTypes;
83996
84034
  }
83997
84035
  if (!(type.flags & 1048576 /* Union */)) {
83998
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84036
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84037
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
83999
84038
  if (iterationTypes_1 === noIterationTypes) {
84000
84039
  if (errorNode) {
84001
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84040
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84041
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84042
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84043
+ }
84002
84044
  }
84003
84045
  return undefined;
84004
84046
  }
84047
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84048
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84049
+ var diag = _c[_i];
84050
+ diagnostics.add(diag);
84051
+ }
84052
+ }
84005
84053
  return iterationTypes_1;
84006
84054
  }
84007
84055
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84009,19 +84057,27 @@ var ts;
84009
84057
  if (cachedTypes)
84010
84058
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84011
84059
  var allIterationTypes;
84012
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84013
- var constituent = _a[_i];
84014
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84060
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84061
+ var constituent = _e[_d];
84062
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84063
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84015
84064
  if (iterationTypes_2 === noIterationTypes) {
84016
84065
  if (errorNode) {
84017
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84066
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84067
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84068
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84069
+ }
84018
84070
  }
84019
84071
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84020
84072
  return undefined;
84021
84073
  }
84022
- else {
84023
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84074
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84075
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84076
+ var diag = _g[_f];
84077
+ diagnostics.add(diag);
84078
+ }
84024
84079
  }
84080
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84025
84081
  }
84026
84082
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84027
84083
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84049,47 +84105,62 @@ var ts;
84049
84105
  * NOTE: You probably don't want to call this directly and should be calling
84050
84106
  * `getIterationTypesOfIterable` instead.
84051
84107
  */
84052
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84108
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84053
84109
  if (isTypeAny(type)) {
84054
84110
  return anyIterationTypes;
84055
84111
  }
84112
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84113
+ // In addition, we should not cache any new results for this call.
84114
+ var noCache = false;
84056
84115
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84057
84116
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84058
84117
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84059
84118
  if (iterationTypes) {
84060
- return use & 8 /* ForOfFlag */ ?
84061
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84062
- iterationTypes;
84119
+ if (iterationTypes === noIterationTypes && errorNode) {
84120
+ // ignore the cached value
84121
+ noCache = true;
84122
+ }
84123
+ else {
84124
+ return use & 8 /* ForOfFlag */ ?
84125
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84126
+ iterationTypes;
84127
+ }
84063
84128
  }
84064
84129
  }
84065
84130
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84066
84131
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84067
84132
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84068
84133
  if (iterationTypes) {
84069
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84070
- // for a sync iterable in an async context, only use the cached types if they are valid.
84071
- if (iterationTypes !== noIterationTypes) {
84072
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84073
- }
84134
+ if (iterationTypes === noIterationTypes && errorNode) {
84135
+ // ignore the cached value
84136
+ noCache = true;
84074
84137
  }
84075
84138
  else {
84076
- return iterationTypes;
84139
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84140
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84141
+ if (iterationTypes !== noIterationTypes) {
84142
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84143
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84144
+ }
84145
+ }
84146
+ else {
84147
+ return iterationTypes;
84148
+ }
84077
84149
  }
84078
84150
  }
84079
84151
  }
84080
84152
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84081
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84153
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84082
84154
  if (iterationTypes !== noIterationTypes) {
84083
84155
  return iterationTypes;
84084
84156
  }
84085
84157
  }
84086
84158
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84087
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84159
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84088
84160
  if (iterationTypes !== noIterationTypes) {
84089
84161
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84090
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84091
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84092
- : noIterationTypes);
84162
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84163
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84093
84164
  }
84094
84165
  else {
84095
84166
  return iterationTypes;
@@ -84110,7 +84181,7 @@ var ts;
84110
84181
  }
84111
84182
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84112
84183
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84113
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84184
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84114
84185
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84115
84186
  }
84116
84187
  /**
@@ -84164,26 +84235,26 @@ var ts;
84164
84235
  * NOTE: You probably don't want to call this directly and should be calling
84165
84236
  * `getIterationTypesOfIterable` instead.
84166
84237
  */
84167
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84238
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84168
84239
  var _a;
84169
84240
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84170
84241
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84171
84242
  if (isTypeAny(methodType)) {
84172
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84243
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84173
84244
  }
84174
84245
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84175
84246
  if (!ts.some(signatures)) {
84176
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84247
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84177
84248
  }
84178
84249
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84179
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84180
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84250
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84251
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84181
84252
  }
84182
84253
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84183
84254
  var message = allowAsyncIterables
84184
84255
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84185
84256
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84186
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84257
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84187
84258
  }
84188
84259
  /**
84189
84260
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -84191,13 +84262,29 @@ var ts;
84191
84262
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84192
84263
  * record is returned. Otherwise, `undefined` is returned.
84193
84264
  */
84194
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84265
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84266
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84267
+ }
84268
+ /**
84269
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84270
+ *
84271
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84272
+ * record is returned. Otherwise, `undefined` is returned.
84273
+ *
84274
+ * NOTE: You probably don't want to call this directly and should be calling
84275
+ * `getIterationTypesOfIterator` instead.
84276
+ */
84277
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84195
84278
  if (isTypeAny(type)) {
84196
84279
  return anyIterationTypes;
84197
84280
  }
84198
84281
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84199
- getIterationTypesOfIteratorFast(type, resolver) ||
84200
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84282
+ getIterationTypesOfIteratorFast(type, resolver);
84283
+ if (iterationTypes === noIterationTypes && errorNode) {
84284
+ iterationTypes = undefined;
84285
+ noCache = true;
84286
+ }
84287
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84201
84288
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84202
84289
  }
84203
84290
  /**
@@ -84235,7 +84322,7 @@ var ts;
84235
84322
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84236
84323
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84237
84324
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84238
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84325
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84239
84326
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84240
84327
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84241
84328
  }
@@ -84305,8 +84392,8 @@ var ts;
84305
84392
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84306
84393
  * record is returned. Otherwise, we return `undefined`.
84307
84394
  */
84308
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84309
- var _a, _b, _c, _d;
84395
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84396
+ var _a, _b, _c, _d, _e, _f;
84310
84397
  var method = getPropertyOfType(type, methodName);
84311
84398
  // Ignore 'return' or 'throw' if they are missing.
84312
84399
  if (!method && methodName !== "next") {
@@ -84326,9 +84413,15 @@ var ts;
84326
84413
  var diagnostic = methodName === "next"
84327
84414
  ? resolver.mustHaveANextMethodDiagnostic
84328
84415
  : resolver.mustBeAMethodDiagnostic;
84329
- error(errorNode, diagnostic, methodName);
84416
+ if (errorOutputContainer) {
84417
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84418
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84419
+ }
84420
+ else {
84421
+ error(errorNode, diagnostic, methodName);
84422
+ }
84330
84423
  }
84331
- return methodName === "next" ? anyIterationTypes : undefined;
84424
+ return methodName === "next" ? noIterationTypes : undefined;
84332
84425
  }
84333
84426
  // If the method signature comes exclusively from the global iterator or generator type,
84334
84427
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84340,8 +84433,8 @@ var ts;
84340
84433
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84341
84434
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84342
84435
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84343
- var isGeneratorMethod = ((_b = (_a = globalGeneratorType.symbol) === null || _a === void 0 ? void 0 : _a.members) === null || _b === void 0 ? void 0 : _b.get(methodName)) === methodType.symbol;
84344
- var isIteratorMethod = !isGeneratorMethod && ((_d = (_c = globalIteratorType.symbol) === null || _c === void 0 ? void 0 : _c.members) === null || _d === void 0 ? void 0 : _d.get(methodName)) === methodType.symbol;
84436
+ var isGeneratorMethod = ((_c = (_b = globalGeneratorType.symbol) === null || _b === void 0 ? void 0 : _b.members) === null || _c === void 0 ? void 0 : _c.get(methodName)) === methodType.symbol;
84437
+ var isIteratorMethod = !isGeneratorMethod && ((_e = (_d = globalIteratorType.symbol) === null || _d === void 0 ? void 0 : _d.members) === null || _e === void 0 ? void 0 : _e.get(methodName)) === methodType.symbol;
84345
84438
  if (isGeneratorMethod || isIteratorMethod) {
84346
84439
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84347
84440
  var mapper = methodType.mapper;
@@ -84381,7 +84474,13 @@ var ts;
84381
84474
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84382
84475
  if (iterationTypes === noIterationTypes) {
84383
84476
  if (errorNode) {
84384
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84477
+ if (errorOutputContainer) {
84478
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84479
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84480
+ }
84481
+ else {
84482
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84483
+ }
84385
84484
  }
84386
84485
  yieldType = anyType;
84387
84486
  returnTypes = ts.append(returnTypes, anyType);
@@ -84402,13 +84501,13 @@ var ts;
84402
84501
  * NOTE: You probably don't want to call this directly and should be calling
84403
84502
  * `getIterationTypesOfIterator` instead.
84404
84503
  */
84405
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84504
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84406
84505
  var iterationTypes = combineIterationTypes([
84407
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84408
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84409
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84506
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84507
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84508
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84410
84509
  ]);
84411
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84510
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84412
84511
  }
84413
84512
  /**
84414
84513
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84429,7 +84528,7 @@ var ts;
84429
84528
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84430
84529
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84431
84530
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84432
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84531
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84433
84532
  }
84434
84533
  function checkBreakOrContinueStatement(node) {
84435
84534
  // Grammar checking
@@ -122726,8 +122825,6 @@ var ts;
122726
122825
  if (watcher.files === 0 && watcher.resolutions === 0) {
122727
122826
  fileWatchesOfAffectingLocations.delete(path);
122728
122827
  watcher.watcher.close();
122729
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122730
- watcher.watcher = ts.noopFileWatcher;
122731
122828
  }
122732
122829
  });
122733
122830
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123073,20 +123170,27 @@ var ts;
123073
123170
  }
123074
123171
  var paths = new ts.Set();
123075
123172
  paths.add(locationToWatch);
123173
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123174
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123175
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123176
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123177
+ paths.forEach(function (path) {
123178
+ if (watcher.resolutions)
123179
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123180
+ if (watcher.files)
123181
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123182
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123183
+ });
123184
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123185
+ }) : ts.noopFileWatcher;
123076
123186
  var watcher = {
123077
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123078
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123079
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123080
- paths.forEach(function (path) {
123081
- var _a;
123082
- if (watcher.resolutions)
123083
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123084
- if (watcher.files)
123085
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123086
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123087
- });
123088
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123089
- }) : ts.noopFileWatcher,
123187
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123188
+ close: function () {
123189
+ actualWatcher.close();
123190
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123191
+ actualWatcher = ts.noopFileWatcher;
123192
+ }
123193
+ } : actualWatcher,
123090
123194
  resolutions: forResolution ? 1 : 0,
123091
123195
  files: forResolution ? 0 : 1,
123092
123196
  paths: paths,
@@ -123500,7 +123604,7 @@ var ts;
123500
123604
  var info = getInfo(importingSourceFileName, host);
123501
123605
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123502
123606
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123503
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123607
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123504
123608
  }
123505
123609
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123506
123610
  if (options === void 0) { options = {}; }
@@ -123583,7 +123687,7 @@ var ts;
123583
123687
  return nodeModulesSpecifiers;
123584
123688
  }
123585
123689
  if (!specifier && !modulePath.isRedirect) {
123586
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123690
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123587
123691
  if (ts.pathIsBareSpecifier(local)) {
123588
123692
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123589
123693
  }
@@ -123611,7 +123715,7 @@ var ts;
123611
123715
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123612
123716
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123613
123717
  }
123614
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123718
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123615
123719
  var ending = _a.ending, relativePreference = _a.relativePreference;
123616
123720
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123617
123721
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123625,9 +123729,8 @@ var ts;
123625
123729
  if (!relativeToBaseUrl) {
123626
123730
  return relativePath;
123627
123731
  }
123628
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123629
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123630
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123732
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123733
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123631
123734
  if (!nonRelative) {
123632
123735
  return relativePath;
123633
123736
  }
@@ -123862,28 +123965,102 @@ var ts;
123862
123965
  return ambientModuleDeclare.name.text;
123863
123966
  }
123864
123967
  }
123865
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
123968
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
123969
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
123970
+ return [2 /* JsExtension */];
123971
+ }
123972
+ switch (preferredEnding) {
123973
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
123974
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
123975
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
123976
+ default: ts.Debug.assertNever(preferredEnding);
123977
+ }
123978
+ }
123979
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
123866
123980
  for (var key in paths) {
123867
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
123868
- var patternText_1 = _a[_i];
123869
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
123981
+ var _loop_36 = function (patternText_1) {
123982
+ var pattern = ts.normalizePath(patternText_1);
123870
123983
  var indexOfStar = pattern.indexOf("*");
123984
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
123985
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
123986
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
123987
+ // and matches the '*'. For example:
123988
+ //
123989
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
123990
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
123991
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
123992
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
123993
+ //
123994
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
123995
+ //
123996
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
123997
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
123998
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
123999
+ // extension for a module specifier.)
124000
+ //
124001
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
124002
+ // .ts extension) or the possible relative module specifiers representing that file:
124003
+ //
124004
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
124005
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
124006
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
124007
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
124008
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
124009
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*"] <- (none) || @app/foo, @app/foo/index, @app/foo/index.js
124010
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
124011
+ //
124012
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
124013
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
124014
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
124015
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
124016
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
124017
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
124018
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
124019
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
124020
+ var candidates = allowedEndings.map(function (ending) { return ({
124021
+ ending: ending,
124022
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
124023
+ }); });
124024
+ if (ts.tryGetExtensionFromPath(pattern)) {
124025
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
124026
+ }
123871
124027
  if (indexOfStar !== -1) {
123872
- var prefix = pattern.substr(0, indexOfStar);
123873
- var suffix = pattern.substr(indexOfStar + 1);
123874
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
123875
- ts.startsWith(relativeToBaseUrl, prefix) &&
123876
- ts.endsWith(relativeToBaseUrl, suffix) ||
123877
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
123878
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
123879
- return key.replace("*", matchedStar);
124028
+ var prefix = pattern.substring(0, indexOfStar);
124029
+ var suffix = pattern.substring(indexOfStar + 1);
124030
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
124031
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
124032
+ if (value.length >= prefix.length + suffix.length &&
124033
+ ts.startsWith(value, prefix) &&
124034
+ ts.endsWith(value, suffix) &&
124035
+ validateEnding({ ending: ending, value: value })) {
124036
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
124037
+ return { value: key.replace("*", matchedStar) };
124038
+ }
123880
124039
  }
123881
124040
  }
123882
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
123883
- return key;
124041
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124042
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124043
+ return { value: key };
123884
124044
  }
124045
+ };
124046
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124047
+ var patternText_1 = _a[_i];
124048
+ var state_12 = _loop_36(patternText_1);
124049
+ if (typeof state_12 === "object")
124050
+ return state_12.value;
123885
124051
  }
123886
124052
  }
124053
+ function validateEnding(_a) {
124054
+ var ending = _a.ending, value = _a.value;
124055
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124056
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124057
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124058
+ // do we check that the host-validated result is consistent with the answer we got before. If it's not, it falls back to the
124059
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124060
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124061
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124062
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124063
+ }
123887
124064
  }
123888
124065
  var MatchingMode;
123889
124066
  (function (MatchingMode) {
@@ -123979,10 +124156,10 @@ var ts;
123979
124156
  return undefined;
123980
124157
  }
123981
124158
  // Simplify the full file path to something that can be resolved by Node.
124159
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
123982
124160
  var moduleSpecifier = path;
123983
124161
  var isPackageRootPath = false;
123984
124162
  if (!packageNameOnly) {
123985
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
123986
124163
  var packageRootIndex = parts.packageRootIndex;
123987
124164
  var moduleFileName = void 0;
123988
124165
  while (true) {
@@ -124031,15 +124208,13 @@ var ts;
124031
124208
  var packageRootPath = path.substring(0, packageRootIndex);
124032
124209
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124033
124210
  var moduleFileToTry = path;
124211
+ var maybeBlockedByTypesVersions = false;
124034
124212
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124035
124213
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124036
124214
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124215
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124037
124216
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124038
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124039
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124040
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124041
- // with, so for now we just stick with the mode of the file.
124042
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124217
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124043
124218
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124044
124219
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124045
124220
  : undefined;
@@ -124058,16 +124233,26 @@ var ts;
124058
124233
  : undefined;
124059
124234
  if (versionPaths) {
124060
124235
  var subModuleName = path.slice(packageRootPath.length + 1);
124061
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124062
- if (fromPaths !== undefined) {
124236
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124237
+ if (fromPaths === undefined) {
124238
+ maybeBlockedByTypesVersions = true;
124239
+ }
124240
+ else {
124063
124241
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124064
124242
  }
124065
124243
  }
124066
124244
  // If the file is the main module, it can be imported by the package name
124067
124245
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124068
- if (ts.isString(mainFileRelative)) {
124246
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124247
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124248
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124249
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124250
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124251
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124252
+ // importNameCodeFix_typesVersions.ts for an example.)
124069
124253
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124070
124254
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124255
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124071
124256
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124072
124257
  }
124073
124258
  }