typescript 4.8.0-dev.20220730 → 4.8.0-dev.20220802

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220730";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220802";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -8571,6 +8571,10 @@ var ts;
8571
8571
  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."),
8572
8572
  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`."),
8573
8573
  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 '**/*'"),
8574
+ 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\""),
8575
+ 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\""),
8576
+ 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\""),
8577
+ 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"),
8574
8578
  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."),
8575
8579
  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."),
8576
8580
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -43248,7 +43252,7 @@ var ts;
43248
43252
  ts.createCacheWithRedirects = createCacheWithRedirects;
43249
43253
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
43250
43254
  var cache;
43251
- return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries };
43255
+ return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries, getInternalMap: getInternalMap };
43252
43256
  function getPackageJsonInfo(packageJsonPath) {
43253
43257
  return cache === null || cache === void 0 ? void 0 : cache.get(ts.toPath(packageJsonPath, currentDirectory, getCanonicalFileName));
43254
43258
  }
@@ -43262,6 +43266,9 @@ var ts;
43262
43266
  var iter = cache === null || cache === void 0 ? void 0 : cache.entries();
43263
43267
  return iter ? ts.arrayFrom(iter) : [];
43264
43268
  }
43269
+ function getInternalMap() {
43270
+ return cache;
43271
+ }
43265
43272
  }
43266
43273
  function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create) {
43267
43274
  var cache = cacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
@@ -43365,15 +43372,18 @@ var ts;
43365
43372
  }
43366
43373
  ts.zipToModeAwareCache = zipToModeAwareCache;
43367
43374
  function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
43368
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43375
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43369
43376
  moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
43370
43377
  var packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
43371
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; } });
43378
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; }, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43372
43379
  function clear() {
43373
- preDirectoryResolutionCache.clear();
43374
- moduleNameToDirectoryMap.clear();
43380
+ clearAllExceptPackageJsonInfoCache();
43375
43381
  packageJsonInfoCache.clear();
43376
43382
  }
43383
+ function clearAllExceptPackageJsonInfoCache() {
43384
+ perDirectoryResolutionCache.clear();
43385
+ moduleNameToDirectoryMap.clear();
43386
+ }
43377
43387
  function update(options) {
43378
43388
  updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap);
43379
43389
  }
@@ -43449,13 +43459,16 @@ var ts;
43449
43459
  }
43450
43460
  ts.createModuleResolutionCache = createModuleResolutionCache;
43451
43461
  function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
43452
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43462
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43453
43463
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
43454
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { clear: clear });
43464
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { clear: clear, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43455
43465
  function clear() {
43456
- preDirectoryResolutionCache.clear();
43466
+ clearAllExceptPackageJsonInfoCache();
43457
43467
  packageJsonInfoCache.clear();
43458
43468
  }
43469
+ function clearAllExceptPackageJsonInfoCache() {
43470
+ perDirectoryResolutionCache.clear();
43471
+ }
43459
43472
  }
43460
43473
  ts.createTypeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache;
43461
43474
  function resolveModuleNameFromCache(moduleName, containingFile, cache, mode) {
@@ -51243,10 +51256,6 @@ var ts;
51243
51256
  checkExpressionCached(expression);
51244
51257
  return getNodeLinks(expression).resolvedSymbol;
51245
51258
  }
51246
- function getTargetOfPropertyAssignment(node, dontRecursivelyResolve) {
51247
- var expression = node.initializer;
51248
- return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
51249
- }
51250
51259
  function getTargetOfAccessExpression(node, dontRecursivelyResolve) {
51251
51260
  if (!(ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */)) {
51252
51261
  return undefined;
@@ -51278,7 +51287,7 @@ var ts;
51278
51287
  case 297 /* ShorthandPropertyAssignment */:
51279
51288
  return resolveEntityName(node.name, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */, /*ignoreErrors*/ true, dontRecursivelyResolve);
51280
51289
  case 296 /* PropertyAssignment */:
51281
- return getTargetOfPropertyAssignment(node, dontRecursivelyResolve);
51290
+ return getTargetOfAliasLikeExpression(node.initializer, dontRecursivelyResolve);
51282
51291
  case 207 /* ElementAccessExpression */:
51283
51292
  case 206 /* PropertyAccessExpression */:
51284
51293
  return getTargetOfAccessExpression(node, dontRecursivelyResolve);
@@ -56803,7 +56812,7 @@ var ts;
56803
56812
  (resolvedSymbol || symbol).exports.forEach(function (s, name) {
56804
56813
  var _a;
56805
56814
  var exportedMember = members_4.get(name);
56806
- if (exportedMember && exportedMember !== s) {
56815
+ if (exportedMember && exportedMember !== s && !(s.flags & 2097152 /* Alias */)) {
56807
56816
  if (s.flags & 111551 /* Value */ && exportedMember.flags & 111551 /* Value */) {
56808
56817
  // If the member has an additional value-like declaration, union the types from the two declarations,
56809
56818
  // but issue an error if they occurred in two different files. The purpose is to support a JS file with
@@ -63295,6 +63304,7 @@ var ts;
63295
63304
  }
63296
63305
  }
63297
63306
  function getTypeFromImportTypeNode(node) {
63307
+ var _a;
63298
63308
  var links = getNodeLinks(node);
63299
63309
  if (!links.resolvedType) {
63300
63310
  if (node.isTypeOf && node.typeArguments) { // Only the non-typeof form can make use of type arguments
@@ -63314,6 +63324,7 @@ var ts;
63314
63324
  links.resolvedSymbol = unknownSymbol;
63315
63325
  return links.resolvedType = errorType;
63316
63326
  }
63327
+ var isExportEquals = !!((_a = innerModuleSymbol.exports) === null || _a === void 0 ? void 0 : _a.get("export=" /* ExportEquals */));
63317
63328
  var moduleSymbol = resolveExternalModuleSymbol(innerModuleSymbol, /*dontResolveAlias*/ false);
63318
63329
  if (!ts.nodeIsMissing(node.qualifier)) {
63319
63330
  var nameStack = getIdentifierChain(node.qualifier);
@@ -63325,9 +63336,11 @@ var ts;
63325
63336
  // That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
63326
63337
  // the `exports` lookup process that only looks up namespace members which is used for most type references
63327
63338
  var mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
63328
- var next = node.isTypeOf
63339
+ var symbolFromVariable = node.isTypeOf || ts.isInJSFile(node) && isExportEquals
63329
63340
  ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ true)
63330
- : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63341
+ : undefined;
63342
+ var symbolFromModule = node.isTypeOf ? undefined : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63343
+ var next = symbolFromModule !== null && symbolFromModule !== void 0 ? symbolFromModule : symbolFromVariable;
63331
63344
  if (!next) {
63332
63345
  error(current, ts.Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), ts.declarationNameToString(current));
63333
63346
  return links.resolvedType = errorType;
@@ -82117,9 +82130,11 @@ var ts;
82117
82130
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82118
82131
  if (isGenericObjectType(type)) {
82119
82132
  var baseConstraint = getBaseConstraintOfType(type);
82120
- // We only need `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82133
+ // 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`,
82121
82134
  // or is promise-like.
82122
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82135
+ if (baseConstraint ?
82136
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82137
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82123
82138
  return true;
82124
82139
  }
82125
82140
  }
@@ -94891,10 +94906,11 @@ var ts;
94891
94906
  }
94892
94907
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
94893
94908
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
94894
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
94909
+ var operand = ts.skipParentheses(node.operand);
94910
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
94895
94911
  var info = void 0;
94896
- if (info = accessPrivateIdentifier(node.operand.name)) {
94897
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
94912
+ if (info = accessPrivateIdentifier(operand.name)) {
94913
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
94898
94914
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
94899
94915
  var expression = createPrivateIdentifierAccess(info, readExpression);
94900
94916
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -94910,7 +94926,7 @@ var ts;
94910
94926
  }
94911
94927
  }
94912
94928
  else if (shouldTransformSuperInStaticInitializers &&
94913
- ts.isSuperProperty(node.operand) &&
94929
+ ts.isSuperProperty(operand) &&
94914
94930
  currentStaticPropertyDeclarationOrStaticBlock &&
94915
94931
  currentClassLexicalEnvironment) {
94916
94932
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -94923,31 +94939,31 @@ var ts;
94923
94939
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
94924
94940
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
94925
94941
  if (facts & 1 /* ClassWasDecorated */) {
94926
- var operand = visitInvalidSuperProperty(node.operand);
94942
+ var expression = visitInvalidSuperProperty(operand);
94927
94943
  return ts.isPrefixUnaryExpression(node) ?
94928
- factory.updatePrefixUnaryExpression(node, operand) :
94929
- factory.updatePostfixUnaryExpression(node, operand);
94944
+ factory.updatePrefixUnaryExpression(node, expression) :
94945
+ factory.updatePostfixUnaryExpression(node, expression);
94930
94946
  }
94931
94947
  if (classConstructor && superClassReference) {
94932
94948
  var setterName = void 0;
94933
94949
  var getterName = void 0;
94934
- if (ts.isPropertyAccessExpression(node.operand)) {
94935
- if (ts.isIdentifier(node.operand.name)) {
94936
- getterName = setterName = factory.createStringLiteralFromNode(node.operand.name);
94950
+ if (ts.isPropertyAccessExpression(operand)) {
94951
+ if (ts.isIdentifier(operand.name)) {
94952
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
94937
94953
  }
94938
94954
  }
94939
94955
  else {
94940
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
94941
- getterName = setterName = node.operand.argumentExpression;
94956
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
94957
+ getterName = setterName = operand.argumentExpression;
94942
94958
  }
94943
94959
  else {
94944
94960
  getterName = factory.createTempVariable(hoistVariableDeclaration);
94945
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
94961
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
94946
94962
  }
94947
94963
  }
94948
94964
  if (setterName && getterName) {
94949
94965
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
94950
- ts.setTextRange(expression, node.operand);
94966
+ ts.setTextRange(expression, operand);
94951
94967
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
94952
94968
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
94953
94969
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117702,6 +117718,12 @@ var ts;
117702
117718
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117703
117719
  */
117704
117720
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117721
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117722
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117723
+ }
117724
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117725
+ /*@internal*/
117726
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117705
117727
  switch (ts.getEmitModuleResolutionKind(options)) {
117706
117728
  case ts.ModuleResolutionKind.Node16:
117707
117729
  case ts.ModuleResolutionKind.NodeNext:
@@ -117713,11 +117735,16 @@ var ts;
117713
117735
  return undefined;
117714
117736
  }
117715
117737
  function lookupFromPackageJson() {
117716
- var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117717
- return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117738
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117739
+ var packageJsonLocations = [];
117740
+ state.failedLookupLocations = packageJsonLocations;
117741
+ state.affectingLocations = packageJsonLocations;
117742
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117743
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117744
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117718
117745
  }
117719
117746
  }
117720
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117747
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117721
117748
  /** @internal */
117722
117749
  ts.plainJSErrors = new ts.Set([
117723
117750
  // binder errors
@@ -118042,7 +118069,7 @@ var ts;
118042
118069
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118043
118070
  var oldSourceFile = oldSourceFiles_1[_i];
118044
118071
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118045
- if (shouldCreateNewSourceFile || !newFile ||
118072
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118046
118073
  // old file wasn't redirect but new file is
118047
118074
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118048
118075
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118435,7 +118462,7 @@ var ts;
118435
118462
  });
118436
118463
  }
118437
118464
  function tryReuseStructureFromOldProgram() {
118438
- var _a;
118465
+ var _a, _b;
118439
118466
  if (!oldProgram) {
118440
118467
  return 0 /* Not */;
118441
118468
  }
@@ -118476,12 +118503,15 @@ var ts;
118476
118503
  var seenPackageNames = new ts.Map();
118477
118504
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118478
118505
  var oldSourceFile = oldSourceFiles_2[_i];
118506
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118479
118507
  var newSourceFile = host.getSourceFileByPath
118480
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
118481
- : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
118508
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118509
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118482
118510
  if (!newSourceFile) {
118483
118511
  return 0 /* Not */;
118484
118512
  }
118513
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118514
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118485
118515
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118486
118516
  var fileChanged = void 0;
118487
118517
  if (oldSourceFile.redirectInfo) {
@@ -118521,38 +118551,43 @@ var ts;
118521
118551
  seenPackageNames.set(packageName, newKind);
118522
118552
  }
118523
118553
  if (fileChanged) {
118554
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118555
+ structureIsReused = 1 /* SafeModules */;
118556
+ }
118524
118557
  // The `newSourceFile` object was created for the new program.
118525
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118558
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118526
118559
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118527
118560
  structureIsReused = 1 /* SafeModules */;
118528
118561
  }
118529
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118562
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118530
118563
  // value of no-default-lib has changed
118531
118564
  // this will affect if default library is injected into the list of files
118532
118565
  structureIsReused = 1 /* SafeModules */;
118533
118566
  }
118534
118567
  // check tripleslash references
118535
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118568
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118536
118569
  // tripleslash references has changed
118537
118570
  structureIsReused = 1 /* SafeModules */;
118538
118571
  }
118539
- // check imports and module augmentations
118540
- collectExternalModuleReferences(newSourceFile);
118541
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118542
- // imports has changed
118543
- structureIsReused = 1 /* SafeModules */;
118544
- }
118545
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118546
- // moduleAugmentations has changed
118547
- structureIsReused = 1 /* SafeModules */;
118548
- }
118549
- if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118550
- // dynamicImport has changed
118551
- structureIsReused = 1 /* SafeModules */;
118552
- }
118553
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118554
- // 'types' references has changed
118555
- structureIsReused = 1 /* SafeModules */;
118572
+ else {
118573
+ // check imports and module augmentations
118574
+ collectExternalModuleReferences(newSourceFile);
118575
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118576
+ // imports has changed
118577
+ structureIsReused = 1 /* SafeModules */;
118578
+ }
118579
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118580
+ // moduleAugmentations has changed
118581
+ structureIsReused = 1 /* SafeModules */;
118582
+ }
118583
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118584
+ // dynamicImport has changed
118585
+ structureIsReused = 1 /* SafeModules */;
118586
+ }
118587
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118588
+ // 'types' references has changed
118589
+ structureIsReused = 1 /* SafeModules */;
118590
+ }
118556
118591
  }
118557
118592
  // tentatively approve the file
118558
118593
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118570,18 +118605,18 @@ var ts;
118570
118605
  return structureIsReused;
118571
118606
  }
118572
118607
  var modifiedFiles = modifiedSourceFiles.map(function (f) { return f.oldFile; });
118573
- for (var _b = 0, oldSourceFiles_3 = oldSourceFiles; _b < oldSourceFiles_3.length; _b++) {
118574
- var oldFile = oldSourceFiles_3[_b];
118608
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118609
+ var oldFile = oldSourceFiles_3[_c];
118575
118610
  if (!ts.contains(modifiedFiles, oldFile)) {
118576
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118577
- var moduleName = _d[_c];
118611
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118612
+ var moduleName = _e[_d];
118578
118613
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118579
118614
  }
118580
118615
  }
118581
118616
  }
118582
118617
  // try to verify results of module resolution
118583
- for (var _e = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _e < modifiedSourceFiles_1.length; _e++) {
118584
- var _f = modifiedSourceFiles_1[_e], oldSourceFile = _f.oldFile, newSourceFile = _f.newFile;
118618
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118619
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118585
118620
  var moduleNames = getModuleNames(newSourceFile);
118586
118621
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118587
118622
  // ensure that module resolution results are still correct
@@ -118608,14 +118643,14 @@ var ts;
118608
118643
  if (structureIsReused !== 2 /* Completely */) {
118609
118644
  return structureIsReused;
118610
118645
  }
118611
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118646
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118612
118647
  return 1 /* SafeModules */;
118613
118648
  }
118614
118649
  missingFilePaths = oldProgram.getMissingFilePaths();
118615
118650
  // update fileName -> file mapping
118616
118651
  ts.Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
118617
- for (var _g = 0, newSourceFiles_1 = newSourceFiles; _g < newSourceFiles_1.length; _g++) {
118618
- var newSourceFile = newSourceFiles_1[_g];
118652
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118653
+ var newSourceFile = newSourceFiles_1[_h];
118619
118654
  filesByName.set(newSourceFile.path, newSourceFile);
118620
118655
  }
118621
118656
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119398,13 +119433,16 @@ var ts;
119398
119433
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119399
119434
  }
119400
119435
  }
119401
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119436
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119437
+ var _a;
119402
119438
  var redirect = Object.create(redirectTarget);
119403
119439
  redirect.fileName = fileName;
119404
119440
  redirect.path = path;
119405
119441
  redirect.resolvedPath = resolvedPath;
119406
119442
  redirect.originalFileName = originalFileName;
119407
119443
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119444
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119445
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119408
119446
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119409
119447
  Object.defineProperties(redirect, {
119410
119448
  id: {
@@ -119433,14 +119471,14 @@ var ts;
119433
119471
  // 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
119434
119472
  // 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
119435
119473
  // 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.
119436
- var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119437
- return {
119438
- languageVersion: ts.getEmitScriptTarget(options),
119439
- impliedNodeFormat: impliedNodeFormat,
119440
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
119441
- };
119474
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119475
+ var languageVersion = ts.getEmitScriptTarget(options);
119476
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119477
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119478
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119442
119479
  }
119443
119480
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119481
+ var _a, _b;
119444
119482
  var path = toPath(fileName);
119445
119483
  if (useSourceOfProjectReferenceRedirect) {
119446
119484
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119527,14 +119565,15 @@ var ts;
119527
119565
  }
119528
119566
  }
119529
119567
  // We haven't looked for this file, do so now and cache result
119530
- 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);
119568
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119569
+ 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));
119531
119570
  if (packageId) {
119532
119571
  var packageIdKey = ts.packageIdToString(packageId);
119533
119572
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119534
119573
  if (fileFromPackageId) {
119535
119574
  // Some other SourceFile already exists with this package name and version.
119536
119575
  // Instead of creating a duplicate, just redirect to the existing one.
119537
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName); // TODO: GH#18217
119576
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119538
119577
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119539
119578
  addFileToFilesByName(dupFile, path, redirectedPath);
119540
119579
  addFileIncludeReason(dupFile, reason);
@@ -119555,6 +119594,8 @@ var ts;
119555
119594
  file.path = path;
119556
119595
  file.resolvedPath = toPath(fileName);
119557
119596
  file.originalFileName = originalFileName;
119597
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119598
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119558
119599
  addFileIncludeReason(file, reason);
119559
119600
  if (host.useCaseSensitiveFileNames()) {
119560
119601
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120185,7 +120226,7 @@ var ts;
120185
120226
  fileIncludeReasons = undefined;
120186
120227
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120187
120228
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120188
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120229
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120189
120230
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120190
120231
  return location && isReferenceFileLocation(location) ?
120191
120232
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122490,7 +122531,7 @@ var ts;
122490
122531
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122491
122532
  * @param dirPath
122492
122533
  */
122493
- function canWatchDirectory(dirPath) {
122534
+ function canWatchDirectoryOrFile(dirPath) {
122494
122535
  var rootLength = ts.getRootLength(dirPath);
122495
122536
  if (dirPath.length === rootLength) {
122496
122537
  // Ignore "/", "c:/"
@@ -122527,7 +122568,7 @@ var ts;
122527
122568
  }
122528
122569
  return true;
122529
122570
  }
122530
- ts.canWatchDirectory = canWatchDirectory;
122571
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122531
122572
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122532
122573
  var filesWithChangedSetOfUnresolvedImports;
122533
122574
  var filesWithInvalidatedResolutions;
@@ -122536,7 +122577,9 @@ var ts;
122536
122577
  var resolutionsWithFailedLookups = [];
122537
122578
  var resolutionsWithOnlyAffectingLocations = [];
122538
122579
  var resolvedFileToResolution = ts.createMultiMap();
122580
+ var impliedFormatPackageJsons = new ts.Map();
122539
122581
  var hasChangedAutomaticTypeDirectiveNames = false;
122582
+ var affectingPathChecksForFile;
122540
122583
  var affectingPathChecks;
122541
122584
  var failedLookupChecks;
122542
122585
  var startsWithPathChecks;
@@ -122576,7 +122619,7 @@ var ts;
122576
122619
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122577
122620
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122578
122621
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122579
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122622
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122580
122623
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122581
122624
  resolveModuleNames: resolveModuleNames,
122582
122625
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122620,9 +122663,10 @@ var ts;
122620
122663
  startsWithPathChecks = undefined;
122621
122664
  isInDirectoryChecks = undefined;
122622
122665
  affectingPathChecks = undefined;
122623
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122624
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122625
- clearPerDirectoryResolutions();
122666
+ affectingPathChecksForFile = undefined;
122667
+ moduleResolutionCache.clear();
122668
+ typeReferenceDirectiveResolutionCache.clear();
122669
+ impliedFormatPackageJsons.clear();
122626
122670
  hasChangedAutomaticTypeDirectiveNames = false;
122627
122671
  }
122628
122672
  function startRecordingFilesWithChangedResolutions() {
@@ -122654,15 +122698,44 @@ var ts;
122654
122698
  return function (path) { return (!!collected && collected.has(path)) ||
122655
122699
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122656
122700
  }
122657
- function clearPerDirectoryResolutions() {
122658
- moduleResolutionCache.clear();
122659
- typeReferenceDirectiveResolutionCache.clear();
122701
+ function startCachingPerDirectoryResolution() {
122702
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122703
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122704
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122705
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122660
122706
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122661
122707
  nonRelativeExternalModuleResolutions.clear();
122662
122708
  }
122663
- function finishCachingPerDirectoryResolution() {
122709
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122664
122710
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122665
- clearPerDirectoryResolutions();
122711
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122712
+ nonRelativeExternalModuleResolutions.clear();
122713
+ // Update file watches
122714
+ if (newProgram !== oldProgram) {
122715
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122716
+ var _a, _b, _c;
122717
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122718
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122719
+ for (var i = existing.length; i < expected; i++) {
122720
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122721
+ }
122722
+ if (existing.length > expected) {
122723
+ for (var i = expected; i < existing.length; i++) {
122724
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122725
+ }
122726
+ }
122727
+ if (expected)
122728
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122729
+ else
122730
+ impliedFormatPackageJsons.delete(newFile.path);
122731
+ });
122732
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122733
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122734
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122735
+ impliedFormatPackageJsons.delete(path);
122736
+ }
122737
+ });
122738
+ }
122666
122739
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122667
122740
  if (watcher.refCount === 0) {
122668
122741
  directoryWatchesOfFailedLookups.delete(path);
@@ -122670,7 +122743,7 @@ var ts;
122670
122743
  }
122671
122744
  });
122672
122745
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122673
- if (watcher.refCount === 0) {
122746
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122674
122747
  fileWatchesOfAffectingLocations.delete(path);
122675
122748
  watcher.watcher.close();
122676
122749
  // Ensure when watching symlinked package.json, we can close the actual file watcher only once
@@ -122901,7 +122974,7 @@ var ts;
122901
122974
  }
122902
122975
  // If the directory is node_modules use it to watch, always watch it recursively
122903
122976
  if (ts.isNodeModulesDirectory(dirPath)) {
122904
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
122977
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
122905
122978
  }
122906
122979
  var nonRecursive = true;
122907
122980
  // Use some ancestor of the root directory
@@ -122919,7 +122992,7 @@ var ts;
122919
122992
  dir = ts.getDirectoryPath(dir);
122920
122993
  }
122921
122994
  }
122922
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
122995
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
122923
122996
  }
122924
122997
  function isPathWithDefaultFailedLookupExtension(path) {
122925
122998
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -122990,46 +123063,58 @@ var ts;
122990
123063
  // Watch package json
122991
123064
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
122992
123065
  var affectingLocation = affectingLocations_1[_i];
122993
- createFileWatcherOfAffectingLocation(affectingLocation);
123066
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
122994
123067
  }
122995
123068
  }
122996
- function createFileWatcherOfAffectingLocation(affectingLocation) {
122997
- var path = resolutionHost.toPath(affectingLocation);
122998
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123069
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123070
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
122999
123071
  if (fileWatcher) {
123000
- fileWatcher.refCount++;
123072
+ if (forResolution)
123073
+ fileWatcher.resolutions++;
123074
+ else
123075
+ fileWatcher.files++;
123001
123076
  return;
123002
123077
  }
123003
123078
  var locationToWatch = affectingLocation;
123004
- var locationToWatchPath = path;
123005
123079
  if (resolutionHost.realpath) {
123006
123080
  locationToWatch = resolutionHost.realpath(affectingLocation);
123007
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123008
- if (path !== locationToWatchPath) {
123009
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123081
+ if (affectingLocation !== locationToWatch) {
123082
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123010
123083
  if (fileWatcher_1) {
123011
- fileWatcher_1.refCount++;
123012
- fileWatcher_1.paths.add(path);
123013
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123084
+ if (forResolution)
123085
+ fileWatcher_1.resolutions++;
123086
+ else
123087
+ fileWatcher_1.files++;
123088
+ fileWatcher_1.paths.add(affectingLocation);
123089
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123014
123090
  return;
123015
123091
  }
123016
123092
  }
123017
123093
  }
123018
123094
  var paths = new ts.Set();
123019
- paths.add(locationToWatchPath);
123095
+ paths.add(locationToWatch);
123020
123096
  var watcher = {
123021
- watcher: resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123022
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, path, eventKind);
123023
- paths.forEach(function (path) { return (affectingPathChecks || (affectingPathChecks = new ts.Set())).add(path); });
123024
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123025
- }),
123026
- refCount: 1,
123097
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123098
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123099
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123100
+ paths.forEach(function (path) {
123101
+ var _a;
123102
+ if (watcher.resolutions)
123103
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123104
+ if (watcher.files)
123105
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123106
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123107
+ });
123108
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123109
+ }) : ts.noopFileWatcher,
123110
+ resolutions: forResolution ? 1 : 0,
123111
+ files: forResolution ? 0 : 1,
123027
123112
  paths: paths,
123028
123113
  };
123029
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123030
- if (path !== locationToWatchPath) {
123031
- fileWatchesOfAffectingLocations.set(path, watcher);
123032
- paths.add(path);
123114
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123115
+ if (affectingLocation !== locationToWatch) {
123116
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123117
+ paths.add(affectingLocation);
123033
123118
  }
123034
123119
  }
123035
123120
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123097,8 +123182,8 @@ var ts;
123097
123182
  }
123098
123183
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123099
123184
  var affectingLocation = affectingLocations_2[_a];
123100
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123101
- watcher.refCount--;
123185
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123186
+ watcher.resolutions--;
123102
123187
  }
123103
123188
  }
123104
123189
  function removeDirectoryWatcher(dirPath) {
@@ -123152,7 +123237,7 @@ var ts;
123152
123237
  resolution.isInvalidated = invalidated = true;
123153
123238
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123154
123239
  var containingFilePath = _b[_a];
123155
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123240
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123156
123241
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123157
123242
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123158
123243
  }
@@ -123219,10 +123304,25 @@ var ts;
123219
123304
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123220
123305
  }
123221
123306
  function invalidateResolutionsOfFailedLookupLocations() {
123307
+ var _a;
123308
+ var invalidated = false;
123309
+ if (affectingPathChecksForFile) {
123310
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123311
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123312
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123313
+ invalidated = true;
123314
+ }
123315
+ });
123316
+ affectingPathChecksForFile = undefined;
123317
+ }
123222
123318
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123223
- return false;
123319
+ return invalidated;
123320
+ }
123321
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123322
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123323
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123324
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123224
123325
  }
123225
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123226
123326
  failedLookupChecks = undefined;
123227
123327
  startsWithPathChecks = undefined;
123228
123328
  isInDirectoryChecks = undefined;
@@ -123235,17 +123335,15 @@ var ts;
123235
123335
  return true;
123236
123336
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123237
123337
  return false;
123238
- return resolution.failedLookupLocations.some(function (location) {
123239
- var locationPath = resolutionHost.toPath(location);
123240
- return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123241
- ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123242
- ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123243
- });
123338
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123339
+ }
123340
+ function isInvalidatedFailedLookup(locationPath) {
123341
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123342
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123343
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123244
123344
  }
123245
123345
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123246
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123247
- return affectingPathChecks.has(resolutionHost.toPath(location));
123248
- });
123346
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123249
123347
  }
123250
123348
  function closeTypeRootsWatch() {
123251
123349
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123311,7 +123409,7 @@ var ts;
123311
123409
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123312
123410
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123313
123411
  var dirPath = resolutionHost.toPath(dir);
123314
- return dirPath === rootPath || canWatchDirectory(dirPath);
123412
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123315
123413
  }
123316
123414
  }
123317
123415
  ts.createResolutionCache = createResolutionCache;
@@ -124284,23 +124382,46 @@ var ts;
124284
124382
  var file = _c[_i];
124285
124383
  write("" + toFileName(file, relativeFileName));
124286
124384
  (_a = reasons.get(file.path)) === null || _a === void 0 ? void 0 : _a.forEach(function (reason) { return write(" " + fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText); });
124287
- (_b = explainIfFileIsRedirect(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124385
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124288
124386
  }
124289
124387
  }
124290
124388
  ts.explainFiles = explainFiles;
124291
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124389
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124390
+ var _a;
124292
124391
  var result;
124293
124392
  if (file.path !== file.resolvedPath) {
124294
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124393
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124295
124394
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124296
124395
  }
124297
124396
  if (file.redirectInfo) {
124298
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124397
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124299
124398
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124300
124399
  }
124400
+ if (ts.isExternalOrCommonJsModule(file)) {
124401
+ switch (file.impliedNodeFormat) {
124402
+ case ts.ModuleKind.ESNext:
124403
+ if (file.packageJsonScope) {
124404
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124405
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124406
+ }
124407
+ break;
124408
+ case ts.ModuleKind.CommonJS:
124409
+ if (file.packageJsonScope) {
124410
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124411
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124412
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124413
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124414
+ }
124415
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124416
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124417
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124418
+ }
124419
+ break;
124420
+ }
124421
+ }
124301
124422
  return result;
124302
124423
  }
124303
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124424
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124304
124425
  function getMatchedFileSpec(program, fileName) {
124305
124426
  var _a;
124306
124427
  var configFile = program.getCompilerOptions().configFile;
@@ -124510,6 +124631,7 @@ var ts;
124510
124631
  MissingFile: "Missing file",
124511
124632
  WildcardDirectory: "Wild card directory",
124512
124633
  FailedLookupLocations: "Failed Lookup Locations",
124634
+ AffectingFileLocation: "File location affecting resolution",
124513
124635
  TypeRoots: "Type roots",
124514
124636
  ConfigFileOfReferencedProject: "Config file of referened project",
124515
124637
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -124833,7 +124955,7 @@ var ts;
124833
124955
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
124834
124956
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
124835
124957
  compilerHost.watchDirectoryOfFailedLookupLocation = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.FailedLookupLocations); };
124836
- compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.PackageJson); };
124958
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
124837
124959
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
124838
124960
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
124839
124961
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -124867,6 +124989,9 @@ var ts;
124867
124989
  return host.resolveTypeReferenceDirectives.apply(host, args);
124868
124990
  }) :
124869
124991
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
124992
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
124993
+ ts.maybeBind(host, host.getModuleResolutionCache) :
124994
+ (function () { return resolutionCache.getModuleResolutionCache(); });
124870
124995
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
124871
124996
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
124872
124997
  synchronizeProgram();
@@ -124969,8 +125094,9 @@ var ts;
124969
125094
  resolutionCache.startCachingPerDirectoryResolution();
124970
125095
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
124971
125096
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125097
+ var oldProgram = getCurrentProgram();
124972
125098
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
124973
- resolutionCache.finishCachingPerDirectoryResolution();
125099
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
124974
125100
  // Update watches
124975
125101
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
124976
125102
  if (needsUpdateInTypeRootWatch) {
@@ -125052,9 +125178,6 @@ var ts;
125052
125178
  sourceFilesCache.set(path, false);
125053
125179
  }
125054
125180
  }
125055
- if (sourceFile) {
125056
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125057
- }
125058
125181
  return sourceFile;
125059
125182
  }
125060
125183
  return hostSourceFile.sourceFile;
@@ -125570,6 +125693,7 @@ var ts;
125570
125693
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125571
125694
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125572
125695
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
125696
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125573
125697
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125574
125698
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125575
125699
  if (!compilerHost.resolveModuleNames) {
@@ -137369,60 +137493,64 @@ var ts;
137369
137493
  }
137370
137494
  return settingsOrHost;
137371
137495
  }
137372
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
137496
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137373
137497
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137374
137498
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137375
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
137499
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137376
137500
  }
137377
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137378
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
137501
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137502
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137379
137503
  }
137380
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
137504
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137381
137505
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137382
137506
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137383
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
137507
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137384
137508
  }
137385
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137386
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
137509
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137510
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
137387
137511
  }
137388
137512
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
137389
137513
  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"));
137390
137514
  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);
137391
137515
  return entry;
137392
137516
  }
137393
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
137517
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
137394
137518
  var _a, _b, _c, _d;
137395
137519
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
137396
137520
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
137397
137521
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
137398
137522
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
137399
- var sourceFileOptions = {
137400
- languageVersion: scriptTarget,
137401
- 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),
137402
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
137403
- };
137523
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
137524
+ languageVersionOrOptions :
137525
+ {
137526
+ languageVersion: scriptTarget,
137527
+ 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),
137528
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
137529
+ };
137530
+ sourceFileOptions.languageVersion = scriptTarget;
137404
137531
  var oldBucketCount = buckets.size;
137405
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
137532
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
137533
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
137406
137534
  if (ts.tracing) {
137407
137535
  if (buckets.size > oldBucketCount) {
137408
137536
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
137409
137537
  // perhaps they are for two projects that don't have any overlap.
137410
137538
  // Bonus: these events can help us interpret the more interesting event below.
137411
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
137539
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
137412
137540
  }
137413
137541
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
137414
137542
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
137415
137543
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
137416
137544
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
137417
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
137545
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
137418
137546
  if (otherBucketKey) {
137419
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
137547
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
137420
137548
  }
137421
137549
  }
137422
137550
  var bucketEntry = bucket.get(path);
137423
137551
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
137424
137552
  if (!entry && externalCache) {
137425
- var sourceFile = externalCache.getDocument(key, path);
137553
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
137426
137554
  if (sourceFile) {
137427
137555
  ts.Debug.assert(acquiring);
137428
137556
  entry = {
@@ -137436,7 +137564,7 @@ var ts;
137436
137564
  // Have never seen this file with these settings. Create a new source file for it.
137437
137565
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
137438
137566
  if (externalCache) {
137439
- externalCache.setDocument(key, path, sourceFile);
137567
+ externalCache.setDocument(keyWithMode, path, sourceFile);
137440
137568
  }
137441
137569
  entry = {
137442
137570
  sourceFile: sourceFile,
@@ -137451,7 +137579,7 @@ var ts;
137451
137579
  if (entry.sourceFile.version !== version) {
137452
137580
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
137453
137581
  if (externalCache) {
137454
- externalCache.setDocument(key, path, entry.sourceFile);
137582
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
137455
137583
  }
137456
137584
  }
137457
137585
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -137480,13 +137608,13 @@ var ts;
137480
137608
  }
137481
137609
  }
137482
137610
  }
137483
- function releaseDocument(fileName, compilationSettings, scriptKind) {
137611
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
137484
137612
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137485
137613
  var key = getKeyForCompilationSettings(compilationSettings);
137486
- return releaseDocumentWithKey(path, key, scriptKind);
137614
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
137487
137615
  }
137488
- function releaseDocumentWithKey(path, key, scriptKind) {
137489
- var bucket = ts.Debug.checkDefined(buckets.get(key));
137616
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
137617
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
137490
137618
  var bucketEntry = bucket.get(path);
137491
137619
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
137492
137620
  entry.languageServiceRefCount--;
@@ -137543,6 +137671,9 @@ var ts;
137543
137671
  function getKeyForCompilationSettings(settings) {
137544
137672
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
137545
137673
  }
137674
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
137675
+ return (mode ? key + "|" + mode : key);
137676
+ }
137546
137677
  })(ts || (ts = {}));
137547
137678
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
137548
137679
  /* @internal */
@@ -166786,12 +166917,12 @@ var ts;
166786
166917
  // not part of the new program.
166787
166918
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
166788
166919
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
166789
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
166920
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
166790
166921
  }
166791
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
166792
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
166922
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
166923
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
166793
166924
  }
166794
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
166925
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
166795
166926
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
166796
166927
  // The program is asking for this file, check first if the host can locate it.
166797
166928
  // If the host can not locate the file, then it does not exist. return undefined
@@ -166834,17 +166965,17 @@ var ts;
166834
166965
  // file's script kind, i.e. in one project some file is treated as ".ts"
166835
166966
  // and in another as ".js"
166836
166967
  if (scriptKind === oldSourceFile.scriptKind) {
166837
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
166968
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
166838
166969
  }
166839
166970
  else {
166840
166971
  // Release old source file and fall through to aquire new file with new script kind
166841
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind);
166972
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
166842
166973
  }
166843
166974
  }
166844
166975
  // We didn't already have the file. Fall through and acquire it from the registry.
166845
166976
  }
166846
166977
  // Could not find this file in the old program, create a new SourceFile for it.
166847
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
166978
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
166848
166979
  }
166849
166980
  }
166850
166981
  // TODO: GH#18217 frequently asserted as defined
@@ -166923,7 +167054,7 @@ var ts;
166923
167054
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
166924
167055
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
166925
167056
  ts.forEach(program.getSourceFiles(), function (f) {
166926
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167057
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
166927
167058
  });
166928
167059
  program = undefined; // TODO: GH#18217
166929
167060
  }
@@ -167840,6 +167971,7 @@ var ts;
167840
167971
  getEmitOutput: getEmitOutput,
167841
167972
  getNonBoundSourceFile: getNonBoundSourceFile,
167842
167973
  getProgram: getProgram,
167974
+ getCurrentProgram: function () { return program; },
167843
167975
  getAutoImportProvider: getAutoImportProvider,
167844
167976
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
167845
167977
  getApplicableRefactors: getApplicableRefactors,
@@ -171476,7 +171608,7 @@ var ts;
171476
171608
  };
171477
171609
  /*@internal*/
171478
171610
  Project.prototype.watchAffectingFileLocation = function (file, cb) {
171479
- return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.PackageJson, this);
171611
+ return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.AffectingFileLocation, this);
171480
171612
  };
171481
171613
  /*@internal*/
171482
171614
  Project.prototype.clearInvalidateResolutionOfFailedLookupTimer = function () {
@@ -172013,7 +172145,7 @@ var ts;
172013
172145
  };
172014
172146
  Project.prototype.updateGraphWorker = function () {
172015
172147
  var _this = this;
172016
- var oldProgram = this.program;
172148
+ var oldProgram = this.languageService.getCurrentProgram();
172017
172149
  ts.Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
172018
172150
  this.writeLog("Starting updateGraphWorker: Project: " + this.getProjectName());
172019
172151
  var start = ts.timestamp();
@@ -172022,7 +172154,7 @@ var ts;
172022
172154
  this.program = this.languageService.getProgram(); // TODO: GH#18217
172023
172155
  this.dirty = false;
172024
172156
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "finishCachingPerDirectoryResolution");
172025
- this.resolutionCache.finishCachingPerDirectoryResolution();
172157
+ this.resolutionCache.finishCachingPerDirectoryResolution(this.program, oldProgram);
172026
172158
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
172027
172159
  ts.Debug.assert(oldProgram === undefined || this.program !== undefined);
172028
172160
  // bump up the version if
@@ -174480,7 +174612,7 @@ var ts;
174480
174612
  // created when any of the script infos are added as root of inferred project
174481
174613
  if (this.configFileExistenceImpactsRootOfInferredProject(configFileExistenceInfo)) {
174482
174614
  // If we cannot watch config file existence without configured project, close the configured file watcher
174483
- if (!ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath))) {
174615
+ if (!ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath))) {
174484
174616
  configFileExistenceInfo.watcher.close();
174485
174617
  configFileExistenceInfo.watcher = noopConfigFileWatcher;
174486
174618
  }
@@ -174560,7 +174692,7 @@ var ts;
174560
174692
  // Set this file as the root of inferred project
174561
174693
  (configFileExistenceInfo.openFilesImpactedByConfigFile || (configFileExistenceInfo.openFilesImpactedByConfigFile = new ts.Map())).set(info.path, true);
174562
174694
  // If there is no configured project for this config file, add the file watcher
174563
- configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174695
+ configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174564
174696
  _this.watchFactory.watchFile(configFileName, function (_filename, eventKind) { return _this.onConfigFileChanged(canonicalConfigFilePath, eventKind); }, ts.PollingInterval.High, _this.hostConfiguration.watchOptions, ts.WatchType.ConfigFileForInferredRoot) :
174565
174697
  noopConfigFileWatcher);
174566
174698
  });