typescript 4.8.0-dev.20220801 → 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.20220801";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220804";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -8765,6 +8765,10 @@ var ts;
8765
8765
  resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."),
8766
8766
  Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require: diag(1456, ts.DiagnosticCategory.Error, "Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require_1456", "Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`."),
8767
8767
  Matched_by_default_include_pattern_Asterisk_Asterisk_Slash_Asterisk: diag(1457, ts.DiagnosticCategory.Message, "Matched_by_default_include_pattern_Asterisk_Asterisk_Slash_Asterisk_1457", "Matched by default include pattern '**/*'"),
8768
+ File_is_ECMAScript_module_because_0_has_field_type_with_value_module: diag(1458, ts.DiagnosticCategory.Message, "File_is_ECMAScript_module_because_0_has_field_type_with_value_module_1458", "File is ECMAScript module because '{0}' has field \"type\" with value \"module\""),
8769
+ File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module: diag(1459, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module_1459", "File is CommonJS module because '{0}' has field \"type\" whose value is not \"module\""),
8770
+ File_is_CommonJS_module_because_0_does_not_have_field_type: diag(1460, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_0_does_not_have_field_type_1460", "File is CommonJS module because '{0}' does not have field \"type\""),
8771
+ File_is_CommonJS_module_because_package_json_was_not_found: diag(1461, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_package_json_was_not_found_1461", "File is CommonJS module because 'package.json' was not found"),
8768
8772
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8769
8773
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8770
8774
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -22068,7 +22072,7 @@ var ts;
22068
22072
  * Wraps an expression in parentheses if it is needed in order to use the expression for
22069
22073
  * property or element access.
22070
22074
  */
22071
- function parenthesizeLeftSideOfAccess(expression) {
22075
+ function parenthesizeLeftSideOfAccess(expression, optionalChain) {
22072
22076
  // isLeftHandSideExpression is almost the correct criterion for when it is not necessary
22073
22077
  // to parenthesize the expression before a dot. The known exception is:
22074
22078
  //
@@ -22077,7 +22081,8 @@ var ts;
22077
22081
  //
22078
22082
  var emittedExpression = ts.skipPartiallyEmittedExpressions(expression);
22079
22083
  if (ts.isLeftHandSideExpression(emittedExpression)
22080
- && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)) {
22084
+ && (emittedExpression.kind !== 209 /* NewExpression */ || emittedExpression.arguments)
22085
+ && (optionalChain || !ts.isOptionalChain(emittedExpression))) {
22081
22086
  // TODO(rbuckton): Verify whether this assertion holds.
22082
22087
  return expression;
22083
22088
  }
@@ -23484,7 +23489,7 @@ var ts;
23484
23489
  // @api
23485
23490
  function createDecorator(expression) {
23486
23491
  var node = createBaseNode(165 /* Decorator */);
23487
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
23492
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
23488
23493
  node.transformFlags |=
23489
23494
  propagateChildFlags(node.expression) |
23490
23495
  1 /* ContainsTypeScript */ |
@@ -24285,7 +24290,7 @@ var ts;
24285
24290
  // @api
24286
24291
  function createPropertyAccessExpression(expression, name) {
24287
24292
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24288
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24293
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24289
24294
  node.name = asName(name);
24290
24295
  node.transformFlags =
24291
24296
  propagateChildFlags(node.expression) |
@@ -24315,7 +24320,7 @@ var ts;
24315
24320
  function createPropertyAccessChain(expression, questionDotToken, name) {
24316
24321
  var node = createBaseExpression(206 /* PropertyAccessExpression */);
24317
24322
  node.flags |= 32 /* OptionalChain */;
24318
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24323
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24319
24324
  node.questionDotToken = questionDotToken;
24320
24325
  node.name = asName(name);
24321
24326
  node.transformFlags |=
@@ -24341,7 +24346,7 @@ var ts;
24341
24346
  // @api
24342
24347
  function createElementAccessExpression(expression, index) {
24343
24348
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24344
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24349
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24345
24350
  node.argumentExpression = asExpression(index);
24346
24351
  node.transformFlags |=
24347
24352
  propagateChildFlags(node.expression) |
@@ -24369,7 +24374,7 @@ var ts;
24369
24374
  function createElementAccessChain(expression, questionDotToken, index) {
24370
24375
  var node = createBaseExpression(207 /* ElementAccessExpression */);
24371
24376
  node.flags |= 32 /* OptionalChain */;
24372
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24377
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24373
24378
  node.questionDotToken = questionDotToken;
24374
24379
  node.argumentExpression = asExpression(index);
24375
24380
  node.transformFlags |=
@@ -24393,7 +24398,7 @@ var ts;
24393
24398
  // @api
24394
24399
  function createCallExpression(expression, typeArguments, argumentsArray) {
24395
24400
  var node = createBaseExpression(208 /* CallExpression */);
24396
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24401
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24397
24402
  node.typeArguments = asNodeArray(typeArguments);
24398
24403
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
24399
24404
  node.transformFlags |=
@@ -24426,7 +24431,7 @@ var ts;
24426
24431
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
24427
24432
  var node = createBaseExpression(208 /* CallExpression */);
24428
24433
  node.flags |= 32 /* OptionalChain */;
24429
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24434
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24430
24435
  node.questionDotToken = questionDotToken;
24431
24436
  node.typeArguments = asNodeArray(typeArguments);
24432
24437
  node.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray));
@@ -24481,7 +24486,7 @@ var ts;
24481
24486
  // @api
24482
24487
  function createTaggedTemplateExpression(tag, typeArguments, template) {
24483
24488
  var node = createBaseExpression(210 /* TaggedTemplateExpression */);
24484
- node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag);
24489
+ node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false);
24485
24490
  node.typeArguments = asNodeArray(typeArguments);
24486
24491
  node.template = template;
24487
24492
  node.transformFlags |=
@@ -24919,7 +24924,7 @@ var ts;
24919
24924
  // @api
24920
24925
  function createExpressionWithTypeArguments(expression, typeArguments) {
24921
24926
  var node = createBaseNode(228 /* ExpressionWithTypeArguments */);
24922
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24927
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24923
24928
  node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
24924
24929
  node.transformFlags |=
24925
24930
  propagateChildFlags(node.expression) |
@@ -24955,7 +24960,7 @@ var ts;
24955
24960
  // @api
24956
24961
  function createNonNullExpression(expression) {
24957
24962
  var node = createBaseExpression(230 /* NonNullExpression */);
24958
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24963
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
24959
24964
  node.transformFlags |=
24960
24965
  propagateChildFlags(node.expression) |
24961
24966
  1 /* ContainsTypeScript */;
@@ -24974,7 +24979,7 @@ var ts;
24974
24979
  function createNonNullChain(expression) {
24975
24980
  var node = createBaseExpression(230 /* NonNullExpression */);
24976
24981
  node.flags |= 32 /* OptionalChain */;
24977
- node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
24982
+ node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true);
24978
24983
  node.transformFlags |=
24979
24984
  propagateChildFlags(node.expression) |
24980
24985
  1 /* ContainsTypeScript */;
@@ -27178,7 +27183,7 @@ var ts;
27178
27183
  }
27179
27184
  else if (ts.getEmitFlags(callee) & 4096 /* HelperName */) {
27180
27185
  thisArg = createVoidZero();
27181
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee);
27186
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(callee, /*optionalChain*/ false);
27182
27187
  }
27183
27188
  else if (ts.isPropertyAccessExpression(callee)) {
27184
27189
  if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
@@ -27207,7 +27212,7 @@ var ts;
27207
27212
  else {
27208
27213
  // for `a()` target is `a` and thisArg is `void 0`
27209
27214
  thisArg = createVoidZero();
27210
- target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression);
27215
+ target = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false);
27211
27216
  }
27212
27217
  return { target: target, thisArg: thisArg };
27213
27218
  }
@@ -43442,7 +43447,7 @@ var ts;
43442
43447
  ts.createCacheWithRedirects = createCacheWithRedirects;
43443
43448
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
43444
43449
  var cache;
43445
- return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries };
43450
+ return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries, getInternalMap: getInternalMap };
43446
43451
  function getPackageJsonInfo(packageJsonPath) {
43447
43452
  return cache === null || cache === void 0 ? void 0 : cache.get(ts.toPath(packageJsonPath, currentDirectory, getCanonicalFileName));
43448
43453
  }
@@ -43456,6 +43461,9 @@ var ts;
43456
43461
  var iter = cache === null || cache === void 0 ? void 0 : cache.entries();
43457
43462
  return iter ? ts.arrayFrom(iter) : [];
43458
43463
  }
43464
+ function getInternalMap() {
43465
+ return cache;
43466
+ }
43459
43467
  }
43460
43468
  function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create) {
43461
43469
  var cache = cacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
@@ -43559,15 +43567,18 @@ var ts;
43559
43567
  }
43560
43568
  ts.zipToModeAwareCache = zipToModeAwareCache;
43561
43569
  function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
43562
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43570
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43563
43571
  moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
43564
43572
  var packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
43565
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; } });
43573
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; }, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43566
43574
  function clear() {
43567
- preDirectoryResolutionCache.clear();
43568
- moduleNameToDirectoryMap.clear();
43575
+ clearAllExceptPackageJsonInfoCache();
43569
43576
  packageJsonInfoCache.clear();
43570
43577
  }
43578
+ function clearAllExceptPackageJsonInfoCache() {
43579
+ perDirectoryResolutionCache.clear();
43580
+ moduleNameToDirectoryMap.clear();
43581
+ }
43571
43582
  function update(options) {
43572
43583
  updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap);
43573
43584
  }
@@ -43643,13 +43654,16 @@ var ts;
43643
43654
  }
43644
43655
  ts.createModuleResolutionCache = createModuleResolutionCache;
43645
43656
  function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
43646
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43657
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43647
43658
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
43648
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { clear: clear });
43659
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { clear: clear, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43649
43660
  function clear() {
43650
- preDirectoryResolutionCache.clear();
43661
+ clearAllExceptPackageJsonInfoCache();
43651
43662
  packageJsonInfoCache.clear();
43652
43663
  }
43664
+ function clearAllExceptPackageJsonInfoCache() {
43665
+ perDirectoryResolutionCache.clear();
43666
+ }
43653
43667
  }
43654
43668
  ts.createTypeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache;
43655
43669
  function resolveModuleNameFromCache(moduleName, containingFile, cache, mode) {
@@ -51437,10 +51451,6 @@ var ts;
51437
51451
  checkExpressionCached(expression);
51438
51452
  return getNodeLinks(expression).resolvedSymbol;
51439
51453
  }
51440
- function getTargetOfPropertyAssignment(node, dontRecursivelyResolve) {
51441
- var expression = node.initializer;
51442
- return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
51443
- }
51444
51454
  function getTargetOfAccessExpression(node, dontRecursivelyResolve) {
51445
51455
  if (!(ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */)) {
51446
51456
  return undefined;
@@ -51472,7 +51482,7 @@ var ts;
51472
51482
  case 297 /* ShorthandPropertyAssignment */:
51473
51483
  return resolveEntityName(node.name, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */, /*ignoreErrors*/ true, dontRecursivelyResolve);
51474
51484
  case 296 /* PropertyAssignment */:
51475
- return getTargetOfPropertyAssignment(node, dontRecursivelyResolve);
51485
+ return getTargetOfAliasLikeExpression(node.initializer, dontRecursivelyResolve);
51476
51486
  case 207 /* ElementAccessExpression */:
51477
51487
  case 206 /* PropertyAccessExpression */:
51478
51488
  return getTargetOfAccessExpression(node, dontRecursivelyResolve);
@@ -56997,7 +57007,7 @@ var ts;
56997
57007
  (resolvedSymbol || symbol).exports.forEach(function (s, name) {
56998
57008
  var _a;
56999
57009
  var exportedMember = members_4.get(name);
57000
- if (exportedMember && exportedMember !== s) {
57010
+ if (exportedMember && exportedMember !== s && !(s.flags & 2097152 /* Alias */)) {
57001
57011
  if (s.flags & 111551 /* Value */ && exportedMember.flags & 111551 /* Value */) {
57002
57012
  // If the member has an additional value-like declaration, union the types from the two declarations,
57003
57013
  // but issue an error if they occurred in two different files. The purpose is to support a JS file with
@@ -63489,6 +63499,7 @@ var ts;
63489
63499
  }
63490
63500
  }
63491
63501
  function getTypeFromImportTypeNode(node) {
63502
+ var _a;
63492
63503
  var links = getNodeLinks(node);
63493
63504
  if (!links.resolvedType) {
63494
63505
  if (node.isTypeOf && node.typeArguments) { // Only the non-typeof form can make use of type arguments
@@ -63508,6 +63519,7 @@ var ts;
63508
63519
  links.resolvedSymbol = unknownSymbol;
63509
63520
  return links.resolvedType = errorType;
63510
63521
  }
63522
+ var isExportEquals = !!((_a = innerModuleSymbol.exports) === null || _a === void 0 ? void 0 : _a.get("export=" /* ExportEquals */));
63511
63523
  var moduleSymbol = resolveExternalModuleSymbol(innerModuleSymbol, /*dontResolveAlias*/ false);
63512
63524
  if (!ts.nodeIsMissing(node.qualifier)) {
63513
63525
  var nameStack = getIdentifierChain(node.qualifier);
@@ -63519,9 +63531,11 @@ var ts;
63519
63531
  // That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
63520
63532
  // the `exports` lookup process that only looks up namespace members which is used for most type references
63521
63533
  var mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
63522
- var next = node.isTypeOf
63534
+ var symbolFromVariable = node.isTypeOf || ts.isInJSFile(node) && isExportEquals
63523
63535
  ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ true)
63524
- : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63536
+ : undefined;
63537
+ var symbolFromModule = node.isTypeOf ? undefined : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63538
+ var next = symbolFromModule !== null && symbolFromModule !== void 0 ? symbolFromModule : symbolFromVariable;
63525
63539
  if (!next) {
63526
63540
  error(current, ts.Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), ts.declarationNameToString(current));
63527
63541
  return links.resolvedType = errorType;
@@ -66379,6 +66393,26 @@ var ts;
66379
66393
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66380
66394
  var saveErrorInfo = captureErrorCalculationState();
66381
66395
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66396
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66397
+ // The combined constraint of an intersection type is the intersection of the constraints of
66398
+ // the constituents. When an intersection type contains instantiable types with union type
66399
+ // constraints, there are situations where we need to examine the combined constraint. One is
66400
+ // when the target is a union type. Another is when the intersection contains types belonging
66401
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66402
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66403
+ // we need to check this constraint against a union on the target side. Also, given a type
66404
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66405
+ // 'string & number | number & number' which reduces to just 'number'.
66406
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66407
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66408
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66409
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66410
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66411
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66412
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66413
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66414
+ }
66415
+ }
66382
66416
  if (result) {
66383
66417
  resetErrorInfo(saveErrorInfo);
66384
66418
  }
@@ -66436,28 +66470,6 @@ var ts;
66436
66470
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66437
66471
  return result;
66438
66472
  }
66439
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66440
- // The combined constraint of an intersection type is the intersection of the constraints of
66441
- // the constituents. When an intersection type contains instantiable types with union type
66442
- // constraints, there are situations where we need to examine the combined constraint. One is
66443
- // when the target is a union type. Another is when the intersection contains types belonging
66444
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66445
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66446
- // we need to check this constraint against a union on the target side. Also, given a type
66447
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66448
- // 'string & number | number & number' which reduces to just 'number'.
66449
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66450
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66451
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66452
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66453
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66454
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66455
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66456
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66457
- return result;
66458
- }
66459
- }
66460
- }
66461
66473
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66462
66474
  // Source is instantiable (e.g. source has union or intersection constraint).
66463
66475
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -82311,9 +82323,11 @@ var ts;
82311
82323
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82312
82324
  if (isGenericObjectType(type)) {
82313
82325
  var baseConstraint = getBaseConstraintOfType(type);
82314
- // We only need `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82326
+ // We only need `Awaited<T>` if `T` is a type variable that has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82315
82327
  // or is promise-like.
82316
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82328
+ if (baseConstraint ?
82329
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82330
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82317
82331
  return true;
82318
82332
  }
82319
82333
  }
@@ -84190,17 +84204,28 @@ var ts;
84190
84204
  * the `[Symbol.asyncIterator]()` method first, and then the `[Symbol.iterator]()` method.
84191
84205
  */
84192
84206
  function getIterationTypesOfIterable(type, use, errorNode) {
84207
+ var _a, _b;
84193
84208
  if (isTypeAny(type)) {
84194
84209
  return anyIterationTypes;
84195
84210
  }
84196
84211
  if (!(type.flags & 1048576 /* Union */)) {
84197
- var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode);
84212
+ var errorOutputContainer = errorNode ? { errors: undefined } : undefined;
84213
+ var iterationTypes_1 = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
84198
84214
  if (iterationTypes_1 === noIterationTypes) {
84199
84215
  if (errorNode) {
84200
- 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
+ }
84201
84220
  }
84202
84221
  return undefined;
84203
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
+ }
84204
84229
  return iterationTypes_1;
84205
84230
  }
84206
84231
  var cacheKey = use & 2 /* AllowsAsyncIterablesFlag */ ? "iterationTypesOfAsyncIterable" : "iterationTypesOfIterable";
@@ -84208,19 +84233,27 @@ var ts;
84208
84233
  if (cachedTypes)
84209
84234
  return cachedTypes === noIterationTypes ? undefined : cachedTypes;
84210
84235
  var allIterationTypes;
84211
- for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
84212
- var constituent = _a[_i];
84213
- 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);
84214
84240
  if (iterationTypes_2 === noIterationTypes) {
84215
84241
  if (errorNode) {
84216
- 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
+ }
84217
84246
  }
84218
84247
  setCachedIterationTypes(type, cacheKey, noIterationTypes);
84219
84248
  return undefined;
84220
84249
  }
84221
- else {
84222
- 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
+ }
84223
84255
  }
84256
+ allIterationTypes = ts.append(allIterationTypes, iterationTypes_2);
84224
84257
  }
84225
84258
  var iterationTypes = allIterationTypes ? combineIterationTypes(allIterationTypes) : noIterationTypes;
84226
84259
  setCachedIterationTypes(type, cacheKey, iterationTypes);
@@ -84248,47 +84281,62 @@ var ts;
84248
84281
  * NOTE: You probably don't want to call this directly and should be calling
84249
84282
  * `getIterationTypesOfIterable` instead.
84250
84283
  */
84251
- function getIterationTypesOfIterableWorker(type, use, errorNode) {
84284
+ function getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer) {
84252
84285
  if (isTypeAny(type)) {
84253
84286
  return anyIterationTypes;
84254
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;
84255
84291
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84256
84292
  var iterationTypes = getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) ||
84257
84293
  getIterationTypesOfIterableFast(type, asyncIterationTypesResolver);
84258
84294
  if (iterationTypes) {
84259
- return use & 8 /* ForOfFlag */ ?
84260
- getAsyncFromSyncIterationTypes(iterationTypes, errorNode) :
84261
- 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
+ }
84262
84304
  }
84263
84305
  }
84264
84306
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84265
84307
  var iterationTypes = getIterationTypesOfIterableCached(type, syncIterationTypesResolver) ||
84266
84308
  getIterationTypesOfIterableFast(type, syncIterationTypesResolver);
84267
84309
  if (iterationTypes) {
84268
- if (use & 2 /* AllowsAsyncIterablesFlag */) {
84269
- // for a sync iterable in an async context, only use the cached types if they are valid.
84270
- if (iterationTypes !== noIterationTypes) {
84271
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", getAsyncFromSyncIterationTypes(iterationTypes, errorNode));
84272
- }
84310
+ if (iterationTypes === noIterationTypes && errorNode) {
84311
+ // ignore the cached value
84312
+ noCache = true;
84273
84313
  }
84274
84314
  else {
84275
- 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
+ }
84276
84325
  }
84277
84326
  }
84278
84327
  }
84279
84328
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84280
- var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode);
84329
+ var iterationTypes = getIterationTypesOfIterableSlow(type, asyncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84281
84330
  if (iterationTypes !== noIterationTypes) {
84282
84331
  return iterationTypes;
84283
84332
  }
84284
84333
  }
84285
84334
  if (use & 1 /* AllowsSyncIterablesFlag */) {
84286
- var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode);
84335
+ var iterationTypes = getIterationTypesOfIterableSlow(type, syncIterationTypesResolver, errorNode, errorOutputContainer, noCache);
84287
84336
  if (iterationTypes !== noIterationTypes) {
84288
84337
  if (use & 2 /* AllowsAsyncIterablesFlag */) {
84289
- return setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes
84290
- ? getAsyncFromSyncIterationTypes(iterationTypes, errorNode)
84291
- : noIterationTypes);
84338
+ iterationTypes = getAsyncFromSyncIterationTypes(iterationTypes, errorNode);
84339
+ return noCache ? iterationTypes : setCachedIterationTypes(type, "iterationTypesOfAsyncIterable", iterationTypes);
84292
84340
  }
84293
84341
  else {
84294
84342
  return iterationTypes;
@@ -84309,7 +84357,7 @@ var ts;
84309
84357
  }
84310
84358
  function getIterationTypesOfGlobalIterableType(globalType, resolver) {
84311
84359
  var globalIterationTypes = getIterationTypesOfIterableCached(globalType, resolver) ||
84312
- getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined);
84360
+ getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84313
84361
  return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes;
84314
84362
  }
84315
84363
  /**
@@ -84363,26 +84411,26 @@ var ts;
84363
84411
  * NOTE: You probably don't want to call this directly and should be calling
84364
84412
  * `getIterationTypesOfIterable` instead.
84365
84413
  */
84366
- function getIterationTypesOfIterableSlow(type, resolver, errorNode) {
84414
+ function getIterationTypesOfIterableSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84367
84415
  var _a;
84368
84416
  var method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
84369
84417
  var methodType = method && !(method.flags & 16777216 /* Optional */) ? getTypeOfSymbol(method) : undefined;
84370
84418
  if (isTypeAny(methodType)) {
84371
- return setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84419
+ return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
84372
84420
  }
84373
84421
  var signatures = methodType ? getSignaturesOfType(methodType, 0 /* Call */) : undefined;
84374
84422
  if (!ts.some(signatures)) {
84375
- return setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84423
+ return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
84376
84424
  }
84377
84425
  var iteratorType = getIntersectionType(ts.map(signatures, getReturnTypeOfSignature));
84378
- var iterationTypes = (_a = getIterationTypesOfIterator(iteratorType, resolver, errorNode)) !== null && _a !== void 0 ? _a : noIterationTypes;
84379
- 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);
84380
84428
  }
84381
84429
  function reportTypeNotIterableError(errorNode, type, allowAsyncIterables) {
84382
84430
  var message = allowAsyncIterables
84383
84431
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
84384
84432
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
84385
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84433
+ return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
84386
84434
  }
84387
84435
  /**
84388
84436
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -84390,13 +84438,29 @@ var ts;
84390
84438
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84391
84439
  * record is returned. Otherwise, `undefined` is returned.
84392
84440
  */
84393
- function getIterationTypesOfIterator(type, resolver, errorNode) {
84441
+ function getIterationTypesOfIterator(type, resolver, errorNode, errorOutputContainer) {
84442
+ return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
84443
+ }
84444
+ /**
84445
+ * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
84446
+ *
84447
+ * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
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.
84452
+ */
84453
+ function getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, noCache) {
84394
84454
  if (isTypeAny(type)) {
84395
84455
  return anyIterationTypes;
84396
84456
  }
84397
84457
  var iterationTypes = getIterationTypesOfIteratorCached(type, resolver) ||
84398
- getIterationTypesOfIteratorFast(type, resolver) ||
84399
- 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));
84400
84464
  return iterationTypes === noIterationTypes ? undefined : iterationTypes;
84401
84465
  }
84402
84466
  /**
@@ -84434,7 +84498,7 @@ var ts;
84434
84498
  // iteration types of their `next`, `return`, and `throw` methods. While we define these as `any`
84435
84499
  // and `undefined` in our libs by default, a custom lib *could* use different definitions.
84436
84500
  var globalIterationTypes = getIterationTypesOfIteratorCached(globalType, resolver) ||
84437
- getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined);
84501
+ getIterationTypesOfIteratorSlow(globalType, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined, /*noCache*/ false);
84438
84502
  var _a = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes, returnType = _a.returnType, nextType = _a.nextType;
84439
84503
  return setCachedIterationTypes(type, resolver.iteratorCacheKey, createIterationTypes(yieldType, returnType, nextType));
84440
84504
  }
@@ -84504,8 +84568,8 @@ var ts;
84504
84568
  * If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
84505
84569
  * record is returned. Otherwise, we return `undefined`.
84506
84570
  */
84507
- function getIterationTypesOfMethod(type, resolver, methodName, errorNode) {
84508
- var _a, _b, _c, _d;
84571
+ function getIterationTypesOfMethod(type, resolver, methodName, errorNode, errorOutputContainer) {
84572
+ var _a, _b, _c, _d, _e, _f;
84509
84573
  var method = getPropertyOfType(type, methodName);
84510
84574
  // Ignore 'return' or 'throw' if they are missing.
84511
84575
  if (!method && methodName !== "next") {
@@ -84525,9 +84589,15 @@ var ts;
84525
84589
  var diagnostic = methodName === "next"
84526
84590
  ? resolver.mustHaveANextMethodDiagnostic
84527
84591
  : resolver.mustBeAMethodDiagnostic;
84528
- 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
+ }
84529
84599
  }
84530
- return methodName === "next" ? anyIterationTypes : undefined;
84600
+ return methodName === "next" ? noIterationTypes : undefined;
84531
84601
  }
84532
84602
  // If the method signature comes exclusively from the global iterator or generator type,
84533
84603
  // create iteration types from its type arguments like `getIterationTypesOfIteratorFast`
@@ -84539,8 +84609,8 @@ var ts;
84539
84609
  if ((methodType === null || methodType === void 0 ? void 0 : methodType.symbol) && methodSignatures.length === 1) {
84540
84610
  var globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false);
84541
84611
  var globalIteratorType = resolver.getGlobalIteratorType(/*reportErrors*/ false);
84542
- 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;
84543
- 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;
84544
84614
  if (isGeneratorMethod || isIteratorMethod) {
84545
84615
  var globalType = isGeneratorMethod ? globalGeneratorType : globalIteratorType;
84546
84616
  var mapper = methodType.mapper;
@@ -84580,7 +84650,13 @@ var ts;
84580
84650
  var iterationTypes = getIterationTypesOfIteratorResult(resolvedMethodReturnType);
84581
84651
  if (iterationTypes === noIterationTypes) {
84582
84652
  if (errorNode) {
84583
- 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
+ }
84584
84660
  }
84585
84661
  yieldType = anyType;
84586
84662
  returnTypes = ts.append(returnTypes, anyType);
@@ -84601,13 +84677,13 @@ var ts;
84601
84677
  * NOTE: You probably don't want to call this directly and should be calling
84602
84678
  * `getIterationTypesOfIterator` instead.
84603
84679
  */
84604
- function getIterationTypesOfIteratorSlow(type, resolver, errorNode) {
84680
+ function getIterationTypesOfIteratorSlow(type, resolver, errorNode, errorOutputContainer, noCache) {
84605
84681
  var iterationTypes = combineIterationTypes([
84606
- getIterationTypesOfMethod(type, resolver, "next", errorNode),
84607
- getIterationTypesOfMethod(type, resolver, "return", errorNode),
84608
- 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),
84609
84685
  ]);
84610
- return setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84686
+ return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iteratorCacheKey, iterationTypes);
84611
84687
  }
84612
84688
  /**
84613
84689
  * Gets the requested "iteration type" from a type that is either `Iterable`-like, `Iterator`-like,
@@ -84628,7 +84704,7 @@ var ts;
84628
84704
  var use = isAsyncGenerator ? 2 /* AsyncGeneratorReturnType */ : 1 /* GeneratorReturnType */;
84629
84705
  var resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver;
84630
84706
  return getIterationTypesOfIterable(type, use, /*errorNode*/ undefined) ||
84631
- getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined);
84707
+ getIterationTypesOfIterator(type, resolver, /*errorNode*/ undefined, /*errorOutputContainer*/ undefined);
84632
84708
  }
84633
84709
  function checkBreakOrContinueStatement(node) {
84634
84710
  // Grammar checking
@@ -95085,10 +95161,11 @@ var ts;
95085
95161
  }
95086
95162
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
95087
95163
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
95088
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
95164
+ var operand = ts.skipParentheses(node.operand);
95165
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
95089
95166
  var info = void 0;
95090
- if (info = accessPrivateIdentifier(node.operand.name)) {
95091
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
95167
+ if (info = accessPrivateIdentifier(operand.name)) {
95168
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
95092
95169
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
95093
95170
  var expression = createPrivateIdentifierAccess(info, readExpression);
95094
95171
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -95104,7 +95181,7 @@ var ts;
95104
95181
  }
95105
95182
  }
95106
95183
  else if (shouldTransformSuperInStaticInitializers &&
95107
- ts.isSuperProperty(node.operand) &&
95184
+ ts.isSuperProperty(operand) &&
95108
95185
  currentStaticPropertyDeclarationOrStaticBlock &&
95109
95186
  currentClassLexicalEnvironment) {
95110
95187
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -95117,31 +95194,31 @@ var ts;
95117
95194
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
95118
95195
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
95119
95196
  if (facts & 1 /* ClassWasDecorated */) {
95120
- var operand = visitInvalidSuperProperty(node.operand);
95197
+ var expression = visitInvalidSuperProperty(operand);
95121
95198
  return ts.isPrefixUnaryExpression(node) ?
95122
- factory.updatePrefixUnaryExpression(node, operand) :
95123
- factory.updatePostfixUnaryExpression(node, operand);
95199
+ factory.updatePrefixUnaryExpression(node, expression) :
95200
+ factory.updatePostfixUnaryExpression(node, expression);
95124
95201
  }
95125
95202
  if (classConstructor && superClassReference) {
95126
95203
  var setterName = void 0;
95127
95204
  var getterName = void 0;
95128
- if (ts.isPropertyAccessExpression(node.operand)) {
95129
- if (ts.isIdentifier(node.operand.name)) {
95130
- getterName = setterName = factory.createStringLiteralFromNode(node.operand.name);
95205
+ if (ts.isPropertyAccessExpression(operand)) {
95206
+ if (ts.isIdentifier(operand.name)) {
95207
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
95131
95208
  }
95132
95209
  }
95133
95210
  else {
95134
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
95135
- getterName = setterName = node.operand.argumentExpression;
95211
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
95212
+ getterName = setterName = operand.argumentExpression;
95136
95213
  }
95137
95214
  else {
95138
95215
  getterName = factory.createTempVariable(hoistVariableDeclaration);
95139
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
95216
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
95140
95217
  }
95141
95218
  }
95142
95219
  if (setterName && getterName) {
95143
95220
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
95144
- ts.setTextRange(expression, node.operand);
95221
+ ts.setTextRange(expression, operand);
95145
95222
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
95146
95223
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
95147
95224
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117896,6 +117973,12 @@ var ts;
117896
117973
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117897
117974
  */
117898
117975
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117976
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117977
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117978
+ }
117979
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117980
+ /*@internal*/
117981
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117899
117982
  switch (ts.getEmitModuleResolutionKind(options)) {
117900
117983
  case ts.ModuleResolutionKind.Node16:
117901
117984
  case ts.ModuleResolutionKind.NodeNext:
@@ -117907,11 +117990,16 @@ var ts;
117907
117990
  return undefined;
117908
117991
  }
117909
117992
  function lookupFromPackageJson() {
117910
- var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117911
- return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117993
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117994
+ var packageJsonLocations = [];
117995
+ state.failedLookupLocations = packageJsonLocations;
117996
+ state.affectingLocations = packageJsonLocations;
117997
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117998
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117999
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117912
118000
  }
117913
118001
  }
117914
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
118002
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117915
118003
  /** @internal */
117916
118004
  ts.plainJSErrors = new ts.Set([
117917
118005
  // binder errors
@@ -118236,7 +118324,7 @@ var ts;
118236
118324
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118237
118325
  var oldSourceFile = oldSourceFiles_1[_i];
118238
118326
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118239
- if (shouldCreateNewSourceFile || !newFile ||
118327
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118240
118328
  // old file wasn't redirect but new file is
118241
118329
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118242
118330
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118629,7 +118717,7 @@ var ts;
118629
118717
  });
118630
118718
  }
118631
118719
  function tryReuseStructureFromOldProgram() {
118632
- var _a;
118720
+ var _a, _b;
118633
118721
  if (!oldProgram) {
118634
118722
  return 0 /* Not */;
118635
118723
  }
@@ -118670,12 +118758,15 @@ var ts;
118670
118758
  var seenPackageNames = new ts.Map();
118671
118759
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118672
118760
  var oldSourceFile = oldSourceFiles_2[_i];
118761
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118673
118762
  var newSourceFile = host.getSourceFileByPath
118674
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
118675
- : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
118763
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118764
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118676
118765
  if (!newSourceFile) {
118677
118766
  return 0 /* Not */;
118678
118767
  }
118768
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118769
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118679
118770
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118680
118771
  var fileChanged = void 0;
118681
118772
  if (oldSourceFile.redirectInfo) {
@@ -118715,38 +118806,43 @@ var ts;
118715
118806
  seenPackageNames.set(packageName, newKind);
118716
118807
  }
118717
118808
  if (fileChanged) {
118809
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118810
+ structureIsReused = 1 /* SafeModules */;
118811
+ }
118718
118812
  // The `newSourceFile` object was created for the new program.
118719
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118813
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118720
118814
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118721
118815
  structureIsReused = 1 /* SafeModules */;
118722
118816
  }
118723
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118817
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118724
118818
  // value of no-default-lib has changed
118725
118819
  // this will affect if default library is injected into the list of files
118726
118820
  structureIsReused = 1 /* SafeModules */;
118727
118821
  }
118728
118822
  // check tripleslash references
118729
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118823
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118730
118824
  // tripleslash references has changed
118731
118825
  structureIsReused = 1 /* SafeModules */;
118732
118826
  }
118733
- // check imports and module augmentations
118734
- collectExternalModuleReferences(newSourceFile);
118735
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118736
- // imports has changed
118737
- structureIsReused = 1 /* SafeModules */;
118738
- }
118739
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118740
- // moduleAugmentations has changed
118741
- structureIsReused = 1 /* SafeModules */;
118742
- }
118743
- if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118744
- // dynamicImport has changed
118745
- structureIsReused = 1 /* SafeModules */;
118746
- }
118747
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118748
- // 'types' references has changed
118749
- structureIsReused = 1 /* SafeModules */;
118827
+ else {
118828
+ // check imports and module augmentations
118829
+ collectExternalModuleReferences(newSourceFile);
118830
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118831
+ // imports has changed
118832
+ structureIsReused = 1 /* SafeModules */;
118833
+ }
118834
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118835
+ // moduleAugmentations has changed
118836
+ structureIsReused = 1 /* SafeModules */;
118837
+ }
118838
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118839
+ // dynamicImport has changed
118840
+ structureIsReused = 1 /* SafeModules */;
118841
+ }
118842
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118843
+ // 'types' references has changed
118844
+ structureIsReused = 1 /* SafeModules */;
118845
+ }
118750
118846
  }
118751
118847
  // tentatively approve the file
118752
118848
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118764,18 +118860,18 @@ var ts;
118764
118860
  return structureIsReused;
118765
118861
  }
118766
118862
  var modifiedFiles = modifiedSourceFiles.map(function (f) { return f.oldFile; });
118767
- for (var _b = 0, oldSourceFiles_3 = oldSourceFiles; _b < oldSourceFiles_3.length; _b++) {
118768
- var oldFile = oldSourceFiles_3[_b];
118863
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118864
+ var oldFile = oldSourceFiles_3[_c];
118769
118865
  if (!ts.contains(modifiedFiles, oldFile)) {
118770
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118771
- var moduleName = _d[_c];
118866
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118867
+ var moduleName = _e[_d];
118772
118868
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118773
118869
  }
118774
118870
  }
118775
118871
  }
118776
118872
  // try to verify results of module resolution
118777
- for (var _e = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _e < modifiedSourceFiles_1.length; _e++) {
118778
- var _f = modifiedSourceFiles_1[_e], oldSourceFile = _f.oldFile, newSourceFile = _f.newFile;
118873
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118874
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118779
118875
  var moduleNames = getModuleNames(newSourceFile);
118780
118876
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118781
118877
  // ensure that module resolution results are still correct
@@ -118802,14 +118898,14 @@ var ts;
118802
118898
  if (structureIsReused !== 2 /* Completely */) {
118803
118899
  return structureIsReused;
118804
118900
  }
118805
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118901
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118806
118902
  return 1 /* SafeModules */;
118807
118903
  }
118808
118904
  missingFilePaths = oldProgram.getMissingFilePaths();
118809
118905
  // update fileName -> file mapping
118810
118906
  ts.Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
118811
- for (var _g = 0, newSourceFiles_1 = newSourceFiles; _g < newSourceFiles_1.length; _g++) {
118812
- var newSourceFile = newSourceFiles_1[_g];
118907
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118908
+ var newSourceFile = newSourceFiles_1[_h];
118813
118909
  filesByName.set(newSourceFile.path, newSourceFile);
118814
118910
  }
118815
118911
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119592,13 +119688,16 @@ var ts;
119592
119688
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119593
119689
  }
119594
119690
  }
119595
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119691
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119692
+ var _a;
119596
119693
  var redirect = Object.create(redirectTarget);
119597
119694
  redirect.fileName = fileName;
119598
119695
  redirect.path = path;
119599
119696
  redirect.resolvedPath = resolvedPath;
119600
119697
  redirect.originalFileName = originalFileName;
119601
119698
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119699
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119700
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119602
119701
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119603
119702
  Object.defineProperties(redirect, {
119604
119703
  id: {
@@ -119627,14 +119726,14 @@ var ts;
119627
119726
  // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
119628
119727
  // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
119629
119728
  // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
119630
- var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119631
- return {
119632
- languageVersion: ts.getEmitScriptTarget(options),
119633
- impliedNodeFormat: impliedNodeFormat,
119634
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
119635
- };
119729
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119730
+ var languageVersion = ts.getEmitScriptTarget(options);
119731
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119732
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119733
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119636
119734
  }
119637
119735
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119736
+ var _a, _b;
119638
119737
  var path = toPath(fileName);
119639
119738
  if (useSourceOfProjectReferenceRedirect) {
119640
119739
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119721,14 +119820,15 @@ var ts;
119721
119820
  }
119722
119821
  }
119723
119822
  // We haven't looked for this file, do so now and cache result
119724
- var file = host.getSourceFile(fileName, getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options), function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile);
119823
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119824
+ var file = host.getSourceFile(fileName, sourceFileOptions, function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile || (((_a = oldProgram === null || oldProgram === void 0 ? void 0 : oldProgram.getSourceFileByPath(toPath(fileName))) === null || _a === void 0 ? void 0 : _a.impliedNodeFormat) !== sourceFileOptions.impliedNodeFormat));
119725
119825
  if (packageId) {
119726
119826
  var packageIdKey = ts.packageIdToString(packageId);
119727
119827
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119728
119828
  if (fileFromPackageId) {
119729
119829
  // Some other SourceFile already exists with this package name and version.
119730
119830
  // Instead of creating a duplicate, just redirect to the existing one.
119731
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName); // TODO: GH#18217
119831
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119732
119832
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119733
119833
  addFileToFilesByName(dupFile, path, redirectedPath);
119734
119834
  addFileIncludeReason(dupFile, reason);
@@ -119749,6 +119849,8 @@ var ts;
119749
119849
  file.path = path;
119750
119850
  file.resolvedPath = toPath(fileName);
119751
119851
  file.originalFileName = originalFileName;
119852
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119853
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119752
119854
  addFileIncludeReason(file, reason);
119753
119855
  if (host.useCaseSensitiveFileNames()) {
119754
119856
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120379,7 +120481,7 @@ var ts;
120379
120481
  fileIncludeReasons = undefined;
120380
120482
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120381
120483
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120382
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120484
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120383
120485
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120384
120486
  return location && isReferenceFileLocation(location) ?
120385
120487
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122684,7 +122786,7 @@ var ts;
122684
122786
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122685
122787
  * @param dirPath
122686
122788
  */
122687
- function canWatchDirectory(dirPath) {
122789
+ function canWatchDirectoryOrFile(dirPath) {
122688
122790
  var rootLength = ts.getRootLength(dirPath);
122689
122791
  if (dirPath.length === rootLength) {
122690
122792
  // Ignore "/", "c:/"
@@ -122721,7 +122823,7 @@ var ts;
122721
122823
  }
122722
122824
  return true;
122723
122825
  }
122724
- ts.canWatchDirectory = canWatchDirectory;
122826
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122725
122827
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122726
122828
  var filesWithChangedSetOfUnresolvedImports;
122727
122829
  var filesWithInvalidatedResolutions;
@@ -122730,7 +122832,9 @@ var ts;
122730
122832
  var resolutionsWithFailedLookups = [];
122731
122833
  var resolutionsWithOnlyAffectingLocations = [];
122732
122834
  var resolvedFileToResolution = ts.createMultiMap();
122835
+ var impliedFormatPackageJsons = new ts.Map();
122733
122836
  var hasChangedAutomaticTypeDirectiveNames = false;
122837
+ var affectingPathChecksForFile;
122734
122838
  var affectingPathChecks;
122735
122839
  var failedLookupChecks;
122736
122840
  var startsWithPathChecks;
@@ -122770,7 +122874,7 @@ var ts;
122770
122874
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122771
122875
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122772
122876
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122773
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122877
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122774
122878
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122775
122879
  resolveModuleNames: resolveModuleNames,
122776
122880
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122814,9 +122918,10 @@ var ts;
122814
122918
  startsWithPathChecks = undefined;
122815
122919
  isInDirectoryChecks = undefined;
122816
122920
  affectingPathChecks = undefined;
122817
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122818
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122819
- clearPerDirectoryResolutions();
122921
+ affectingPathChecksForFile = undefined;
122922
+ moduleResolutionCache.clear();
122923
+ typeReferenceDirectiveResolutionCache.clear();
122924
+ impliedFormatPackageJsons.clear();
122820
122925
  hasChangedAutomaticTypeDirectiveNames = false;
122821
122926
  }
122822
122927
  function startRecordingFilesWithChangedResolutions() {
@@ -122848,15 +122953,44 @@ var ts;
122848
122953
  return function (path) { return (!!collected && collected.has(path)) ||
122849
122954
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122850
122955
  }
122851
- function clearPerDirectoryResolutions() {
122852
- moduleResolutionCache.clear();
122853
- typeReferenceDirectiveResolutionCache.clear();
122956
+ function startCachingPerDirectoryResolution() {
122957
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122958
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122959
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122960
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122854
122961
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122855
122962
  nonRelativeExternalModuleResolutions.clear();
122856
122963
  }
122857
- function finishCachingPerDirectoryResolution() {
122964
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122858
122965
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122859
- clearPerDirectoryResolutions();
122966
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122967
+ nonRelativeExternalModuleResolutions.clear();
122968
+ // Update file watches
122969
+ if (newProgram !== oldProgram) {
122970
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122971
+ var _a, _b, _c;
122972
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122973
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122974
+ for (var i = existing.length; i < expected; i++) {
122975
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122976
+ }
122977
+ if (existing.length > expected) {
122978
+ for (var i = expected; i < existing.length; i++) {
122979
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122980
+ }
122981
+ }
122982
+ if (expected)
122983
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122984
+ else
122985
+ impliedFormatPackageJsons.delete(newFile.path);
122986
+ });
122987
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122988
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122989
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122990
+ impliedFormatPackageJsons.delete(path);
122991
+ }
122992
+ });
122993
+ }
122860
122994
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122861
122995
  if (watcher.refCount === 0) {
122862
122996
  directoryWatchesOfFailedLookups.delete(path);
@@ -122864,11 +122998,9 @@ var ts;
122864
122998
  }
122865
122999
  });
122866
123000
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122867
- if (watcher.refCount === 0) {
123001
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122868
123002
  fileWatchesOfAffectingLocations.delete(path);
122869
123003
  watcher.watcher.close();
122870
- // Ensure when watching symlinked package.json, we can close the actual file watcher only once
122871
- watcher.watcher = ts.noopFileWatcher;
122872
123004
  }
122873
123005
  });
122874
123006
  hasChangedAutomaticTypeDirectiveNames = false;
@@ -123095,7 +123227,7 @@ var ts;
123095
123227
  }
123096
123228
  // If the directory is node_modules use it to watch, always watch it recursively
123097
123229
  if (ts.isNodeModulesDirectory(dirPath)) {
123098
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123230
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123099
123231
  }
123100
123232
  var nonRecursive = true;
123101
123233
  // Use some ancestor of the root directory
@@ -123113,7 +123245,7 @@ var ts;
123113
123245
  dir = ts.getDirectoryPath(dir);
123114
123246
  }
123115
123247
  }
123116
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123248
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123117
123249
  }
123118
123250
  function isPathWithDefaultFailedLookupExtension(path) {
123119
123251
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -123184,46 +123316,65 @@ var ts;
123184
123316
  // Watch package json
123185
123317
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
123186
123318
  var affectingLocation = affectingLocations_1[_i];
123187
- createFileWatcherOfAffectingLocation(affectingLocation);
123319
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
123188
123320
  }
123189
123321
  }
123190
- function createFileWatcherOfAffectingLocation(affectingLocation) {
123191
- var path = resolutionHost.toPath(affectingLocation);
123192
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123322
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123323
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123193
123324
  if (fileWatcher) {
123194
- fileWatcher.refCount++;
123325
+ if (forResolution)
123326
+ fileWatcher.resolutions++;
123327
+ else
123328
+ fileWatcher.files++;
123195
123329
  return;
123196
123330
  }
123197
123331
  var locationToWatch = affectingLocation;
123198
- var locationToWatchPath = path;
123199
123332
  if (resolutionHost.realpath) {
123200
123333
  locationToWatch = resolutionHost.realpath(affectingLocation);
123201
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123202
- if (path !== locationToWatchPath) {
123203
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123334
+ if (affectingLocation !== locationToWatch) {
123335
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123204
123336
  if (fileWatcher_1) {
123205
- fileWatcher_1.refCount++;
123206
- fileWatcher_1.paths.add(path);
123207
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123337
+ if (forResolution)
123338
+ fileWatcher_1.resolutions++;
123339
+ else
123340
+ fileWatcher_1.files++;
123341
+ fileWatcher_1.paths.add(affectingLocation);
123342
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123208
123343
  return;
123209
123344
  }
123210
123345
  }
123211
123346
  }
123212
123347
  var paths = new ts.Set();
123213
- paths.add(locationToWatchPath);
123214
- var watcher = {
123215
- watcher: resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123216
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, path, eventKind);
123217
- paths.forEach(function (path) { return (affectingPathChecks || (affectingPathChecks = new ts.Set())).add(path); });
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
+ });
123218
123360
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123219
- }),
123220
- refCount: 1,
123361
+ }) : ts.noopFileWatcher;
123362
+ var watcher = {
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,
123370
+ resolutions: forResolution ? 1 : 0,
123371
+ files: forResolution ? 0 : 1,
123221
123372
  paths: paths,
123222
123373
  };
123223
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123224
- if (path !== locationToWatchPath) {
123225
- fileWatchesOfAffectingLocations.set(path, watcher);
123226
- paths.add(path);
123374
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123375
+ if (affectingLocation !== locationToWatch) {
123376
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123377
+ paths.add(affectingLocation);
123227
123378
  }
123228
123379
  }
123229
123380
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123291,8 +123442,8 @@ var ts;
123291
123442
  }
123292
123443
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123293
123444
  var affectingLocation = affectingLocations_2[_a];
123294
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123295
- watcher.refCount--;
123445
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123446
+ watcher.resolutions--;
123296
123447
  }
123297
123448
  }
123298
123449
  function removeDirectoryWatcher(dirPath) {
@@ -123346,7 +123497,7 @@ var ts;
123346
123497
  resolution.isInvalidated = invalidated = true;
123347
123498
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123348
123499
  var containingFilePath = _b[_a];
123349
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123500
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123350
123501
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123351
123502
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123352
123503
  }
@@ -123413,10 +123564,25 @@ var ts;
123413
123564
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123414
123565
  }
123415
123566
  function invalidateResolutionsOfFailedLookupLocations() {
123567
+ var _a;
123568
+ var invalidated = false;
123569
+ if (affectingPathChecksForFile) {
123570
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123571
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123572
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123573
+ invalidated = true;
123574
+ }
123575
+ });
123576
+ affectingPathChecksForFile = undefined;
123577
+ }
123416
123578
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123417
- return false;
123579
+ return invalidated;
123580
+ }
123581
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123582
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123583
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123584
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123418
123585
  }
123419
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123420
123586
  failedLookupChecks = undefined;
123421
123587
  startsWithPathChecks = undefined;
123422
123588
  isInDirectoryChecks = undefined;
@@ -123429,17 +123595,15 @@ var ts;
123429
123595
  return true;
123430
123596
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123431
123597
  return false;
123432
- return resolution.failedLookupLocations.some(function (location) {
123433
- var locationPath = resolutionHost.toPath(location);
123434
- return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123435
- ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123436
- ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123437
- });
123598
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123599
+ }
123600
+ function isInvalidatedFailedLookup(locationPath) {
123601
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123602
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123603
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123438
123604
  }
123439
123605
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123440
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123441
- return affectingPathChecks.has(resolutionHost.toPath(location));
123442
- });
123606
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123443
123607
  }
123444
123608
  function closeTypeRootsWatch() {
123445
123609
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123505,7 +123669,7 @@ var ts;
123505
123669
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123506
123670
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123507
123671
  var dirPath = resolutionHost.toPath(dir);
123508
- return dirPath === rootPath || canWatchDirectory(dirPath);
123672
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123509
123673
  }
123510
123674
  }
123511
123675
  ts.createResolutionCache = createResolutionCache;
@@ -123616,7 +123780,7 @@ var ts;
123616
123780
  var info = getInfo(importingSourceFileName, host);
123617
123781
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
123618
123782
  return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
123619
- getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
123783
+ getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123620
123784
  }
123621
123785
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
123622
123786
  if (options === void 0) { options = {}; }
@@ -123699,7 +123863,7 @@ var ts;
123699
123863
  return nodeModulesSpecifiers;
123700
123864
  }
123701
123865
  if (!specifier && !modulePath.isRedirect) {
123702
- var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
123866
+ var local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
123703
123867
  if (ts.pathIsBareSpecifier(local)) {
123704
123868
  pathsSpecifiers = ts.append(pathsSpecifiers, local);
123705
123869
  }
@@ -123727,7 +123891,7 @@ var ts;
123727
123891
  var sourceDirectory = ts.getDirectoryPath(importingSourceFileName);
123728
123892
  return { getCanonicalFileName: getCanonicalFileName, importingSourceFileName: importingSourceFileName, sourceDirectory: sourceDirectory };
123729
123893
  }
123730
- function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, _a) {
123894
+ function getLocalModuleSpecifier(moduleFileName, info, compilerOptions, host, importMode, _a) {
123731
123895
  var ending = _a.ending, relativePreference = _a.relativePreference;
123732
123896
  var baseUrl = compilerOptions.baseUrl, paths = compilerOptions.paths, rootDirs = compilerOptions.rootDirs;
123733
123897
  var sourceDirectory = info.sourceDirectory, getCanonicalFileName = info.getCanonicalFileName;
@@ -123741,9 +123905,8 @@ var ts;
123741
123905
  if (!relativeToBaseUrl) {
123742
123906
  return relativePath;
123743
123907
  }
123744
- var importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, ending, compilerOptions);
123745
- var fromPaths = paths && tryGetModuleNameFromPaths(ts.removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
123746
- 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;
123747
123910
  if (!nonRelative) {
123748
123911
  return relativePath;
123749
123912
  }
@@ -123978,28 +124141,102 @@ var ts;
123978
124141
  return ambientModuleDeclare.name.text;
123979
124142
  }
123980
124143
  }
123981
- 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) {
123982
124156
  for (var key in paths) {
123983
- for (var _i = 0, _a = paths[key]; _i < _a.length; _i++) {
123984
- var patternText_1 = _a[_i];
123985
- var pattern = ts.removeFileExtension(ts.normalizePath(patternText_1));
124157
+ var _loop_36 = function (patternText_1) {
124158
+ var pattern = ts.normalizePath(patternText_1);
123986
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
+ }
123987
124203
  if (indexOfStar !== -1) {
123988
- var prefix = pattern.substr(0, indexOfStar);
123989
- var suffix = pattern.substr(indexOfStar + 1);
123990
- if (relativeToBaseUrl.length >= prefix.length + suffix.length &&
123991
- ts.startsWith(relativeToBaseUrl, prefix) &&
123992
- ts.endsWith(relativeToBaseUrl, suffix) ||
123993
- !suffix && relativeToBaseUrl === ts.removeTrailingDirectorySeparator(prefix)) {
123994
- var matchedStar = relativeToBaseUrl.substr(prefix.length, relativeToBaseUrl.length - suffix.length - prefix.length);
123995
- 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
+ }
123996
124215
  }
123997
124216
  }
123998
- else if (pattern === relativeToBaseUrl || pattern === relativeToBaseUrlWithIndex) {
123999
- 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 };
124000
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;
124001
124227
  }
124002
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
+ }
124003
124240
  }
124004
124241
  var MatchingMode;
124005
124242
  (function (MatchingMode) {
@@ -124095,10 +124332,10 @@ var ts;
124095
124332
  return undefined;
124096
124333
  }
124097
124334
  // Simplify the full file path to something that can be resolved by Node.
124335
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124098
124336
  var moduleSpecifier = path;
124099
124337
  var isPackageRootPath = false;
124100
124338
  if (!packageNameOnly) {
124101
- var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
124102
124339
  var packageRootIndex = parts.packageRootIndex;
124103
124340
  var moduleFileName = void 0;
124104
124341
  while (true) {
@@ -124147,15 +124384,13 @@ var ts;
124147
124384
  var packageRootPath = path.substring(0, packageRootIndex);
124148
124385
  var packageJsonPath = ts.combinePaths(packageRootPath, "package.json");
124149
124386
  var moduleFileToTry = path;
124387
+ var maybeBlockedByTypesVersions = false;
124150
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);
124151
124389
  if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
124152
124390
  var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath));
124391
+ var importMode = overrideMode || importingSourceFile.impliedNodeFormat;
124153
124392
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
124154
- // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
124155
- // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
124156
- // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
124157
- // with, so for now we just stick with the mode of the file.
124158
- var conditions = ["node", overrideMode || importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124393
+ var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"];
124159
124394
  var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
124160
124395
  ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
124161
124396
  : undefined;
@@ -124174,16 +124409,26 @@ var ts;
124174
124409
  : undefined;
124175
124410
  if (versionPaths) {
124176
124411
  var subModuleName = path.slice(packageRootPath.length + 1);
124177
- var fromPaths = tryGetModuleNameFromPaths(ts.removeFileExtension(subModuleName), removeExtensionAndIndexPostFix(subModuleName, 0 /* Minimal */, options), versionPaths.paths);
124178
- 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 {
124179
124417
  moduleFileToTry = ts.combinePaths(packageRootPath, fromPaths);
124180
124418
  }
124181
124419
  }
124182
124420
  // If the file is the main module, it can be imported by the package name
124183
124421
  var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
124184
- 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.)
124185
124429
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
124186
124430
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
124431
+ // ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
124187
124432
  return { packageRootPath: packageRootPath, moduleFileToTry: moduleFileToTry };
124188
124433
  }
124189
124434
  }
@@ -124478,23 +124723,46 @@ var ts;
124478
124723
  var file = _c[_i];
124479
124724
  write("" + toFileName(file, relativeFileName));
124480
124725
  (_a = reasons.get(file.path)) === null || _a === void 0 ? void 0 : _a.forEach(function (reason) { return write(" " + fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText); });
124481
- (_b = explainIfFileIsRedirect(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124726
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124482
124727
  }
124483
124728
  }
124484
124729
  ts.explainFiles = explainFiles;
124485
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124730
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124731
+ var _a;
124486
124732
  var result;
124487
124733
  if (file.path !== file.resolvedPath) {
124488
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124734
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124489
124735
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124490
124736
  }
124491
124737
  if (file.redirectInfo) {
124492
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124738
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124493
124739
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124494
124740
  }
124741
+ if (ts.isExternalOrCommonJsModule(file)) {
124742
+ switch (file.impliedNodeFormat) {
124743
+ case ts.ModuleKind.ESNext:
124744
+ if (file.packageJsonScope) {
124745
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124746
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124747
+ }
124748
+ break;
124749
+ case ts.ModuleKind.CommonJS:
124750
+ if (file.packageJsonScope) {
124751
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124752
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124753
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124754
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124755
+ }
124756
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124757
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124758
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124759
+ }
124760
+ break;
124761
+ }
124762
+ }
124495
124763
  return result;
124496
124764
  }
124497
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124765
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124498
124766
  function getMatchedFileSpec(program, fileName) {
124499
124767
  var _a;
124500
124768
  var configFile = program.getCompilerOptions().configFile;
@@ -124704,6 +124972,7 @@ var ts;
124704
124972
  MissingFile: "Missing file",
124705
124973
  WildcardDirectory: "Wild card directory",
124706
124974
  FailedLookupLocations: "Failed Lookup Locations",
124975
+ AffectingFileLocation: "File location affecting resolution",
124707
124976
  TypeRoots: "Type roots",
124708
124977
  ConfigFileOfReferencedProject: "Config file of referened project",
124709
124978
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -125027,7 +125296,7 @@ var ts;
125027
125296
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
125028
125297
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
125029
125298
  compilerHost.watchDirectoryOfFailedLookupLocation = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.FailedLookupLocations); };
125030
- compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.PackageJson); };
125299
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
125031
125300
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
125032
125301
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
125033
125302
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -125061,6 +125330,9 @@ var ts;
125061
125330
  return host.resolveTypeReferenceDirectives.apply(host, args);
125062
125331
  }) :
125063
125332
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
125333
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
125334
+ ts.maybeBind(host, host.getModuleResolutionCache) :
125335
+ (function () { return resolutionCache.getModuleResolutionCache(); });
125064
125336
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
125065
125337
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
125066
125338
  synchronizeProgram();
@@ -125163,8 +125435,9 @@ var ts;
125163
125435
  resolutionCache.startCachingPerDirectoryResolution();
125164
125436
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
125165
125437
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125438
+ var oldProgram = getCurrentProgram();
125166
125439
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
125167
- resolutionCache.finishCachingPerDirectoryResolution();
125440
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
125168
125441
  // Update watches
125169
125442
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
125170
125443
  if (needsUpdateInTypeRootWatch) {
@@ -125246,9 +125519,6 @@ var ts;
125246
125519
  sourceFilesCache.set(path, false);
125247
125520
  }
125248
125521
  }
125249
- if (sourceFile) {
125250
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125251
- }
125252
125522
  return sourceFile;
125253
125523
  }
125254
125524
  return hostSourceFile.sourceFile;
@@ -125764,6 +126034,7 @@ var ts;
125764
126034
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125765
126035
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125766
126036
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
126037
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125767
126038
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125768
126039
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125769
126040
  if (!compilerHost.resolveModuleNames) {
@@ -137982,60 +138253,64 @@ var ts;
137982
138253
  }
137983
138254
  return settingsOrHost;
137984
138255
  }
137985
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138256
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137986
138257
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137987
138258
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137988
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138259
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137989
138260
  }
137990
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137991
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
138261
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138262
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137992
138263
  }
137993
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138264
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137994
138265
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137995
138266
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137996
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138267
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137997
138268
  }
137998
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137999
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
138269
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138270
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
138000
138271
  }
138001
138272
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
138002
138273
  var entry = isDocumentRegistryEntry(bucketEntry) ? bucketEntry : bucketEntry.get(ts.Debug.checkDefined(scriptKind, "If there are more than one scriptKind's for same document the scriptKind should be provided"));
138003
138274
  ts.Debug.assert(scriptKind === undefined || !entry || entry.sourceFile.scriptKind === scriptKind, "Script kind should match provided ScriptKind:" + scriptKind + " and sourceFile.scriptKind: " + (entry === null || entry === void 0 ? void 0 : entry.sourceFile.scriptKind) + ", !entry: " + !entry);
138004
138275
  return entry;
138005
138276
  }
138006
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
138277
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
138007
138278
  var _a, _b, _c, _d;
138008
138279
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
138009
138280
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
138010
138281
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
138011
138282
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
138012
- var sourceFileOptions = {
138013
- languageVersion: scriptTarget,
138014
- impliedNodeFormat: host && ts.getImpliedNodeFormatForFile(path, (_d = (_c = (_b = (_a = host.getCompilerHost) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getModuleResolutionCache) === null || _c === void 0 ? void 0 : _c.call(_b)) === null || _d === void 0 ? void 0 : _d.getPackageJsonInfoCache(), host, compilationSettings),
138015
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138016
- };
138283
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
138284
+ languageVersionOrOptions :
138285
+ {
138286
+ languageVersion: scriptTarget,
138287
+ impliedNodeFormat: host && ts.getImpliedNodeFormatForFile(path, (_d = (_c = (_b = (_a = host.getCompilerHost) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getModuleResolutionCache) === null || _c === void 0 ? void 0 : _c.call(_b)) === null || _d === void 0 ? void 0 : _d.getPackageJsonInfoCache(), host, compilationSettings),
138288
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138289
+ };
138290
+ sourceFileOptions.languageVersion = scriptTarget;
138017
138291
  var oldBucketCount = buckets.size;
138018
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
138292
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
138293
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
138019
138294
  if (ts.tracing) {
138020
138295
  if (buckets.size > oldBucketCount) {
138021
138296
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
138022
138297
  // perhaps they are for two projects that don't have any overlap.
138023
138298
  // Bonus: these events can help us interpret the more interesting event below.
138024
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
138299
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
138025
138300
  }
138026
138301
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
138027
138302
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
138028
138303
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
138029
138304
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
138030
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
138305
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
138031
138306
  if (otherBucketKey) {
138032
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
138307
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
138033
138308
  }
138034
138309
  }
138035
138310
  var bucketEntry = bucket.get(path);
138036
138311
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
138037
138312
  if (!entry && externalCache) {
138038
- var sourceFile = externalCache.getDocument(key, path);
138313
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
138039
138314
  if (sourceFile) {
138040
138315
  ts.Debug.assert(acquiring);
138041
138316
  entry = {
@@ -138049,7 +138324,7 @@ var ts;
138049
138324
  // Have never seen this file with these settings. Create a new source file for it.
138050
138325
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
138051
138326
  if (externalCache) {
138052
- externalCache.setDocument(key, path, sourceFile);
138327
+ externalCache.setDocument(keyWithMode, path, sourceFile);
138053
138328
  }
138054
138329
  entry = {
138055
138330
  sourceFile: sourceFile,
@@ -138064,7 +138339,7 @@ var ts;
138064
138339
  if (entry.sourceFile.version !== version) {
138065
138340
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
138066
138341
  if (externalCache) {
138067
- externalCache.setDocument(key, path, entry.sourceFile);
138342
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
138068
138343
  }
138069
138344
  }
138070
138345
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -138093,13 +138368,13 @@ var ts;
138093
138368
  }
138094
138369
  }
138095
138370
  }
138096
- function releaseDocument(fileName, compilationSettings, scriptKind) {
138371
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
138097
138372
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
138098
138373
  var key = getKeyForCompilationSettings(compilationSettings);
138099
- return releaseDocumentWithKey(path, key, scriptKind);
138374
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
138100
138375
  }
138101
- function releaseDocumentWithKey(path, key, scriptKind) {
138102
- var bucket = ts.Debug.checkDefined(buckets.get(key));
138376
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
138377
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
138103
138378
  var bucketEntry = bucket.get(path);
138104
138379
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
138105
138380
  entry.languageServiceRefCount--;
@@ -138156,6 +138431,9 @@ var ts;
138156
138431
  function getKeyForCompilationSettings(settings) {
138157
138432
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
138158
138433
  }
138434
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
138435
+ return (mode ? key + "|" + mode : key);
138436
+ }
138159
138437
  })(ts || (ts = {}));
138160
138438
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
138161
138439
  /* @internal */
@@ -162215,6 +162493,9 @@ var ts;
162215
162493
  if (!containingDecl) {
162216
162494
  return;
162217
162495
  }
162496
+ if (ts.isFunctionLikeDeclaration(containingDecl) && containingDecl.body && ts.rangeContainsPosition(containingDecl.body, startPosition)) {
162497
+ return;
162498
+ }
162218
162499
  var checker = program.getTypeChecker();
162219
162500
  var signatureSymbol = containingDecl.symbol;
162220
162501
  if (!signatureSymbol) {
@@ -167399,12 +167680,12 @@ var ts;
167399
167680
  // not part of the new program.
167400
167681
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
167401
167682
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
167402
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
167683
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167403
167684
  }
167404
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
167405
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
167685
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
167686
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
167406
167687
  }
167407
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
167688
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
167408
167689
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
167409
167690
  // The program is asking for this file, check first if the host can locate it.
167410
167691
  // If the host can not locate the file, then it does not exist. return undefined
@@ -167447,17 +167728,17 @@ var ts;
167447
167728
  // file's script kind, i.e. in one project some file is treated as ".ts"
167448
167729
  // and in another as ".js"
167449
167730
  if (scriptKind === oldSourceFile.scriptKind) {
167450
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167731
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167451
167732
  }
167452
167733
  else {
167453
167734
  // Release old source file and fall through to aquire new file with new script kind
167454
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind);
167735
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167455
167736
  }
167456
167737
  }
167457
167738
  // We didn't already have the file. Fall through and acquire it from the registry.
167458
167739
  }
167459
167740
  // Could not find this file in the old program, create a new SourceFile for it.
167460
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167741
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167461
167742
  }
167462
167743
  }
167463
167744
  // TODO: GH#18217 frequently asserted as defined
@@ -167536,7 +167817,7 @@ var ts;
167536
167817
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
167537
167818
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
167538
167819
  ts.forEach(program.getSourceFiles(), function (f) {
167539
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167820
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
167540
167821
  });
167541
167822
  program = undefined; // TODO: GH#18217
167542
167823
  }
@@ -168453,6 +168734,7 @@ var ts;
168453
168734
  getEmitOutput: getEmitOutput,
168454
168735
  getNonBoundSourceFile: getNonBoundSourceFile,
168455
168736
  getProgram: getProgram,
168737
+ getCurrentProgram: function () { return program; },
168456
168738
  getAutoImportProvider: getAutoImportProvider,
168457
168739
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
168458
168740
  getApplicableRefactors: getApplicableRefactors,
@@ -171670,7 +171952,7 @@ var ts;
171670
171952
  };
171671
171953
  /*@internal*/
171672
171954
  Project.prototype.watchAffectingFileLocation = function (file, cb) {
171673
- return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.PackageJson, this);
171955
+ return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.AffectingFileLocation, this);
171674
171956
  };
171675
171957
  /*@internal*/
171676
171958
  Project.prototype.clearInvalidateResolutionOfFailedLookupTimer = function () {
@@ -172207,7 +172489,7 @@ var ts;
172207
172489
  };
172208
172490
  Project.prototype.updateGraphWorker = function () {
172209
172491
  var _this = this;
172210
- var oldProgram = this.program;
172492
+ var oldProgram = this.languageService.getCurrentProgram();
172211
172493
  ts.Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
172212
172494
  this.writeLog("Starting updateGraphWorker: Project: " + this.getProjectName());
172213
172495
  var start = ts.timestamp();
@@ -172216,7 +172498,7 @@ var ts;
172216
172498
  this.program = this.languageService.getProgram(); // TODO: GH#18217
172217
172499
  this.dirty = false;
172218
172500
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "finishCachingPerDirectoryResolution");
172219
- this.resolutionCache.finishCachingPerDirectoryResolution();
172501
+ this.resolutionCache.finishCachingPerDirectoryResolution(this.program, oldProgram);
172220
172502
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
172221
172503
  ts.Debug.assert(oldProgram === undefined || this.program !== undefined);
172222
172504
  // bump up the version if
@@ -174674,7 +174956,7 @@ var ts;
174674
174956
  // created when any of the script infos are added as root of inferred project
174675
174957
  if (this.configFileExistenceImpactsRootOfInferredProject(configFileExistenceInfo)) {
174676
174958
  // If we cannot watch config file existence without configured project, close the configured file watcher
174677
- if (!ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath))) {
174959
+ if (!ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath))) {
174678
174960
  configFileExistenceInfo.watcher.close();
174679
174961
  configFileExistenceInfo.watcher = noopConfigFileWatcher;
174680
174962
  }
@@ -174754,7 +175036,7 @@ var ts;
174754
175036
  // Set this file as the root of inferred project
174755
175037
  (configFileExistenceInfo.openFilesImpactedByConfigFile || (configFileExistenceInfo.openFilesImpactedByConfigFile = new ts.Map())).set(info.path, true);
174756
175038
  // If there is no configured project for this config file, add the file watcher
174757
- configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath)) ?
175039
+ configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174758
175040
  _this.watchFactory.watchFile(configFileName, function (_filename, eventKind) { return _this.onConfigFileChanged(canonicalConfigFilePath, eventKind); }, ts.PollingInterval.High, _this.hostConfiguration.watchOptions, ts.WatchType.ConfigFileForInferredRoot) :
174759
175041
  noopConfigFileWatcher);
174760
175042
  });