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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220802";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220805";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -8770,7 +8770,7 @@ var ts;
8770
8770
  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\""),
8771
8771
  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"),
8772
8772
  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."),
8773
- 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."),
8773
+ 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."),
8774
8774
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8775
8775
  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."),
8776
8776
  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."),
@@ -8778,6 +8778,11 @@ var ts;
8778
8778
  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."),
8779
8779
  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."),
8780
8780
  Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
8781
+ 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."),
8782
+ 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\" }`."),
8783
+ 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}'."),
8784
+ 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}'."),
8785
+ 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\" }`."),
8781
8786
  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."),
8782
8787
  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."),
8783
8788
  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),
@@ -22072,7 +22077,7 @@ var ts;
22072
22077
  * Wraps an expression in parentheses if it is needed in order to use the expression for
22073
22078
  * property or element access.
22074
22079
  */
22075
- function parenthesizeLeftSideOfAccess(expression) {
22080
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
22076
22081
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
22077
22082
  // to parenthesize the expression before a dot. The known exception is:
22078
22083
  //
@@ -22081,7 +22086,8 @@ var ts;
22081
22086
  //
22082
22087
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
22083
22088
  if (ts.isLeftHandSideExpression(emittedExpression)
22084
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
22089
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
22090
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
22085
22091
  // TODO(rbuckton): Verify whether this assertion holds.
22086
22092
  return expression;
22087
22093
  }
@@ -23488,7 +23494,7 @@ var ts;
23488
23494
  // @api
23489
23495
  function createDecorator(expression) {
23490
23496
  var node = createBaseNode(165 /* Decorator */);
23491
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23497
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23492
23498
  node.transformFlags |=
23493
23499
  propagateChildFlags(node.expression) |
23494
23500
  1 /* ContainsTypeScript */ |
@@ -24289,7 +24295,7 @@ var ts;
24289
24295
  // @api
24290
24296
  function createPropertyAccessExpression(expression, name) {
24291
24297
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24292
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24298
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24293
24299
  node.name = asName(name);
24294
24300
  node.transformFlags =
24295
24301
  propagateChildFlags(node.expression) |
@@ -24319,7 +24325,7 @@ var ts;
24319
24325
  function createPropertyAccessChain(expression, questionDotToken, name) {
24320
24326
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24321
24327
  node.flags |= 32 /* OptionalChain */;
24322
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24328
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24323
24329
  node.questionDotToken = questionDotToken;
24324
24330
  node.name = asName(name);
24325
24331
  node.transformFlags |=
@@ -24345,7 +24351,7 @@ var ts;
24345
24351
  // @api
24346
24352
  function createElementAccessExpression(expression, index) {
24347
24353
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24348
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24354
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24349
24355
  node.argumentExpression = asExpression(index);
24350
24356
  node.transformFlags |=
24351
24357
  propagateChildFlags(node.expression) |
@@ -24373,7 +24379,7 @@ var ts;
24373
24379
  function createElementAccessChain(expression, questionDotToken, index) {
24374
24380
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24375
24381
  node.flags |= 32 /* OptionalChain */;
24376
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24382
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24377
24383
  node.questionDotToken = questionDotToken;
24378
24384
  node.argumentExpression = asExpression(index);
24379
24385
  node.transformFlags |=
@@ -24397,7 +24403,7 @@ var ts;
24397
24403
  // @api
24398
24404
  function createCallExpression(expression, typeArguments, argumentsArray) {
24399
24405
  var node = createBaseExpression(208 /* CallExpression */);
24400
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24406
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24401
24407
  node.typeArguments = asNodeArray(typeArguments);
24402
24408
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24403
24409
  node.transformFlags |=
@@ -24430,7 +24436,7 @@ var ts;
24430
24436
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24431
24437
  var node = createBaseExpression(208 /* CallExpression */);
24432
24438
  node.flags |= 32 /* OptionalChain */;
24433
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24439
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24434
24440
  node.questionDotToken = questionDotToken;
24435
24441
  node.typeArguments = asNodeArray(typeArguments);
24436
24442
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24485,7 +24491,7 @@ var ts;
24485
24491
  // @api
24486
24492
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24487
24493
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24488
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24494
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24489
24495
  node.typeArguments = asNodeArray(typeArguments);
24490
24496
  node.template = template;
24491
24497
  node.transformFlags |=
@@ -24923,7 +24929,7 @@ var ts;
24923
24929
  // @api
24924
24930
  function createExpressionWithTypeArguments(expression, typeArguments) {
24925
24931
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24926
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24932
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24927
24933
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24928
24934
  node.transformFlags |=
24929
24935
  propagateChildFlags(node.expression) |
@@ -24959,7 +24965,7 @@ var ts;
24959
24965
  // @api
24960
24966
  function createNonNullExpression(expression) {
24961
24967
  var node = createBaseExpression(230 /* NonNullExpression */);
24962
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24968
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24963
24969
  node.transformFlags |=
24964
24970
  propagateChildFlags(node.expression) |
24965
24971
  1 /* ContainsTypeScript */;
@@ -24978,7 +24984,7 @@ var ts;
24978
24984
  function createNonNullChain(expression) {
24979
24985
  var node = createBaseExpression(230 /* NonNullExpression */);
24980
24986
  node.flags |= 32 /* OptionalChain */;
24981
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24987
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24982
24988
  node.transformFlags |=
24983
24989
  propagateChildFlags(node.expression) |
24984
24990
  1 /* ContainsTypeScript */;
@@ -27182,7 +27188,7 @@ var ts;
27182
27188
  }
27183
27189
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
27184
27190
  thisArg = createVoidZero();
27185
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
27191
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
27186
27192
  }
27187
27193
  else if (ts.isPropertyAccessExpression(callee)) {
27188
27194
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -27211,7 +27217,7 @@ var ts;
27211
27217
  else {
27212
27218
  // for `a()` target is `a` and thisArg is `void 0`
27213
27219
  thisArg = createVoidZero();
27214
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27220
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27215
27221
  }
27216
27222
  return { target: target, thisArg: thisArg };
27217
27223
  }
@@ -51886,7 +51892,40 @@ var ts;
51886
51892
  // An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
51887
51893
  // normal mode restrictions
51888
51894
  if (isSyncImport && sourceFile.impliedNodeFormat === ts.ModuleKind.ESNext && !ts.getResolutionModeOverrideForClause(overrideClause)) {
51889
- 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);
51895
+ if (ts.findAncestor(location, ts.isImportEqualsDeclaration)) {
51896
+ // ImportEquals in a ESM file resolving to another ESM file
51897
+ 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);
51898
+ }
51899
+ else {
51900
+ // CJS file resolving to an ESM file
51901
+ var diagnosticDetails = void 0;
51902
+ var ext = ts.tryGetExtensionFromPath(currentSourceFile.fileName);
51903
+ if (ext === ".ts" /* Ts */ || ext === ".js" /* Js */ || ext === ".tsx" /* Tsx */ || ext === ".jsx" /* Jsx */) {
51904
+ var scope = currentSourceFile.packageJsonScope;
51905
+ var targetExt = ext === ".ts" /* Ts */ ? ".mts" /* Mts */ : ext === ".js" /* Js */ ? ".mjs" /* Mjs */ : undefined;
51906
+ if (scope && !scope.packageJsonContent.type) {
51907
+ if (targetExt) {
51908
+ diagnosticDetails = ts.chainDiagnosticMessages(
51909
+ /*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"));
51910
+ }
51911
+ else {
51912
+ diagnosticDetails = ts.chainDiagnosticMessages(
51913
+ /*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"));
51914
+ }
51915
+ }
51916
+ else {
51917
+ if (targetExt) {
51918
+ diagnosticDetails = ts.chainDiagnosticMessages(
51919
+ /*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);
51920
+ }
51921
+ else {
51922
+ diagnosticDetails = ts.chainDiagnosticMessages(
51923
+ /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module);
51924
+ }
51925
+ }
51926
+ }
51927
+ 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)));
51928
+ }
51890
51929
  }
51891
51930
  }
51892
51931
  // merged symbol is module declaration symbol combined with all augmentations
@@ -66392,6 +66431,26 @@ var ts;
66392
66431
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66393
66432
  var saveErrorInfo = captureErrorCalculationState();
66394
66433
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66434
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66435
+ // The combined constraint of an intersection type is the intersection of the constraints of
66436
+ // the constituents. When an intersection type contains instantiable types with union type
66437
+ // constraints, there are situations where we need to examine the combined constraint. One is
66438
+ // when the target is a union type. Another is when the intersection contains types belonging
66439
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66440
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66441
+ // we need to check this constraint against a union on the target side. Also, given a type
66442
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66443
+ // 'string & number | number & number' which reduces to just 'number'.
66444
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66445
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66446
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66447
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66448
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66449
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66450
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66451
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66452
+ }
66453
+ }
66395
66454
  if (result) {
66396
66455
  resetErrorInfo(saveErrorInfo);
66397
66456
  }
@@ -66449,28 +66508,6 @@ var ts;
66449
66508
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66450
66509
  return result;
66451
66510
  }
66452
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66453
- // The combined constraint of an intersection type is the intersection of the constraints of
66454
- // the constituents. When an intersection type contains instantiable types with union type
66455
- // constraints, there are situations where we need to examine the combined constraint. One is
66456
- // when the target is a union type. Another is when the intersection contains types belonging
66457
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66458
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66459
- // we need to check this constraint against a union on the target side. Also, given a type
66460
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66461
- // 'string & number | number & number' which reduces to just 'number'.
66462
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66463
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66464
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66465
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66466
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66467
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66468
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66469
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66470
- return result;
66471
- }
66472
- }
66473
- }
66474
66511
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66475
66512
  // Source is instantiable (e.g. source has union or intersection constraint).
66476
66513
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -84205,17 +84242,28 @@ var ts;
84205
84242
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
84206
84243
  */
84207
84244
  function getIterationTypesOfIterable(type, use, errorNode) {
84245
+ var _a, _b;
84208
84246
  if (isTypeAny(type)) {
84209
84247
  return anyIterationTypes;
84210
84248
  }
84211
84249
  if (!(type.flags & 1048576 /* Union */)) {
84212
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84250
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84251
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
84213
84252
  if (iterationTypes_1 === noIterationTypes) {
84214
84253
  if (errorNode) {
84215
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84254
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84255
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84256
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84257
+ }
84216
84258
  }
84217
84259
  return undefined;
84218
84260
  }
84261
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84262
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84263
+ var diag = _c[_i];
84264
+ diagnostics.add(diag);
84265
+ }
84266
+ }
84219
84267
  return iterationTypes_1;
84220
84268
  }
84221
84269
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84223,19 +84271,27 @@ var ts;
84223
84271
  if (cachedTypes)
84224
84272
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84225
84273
  var allIterationTypes;
84226
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84227
- var constituent = _a[_i];
84228
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84274
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84275
+ var constituent = _e[_d];
84276
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84277
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84229
84278
  if (iterationTypes_2 === noIterationTypes) {
84230
84279
  if (errorNode) {
84231
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84280
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84281
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84282
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84283
+ }
84232
84284
  }
84233
84285
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84234
84286
  return undefined;
84235
84287
  }
84236
- else {
84237
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84288
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84289
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84290
+ var diag = _g[_f];
84291
+ diagnostics.add(diag);
84292
+ }
84238
84293
  }
84294
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84239
84295
  }
84240
84296
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84241
84297
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84263,47 +84319,62 @@ var ts;
84263
84319
  * NOTE: You probably don't want to call this directly and should be calling
84264
84320
  * `getIterationTypesOfIterable` instead.
84265
84321
  */
84266
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84322
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84267
84323
  if (isTypeAny(type)) {
84268
84324
  return anyIterationTypes;
84269
84325
  }
84326
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84327
+ // In addition, we should not cache any new results for this call.
84328
+ var noCache = false;
84270
84329
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84271
84330
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84272
84331
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84273
84332
  if (iterationTypes) {
84274
- return use & 8 /* ForOfFlag */ ?
84275
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84276
- iterationTypes;
84333
+ if (iterationTypes === noIterationTypes && errorNode) {
84334
+ // ignore the cached value
84335
+ noCache = true;
84336
+ }
84337
+ else {
84338
+ return use & 8 /* ForOfFlag */ ?
84339
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84340
+ iterationTypes;
84341
+ }
84277
84342
  }
84278
84343
  }
84279
84344
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84280
84345
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84281
84346
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84282
84347
  if (iterationTypes) {
84283
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84284
- // for a sync iterable in an async context, only use the cached types if they are valid.
84285
- if (iterationTypes !== noIterationTypes) {
84286
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84287
- }
84348
+ if (iterationTypes === noIterationTypes && errorNode) {
84349
+ // ignore the cached value
84350
+ noCache = true;
84288
84351
  }
84289
84352
  else {
84290
- return iterationTypes;
84353
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84354
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84355
+ if (iterationTypes !== noIterationTypes) {
84356
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84357
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84358
+ }
84359
+ }
84360
+ else {
84361
+ return iterationTypes;
84362
+ }
84291
84363
  }
84292
84364
  }
84293
84365
  }
84294
84366
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84295
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84367
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84296
84368
  if (iterationTypes !== noIterationTypes) {
84297
84369
  return iterationTypes;
84298
84370
  }
84299
84371
  }
84300
84372
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84301
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84373
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84302
84374
  if (iterationTypes !== noIterationTypes) {
84303
84375
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84304
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84305
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84306
- : noIterationTypes);
84376
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84377
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84307
84378
  }
84308
84379
  else {
84309
84380
  return iterationTypes;
@@ -84324,7 +84395,7 @@ var ts;
84324
84395
  }
84325
84396
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84326
84397
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84327
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84398
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84328
84399
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84329
84400
  }
84330
84401
  /**
@@ -84378,40 +84449,56 @@ var ts;
84378
84449
  * NOTE: You probably don't want to call this directly and should be calling
84379
84450
  * `getIterationTypesOfIterable` instead.
84380
84451
  */
84381
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84452
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84382
84453
  var _a;
84383
84454
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84384
84455
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84385
84456
  if (isTypeAny(methodType)) {
84386
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84457
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84387
84458
  }
84388
84459
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84389
84460
  if (!ts.some(signatures)) {
84390
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84461
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84391
84462
  }
84392
84463
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84393
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84394
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84464
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84465
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84395
84466
  }
84396
84467
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84397
84468
  var message = allowAsyncIterables
84398
84469
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84399
84470
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84400
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84471
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84472
+ }
84473
+ /**
84474
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84475
+ *
84476
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84477
+ * record is returned. Otherwise, `undefined` is returned.
84478
+ */
84479
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84480
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84401
84481
  }
84402
84482
  /**
84403
84483
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84404
84484
  *
84405
84485
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84406
84486
  * record is returned. Otherwise, `undefined` is returned.
84487
+ *
84488
+ * NOTE: You probably don't want to call this directly and should be calling
84489
+ * `getIterationTypesOfIterator` instead.
84407
84490
  */
84408
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84491
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84409
84492
  if (isTypeAny(type)) {
84410
84493
  return anyIterationTypes;
84411
84494
  }
84412
84495
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84413
- getIterationTypesOfIteratorFast(type, resolver) ||
84414
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84496
+ getIterationTypesOfIteratorFast(type, resolver);
84497
+ if (iterationTypes === noIterationTypes && errorNode) {
84498
+ iterationTypes = undefined;
84499
+ noCache = true;
84500
+ }
84501
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84415
84502
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84416
84503
  }
84417
84504
  /**
@@ -84449,7 +84536,7 @@ var ts;
84449
84536
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84450
84537
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84451
84538
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84452
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84539
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84453
84540
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84454
84541
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84455
84542
  }
@@ -84519,8 +84606,8 @@ var ts;
84519
84606
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84520
84607
  * record is returned. Otherwise, we return `undefined`.
84521
84608
  */
84522
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84523
- var _a, _b, _c, _d;
84609
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84610
+ var _a, _b, _c, _d, _e, _f;
84524
84611
  var method = getPropertyOfType(type, methodName);
84525
84612
  // Ignore 'return' or 'throw' if they are missing.
84526
84613
  if (!method && methodName !== "next") {
@@ -84540,9 +84627,15 @@ var ts;
84540
84627
  var diagnostic = methodName === "next"
84541
84628
  ? resolver.mustHaveANextMethodDiagnostic
84542
84629
  : resolver.mustBeAMethodDiagnostic;
84543
- error(errorNode, diagnostic, methodName);
84630
+ if (errorOutputContainer) {
84631
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84632
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84633
+ }
84634
+ else {
84635
+ error(errorNode, diagnostic, methodName);
84636
+ }
84544
84637
  }
84545
- return methodName === "next" ? anyIterationTypes : undefined;
84638
+ return methodName === "next" ? noIterationTypes : undefined;
84546
84639
  }
84547
84640
  // If the method signature comes exclusively from the global iterator or generator type,
84548
84641
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84554,8 +84647,8 @@ var ts;
84554
84647
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84555
84648
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84556
84649
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84557
- 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;
84558
- 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;
84650
+ 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;
84651
+ 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;
84559
84652
  if (isGeneratorMethod || isIteratorMethod) {
84560
84653
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84561
84654
  var mapper = methodType.mapper;
@@ -84595,7 +84688,13 @@ var ts;
84595
84688
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84596
84689
  if (iterationTypes === noIterationTypes) {
84597
84690
  if (errorNode) {
84598
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84691
+ if (errorOutputContainer) {
84692
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84693
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84694
+ }
84695
+ else {
84696
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84697
+ }
84599
84698
  }
84600
84699
  yieldType = anyType;
84601
84700
  returnTypes = ts.append(returnTypes, anyType);
@@ -84616,13 +84715,13 @@ var ts;
84616
84715
  * NOTE: You probably don't want to call this directly and should be calling
84617
84716
  * `getIterationTypesOfIterator` instead.
84618
84717
  */
84619
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84718
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84620
84719
  var iterationTypes = combineIterationTypes([
84621
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84622
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84623
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84720
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84721
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84722
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84624
84723
  ]);
84625
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84724
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84626
84725
  }
84627
84726
  /**
84628
84727
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84643,7 +84742,7 @@ var ts;
84643
84742
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84644
84743
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84645
84744
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84646
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84745
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84647
84746
  }
84648
84747
  function checkBreakOrContinueStatement(node) {
84649
84748
  // Grammar checking
@@ -122940,8 +123039,6 @@ var ts;
122940
123039
  if (watcher.files === 0 && watcher.resolutions === 0) {
122941
123040
  fileWatchesOfAffectingLocations.delete(path);
122942
123041
  watcher.watcher.close();
122943
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122944
- watcher.watcher = ts.noopFileWatcher;
122945
123042
  }
122946
123043
  });
122947
123044
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123287,20 +123384,27 @@ var ts;
123287
123384
  }
123288
123385
  var paths = new ts.Set();
123289
123386
  paths.add(locationToWatch);
123387
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123388
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123389
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123390
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123391
+ paths.forEach(function (path) {
123392
+ if (watcher.resolutions)
123393
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123394
+ if (watcher.files)
123395
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123396
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123397
+ });
123398
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123399
+ }) : ts.noopFileWatcher;
123290
123400
  var watcher = {
123291
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123292
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123293
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123294
- paths.forEach(function (path) {
123295
- var _a;
123296
- if (watcher.resolutions)
123297
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123298
- if (watcher.files)
123299
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123300
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123301
- });
123302
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123303
- }) : ts.noopFileWatcher,
123401
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123402
+ close: function () {
123403
+ actualWatcher.close();
123404
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123405
+ actualWatcher = ts.noopFileWatcher;
123406
+ }
123407
+ } : actualWatcher,
123304
123408
  resolutions: forResolution ? 1 : 0,
123305
123409
  files: forResolution ? 0 : 1,
123306
123410
  paths: paths,
@@ -123714,7 +123818,7 @@ var ts;
123714
123818
  var info = getInfo(importingSourceFileName, host);
123715
123819
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123716
123820
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123717
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123821
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123718
123822
  }
123719
123823
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123720
123824
  if (options === void 0) { options = {}; }
@@ -123797,7 +123901,7 @@ var ts;
123797
123901
  return nodeModulesSpecifiers;
123798
123902
  }
123799
123903
  if (!specifier && !modulePath.isRedirect) {
123800
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123904
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123801
123905
  if (ts.pathIsBareSpecifier(local)) {
123802
123906
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123803
123907
  }
@@ -123825,7 +123929,7 @@ var ts;
123825
123929
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123826
123930
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123827
123931
  }
123828
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123932
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123829
123933
  var ending = _a.ending, relativePreference = _a.relativePreference;
123830
123934
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123831
123935
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123839,9 +123943,8 @@ var ts;
123839
123943
  if (!relativeToBaseUrl) {
123840
123944
  return relativePath;
123841
123945
  }
123842
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123843
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123844
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123946
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123947
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123845
123948
  if (!nonRelative) {
123846
123949
  return relativePath;
123847
123950
  }
@@ -124076,28 +124179,102 @@ var ts;
124076
124179
  return ambientModuleDeclare.name.text;
124077
124180
  }
124078
124181
  }
124079
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
124182
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
124183
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
124184
+ return [2 /* JsExtension */];
124185
+ }
124186
+ switch (preferredEnding) {
124187
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
124188
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
124189
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
124190
+ default: ts.Debug.assertNever(preferredEnding);
124191
+ }
124192
+ }
124193
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
124080
124194
  for (var key in paths) {
124081
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124082
- var patternText_1 = _a[_i];
124083
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
124195
+ var _loop_36 = function (patternText_1) {
124196
+ var pattern = ts.normalizePath(patternText_1);
124084
124197
  var indexOfStar = pattern.indexOf("*");
124198
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
124199
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
124200
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
124201
+ // and matches the '*'. For example:
124202
+ //
124203
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
124204
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
124205
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
124206
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
124207
+ //
124208
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
124209
+ //
124210
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
124211
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
124212
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
124213
+ // extension for a module specifier.)
124214
+ //
124215
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
124216
+ // .ts extension) or the possible relative module specifiers representing that file:
124217
+ //
124218
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
124219
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
124220
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
124221
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
124222
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
124223
+ // 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
124224
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
124225
+ //
124226
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
124227
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
124228
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
124229
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
124230
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
124231
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
124232
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
124233
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
124234
+ var candidates = allowedEndings.map(function (ending) { return ({
124235
+ ending: ending,
124236
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
124237
+ }); });
124238
+ if (ts.tryGetExtensionFromPath(pattern)) {
124239
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
124240
+ }
124085
124241
  if (indexOfStar !== -1) {
124086
- var prefix = pattern.substr(0, indexOfStar);
124087
- var suffix = pattern.substr(indexOfStar + 1);
124088
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
124089
- ts.startsWith(relativeToBaseUrl, prefix) &&
124090
- ts.endsWith(relativeToBaseUrl, suffix) ||
124091
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
124092
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
124093
- return key.replace("*", matchedStar);
124242
+ var prefix = pattern.substring(0, indexOfStar);
124243
+ var suffix = pattern.substring(indexOfStar + 1);
124244
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
124245
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
124246
+ if (value.length >= prefix.length + suffix.length &&
124247
+ ts.startsWith(value, prefix) &&
124248
+ ts.endsWith(value, suffix) &&
124249
+ validateEnding({ ending: ending, value: value })) {
124250
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
124251
+ return { value: key.replace("*", matchedStar) };
124252
+ }
124094
124253
  }
124095
124254
  }
124096
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
124097
- return key;
124255
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124256
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124257
+ return { value: key };
124098
124258
  }
124259
+ };
124260
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124261
+ var patternText_1 = _a[_i];
124262
+ var state_12 = _loop_36(patternText_1);
124263
+ if (typeof state_12 === "object")
124264
+ return state_12.value;
124099
124265
  }
124100
124266
  }
124267
+ function validateEnding(_a) {
124268
+ var ending = _a.ending, value = _a.value;
124269
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124270
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124271
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124272
+ // 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
124273
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124274
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124275
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124276
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124277
+ }
124101
124278
  }
124102
124279
  var MatchingMode;
124103
124280
  (function (MatchingMode) {
@@ -124193,10 +124370,10 @@ var ts;
124193
124370
  return undefined;
124194
124371
  }
124195
124372
  // Simplify the full file path to something that can be resolved by Node.
124373
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124196
124374
  var moduleSpecifier = path;
124197
124375
  var isPackageRootPath = false;
124198
124376
  if (!packageNameOnly) {
124199
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124200
124377
  var packageRootIndex = parts.packageRootIndex;
124201
124378
  var moduleFileName = void 0;
124202
124379
  while (true) {
@@ -124245,15 +124422,13 @@ var ts;
124245
124422
  var packageRootPath = path.substring(0, packageRootIndex);
124246
124423
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124247
124424
  var moduleFileToTry = path;
124425
+ var maybeBlockedByTypesVersions = false;
124248
124426
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124249
124427
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124250
124428
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124429
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124251
124430
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124252
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124253
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124254
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124255
- // with, so for now we just stick with the mode of the file.
124256
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124431
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124257
124432
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124258
124433
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124259
124434
  : undefined;
@@ -124272,16 +124447,26 @@ var ts;
124272
124447
  : undefined;
124273
124448
  if (versionPaths) {
124274
124449
  var subModuleName = path.slice(packageRootPath.length + 1);
124275
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124276
- if (fromPaths !== undefined) {
124450
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124451
+ if (fromPaths === undefined) {
124452
+ maybeBlockedByTypesVersions = true;
124453
+ }
124454
+ else {
124277
124455
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124278
124456
  }
124279
124457
  }
124280
124458
  // If the file is the main module, it can be imported by the package name
124281
124459
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124282
- if (ts.isString(mainFileRelative)) {
124460
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124461
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124462
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124463
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124464
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124465
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124466
+ // importNameCodeFix_typesVersions.ts for an example.)
124283
124467
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124284
124468
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124469
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124285
124470
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124286
124471
  }
124287
124472
  }
@@ -157101,7 +157286,7 @@ var ts;
157101
157286
  return undefined;
157102
157287
  return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
157103
157288
  }
157104
- if (ts.isIdentifier(token) && ts.isCallExpression(parent)) {
157289
+ if (ts.isIdentifier(token) && ts.isCallExpression(parent) && parent.expression === token) {
157105
157290
  return { kind: 2 /* Function */, token: token, call: parent, sourceFile: sourceFile, modifierFlags: 0 /* None */, parentDeclaration: sourceFile };
157106
157291
  }
157107
157292
  if (!ts.isPropertyAccessExpression(parent))
@@ -162346,6 +162531,9 @@ var ts;
162346
162531
  if (!containingDecl) {
162347
162532
  return;
162348
162533
  }
162534
+ if (ts.isFunctionLikeDeclaration(containingDecl) && containingDecl.body && ts.rangeContainsPosition(containingDecl.body, startPosition)) {
162535
+ return;
162536
+ }
162349
162537
  var checker = program.getTypeChecker();
162350
162538
  var signatureSymbol = containingDecl.symbol;
162351
162539
  if (!signatureSymbol) {