typescript 4.8.0-dev.20220731 → 4.8.0-dev.20220803

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220731";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220803";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8756,6 +8756,10 @@ var ts;
8756
8756
  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."),
8757
8757
  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`."),
8758
8758
  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 '**/*'"),
8759
+ 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\""),
8760
+ 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\""),
8761
+ 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\""),
8762
+ 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"),
8759
8763
  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."),
8760
8764
  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."),
8761
8765
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -43433,7 +43437,7 @@ var ts;
43433
43437
  ts.createCacheWithRedirects = createCacheWithRedirects;
43434
43438
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
43435
43439
  var cache;
43436
- return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries };
43440
+ return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries, getInternalMap: getInternalMap };
43437
43441
  function getPackageJsonInfo(packageJsonPath) {
43438
43442
  return cache === null || cache === void 0 ? void 0 : cache.get(ts.toPath(packageJsonPath, currentDirectory, getCanonicalFileName));
43439
43443
  }
@@ -43447,6 +43451,9 @@ var ts;
43447
43451
  var iter = cache === null || cache === void 0 ? void 0 : cache.entries();
43448
43452
  return iter ? ts.arrayFrom(iter) : [];
43449
43453
  }
43454
+ function getInternalMap() {
43455
+ return cache;
43456
+ }
43450
43457
  }
43451
43458
  function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create) {
43452
43459
  var cache = cacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
@@ -43550,15 +43557,18 @@ var ts;
43550
43557
  }
43551
43558
  ts.zipToModeAwareCache = zipToModeAwareCache;
43552
43559
  function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
43553
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43560
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43554
43561
  moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
43555
43562
  var packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
43556
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; } });
43563
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; }, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43557
43564
  function clear() {
43558
- preDirectoryResolutionCache.clear();
43559
- moduleNameToDirectoryMap.clear();
43565
+ clearAllExceptPackageJsonInfoCache();
43560
43566
  packageJsonInfoCache.clear();
43561
43567
  }
43568
+ function clearAllExceptPackageJsonInfoCache() {
43569
+ perDirectoryResolutionCache.clear();
43570
+ moduleNameToDirectoryMap.clear();
43571
+ }
43562
43572
  function update(options) {
43563
43573
  updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap);
43564
43574
  }
@@ -43634,13 +43644,16 @@ var ts;
43634
43644
  }
43635
43645
  ts.createModuleResolutionCache = createModuleResolutionCache;
43636
43646
  function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
43637
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43647
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43638
43648
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
43639
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { clear: clear });
43649
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { clear: clear, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43640
43650
  function clear() {
43641
- preDirectoryResolutionCache.clear();
43651
+ clearAllExceptPackageJsonInfoCache();
43642
43652
  packageJsonInfoCache.clear();
43643
43653
  }
43654
+ function clearAllExceptPackageJsonInfoCache() {
43655
+ perDirectoryResolutionCache.clear();
43656
+ }
43644
43657
  }
43645
43658
  ts.createTypeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache;
43646
43659
  function resolveModuleNameFromCache(moduleName, containingFile, cache, mode) {
@@ -51428,10 +51441,6 @@ var ts;
51428
51441
  checkExpressionCached(expression);
51429
51442
  return getNodeLinks(expression).resolvedSymbol;
51430
51443
  }
51431
- function getTargetOfPropertyAssignment(node, dontRecursivelyResolve) {
51432
- var expression = node.initializer;
51433
- return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
51434
- }
51435
51444
  function getTargetOfAccessExpression(node, dontRecursivelyResolve) {
51436
51445
  if (!(ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */)) {
51437
51446
  return undefined;
@@ -51463,7 +51472,7 @@ var ts;
51463
51472
  case 297 /* ShorthandPropertyAssignment */:
51464
51473
  return resolveEntityName(node.name, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */, /*ignoreErrors*/ true, dontRecursivelyResolve);
51465
51474
  case 296 /* PropertyAssignment */:
51466
- return getTargetOfPropertyAssignment(node, dontRecursivelyResolve);
51475
+ return getTargetOfAliasLikeExpression(node.initializer, dontRecursivelyResolve);
51467
51476
  case 207 /* ElementAccessExpression */:
51468
51477
  case 206 /* PropertyAccessExpression */:
51469
51478
  return getTargetOfAccessExpression(node, dontRecursivelyResolve);
@@ -56988,7 +56997,7 @@ var ts;
56988
56997
  (resolvedSymbol || symbol).exports.forEach(function (s, name) {
56989
56998
  var _a;
56990
56999
  var exportedMember = members_4.get(name);
56991
- if (exportedMember && exportedMember !== s) {
57000
+ if (exportedMember && exportedMember !== s && !(s.flags & 2097152 /* Alias */)) {
56992
57001
  if (s.flags & 111551 /* Value */ && exportedMember.flags & 111551 /* Value */) {
56993
57002
  // If the member has an additional value-like declaration, union the types from the two declarations,
56994
57003
  // but issue an error if they occurred in two different files. The purpose is to support a JS file with
@@ -63480,6 +63489,7 @@ var ts;
63480
63489
  }
63481
63490
  }
63482
63491
  function getTypeFromImportTypeNode(node) {
63492
+ var _a;
63483
63493
  var links = getNodeLinks(node);
63484
63494
  if (!links.resolvedType) {
63485
63495
  if (node.isTypeOf && node.typeArguments) { // Only the non-typeof form can make use of type arguments
@@ -63499,6 +63509,7 @@ var ts;
63499
63509
  links.resolvedSymbol = unknownSymbol;
63500
63510
  return links.resolvedType = errorType;
63501
63511
  }
63512
+ var isExportEquals = !!((_a = innerModuleSymbol.exports) === null || _a === void 0 ? void 0 : _a.get("export=" /* ExportEquals */));
63502
63513
  var moduleSymbol = resolveExternalModuleSymbol(innerModuleSymbol, /*dontResolveAlias*/ false);
63503
63514
  if (!ts.nodeIsMissing(node.qualifier)) {
63504
63515
  var nameStack = getIdentifierChain(node.qualifier);
@@ -63510,9 +63521,11 @@ var ts;
63510
63521
  // That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
63511
63522
  // the `exports` lookup process that only looks up namespace members which is used for most type references
63512
63523
  var mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
63513
- var next = node.isTypeOf
63524
+ var symbolFromVariable = node.isTypeOf || ts.isInJSFile(node) && isExportEquals
63514
63525
  ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ true)
63515
- : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63526
+ : undefined;
63527
+ var symbolFromModule = node.isTypeOf ? undefined : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63528
+ var next = symbolFromModule !== null && symbolFromModule !== void 0 ? symbolFromModule : symbolFromVariable;
63516
63529
  if (!next) {
63517
63530
  error(current, ts.Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), ts.declarationNameToString(current));
63518
63531
  return links.resolvedType = errorType;
@@ -66370,6 +66383,26 @@ var ts;
66370
66383
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66371
66384
  var saveErrorInfo = captureErrorCalculationState();
66372
66385
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66386
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66387
+ // The combined constraint of an intersection type is the intersection of the constraints of
66388
+ // the constituents. When an intersection type contains instantiable types with union type
66389
+ // constraints, there are situations where we need to examine the combined constraint. One is
66390
+ // when the target is a union type. Another is when the intersection contains types belonging
66391
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66392
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66393
+ // we need to check this constraint against a union on the target side. Also, given a type
66394
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66395
+ // 'string & number | number & number' which reduces to just 'number'.
66396
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66397
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66398
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66399
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66400
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66401
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66402
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66403
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66404
+ }
66405
+ }
66373
66406
  if (result) {
66374
66407
  resetErrorInfo(saveErrorInfo);
66375
66408
  }
@@ -66427,28 +66460,6 @@ var ts;
66427
66460
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66428
66461
  return result;
66429
66462
  }
66430
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66431
- // The combined constraint of an intersection type is the intersection of the constraints of
66432
- // the constituents. When an intersection type contains instantiable types with union type
66433
- // constraints, there are situations where we need to examine the combined constraint. One is
66434
- // when the target is a union type. Another is when the intersection contains types belonging
66435
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66436
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66437
- // we need to check this constraint against a union on the target side. Also, given a type
66438
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66439
- // 'string & number | number & number' which reduces to just 'number'.
66440
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66441
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66442
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66443
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66444
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66445
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66446
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66447
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66448
- return result;
66449
- }
66450
- }
66451
- }
66452
66463
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66453
66464
  // Source is instantiable (e.g. source has union or intersection constraint).
66454
66465
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -82302,9 +82313,11 @@ var ts;
82302
82313
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82303
82314
  if (isGenericObjectType(type)) {
82304
82315
  var baseConstraint = getBaseConstraintOfType(type);
82305
- // We only need `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82316
+ // 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`,
82306
82317
  // or is promise-like.
82307
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82318
+ if (baseConstraint ?
82319
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82320
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82308
82321
  return true;
82309
82322
  }
82310
82323
  }
@@ -95076,10 +95089,11 @@ var ts;
95076
95089
  }
95077
95090
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
95078
95091
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
95079
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
95092
+ var operand = ts.skipParentheses(node.operand);
95093
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
95080
95094
  var info = void 0;
95081
- if (info = accessPrivateIdentifier(node.operand.name)) {
95082
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
95095
+ if (info = accessPrivateIdentifier(operand.name)) {
95096
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
95083
95097
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
95084
95098
  var expression = createPrivateIdentifierAccess(info, readExpression);
95085
95099
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -95095,7 +95109,7 @@ var ts;
95095
95109
  }
95096
95110
  }
95097
95111
  else if (shouldTransformSuperInStaticInitializers &&
95098
- ts.isSuperProperty(node.operand) &&
95112
+ ts.isSuperProperty(operand) &&
95099
95113
  currentStaticPropertyDeclarationOrStaticBlock &&
95100
95114
  currentClassLexicalEnvironment) {
95101
95115
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -95108,31 +95122,31 @@ var ts;
95108
95122
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
95109
95123
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
95110
95124
  if (facts & 1 /* ClassWasDecorated */) {
95111
- var operand = visitInvalidSuperProperty(node.operand);
95125
+ var expression = visitInvalidSuperProperty(operand);
95112
95126
  return ts.isPrefixUnaryExpression(node) ?
95113
- factory.updatePrefixUnaryExpression(node, operand) :
95114
- factory.updatePostfixUnaryExpression(node, operand);
95127
+ factory.updatePrefixUnaryExpression(node, expression) :
95128
+ factory.updatePostfixUnaryExpression(node, expression);
95115
95129
  }
95116
95130
  if (classConstructor && superClassReference) {
95117
95131
  var setterName = void 0;
95118
95132
  var getterName = void 0;
95119
- if (ts.isPropertyAccessExpression(node.operand)) {
95120
- if (ts.isIdentifier(node.operand.name)) {
95121
- getterName = setterName = factory.createStringLiteralFromNode(node.operand.name);
95133
+ if (ts.isPropertyAccessExpression(operand)) {
95134
+ if (ts.isIdentifier(operand.name)) {
95135
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
95122
95136
  }
95123
95137
  }
95124
95138
  else {
95125
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
95126
- getterName = setterName = node.operand.argumentExpression;
95139
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
95140
+ getterName = setterName = operand.argumentExpression;
95127
95141
  }
95128
95142
  else {
95129
95143
  getterName = factory.createTempVariable(hoistVariableDeclaration);
95130
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
95144
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
95131
95145
  }
95132
95146
  }
95133
95147
  if (setterName && getterName) {
95134
95148
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
95135
- ts.setTextRange(expression, node.operand);
95149
+ ts.setTextRange(expression, operand);
95136
95150
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
95137
95151
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
95138
95152
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117887,6 +117901,12 @@ var ts;
117887
117901
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117888
117902
  */
117889
117903
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117904
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117905
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117906
+ }
117907
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117908
+ /*@internal*/
117909
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117890
117910
  switch (ts.getEmitModuleResolutionKind(options)) {
117891
117911
  case ts.ModuleResolutionKind.Node16:
117892
117912
  case ts.ModuleResolutionKind.NodeNext:
@@ -117898,11 +117918,16 @@ var ts;
117898
117918
  return undefined;
117899
117919
  }
117900
117920
  function lookupFromPackageJson() {
117901
- var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117902
- return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117921
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117922
+ var packageJsonLocations = [];
117923
+ state.failedLookupLocations = packageJsonLocations;
117924
+ state.affectingLocations = packageJsonLocations;
117925
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117926
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117927
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117903
117928
  }
117904
117929
  }
117905
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117930
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117906
117931
  /** @internal */
117907
117932
  ts.plainJSErrors = new ts.Set([
117908
117933
  // binder errors
@@ -118227,7 +118252,7 @@ var ts;
118227
118252
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118228
118253
  var oldSourceFile = oldSourceFiles_1[_i];
118229
118254
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118230
- if (shouldCreateNewSourceFile || !newFile ||
118255
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118231
118256
  // old file wasn't redirect but new file is
118232
118257
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118233
118258
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118620,7 +118645,7 @@ var ts;
118620
118645
  });
118621
118646
  }
118622
118647
  function tryReuseStructureFromOldProgram() {
118623
- var _a;
118648
+ var _a, _b;
118624
118649
  if (!oldProgram) {
118625
118650
  return 0 /* Not */;
118626
118651
  }
@@ -118661,12 +118686,15 @@ var ts;
118661
118686
  var seenPackageNames = new ts.Map();
118662
118687
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118663
118688
  var oldSourceFile = oldSourceFiles_2[_i];
118689
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118664
118690
  var newSourceFile = host.getSourceFileByPath
118665
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
118666
- : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
118691
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118692
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118667
118693
  if (!newSourceFile) {
118668
118694
  return 0 /* Not */;
118669
118695
  }
118696
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118697
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118670
118698
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118671
118699
  var fileChanged = void 0;
118672
118700
  if (oldSourceFile.redirectInfo) {
@@ -118706,38 +118734,43 @@ var ts;
118706
118734
  seenPackageNames.set(packageName, newKind);
118707
118735
  }
118708
118736
  if (fileChanged) {
118737
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118738
+ structureIsReused = 1 /* SafeModules */;
118739
+ }
118709
118740
  // The `newSourceFile` object was created for the new program.
118710
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118741
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118711
118742
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118712
118743
  structureIsReused = 1 /* SafeModules */;
118713
118744
  }
118714
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118745
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118715
118746
  // value of no-default-lib has changed
118716
118747
  // this will affect if default library is injected into the list of files
118717
118748
  structureIsReused = 1 /* SafeModules */;
118718
118749
  }
118719
118750
  // check tripleslash references
118720
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118751
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118721
118752
  // tripleslash references has changed
118722
118753
  structureIsReused = 1 /* SafeModules */;
118723
118754
  }
118724
- // check imports and module augmentations
118725
- collectExternalModuleReferences(newSourceFile);
118726
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118727
- // imports has changed
118728
- structureIsReused = 1 /* SafeModules */;
118729
- }
118730
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118731
- // moduleAugmentations has changed
118732
- structureIsReused = 1 /* SafeModules */;
118733
- }
118734
- if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118735
- // dynamicImport has changed
118736
- structureIsReused = 1 /* SafeModules */;
118737
- }
118738
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118739
- // 'types' references has changed
118740
- structureIsReused = 1 /* SafeModules */;
118755
+ else {
118756
+ // check imports and module augmentations
118757
+ collectExternalModuleReferences(newSourceFile);
118758
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118759
+ // imports has changed
118760
+ structureIsReused = 1 /* SafeModules */;
118761
+ }
118762
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118763
+ // moduleAugmentations has changed
118764
+ structureIsReused = 1 /* SafeModules */;
118765
+ }
118766
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118767
+ // dynamicImport has changed
118768
+ structureIsReused = 1 /* SafeModules */;
118769
+ }
118770
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118771
+ // 'types' references has changed
118772
+ structureIsReused = 1 /* SafeModules */;
118773
+ }
118741
118774
  }
118742
118775
  // tentatively approve the file
118743
118776
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118755,18 +118788,18 @@ var ts;
118755
118788
  return structureIsReused;
118756
118789
  }
118757
118790
  var modifiedFiles = modifiedSourceFiles.map(function (f) { return f.oldFile; });
118758
- for (var _b = 0, oldSourceFiles_3 = oldSourceFiles; _b < oldSourceFiles_3.length; _b++) {
118759
- var oldFile = oldSourceFiles_3[_b];
118791
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118792
+ var oldFile = oldSourceFiles_3[_c];
118760
118793
  if (!ts.contains(modifiedFiles, oldFile)) {
118761
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118762
- var moduleName = _d[_c];
118794
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118795
+ var moduleName = _e[_d];
118763
118796
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118764
118797
  }
118765
118798
  }
118766
118799
  }
118767
118800
  // try to verify results of module resolution
118768
- for (var _e = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _e < modifiedSourceFiles_1.length; _e++) {
118769
- var _f = modifiedSourceFiles_1[_e], oldSourceFile = _f.oldFile, newSourceFile = _f.newFile;
118801
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118802
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118770
118803
  var moduleNames = getModuleNames(newSourceFile);
118771
118804
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118772
118805
  // ensure that module resolution results are still correct
@@ -118793,14 +118826,14 @@ var ts;
118793
118826
  if (structureIsReused !== 2 /* Completely */) {
118794
118827
  return structureIsReused;
118795
118828
  }
118796
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118829
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118797
118830
  return 1 /* SafeModules */;
118798
118831
  }
118799
118832
  missingFilePaths = oldProgram.getMissingFilePaths();
118800
118833
  // update fileName -> file mapping
118801
118834
  ts.Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
118802
- for (var _g = 0, newSourceFiles_1 = newSourceFiles; _g < newSourceFiles_1.length; _g++) {
118803
- var newSourceFile = newSourceFiles_1[_g];
118835
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118836
+ var newSourceFile = newSourceFiles_1[_h];
118804
118837
  filesByName.set(newSourceFile.path, newSourceFile);
118805
118838
  }
118806
118839
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119583,13 +119616,16 @@ var ts;
119583
119616
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119584
119617
  }
119585
119618
  }
119586
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119619
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119620
+ var _a;
119587
119621
  var redirect = Object.create(redirectTarget);
119588
119622
  redirect.fileName = fileName;
119589
119623
  redirect.path = path;
119590
119624
  redirect.resolvedPath = resolvedPath;
119591
119625
  redirect.originalFileName = originalFileName;
119592
119626
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119627
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119628
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119593
119629
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119594
119630
  Object.defineProperties(redirect, {
119595
119631
  id: {
@@ -119618,14 +119654,14 @@ var ts;
119618
119654
  // 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
119619
119655
  // 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
119620
119656
  // 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.
119621
- var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119622
- return {
119623
- languageVersion: ts.getEmitScriptTarget(options),
119624
- impliedNodeFormat: impliedNodeFormat,
119625
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
119626
- };
119657
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119658
+ var languageVersion = ts.getEmitScriptTarget(options);
119659
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119660
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119661
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119627
119662
  }
119628
119663
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119664
+ var _a, _b;
119629
119665
  var path = toPath(fileName);
119630
119666
  if (useSourceOfProjectReferenceRedirect) {
119631
119667
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119712,14 +119748,15 @@ var ts;
119712
119748
  }
119713
119749
  }
119714
119750
  // We haven't looked for this file, do so now and cache result
119715
- 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);
119751
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119752
+ 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));
119716
119753
  if (packageId) {
119717
119754
  var packageIdKey = ts.packageIdToString(packageId);
119718
119755
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119719
119756
  if (fileFromPackageId) {
119720
119757
  // Some other SourceFile already exists with this package name and version.
119721
119758
  // Instead of creating a duplicate, just redirect to the existing one.
119722
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName); // TODO: GH#18217
119759
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119723
119760
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119724
119761
  addFileToFilesByName(dupFile, path, redirectedPath);
119725
119762
  addFileIncludeReason(dupFile, reason);
@@ -119740,6 +119777,8 @@ var ts;
119740
119777
  file.path = path;
119741
119778
  file.resolvedPath = toPath(fileName);
119742
119779
  file.originalFileName = originalFileName;
119780
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119781
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119743
119782
  addFileIncludeReason(file, reason);
119744
119783
  if (host.useCaseSensitiveFileNames()) {
119745
119784
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120370,7 +120409,7 @@ var ts;
120370
120409
  fileIncludeReasons = undefined;
120371
120410
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120372
120411
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120373
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120412
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120374
120413
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120375
120414
  return location && isReferenceFileLocation(location) ?
120376
120415
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122675,7 +122714,7 @@ var ts;
122675
122714
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122676
122715
  * @param dirPath
122677
122716
  */
122678
- function canWatchDirectory(dirPath) {
122717
+ function canWatchDirectoryOrFile(dirPath) {
122679
122718
  var rootLength = ts.getRootLength(dirPath);
122680
122719
  if (dirPath.length === rootLength) {
122681
122720
  // Ignore "/", "c:/"
@@ -122712,7 +122751,7 @@ var ts;
122712
122751
  }
122713
122752
  return true;
122714
122753
  }
122715
- ts.canWatchDirectory = canWatchDirectory;
122754
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122716
122755
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122717
122756
  var filesWithChangedSetOfUnresolvedImports;
122718
122757
  var filesWithInvalidatedResolutions;
@@ -122721,7 +122760,9 @@ var ts;
122721
122760
  var resolutionsWithFailedLookups = [];
122722
122761
  var resolutionsWithOnlyAffectingLocations = [];
122723
122762
  var resolvedFileToResolution = ts.createMultiMap();
122763
+ var impliedFormatPackageJsons = new ts.Map();
122724
122764
  var hasChangedAutomaticTypeDirectiveNames = false;
122765
+ var affectingPathChecksForFile;
122725
122766
  var affectingPathChecks;
122726
122767
  var failedLookupChecks;
122727
122768
  var startsWithPathChecks;
@@ -122761,7 +122802,7 @@ var ts;
122761
122802
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122762
122803
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122763
122804
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122764
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122805
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122765
122806
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122766
122807
  resolveModuleNames: resolveModuleNames,
122767
122808
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122805,9 +122846,10 @@ var ts;
122805
122846
  startsWithPathChecks = undefined;
122806
122847
  isInDirectoryChecks = undefined;
122807
122848
  affectingPathChecks = undefined;
122808
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122809
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122810
- clearPerDirectoryResolutions();
122849
+ affectingPathChecksForFile = undefined;
122850
+ moduleResolutionCache.clear();
122851
+ typeReferenceDirectiveResolutionCache.clear();
122852
+ impliedFormatPackageJsons.clear();
122811
122853
  hasChangedAutomaticTypeDirectiveNames = false;
122812
122854
  }
122813
122855
  function startRecordingFilesWithChangedResolutions() {
@@ -122839,15 +122881,44 @@ var ts;
122839
122881
  return function (path) { return (!!collected && collected.has(path)) ||
122840
122882
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122841
122883
  }
122842
- function clearPerDirectoryResolutions() {
122843
- moduleResolutionCache.clear();
122844
- typeReferenceDirectiveResolutionCache.clear();
122884
+ function startCachingPerDirectoryResolution() {
122885
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122886
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122887
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122888
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122845
122889
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122846
122890
  nonRelativeExternalModuleResolutions.clear();
122847
122891
  }
122848
- function finishCachingPerDirectoryResolution() {
122892
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122849
122893
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122850
- clearPerDirectoryResolutions();
122894
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122895
+ nonRelativeExternalModuleResolutions.clear();
122896
+ // Update file watches
122897
+ if (newProgram !== oldProgram) {
122898
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122899
+ var _a, _b, _c;
122900
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122901
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122902
+ for (var i = existing.length; i < expected; i++) {
122903
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122904
+ }
122905
+ if (existing.length > expected) {
122906
+ for (var i = expected; i < existing.length; i++) {
122907
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122908
+ }
122909
+ }
122910
+ if (expected)
122911
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122912
+ else
122913
+ impliedFormatPackageJsons.delete(newFile.path);
122914
+ });
122915
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122916
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122917
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122918
+ impliedFormatPackageJsons.delete(path);
122919
+ }
122920
+ });
122921
+ }
122851
122922
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122852
122923
  if (watcher.refCount === 0) {
122853
122924
  directoryWatchesOfFailedLookups.delete(path);
@@ -122855,7 +122926,7 @@ var ts;
122855
122926
  }
122856
122927
  });
122857
122928
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122858
- if (watcher.refCount === 0) {
122929
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122859
122930
  fileWatchesOfAffectingLocations.delete(path);
122860
122931
  watcher.watcher.close();
122861
122932
  // Ensure when watching symlinked package.json, we can close the actual file watcher only once
@@ -123086,7 +123157,7 @@ var ts;
123086
123157
  }
123087
123158
  // If the directory is node_modules use it to watch, always watch it recursively
123088
123159
  if (ts.isNodeModulesDirectory(dirPath)) {
123089
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123160
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123090
123161
  }
123091
123162
  var nonRecursive = true;
123092
123163
  // Use some ancestor of the root directory
@@ -123104,7 +123175,7 @@ var ts;
123104
123175
  dir = ts.getDirectoryPath(dir);
123105
123176
  }
123106
123177
  }
123107
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123178
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123108
123179
  }
123109
123180
  function isPathWithDefaultFailedLookupExtension(path) {
123110
123181
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -123175,46 +123246,58 @@ var ts;
123175
123246
  // Watch package json
123176
123247
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
123177
123248
  var affectingLocation = affectingLocations_1[_i];
123178
- createFileWatcherOfAffectingLocation(affectingLocation);
123249
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
123179
123250
  }
123180
123251
  }
123181
- function createFileWatcherOfAffectingLocation(affectingLocation) {
123182
- var path = resolutionHost.toPath(affectingLocation);
123183
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123252
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123253
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123184
123254
  if (fileWatcher) {
123185
- fileWatcher.refCount++;
123255
+ if (forResolution)
123256
+ fileWatcher.resolutions++;
123257
+ else
123258
+ fileWatcher.files++;
123186
123259
  return;
123187
123260
  }
123188
123261
  var locationToWatch = affectingLocation;
123189
- var locationToWatchPath = path;
123190
123262
  if (resolutionHost.realpath) {
123191
123263
  locationToWatch = resolutionHost.realpath(affectingLocation);
123192
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123193
- if (path !== locationToWatchPath) {
123194
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123264
+ if (affectingLocation !== locationToWatch) {
123265
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123195
123266
  if (fileWatcher_1) {
123196
- fileWatcher_1.refCount++;
123197
- fileWatcher_1.paths.add(path);
123198
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123267
+ if (forResolution)
123268
+ fileWatcher_1.resolutions++;
123269
+ else
123270
+ fileWatcher_1.files++;
123271
+ fileWatcher_1.paths.add(affectingLocation);
123272
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123199
123273
  return;
123200
123274
  }
123201
123275
  }
123202
123276
  }
123203
123277
  var paths = new ts.Set();
123204
- paths.add(locationToWatchPath);
123278
+ paths.add(locationToWatch);
123205
123279
  var watcher = {
123206
- watcher: resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123207
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, path, eventKind);
123208
- paths.forEach(function (path) { return (affectingPathChecks || (affectingPathChecks = new ts.Set())).add(path); });
123209
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123210
- }),
123211
- refCount: 1,
123280
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123281
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123282
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123283
+ paths.forEach(function (path) {
123284
+ var _a;
123285
+ if (watcher.resolutions)
123286
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123287
+ if (watcher.files)
123288
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123289
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123290
+ });
123291
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123292
+ }) : ts.noopFileWatcher,
123293
+ resolutions: forResolution ? 1 : 0,
123294
+ files: forResolution ? 0 : 1,
123212
123295
  paths: paths,
123213
123296
  };
123214
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123215
- if (path !== locationToWatchPath) {
123216
- fileWatchesOfAffectingLocations.set(path, watcher);
123217
- paths.add(path);
123297
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123298
+ if (affectingLocation !== locationToWatch) {
123299
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123300
+ paths.add(affectingLocation);
123218
123301
  }
123219
123302
  }
123220
123303
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123282,8 +123365,8 @@ var ts;
123282
123365
  }
123283
123366
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123284
123367
  var affectingLocation = affectingLocations_2[_a];
123285
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123286
- watcher.refCount--;
123368
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123369
+ watcher.resolutions--;
123287
123370
  }
123288
123371
  }
123289
123372
  function removeDirectoryWatcher(dirPath) {
@@ -123337,7 +123420,7 @@ var ts;
123337
123420
  resolution.isInvalidated = invalidated = true;
123338
123421
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123339
123422
  var containingFilePath = _b[_a];
123340
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123423
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123341
123424
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123342
123425
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123343
123426
  }
@@ -123404,10 +123487,25 @@ var ts;
123404
123487
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123405
123488
  }
123406
123489
  function invalidateResolutionsOfFailedLookupLocations() {
123490
+ var _a;
123491
+ var invalidated = false;
123492
+ if (affectingPathChecksForFile) {
123493
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123494
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123495
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123496
+ invalidated = true;
123497
+ }
123498
+ });
123499
+ affectingPathChecksForFile = undefined;
123500
+ }
123407
123501
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123408
- return false;
123502
+ return invalidated;
123503
+ }
123504
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123505
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123506
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123507
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123409
123508
  }
123410
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123411
123509
  failedLookupChecks = undefined;
123412
123510
  startsWithPathChecks = undefined;
123413
123511
  isInDirectoryChecks = undefined;
@@ -123420,17 +123518,15 @@ var ts;
123420
123518
  return true;
123421
123519
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123422
123520
  return false;
123423
- return resolution.failedLookupLocations.some(function (location) {
123424
- var locationPath = resolutionHost.toPath(location);
123425
- return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123426
- ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123427
- ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123428
- });
123521
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123522
+ }
123523
+ function isInvalidatedFailedLookup(locationPath) {
123524
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123525
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123526
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123429
123527
  }
123430
123528
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123431
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123432
- return affectingPathChecks.has(resolutionHost.toPath(location));
123433
- });
123529
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123434
123530
  }
123435
123531
  function closeTypeRootsWatch() {
123436
123532
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123496,7 +123592,7 @@ var ts;
123496
123592
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123497
123593
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123498
123594
  var dirPath = resolutionHost.toPath(dir);
123499
- return dirPath === rootPath || canWatchDirectory(dirPath);
123595
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123500
123596
  }
123501
123597
  }
123502
123598
  ts.createResolutionCache = createResolutionCache;
@@ -124469,23 +124565,46 @@ var ts;
124469
124565
  var file = _c[_i];
124470
124566
  write("" + toFileName(file, relativeFileName));
124471
124567
  (_a = reasons.get(file.path)) === null || _a === void 0 ? void 0 : _a.forEach(function (reason) { return write(" " + fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText); });
124472
- (_b = explainIfFileIsRedirect(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124568
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124473
124569
  }
124474
124570
  }
124475
124571
  ts.explainFiles = explainFiles;
124476
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124572
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124573
+ var _a;
124477
124574
  var result;
124478
124575
  if (file.path !== file.resolvedPath) {
124479
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124576
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124480
124577
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124481
124578
  }
124482
124579
  if (file.redirectInfo) {
124483
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124580
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124484
124581
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124485
124582
  }
124583
+ if (ts.isExternalOrCommonJsModule(file)) {
124584
+ switch (file.impliedNodeFormat) {
124585
+ case ts.ModuleKind.ESNext:
124586
+ if (file.packageJsonScope) {
124587
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124588
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124589
+ }
124590
+ break;
124591
+ case ts.ModuleKind.CommonJS:
124592
+ if (file.packageJsonScope) {
124593
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124594
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124595
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124596
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124597
+ }
124598
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124599
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124600
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124601
+ }
124602
+ break;
124603
+ }
124604
+ }
124486
124605
  return result;
124487
124606
  }
124488
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124607
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124489
124608
  function getMatchedFileSpec(program, fileName) {
124490
124609
  var _a;
124491
124610
  var configFile = program.getCompilerOptions().configFile;
@@ -124695,6 +124814,7 @@ var ts;
124695
124814
  MissingFile: "Missing file",
124696
124815
  WildcardDirectory: "Wild card directory",
124697
124816
  FailedLookupLocations: "Failed Lookup Locations",
124817
+ AffectingFileLocation: "File location affecting resolution",
124698
124818
  TypeRoots: "Type roots",
124699
124819
  ConfigFileOfReferencedProject: "Config file of referened project",
124700
124820
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -125018,7 +125138,7 @@ var ts;
125018
125138
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
125019
125139
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
125020
125140
  compilerHost.watchDirectoryOfFailedLookupLocation = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.FailedLookupLocations); };
125021
- compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.PackageJson); };
125141
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
125022
125142
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
125023
125143
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
125024
125144
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -125052,6 +125172,9 @@ var ts;
125052
125172
  return host.resolveTypeReferenceDirectives.apply(host, args);
125053
125173
  }) :
125054
125174
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
125175
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
125176
+ ts.maybeBind(host, host.getModuleResolutionCache) :
125177
+ (function () { return resolutionCache.getModuleResolutionCache(); });
125055
125178
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
125056
125179
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
125057
125180
  synchronizeProgram();
@@ -125154,8 +125277,9 @@ var ts;
125154
125277
  resolutionCache.startCachingPerDirectoryResolution();
125155
125278
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
125156
125279
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125280
+ var oldProgram = getCurrentProgram();
125157
125281
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
125158
- resolutionCache.finishCachingPerDirectoryResolution();
125282
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
125159
125283
  // Update watches
125160
125284
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
125161
125285
  if (needsUpdateInTypeRootWatch) {
@@ -125237,9 +125361,6 @@ var ts;
125237
125361
  sourceFilesCache.set(path, false);
125238
125362
  }
125239
125363
  }
125240
- if (sourceFile) {
125241
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125242
- }
125243
125364
  return sourceFile;
125244
125365
  }
125245
125366
  return hostSourceFile.sourceFile;
@@ -125755,6 +125876,7 @@ var ts;
125755
125876
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125756
125877
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125757
125878
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
125879
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125758
125880
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125759
125881
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125760
125882
  if (!compilerHost.resolveModuleNames) {
@@ -137973,60 +138095,64 @@ var ts;
137973
138095
  }
137974
138096
  return settingsOrHost;
137975
138097
  }
137976
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138098
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137977
138099
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137978
138100
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137979
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138101
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137980
138102
  }
137981
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137982
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
138103
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138104
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137983
138105
  }
137984
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138106
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137985
138107
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137986
138108
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137987
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138109
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137988
138110
  }
137989
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137990
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
138111
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138112
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
137991
138113
  }
137992
138114
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
137993
138115
  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"));
137994
138116
  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);
137995
138117
  return entry;
137996
138118
  }
137997
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
138119
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
137998
138120
  var _a, _b, _c, _d;
137999
138121
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
138000
138122
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
138001
138123
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
138002
138124
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
138003
- var sourceFileOptions = {
138004
- languageVersion: scriptTarget,
138005
- 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),
138006
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138007
- };
138125
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
138126
+ languageVersionOrOptions :
138127
+ {
138128
+ languageVersion: scriptTarget,
138129
+ 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),
138130
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138131
+ };
138132
+ sourceFileOptions.languageVersion = scriptTarget;
138008
138133
  var oldBucketCount = buckets.size;
138009
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
138134
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
138135
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
138010
138136
  if (ts.tracing) {
138011
138137
  if (buckets.size > oldBucketCount) {
138012
138138
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
138013
138139
  // perhaps they are for two projects that don't have any overlap.
138014
138140
  // Bonus: these events can help us interpret the more interesting event below.
138015
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
138141
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
138016
138142
  }
138017
138143
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
138018
138144
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
138019
138145
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
138020
138146
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
138021
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
138147
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
138022
138148
  if (otherBucketKey) {
138023
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
138149
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
138024
138150
  }
138025
138151
  }
138026
138152
  var bucketEntry = bucket.get(path);
138027
138153
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
138028
138154
  if (!entry && externalCache) {
138029
- var sourceFile = externalCache.getDocument(key, path);
138155
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
138030
138156
  if (sourceFile) {
138031
138157
  ts.Debug.assert(acquiring);
138032
138158
  entry = {
@@ -138040,7 +138166,7 @@ var ts;
138040
138166
  // Have never seen this file with these settings. Create a new source file for it.
138041
138167
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
138042
138168
  if (externalCache) {
138043
- externalCache.setDocument(key, path, sourceFile);
138169
+ externalCache.setDocument(keyWithMode, path, sourceFile);
138044
138170
  }
138045
138171
  entry = {
138046
138172
  sourceFile: sourceFile,
@@ -138055,7 +138181,7 @@ var ts;
138055
138181
  if (entry.sourceFile.version !== version) {
138056
138182
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
138057
138183
  if (externalCache) {
138058
- externalCache.setDocument(key, path, entry.sourceFile);
138184
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
138059
138185
  }
138060
138186
  }
138061
138187
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -138084,13 +138210,13 @@ var ts;
138084
138210
  }
138085
138211
  }
138086
138212
  }
138087
- function releaseDocument(fileName, compilationSettings, scriptKind) {
138213
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
138088
138214
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
138089
138215
  var key = getKeyForCompilationSettings(compilationSettings);
138090
- return releaseDocumentWithKey(path, key, scriptKind);
138216
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
138091
138217
  }
138092
- function releaseDocumentWithKey(path, key, scriptKind) {
138093
- var bucket = ts.Debug.checkDefined(buckets.get(key));
138218
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
138219
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
138094
138220
  var bucketEntry = bucket.get(path);
138095
138221
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
138096
138222
  entry.languageServiceRefCount--;
@@ -138147,6 +138273,9 @@ var ts;
138147
138273
  function getKeyForCompilationSettings(settings) {
138148
138274
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
138149
138275
  }
138276
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
138277
+ return (mode ? key + "|" + mode : key);
138278
+ }
138150
138279
  })(ts || (ts = {}));
138151
138280
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
138152
138281
  /* @internal */
@@ -167390,12 +167519,12 @@ var ts;
167390
167519
  // not part of the new program.
167391
167520
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
167392
167521
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
167393
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
167522
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167394
167523
  }
167395
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
167396
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
167524
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
167525
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
167397
167526
  }
167398
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
167527
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
167399
167528
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
167400
167529
  // The program is asking for this file, check first if the host can locate it.
167401
167530
  // If the host can not locate the file, then it does not exist. return undefined
@@ -167438,17 +167567,17 @@ var ts;
167438
167567
  // file's script kind, i.e. in one project some file is treated as ".ts"
167439
167568
  // and in another as ".js"
167440
167569
  if (scriptKind === oldSourceFile.scriptKind) {
167441
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167570
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167442
167571
  }
167443
167572
  else {
167444
167573
  // Release old source file and fall through to aquire new file with new script kind
167445
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind);
167574
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167446
167575
  }
167447
167576
  }
167448
167577
  // We didn't already have the file. Fall through and acquire it from the registry.
167449
167578
  }
167450
167579
  // Could not find this file in the old program, create a new SourceFile for it.
167451
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167580
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167452
167581
  }
167453
167582
  }
167454
167583
  // TODO: GH#18217 frequently asserted as defined
@@ -167527,7 +167656,7 @@ var ts;
167527
167656
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
167528
167657
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
167529
167658
  ts.forEach(program.getSourceFiles(), function (f) {
167530
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167659
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
167531
167660
  });
167532
167661
  program = undefined; // TODO: GH#18217
167533
167662
  }
@@ -168444,6 +168573,7 @@ var ts;
168444
168573
  getEmitOutput: getEmitOutput,
168445
168574
  getNonBoundSourceFile: getNonBoundSourceFile,
168446
168575
  getProgram: getProgram,
168576
+ getCurrentProgram: function () { return program; },
168447
168577
  getAutoImportProvider: getAutoImportProvider,
168448
168578
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
168449
168579
  getApplicableRefactors: getApplicableRefactors,