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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220730";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220802";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -8765,6 +8765,10 @@ var ts;
8765
8765
  resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."),
8766
8766
  Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require: diag(1456, ts.DiagnosticCategory.Error, "Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require_1456", "Type import assertions should have exactly one key - `resolution-mode` - with value `import` or `require`."),
8767
8767
  Matched_by_default_include_pattern_Asterisk_Asterisk_Slash_Asterisk: diag(1457, ts.DiagnosticCategory.Message, "Matched_by_default_include_pattern_Asterisk_Asterisk_Slash_Asterisk_1457", "Matched by default include pattern '**/*'"),
8768
+ File_is_ECMAScript_module_because_0_has_field_type_with_value_module: diag(1458, ts.DiagnosticCategory.Message, "File_is_ECMAScript_module_because_0_has_field_type_with_value_module_1458", "File is ECMAScript module because '{0}' has field \"type\" with value \"module\""),
8769
+ File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module: diag(1459, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module_1459", "File is CommonJS module because '{0}' has field \"type\" whose value is not \"module\""),
8770
+ File_is_CommonJS_module_because_0_does_not_have_field_type: diag(1460, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_0_does_not_have_field_type_1460", "File is CommonJS module because '{0}' does not have field \"type\""),
8771
+ File_is_CommonJS_module_because_package_json_was_not_found: diag(1461, ts.DiagnosticCategory.Message, "File_is_CommonJS_module_because_package_json_was_not_found_1461", "File is CommonJS module because 'package.json' was not found"),
8768
8772
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8769
8773
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8770
8774
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -43442,7 +43446,7 @@ var ts;
43442
43446
  ts.createCacheWithRedirects = createCacheWithRedirects;
43443
43447
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
43444
43448
  var cache;
43445
- return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries };
43449
+ return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries, getInternalMap: getInternalMap };
43446
43450
  function getPackageJsonInfo(packageJsonPath) {
43447
43451
  return cache === null || cache === void 0 ? void 0 : cache.get(ts.toPath(packageJsonPath, currentDirectory, getCanonicalFileName));
43448
43452
  }
@@ -43456,6 +43460,9 @@ var ts;
43456
43460
  var iter = cache === null || cache === void 0 ? void 0 : cache.entries();
43457
43461
  return iter ? ts.arrayFrom(iter) : [];
43458
43462
  }
43463
+ function getInternalMap() {
43464
+ return cache;
43465
+ }
43459
43466
  }
43460
43467
  function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create) {
43461
43468
  var cache = cacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
@@ -43559,15 +43566,18 @@ var ts;
43559
43566
  }
43560
43567
  ts.zipToModeAwareCache = zipToModeAwareCache;
43561
43568
  function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
43562
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43569
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43563
43570
  moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
43564
43571
  var packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
43565
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; } });
43572
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; }, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43566
43573
  function clear() {
43567
- preDirectoryResolutionCache.clear();
43568
- moduleNameToDirectoryMap.clear();
43574
+ clearAllExceptPackageJsonInfoCache();
43569
43575
  packageJsonInfoCache.clear();
43570
43576
  }
43577
+ function clearAllExceptPackageJsonInfoCache() {
43578
+ perDirectoryResolutionCache.clear();
43579
+ moduleNameToDirectoryMap.clear();
43580
+ }
43571
43581
  function update(options) {
43572
43582
  updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap);
43573
43583
  }
@@ -43643,13 +43653,16 @@ var ts;
43643
43653
  }
43644
43654
  ts.createModuleResolutionCache = createModuleResolutionCache;
43645
43655
  function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
43646
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43656
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
43647
43657
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
43648
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { clear: clear });
43658
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { clear: clear, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
43649
43659
  function clear() {
43650
- preDirectoryResolutionCache.clear();
43660
+ clearAllExceptPackageJsonInfoCache();
43651
43661
  packageJsonInfoCache.clear();
43652
43662
  }
43663
+ function clearAllExceptPackageJsonInfoCache() {
43664
+ perDirectoryResolutionCache.clear();
43665
+ }
43653
43666
  }
43654
43667
  ts.createTypeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache;
43655
43668
  function resolveModuleNameFromCache(moduleName, containingFile, cache, mode) {
@@ -51437,10 +51450,6 @@ var ts;
51437
51450
  checkExpressionCached(expression);
51438
51451
  return getNodeLinks(expression).resolvedSymbol;
51439
51452
  }
51440
- function getTargetOfPropertyAssignment(node, dontRecursivelyResolve) {
51441
- var expression = node.initializer;
51442
- return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
51443
- }
51444
51453
  function getTargetOfAccessExpression(node, dontRecursivelyResolve) {
51445
51454
  if (!(ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */)) {
51446
51455
  return undefined;
@@ -51472,7 +51481,7 @@ var ts;
51472
51481
  case 297 /* ShorthandPropertyAssignment */:
51473
51482
  return resolveEntityName(node.name, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */, /*ignoreErrors*/ true, dontRecursivelyResolve);
51474
51483
  case 296 /* PropertyAssignment */:
51475
- return getTargetOfPropertyAssignment(node, dontRecursivelyResolve);
51484
+ return getTargetOfAliasLikeExpression(node.initializer, dontRecursivelyResolve);
51476
51485
  case 207 /* ElementAccessExpression */:
51477
51486
  case 206 /* PropertyAccessExpression */:
51478
51487
  return getTargetOfAccessExpression(node, dontRecursivelyResolve);
@@ -56997,7 +57006,7 @@ var ts;
56997
57006
  (resolvedSymbol || symbol).exports.forEach(function (s, name) {
56998
57007
  var _a;
56999
57008
  var exportedMember = members_4.get(name);
57000
- if (exportedMember && exportedMember !== s) {
57009
+ if (exportedMember && exportedMember !== s && !(s.flags & 2097152 /* Alias */)) {
57001
57010
  if (s.flags & 111551 /* Value */ && exportedMember.flags & 111551 /* Value */) {
57002
57011
  // If the member has an additional value-like declaration, union the types from the two declarations,
57003
57012
  // but issue an error if they occurred in two different files. The purpose is to support a JS file with
@@ -63489,6 +63498,7 @@ var ts;
63489
63498
  }
63490
63499
  }
63491
63500
  function getTypeFromImportTypeNode(node) {
63501
+ var _a;
63492
63502
  var links = getNodeLinks(node);
63493
63503
  if (!links.resolvedType) {
63494
63504
  if (node.isTypeOf && node.typeArguments) { // Only the non-typeof form can make use of type arguments
@@ -63508,6 +63518,7 @@ var ts;
63508
63518
  links.resolvedSymbol = unknownSymbol;
63509
63519
  return links.resolvedType = errorType;
63510
63520
  }
63521
+ var isExportEquals = !!((_a = innerModuleSymbol.exports) === null || _a === void 0 ? void 0 : _a.get("export=" /* ExportEquals */));
63511
63522
  var moduleSymbol = resolveExternalModuleSymbol(innerModuleSymbol, /*dontResolveAlias*/ false);
63512
63523
  if (!ts.nodeIsMissing(node.qualifier)) {
63513
63524
  var nameStack = getIdentifierChain(node.qualifier);
@@ -63519,9 +63530,11 @@ var ts;
63519
63530
  // That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
63520
63531
  // the `exports` lookup process that only looks up namespace members which is used for most type references
63521
63532
  var mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
63522
- var next = node.isTypeOf
63533
+ var symbolFromVariable = node.isTypeOf || ts.isInJSFile(node) && isExportEquals
63523
63534
  ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ true)
63524
- : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63535
+ : undefined;
63536
+ var symbolFromModule = node.isTypeOf ? undefined : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
63537
+ var next = symbolFromModule !== null && symbolFromModule !== void 0 ? symbolFromModule : symbolFromVariable;
63525
63538
  if (!next) {
63526
63539
  error(current, ts.Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), ts.declarationNameToString(current));
63527
63540
  return links.resolvedType = errorType;
@@ -82311,9 +82324,11 @@ var ts;
82311
82324
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82312
82325
  if (isGenericObjectType(type)) {
82313
82326
  var baseConstraint = getBaseConstraintOfType(type);
82314
- // We only need `Awaited<T>` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82327
+ // We only need `Awaited<T>` if `T` is a type variable that has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`,
82315
82328
  // or is promise-like.
82316
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82329
+ if (baseConstraint ?
82330
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82331
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82317
82332
  return true;
82318
82333
  }
82319
82334
  }
@@ -95085,10 +95100,11 @@ var ts;
95085
95100
  }
95086
95101
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
95087
95102
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
95088
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
95103
+ var operand = ts.skipParentheses(node.operand);
95104
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
95089
95105
  var info = void 0;
95090
- if (info = accessPrivateIdentifier(node.operand.name)) {
95091
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
95106
+ if (info = accessPrivateIdentifier(operand.name)) {
95107
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
95092
95108
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
95093
95109
  var expression = createPrivateIdentifierAccess(info, readExpression);
95094
95110
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -95104,7 +95120,7 @@ var ts;
95104
95120
  }
95105
95121
  }
95106
95122
  else if (shouldTransformSuperInStaticInitializers &&
95107
- ts.isSuperProperty(node.operand) &&
95123
+ ts.isSuperProperty(operand) &&
95108
95124
  currentStaticPropertyDeclarationOrStaticBlock &&
95109
95125
  currentClassLexicalEnvironment) {
95110
95126
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -95117,31 +95133,31 @@ var ts;
95117
95133
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
95118
95134
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
95119
95135
  if (facts & 1 /* ClassWasDecorated */) {
95120
- var operand = visitInvalidSuperProperty(node.operand);
95136
+ var expression = visitInvalidSuperProperty(operand);
95121
95137
  return ts.isPrefixUnaryExpression(node) ?
95122
- factory.updatePrefixUnaryExpression(node, operand) :
95123
- factory.updatePostfixUnaryExpression(node, operand);
95138
+ factory.updatePrefixUnaryExpression(node, expression) :
95139
+ factory.updatePostfixUnaryExpression(node, expression);
95124
95140
  }
95125
95141
  if (classConstructor && superClassReference) {
95126
95142
  var setterName = void 0;
95127
95143
  var getterName = void 0;
95128
- if (ts.isPropertyAccessExpression(node.operand)) {
95129
- if (ts.isIdentifier(node.operand.name)) {
95130
- getterName = setterName = factory.createStringLiteralFromNode(node.operand.name);
95144
+ if (ts.isPropertyAccessExpression(operand)) {
95145
+ if (ts.isIdentifier(operand.name)) {
95146
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
95131
95147
  }
95132
95148
  }
95133
95149
  else {
95134
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
95135
- getterName = setterName = node.operand.argumentExpression;
95150
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
95151
+ getterName = setterName = operand.argumentExpression;
95136
95152
  }
95137
95153
  else {
95138
95154
  getterName = factory.createTempVariable(hoistVariableDeclaration);
95139
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
95155
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
95140
95156
  }
95141
95157
  }
95142
95158
  if (setterName && getterName) {
95143
95159
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
95144
- ts.setTextRange(expression, node.operand);
95160
+ ts.setTextRange(expression, operand);
95145
95161
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
95146
95162
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
95147
95163
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117896,6 +117912,12 @@ var ts;
117896
117912
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117897
117913
  */
117898
117914
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117915
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117916
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117917
+ }
117918
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117919
+ /*@internal*/
117920
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117899
117921
  switch (ts.getEmitModuleResolutionKind(options)) {
117900
117922
  case ts.ModuleResolutionKind.Node16:
117901
117923
  case ts.ModuleResolutionKind.NodeNext:
@@ -117907,11 +117929,16 @@ var ts;
117907
117929
  return undefined;
117908
117930
  }
117909
117931
  function lookupFromPackageJson() {
117910
- var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117911
- return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117932
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117933
+ var packageJsonLocations = [];
117934
+ state.failedLookupLocations = packageJsonLocations;
117935
+ state.affectingLocations = packageJsonLocations;
117936
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117937
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117938
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117912
117939
  }
117913
117940
  }
117914
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117941
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117915
117942
  /** @internal */
117916
117943
  ts.plainJSErrors = new ts.Set([
117917
117944
  // binder errors
@@ -118236,7 +118263,7 @@ var ts;
118236
118263
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118237
118264
  var oldSourceFile = oldSourceFiles_1[_i];
118238
118265
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118239
- if (shouldCreateNewSourceFile || !newFile ||
118266
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118240
118267
  // old file wasn't redirect but new file is
118241
118268
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118242
118269
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118629,7 +118656,7 @@ var ts;
118629
118656
  });
118630
118657
  }
118631
118658
  function tryReuseStructureFromOldProgram() {
118632
- var _a;
118659
+ var _a, _b;
118633
118660
  if (!oldProgram) {
118634
118661
  return 0 /* Not */;
118635
118662
  }
@@ -118670,12 +118697,15 @@ var ts;
118670
118697
  var seenPackageNames = new ts.Map();
118671
118698
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118672
118699
  var oldSourceFile = oldSourceFiles_2[_i];
118700
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118673
118701
  var newSourceFile = host.getSourceFileByPath
118674
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
118675
- : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
118702
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118703
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118676
118704
  if (!newSourceFile) {
118677
118705
  return 0 /* Not */;
118678
118706
  }
118707
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118708
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118679
118709
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118680
118710
  var fileChanged = void 0;
118681
118711
  if (oldSourceFile.redirectInfo) {
@@ -118715,38 +118745,43 @@ var ts;
118715
118745
  seenPackageNames.set(packageName, newKind);
118716
118746
  }
118717
118747
  if (fileChanged) {
118748
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118749
+ structureIsReused = 1 /* SafeModules */;
118750
+ }
118718
118751
  // The `newSourceFile` object was created for the new program.
118719
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118752
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118720
118753
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118721
118754
  structureIsReused = 1 /* SafeModules */;
118722
118755
  }
118723
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118756
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118724
118757
  // value of no-default-lib has changed
118725
118758
  // this will affect if default library is injected into the list of files
118726
118759
  structureIsReused = 1 /* SafeModules */;
118727
118760
  }
118728
118761
  // check tripleslash references
118729
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118762
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118730
118763
  // tripleslash references has changed
118731
118764
  structureIsReused = 1 /* SafeModules */;
118732
118765
  }
118733
- // check imports and module augmentations
118734
- collectExternalModuleReferences(newSourceFile);
118735
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118736
- // imports has changed
118737
- structureIsReused = 1 /* SafeModules */;
118738
- }
118739
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118740
- // moduleAugmentations has changed
118741
- structureIsReused = 1 /* SafeModules */;
118742
- }
118743
- if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118744
- // dynamicImport has changed
118745
- structureIsReused = 1 /* SafeModules */;
118746
- }
118747
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118748
- // 'types' references has changed
118749
- structureIsReused = 1 /* SafeModules */;
118766
+ else {
118767
+ // check imports and module augmentations
118768
+ collectExternalModuleReferences(newSourceFile);
118769
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118770
+ // imports has changed
118771
+ structureIsReused = 1 /* SafeModules */;
118772
+ }
118773
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118774
+ // moduleAugmentations has changed
118775
+ structureIsReused = 1 /* SafeModules */;
118776
+ }
118777
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118778
+ // dynamicImport has changed
118779
+ structureIsReused = 1 /* SafeModules */;
118780
+ }
118781
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118782
+ // 'types' references has changed
118783
+ structureIsReused = 1 /* SafeModules */;
118784
+ }
118750
118785
  }
118751
118786
  // tentatively approve the file
118752
118787
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118764,18 +118799,18 @@ var ts;
118764
118799
  return structureIsReused;
118765
118800
  }
118766
118801
  var modifiedFiles = modifiedSourceFiles.map(function (f) { return f.oldFile; });
118767
- for (var _b = 0, oldSourceFiles_3 = oldSourceFiles; _b < oldSourceFiles_3.length; _b++) {
118768
- var oldFile = oldSourceFiles_3[_b];
118802
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118803
+ var oldFile = oldSourceFiles_3[_c];
118769
118804
  if (!ts.contains(modifiedFiles, oldFile)) {
118770
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118771
- var moduleName = _d[_c];
118805
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118806
+ var moduleName = _e[_d];
118772
118807
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118773
118808
  }
118774
118809
  }
118775
118810
  }
118776
118811
  // try to verify results of module resolution
118777
- for (var _e = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _e < modifiedSourceFiles_1.length; _e++) {
118778
- var _f = modifiedSourceFiles_1[_e], oldSourceFile = _f.oldFile, newSourceFile = _f.newFile;
118812
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118813
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118779
118814
  var moduleNames = getModuleNames(newSourceFile);
118780
118815
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118781
118816
  // ensure that module resolution results are still correct
@@ -118802,14 +118837,14 @@ var ts;
118802
118837
  if (structureIsReused !== 2 /* Completely */) {
118803
118838
  return structureIsReused;
118804
118839
  }
118805
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118840
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118806
118841
  return 1 /* SafeModules */;
118807
118842
  }
118808
118843
  missingFilePaths = oldProgram.getMissingFilePaths();
118809
118844
  // update fileName -> file mapping
118810
118845
  ts.Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
118811
- for (var _g = 0, newSourceFiles_1 = newSourceFiles; _g < newSourceFiles_1.length; _g++) {
118812
- var newSourceFile = newSourceFiles_1[_g];
118846
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118847
+ var newSourceFile = newSourceFiles_1[_h];
118813
118848
  filesByName.set(newSourceFile.path, newSourceFile);
118814
118849
  }
118815
118850
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119592,13 +119627,16 @@ var ts;
119592
119627
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119593
119628
  }
119594
119629
  }
119595
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119630
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119631
+ var _a;
119596
119632
  var redirect = Object.create(redirectTarget);
119597
119633
  redirect.fileName = fileName;
119598
119634
  redirect.path = path;
119599
119635
  redirect.resolvedPath = resolvedPath;
119600
119636
  redirect.originalFileName = originalFileName;
119601
119637
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119638
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119639
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119602
119640
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119603
119641
  Object.defineProperties(redirect, {
119604
119642
  id: {
@@ -119627,14 +119665,14 @@ var ts;
119627
119665
  // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
119628
119666
  // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
119629
119667
  // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
119630
- var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119631
- return {
119632
- languageVersion: ts.getEmitScriptTarget(options),
119633
- impliedNodeFormat: impliedNodeFormat,
119634
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
119635
- };
119668
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119669
+ var languageVersion = ts.getEmitScriptTarget(options);
119670
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119671
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119672
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119636
119673
  }
119637
119674
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119675
+ var _a, _b;
119638
119676
  var path = toPath(fileName);
119639
119677
  if (useSourceOfProjectReferenceRedirect) {
119640
119678
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119721,14 +119759,15 @@ var ts;
119721
119759
  }
119722
119760
  }
119723
119761
  // We haven't looked for this file, do so now and cache result
119724
- var file = host.getSourceFile(fileName, getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options), function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile);
119762
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119763
+ var file = host.getSourceFile(fileName, sourceFileOptions, function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile || (((_a = oldProgram === null || oldProgram === void 0 ? void 0 : oldProgram.getSourceFileByPath(toPath(fileName))) === null || _a === void 0 ? void 0 : _a.impliedNodeFormat) !== sourceFileOptions.impliedNodeFormat));
119725
119764
  if (packageId) {
119726
119765
  var packageIdKey = ts.packageIdToString(packageId);
119727
119766
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119728
119767
  if (fileFromPackageId) {
119729
119768
  // Some other SourceFile already exists with this package name and version.
119730
119769
  // Instead of creating a duplicate, just redirect to the existing one.
119731
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName); // TODO: GH#18217
119770
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119732
119771
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119733
119772
  addFileToFilesByName(dupFile, path, redirectedPath);
119734
119773
  addFileIncludeReason(dupFile, reason);
@@ -119749,6 +119788,8 @@ var ts;
119749
119788
  file.path = path;
119750
119789
  file.resolvedPath = toPath(fileName);
119751
119790
  file.originalFileName = originalFileName;
119791
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119792
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119752
119793
  addFileIncludeReason(file, reason);
119753
119794
  if (host.useCaseSensitiveFileNames()) {
119754
119795
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120379,7 +120420,7 @@ var ts;
120379
120420
  fileIncludeReasons = undefined;
120380
120421
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120381
120422
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120382
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120423
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120383
120424
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120384
120425
  return location && isReferenceFileLocation(location) ?
120385
120426
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122684,7 +122725,7 @@ var ts;
122684
122725
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122685
122726
  * @param dirPath
122686
122727
  */
122687
- function canWatchDirectory(dirPath) {
122728
+ function canWatchDirectoryOrFile(dirPath) {
122688
122729
  var rootLength = ts.getRootLength(dirPath);
122689
122730
  if (dirPath.length === rootLength) {
122690
122731
  // Ignore "/", "c:/"
@@ -122721,7 +122762,7 @@ var ts;
122721
122762
  }
122722
122763
  return true;
122723
122764
  }
122724
- ts.canWatchDirectory = canWatchDirectory;
122765
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122725
122766
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122726
122767
  var filesWithChangedSetOfUnresolvedImports;
122727
122768
  var filesWithInvalidatedResolutions;
@@ -122730,7 +122771,9 @@ var ts;
122730
122771
  var resolutionsWithFailedLookups = [];
122731
122772
  var resolutionsWithOnlyAffectingLocations = [];
122732
122773
  var resolvedFileToResolution = ts.createMultiMap();
122774
+ var impliedFormatPackageJsons = new ts.Map();
122733
122775
  var hasChangedAutomaticTypeDirectiveNames = false;
122776
+ var affectingPathChecksForFile;
122734
122777
  var affectingPathChecks;
122735
122778
  var failedLookupChecks;
122736
122779
  var startsWithPathChecks;
@@ -122770,7 +122813,7 @@ var ts;
122770
122813
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122771
122814
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122772
122815
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122773
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122816
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122774
122817
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122775
122818
  resolveModuleNames: resolveModuleNames,
122776
122819
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122814,9 +122857,10 @@ var ts;
122814
122857
  startsWithPathChecks = undefined;
122815
122858
  isInDirectoryChecks = undefined;
122816
122859
  affectingPathChecks = undefined;
122817
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122818
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122819
- clearPerDirectoryResolutions();
122860
+ affectingPathChecksForFile = undefined;
122861
+ moduleResolutionCache.clear();
122862
+ typeReferenceDirectiveResolutionCache.clear();
122863
+ impliedFormatPackageJsons.clear();
122820
122864
  hasChangedAutomaticTypeDirectiveNames = false;
122821
122865
  }
122822
122866
  function startRecordingFilesWithChangedResolutions() {
@@ -122848,15 +122892,44 @@ var ts;
122848
122892
  return function (path) { return (!!collected && collected.has(path)) ||
122849
122893
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122850
122894
  }
122851
- function clearPerDirectoryResolutions() {
122852
- moduleResolutionCache.clear();
122853
- typeReferenceDirectiveResolutionCache.clear();
122895
+ function startCachingPerDirectoryResolution() {
122896
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122897
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122898
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122899
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122854
122900
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122855
122901
  nonRelativeExternalModuleResolutions.clear();
122856
122902
  }
122857
- function finishCachingPerDirectoryResolution() {
122903
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122858
122904
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122859
- clearPerDirectoryResolutions();
122905
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122906
+ nonRelativeExternalModuleResolutions.clear();
122907
+ // Update file watches
122908
+ if (newProgram !== oldProgram) {
122909
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122910
+ var _a, _b, _c;
122911
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122912
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122913
+ for (var i = existing.length; i < expected; i++) {
122914
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122915
+ }
122916
+ if (existing.length > expected) {
122917
+ for (var i = expected; i < existing.length; i++) {
122918
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122919
+ }
122920
+ }
122921
+ if (expected)
122922
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122923
+ else
122924
+ impliedFormatPackageJsons.delete(newFile.path);
122925
+ });
122926
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122927
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122928
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122929
+ impliedFormatPackageJsons.delete(path);
122930
+ }
122931
+ });
122932
+ }
122860
122933
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122861
122934
  if (watcher.refCount === 0) {
122862
122935
  directoryWatchesOfFailedLookups.delete(path);
@@ -122864,7 +122937,7 @@ var ts;
122864
122937
  }
122865
122938
  });
122866
122939
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122867
- if (watcher.refCount === 0) {
122940
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122868
122941
  fileWatchesOfAffectingLocations.delete(path);
122869
122942
  watcher.watcher.close();
122870
122943
  // Ensure when watching symlinked package.json, we can close the actual file watcher only once
@@ -123095,7 +123168,7 @@ var ts;
123095
123168
  }
123096
123169
  // If the directory is node_modules use it to watch, always watch it recursively
123097
123170
  if (ts.isNodeModulesDirectory(dirPath)) {
123098
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123171
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123099
123172
  }
123100
123173
  var nonRecursive = true;
123101
123174
  // Use some ancestor of the root directory
@@ -123113,7 +123186,7 @@ var ts;
123113
123186
  dir = ts.getDirectoryPath(dir);
123114
123187
  }
123115
123188
  }
123116
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123189
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123117
123190
  }
123118
123191
  function isPathWithDefaultFailedLookupExtension(path) {
123119
123192
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -123184,46 +123257,58 @@ var ts;
123184
123257
  // Watch package json
123185
123258
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
123186
123259
  var affectingLocation = affectingLocations_1[_i];
123187
- createFileWatcherOfAffectingLocation(affectingLocation);
123260
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
123188
123261
  }
123189
123262
  }
123190
- function createFileWatcherOfAffectingLocation(affectingLocation) {
123191
- var path = resolutionHost.toPath(affectingLocation);
123192
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123263
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123264
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123193
123265
  if (fileWatcher) {
123194
- fileWatcher.refCount++;
123266
+ if (forResolution)
123267
+ fileWatcher.resolutions++;
123268
+ else
123269
+ fileWatcher.files++;
123195
123270
  return;
123196
123271
  }
123197
123272
  var locationToWatch = affectingLocation;
123198
- var locationToWatchPath = path;
123199
123273
  if (resolutionHost.realpath) {
123200
123274
  locationToWatch = resolutionHost.realpath(affectingLocation);
123201
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123202
- if (path !== locationToWatchPath) {
123203
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123275
+ if (affectingLocation !== locationToWatch) {
123276
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123204
123277
  if (fileWatcher_1) {
123205
- fileWatcher_1.refCount++;
123206
- fileWatcher_1.paths.add(path);
123207
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123278
+ if (forResolution)
123279
+ fileWatcher_1.resolutions++;
123280
+ else
123281
+ fileWatcher_1.files++;
123282
+ fileWatcher_1.paths.add(affectingLocation);
123283
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123208
123284
  return;
123209
123285
  }
123210
123286
  }
123211
123287
  }
123212
123288
  var paths = new ts.Set();
123213
- paths.add(locationToWatchPath);
123289
+ paths.add(locationToWatch);
123214
123290
  var watcher = {
123215
- watcher: resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123216
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, path, eventKind);
123217
- paths.forEach(function (path) { return (affectingPathChecks || (affectingPathChecks = new ts.Set())).add(path); });
123218
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123219
- }),
123220
- refCount: 1,
123291
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123292
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123293
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123294
+ paths.forEach(function (path) {
123295
+ var _a;
123296
+ if (watcher.resolutions)
123297
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123298
+ if (watcher.files)
123299
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123300
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123301
+ });
123302
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123303
+ }) : ts.noopFileWatcher,
123304
+ resolutions: forResolution ? 1 : 0,
123305
+ files: forResolution ? 0 : 1,
123221
123306
  paths: paths,
123222
123307
  };
123223
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123224
- if (path !== locationToWatchPath) {
123225
- fileWatchesOfAffectingLocations.set(path, watcher);
123226
- paths.add(path);
123308
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123309
+ if (affectingLocation !== locationToWatch) {
123310
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123311
+ paths.add(affectingLocation);
123227
123312
  }
123228
123313
  }
123229
123314
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123291,8 +123376,8 @@ var ts;
123291
123376
  }
123292
123377
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123293
123378
  var affectingLocation = affectingLocations_2[_a];
123294
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123295
- watcher.refCount--;
123379
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123380
+ watcher.resolutions--;
123296
123381
  }
123297
123382
  }
123298
123383
  function removeDirectoryWatcher(dirPath) {
@@ -123346,7 +123431,7 @@ var ts;
123346
123431
  resolution.isInvalidated = invalidated = true;
123347
123432
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123348
123433
  var containingFilePath = _b[_a];
123349
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123434
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123350
123435
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123351
123436
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123352
123437
  }
@@ -123413,10 +123498,25 @@ var ts;
123413
123498
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123414
123499
  }
123415
123500
  function invalidateResolutionsOfFailedLookupLocations() {
123501
+ var _a;
123502
+ var invalidated = false;
123503
+ if (affectingPathChecksForFile) {
123504
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123505
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123506
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123507
+ invalidated = true;
123508
+ }
123509
+ });
123510
+ affectingPathChecksForFile = undefined;
123511
+ }
123416
123512
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123417
- return false;
123513
+ return invalidated;
123514
+ }
123515
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123516
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123517
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123518
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123418
123519
  }
123419
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123420
123520
  failedLookupChecks = undefined;
123421
123521
  startsWithPathChecks = undefined;
123422
123522
  isInDirectoryChecks = undefined;
@@ -123429,17 +123529,15 @@ var ts;
123429
123529
  return true;
123430
123530
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123431
123531
  return false;
123432
- return resolution.failedLookupLocations.some(function (location) {
123433
- var locationPath = resolutionHost.toPath(location);
123434
- return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123435
- ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123436
- ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123437
- });
123532
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123533
+ }
123534
+ function isInvalidatedFailedLookup(locationPath) {
123535
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123536
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123537
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123438
123538
  }
123439
123539
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123440
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123441
- return affectingPathChecks.has(resolutionHost.toPath(location));
123442
- });
123540
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123443
123541
  }
123444
123542
  function closeTypeRootsWatch() {
123445
123543
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123505,7 +123603,7 @@ var ts;
123505
123603
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123506
123604
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123507
123605
  var dirPath = resolutionHost.toPath(dir);
123508
- return dirPath === rootPath || canWatchDirectory(dirPath);
123606
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123509
123607
  }
123510
123608
  }
123511
123609
  ts.createResolutionCache = createResolutionCache;
@@ -124478,23 +124576,46 @@ var ts;
124478
124576
  var file = _c[_i];
124479
124577
  write("" + toFileName(file, relativeFileName));
124480
124578
  (_a = reasons.get(file.path)) === null || _a === void 0 ? void 0 : _a.forEach(function (reason) { return write(" " + fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText); });
124481
- (_b = explainIfFileIsRedirect(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124579
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124482
124580
  }
124483
124581
  }
124484
124582
  ts.explainFiles = explainFiles;
124485
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124583
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124584
+ var _a;
124486
124585
  var result;
124487
124586
  if (file.path !== file.resolvedPath) {
124488
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124587
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124489
124588
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124490
124589
  }
124491
124590
  if (file.redirectInfo) {
124492
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124591
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124493
124592
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124494
124593
  }
124594
+ if (ts.isExternalOrCommonJsModule(file)) {
124595
+ switch (file.impliedNodeFormat) {
124596
+ case ts.ModuleKind.ESNext:
124597
+ if (file.packageJsonScope) {
124598
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124599
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124600
+ }
124601
+ break;
124602
+ case ts.ModuleKind.CommonJS:
124603
+ if (file.packageJsonScope) {
124604
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124605
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124606
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124607
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124608
+ }
124609
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124610
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124611
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124612
+ }
124613
+ break;
124614
+ }
124615
+ }
124495
124616
  return result;
124496
124617
  }
124497
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124618
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124498
124619
  function getMatchedFileSpec(program, fileName) {
124499
124620
  var _a;
124500
124621
  var configFile = program.getCompilerOptions().configFile;
@@ -124704,6 +124825,7 @@ var ts;
124704
124825
  MissingFile: "Missing file",
124705
124826
  WildcardDirectory: "Wild card directory",
124706
124827
  FailedLookupLocations: "Failed Lookup Locations",
124828
+ AffectingFileLocation: "File location affecting resolution",
124707
124829
  TypeRoots: "Type roots",
124708
124830
  ConfigFileOfReferencedProject: "Config file of referened project",
124709
124831
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -125027,7 +125149,7 @@ var ts;
125027
125149
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
125028
125150
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
125029
125151
  compilerHost.watchDirectoryOfFailedLookupLocation = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.FailedLookupLocations); };
125030
- compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.PackageJson); };
125152
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
125031
125153
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
125032
125154
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
125033
125155
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -125061,6 +125183,9 @@ var ts;
125061
125183
  return host.resolveTypeReferenceDirectives.apply(host, args);
125062
125184
  }) :
125063
125185
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
125186
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
125187
+ ts.maybeBind(host, host.getModuleResolutionCache) :
125188
+ (function () { return resolutionCache.getModuleResolutionCache(); });
125064
125189
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
125065
125190
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
125066
125191
  synchronizeProgram();
@@ -125163,8 +125288,9 @@ var ts;
125163
125288
  resolutionCache.startCachingPerDirectoryResolution();
125164
125289
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
125165
125290
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125291
+ var oldProgram = getCurrentProgram();
125166
125292
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
125167
- resolutionCache.finishCachingPerDirectoryResolution();
125293
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
125168
125294
  // Update watches
125169
125295
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
125170
125296
  if (needsUpdateInTypeRootWatch) {
@@ -125246,9 +125372,6 @@ var ts;
125246
125372
  sourceFilesCache.set(path, false);
125247
125373
  }
125248
125374
  }
125249
- if (sourceFile) {
125250
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125251
- }
125252
125375
  return sourceFile;
125253
125376
  }
125254
125377
  return hostSourceFile.sourceFile;
@@ -125764,6 +125887,7 @@ var ts;
125764
125887
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125765
125888
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125766
125889
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
125890
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125767
125891
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125768
125892
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125769
125893
  if (!compilerHost.resolveModuleNames) {
@@ -137982,60 +138106,64 @@ var ts;
137982
138106
  }
137983
138107
  return settingsOrHost;
137984
138108
  }
137985
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138109
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137986
138110
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137987
138111
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137988
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138112
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137989
138113
  }
137990
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137991
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
138114
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138115
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137992
138116
  }
137993
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138117
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137994
138118
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137995
138119
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137996
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138120
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137997
138121
  }
137998
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137999
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
138122
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138123
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
138000
138124
  }
138001
138125
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
138002
138126
  var entry = isDocumentRegistryEntry(bucketEntry) ? bucketEntry : bucketEntry.get(ts.Debug.checkDefined(scriptKind, "If there are more than one scriptKind's for same document the scriptKind should be provided"));
138003
138127
  ts.Debug.assert(scriptKind === undefined || !entry || entry.sourceFile.scriptKind === scriptKind, "Script kind should match provided ScriptKind:" + scriptKind + " and sourceFile.scriptKind: " + (entry === null || entry === void 0 ? void 0 : entry.sourceFile.scriptKind) + ", !entry: " + !entry);
138004
138128
  return entry;
138005
138129
  }
138006
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
138130
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
138007
138131
  var _a, _b, _c, _d;
138008
138132
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
138009
138133
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
138010
138134
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
138011
138135
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
138012
- var sourceFileOptions = {
138013
- languageVersion: scriptTarget,
138014
- impliedNodeFormat: host && ts.getImpliedNodeFormatForFile(path, (_d = (_c = (_b = (_a = host.getCompilerHost) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getModuleResolutionCache) === null || _c === void 0 ? void 0 : _c.call(_b)) === null || _d === void 0 ? void 0 : _d.getPackageJsonInfoCache(), host, compilationSettings),
138015
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138016
- };
138136
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
138137
+ languageVersionOrOptions :
138138
+ {
138139
+ languageVersion: scriptTarget,
138140
+ 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),
138141
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138142
+ };
138143
+ sourceFileOptions.languageVersion = scriptTarget;
138017
138144
  var oldBucketCount = buckets.size;
138018
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
138145
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
138146
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
138019
138147
  if (ts.tracing) {
138020
138148
  if (buckets.size > oldBucketCount) {
138021
138149
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
138022
138150
  // perhaps they are for two projects that don't have any overlap.
138023
138151
  // Bonus: these events can help us interpret the more interesting event below.
138024
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
138152
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
138025
138153
  }
138026
138154
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
138027
138155
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
138028
138156
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
138029
138157
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
138030
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
138158
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
138031
138159
  if (otherBucketKey) {
138032
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
138160
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
138033
138161
  }
138034
138162
  }
138035
138163
  var bucketEntry = bucket.get(path);
138036
138164
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
138037
138165
  if (!entry && externalCache) {
138038
- var sourceFile = externalCache.getDocument(key, path);
138166
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
138039
138167
  if (sourceFile) {
138040
138168
  ts.Debug.assert(acquiring);
138041
138169
  entry = {
@@ -138049,7 +138177,7 @@ var ts;
138049
138177
  // Have never seen this file with these settings. Create a new source file for it.
138050
138178
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
138051
138179
  if (externalCache) {
138052
- externalCache.setDocument(key, path, sourceFile);
138180
+ externalCache.setDocument(keyWithMode, path, sourceFile);
138053
138181
  }
138054
138182
  entry = {
138055
138183
  sourceFile: sourceFile,
@@ -138064,7 +138192,7 @@ var ts;
138064
138192
  if (entry.sourceFile.version !== version) {
138065
138193
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
138066
138194
  if (externalCache) {
138067
- externalCache.setDocument(key, path, entry.sourceFile);
138195
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
138068
138196
  }
138069
138197
  }
138070
138198
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -138093,13 +138221,13 @@ var ts;
138093
138221
  }
138094
138222
  }
138095
138223
  }
138096
- function releaseDocument(fileName, compilationSettings, scriptKind) {
138224
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
138097
138225
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
138098
138226
  var key = getKeyForCompilationSettings(compilationSettings);
138099
- return releaseDocumentWithKey(path, key, scriptKind);
138227
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
138100
138228
  }
138101
- function releaseDocumentWithKey(path, key, scriptKind) {
138102
- var bucket = ts.Debug.checkDefined(buckets.get(key));
138229
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
138230
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
138103
138231
  var bucketEntry = bucket.get(path);
138104
138232
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
138105
138233
  entry.languageServiceRefCount--;
@@ -138156,6 +138284,9 @@ var ts;
138156
138284
  function getKeyForCompilationSettings(settings) {
138157
138285
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
138158
138286
  }
138287
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
138288
+ return (mode ? key + "|" + mode : key);
138289
+ }
138159
138290
  })(ts || (ts = {}));
138160
138291
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
138161
138292
  /* @internal */
@@ -167399,12 +167530,12 @@ var ts;
167399
167530
  // not part of the new program.
167400
167531
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
167401
167532
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
167402
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
167533
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167403
167534
  }
167404
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
167405
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
167535
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
167536
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
167406
167537
  }
167407
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
167538
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
167408
167539
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
167409
167540
  // The program is asking for this file, check first if the host can locate it.
167410
167541
  // If the host can not locate the file, then it does not exist. return undefined
@@ -167447,17 +167578,17 @@ var ts;
167447
167578
  // file's script kind, i.e. in one project some file is treated as ".ts"
167448
167579
  // and in another as ".js"
167449
167580
  if (scriptKind === oldSourceFile.scriptKind) {
167450
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167581
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167451
167582
  }
167452
167583
  else {
167453
167584
  // Release old source file and fall through to aquire new file with new script kind
167454
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind);
167585
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167455
167586
  }
167456
167587
  }
167457
167588
  // We didn't already have the file. Fall through and acquire it from the registry.
167458
167589
  }
167459
167590
  // Could not find this file in the old program, create a new SourceFile for it.
167460
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167591
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167461
167592
  }
167462
167593
  }
167463
167594
  // TODO: GH#18217 frequently asserted as defined
@@ -167536,7 +167667,7 @@ var ts;
167536
167667
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
167537
167668
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
167538
167669
  ts.forEach(program.getSourceFiles(), function (f) {
167539
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167670
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
167540
167671
  });
167541
167672
  program = undefined; // TODO: GH#18217
167542
167673
  }
@@ -168453,6 +168584,7 @@ var ts;
168453
168584
  getEmitOutput: getEmitOutput,
168454
168585
  getNonBoundSourceFile: getNonBoundSourceFile,
168455
168586
  getProgram: getProgram,
168587
+ getCurrentProgram: function () { return program; },
168456
168588
  getAutoImportProvider: getAutoImportProvider,
168457
168589
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
168458
168590
  getApplicableRefactors: getApplicableRefactors,
@@ -171670,7 +171802,7 @@ var ts;
171670
171802
  };
171671
171803
  /*@internal*/
171672
171804
  Project.prototype.watchAffectingFileLocation = function (file, cb) {
171673
- return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.PackageJson, this);
171805
+ return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.AffectingFileLocation, this);
171674
171806
  };
171675
171807
  /*@internal*/
171676
171808
  Project.prototype.clearInvalidateResolutionOfFailedLookupTimer = function () {
@@ -172207,7 +172339,7 @@ var ts;
172207
172339
  };
172208
172340
  Project.prototype.updateGraphWorker = function () {
172209
172341
  var _this = this;
172210
- var oldProgram = this.program;
172342
+ var oldProgram = this.languageService.getCurrentProgram();
172211
172343
  ts.Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
172212
172344
  this.writeLog("Starting updateGraphWorker: Project: " + this.getProjectName());
172213
172345
  var start = ts.timestamp();
@@ -172216,7 +172348,7 @@ var ts;
172216
172348
  this.program = this.languageService.getProgram(); // TODO: GH#18217
172217
172349
  this.dirty = false;
172218
172350
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "finishCachingPerDirectoryResolution");
172219
- this.resolutionCache.finishCachingPerDirectoryResolution();
172351
+ this.resolutionCache.finishCachingPerDirectoryResolution(this.program, oldProgram);
172220
172352
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
172221
172353
  ts.Debug.assert(oldProgram === undefined || this.program !== undefined);
172222
172354
  // bump up the version if
@@ -174674,7 +174806,7 @@ var ts;
174674
174806
  // created when any of the script infos are added as root of inferred project
174675
174807
  if (this.configFileExistenceImpactsRootOfInferredProject(configFileExistenceInfo)) {
174676
174808
  // If we cannot watch config file existence without configured project, close the configured file watcher
174677
- if (!ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath))) {
174809
+ if (!ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath))) {
174678
174810
  configFileExistenceInfo.watcher.close();
174679
174811
  configFileExistenceInfo.watcher = noopConfigFileWatcher;
174680
174812
  }
@@ -174754,7 +174886,7 @@ var ts;
174754
174886
  // Set this file as the root of inferred project
174755
174887
  (configFileExistenceInfo.openFilesImpactedByConfigFile || (configFileExistenceInfo.openFilesImpactedByConfigFile = new ts.Map())).set(info.path, true);
174756
174888
  // If there is no configured project for this config file, add the file watcher
174757
- configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174889
+ configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174758
174890
  _this.watchFactory.watchFile(configFileName, function (_filename, eventKind) { return _this.onConfigFileChanged(canonicalConfigFilePath, eventKind); }, ts.PollingInterval.High, _this.hostConfiguration.watchOptions, ts.WatchType.ConfigFileForInferredRoot) :
174759
174891
  noopConfigFileWatcher);
174760
174892
  });