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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220803";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220804";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -22072,7 +22072,7 @@ var ts;
22072
22072
  * Wraps an expression in parentheses if it is needed in order to use the expression for
22073
22073
  * property or element access.
22074
22074
  */
22075
- function parenthesizeLeftSideOfAccess(expression) {
22075
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
22076
22076
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
22077
22077
  // to parenthesize the expression before a dot. The known exception is:
22078
22078
  //
@@ -22081,7 +22081,8 @@ var ts;
22081
22081
  //
22082
22082
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
22083
22083
  if (ts.isLeftHandSideExpression(emittedExpression)
22084
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
22084
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
22085
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
22085
22086
  // TODO(rbuckton): Verify whether this assertion holds.
22086
22087
  return expression;
22087
22088
  }
@@ -23488,7 +23489,7 @@ var ts;
23488
23489
  // @api
23489
23490
  function createDecorator(expression) {
23490
23491
  var node = createBaseNode(165 /* Decorator */);
23491
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23492
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23492
23493
  node.transformFlags |=
23493
23494
  propagateChildFlags(node.expression) |
23494
23495
  1 /* ContainsTypeScript */ |
@@ -24289,7 +24290,7 @@ var ts;
24289
24290
  // @api
24290
24291
  function createPropertyAccessExpression(expression, name) {
24291
24292
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24292
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24293
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24293
24294
  node.name = asName(name);
24294
24295
  node.transformFlags =
24295
24296
  propagateChildFlags(node.expression) |
@@ -24319,7 +24320,7 @@ var ts;
24319
24320
  function createPropertyAccessChain(expression, questionDotToken, name) {
24320
24321
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24321
24322
  node.flags |= 32 /* OptionalChain */;
24322
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24323
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24323
24324
  node.questionDotToken = questionDotToken;
24324
24325
  node.name = asName(name);
24325
24326
  node.transformFlags |=
@@ -24345,7 +24346,7 @@ var ts;
24345
24346
  // @api
24346
24347
  function createElementAccessExpression(expression, index) {
24347
24348
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24348
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24349
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24349
24350
  node.argumentExpression = asExpression(index);
24350
24351
  node.transformFlags |=
24351
24352
  propagateChildFlags(node.expression) |
@@ -24373,7 +24374,7 @@ var ts;
24373
24374
  function createElementAccessChain(expression, questionDotToken, index) {
24374
24375
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24375
24376
  node.flags |= 32 /* OptionalChain */;
24376
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24377
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24377
24378
  node.questionDotToken = questionDotToken;
24378
24379
  node.argumentExpression = asExpression(index);
24379
24380
  node.transformFlags |=
@@ -24397,7 +24398,7 @@ var ts;
24397
24398
  // @api
24398
24399
  function createCallExpression(expression, typeArguments, argumentsArray) {
24399
24400
  var node = createBaseExpression(208 /* CallExpression */);
24400
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24401
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24401
24402
  node.typeArguments = asNodeArray(typeArguments);
24402
24403
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24403
24404
  node.transformFlags |=
@@ -24430,7 +24431,7 @@ var ts;
24430
24431
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24431
24432
  var node = createBaseExpression(208 /* CallExpression */);
24432
24433
  node.flags |= 32 /* OptionalChain */;
24433
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24434
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24434
24435
  node.questionDotToken = questionDotToken;
24435
24436
  node.typeArguments = asNodeArray(typeArguments);
24436
24437
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24485,7 +24486,7 @@ var ts;
24485
24486
  // @api
24486
24487
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24487
24488
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24488
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24489
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24489
24490
  node.typeArguments = asNodeArray(typeArguments);
24490
24491
  node.template = template;
24491
24492
  node.transformFlags |=
@@ -24923,7 +24924,7 @@ var ts;
24923
24924
  // @api
24924
24925
  function createExpressionWithTypeArguments(expression, typeArguments) {
24925
24926
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24926
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24927
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24927
24928
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24928
24929
  node.transformFlags |=
24929
24930
  propagateChildFlags(node.expression) |
@@ -24959,7 +24960,7 @@ var ts;
24959
24960
  // @api
24960
24961
  function createNonNullExpression(expression) {
24961
24962
  var node = createBaseExpression(230 /* NonNullExpression */);
24962
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24963
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24963
24964
  node.transformFlags |=
24964
24965
  propagateChildFlags(node.expression) |
24965
24966
  1 /* ContainsTypeScript */;
@@ -24978,7 +24979,7 @@ var ts;
24978
24979
  function createNonNullChain(expression) {
24979
24980
  var node = createBaseExpression(230 /* NonNullExpression */);
24980
24981
  node.flags |= 32 /* OptionalChain */;
24981
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24982
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24982
24983
  node.transformFlags |=
24983
24984
  propagateChildFlags(node.expression) |
24984
24985
  1 /* ContainsTypeScript */;
@@ -27182,7 +27183,7 @@ var ts;
27182
27183
  }
27183
27184
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
27184
27185
  thisArg = createVoidZero();
27185
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
27186
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
27186
27187
  }
27187
27188
  else if (ts.isPropertyAccessExpression(callee)) {
27188
27189
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -27211,7 +27212,7 @@ var ts;
27211
27212
  else {
27212
27213
  // for `a()` target is `a` and thisArg is `void 0`
27213
27214
  thisArg = createVoidZero();
27214
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27215
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27215
27216
  }
27216
27217
  return { target: target, thisArg: thisArg };
27217
27218
  }
@@ -84203,17 +84204,28 @@ var ts;
84203
84204
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
84204
84205
  */
84205
84206
  function getIterationTypesOfIterable(type, use, errorNode) {
84207
+ var _a, _b;
84206
84208
  if (isTypeAny(type)) {
84207
84209
  return anyIterationTypes;
84208
84210
  }
84209
84211
  if (!(type.flags & 1048576 /* Union */)) {
84210
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84212
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84213
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
84211
84214
  if (iterationTypes_1 === noIterationTypes) {
84212
84215
  if (errorNode) {
84213
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84216
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84217
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84218
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84219
+ }
84214
84220
  }
84215
84221
  return undefined;
84216
84222
  }
84223
+ else if ((_a = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _a === void 0 ? void 0 : _a.length) {
84224
+ for (var _i = 0, _c = errorOutputContainer.errors; _i < _c.length; _i++) {
84225
+ var diag = _c[_i];
84226
+ diagnostics.add(diag);
84227
+ }
84228
+ }
84217
84229
  return iterationTypes_1;
84218
84230
  }
84219
84231
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84221,19 +84233,27 @@ var ts;
84221
84233
  if (cachedTypes)
84222
84234
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84223
84235
  var allIterationTypes;
84224
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84225
- var constituent = _a[_i];
84226
- var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode);
84236
+ for (var _d = 0, _e = type.types; _d < _e.length; _d++) {
84237
+ var constituent = _e[_d];
84238
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84239
+ var iterationTypes_2 = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
84227
84240
  if (iterationTypes_2 === noIterationTypes) {
84228
84241
  if (errorNode) {
84229
- reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84242
+ var rootDiag = reportTypeNotIterableError(errorNode, type, !!(use & 2 /* AllowsAsyncIterablesFlag */));
84243
+ if (errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) {
84244
+ ts.addRelatedInfo.apply(void 0, __spreadArray([rootDiag], errorOutputContainer.errors, false));
84245
+ }
84230
84246
  }
84231
84247
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84232
84248
  return undefined;
84233
84249
  }
84234
- else {
84235
- allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84250
+ else if ((_b = errorOutputContainer === null || errorOutputContainer === void 0 ? void 0 : errorOutputContainer.errors) === null || _b === void 0 ? void 0 : _b.length) {
84251
+ for (var _f = 0, _g = errorOutputContainer.errors; _f < _g.length; _f++) {
84252
+ var diag = _g[_f];
84253
+ diagnostics.add(diag);
84254
+ }
84236
84255
  }
84256
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84237
84257
  }
84238
84258
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84239
84259
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84261,47 +84281,62 @@ var ts;
84261
84281
  * NOTE: You probably don't want to call this directly and should be calling
84262
84282
  * `getIterationTypesOfIterable` instead.
84263
84283
  */
84264
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84284
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84265
84285
  if (isTypeAny(type)) {
84266
84286
  return anyIterationTypes;
84267
84287
  }
84288
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
84289
+ // In addition, we should not cache any new results for this call.
84290
+ var noCache = false;
84268
84291
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84269
84292
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84270
84293
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84271
84294
  if (iterationTypes) {
84272
- return use & 8 /* ForOfFlag */ ?
84273
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84274
- iterationTypes;
84295
+ if (iterationTypes === noIterationTypes && errorNode) {
84296
+ // ignore the cached value
84297
+ noCache = true;
84298
+ }
84299
+ else {
84300
+ return use & 8 /* ForOfFlag */ ?
84301
+ getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84302
+ iterationTypes;
84303
+ }
84275
84304
  }
84276
84305
  }
84277
84306
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84278
84307
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84279
84308
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84280
84309
  if (iterationTypes) {
84281
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84282
- // for a sync iterable in an async context, only use the cached types if they are valid.
84283
- if (iterationTypes !== noIterationTypes) {
84284
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84285
- }
84310
+ if (iterationTypes === noIterationTypes && errorNode) {
84311
+ // ignore the cached value
84312
+ noCache = true;
84286
84313
  }
84287
84314
  else {
84288
- return iterationTypes;
84315
+ if (use & 2 /* AllowsAsyncIterablesFlag */) {
84316
+ // for a sync iterable in an async context, only use the cached types if they are valid.
84317
+ if (iterationTypes !== noIterationTypes) {
84318
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84319
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84320
+ }
84321
+ }
84322
+ else {
84323
+ return iterationTypes;
84324
+ }
84289
84325
  }
84290
84326
  }
84291
84327
  }
84292
84328
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84293
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84329
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84294
84330
  if (iterationTypes !== noIterationTypes) {
84295
84331
  return iterationTypes;
84296
84332
  }
84297
84333
  }
84298
84334
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84299
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84335
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84300
84336
  if (iterationTypes !== noIterationTypes) {
84301
84337
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84302
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84303
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84304
- : noIterationTypes);
84338
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84339
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84305
84340
  }
84306
84341
  else {
84307
84342
  return iterationTypes;
@@ -84322,7 +84357,7 @@ var ts;
84322
84357
  }
84323
84358
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84324
84359
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84325
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84360
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84326
84361
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84327
84362
  }
84328
84363
  /**
@@ -84376,40 +84411,56 @@ var ts;
84376
84411
  * NOTE: You probably don't want to call this directly and should be calling
84377
84412
  * `getIterationTypesOfIterable` instead.
84378
84413
  */
84379
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84414
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84380
84415
  var _a;
84381
84416
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84382
84417
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84383
84418
  if (isTypeAny(methodType)) {
84384
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84419
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84385
84420
  }
84386
84421
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84387
84422
  if (!ts.some(signatures)) {
84388
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84423
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84389
84424
  }
84390
84425
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84391
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84392
- return setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84426
+ var iterationTypes = (_a = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache)) !== null && _a !== void 0 ? _a : noIterationTypes;
84427
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
84393
84428
  }
84394
84429
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84395
84430
  var message = allowAsyncIterables
84396
84431
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84397
84432
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84398
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84433
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84434
+ }
84435
+ /**
84436
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84437
+ *
84438
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84439
+ * record is returned. Otherwise, `undefined` is returned.
84440
+ */
84441
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84442
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84399
84443
  }
84400
84444
  /**
84401
84445
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84402
84446
  *
84403
84447
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84404
84448
  * record is returned. Otherwise, `undefined` is returned.
84449
+ *
84450
+ * NOTE: You probably don't want to call this directly and should be calling
84451
+ * `getIterationTypesOfIterator` instead.
84405
84452
  */
84406
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84453
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84407
84454
  if (isTypeAny(type)) {
84408
84455
  return anyIterationTypes;
84409
84456
  }
84410
84457
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84411
- getIterationTypesOfIteratorFast(type, resolver) ||
84412
- getIterationTypesOfIteratorSlow(type, resolver, errorNode);
84458
+ getIterationTypesOfIteratorFast(type, resolver);
84459
+ if (iterationTypes === noIterationTypes && errorNode) {
84460
+ iterationTypes = undefined;
84461
+ noCache = true;
84462
+ }
84463
+ iterationTypes !== null && iterationTypes !== void 0 ? iterationTypes : (iterationTypes = getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache));
84413
84464
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84414
84465
  }
84415
84466
  /**
@@ -84447,7 +84498,7 @@ var ts;
84447
84498
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84448
84499
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84449
84500
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84450
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84501
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84451
84502
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84452
84503
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84453
84504
  }
@@ -84517,8 +84568,8 @@ var ts;
84517
84568
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84518
84569
  * record is returned. Otherwise, we return `undefined`.
84519
84570
  */
84520
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84521
- var _a, _b, _c, _d;
84571
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84572
+ var _a, _b, _c, _d, _e, _f;
84522
84573
  var method = getPropertyOfType(type, methodName);
84523
84574
  // Ignore 'return' or 'throw' if they are missing.
84524
84575
  if (!method && methodName !== "next") {
@@ -84538,9 +84589,15 @@ var ts;
84538
84589
  var diagnostic = methodName === "next"
84539
84590
  ? resolver.mustHaveANextMethodDiagnostic
84540
84591
  : resolver.mustBeAMethodDiagnostic;
84541
- error(errorNode, diagnostic, methodName);
84592
+ if (errorOutputContainer) {
84593
+ (_a = errorOutputContainer.errors) !== null && _a !== void 0 ? _a : (errorOutputContainer.errors = []);
84594
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, diagnostic, methodName));
84595
+ }
84596
+ else {
84597
+ error(errorNode, diagnostic, methodName);
84598
+ }
84542
84599
  }
84543
- return methodName === "next" ? anyIterationTypes : undefined;
84600
+ return methodName === "next" ? noIterationTypes : undefined;
84544
84601
  }
84545
84602
  // If the method signature comes exclusively from the global iterator or generator type,
84546
84603
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84552,8 +84609,8 @@ var ts;
84552
84609
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84553
84610
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84554
84611
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84555
- var isGeneratorMethod = ((_b = (_a = globalGeneratorType.symbol) === null || _a === void 0 ? void 0 : _a.members) === null || _b === void 0 ? void 0 : _b.get(methodName)) === methodType.symbol;
84556
- var isIteratorMethod = !isGeneratorMethod && ((_d = (_c = globalIteratorType.symbol) === null || _c === void 0 ? void 0 : _c.members) === null || _d === void 0 ? void 0 : _d.get(methodName)) === methodType.symbol;
84612
+ 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;
84613
+ var isIteratorMethod = !isGeneratorMethod && ((_e = (_d = globalIteratorType.symbol) === null || _d === void 0 ? void 0 : _d.members) === null || _e === void 0 ? void 0 : _e.get(methodName)) === methodType.symbol;
84557
84614
  if (isGeneratorMethod || isIteratorMethod) {
84558
84615
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84559
84616
  var mapper = methodType.mapper;
@@ -84593,7 +84650,13 @@ var ts;
84593
84650
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84594
84651
  if (iterationTypes === noIterationTypes) {
84595
84652
  if (errorNode) {
84596
- error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84653
+ if (errorOutputContainer) {
84654
+ (_f = errorOutputContainer.errors) !== null && _f !== void 0 ? _f : (errorOutputContainer.errors = []);
84655
+ errorOutputContainer.errors.push(ts.createDiagnosticForNode(errorNode, resolver.mustHaveAValueDiagnostic, methodName));
84656
+ }
84657
+ else {
84658
+ error(errorNode, resolver.mustHaveAValueDiagnostic, methodName);
84659
+ }
84597
84660
  }
84598
84661
  yieldType = anyType;
84599
84662
  returnTypes = ts.append(returnTypes, anyType);
@@ -84614,13 +84677,13 @@ var ts;
84614
84677
  * NOTE: You probably don't want to call this directly and should be calling
84615
84678
  * `getIterationTypesOfIterator` instead.
84616
84679
  */
84617
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84680
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84618
84681
  var iterationTypes = combineIterationTypes([
84619
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84620
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84621
- getIterationTypesOfMethod(type, resolver, "throw", errorNode),
84682
+ getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
84683
+ getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
84684
+ getIterationTypesOfMethod(type, resolver, "throw", errorNode, errorOutputContainer),
84622
84685
  ]);
84623
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84686
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84624
84687
  }
84625
84688
  /**
84626
84689
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84641,7 +84704,7 @@ var ts;
84641
84704
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84642
84705
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84643
84706
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84644
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84707
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84645
84708
  }
84646
84709
  function checkBreakOrContinueStatement(node) {
84647
84710
  // Grammar checking
@@ -122938,8 +123001,6 @@ var ts;
122938
123001
  if (watcher.files === 0 && watcher.resolutions === 0) {
122939
123002
  fileWatchesOfAffectingLocations.delete(path);
122940
123003
  watcher.watcher.close();
122941
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122942
- watcher.watcher = ts.noopFileWatcher;
122943
123004
  }
122944
123005
  });
122945
123006
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123285,20 +123346,27 @@ var ts;
123285
123346
  }
123286
123347
  var paths = new ts.Set();
123287
123348
  paths.add(locationToWatch);
123349
+ var actualWatcher = canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123350
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123351
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123352
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123353
+ paths.forEach(function (path) {
123354
+ if (watcher.resolutions)
123355
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123356
+ if (watcher.files)
123357
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123358
+ packageJsonMap === null || packageJsonMap === void 0 ? void 0 : packageJsonMap.delete(resolutionHost.toPath(path));
123359
+ });
123360
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123361
+ }) : ts.noopFileWatcher;
123288
123362
  var watcher = {
123289
- watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123290
- resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123291
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123292
- paths.forEach(function (path) {
123293
- var _a;
123294
- if (watcher.resolutions)
123295
- (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123296
- if (watcher.files)
123297
- (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123298
- (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123299
- });
123300
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123301
- }) : ts.noopFileWatcher,
123363
+ watcher: actualWatcher !== ts.noopFileWatcher ? {
123364
+ close: function () {
123365
+ actualWatcher.close();
123366
+ // Ensure when watching symlinked package.json, we can close the actual file watcher only once
123367
+ actualWatcher = ts.noopFileWatcher;
123368
+ }
123369
+ } : actualWatcher,
123302
123370
  resolutions: forResolution ? 1 : 0,
123303
123371
  files: forResolution ? 0 : 1,
123304
123372
  paths: paths,
@@ -123712,7 +123780,7 @@ var ts;
123712
123780
  var info = getInfo(importingSourceFileName, host);
123713
123781
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123714
123782
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123715
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123783
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123716
123784
  }
123717
123785
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123718
123786
  if (options === void 0) { options = {}; }
@@ -123795,7 +123863,7 @@ var ts;
123795
123863
  return nodeModulesSpecifiers;
123796
123864
  }
123797
123865
  if (!specifier && !modulePath.isRedirect) {
123798
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123866
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123799
123867
  if (ts.pathIsBareSpecifier(local)) {
123800
123868
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123801
123869
  }
@@ -123823,7 +123891,7 @@ var ts;
123823
123891
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123824
123892
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123825
123893
  }
123826
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123894
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123827
123895
  var ending = _a.ending, relativePreference = _a.relativePreference;
123828
123896
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123829
123897
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123837,9 +123905,8 @@ var ts;
123837
123905
  if (!relativeToBaseUrl) {
123838
123906
  return relativePath;
123839
123907
  }
123840
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123841
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123842
- var nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
123908
+ var fromPaths = paths && tryGetModuleNameFromPaths(relativeToBaseUrl, paths, getAllowedEndings(ending, compilerOptions, importMode), host, compilerOptions);
123909
+ var nonRelative = fromPaths === undefined && baseUrl !== undefined ? removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions) : fromPaths;
123843
123910
  if (!nonRelative) {
123844
123911
  return relativePath;
123845
123912
  }
@@ -124074,28 +124141,102 @@ var ts;
124074
124141
  return ambientModuleDeclare.name.text;
124075
124142
  }
124076
124143
  }
124077
- function tryGetModuleNameFromPaths(relativeToBaseUrlWithIndex, relativeToBaseUrl, paths) {
124144
+ function getAllowedEndings(preferredEnding, compilerOptions, importMode) {
124145
+ if (ts.getEmitModuleResolutionKind(compilerOptions) >= ts.ModuleResolutionKind.Node16 && importMode === ts.ModuleKind.ESNext) {
124146
+ return [2 /* JsExtension */];
124147
+ }
124148
+ switch (preferredEnding) {
124149
+ case 2 /* JsExtension */: return [2 /* JsExtension */, 0 /* Minimal */, 1 /* Index */];
124150
+ case 1 /* Index */: return [1 /* Index */, 0 /* Minimal */, 2 /* JsExtension */];
124151
+ case 0 /* Minimal */: return [0 /* Minimal */, 1 /* Index */, 2 /* JsExtension */];
124152
+ default: ts.Debug.assertNever(preferredEnding);
124153
+ }
124154
+ }
124155
+ function tryGetModuleNameFromPaths(relativeToBaseUrl, paths, allowedEndings, host, compilerOptions) {
124078
124156
  for (var key in paths) {
124079
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124080
- var patternText_1 = _a[_i];
124081
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
124157
+ var _loop_36 = function (patternText_1) {
124158
+ var pattern = ts.normalizePath(patternText_1);
124082
124159
  var indexOfStar = pattern.indexOf("*");
124160
+ // In module resolution, if `pattern` itself has an extension, a file with that extension is looked up directly,
124161
+ // meaning a '.ts' or '.d.ts' extension is allowed to resolve. This is distinct from the case where a '*' substitution
124162
+ // causes a module specifier to have an extension, i.e. the extension comes from the module specifier in a JS/TS file
124163
+ // and matches the '*'. For example:
124164
+ //
124165
+ // Module Specifier | Path Mapping (key: [pattern]) | Interpolation | Resolution Action
124166
+ // ---------------------->------------------------------->--------------------->---------------------------------------------------------------
124167
+ // import "@app/foo" -> "@app/*": ["./src/app/*.ts"] -> "./src/app/foo.ts" -> tryFile("./src/app/foo.ts") || [continue resolution algorithm]
124168
+ // import "@app/foo.ts" -> "@app/*": ["./src/app/*"] -> "./src/app/foo.ts" -> [continue resolution algorithm]
124169
+ //
124170
+ // (https://github.com/microsoft/TypeScript/blob/ad4ded80e1d58f0bf36ac16bea71bc10d9f09895/src/compiler/moduleNameResolver.ts#L2509-L2516)
124171
+ //
124172
+ // The interpolation produced by both scenarios is identical, but only in the former, where the extension is encoded in
124173
+ // the path mapping rather than in the module specifier, will we prioritize a file lookup on the interpolation result.
124174
+ // (In fact, currently, the latter scenario will necessarily fail since no resolution mode recognizes '.ts' as a valid
124175
+ // extension for a module specifier.)
124176
+ //
124177
+ // Here, this means we need to be careful about whether we generate a match from the target filename (typically with a
124178
+ // .ts extension) or the possible relative module specifiers representing that file:
124179
+ //
124180
+ // Filename | Relative Module Specifier Candidates | Path Mapping | Filename Result | Module Specifier Results
124181
+ // --------------------<----------------------------------------------<------------------------------<-------------------||----------------------------
124182
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*.d.ts"] <- @app/haha || (none)
124183
+ // dist/haha.d.ts <- dist/haha, dist/haha.js <- "@app/*": ["./dist/*"] <- (none) || @app/haha, @app/haha.js
124184
+ // dist/foo/index.d.ts <- dist/foo, dist/foo/index, dist/foo/index.js <- "@app/*": ["./dist/*.d.ts"] <- @app/foo/index || (none)
124185
+ // 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
124186
+ // dist/wow.js.js <- dist/wow.js, dist/wow.js.js <- "@app/*": ["./dist/*.js"] <- @app/wow.js || @app/wow, @app/wow.js
124187
+ //
124188
+ // The "Filename Result" can be generated only if `pattern` has an extension. Care must be taken that the list of
124189
+ // relative module specifiers to run the interpolation (a) is actually valid for the module resolution mode, (b) takes
124190
+ // into account the existence of other files (e.g. 'dist/wow.js' cannot refer to 'dist/wow.js.js' if 'dist/wow.js'
124191
+ // exists) and (c) that they are ordered by preference. The last row shows that the filename result and module
124192
+ // specifier results are not mutually exclusive. Note that the filename result is a higher priority in module
124193
+ // resolution, but as long criteria (b) above is met, I don't think its result needs to be the highest priority result
124194
+ // in module specifier generation. I have included it last, as it's difficult to tell exactly where it should be
124195
+ // sorted among the others for a particular value of `importModuleSpecifierEnding`.
124196
+ var candidates = allowedEndings.map(function (ending) { return ({
124197
+ ending: ending,
124198
+ value: removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions)
124199
+ }); });
124200
+ if (ts.tryGetExtensionFromPath(pattern)) {
124201
+ candidates.push({ ending: undefined, value: relativeToBaseUrl });
124202
+ }
124083
124203
  if (indexOfStar !== -1) {
124084
- var prefix = pattern.substr(0, indexOfStar);
124085
- var suffix = pattern.substr(indexOfStar + 1);
124086
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
124087
- ts.startsWith(relativeToBaseUrl, prefix) &&
124088
- ts.endsWith(relativeToBaseUrl, suffix) ||
124089
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
124090
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
124091
- return key.replace("*", matchedStar);
124204
+ var prefix = pattern.substring(0, indexOfStar);
124205
+ var suffix = pattern.substring(indexOfStar + 1);
124206
+ for (var _b = 0, candidates_3 = candidates; _b < candidates_3.length; _b++) {
124207
+ var _c = candidates_3[_b], ending = _c.ending, value = _c.value;
124208
+ if (value.length >= prefix.length + suffix.length &&
124209
+ ts.startsWith(value, prefix) &&
124210
+ ts.endsWith(value, suffix) &&
124211
+ validateEnding({ ending: ending, value: value })) {
124212
+ var matchedStar = value.substring(prefix.length, value.length - suffix.length);
124213
+ return { value: key.replace("*", matchedStar) };
124214
+ }
124092
124215
  }
124093
124216
  }
124094
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
124095
- return key;
124217
+ else if (ts.some(candidates, function (c) { return c.ending !== 0 /* Minimal */ && pattern === c.value; }) ||
124218
+ ts.some(candidates, function (c) { return c.ending === 0 /* Minimal */ && pattern === c.value && validateEnding(c); })) {
124219
+ return { value: key };
124096
124220
  }
124221
+ };
124222
+ for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
124223
+ var patternText_1 = _a[_i];
124224
+ var state_12 = _loop_36(patternText_1);
124225
+ if (typeof state_12 === "object")
124226
+ return state_12.value;
124097
124227
  }
124098
124228
  }
124229
+ function validateEnding(_a) {
124230
+ var ending = _a.ending, value = _a.value;
124231
+ // Optimization: `removeExtensionAndIndexPostFix` can query the file system (a good bit) if `ending` is `Minimal`, the basename
124232
+ // is 'index', and a `host` is provided. To avoid that until it's unavoidable, we ran the function with no `host` above. Only
124233
+ // here, after we've checked that the minimal ending is indeed a match (via the length and prefix/suffix checks / `some` calls),
124234
+ // 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
124235
+ // `Ending.Index` result, which should already be in the list of candidates if `Minimal` was. (Note: the assumption here is
124236
+ // that every module resolution mode that supports dropping extensions also supports dropping `/index`. Like literally
124237
+ // everything else in this file, this logic needs to be updated if that's not true in some future module resolution mode.)
124238
+ return ending !== 0 /* Minimal */ || value === removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions, host);
124239
+ }
124099
124240
  }
124100
124241
  var MatchingMode;
124101
124242
  (function (MatchingMode) {
@@ -124191,10 +124332,10 @@ var ts;
124191
124332
  return undefined;
124192
124333
  }
124193
124334
  // Simplify the full file path to something that can be resolved by Node.
124335
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124194
124336
  var moduleSpecifier = path;
124195
124337
  var isPackageRootPath = false;
124196
124338
  if (!packageNameOnly) {
124197
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124198
124339
  var packageRootIndex = parts.packageRootIndex;
124199
124340
  var moduleFileName = void 0;
124200
124341
  while (true) {
@@ -124243,15 +124384,13 @@ var ts;
124243
124384
  var packageRootPath = path.substring(0, packageRootIndex);
124244
124385
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124245
124386
  var moduleFileToTry = path;
124387
+ var maybeBlockedByTypesVersions = false;
124246
124388
  var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
124247
124389
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124248
124390
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124391
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124249
124392
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124250
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124251
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124252
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124253
- // with, so for now we just stick with the mode of the file.
124254
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124393
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124255
124394
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124256
124395
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124257
124396
  : undefined;
@@ -124270,16 +124409,26 @@ var ts;
124270
124409
  : undefined;
124271
124410
  if (versionPaths) {
124272
124411
  var subModuleName = path.slice(packageRootPath.length + 1);
124273
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124274
- if (fromPaths !== undefined) {
124412
+ var fromPaths = tryGetModuleNameFromPaths(subModuleName, versionPaths.paths, getAllowedEndings(preferences.ending, options, importMode), host, options);
124413
+ if (fromPaths === undefined) {
124414
+ maybeBlockedByTypesVersions = true;
124415
+ }
124416
+ else {
124275
124417
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124276
124418
  }
124277
124419
  }
124278
124420
  // If the file is the main module, it can be imported by the package name
124279
124421
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124280
- if (ts.isString(mainFileRelative)) {
124422
+ if (ts.isString(mainFileRelative) && !(maybeBlockedByTypesVersions && ts.matchPatternOrExact(ts.tryParsePatterns(versionPaths.paths), mainFileRelative))) {
124423
+ // The 'main' file is also subject to mapping through typesVersions, and we couldn't come up with a path
124424
+ // explicitly through typesVersions, so if it matches a key in typesVersions now, it's not reachable.
124425
+ // (The only way this can happen is if some file in a package that's not resolvable from outside the
124426
+ // package got pulled into the program anyway, e.g. transitively through a file that *is* reachable. It
124427
+ // happens very easily in fourslash tests though, since every test file listed gets included. See
124428
+ // importNameCodeFix_typesVersions.ts for an example.)
124281
124429
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124282
124430
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124431
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124283
124432
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124284
124433
  }
124285
124434
  }
@@ -162344,6 +162493,9 @@ var ts;
162344
162493
  if (!containingDecl) {
162345
162494
  return;
162346
162495
  }
162496
+ if (ts.isFunctionLikeDeclaration(containingDecl) && containingDecl.body && ts.rangeContainsPosition(containingDecl.body, startPosition)) {
162497
+ return;
162498
+ }
162347
162499
  var checker = program.getTypeChecker();
162348
162500
  var signatureSymbol = containingDecl.symbol;
162349
162501
  if (!signatureSymbol) {