typescript 4.8.0-dev.20220803 → 4.8.0-dev.20220806

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsc.js CHANGED
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  var ts;
70
70
  (function (ts) {
71
71
  ts.versionMajorMinor = "4.8";
72
- ts.version = ts.versionMajorMinor + ".0-dev.20220803";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220806";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -5732,7 +5732,7 @@ var ts;
5732
5732
  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\""),
5733
5733
  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"),
5734
5734
  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."),
5735
- 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."),
5735
+ 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."),
5736
5736
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
5737
5737
  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."),
5738
5738
  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."),
@@ -5740,6 +5740,11 @@ var ts;
5740
5740
  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."),
5741
5741
  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."),
5742
5742
  Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
5743
+ 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."),
5744
+ 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\" }`."),
5745
+ 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}'."),
5746
+ 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}'."),
5747
+ 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\" }`."),
5743
5748
  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."),
5744
5749
  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."),
5745
5750
  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.", undefined, true),
@@ -17383,10 +17388,11 @@ var ts;
17383
17388
  }
17384
17389
  return parenthesizeLeftSideOfAccess(expression);
17385
17390
  }
17386
- function parenthesizeLeftSideOfAccess(expression) {
17391
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
17387
17392
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
17388
17393
  if (ts.isLeftHandSideExpression(emittedExpression)
17389
- && (emittedExpression.kind !== 209 || emittedExpression.arguments)) {
17394
+ && (emittedExpression.kind !== 209 || emittedExpression.arguments)
17395
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
17390
17396
  return expression;
17391
17397
  }
17392
17398
  return ts.setTextRange(factory.createParenthesizedExpression(expression), expression);
@@ -18596,7 +18602,7 @@ var ts;
18596
18602
  }
18597
18603
  function createDecorator(expression) {
18598
18604
  var node = createBaseNode(165);
18599
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
18605
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
18600
18606
  node.transformFlags |=
18601
18607
  propagateChildFlags(node.expression) |
18602
18608
  1 |
@@ -19270,7 +19276,7 @@ var ts;
19270
19276
  }
19271
19277
  function createPropertyAccessExpression(expression, name) {
19272
19278
  var node = createBaseExpression(206);
19273
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19279
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
19274
19280
  node.name = asName(name);
19275
19281
  node.transformFlags =
19276
19282
  propagateChildFlags(node.expression) |
@@ -19296,7 +19302,7 @@ var ts;
19296
19302
  function createPropertyAccessChain(expression, questionDotToken, name) {
19297
19303
  var node = createBaseExpression(206);
19298
19304
  node.flags |= 32;
19299
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19305
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, true);
19300
19306
  node.questionDotToken = questionDotToken;
19301
19307
  node.name = asName(name);
19302
19308
  node.transformFlags |=
@@ -19318,7 +19324,7 @@ var ts;
19318
19324
  }
19319
19325
  function createElementAccessExpression(expression, index) {
19320
19326
  var node = createBaseExpression(207);
19321
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19327
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
19322
19328
  node.argumentExpression = asExpression(index);
19323
19329
  node.transformFlags |=
19324
19330
  propagateChildFlags(node.expression) |
@@ -19342,7 +19348,7 @@ var ts;
19342
19348
  function createElementAccessChain(expression, questionDotToken, index) {
19343
19349
  var node = createBaseExpression(207);
19344
19350
  node.flags |= 32;
19345
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19351
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, true);
19346
19352
  node.questionDotToken = questionDotToken;
19347
19353
  node.argumentExpression = asExpression(index);
19348
19354
  node.transformFlags |=
@@ -19362,7 +19368,7 @@ var ts;
19362
19368
  }
19363
19369
  function createCallExpression(expression, typeArguments, argumentsArray) {
19364
19370
  var node = createBaseExpression(208);
19365
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19371
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
19366
19372
  node.typeArguments = asNodeArray(typeArguments);
19367
19373
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
19368
19374
  node.transformFlags |=
@@ -19393,7 +19399,7 @@ var ts;
19393
19399
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
19394
19400
  var node = createBaseExpression(208);
19395
19401
  node.flags |= 32;
19396
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19402
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, true);
19397
19403
  node.questionDotToken = questionDotToken;
19398
19404
  node.typeArguments = asNodeArray(typeArguments);
19399
19405
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -19444,7 +19450,7 @@ var ts;
19444
19450
  }
19445
19451
  function createTaggedTemplateExpression(tag, typeArguments, template) {
19446
19452
  var node = createBaseExpression(210);
19447
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
19453
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, false);
19448
19454
  node.typeArguments = asNodeArray(typeArguments);
19449
19455
  node.template = template;
19450
19456
  node.transformFlags |=
@@ -19833,7 +19839,7 @@ var ts;
19833
19839
  }
19834
19840
  function createExpressionWithTypeArguments(expression, typeArguments) {
19835
19841
  var node = createBaseNode(228);
19836
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19842
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
19837
19843
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
19838
19844
  node.transformFlags |=
19839
19845
  propagateChildFlags(node.expression) |
@@ -19865,7 +19871,7 @@ var ts;
19865
19871
  }
19866
19872
  function createNonNullExpression(expression) {
19867
19873
  var node = createBaseExpression(230);
19868
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19874
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
19869
19875
  node.transformFlags |=
19870
19876
  propagateChildFlags(node.expression) |
19871
19877
  1;
@@ -19882,7 +19888,7 @@ var ts;
19882
19888
  function createNonNullChain(expression) {
19883
19889
  var node = createBaseExpression(230);
19884
19890
  node.flags |= 32;
19885
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
19891
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, true);
19886
19892
  node.transformFlags |=
19887
19893
  propagateChildFlags(node.expression) |
19888
19894
  1;
@@ -21725,7 +21731,7 @@ var ts;
21725
21731
  }
21726
21732
  else if (ts.getEmitFlags(callee) & 4096) {
21727
21733
  thisArg = createVoidZero();
21728
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
21734
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, false);
21729
21735
  }
21730
21736
  else if (ts.isPropertyAccessExpression(callee)) {
21731
21737
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -21751,7 +21757,7 @@ var ts;
21751
21757
  }
21752
21758
  else {
21753
21759
  thisArg = createVoidZero();
21754
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
21760
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, false);
21755
21761
  }
21756
21762
  return { target: target, thisArg: thisArg };
21757
21763
  }
@@ -42487,7 +42493,34 @@ var ts;
42487
42493
  var overrideClauseHost = ts.findAncestor(location, function (l) { return ts.isImportTypeNode(l) || ts.isExportDeclaration(l) || ts.isImportDeclaration(l); });
42488
42494
  var overrideClause = overrideClauseHost && ts.isImportTypeNode(overrideClauseHost) ? (_g = overrideClauseHost.assertions) === null || _g === void 0 ? void 0 : _g.assertClause : overrideClauseHost === null || overrideClauseHost === void 0 ? void 0 : overrideClauseHost.assertClause;
42489
42495
  if (isSyncImport && sourceFile.impliedNodeFormat === ts.ModuleKind.ESNext && !ts.getResolutionModeOverrideForClause(overrideClause)) {
42490
- 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);
42496
+ if (ts.findAncestor(location, ts.isImportEqualsDeclaration)) {
42497
+ 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);
42498
+ }
42499
+ else {
42500
+ var diagnosticDetails = void 0;
42501
+ var ext = ts.tryGetExtensionFromPath(currentSourceFile.fileName);
42502
+ if (ext === ".ts" || ext === ".js" || ext === ".tsx" || ext === ".jsx") {
42503
+ var scope = currentSourceFile.packageJsonScope;
42504
+ var targetExt = ext === ".ts" ? ".mts" : ext === ".js" ? ".mjs" : undefined;
42505
+ if (scope && !scope.packageJsonContent.type) {
42506
+ if (targetExt) {
42507
+ diagnosticDetails = ts.chainDiagnosticMessages(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"));
42508
+ }
42509
+ else {
42510
+ diagnosticDetails = ts.chainDiagnosticMessages(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"));
42511
+ }
42512
+ }
42513
+ else {
42514
+ if (targetExt) {
42515
+ diagnosticDetails = ts.chainDiagnosticMessages(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);
42516
+ }
42517
+ else {
42518
+ diagnosticDetails = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module);
42519
+ }
42520
+ }
42521
+ }
42522
+ 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)));
42523
+ }
42491
42524
  }
42492
42525
  }
42493
42526
  return getMergedSymbol(sourceFile.symbol);
@@ -61175,12 +61208,15 @@ var ts;
61175
61208
  if (contextualReturnType) {
61176
61209
  var functionFlags = ts.getFunctionFlags(func);
61177
61210
  if (functionFlags & 1) {
61178
- var use = functionFlags & 2 ? 2 : 1;
61179
- var iterationTypes = getIterationTypesOfIterable(contextualReturnType, use, undefined);
61180
- if (!iterationTypes) {
61211
+ var isAsyncGenerator_1 = (functionFlags & 2) !== 0;
61212
+ if (contextualReturnType.flags & 1048576) {
61213
+ contextualReturnType = filterType(contextualReturnType, function (type) { return !!getIterationTypeOfGeneratorFunctionReturnType(1, type, isAsyncGenerator_1); });
61214
+ }
61215
+ var iterationReturnType = getIterationTypeOfGeneratorFunctionReturnType(1, contextualReturnType, (functionFlags & 2) !== 0);
61216
+ if (!iterationReturnType) {
61181
61217
  return undefined;
61182
61218
  }
61183
- contextualReturnType = iterationTypes.returnType;
61219
+ contextualReturnType = iterationReturnType;
61184
61220
  }
61185
61221
  if (functionFlags & 2) {
61186
61222
  var contextualAwaitedType = mapType(contextualReturnType, getAwaitedTypeNoAlias);
@@ -61205,9 +61241,13 @@ var ts;
61205
61241
  var functionFlags = ts.getFunctionFlags(func);
61206
61242
  var contextualReturnType = getContextualReturnType(func, contextFlags);
61207
61243
  if (contextualReturnType) {
61244
+ var isAsyncGenerator_2 = (functionFlags & 2) !== 0;
61245
+ if (!node.asteriskToken && contextualReturnType.flags & 1048576) {
61246
+ contextualReturnType = filterType(contextualReturnType, function (type) { return !!getIterationTypeOfGeneratorFunctionReturnType(1, type, isAsyncGenerator_2); });
61247
+ }
61208
61248
  return node.asteriskToken
61209
61249
  ? contextualReturnType
61210
- : getIterationTypeOfGeneratorFunctionReturnType(0, contextualReturnType, (functionFlags & 2) !== 0);
61250
+ : getIterationTypeOfGeneratorFunctionReturnType(0, contextualReturnType, isAsyncGenerator_2);
61211
61251
  }
61212
61252
  }
61213
61253
  return undefined;
@@ -70471,17 +70511,28 @@ var ts;
70471
70511
  return type[cacheKey] = cachedTypes;
70472
70512
  }
70473
70513
  function getIterationTypesOfIterable(type, use, errorNode) {
70514
+ var _a, _b;
70474
70515
  if (isTypeAny(type)) {
70475
70516
  return anyIterationTypes;
70476
70517
  }
70477
70518
  if (!(type.flags & 1048576)) {
70478
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
70519
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
70520
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
70479
70521
  if (iterationTypes_1 === noIterationTypes) {
70480
70522
  if (errorNode) {
70481
- reportTypeNotIterableError(errorNode, type, !!(use & 2));
70523
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2));
70524
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
70525
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
70526
+ }
70482
70527
  }
70483
70528
  return undefined;
70484
70529
  }
70530
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
70531
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
70532
+ var diag = _c[_i];
70533
+ diagnostics.add(diag);
70534
+ }
70535
+ }
70485
70536
  return iterationTypes_1;
70486
70537
  }
70487
70538
  var cacheKey = use & 2 ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -70489,19 +70540,27 @@ var ts;
70489
70540
  if (cachedTypes)
70490
70541
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
70491
70542
  var allIterationTypes;
70492
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
70493
- var constituent = _a[_i];
70494
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
70543
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
70544
+ var constituent = _e[_d];
70545
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
70546
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
70495
70547
  if (iterationTypes_2 === noIterationTypes) {
70496
70548
  if (errorNode) {
70497
- reportTypeNotIterableError(errorNode, type, !!(use & 2));
70549
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2));
70550
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
70551
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
70552
+ }
70498
70553
  }
70499
70554
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
70500
70555
  return undefined;
70501
70556
  }
70502
- else {
70503
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
70557
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
70558
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
70559
+ var diag = _g[_f];
70560
+ diagnostics.add(diag);
70561
+ }
70504
70562
  }
70563
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
70505
70564
  }
70506
70565
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
70507
70566
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -70518,46 +70577,57 @@ var ts;
70518
70577
  }
70519
70578
  return createIterationTypes(getAwaitedType(yieldType, errorNode) || anyType, getAwaitedType(returnType, errorNode) || anyType, nextType);
70520
70579
  }
70521
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
70580
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
70522
70581
  if (isTypeAny(type)) {
70523
70582
  return anyIterationTypes;
70524
70583
  }
70584
+ var noCache = false;
70525
70585
  if (use & 2) {
70526
70586
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
70527
70587
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
70528
70588
  if (iterationTypes) {
70529
- return use & 8 ?
70530
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
70531
- iterationTypes;
70589
+ if (iterationTypes === noIterationTypes && errorNode) {
70590
+ noCache = true;
70591
+ }
70592
+ else {
70593
+ return use & 8 ?
70594
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
70595
+ iterationTypes;
70596
+ }
70532
70597
  }
70533
70598
  }
70534
70599
  if (use & 1) {
70535
70600
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
70536
70601
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
70537
70602
  if (iterationTypes) {
70538
- if (use & 2) {
70539
- if (iterationTypes !== noIterationTypes) {
70540
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
70541
- }
70603
+ if (iterationTypes === noIterationTypes && errorNode) {
70604
+ noCache = true;
70542
70605
  }
70543
70606
  else {
70544
- return iterationTypes;
70607
+ if (use & 2) {
70608
+ if (iterationTypes !== noIterationTypes) {
70609
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
70610
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
70611
+ }
70612
+ }
70613
+ else {
70614
+ return iterationTypes;
70615
+ }
70545
70616
  }
70546
70617
  }
70547
70618
  }
70548
70619
  if (use & 2) {
70549
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
70620
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
70550
70621
  if (iterationTypes !== noIterationTypes) {
70551
70622
  return iterationTypes;
70552
70623
  }
70553
70624
  }
70554
70625
  if (use & 1) {
70555
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
70626
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
70556
70627
  if (iterationTypes !== noIterationTypes) {
70557
70628
  if (use & 2) {
70558
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
70559
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
70560
- : noIterationTypes);
70629
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
70630
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
70561
70631
  }
70562
70632
  else {
70563
70633
  return iterationTypes;
@@ -70571,7 +70641,7 @@ var ts;
70571
70641
  }
70572
70642
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
70573
70643
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
70574
- getIterationTypesOfIterableSlow(globalType, resolver, undefined);
70644
+ getIterationTypesOfIterableSlow(globalType, resolver, undefined, undefined, false);
70575
70645
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
70576
70646
  }
70577
70647
  function getIterationTypesOfIterableFast(type, resolver) {
@@ -70592,34 +70662,41 @@ var ts;
70592
70662
  var uniqueType = ctorType && getTypeOfPropertyOfType(getTypeOfSymbol(ctorType), ts.escapeLeadingUnderscores(symbolName));
70593
70663
  return uniqueType && isTypeUsableAsPropertyName(uniqueType) ? getPropertyNameFromType(uniqueType) : "__@" + symbolName;
70594
70664
  }
70595
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
70665
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
70596
70666
  var _a;
70597
70667
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
70598
70668
  var methodType = method && !(method.flags & 16777216) ? getTypeOfSymbol(method) : undefined;
70599
70669
  if (isTypeAny(methodType)) {
70600
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
70670
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
70601
70671
  }
70602
70672
  var signatures = methodType ? getSignaturesOfType(methodType, 0) : undefined;
70603
70673
  if (!ts.some(signatures)) {
70604
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
70674
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
70605
70675
  }
70606
70676
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
70607
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
70608
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
70677
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
70678
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
70609
70679
  }
70610
70680
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
70611
70681
  var message = allowAsyncIterables
70612
70682
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
70613
70683
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
70614
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
70684
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
70615
70685
  }
70616
- function getIterationTypesOfIterator(type, resolver, errorNode) {
70686
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
70687
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, false);
70688
+ }
70689
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
70617
70690
  if (isTypeAny(type)) {
70618
70691
  return anyIterationTypes;
70619
70692
  }
70620
70693
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
70621
- getIterationTypesOfIteratorFast(type, resolver) ||
70622
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
70694
+ getIterationTypesOfIteratorFast(type, resolver);
70695
+ if (iterationTypes === noIterationTypes && errorNode) {
70696
+ iterationTypes = undefined;
70697
+ noCache = true;
70698
+ }
70699
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
70623
70700
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
70624
70701
  }
70625
70702
  function getIterationTypesOfIteratorCached(type, resolver) {
@@ -70630,7 +70707,7 @@ var ts;
70630
70707
  if (isReferenceToType(type, globalType)) {
70631
70708
  var yieldType = getTypeArguments(type)[0];
70632
70709
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
70633
- getIterationTypesOfIteratorSlow(globalType, resolver, undefined);
70710
+ getIterationTypesOfIteratorSlow(globalType, resolver, undefined, undefined, false);
70634
70711
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
70635
70712
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
70636
70713
  }
@@ -70675,8 +70752,8 @@ var ts;
70675
70752
  }
70676
70753
  return setCachedIterationTypes(type, "iterationTypesOfIteratorResult", createIterationTypes(yieldType, returnType || voidType, undefined));
70677
70754
  }
70678
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
70679
- var _a, _b, _c, _d;
70755
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
70756
+ var _a, _b, _c, _d, _e, _f;
70680
70757
  var method = getPropertyOfType(type, methodName);
70681
70758
  if (!method && methodName !== "next") {
70682
70759
  return undefined;
@@ -70693,15 +70770,21 @@ var ts;
70693
70770
  var diagnostic = methodName === "next"
70694
70771
  ? resolver.mustHaveANextMethodDiagnostic
70695
70772
  : resolver.mustBeAMethodDiagnostic;
70696
- error(errorNode, diagnostic, methodName);
70773
+ if (errorOutputContainer) {
70774
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
70775
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
70776
+ }
70777
+ else {
70778
+ error(errorNode, diagnostic, methodName);
70779
+ }
70697
70780
  }
70698
- return methodName === "next" ? anyIterationTypes : undefined;
70781
+ return methodName === "next" ? noIterationTypes : undefined;
70699
70782
  }
70700
70783
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
70701
70784
  var globalGeneratorType = resolver.getGlobalGeneratorType(false);
70702
70785
  var globalIteratorType = resolver.getGlobalIteratorType(false);
70703
- 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;
70704
- 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;
70786
+ 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;
70787
+ 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;
70705
70788
  if (isGeneratorMethod || isIteratorMethod) {
70706
70789
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
70707
70790
  var mapper = methodType.mapper;
@@ -70735,7 +70818,13 @@ var ts;
70735
70818
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
70736
70819
  if (iterationTypes === noIterationTypes) {
70737
70820
  if (errorNode) {
70738
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
70821
+ if (errorOutputContainer) {
70822
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
70823
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
70824
+ }
70825
+ else {
70826
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
70827
+ }
70739
70828
  }
70740
70829
  yieldType = anyType;
70741
70830
  returnTypes = ts.append(returnTypes, anyType);
@@ -70746,13 +70835,13 @@ var ts;
70746
70835
  }
70747
70836
  return createIterationTypes(yieldType, getUnionType(returnTypes), nextType);
70748
70837
  }
70749
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
70838
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
70750
70839
  var iterationTypes = combineIterationTypes([
70751
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
70752
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
70753
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
70840
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
70841
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
70842
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
70754
70843
  ]);
70755
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
70844
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
70756
70845
  }
70757
70846
  function getIterationTypeOfGeneratorFunctionReturnType(kind, returnType, isAsyncGenerator) {
70758
70847
  if (isTypeAny(returnType)) {
@@ -70768,7 +70857,7 @@ var ts;
70768
70857
  var use = isAsyncGenerator ? 2 : 1;
70769
70858
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
70770
70859
  return getIterationTypesOfIterable(type, use, undefined) ||
70771
- getIterationTypesOfIterator(type, resolver, undefined);
70860
+ getIterationTypesOfIterator(type, resolver, undefined, undefined);
70772
70861
  }
70773
70862
  function checkBreakOrContinueStatement(node) {
70774
70863
  if (!checkGrammarStatementInAmbientContext(node))
@@ -101691,7 +101780,6 @@ var ts;
101691
101780
  if (watcher.files === 0 && watcher.resolutions === 0) {
101692
101781
  fileWatchesOfAffectingLocations.delete(path);
101693
101782
  watcher.watcher.close();
101694
- watcher.watcher = ts.noopFileWatcher;
101695
101783
  }
101696
101784
  });
101697
101785
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -102011,20 +102099,26 @@ var ts;
102011
102099
  }
102012
102100
  var paths = new ts.Set();
102013
102101
  paths.add(locationToWatch);
102102
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
102103
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
102104
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
102105
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
102106
+ paths.forEach(function (path) {
102107
+ if (watcher.resolutions)
102108
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
102109
+ if (watcher.files)
102110
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
102111
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
102112
+ });
102113
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102114
+ }) : ts.noopFileWatcher;
102014
102115
  var watcher = {
102015
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
102016
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
102017
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
102018
- paths.forEach(function (path) {
102019
- var _a;
102020
- if (watcher.resolutions)
102021
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
102022
- if (watcher.files)
102023
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
102024
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
102025
- });
102026
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102027
- }) : ts.noopFileWatcher,
102116
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
102117
+ close: function () {
102118
+ actualWatcher.close();
102119
+ actualWatcher = ts.noopFileWatcher;
102120
+ }
102121
+ } : actualWatcher,
102028
102122
  resolutions: forResolution ? 1 : 0,
102029
102123
  files: forResolution ? 0 : 1,
102030
102124
  paths: paths,
@@ -102373,7 +102467,7 @@ var ts;
102373
102467
  var info = getInfo(importingSourceFileName, host);
102374
102468
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
102375
102469
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, undefined, options.overrideImportMode); }) ||
102376
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
102470
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
102377
102471
  }
102378
102472
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
102379
102473
  if (options === void 0) { options = {}; }
@@ -102444,7 +102538,7 @@ var ts;
102444
102538
  return nodeModulesSpecifiers;
102445
102539
  }
102446
102540
  if (!specifier && !modulePath.isRedirect) {
102447
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
102541
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
102448
102542
  if (ts.pathIsBareSpecifier(local)) {
102449
102543
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
102450
102544
  }
@@ -102462,7 +102556,7 @@ var ts;
102462
102556
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
102463
102557
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
102464
102558
  }
102465
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
102559
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
102466
102560
  var ending = _a.ending, relativePreference = _a.relativePreference;
102467
102561
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
102468
102562
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -102476,9 +102570,8 @@ var ts;
102476
102570
  if (!relativeToBaseUrl) {
102477
102571
  return relativePath;
102478
102572
  }
102479
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
102480
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
102481
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
102573
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
102574
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
102482
102575
  if (!nonRelative) {
102483
102576
  return relativePath;
102484
102577
  }
@@ -102675,28 +102768,59 @@ var ts;
102675
102768
  return ambientModuleDeclare.name.text;
102676
102769
  }
102677
102770
  }
102678
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
102771
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
102772
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
102773
+ return [2];
102774
+ }
102775
+ switch (preferredEnding) {
102776
+ case 2: return [2, 0, 1];
102777
+ case 1: return [1, 0, 2];
102778
+ case 0: return [0, 1, 2];
102779
+ default: ts.Debug.assertNever(preferredEnding);
102780
+ }
102781
+ }
102782
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
102679
102783
  for (var key in paths) {
102680
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
102681
- var patternText_1 = _a[_i];
102682
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
102784
+ var _loop_36 = function (patternText_1) {
102785
+ var pattern = ts.normalizePath(patternText_1);
102683
102786
  var indexOfStar = pattern.indexOf("*");
102787
+ var candidates = allowedEndings.map(function (ending) { return ({
102788
+ ending: ending,
102789
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
102790
+ }); });
102791
+ if (ts.tryGetExtensionFromPath(pattern)) {
102792
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
102793
+ }
102684
102794
  if (indexOfStar !== -1) {
102685
- var prefix = pattern.substr(0, indexOfStar);
102686
- var suffix = pattern.substr(indexOfStar + 1);
102687
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
102688
- ts.startsWith(relativeToBaseUrl, prefix) &&
102689
- ts.endsWith(relativeToBaseUrl, suffix) ||
102690
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
102691
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
102692
- return key.replace("*", matchedStar);
102795
+ var prefix = pattern.substring(0, indexOfStar);
102796
+ var suffix = pattern.substring(indexOfStar + 1);
102797
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
102798
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
102799
+ if (value.length >= prefix.length + suffix.length &&
102800
+ ts.startsWith(value, prefix) &&
102801
+ ts.endsWith(value, suffix) &&
102802
+ validateEnding({ ending: ending, value: value })) {
102803
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
102804
+ return { value: key.replace("*", matchedStar) };
102805
+ }
102693
102806
  }
102694
102807
  }
102695
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
102696
- return key;
102808
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 && pattern === c.value; }) ||
102809
+ ts.some(candidates, function (c) { return c.ending === 0 && pattern === c.value && validateEnding(c); })) {
102810
+ return { value: key };
102697
102811
  }
102812
+ };
102813
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
102814
+ var patternText_1 = _a[_i];
102815
+ var state_12 = _loop_36(patternText_1);
102816
+ if (typeof state_12 === "object")
102817
+ return state_12.value;
102698
102818
  }
102699
102819
  }
102820
+ function validateEnding(_a) {
102821
+ var ending = _a.ending, value = _a.value;
102822
+ return ending !== 0 || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
102823
+ }
102700
102824
  }
102701
102825
  function tryGetModuleNameFromExports(options, targetFilePath, packageDirectory, packageName, exports, conditions, mode) {
102702
102826
  if (mode === void 0) { mode = 0; }
@@ -102779,10 +102903,10 @@ var ts;
102779
102903
  if (!parts) {
102780
102904
  return undefined;
102781
102905
  }
102906
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
102782
102907
  var moduleSpecifier = path;
102783
102908
  var isPackageRootPath = false;
102784
102909
  if (!packageNameOnly) {
102785
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
102786
102910
  var packageRootIndex = parts.packageRootIndex;
102787
102911
  var moduleFileName = void 0;
102788
102912
  while (true) {
@@ -102825,11 +102949,13 @@ var ts;
102825
102949
  var packageRootPath = path.substring(0, packageRootIndex);
102826
102950
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
102827
102951
  var moduleFileToTry = path;
102952
+ var maybeBlockedByTypesVersions = false;
102828
102953
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
102829
102954
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
102830
102955
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
102956
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
102831
102957
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
102832
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
102958
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
102833
102959
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
102834
102960
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
102835
102961
  : undefined;
@@ -102848,13 +102974,16 @@ var ts;
102848
102974
  : undefined;
102849
102975
  if (versionPaths) {
102850
102976
  var subModuleName = path.slice(packageRootPath.length + 1);
102851
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0, options), versionPaths.paths);
102852
- if (fromPaths !== undefined) {
102977
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
102978
+ if (fromPaths === undefined) {
102979
+ maybeBlockedByTypesVersions = true;
102980
+ }
102981
+ else {
102853
102982
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
102854
102983
  }
102855
102984
  }
102856
102985
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
102857
- if (ts.isString(mainFileRelative)) {
102986
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
102858
102987
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
102859
102988
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
102860
102989
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };