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.
@@ -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.20220803";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220806";
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
@@ -73394,12 +73433,15 @@ var ts;
73394
73433
  if (contextualReturnType) {
73395
73434
  var functionFlags = ts.getFunctionFlags(func);
73396
73435
  if (functionFlags & 1 /* Generator */) { // Generator or AsyncGenerator function
73397
- var use = functionFlags & 2 /* Async */ ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
73398
- var iterationTypes = getIterationTypesOfIterable(contextualReturnType, use, /*errorNode*/ undefined);
73399
- if (!iterationTypes) {
73436
+ var isAsyncGenerator_1 = (functionFlags & 2 /* Async */) !== 0;
73437
+ if (contextualReturnType.flags & 1048576 /* Union */) {
73438
+ contextualReturnType = filterType(contextualReturnType, function (type) { return !!getIterationTypeOfGeneratorFunctionReturnType(1 /* Return */, type, isAsyncGenerator_1); });
73439
+ }
73440
+ var iterationReturnType = getIterationTypeOfGeneratorFunctionReturnType(1 /* Return */, contextualReturnType, (functionFlags & 2 /* Async */) !== 0);
73441
+ if (!iterationReturnType) {
73400
73442
  return undefined;
73401
73443
  }
73402
- contextualReturnType = iterationTypes.returnType;
73444
+ contextualReturnType = iterationReturnType;
73403
73445
  // falls through to unwrap Promise for AsyncGenerators
73404
73446
  }
73405
73447
  if (functionFlags & 2 /* Async */) { // Async function or AsyncGenerator function
@@ -73426,9 +73468,13 @@ var ts;
73426
73468
  var functionFlags = ts.getFunctionFlags(func);
73427
73469
  var contextualReturnType = getContextualReturnType(func, contextFlags);
73428
73470
  if (contextualReturnType) {
73471
+ var isAsyncGenerator_2 = (functionFlags & 2 /* Async */) !== 0;
73472
+ if (!node.asteriskToken && contextualReturnType.flags & 1048576 /* Union */) {
73473
+ contextualReturnType = filterType(contextualReturnType, function (type) { return !!getIterationTypeOfGeneratorFunctionReturnType(1 /* Return */, type, isAsyncGenerator_2); });
73474
+ }
73429
73475
  return node.asteriskToken
73430
73476
  ? contextualReturnType
73431
- : getIterationTypeOfGeneratorFunctionReturnType(0 /* Yield */, contextualReturnType, (functionFlags & 2 /* Async */) !== 0);
73477
+ : getIterationTypeOfGeneratorFunctionReturnType(0 /* Yield */, contextualReturnType, isAsyncGenerator_2);
73432
73478
  }
73433
73479
  }
73434
73480
  return undefined;
@@ -84203,17 +84249,28 @@ var ts;
84203
84249
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
84204
84250
  */
84205
84251
  function getIterationTypesOfIterable(type, use, errorNode) {
84252
+ var _a, _b;
84206
84253
  if (isTypeAny(type)) {
84207
84254
  return anyIterationTypes;
84208
84255
  }
84209
84256
  if (!(type.flags & 1048576 /* Union */)) {
84210
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84257
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84258
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
84211
84259
  if (iterationTypes_1 === noIterationTypes) {
84212
84260
  if (errorNode) {
84213
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84261
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84262
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84263
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84264
+ }
84214
84265
  }
84215
84266
  return undefined;
84216
84267
  }
84268
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84269
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84270
+ var diag = _c[_i];
84271
+ diagnostics.add(diag);
84272
+ }
84273
+ }
84217
84274
  return iterationTypes_1;
84218
84275
  }
84219
84276
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84221,19 +84278,27 @@ var ts;
84221
84278
  if (cachedTypes)
84222
84279
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84223
84280
  var allIterationTypes;
84224
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84225
- var constituent = _a[_i];
84226
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84281
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84282
+ var constituent = _e[_d];
84283
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84284
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84227
84285
  if (iterationTypes_2 === noIterationTypes) {
84228
84286
  if (errorNode) {
84229
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84287
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84288
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84289
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84290
+ }
84230
84291
  }
84231
84292
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84232
84293
  return undefined;
84233
84294
  }
84234
- else {
84235
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84295
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84296
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84297
+ var diag = _g[_f];
84298
+ diagnostics.add(diag);
84299
+ }
84236
84300
  }
84301
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84237
84302
  }
84238
84303
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84239
84304
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84261,47 +84326,62 @@ var ts;
84261
84326
  * NOTE: You probably don't want to call this directly and should be calling
84262
84327
  * `getIterationTypesOfIterable` instead.
84263
84328
  */
84264
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84329
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84265
84330
  if (isTypeAny(type)) {
84266
84331
  return anyIterationTypes;
84267
84332
  }
84333
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84334
+ // In addition, we should not cache any new results for this call.
84335
+ var noCache = false;
84268
84336
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84269
84337
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84270
84338
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84271
84339
  if (iterationTypes) {
84272
- return use & 8 /* ForOfFlag */ ?
84273
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84274
- iterationTypes;
84340
+ if (iterationTypes === noIterationTypes && errorNode) {
84341
+ // ignore the cached value
84342
+ noCache = true;
84343
+ }
84344
+ else {
84345
+ return use & 8 /* ForOfFlag */ ?
84346
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84347
+ iterationTypes;
84348
+ }
84275
84349
  }
84276
84350
  }
84277
84351
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84278
84352
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84279
84353
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84280
84354
  if (iterationTypes) {
84281
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84282
- // for a sync iterable in an async context, only use the cached types if they are valid.
84283
- if (iterationTypes !== noIterationTypes) {
84284
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84285
- }
84355
+ if (iterationTypes === noIterationTypes && errorNode) {
84356
+ // ignore the cached value
84357
+ noCache = true;
84286
84358
  }
84287
84359
  else {
84288
- return iterationTypes;
84360
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84361
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84362
+ if (iterationTypes !== noIterationTypes) {
84363
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84364
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84365
+ }
84366
+ }
84367
+ else {
84368
+ return iterationTypes;
84369
+ }
84289
84370
  }
84290
84371
  }
84291
84372
  }
84292
84373
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84293
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84374
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84294
84375
  if (iterationTypes !== noIterationTypes) {
84295
84376
  return iterationTypes;
84296
84377
  }
84297
84378
  }
84298
84379
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84299
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84380
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84300
84381
  if (iterationTypes !== noIterationTypes) {
84301
84382
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84302
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84303
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84304
- : noIterationTypes);
84383
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84384
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84305
84385
  }
84306
84386
  else {
84307
84387
  return iterationTypes;
@@ -84322,7 +84402,7 @@ var ts;
84322
84402
  }
84323
84403
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84324
84404
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84325
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84405
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84326
84406
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84327
84407
  }
84328
84408
  /**
@@ -84376,40 +84456,56 @@ var ts;
84376
84456
  * NOTE: You probably don't want to call this directly and should be calling
84377
84457
  * `getIterationTypesOfIterable` instead.
84378
84458
  */
84379
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84459
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84380
84460
  var _a;
84381
84461
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84382
84462
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84383
84463
  if (isTypeAny(methodType)) {
84384
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84464
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84385
84465
  }
84386
84466
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84387
84467
  if (!ts.some(signatures)) {
84388
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84468
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84389
84469
  }
84390
84470
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84391
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84392
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84471
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84472
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84393
84473
  }
84394
84474
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84395
84475
  var message = allowAsyncIterables
84396
84476
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84397
84477
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84398
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84478
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84479
+ }
84480
+ /**
84481
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84482
+ *
84483
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84484
+ * record is returned. Otherwise, `undefined` is returned.
84485
+ */
84486
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84487
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84399
84488
  }
84400
84489
  /**
84401
84490
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84402
84491
  *
84403
84492
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84404
84493
  * record is returned. Otherwise, `undefined` is returned.
84494
+ *
84495
+ * NOTE: You probably don't want to call this directly and should be calling
84496
+ * `getIterationTypesOfIterator` instead.
84405
84497
  */
84406
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84498
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84407
84499
  if (isTypeAny(type)) {
84408
84500
  return anyIterationTypes;
84409
84501
  }
84410
84502
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84411
- getIterationTypesOfIteratorFast(type, resolver) ||
84412
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84503
+ getIterationTypesOfIteratorFast(type, resolver);
84504
+ if (iterationTypes === noIterationTypes && errorNode) {
84505
+ iterationTypes = undefined;
84506
+ noCache = true;
84507
+ }
84508
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84413
84509
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84414
84510
  }
84415
84511
  /**
@@ -84447,7 +84543,7 @@ var ts;
84447
84543
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84448
84544
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84449
84545
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84450
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84546
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84451
84547
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84452
84548
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84453
84549
  }
@@ -84517,8 +84613,8 @@ var ts;
84517
84613
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84518
84614
  * record is returned. Otherwise, we return `undefined`.
84519
84615
  */
84520
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84521
- var _a, _b, _c, _d;
84616
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84617
+ var _a, _b, _c, _d, _e, _f;
84522
84618
  var method = getPropertyOfType(type, methodName);
84523
84619
  // Ignore 'return' or 'throw' if they are missing.
84524
84620
  if (!method && methodName !== "next") {
@@ -84538,9 +84634,15 @@ var ts;
84538
84634
  var diagnostic = methodName === "next"
84539
84635
  ? resolver.mustHaveANextMethodDiagnostic
84540
84636
  : resolver.mustBeAMethodDiagnostic;
84541
- error(errorNode, diagnostic, methodName);
84637
+ if (errorOutputContainer) {
84638
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84639
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84640
+ }
84641
+ else {
84642
+ error(errorNode, diagnostic, methodName);
84643
+ }
84542
84644
  }
84543
- return methodName === "next" ? anyIterationTypes : undefined;
84645
+ return methodName === "next" ? noIterationTypes : undefined;
84544
84646
  }
84545
84647
  // If the method signature comes exclusively from the global iterator or generator type,
84546
84648
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84552,8 +84654,8 @@ var ts;
84552
84654
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84553
84655
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84554
84656
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84555
- 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;
84556
- 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;
84657
+ 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;
84658
+ 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;
84557
84659
  if (isGeneratorMethod || isIteratorMethod) {
84558
84660
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84559
84661
  var mapper = methodType.mapper;
@@ -84593,7 +84695,13 @@ var ts;
84593
84695
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84594
84696
  if (iterationTypes === noIterationTypes) {
84595
84697
  if (errorNode) {
84596
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84698
+ if (errorOutputContainer) {
84699
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84700
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84701
+ }
84702
+ else {
84703
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84704
+ }
84597
84705
  }
84598
84706
  yieldType = anyType;
84599
84707
  returnTypes = ts.append(returnTypes, anyType);
@@ -84614,13 +84722,13 @@ var ts;
84614
84722
  * NOTE: You probably don't want to call this directly and should be calling
84615
84723
  * `getIterationTypesOfIterator` instead.
84616
84724
  */
84617
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84725
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84618
84726
  var iterationTypes = combineIterationTypes([
84619
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84620
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84621
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84727
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84728
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84729
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84622
84730
  ]);
84623
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84731
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84624
84732
  }
84625
84733
  /**
84626
84734
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84641,7 +84749,7 @@ var ts;
84641
84749
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84642
84750
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84643
84751
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84644
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84752
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84645
84753
  }
84646
84754
  function checkBreakOrContinueStatement(node) {
84647
84755
  // Grammar checking
@@ -122938,8 +123046,6 @@ var ts;
122938
123046
  if (watcher.files === 0 && watcher.resolutions === 0) {
122939
123047
  fileWatchesOfAffectingLocations.delete(path);
122940
123048
  watcher.watcher.close();
122941
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122942
- watcher.watcher = ts.noopFileWatcher;
122943
123049
  }
122944
123050
  });
122945
123051
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123285,20 +123391,27 @@ var ts;
123285
123391
  }
123286
123392
  var paths = new ts.Set();
123287
123393
  paths.add(locationToWatch);
123394
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123395
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123396
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123397
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123398
+ paths.forEach(function (path) {
123399
+ if (watcher.resolutions)
123400
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123401
+ if (watcher.files)
123402
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123403
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123404
+ });
123405
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123406
+ }) : ts.noopFileWatcher;
123288
123407
  var watcher = {
123289
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123290
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123291
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123292
- paths.forEach(function (path) {
123293
- var _a;
123294
- if (watcher.resolutions)
123295
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123296
- if (watcher.files)
123297
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123298
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123299
- });
123300
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123301
- }) : ts.noopFileWatcher,
123408
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123409
+ close: function () {
123410
+ actualWatcher.close();
123411
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123412
+ actualWatcher = ts.noopFileWatcher;
123413
+ }
123414
+ } : actualWatcher,
123302
123415
  resolutions: forResolution ? 1 : 0,
123303
123416
  files: forResolution ? 0 : 1,
123304
123417
  paths: paths,
@@ -123712,7 +123825,7 @@ var ts;
123712
123825
  var info = getInfo(importingSourceFileName, host);
123713
123826
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123714
123827
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123715
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123828
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123716
123829
  }
123717
123830
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123718
123831
  if (options === void 0) { options = {}; }
@@ -123795,7 +123908,7 @@ var ts;
123795
123908
  return nodeModulesSpecifiers;
123796
123909
  }
123797
123910
  if (!specifier && !modulePath.isRedirect) {
123798
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123911
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123799
123912
  if (ts.pathIsBareSpecifier(local)) {
123800
123913
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123801
123914
  }
@@ -123823,7 +123936,7 @@ var ts;
123823
123936
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123824
123937
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123825
123938
  }
123826
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123939
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123827
123940
  var ending = _a.ending, relativePreference = _a.relativePreference;
123828
123941
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123829
123942
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123837,9 +123950,8 @@ var ts;
123837
123950
  if (!relativeToBaseUrl) {
123838
123951
  return relativePath;
123839
123952
  }
123840
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123841
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123842
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123953
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123954
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123843
123955
  if (!nonRelative) {
123844
123956
  return relativePath;
123845
123957
  }
@@ -124074,28 +124186,102 @@ var ts;
124074
124186
  return ambientModuleDeclare.name.text;
124075
124187
  }
124076
124188
  }
124077
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
124189
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
124190
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
124191
+ return [2 /* JsExtension */];
124192
+ }
124193
+ switch (preferredEnding) {
124194
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
124195
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
124196
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
124197
+ default: ts.Debug.assertNever(preferredEnding);
124198
+ }
124199
+ }
124200
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
124078
124201
  for (var key in paths) {
124079
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124080
- var patternText_1 = _a[_i];
124081
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
124202
+ var _loop_36 = function (patternText_1) {
124203
+ var pattern = ts.normalizePath(patternText_1);
124082
124204
  var indexOfStar = pattern.indexOf("*");
124205
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
124206
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
124207
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
124208
+ // and matches the '*'. For example:
124209
+ //
124210
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
124211
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
124212
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
124213
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
124214
+ //
124215
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
124216
+ //
124217
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
124218
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
124219
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
124220
+ // extension for a module specifier.)
124221
+ //
124222
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
124223
+ // .ts extension) or the possible relative module specifiers representing that file:
124224
+ //
124225
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
124226
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
124227
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
124228
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
124229
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
124230
+ // 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
124231
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
124232
+ //
124233
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
124234
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
124235
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
124236
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
124237
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
124238
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
124239
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
124240
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
124241
+ var candidates = allowedEndings.map(function (ending) { return ({
124242
+ ending: ending,
124243
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
124244
+ }); });
124245
+ if (ts.tryGetExtensionFromPath(pattern)) {
124246
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
124247
+ }
124083
124248
  if (indexOfStar !== -1) {
124084
- var prefix = pattern.substr(0, indexOfStar);
124085
- var suffix = pattern.substr(indexOfStar + 1);
124086
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
124087
- ts.startsWith(relativeToBaseUrl, prefix) &&
124088
- ts.endsWith(relativeToBaseUrl, suffix) ||
124089
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
124090
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
124091
- return key.replace("*", matchedStar);
124249
+ var prefix = pattern.substring(0, indexOfStar);
124250
+ var suffix = pattern.substring(indexOfStar + 1);
124251
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
124252
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
124253
+ if (value.length >= prefix.length + suffix.length &&
124254
+ ts.startsWith(value, prefix) &&
124255
+ ts.endsWith(value, suffix) &&
124256
+ validateEnding({ ending: ending, value: value })) {
124257
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
124258
+ return { value: key.replace("*", matchedStar) };
124259
+ }
124092
124260
  }
124093
124261
  }
124094
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
124095
- return key;
124262
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124263
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124264
+ return { value: key };
124096
124265
  }
124266
+ };
124267
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124268
+ var patternText_1 = _a[_i];
124269
+ var state_12 = _loop_36(patternText_1);
124270
+ if (typeof state_12 === "object")
124271
+ return state_12.value;
124097
124272
  }
124098
124273
  }
124274
+ function validateEnding(_a) {
124275
+ var ending = _a.ending, value = _a.value;
124276
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124277
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124278
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124279
+ // 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
124280
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124281
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124282
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124283
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124284
+ }
124099
124285
  }
124100
124286
  var MatchingMode;
124101
124287
  (function (MatchingMode) {
@@ -124191,10 +124377,10 @@ var ts;
124191
124377
  return undefined;
124192
124378
  }
124193
124379
  // Simplify the full file path to something that can be resolved by Node.
124380
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124194
124381
  var moduleSpecifier = path;
124195
124382
  var isPackageRootPath = false;
124196
124383
  if (!packageNameOnly) {
124197
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124198
124384
  var packageRootIndex = parts.packageRootIndex;
124199
124385
  var moduleFileName = void 0;
124200
124386
  while (true) {
@@ -124243,15 +124429,13 @@ var ts;
124243
124429
  var packageRootPath = path.substring(0, packageRootIndex);
124244
124430
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124245
124431
  var moduleFileToTry = path;
124432
+ var maybeBlockedByTypesVersions = false;
124246
124433
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124247
124434
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124248
124435
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124436
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124249
124437
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124250
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124251
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124252
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124253
- // with, so for now we just stick with the mode of the file.
124254
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124438
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124255
124439
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124256
124440
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124257
124441
  : undefined;
@@ -124270,16 +124454,26 @@ var ts;
124270
124454
  : undefined;
124271
124455
  if (versionPaths) {
124272
124456
  var subModuleName = path.slice(packageRootPath.length + 1);
124273
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124274
- if (fromPaths !== undefined) {
124457
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124458
+ if (fromPaths === undefined) {
124459
+ maybeBlockedByTypesVersions = true;
124460
+ }
124461
+ else {
124275
124462
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124276
124463
  }
124277
124464
  }
124278
124465
  // If the file is the main module, it can be imported by the package name
124279
124466
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124280
- if (ts.isString(mainFileRelative)) {
124467
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124468
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124469
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124470
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124471
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124472
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124473
+ // importNameCodeFix_typesVersions.ts for an example.)
124281
124474
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124282
124475
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124476
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124283
124477
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124284
124478
  }
124285
124479
  }
@@ -157099,7 +157293,7 @@ var ts;
157099
157293
  return undefined;
157100
157294
  return { kind: 4 /* JsxAttributes */, token: token, attributes: attributes, parentDeclaration: token.parent };
157101
157295
  }
157102
- if (ts.isIdentifier(token) && ts.isCallExpression(parent)) {
157296
+ if (ts.isIdentifier(token) && ts.isCallExpression(parent) && parent.expression === token) {
157103
157297
  return { kind: 2 /* Function */, token: token, call: parent, sourceFile: sourceFile, modifierFlags: 0 /* None */, parentDeclaration: sourceFile };
157104
157298
  }
157105
157299
  if (!ts.isPropertyAccessExpression(parent))
@@ -162344,6 +162538,9 @@ var ts;
162344
162538
  if (!containingDecl) {
162345
162539
  return;
162346
162540
  }
162541
+ if (ts.isFunctionLikeDeclaration(containingDecl) && containingDecl.body && ts.rangeContainsPosition(containingDecl.body, startPosition)) {
162542
+ return;
162543
+ }
162347
162544
  var checker = program.getTypeChecker();
162348
162545
  var signatureSymbol = containingDecl.symbol;
162349
162546
  if (!signatureSymbol) {