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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/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.20220731";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220803";
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;
@@ -66185,6 +66198,26 @@ var ts;
66185
66198
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66186
66199
  var saveErrorInfo = captureErrorCalculationState();
66187
66200
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66201
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66202
+ // The combined constraint of an intersection type is the intersection of the constraints of
66203
+ // the constituents. When an intersection type contains instantiable types with union type
66204
+ // constraints, there are situations where we need to examine the combined constraint. One is
66205
+ // when the target is a union type. Another is when the intersection contains types belonging
66206
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66207
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66208
+ // we need to check this constraint against a union on the target side. Also, given a type
66209
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66210
+ // 'string & number | number & number' which reduces to just 'number'.
66211
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66212
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66213
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66214
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66215
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66216
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66217
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66218
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66219
+ }
66220
+ }
66188
66221
  if (result) {
66189
66222
  resetErrorInfo(saveErrorInfo);
66190
66223
  }
@@ -66242,28 +66275,6 @@ var ts;
66242
66275
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66243
66276
  return result;
66244
66277
  }
66245
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66246
- // The combined constraint of an intersection type is the intersection of the constraints of
66247
- // the constituents. When an intersection type contains instantiable types with union type
66248
- // constraints, there are situations where we need to examine the combined constraint. One is
66249
- // when the target is a union type. Another is when the intersection contains types belonging
66250
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66251
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66252
- // we need to check this constraint against a union on the target side. Also, given a type
66253
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66254
- // 'string & number | number & number' which reduces to just 'number'.
66255
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66256
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66257
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66258
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66259
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66260
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66261
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66262
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66263
- return result;
66264
- }
66265
- }
66266
- }
66267
66278
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66268
66279
  // Source is instantiable (e.g. source has union or intersection constraint).
66269
66280
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -82117,9 +82128,11 @@ var ts;
82117
82128
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82118
82129
  if (isGenericObjectType(type)) {
82119
82130
  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`,
82131
+ // 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
82132
  // or is promise-like.
82122
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82133
+ if (baseConstraint ?
82134
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82135
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82123
82136
  return true;
82124
82137
  }
82125
82138
  }
@@ -94891,10 +94904,11 @@ var ts;
94891
94904
  }
94892
94905
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
94893
94906
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
94894
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
94907
+ var operand = ts.skipParentheses(node.operand);
94908
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
94895
94909
  var info = void 0;
94896
- if (info = accessPrivateIdentifier(node.operand.name)) {
94897
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
94910
+ if (info = accessPrivateIdentifier(operand.name)) {
94911
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
94898
94912
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
94899
94913
  var expression = createPrivateIdentifierAccess(info, readExpression);
94900
94914
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -94910,7 +94924,7 @@ var ts;
94910
94924
  }
94911
94925
  }
94912
94926
  else if (shouldTransformSuperInStaticInitializers &&
94913
- ts.isSuperProperty(node.operand) &&
94927
+ ts.isSuperProperty(operand) &&
94914
94928
  currentStaticPropertyDeclarationOrStaticBlock &&
94915
94929
  currentClassLexicalEnvironment) {
94916
94930
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -94923,31 +94937,31 @@ var ts;
94923
94937
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
94924
94938
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
94925
94939
  if (facts & 1 /* ClassWasDecorated */) {
94926
- var operand = visitInvalidSuperProperty(node.operand);
94940
+ var expression = visitInvalidSuperProperty(operand);
94927
94941
  return ts.isPrefixUnaryExpression(node) ?
94928
- factory.updatePrefixUnaryExpression(node, operand) :
94929
- factory.updatePostfixUnaryExpression(node, operand);
94942
+ factory.updatePrefixUnaryExpression(node, expression) :
94943
+ factory.updatePostfixUnaryExpression(node, expression);
94930
94944
  }
94931
94945
  if (classConstructor && superClassReference) {
94932
94946
  var setterName = void 0;
94933
94947
  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);
94948
+ if (ts.isPropertyAccessExpression(operand)) {
94949
+ if (ts.isIdentifier(operand.name)) {
94950
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
94937
94951
  }
94938
94952
  }
94939
94953
  else {
94940
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
94941
- getterName = setterName = node.operand.argumentExpression;
94954
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
94955
+ getterName = setterName = operand.argumentExpression;
94942
94956
  }
94943
94957
  else {
94944
94958
  getterName = factory.createTempVariable(hoistVariableDeclaration);
94945
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
94959
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
94946
94960
  }
94947
94961
  }
94948
94962
  if (setterName && getterName) {
94949
94963
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
94950
- ts.setTextRange(expression, node.operand);
94964
+ ts.setTextRange(expression, operand);
94951
94965
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
94952
94966
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
94953
94967
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117702,6 +117716,12 @@ var ts;
117702
117716
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117703
117717
  */
117704
117718
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117719
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117720
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117721
+ }
117722
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117723
+ /*@internal*/
117724
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117705
117725
  switch (ts.getEmitModuleResolutionKind(options)) {
117706
117726
  case ts.ModuleResolutionKind.Node16:
117707
117727
  case ts.ModuleResolutionKind.NodeNext:
@@ -117713,11 +117733,16 @@ var ts;
117713
117733
  return undefined;
117714
117734
  }
117715
117735
  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;
117736
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117737
+ var packageJsonLocations = [];
117738
+ state.failedLookupLocations = packageJsonLocations;
117739
+ state.affectingLocations = packageJsonLocations;
117740
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117741
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117742
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117718
117743
  }
117719
117744
  }
117720
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117745
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117721
117746
  /** @internal */
117722
117747
  ts.plainJSErrors = new ts.Set([
117723
117748
  // binder errors
@@ -118042,7 +118067,7 @@ var ts;
118042
118067
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118043
118068
  var oldSourceFile = oldSourceFiles_1[_i];
118044
118069
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118045
- if (shouldCreateNewSourceFile || !newFile ||
118070
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118046
118071
  // old file wasn't redirect but new file is
118047
118072
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118048
118073
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118435,7 +118460,7 @@ var ts;
118435
118460
  });
118436
118461
  }
118437
118462
  function tryReuseStructureFromOldProgram() {
118438
- var _a;
118463
+ var _a, _b;
118439
118464
  if (!oldProgram) {
118440
118465
  return 0 /* Not */;
118441
118466
  }
@@ -118476,12 +118501,15 @@ var ts;
118476
118501
  var seenPackageNames = new ts.Map();
118477
118502
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118478
118503
  var oldSourceFile = oldSourceFiles_2[_i];
118504
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118479
118505
  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
118506
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118507
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118482
118508
  if (!newSourceFile) {
118483
118509
  return 0 /* Not */;
118484
118510
  }
118511
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118512
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118485
118513
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118486
118514
  var fileChanged = void 0;
118487
118515
  if (oldSourceFile.redirectInfo) {
@@ -118521,38 +118549,43 @@ var ts;
118521
118549
  seenPackageNames.set(packageName, newKind);
118522
118550
  }
118523
118551
  if (fileChanged) {
118552
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118553
+ structureIsReused = 1 /* SafeModules */;
118554
+ }
118524
118555
  // The `newSourceFile` object was created for the new program.
118525
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118556
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118526
118557
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118527
118558
  structureIsReused = 1 /* SafeModules */;
118528
118559
  }
118529
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118560
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118530
118561
  // value of no-default-lib has changed
118531
118562
  // this will affect if default library is injected into the list of files
118532
118563
  structureIsReused = 1 /* SafeModules */;
118533
118564
  }
118534
118565
  // check tripleslash references
118535
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118566
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118536
118567
  // tripleslash references has changed
118537
118568
  structureIsReused = 1 /* SafeModules */;
118538
118569
  }
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 */;
118570
+ else {
118571
+ // check imports and module augmentations
118572
+ collectExternalModuleReferences(newSourceFile);
118573
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118574
+ // imports has changed
118575
+ structureIsReused = 1 /* SafeModules */;
118576
+ }
118577
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118578
+ // moduleAugmentations has changed
118579
+ structureIsReused = 1 /* SafeModules */;
118580
+ }
118581
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118582
+ // dynamicImport has changed
118583
+ structureIsReused = 1 /* SafeModules */;
118584
+ }
118585
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118586
+ // 'types' references has changed
118587
+ structureIsReused = 1 /* SafeModules */;
118588
+ }
118556
118589
  }
118557
118590
  // tentatively approve the file
118558
118591
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118570,18 +118603,18 @@ var ts;
118570
118603
  return structureIsReused;
118571
118604
  }
118572
118605
  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];
118606
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118607
+ var oldFile = oldSourceFiles_3[_c];
118575
118608
  if (!ts.contains(modifiedFiles, oldFile)) {
118576
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118577
- var moduleName = _d[_c];
118609
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118610
+ var moduleName = _e[_d];
118578
118611
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118579
118612
  }
118580
118613
  }
118581
118614
  }
118582
118615
  // 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;
118616
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118617
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118585
118618
  var moduleNames = getModuleNames(newSourceFile);
118586
118619
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118587
118620
  // ensure that module resolution results are still correct
@@ -118608,14 +118641,14 @@ var ts;
118608
118641
  if (structureIsReused !== 2 /* Completely */) {
118609
118642
  return structureIsReused;
118610
118643
  }
118611
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118644
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118612
118645
  return 1 /* SafeModules */;
118613
118646
  }
118614
118647
  missingFilePaths = oldProgram.getMissingFilePaths();
118615
118648
  // update fileName -> file mapping
118616
118649
  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];
118650
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118651
+ var newSourceFile = newSourceFiles_1[_h];
118619
118652
  filesByName.set(newSourceFile.path, newSourceFile);
118620
118653
  }
118621
118654
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119398,13 +119431,16 @@ var ts;
119398
119431
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119399
119432
  }
119400
119433
  }
119401
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119434
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119435
+ var _a;
119402
119436
  var redirect = Object.create(redirectTarget);
119403
119437
  redirect.fileName = fileName;
119404
119438
  redirect.path = path;
119405
119439
  redirect.resolvedPath = resolvedPath;
119406
119440
  redirect.originalFileName = originalFileName;
119407
119441
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119442
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119443
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119408
119444
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119409
119445
  Object.defineProperties(redirect, {
119410
119446
  id: {
@@ -119433,14 +119469,14 @@ var ts;
119433
119469
  // 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
119470
  // 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
119471
  // 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
- };
119472
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119473
+ var languageVersion = ts.getEmitScriptTarget(options);
119474
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119475
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119476
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119442
119477
  }
119443
119478
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119479
+ var _a, _b;
119444
119480
  var path = toPath(fileName);
119445
119481
  if (useSourceOfProjectReferenceRedirect) {
119446
119482
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119527,14 +119563,15 @@ var ts;
119527
119563
  }
119528
119564
  }
119529
119565
  // 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);
119566
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119567
+ 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
119568
  if (packageId) {
119532
119569
  var packageIdKey = ts.packageIdToString(packageId);
119533
119570
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119534
119571
  if (fileFromPackageId) {
119535
119572
  // Some other SourceFile already exists with this package name and version.
119536
119573
  // 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
119574
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119538
119575
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119539
119576
  addFileToFilesByName(dupFile, path, redirectedPath);
119540
119577
  addFileIncludeReason(dupFile, reason);
@@ -119555,6 +119592,8 @@ var ts;
119555
119592
  file.path = path;
119556
119593
  file.resolvedPath = toPath(fileName);
119557
119594
  file.originalFileName = originalFileName;
119595
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119596
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119558
119597
  addFileIncludeReason(file, reason);
119559
119598
  if (host.useCaseSensitiveFileNames()) {
119560
119599
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120185,7 +120224,7 @@ var ts;
120185
120224
  fileIncludeReasons = undefined;
120186
120225
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120187
120226
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120188
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120227
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120189
120228
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120190
120229
  return location && isReferenceFileLocation(location) ?
120191
120230
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122490,7 +122529,7 @@ var ts;
122490
122529
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122491
122530
  * @param dirPath
122492
122531
  */
122493
- function canWatchDirectory(dirPath) {
122532
+ function canWatchDirectoryOrFile(dirPath) {
122494
122533
  var rootLength = ts.getRootLength(dirPath);
122495
122534
  if (dirPath.length === rootLength) {
122496
122535
  // Ignore "/", "c:/"
@@ -122527,7 +122566,7 @@ var ts;
122527
122566
  }
122528
122567
  return true;
122529
122568
  }
122530
- ts.canWatchDirectory = canWatchDirectory;
122569
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122531
122570
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122532
122571
  var filesWithChangedSetOfUnresolvedImports;
122533
122572
  var filesWithInvalidatedResolutions;
@@ -122536,7 +122575,9 @@ var ts;
122536
122575
  var resolutionsWithFailedLookups = [];
122537
122576
  var resolutionsWithOnlyAffectingLocations = [];
122538
122577
  var resolvedFileToResolution = ts.createMultiMap();
122578
+ var impliedFormatPackageJsons = new ts.Map();
122539
122579
  var hasChangedAutomaticTypeDirectiveNames = false;
122580
+ var affectingPathChecksForFile;
122540
122581
  var affectingPathChecks;
122541
122582
  var failedLookupChecks;
122542
122583
  var startsWithPathChecks;
@@ -122576,7 +122617,7 @@ var ts;
122576
122617
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122577
122618
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122578
122619
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122579
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122620
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122580
122621
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122581
122622
  resolveModuleNames: resolveModuleNames,
122582
122623
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122620,9 +122661,10 @@ var ts;
122620
122661
  startsWithPathChecks = undefined;
122621
122662
  isInDirectoryChecks = undefined;
122622
122663
  affectingPathChecks = undefined;
122623
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122624
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122625
- clearPerDirectoryResolutions();
122664
+ affectingPathChecksForFile = undefined;
122665
+ moduleResolutionCache.clear();
122666
+ typeReferenceDirectiveResolutionCache.clear();
122667
+ impliedFormatPackageJsons.clear();
122626
122668
  hasChangedAutomaticTypeDirectiveNames = false;
122627
122669
  }
122628
122670
  function startRecordingFilesWithChangedResolutions() {
@@ -122654,15 +122696,44 @@ var ts;
122654
122696
  return function (path) { return (!!collected && collected.has(path)) ||
122655
122697
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122656
122698
  }
122657
- function clearPerDirectoryResolutions() {
122658
- moduleResolutionCache.clear();
122659
- typeReferenceDirectiveResolutionCache.clear();
122699
+ function startCachingPerDirectoryResolution() {
122700
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122701
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122702
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122703
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122660
122704
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122661
122705
  nonRelativeExternalModuleResolutions.clear();
122662
122706
  }
122663
- function finishCachingPerDirectoryResolution() {
122707
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122664
122708
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122665
- clearPerDirectoryResolutions();
122709
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122710
+ nonRelativeExternalModuleResolutions.clear();
122711
+ // Update file watches
122712
+ if (newProgram !== oldProgram) {
122713
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122714
+ var _a, _b, _c;
122715
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122716
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122717
+ for (var i = existing.length; i < expected; i++) {
122718
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122719
+ }
122720
+ if (existing.length > expected) {
122721
+ for (var i = expected; i < existing.length; i++) {
122722
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122723
+ }
122724
+ }
122725
+ if (expected)
122726
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122727
+ else
122728
+ impliedFormatPackageJsons.delete(newFile.path);
122729
+ });
122730
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122731
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122732
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122733
+ impliedFormatPackageJsons.delete(path);
122734
+ }
122735
+ });
122736
+ }
122666
122737
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122667
122738
  if (watcher.refCount === 0) {
122668
122739
  directoryWatchesOfFailedLookups.delete(path);
@@ -122670,7 +122741,7 @@ var ts;
122670
122741
  }
122671
122742
  });
122672
122743
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122673
- if (watcher.refCount === 0) {
122744
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122674
122745
  fileWatchesOfAffectingLocations.delete(path);
122675
122746
  watcher.watcher.close();
122676
122747
  // Ensure when watching symlinked package.json, we can close the actual file watcher only once
@@ -122901,7 +122972,7 @@ var ts;
122901
122972
  }
122902
122973
  // If the directory is node_modules use it to watch, always watch it recursively
122903
122974
  if (ts.isNodeModulesDirectory(dirPath)) {
122904
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
122975
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
122905
122976
  }
122906
122977
  var nonRecursive = true;
122907
122978
  // Use some ancestor of the root directory
@@ -122919,7 +122990,7 @@ var ts;
122919
122990
  dir = ts.getDirectoryPath(dir);
122920
122991
  }
122921
122992
  }
122922
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
122993
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
122923
122994
  }
122924
122995
  function isPathWithDefaultFailedLookupExtension(path) {
122925
122996
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -122990,46 +123061,58 @@ var ts;
122990
123061
  // Watch package json
122991
123062
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
122992
123063
  var affectingLocation = affectingLocations_1[_i];
122993
- createFileWatcherOfAffectingLocation(affectingLocation);
123064
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
122994
123065
  }
122995
123066
  }
122996
- function createFileWatcherOfAffectingLocation(affectingLocation) {
122997
- var path = resolutionHost.toPath(affectingLocation);
122998
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123067
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123068
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
122999
123069
  if (fileWatcher) {
123000
- fileWatcher.refCount++;
123070
+ if (forResolution)
123071
+ fileWatcher.resolutions++;
123072
+ else
123073
+ fileWatcher.files++;
123001
123074
  return;
123002
123075
  }
123003
123076
  var locationToWatch = affectingLocation;
123004
- var locationToWatchPath = path;
123005
123077
  if (resolutionHost.realpath) {
123006
123078
  locationToWatch = resolutionHost.realpath(affectingLocation);
123007
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123008
- if (path !== locationToWatchPath) {
123009
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123079
+ if (affectingLocation !== locationToWatch) {
123080
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123010
123081
  if (fileWatcher_1) {
123011
- fileWatcher_1.refCount++;
123012
- fileWatcher_1.paths.add(path);
123013
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123082
+ if (forResolution)
123083
+ fileWatcher_1.resolutions++;
123084
+ else
123085
+ fileWatcher_1.files++;
123086
+ fileWatcher_1.paths.add(affectingLocation);
123087
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123014
123088
  return;
123015
123089
  }
123016
123090
  }
123017
123091
  }
123018
123092
  var paths = new ts.Set();
123019
- paths.add(locationToWatchPath);
123093
+ paths.add(locationToWatch);
123020
123094
  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,
123095
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123096
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123097
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123098
+ paths.forEach(function (path) {
123099
+ var _a;
123100
+ if (watcher.resolutions)
123101
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123102
+ if (watcher.files)
123103
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123104
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123105
+ });
123106
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123107
+ }) : ts.noopFileWatcher,
123108
+ resolutions: forResolution ? 1 : 0,
123109
+ files: forResolution ? 0 : 1,
123027
123110
  paths: paths,
123028
123111
  };
123029
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123030
- if (path !== locationToWatchPath) {
123031
- fileWatchesOfAffectingLocations.set(path, watcher);
123032
- paths.add(path);
123112
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123113
+ if (affectingLocation !== locationToWatch) {
123114
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123115
+ paths.add(affectingLocation);
123033
123116
  }
123034
123117
  }
123035
123118
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123097,8 +123180,8 @@ var ts;
123097
123180
  }
123098
123181
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123099
123182
  var affectingLocation = affectingLocations_2[_a];
123100
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123101
- watcher.refCount--;
123183
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123184
+ watcher.resolutions--;
123102
123185
  }
123103
123186
  }
123104
123187
  function removeDirectoryWatcher(dirPath) {
@@ -123152,7 +123235,7 @@ var ts;
123152
123235
  resolution.isInvalidated = invalidated = true;
123153
123236
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123154
123237
  var containingFilePath = _b[_a];
123155
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123238
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123156
123239
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123157
123240
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123158
123241
  }
@@ -123219,10 +123302,25 @@ var ts;
123219
123302
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123220
123303
  }
123221
123304
  function invalidateResolutionsOfFailedLookupLocations() {
123305
+ var _a;
123306
+ var invalidated = false;
123307
+ if (affectingPathChecksForFile) {
123308
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123309
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123310
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123311
+ invalidated = true;
123312
+ }
123313
+ });
123314
+ affectingPathChecksForFile = undefined;
123315
+ }
123222
123316
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123223
- return false;
123317
+ return invalidated;
123318
+ }
123319
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123320
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123321
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123322
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123224
123323
  }
123225
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123226
123324
  failedLookupChecks = undefined;
123227
123325
  startsWithPathChecks = undefined;
123228
123326
  isInDirectoryChecks = undefined;
@@ -123235,17 +123333,15 @@ var ts;
123235
123333
  return true;
123236
123334
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123237
123335
  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
- });
123336
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123337
+ }
123338
+ function isInvalidatedFailedLookup(locationPath) {
123339
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123340
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123341
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123244
123342
  }
123245
123343
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123246
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123247
- return affectingPathChecks.has(resolutionHost.toPath(location));
123248
- });
123344
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123249
123345
  }
123250
123346
  function closeTypeRootsWatch() {
123251
123347
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123311,7 +123407,7 @@ var ts;
123311
123407
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123312
123408
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123313
123409
  var dirPath = resolutionHost.toPath(dir);
123314
- return dirPath === rootPath || canWatchDirectory(dirPath);
123410
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123315
123411
  }
123316
123412
  }
123317
123413
  ts.createResolutionCache = createResolutionCache;
@@ -124284,23 +124380,46 @@ var ts;
124284
124380
  var file = _c[_i];
124285
124381
  write("" + toFileName(file, relativeFileName));
124286
124382
  (_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); });
124383
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124288
124384
  }
124289
124385
  }
124290
124386
  ts.explainFiles = explainFiles;
124291
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124387
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124388
+ var _a;
124292
124389
  var result;
124293
124390
  if (file.path !== file.resolvedPath) {
124294
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124391
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124295
124392
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124296
124393
  }
124297
124394
  if (file.redirectInfo) {
124298
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124395
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124299
124396
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124300
124397
  }
124398
+ if (ts.isExternalOrCommonJsModule(file)) {
124399
+ switch (file.impliedNodeFormat) {
124400
+ case ts.ModuleKind.ESNext:
124401
+ if (file.packageJsonScope) {
124402
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124403
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124404
+ }
124405
+ break;
124406
+ case ts.ModuleKind.CommonJS:
124407
+ if (file.packageJsonScope) {
124408
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124409
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124410
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124411
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124412
+ }
124413
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124414
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124415
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124416
+ }
124417
+ break;
124418
+ }
124419
+ }
124301
124420
  return result;
124302
124421
  }
124303
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124422
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124304
124423
  function getMatchedFileSpec(program, fileName) {
124305
124424
  var _a;
124306
124425
  var configFile = program.getCompilerOptions().configFile;
@@ -124510,6 +124629,7 @@ var ts;
124510
124629
  MissingFile: "Missing file",
124511
124630
  WildcardDirectory: "Wild card directory",
124512
124631
  FailedLookupLocations: "Failed Lookup Locations",
124632
+ AffectingFileLocation: "File location affecting resolution",
124513
124633
  TypeRoots: "Type roots",
124514
124634
  ConfigFileOfReferencedProject: "Config file of referened project",
124515
124635
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -124833,7 +124953,7 @@ var ts;
124833
124953
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
124834
124954
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
124835
124955
  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); };
124956
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
124837
124957
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
124838
124958
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
124839
124959
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -124867,6 +124987,9 @@ var ts;
124867
124987
  return host.resolveTypeReferenceDirectives.apply(host, args);
124868
124988
  }) :
124869
124989
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
124990
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
124991
+ ts.maybeBind(host, host.getModuleResolutionCache) :
124992
+ (function () { return resolutionCache.getModuleResolutionCache(); });
124870
124993
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
124871
124994
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
124872
124995
  synchronizeProgram();
@@ -124969,8 +125092,9 @@ var ts;
124969
125092
  resolutionCache.startCachingPerDirectoryResolution();
124970
125093
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
124971
125094
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125095
+ var oldProgram = getCurrentProgram();
124972
125096
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
124973
- resolutionCache.finishCachingPerDirectoryResolution();
125097
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
124974
125098
  // Update watches
124975
125099
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
124976
125100
  if (needsUpdateInTypeRootWatch) {
@@ -125052,9 +125176,6 @@ var ts;
125052
125176
  sourceFilesCache.set(path, false);
125053
125177
  }
125054
125178
  }
125055
- if (sourceFile) {
125056
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125057
- }
125058
125179
  return sourceFile;
125059
125180
  }
125060
125181
  return hostSourceFile.sourceFile;
@@ -125570,6 +125691,7 @@ var ts;
125570
125691
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125571
125692
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125572
125693
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
125694
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125573
125695
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125574
125696
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125575
125697
  if (!compilerHost.resolveModuleNames) {
@@ -137369,60 +137491,64 @@ var ts;
137369
137491
  }
137370
137492
  return settingsOrHost;
137371
137493
  }
137372
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
137494
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137373
137495
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137374
137496
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137375
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
137497
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137376
137498
  }
137377
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137378
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
137499
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137500
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137379
137501
  }
137380
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
137502
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137381
137503
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137382
137504
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137383
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
137505
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137384
137506
  }
137385
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137386
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
137507
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137508
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
137387
137509
  }
137388
137510
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
137389
137511
  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
137512
  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
137513
  return entry;
137392
137514
  }
137393
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
137515
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
137394
137516
  var _a, _b, _c, _d;
137395
137517
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
137396
137518
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
137397
137519
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
137398
137520
  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
- };
137521
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
137522
+ languageVersionOrOptions :
137523
+ {
137524
+ languageVersion: scriptTarget,
137525
+ 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),
137526
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
137527
+ };
137528
+ sourceFileOptions.languageVersion = scriptTarget;
137404
137529
  var oldBucketCount = buckets.size;
137405
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
137530
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
137531
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
137406
137532
  if (ts.tracing) {
137407
137533
  if (buckets.size > oldBucketCount) {
137408
137534
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
137409
137535
  // perhaps they are for two projects that don't have any overlap.
137410
137536
  // Bonus: these events can help us interpret the more interesting event below.
137411
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
137537
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
137412
137538
  }
137413
137539
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
137414
137540
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
137415
137541
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
137416
137542
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
137417
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
137543
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
137418
137544
  if (otherBucketKey) {
137419
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
137545
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
137420
137546
  }
137421
137547
  }
137422
137548
  var bucketEntry = bucket.get(path);
137423
137549
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
137424
137550
  if (!entry && externalCache) {
137425
- var sourceFile = externalCache.getDocument(key, path);
137551
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
137426
137552
  if (sourceFile) {
137427
137553
  ts.Debug.assert(acquiring);
137428
137554
  entry = {
@@ -137436,7 +137562,7 @@ var ts;
137436
137562
  // Have never seen this file with these settings. Create a new source file for it.
137437
137563
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
137438
137564
  if (externalCache) {
137439
- externalCache.setDocument(key, path, sourceFile);
137565
+ externalCache.setDocument(keyWithMode, path, sourceFile);
137440
137566
  }
137441
137567
  entry = {
137442
137568
  sourceFile: sourceFile,
@@ -137451,7 +137577,7 @@ var ts;
137451
137577
  if (entry.sourceFile.version !== version) {
137452
137578
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
137453
137579
  if (externalCache) {
137454
- externalCache.setDocument(key, path, entry.sourceFile);
137580
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
137455
137581
  }
137456
137582
  }
137457
137583
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -137480,13 +137606,13 @@ var ts;
137480
137606
  }
137481
137607
  }
137482
137608
  }
137483
- function releaseDocument(fileName, compilationSettings, scriptKind) {
137609
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
137484
137610
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137485
137611
  var key = getKeyForCompilationSettings(compilationSettings);
137486
- return releaseDocumentWithKey(path, key, scriptKind);
137612
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
137487
137613
  }
137488
- function releaseDocumentWithKey(path, key, scriptKind) {
137489
- var bucket = ts.Debug.checkDefined(buckets.get(key));
137614
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
137615
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
137490
137616
  var bucketEntry = bucket.get(path);
137491
137617
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
137492
137618
  entry.languageServiceRefCount--;
@@ -137543,6 +137669,9 @@ var ts;
137543
137669
  function getKeyForCompilationSettings(settings) {
137544
137670
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
137545
137671
  }
137672
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
137673
+ return (mode ? key + "|" + mode : key);
137674
+ }
137546
137675
  })(ts || (ts = {}));
137547
137676
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
137548
137677
  /* @internal */
@@ -166786,12 +166915,12 @@ var ts;
166786
166915
  // not part of the new program.
166787
166916
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
166788
166917
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
166789
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
166918
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
166790
166919
  }
166791
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
166792
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
166920
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
166921
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
166793
166922
  }
166794
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
166923
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
166795
166924
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
166796
166925
  // The program is asking for this file, check first if the host can locate it.
166797
166926
  // If the host can not locate the file, then it does not exist. return undefined
@@ -166834,17 +166963,17 @@ var ts;
166834
166963
  // file's script kind, i.e. in one project some file is treated as ".ts"
166835
166964
  // and in another as ".js"
166836
166965
  if (scriptKind === oldSourceFile.scriptKind) {
166837
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
166966
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
166838
166967
  }
166839
166968
  else {
166840
166969
  // 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);
166970
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
166842
166971
  }
166843
166972
  }
166844
166973
  // We didn't already have the file. Fall through and acquire it from the registry.
166845
166974
  }
166846
166975
  // 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);
166976
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
166848
166977
  }
166849
166978
  }
166850
166979
  // TODO: GH#18217 frequently asserted as defined
@@ -166923,7 +167052,7 @@ var ts;
166923
167052
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
166924
167053
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
166925
167054
  ts.forEach(program.getSourceFiles(), function (f) {
166926
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167055
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
166927
167056
  });
166928
167057
  program = undefined; // TODO: GH#18217
166929
167058
  }
@@ -167840,6 +167969,7 @@ var ts;
167840
167969
  getEmitOutput: getEmitOutput,
167841
167970
  getNonBoundSourceFile: getNonBoundSourceFile,
167842
167971
  getProgram: getProgram,
167972
+ getCurrentProgram: function () { return program; },
167843
167973
  getAutoImportProvider: getAutoImportProvider,
167844
167974
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
167845
167975
  getApplicableRefactors: getApplicableRefactors,
@@ -171476,7 +171606,7 @@ var ts;
171476
171606
  };
171477
171607
  /*@internal*/
171478
171608
  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);
171609
+ return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.AffectingFileLocation, this);
171480
171610
  };
171481
171611
  /*@internal*/
171482
171612
  Project.prototype.clearInvalidateResolutionOfFailedLookupTimer = function () {
@@ -172013,7 +172143,7 @@ var ts;
172013
172143
  };
172014
172144
  Project.prototype.updateGraphWorker = function () {
172015
172145
  var _this = this;
172016
- var oldProgram = this.program;
172146
+ var oldProgram = this.languageService.getCurrentProgram();
172017
172147
  ts.Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
172018
172148
  this.writeLog("Starting updateGraphWorker: Project: " + this.getProjectName());
172019
172149
  var start = ts.timestamp();
@@ -172022,7 +172152,7 @@ var ts;
172022
172152
  this.program = this.languageService.getProgram(); // TODO: GH#18217
172023
172153
  this.dirty = false;
172024
172154
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "finishCachingPerDirectoryResolution");
172025
- this.resolutionCache.finishCachingPerDirectoryResolution();
172155
+ this.resolutionCache.finishCachingPerDirectoryResolution(this.program, oldProgram);
172026
172156
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
172027
172157
  ts.Debug.assert(oldProgram === undefined || this.program !== undefined);
172028
172158
  // bump up the version if
@@ -174480,7 +174610,7 @@ var ts;
174480
174610
  // created when any of the script infos are added as root of inferred project
174481
174611
  if (this.configFileExistenceImpactsRootOfInferredProject(configFileExistenceInfo)) {
174482
174612
  // If we cannot watch config file existence without configured project, close the configured file watcher
174483
- if (!ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath))) {
174613
+ if (!ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath))) {
174484
174614
  configFileExistenceInfo.watcher.close();
174485
174615
  configFileExistenceInfo.watcher = noopConfigFileWatcher;
174486
174616
  }
@@ -174560,7 +174690,7 @@ var ts;
174560
174690
  // Set this file as the root of inferred project
174561
174691
  (configFileExistenceInfo.openFilesImpactedByConfigFile || (configFileExistenceInfo.openFilesImpactedByConfigFile = new ts.Map())).set(info.path, true);
174562
174692
  // If there is no configured project for this config file, add the file watcher
174563
- configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174693
+ configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174564
174694
  _this.watchFactory.watchFile(configFileName, function (_filename, eventKind) { return _this.onConfigFileChanged(canonicalConfigFilePath, eventKind); }, ts.PollingInterval.High, _this.hostConfiguration.watchOptions, ts.WatchType.ConfigFileForInferredRoot) :
174565
174695
  noopConfigFileWatcher);
174566
174696
  });