typescript 4.8.0-dev.20220803 → 4.8.0-dev.20220804

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220803";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220804";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -21858,7 +21858,7 @@ var ts;
21858
21858
  * Wraps an expression in parentheses if it is needed in order to use the expression for
21859
21859
  * property or element access.
21860
21860
  */
21861
- function parenthesizeLeftSideOfAccess(expression) {
21861
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
21862
21862
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
21863
21863
  // to parenthesize the expression before a dot. The known exception is:
21864
21864
  //
@@ -21867,7 +21867,8 @@ var ts;
21867
21867
  //
21868
21868
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
21869
21869
  if (ts.isLeftHandSideExpression(emittedExpression)
21870
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
21870
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
21871
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
21871
21872
  // TODO(rbuckton): Verify whether this assertion holds.
21872
21873
  return expression;
21873
21874
  }
@@ -23274,7 +23275,7 @@ var ts;
23274
23275
  // @api
23275
23276
  function createDecorator(expression) {
23276
23277
  var node = createBaseNode(165 /* Decorator */);
23277
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23278
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23278
23279
  node.transformFlags |=
23279
23280
  propagateChildFlags(node.expression) |
23280
23281
  1 /* ContainsTypeScript */ |
@@ -24075,7 +24076,7 @@ var ts;
24075
24076
  // @api
24076
24077
  function createPropertyAccessExpression(expression, name) {
24077
24078
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24078
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24079
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24079
24080
  node.name = asName(name);
24080
24081
  node.transformFlags =
24081
24082
  propagateChildFlags(node.expression) |
@@ -24105,7 +24106,7 @@ var ts;
24105
24106
  function createPropertyAccessChain(expression, questionDotToken, name) {
24106
24107
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24107
24108
  node.flags |= 32 /* OptionalChain */;
24108
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24109
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24109
24110
  node.questionDotToken = questionDotToken;
24110
24111
  node.name = asName(name);
24111
24112
  node.transformFlags |=
@@ -24131,7 +24132,7 @@ var ts;
24131
24132
  // @api
24132
24133
  function createElementAccessExpression(expression, index) {
24133
24134
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24134
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24135
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24135
24136
  node.argumentExpression = asExpression(index);
24136
24137
  node.transformFlags |=
24137
24138
  propagateChildFlags(node.expression) |
@@ -24159,7 +24160,7 @@ var ts;
24159
24160
  function createElementAccessChain(expression, questionDotToken, index) {
24160
24161
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24161
24162
  node.flags |= 32 /* OptionalChain */;
24162
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24163
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24163
24164
  node.questionDotToken = questionDotToken;
24164
24165
  node.argumentExpression = asExpression(index);
24165
24166
  node.transformFlags |=
@@ -24183,7 +24184,7 @@ var ts;
24183
24184
  // @api
24184
24185
  function createCallExpression(expression, typeArguments, argumentsArray) {
24185
24186
  var node = createBaseExpression(208 /* CallExpression */);
24186
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24187
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24187
24188
  node.typeArguments = asNodeArray(typeArguments);
24188
24189
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24189
24190
  node.transformFlags |=
@@ -24216,7 +24217,7 @@ var ts;
24216
24217
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24217
24218
  var node = createBaseExpression(208 /* CallExpression */);
24218
24219
  node.flags |= 32 /* OptionalChain */;
24219
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24220
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24220
24221
  node.questionDotToken = questionDotToken;
24221
24222
  node.typeArguments = asNodeArray(typeArguments);
24222
24223
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24271,7 +24272,7 @@ var ts;
24271
24272
  // @api
24272
24273
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24273
24274
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24274
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24275
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24275
24276
  node.typeArguments = asNodeArray(typeArguments);
24276
24277
  node.template = template;
24277
24278
  node.transformFlags |=
@@ -24709,7 +24710,7 @@ var ts;
24709
24710
  // @api
24710
24711
  function createExpressionWithTypeArguments(expression, typeArguments) {
24711
24712
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24712
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24713
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24713
24714
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24714
24715
  node.transformFlags |=
24715
24716
  propagateChildFlags(node.expression) |
@@ -24745,7 +24746,7 @@ var ts;
24745
24746
  // @api
24746
24747
  function createNonNullExpression(expression) {
24747
24748
  var node = createBaseExpression(230 /* NonNullExpression */);
24748
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24749
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24749
24750
  node.transformFlags |=
24750
24751
  propagateChildFlags(node.expression) |
24751
24752
  1 /* ContainsTypeScript */;
@@ -24764,7 +24765,7 @@ var ts;
24764
24765
  function createNonNullChain(expression) {
24765
24766
  var node = createBaseExpression(230 /* NonNullExpression */);
24766
24767
  node.flags |= 32 /* OptionalChain */;
24767
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24768
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24768
24769
  node.transformFlags |=
24769
24770
  propagateChildFlags(node.expression) |
24770
24771
  1 /* ContainsTypeScript */;
@@ -26968,7 +26969,7 @@ var ts;
26968
26969
  }
26969
26970
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
26970
26971
  thisArg = createVoidZero();
26971
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
26972
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
26972
26973
  }
26973
26974
  else if (ts.isPropertyAccessExpression(callee)) {
26974
26975
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -26997,7 +26998,7 @@ var ts;
26997
26998
  else {
26998
26999
  // for `a()` target is `a` and thisArg is `void 0`
26999
27000
  thisArg = createVoidZero();
27000
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27001
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27001
27002
  }
27002
27003
  return { target: target, thisArg: thisArg };
27003
27004
  }
@@ -83989,17 +83990,28 @@ var ts;
83989
83990
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
83990
83991
  */
83991
83992
  function getIterationTypesOfIterable(type, use, errorNode) {
83993
+ var _a, _b;
83992
83994
  if (isTypeAny(type)) {
83993
83995
  return anyIterationTypes;
83994
83996
  }
83995
83997
  if (!(type.flags & 1048576 /* Union */)) {
83996
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
83998
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
83999
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
83997
84000
  if (iterationTypes_1 === noIterationTypes) {
83998
84001
  if (errorNode) {
83999
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84002
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84003
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84004
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84005
+ }
84000
84006
  }
84001
84007
  return undefined;
84002
84008
  }
84009
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84010
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84011
+ var diag = _c[_i];
84012
+ diagnostics.add(diag);
84013
+ }
84014
+ }
84003
84015
  return iterationTypes_1;
84004
84016
  }
84005
84017
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84007,19 +84019,27 @@ var ts;
84007
84019
  if (cachedTypes)
84008
84020
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84009
84021
  var allIterationTypes;
84010
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84011
- var constituent = _a[_i];
84012
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84022
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84023
+ var constituent = _e[_d];
84024
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84025
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84013
84026
  if (iterationTypes_2 === noIterationTypes) {
84014
84027
  if (errorNode) {
84015
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84028
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84029
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84030
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84031
+ }
84016
84032
  }
84017
84033
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84018
84034
  return undefined;
84019
84035
  }
84020
- else {
84021
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84036
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84037
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84038
+ var diag = _g[_f];
84039
+ diagnostics.add(diag);
84040
+ }
84022
84041
  }
84042
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84023
84043
  }
84024
84044
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84025
84045
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84047,47 +84067,62 @@ var ts;
84047
84067
  * NOTE: You probably don't want to call this directly and should be calling
84048
84068
  * `getIterationTypesOfIterable` instead.
84049
84069
  */
84050
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84070
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84051
84071
  if (isTypeAny(type)) {
84052
84072
  return anyIterationTypes;
84053
84073
  }
84074
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84075
+ // In addition, we should not cache any new results for this call.
84076
+ var noCache = false;
84054
84077
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84055
84078
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84056
84079
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84057
84080
  if (iterationTypes) {
84058
- return use & 8 /* ForOfFlag */ ?
84059
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84060
- iterationTypes;
84081
+ if (iterationTypes === noIterationTypes && errorNode) {
84082
+ // ignore the cached value
84083
+ noCache = true;
84084
+ }
84085
+ else {
84086
+ return use & 8 /* ForOfFlag */ ?
84087
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84088
+ iterationTypes;
84089
+ }
84061
84090
  }
84062
84091
  }
84063
84092
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84064
84093
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84065
84094
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84066
84095
  if (iterationTypes) {
84067
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84068
- // for a sync iterable in an async context, only use the cached types if they are valid.
84069
- if (iterationTypes !== noIterationTypes) {
84070
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84071
- }
84096
+ if (iterationTypes === noIterationTypes && errorNode) {
84097
+ // ignore the cached value
84098
+ noCache = true;
84072
84099
  }
84073
84100
  else {
84074
- return iterationTypes;
84101
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84102
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84103
+ if (iterationTypes !== noIterationTypes) {
84104
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84105
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84106
+ }
84107
+ }
84108
+ else {
84109
+ return iterationTypes;
84110
+ }
84075
84111
  }
84076
84112
  }
84077
84113
  }
84078
84114
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84079
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84115
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84080
84116
  if (iterationTypes !== noIterationTypes) {
84081
84117
  return iterationTypes;
84082
84118
  }
84083
84119
  }
84084
84120
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84085
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84121
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84086
84122
  if (iterationTypes !== noIterationTypes) {
84087
84123
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84088
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84089
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84090
- : noIterationTypes);
84124
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84125
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84091
84126
  }
84092
84127
  else {
84093
84128
  return iterationTypes;
@@ -84108,7 +84143,7 @@ var ts;
84108
84143
  }
84109
84144
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84110
84145
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84111
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84146
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84112
84147
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84113
84148
  }
84114
84149
  /**
@@ -84162,26 +84197,26 @@ var ts;
84162
84197
  * NOTE: You probably don't want to call this directly and should be calling
84163
84198
  * `getIterationTypesOfIterable` instead.
84164
84199
  */
84165
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84200
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84166
84201
  var _a;
84167
84202
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84168
84203
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84169
84204
  if (isTypeAny(methodType)) {
84170
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84205
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84171
84206
  }
84172
84207
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84173
84208
  if (!ts.some(signatures)) {
84174
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84209
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84175
84210
  }
84176
84211
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84177
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84178
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84212
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84213
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84179
84214
  }
84180
84215
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84181
84216
  var message = allowAsyncIterables
84182
84217
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84183
84218
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84184
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84219
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84185
84220
  }
84186
84221
  /**
84187
84222
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -84189,13 +84224,29 @@ var ts;
84189
84224
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84190
84225
  * record is returned. Otherwise, `undefined` is returned.
84191
84226
  */
84192
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84227
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84228
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84229
+ }
84230
+ /**
84231
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84232
+ *
84233
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84234
+ * record is returned. Otherwise, `undefined` is returned.
84235
+ *
84236
+ * NOTE: You probably don't want to call this directly and should be calling
84237
+ * `getIterationTypesOfIterator` instead.
84238
+ */
84239
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84193
84240
  if (isTypeAny(type)) {
84194
84241
  return anyIterationTypes;
84195
84242
  }
84196
84243
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84197
- getIterationTypesOfIteratorFast(type, resolver) ||
84198
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84244
+ getIterationTypesOfIteratorFast(type, resolver);
84245
+ if (iterationTypes === noIterationTypes && errorNode) {
84246
+ iterationTypes = undefined;
84247
+ noCache = true;
84248
+ }
84249
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84199
84250
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84200
84251
  }
84201
84252
  /**
@@ -84233,7 +84284,7 @@ var ts;
84233
84284
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84234
84285
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84235
84286
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84236
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84287
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84237
84288
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84238
84289
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84239
84290
  }
@@ -84303,8 +84354,8 @@ var ts;
84303
84354
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84304
84355
  * record is returned. Otherwise, we return `undefined`.
84305
84356
  */
84306
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84307
- var _a, _b, _c, _d;
84357
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84358
+ var _a, _b, _c, _d, _e, _f;
84308
84359
  var method = getPropertyOfType(type, methodName);
84309
84360
  // Ignore 'return' or 'throw' if they are missing.
84310
84361
  if (!method && methodName !== "next") {
@@ -84324,9 +84375,15 @@ var ts;
84324
84375
  var diagnostic = methodName === "next"
84325
84376
  ? resolver.mustHaveANextMethodDiagnostic
84326
84377
  : resolver.mustBeAMethodDiagnostic;
84327
- error(errorNode, diagnostic, methodName);
84378
+ if (errorOutputContainer) {
84379
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84380
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84381
+ }
84382
+ else {
84383
+ error(errorNode, diagnostic, methodName);
84384
+ }
84328
84385
  }
84329
- return methodName === "next" ? anyIterationTypes : undefined;
84386
+ return methodName === "next" ? noIterationTypes : undefined;
84330
84387
  }
84331
84388
  // If the method signature comes exclusively from the global iterator or generator type,
84332
84389
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84338,8 +84395,8 @@ var ts;
84338
84395
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84339
84396
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84340
84397
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84341
- 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;
84342
- 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;
84398
+ 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;
84399
+ 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;
84343
84400
  if (isGeneratorMethod || isIteratorMethod) {
84344
84401
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84345
84402
  var mapper = methodType.mapper;
@@ -84379,7 +84436,13 @@ var ts;
84379
84436
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84380
84437
  if (iterationTypes === noIterationTypes) {
84381
84438
  if (errorNode) {
84382
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84439
+ if (errorOutputContainer) {
84440
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84441
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84442
+ }
84443
+ else {
84444
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84445
+ }
84383
84446
  }
84384
84447
  yieldType = anyType;
84385
84448
  returnTypes = ts.append(returnTypes, anyType);
@@ -84400,13 +84463,13 @@ var ts;
84400
84463
  * NOTE: You probably don't want to call this directly and should be calling
84401
84464
  * `getIterationTypesOfIterator` instead.
84402
84465
  */
84403
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84466
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84404
84467
  var iterationTypes = combineIterationTypes([
84405
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84406
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84407
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84468
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84469
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84470
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84408
84471
  ]);
84409
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84472
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84410
84473
  }
84411
84474
  /**
84412
84475
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84427,7 +84490,7 @@ var ts;
84427
84490
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84428
84491
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84429
84492
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84430
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84493
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84431
84494
  }
84432
84495
  function checkBreakOrContinueStatement(node) {
84433
84496
  // Grammar checking
@@ -122724,8 +122787,6 @@ var ts;
122724
122787
  if (watcher.files === 0 && watcher.resolutions === 0) {
122725
122788
  fileWatchesOfAffectingLocations.delete(path);
122726
122789
  watcher.watcher.close();
122727
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122728
- watcher.watcher = ts.noopFileWatcher;
122729
122790
  }
122730
122791
  });
122731
122792
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123071,20 +123132,27 @@ var ts;
123071
123132
  }
123072
123133
  var paths = new ts.Set();
123073
123134
  paths.add(locationToWatch);
123135
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123136
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123137
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123138
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123139
+ paths.forEach(function (path) {
123140
+ if (watcher.resolutions)
123141
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123142
+ if (watcher.files)
123143
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123144
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123145
+ });
123146
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123147
+ }) : ts.noopFileWatcher;
123074
123148
  var watcher = {
123075
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123076
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123077
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123078
- paths.forEach(function (path) {
123079
- var _a;
123080
- if (watcher.resolutions)
123081
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123082
- if (watcher.files)
123083
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123084
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123085
- });
123086
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123087
- }) : ts.noopFileWatcher,
123149
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123150
+ close: function () {
123151
+ actualWatcher.close();
123152
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123153
+ actualWatcher = ts.noopFileWatcher;
123154
+ }
123155
+ } : actualWatcher,
123088
123156
  resolutions: forResolution ? 1 : 0,
123089
123157
  files: forResolution ? 0 : 1,
123090
123158
  paths: paths,
@@ -123498,7 +123566,7 @@ var ts;
123498
123566
  var info = getInfo(importingSourceFileName, host);
123499
123567
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123500
123568
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123501
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123569
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123502
123570
  }
123503
123571
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123504
123572
  if (options === void 0) { options = {}; }
@@ -123581,7 +123649,7 @@ var ts;
123581
123649
  return nodeModulesSpecifiers;
123582
123650
  }
123583
123651
  if (!specifier && !modulePath.isRedirect) {
123584
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123652
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123585
123653
  if (ts.pathIsBareSpecifier(local)) {
123586
123654
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123587
123655
  }
@@ -123609,7 +123677,7 @@ var ts;
123609
123677
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123610
123678
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123611
123679
  }
123612
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123680
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123613
123681
  var ending = _a.ending, relativePreference = _a.relativePreference;
123614
123682
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123615
123683
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123623,9 +123691,8 @@ var ts;
123623
123691
  if (!relativeToBaseUrl) {
123624
123692
  return relativePath;
123625
123693
  }
123626
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123627
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123628
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123694
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123695
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123629
123696
  if (!nonRelative) {
123630
123697
  return relativePath;
123631
123698
  }
@@ -123860,28 +123927,102 @@ var ts;
123860
123927
  return ambientModuleDeclare.name.text;
123861
123928
  }
123862
123929
  }
123863
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
123930
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
123931
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
123932
+ return [2 /* JsExtension */];
123933
+ }
123934
+ switch (preferredEnding) {
123935
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
123936
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
123937
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
123938
+ default: ts.Debug.assertNever(preferredEnding);
123939
+ }
123940
+ }
123941
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
123864
123942
  for (var key in paths) {
123865
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
123866
- var patternText_1 = _a[_i];
123867
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
123943
+ var _loop_36 = function (patternText_1) {
123944
+ var pattern = ts.normalizePath(patternText_1);
123868
123945
  var indexOfStar = pattern.indexOf("*");
123946
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
123947
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
123948
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
123949
+ // and matches the '*'. For example:
123950
+ //
123951
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
123952
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
123953
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
123954
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
123955
+ //
123956
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
123957
+ //
123958
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
123959
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
123960
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
123961
+ // extension for a module specifier.)
123962
+ //
123963
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
123964
+ // .ts extension) or the possible relative module specifiers representing that file:
123965
+ //
123966
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
123967
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
123968
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
123969
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
123970
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
123971
+ // 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
123972
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
123973
+ //
123974
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
123975
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
123976
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
123977
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
123978
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
123979
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
123980
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
123981
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
123982
+ var candidates = allowedEndings.map(function (ending) { return ({
123983
+ ending: ending,
123984
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
123985
+ }); });
123986
+ if (ts.tryGetExtensionFromPath(pattern)) {
123987
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
123988
+ }
123869
123989
  if (indexOfStar !== -1) {
123870
- var prefix = pattern.substr(0, indexOfStar);
123871
- var suffix = pattern.substr(indexOfStar + 1);
123872
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
123873
- ts.startsWith(relativeToBaseUrl, prefix) &&
123874
- ts.endsWith(relativeToBaseUrl, suffix) ||
123875
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
123876
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
123877
- return key.replace("*", matchedStar);
123990
+ var prefix = pattern.substring(0, indexOfStar);
123991
+ var suffix = pattern.substring(indexOfStar + 1);
123992
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
123993
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
123994
+ if (value.length >= prefix.length + suffix.length &&
123995
+ ts.startsWith(value, prefix) &&
123996
+ ts.endsWith(value, suffix) &&
123997
+ validateEnding({ ending: ending, value: value })) {
123998
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
123999
+ return { value: key.replace("*", matchedStar) };
124000
+ }
123878
124001
  }
123879
124002
  }
123880
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
123881
- return key;
124003
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124004
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124005
+ return { value: key };
123882
124006
  }
124007
+ };
124008
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124009
+ var patternText_1 = _a[_i];
124010
+ var state_12 = _loop_36(patternText_1);
124011
+ if (typeof state_12 === "object")
124012
+ return state_12.value;
123883
124013
  }
123884
124014
  }
124015
+ function validateEnding(_a) {
124016
+ var ending = _a.ending, value = _a.value;
124017
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124018
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124019
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124020
+ // 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
124021
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124022
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124023
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124024
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124025
+ }
123885
124026
  }
123886
124027
  var MatchingMode;
123887
124028
  (function (MatchingMode) {
@@ -123977,10 +124118,10 @@ var ts;
123977
124118
  return undefined;
123978
124119
  }
123979
124120
  // Simplify the full file path to something that can be resolved by Node.
124121
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
123980
124122
  var moduleSpecifier = path;
123981
124123
  var isPackageRootPath = false;
123982
124124
  if (!packageNameOnly) {
123983
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
123984
124125
  var packageRootIndex = parts.packageRootIndex;
123985
124126
  var moduleFileName = void 0;
123986
124127
  while (true) {
@@ -124029,15 +124170,13 @@ var ts;
124029
124170
  var packageRootPath = path.substring(0, packageRootIndex);
124030
124171
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124031
124172
  var moduleFileToTry = path;
124173
+ var maybeBlockedByTypesVersions = false;
124032
124174
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124033
124175
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124034
124176
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124177
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124035
124178
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124036
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124037
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124038
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124039
- // with, so for now we just stick with the mode of the file.
124040
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124179
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124041
124180
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124042
124181
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124043
124182
  : undefined;
@@ -124056,16 +124195,26 @@ var ts;
124056
124195
  : undefined;
124057
124196
  if (versionPaths) {
124058
124197
  var subModuleName = path.slice(packageRootPath.length + 1);
124059
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124060
- if (fromPaths !== undefined) {
124198
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124199
+ if (fromPaths === undefined) {
124200
+ maybeBlockedByTypesVersions = true;
124201
+ }
124202
+ else {
124061
124203
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124062
124204
  }
124063
124205
  }
124064
124206
  // If the file is the main module, it can be imported by the package name
124065
124207
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124066
- if (ts.isString(mainFileRelative)) {
124208
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124209
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124210
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124211
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124212
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124213
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124214
+ // importNameCodeFix_typesVersions.ts for an example.)
124067
124215
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124068
124216
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124217
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124069
124218
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124070
124219
  }
124071
124220
  }