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.
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220803";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220804";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -21878,7 +21878,7 @@ var ts;
21878
21878
  * Wraps an expression in parentheses if it is needed in order to use the expression for
21879
21879
  * property or element access.
21880
21880
  */
21881
- function parenthesizeLeftSideOfAccess(expression) {
21881
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
21882
21882
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
21883
21883
  // to parenthesize the expression before a dot. The known exception is:
21884
21884
  //
@@ -21887,7 +21887,8 @@ var ts;
21887
21887
  //
21888
21888
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
21889
21889
  if (ts.isLeftHandSideExpression(emittedExpression)
21890
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
21890
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
21891
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
21891
21892
  // TODO(rbuckton): Verify whether this assertion holds.
21892
21893
  return expression;
21893
21894
  }
@@ -23294,7 +23295,7 @@ var ts;
23294
23295
  // @api
23295
23296
  function createDecorator(expression) {
23296
23297
  var node = createBaseNode(165 /* Decorator */);
23297
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23298
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23298
23299
  node.transformFlags |=
23299
23300
  propagateChildFlags(node.expression) |
23300
23301
  1 /* ContainsTypeScript */ |
@@ -24095,7 +24096,7 @@ var ts;
24095
24096
  // @api
24096
24097
  function createPropertyAccessExpression(expression, name) {
24097
24098
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24098
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24099
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24099
24100
  node.name = asName(name);
24100
24101
  node.transformFlags =
24101
24102
  propagateChildFlags(node.expression) |
@@ -24125,7 +24126,7 @@ var ts;
24125
24126
  function createPropertyAccessChain(expression, questionDotToken, name) {
24126
24127
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24127
24128
  node.flags |= 32 /* OptionalChain */;
24128
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24129
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24129
24130
  node.questionDotToken = questionDotToken;
24130
24131
  node.name = asName(name);
24131
24132
  node.transformFlags |=
@@ -24151,7 +24152,7 @@ var ts;
24151
24152
  // @api
24152
24153
  function createElementAccessExpression(expression, index) {
24153
24154
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24154
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24155
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24155
24156
  node.argumentExpression = asExpression(index);
24156
24157
  node.transformFlags |=
24157
24158
  propagateChildFlags(node.expression) |
@@ -24179,7 +24180,7 @@ var ts;
24179
24180
  function createElementAccessChain(expression, questionDotToken, index) {
24180
24181
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24181
24182
  node.flags |= 32 /* OptionalChain */;
24182
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24183
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24183
24184
  node.questionDotToken = questionDotToken;
24184
24185
  node.argumentExpression = asExpression(index);
24185
24186
  node.transformFlags |=
@@ -24203,7 +24204,7 @@ var ts;
24203
24204
  // @api
24204
24205
  function createCallExpression(expression, typeArguments, argumentsArray) {
24205
24206
  var node = createBaseExpression(208 /* CallExpression */);
24206
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24207
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24207
24208
  node.typeArguments = asNodeArray(typeArguments);
24208
24209
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24209
24210
  node.transformFlags |=
@@ -24236,7 +24237,7 @@ var ts;
24236
24237
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24237
24238
  var node = createBaseExpression(208 /* CallExpression */);
24238
24239
  node.flags |= 32 /* OptionalChain */;
24239
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24240
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24240
24241
  node.questionDotToken = questionDotToken;
24241
24242
  node.typeArguments = asNodeArray(typeArguments);
24242
24243
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24291,7 +24292,7 @@ var ts;
24291
24292
  // @api
24292
24293
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24293
24294
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24294
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24295
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24295
24296
  node.typeArguments = asNodeArray(typeArguments);
24296
24297
  node.template = template;
24297
24298
  node.transformFlags |=
@@ -24729,7 +24730,7 @@ var ts;
24729
24730
  // @api
24730
24731
  function createExpressionWithTypeArguments(expression, typeArguments) {
24731
24732
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24732
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24733
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24733
24734
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24734
24735
  node.transformFlags |=
24735
24736
  propagateChildFlags(node.expression) |
@@ -24765,7 +24766,7 @@ var ts;
24765
24766
  // @api
24766
24767
  function createNonNullExpression(expression) {
24767
24768
  var node = createBaseExpression(230 /* NonNullExpression */);
24768
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24769
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24769
24770
  node.transformFlags |=
24770
24771
  propagateChildFlags(node.expression) |
24771
24772
  1 /* ContainsTypeScript */;
@@ -24784,7 +24785,7 @@ var ts;
24784
24785
  function createNonNullChain(expression) {
24785
24786
  var node = createBaseExpression(230 /* NonNullExpression */);
24786
24787
  node.flags |= 32 /* OptionalChain */;
24787
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24788
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24788
24789
  node.transformFlags |=
24789
24790
  propagateChildFlags(node.expression) |
24790
24791
  1 /* ContainsTypeScript */;
@@ -26988,7 +26989,7 @@ var ts;
26988
26989
  }
26989
26990
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
26990
26991
  thisArg = createVoidZero();
26991
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
26992
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
26992
26993
  }
26993
26994
  else if (ts.isPropertyAccessExpression(callee)) {
26994
26995
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -27017,7 +27018,7 @@ var ts;
27017
27018
  else {
27018
27019
  // for `a()` target is `a` and thisArg is `void 0`
27019
27020
  thisArg = createVoidZero();
27020
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27021
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27021
27022
  }
27022
27023
  return { target: target, thisArg: thisArg };
27023
27024
  }
@@ -84009,17 +84010,28 @@ var ts;
84009
84010
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
84010
84011
  */
84011
84012
  function getIterationTypesOfIterable(type, use, errorNode) {
84013
+ var _a, _b;
84012
84014
  if (isTypeAny(type)) {
84013
84015
  return anyIterationTypes;
84014
84016
  }
84015
84017
  if (!(type.flags & 1048576 /* Union */)) {
84016
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84018
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84019
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
84017
84020
  if (iterationTypes_1 === noIterationTypes) {
84018
84021
  if (errorNode) {
84019
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84022
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84023
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84024
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84025
+ }
84020
84026
  }
84021
84027
  return undefined;
84022
84028
  }
84029
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84030
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84031
+ var diag = _c[_i];
84032
+ diagnostics.add(diag);
84033
+ }
84034
+ }
84023
84035
  return iterationTypes_1;
84024
84036
  }
84025
84037
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84027,19 +84039,27 @@ var ts;
84027
84039
  if (cachedTypes)
84028
84040
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84029
84041
  var allIterationTypes;
84030
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84031
- var constituent = _a[_i];
84032
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84042
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84043
+ var constituent = _e[_d];
84044
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84045
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84033
84046
  if (iterationTypes_2 === noIterationTypes) {
84034
84047
  if (errorNode) {
84035
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84048
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84049
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84050
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84051
+ }
84036
84052
  }
84037
84053
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84038
84054
  return undefined;
84039
84055
  }
84040
- else {
84041
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84056
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84057
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84058
+ var diag = _g[_f];
84059
+ diagnostics.add(diag);
84060
+ }
84042
84061
  }
84062
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84043
84063
  }
84044
84064
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84045
84065
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84067,47 +84087,62 @@ var ts;
84067
84087
  * NOTE: You probably don't want to call this directly and should be calling
84068
84088
  * `getIterationTypesOfIterable` instead.
84069
84089
  */
84070
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84090
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84071
84091
  if (isTypeAny(type)) {
84072
84092
  return anyIterationTypes;
84073
84093
  }
84094
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84095
+ // In addition, we should not cache any new results for this call.
84096
+ var noCache = false;
84074
84097
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84075
84098
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84076
84099
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84077
84100
  if (iterationTypes) {
84078
- return use & 8 /* ForOfFlag */ ?
84079
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84080
- iterationTypes;
84101
+ if (iterationTypes === noIterationTypes && errorNode) {
84102
+ // ignore the cached value
84103
+ noCache = true;
84104
+ }
84105
+ else {
84106
+ return use & 8 /* ForOfFlag */ ?
84107
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84108
+ iterationTypes;
84109
+ }
84081
84110
  }
84082
84111
  }
84083
84112
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84084
84113
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84085
84114
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84086
84115
  if (iterationTypes) {
84087
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84088
- // for a sync iterable in an async context, only use the cached types if they are valid.
84089
- if (iterationTypes !== noIterationTypes) {
84090
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84091
- }
84116
+ if (iterationTypes === noIterationTypes && errorNode) {
84117
+ // ignore the cached value
84118
+ noCache = true;
84092
84119
  }
84093
84120
  else {
84094
- return iterationTypes;
84121
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84122
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84123
+ if (iterationTypes !== noIterationTypes) {
84124
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84125
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84126
+ }
84127
+ }
84128
+ else {
84129
+ return iterationTypes;
84130
+ }
84095
84131
  }
84096
84132
  }
84097
84133
  }
84098
84134
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84099
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84135
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84100
84136
  if (iterationTypes !== noIterationTypes) {
84101
84137
  return iterationTypes;
84102
84138
  }
84103
84139
  }
84104
84140
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84105
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84141
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84106
84142
  if (iterationTypes !== noIterationTypes) {
84107
84143
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84108
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84109
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84110
- : noIterationTypes);
84144
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84145
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84111
84146
  }
84112
84147
  else {
84113
84148
  return iterationTypes;
@@ -84128,7 +84163,7 @@ var ts;
84128
84163
  }
84129
84164
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84130
84165
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84131
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84166
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84132
84167
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84133
84168
  }
84134
84169
  /**
@@ -84182,40 +84217,56 @@ var ts;
84182
84217
  * NOTE: You probably don't want to call this directly and should be calling
84183
84218
  * `getIterationTypesOfIterable` instead.
84184
84219
  */
84185
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84220
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84186
84221
  var _a;
84187
84222
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84188
84223
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84189
84224
  if (isTypeAny(methodType)) {
84190
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84225
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84191
84226
  }
84192
84227
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84193
84228
  if (!ts.some(signatures)) {
84194
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84229
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84195
84230
  }
84196
84231
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84197
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84198
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84232
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84233
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84199
84234
  }
84200
84235
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84201
84236
  var message = allowAsyncIterables
84202
84237
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84203
84238
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84204
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84239
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84240
+ }
84241
+ /**
84242
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84243
+ *
84244
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84245
+ * record is returned. Otherwise, `undefined` is returned.
84246
+ */
84247
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84248
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84205
84249
  }
84206
84250
  /**
84207
84251
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84208
84252
  *
84209
84253
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84210
84254
  * record is returned. Otherwise, `undefined` is returned.
84255
+ *
84256
+ * NOTE: You probably don't want to call this directly and should be calling
84257
+ * `getIterationTypesOfIterator` instead.
84211
84258
  */
84212
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84259
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84213
84260
  if (isTypeAny(type)) {
84214
84261
  return anyIterationTypes;
84215
84262
  }
84216
84263
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84217
- getIterationTypesOfIteratorFast(type, resolver) ||
84218
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84264
+ getIterationTypesOfIteratorFast(type, resolver);
84265
+ if (iterationTypes === noIterationTypes && errorNode) {
84266
+ iterationTypes = undefined;
84267
+ noCache = true;
84268
+ }
84269
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84219
84270
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84220
84271
  }
84221
84272
  /**
@@ -84253,7 +84304,7 @@ var ts;
84253
84304
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84254
84305
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84255
84306
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84256
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84307
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84257
84308
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84258
84309
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84259
84310
  }
@@ -84323,8 +84374,8 @@ var ts;
84323
84374
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84324
84375
  * record is returned. Otherwise, we return `undefined`.
84325
84376
  */
84326
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84327
- var _a, _b, _c, _d;
84377
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84378
+ var _a, _b, _c, _d, _e, _f;
84328
84379
  var method = getPropertyOfType(type, methodName);
84329
84380
  // Ignore 'return' or 'throw' if they are missing.
84330
84381
  if (!method && methodName !== "next") {
@@ -84344,9 +84395,15 @@ var ts;
84344
84395
  var diagnostic = methodName === "next"
84345
84396
  ? resolver.mustHaveANextMethodDiagnostic
84346
84397
  : resolver.mustBeAMethodDiagnostic;
84347
- error(errorNode, diagnostic, methodName);
84398
+ if (errorOutputContainer) {
84399
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84400
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84401
+ }
84402
+ else {
84403
+ error(errorNode, diagnostic, methodName);
84404
+ }
84348
84405
  }
84349
- return methodName === "next" ? anyIterationTypes : undefined;
84406
+ return methodName === "next" ? noIterationTypes : undefined;
84350
84407
  }
84351
84408
  // If the method signature comes exclusively from the global iterator or generator type,
84352
84409
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84358,8 +84415,8 @@ var ts;
84358
84415
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84359
84416
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84360
84417
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84361
- 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;
84362
- 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;
84418
+ 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;
84419
+ 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;
84363
84420
  if (isGeneratorMethod || isIteratorMethod) {
84364
84421
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84365
84422
  var mapper = methodType.mapper;
@@ -84399,7 +84456,13 @@ var ts;
84399
84456
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84400
84457
  if (iterationTypes === noIterationTypes) {
84401
84458
  if (errorNode) {
84402
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84459
+ if (errorOutputContainer) {
84460
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84461
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84462
+ }
84463
+ else {
84464
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84465
+ }
84403
84466
  }
84404
84467
  yieldType = anyType;
84405
84468
  returnTypes = ts.append(returnTypes, anyType);
@@ -84420,13 +84483,13 @@ var ts;
84420
84483
  * NOTE: You probably don't want to call this directly and should be calling
84421
84484
  * `getIterationTypesOfIterator` instead.
84422
84485
  */
84423
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84486
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84424
84487
  var iterationTypes = combineIterationTypes([
84425
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84426
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84427
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84488
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84489
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84490
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84428
84491
  ]);
84429
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84492
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84430
84493
  }
84431
84494
  /**
84432
84495
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84447,7 +84510,7 @@ var ts;
84447
84510
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84448
84511
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84449
84512
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84450
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84513
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84451
84514
  }
84452
84515
  function checkBreakOrContinueStatement(node) {
84453
84516
  // Grammar checking
@@ -122744,8 +122807,6 @@ var ts;
122744
122807
  if (watcher.files === 0 && watcher.resolutions === 0) {
122745
122808
  fileWatchesOfAffectingLocations.delete(path);
122746
122809
  watcher.watcher.close();
122747
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122748
- watcher.watcher = ts.noopFileWatcher;
122749
122810
  }
122750
122811
  });
122751
122812
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123091,20 +123152,27 @@ var ts;
123091
123152
  }
123092
123153
  var paths = new ts.Set();
123093
123154
  paths.add(locationToWatch);
123155
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123156
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123157
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123158
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123159
+ paths.forEach(function (path) {
123160
+ if (watcher.resolutions)
123161
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123162
+ if (watcher.files)
123163
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123164
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123165
+ });
123166
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123167
+ }) : ts.noopFileWatcher;
123094
123168
  var watcher = {
123095
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123096
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123097
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123098
- paths.forEach(function (path) {
123099
- var _a;
123100
- if (watcher.resolutions)
123101
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123102
- if (watcher.files)
123103
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123104
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123105
- });
123106
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123107
- }) : ts.noopFileWatcher,
123169
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123170
+ close: function () {
123171
+ actualWatcher.close();
123172
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123173
+ actualWatcher = ts.noopFileWatcher;
123174
+ }
123175
+ } : actualWatcher,
123108
123176
  resolutions: forResolution ? 1 : 0,
123109
123177
  files: forResolution ? 0 : 1,
123110
123178
  paths: paths,
@@ -123518,7 +123586,7 @@ var ts;
123518
123586
  var info = getInfo(importingSourceFileName, host);
123519
123587
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123520
123588
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123521
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123589
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123522
123590
  }
123523
123591
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123524
123592
  if (options === void 0) { options = {}; }
@@ -123601,7 +123669,7 @@ var ts;
123601
123669
  return nodeModulesSpecifiers;
123602
123670
  }
123603
123671
  if (!specifier && !modulePath.isRedirect) {
123604
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123672
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123605
123673
  if (ts.pathIsBareSpecifier(local)) {
123606
123674
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123607
123675
  }
@@ -123629,7 +123697,7 @@ var ts;
123629
123697
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123630
123698
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123631
123699
  }
123632
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123700
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123633
123701
  var ending = _a.ending, relativePreference = _a.relativePreference;
123634
123702
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123635
123703
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123643,9 +123711,8 @@ var ts;
123643
123711
  if (!relativeToBaseUrl) {
123644
123712
  return relativePath;
123645
123713
  }
123646
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123647
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123648
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123714
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123715
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123649
123716
  if (!nonRelative) {
123650
123717
  return relativePath;
123651
123718
  }
@@ -123880,28 +123947,102 @@ var ts;
123880
123947
  return ambientModuleDeclare.name.text;
123881
123948
  }
123882
123949
  }
123883
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
123950
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
123951
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
123952
+ return [2 /* JsExtension */];
123953
+ }
123954
+ switch (preferredEnding) {
123955
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
123956
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
123957
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
123958
+ default: ts.Debug.assertNever(preferredEnding);
123959
+ }
123960
+ }
123961
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
123884
123962
  for (var key in paths) {
123885
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
123886
- var patternText_1 = _a[_i];
123887
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
123963
+ var _loop_36 = function (patternText_1) {
123964
+ var pattern = ts.normalizePath(patternText_1);
123888
123965
  var indexOfStar = pattern.indexOf("*");
123966
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
123967
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
123968
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
123969
+ // and matches the '*'. For example:
123970
+ //
123971
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
123972
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
123973
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
123974
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
123975
+ //
123976
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
123977
+ //
123978
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
123979
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
123980
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
123981
+ // extension for a module specifier.)
123982
+ //
123983
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
123984
+ // .ts extension) or the possible relative module specifiers representing that file:
123985
+ //
123986
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
123987
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
123988
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
123989
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
123990
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
123991
+ // 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
123992
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
123993
+ //
123994
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
123995
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
123996
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
123997
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
123998
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
123999
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
124000
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
124001
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
124002
+ var candidates = allowedEndings.map(function (ending) { return ({
124003
+ ending: ending,
124004
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
124005
+ }); });
124006
+ if (ts.tryGetExtensionFromPath(pattern)) {
124007
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
124008
+ }
123889
124009
  if (indexOfStar !== -1) {
123890
- var prefix = pattern.substr(0, indexOfStar);
123891
- var suffix = pattern.substr(indexOfStar + 1);
123892
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
123893
- ts.startsWith(relativeToBaseUrl, prefix) &&
123894
- ts.endsWith(relativeToBaseUrl, suffix) ||
123895
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
123896
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
123897
- return key.replace("*", matchedStar);
124010
+ var prefix = pattern.substring(0, indexOfStar);
124011
+ var suffix = pattern.substring(indexOfStar + 1);
124012
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
124013
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
124014
+ if (value.length >= prefix.length + suffix.length &&
124015
+ ts.startsWith(value, prefix) &&
124016
+ ts.endsWith(value, suffix) &&
124017
+ validateEnding({ ending: ending, value: value })) {
124018
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
124019
+ return { value: key.replace("*", matchedStar) };
124020
+ }
123898
124021
  }
123899
124022
  }
123900
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
123901
- return key;
124023
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124024
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124025
+ return { value: key };
123902
124026
  }
124027
+ };
124028
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124029
+ var patternText_1 = _a[_i];
124030
+ var state_12 = _loop_36(patternText_1);
124031
+ if (typeof state_12 === "object")
124032
+ return state_12.value;
123903
124033
  }
123904
124034
  }
124035
+ function validateEnding(_a) {
124036
+ var ending = _a.ending, value = _a.value;
124037
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124038
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124039
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124040
+ // 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
124041
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124042
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124043
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124044
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124045
+ }
123905
124046
  }
123906
124047
  var MatchingMode;
123907
124048
  (function (MatchingMode) {
@@ -123997,10 +124138,10 @@ var ts;
123997
124138
  return undefined;
123998
124139
  }
123999
124140
  // Simplify the full file path to something that can be resolved by Node.
124141
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124000
124142
  var moduleSpecifier = path;
124001
124143
  var isPackageRootPath = false;
124002
124144
  if (!packageNameOnly) {
124003
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124004
124145
  var packageRootIndex = parts.packageRootIndex;
124005
124146
  var moduleFileName = void 0;
124006
124147
  while (true) {
@@ -124049,15 +124190,13 @@ var ts;
124049
124190
  var packageRootPath = path.substring(0, packageRootIndex);
124050
124191
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124051
124192
  var moduleFileToTry = path;
124193
+ var maybeBlockedByTypesVersions = false;
124052
124194
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124053
124195
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124054
124196
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124197
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124055
124198
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124056
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124057
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124058
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124059
- // with, so for now we just stick with the mode of the file.
124060
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124199
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124061
124200
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124062
124201
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124063
124202
  : undefined;
@@ -124076,16 +124215,26 @@ var ts;
124076
124215
  : undefined;
124077
124216
  if (versionPaths) {
124078
124217
  var subModuleName = path.slice(packageRootPath.length + 1);
124079
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124080
- if (fromPaths !== undefined) {
124218
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124219
+ if (fromPaths === undefined) {
124220
+ maybeBlockedByTypesVersions = true;
124221
+ }
124222
+ else {
124081
124223
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124082
124224
  }
124083
124225
  }
124084
124226
  // If the file is the main module, it can be imported by the package name
124085
124227
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124086
- if (ts.isString(mainFileRelative)) {
124228
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124229
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124230
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124231
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124232
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124233
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124234
+ // importNameCodeFix_typesVersions.ts for an example.)
124087
124235
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124088
124236
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124237
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124089
124238
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124090
124239
  }
124091
124240
  }
@@ -161731,6 +161880,9 @@ var ts;
161731
161880
  if (!containingDecl) {
161732
161881
  return;
161733
161882
  }
161883
+ if (ts.isFunctionLikeDeclaration(containingDecl) && containingDecl.body && ts.rangeContainsPosition(containingDecl.body, startPosition)) {
161884
+ return;
161885
+ }
161734
161886
  var checker = program.getTypeChecker();
161735
161887
  var signatureSymbol = containingDecl.symbol;
161736
161888
  if (!signatureSymbol) {