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.
@@ -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.20220731";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220803";
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;
@@ -66379,6 +66392,26 @@ var ts;
66379
66392
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66380
66393
  var saveErrorInfo = captureErrorCalculationState();
66381
66394
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66395
+ if (!result && (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */)) {
66396
+ // The combined constraint of an intersection type is the intersection of the constraints of
66397
+ // the constituents. When an intersection type contains instantiable types with union type
66398
+ // constraints, there are situations where we need to examine the combined constraint. One is
66399
+ // when the target is a union type. Another is when the intersection contains types belonging
66400
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
66401
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66402
+ // we need to check this constraint against a union on the target side. Also, given a type
66403
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66404
+ // 'string & number | number & number' which reduces to just 'number'.
66405
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
66406
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
66407
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66408
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66409
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66410
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66411
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66412
+ result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
66413
+ }
66414
+ }
66382
66415
  if (result) {
66383
66416
  resetErrorInfo(saveErrorInfo);
66384
66417
  }
@@ -66436,28 +66469,6 @@ var ts;
66436
66469
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
66437
66470
  return result;
66438
66471
  }
66439
- if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
66440
- // The combined constraint of an intersection type is the intersection of the constraints of
66441
- // the constituents. When an intersection type contains instantiable types with union type
66442
- // constraints, there are situations where we need to examine the combined constraint. One is
66443
- // when the target is a union type. Another is when the intersection contains types belonging
66444
- // to one of the disjoint domains. For example, given type variables T and U, each with the
66445
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
66446
- // we need to check this constraint against a union on the target side. Also, given a type
66447
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
66448
- // 'string & number | number & number' which reduces to just 'number'.
66449
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
66450
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
66451
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
66452
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
66453
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
66454
- if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66455
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66456
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66457
- return result;
66458
- }
66459
- }
66460
- }
66461
66472
  // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
66462
66473
  // Source is instantiable (e.g. source has union or intersection constraint).
66463
66474
  // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
@@ -82311,9 +82322,11 @@ var ts;
82311
82322
  // We only need `Awaited<T>` if `T` contains possibly non-primitive types.
82312
82323
  if (isGenericObjectType(type)) {
82313
82324
  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`,
82325
+ // 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
82326
  // or is promise-like.
82316
- if (!baseConstraint || (baseConstraint.flags & 3 /* AnyOrUnknown */) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
82327
+ if (baseConstraint ?
82328
+ baseConstraint.flags & 3 /* AnyOrUnknown */ || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
82329
+ maybeTypeOfKind(type, 8650752 /* TypeVariable */)) {
82317
82330
  return true;
82318
82331
  }
82319
82332
  }
@@ -95085,10 +95098,11 @@ var ts;
95085
95098
  }
95086
95099
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
95087
95100
  if (node.operator === 45 /* PlusPlusToken */ || node.operator === 46 /* MinusMinusToken */) {
95088
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
95101
+ var operand = ts.skipParentheses(node.operand);
95102
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
95089
95103
  var info = void 0;
95090
- if (info = accessPrivateIdentifier(node.operand.name)) {
95091
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
95104
+ if (info = accessPrivateIdentifier(operand.name)) {
95105
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
95092
95106
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
95093
95107
  var expression = createPrivateIdentifierAccess(info, readExpression);
95094
95108
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -95104,7 +95118,7 @@ var ts;
95104
95118
  }
95105
95119
  }
95106
95120
  else if (shouldTransformSuperInStaticInitializers &&
95107
- ts.isSuperProperty(node.operand) &&
95121
+ ts.isSuperProperty(operand) &&
95108
95122
  currentStaticPropertyDeclarationOrStaticBlock &&
95109
95123
  currentClassLexicalEnvironment) {
95110
95124
  // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`
@@ -95117,31 +95131,31 @@ var ts;
95117
95131
  // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)`
95118
95132
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
95119
95133
  if (facts & 1 /* ClassWasDecorated */) {
95120
- var operand = visitInvalidSuperProperty(node.operand);
95134
+ var expression = visitInvalidSuperProperty(operand);
95121
95135
  return ts.isPrefixUnaryExpression(node) ?
95122
- factory.updatePrefixUnaryExpression(node, operand) :
95123
- factory.updatePostfixUnaryExpression(node, operand);
95136
+ factory.updatePrefixUnaryExpression(node, expression) :
95137
+ factory.updatePostfixUnaryExpression(node, expression);
95124
95138
  }
95125
95139
  if (classConstructor && superClassReference) {
95126
95140
  var setterName = void 0;
95127
95141
  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);
95142
+ if (ts.isPropertyAccessExpression(operand)) {
95143
+ if (ts.isIdentifier(operand.name)) {
95144
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
95131
95145
  }
95132
95146
  }
95133
95147
  else {
95134
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
95135
- getterName = setterName = node.operand.argumentExpression;
95148
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
95149
+ getterName = setterName = operand.argumentExpression;
95136
95150
  }
95137
95151
  else {
95138
95152
  getterName = factory.createTempVariable(hoistVariableDeclaration);
95139
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
95153
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
95140
95154
  }
95141
95155
  }
95142
95156
  if (setterName && getterName) {
95143
95157
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
95144
- ts.setTextRange(expression, node.operand);
95158
+ ts.setTextRange(expression, operand);
95145
95159
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
95146
95160
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
95147
95161
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -117896,6 +117910,12 @@ var ts;
117896
117910
  * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
117897
117911
  */
117898
117912
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
117913
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
117914
+ return typeof result === "object" ? result.impliedNodeFormat : result;
117915
+ }
117916
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117917
+ /*@internal*/
117918
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117899
117919
  switch (ts.getEmitModuleResolutionKind(options)) {
117900
117920
  case ts.ModuleResolutionKind.Node16:
117901
117921
  case ts.ModuleResolutionKind.NodeNext:
@@ -117907,11 +117927,16 @@ var ts;
117907
117927
  return undefined;
117908
117928
  }
117909
117929
  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;
117930
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117931
+ var packageJsonLocations = [];
117932
+ state.failedLookupLocations = packageJsonLocations;
117933
+ state.affectingLocations = packageJsonLocations;
117934
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
117935
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117936
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
117912
117937
  }
117913
117938
  }
117914
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
117939
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
117915
117940
  /** @internal */
117916
117941
  ts.plainJSErrors = new ts.Set([
117917
117942
  // binder errors
@@ -118236,7 +118261,7 @@ var ts;
118236
118261
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
118237
118262
  var oldSourceFile = oldSourceFiles_1[_i];
118238
118263
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
118239
- if (shouldCreateNewSourceFile || !newFile ||
118264
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
118240
118265
  // old file wasn't redirect but new file is
118241
118266
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
118242
118267
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
@@ -118629,7 +118654,7 @@ var ts;
118629
118654
  });
118630
118655
  }
118631
118656
  function tryReuseStructureFromOldProgram() {
118632
- var _a;
118657
+ var _a, _b;
118633
118658
  if (!oldProgram) {
118634
118659
  return 0 /* Not */;
118635
118660
  }
@@ -118670,12 +118695,15 @@ var ts;
118670
118695
  var seenPackageNames = new ts.Map();
118671
118696
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
118672
118697
  var oldSourceFile = oldSourceFiles_2[_i];
118698
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
118673
118699
  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
118700
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
118701
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, /*onError*/ undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat); // TODO: GH#18217
118676
118702
  if (!newSourceFile) {
118677
118703
  return 0 /* Not */;
118678
118704
  }
118705
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
118706
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
118679
118707
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
118680
118708
  var fileChanged = void 0;
118681
118709
  if (oldSourceFile.redirectInfo) {
@@ -118715,38 +118743,43 @@ var ts;
118715
118743
  seenPackageNames.set(packageName, newKind);
118716
118744
  }
118717
118745
  if (fileChanged) {
118746
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
118747
+ structureIsReused = 1 /* SafeModules */;
118748
+ }
118718
118749
  // The `newSourceFile` object was created for the new program.
118719
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118750
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
118720
118751
  // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
118721
118752
  structureIsReused = 1 /* SafeModules */;
118722
118753
  }
118723
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118754
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
118724
118755
  // value of no-default-lib has changed
118725
118756
  // this will affect if default library is injected into the list of files
118726
118757
  structureIsReused = 1 /* SafeModules */;
118727
118758
  }
118728
118759
  // check tripleslash references
118729
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118760
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
118730
118761
  // tripleslash references has changed
118731
118762
  structureIsReused = 1 /* SafeModules */;
118732
118763
  }
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 */;
118764
+ else {
118765
+ // check imports and module augmentations
118766
+ collectExternalModuleReferences(newSourceFile);
118767
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
118768
+ // imports has changed
118769
+ structureIsReused = 1 /* SafeModules */;
118770
+ }
118771
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
118772
+ // moduleAugmentations has changed
118773
+ structureIsReused = 1 /* SafeModules */;
118774
+ }
118775
+ else if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
118776
+ // dynamicImport has changed
118777
+ structureIsReused = 1 /* SafeModules */;
118778
+ }
118779
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
118780
+ // 'types' references has changed
118781
+ structureIsReused = 1 /* SafeModules */;
118782
+ }
118750
118783
  }
118751
118784
  // tentatively approve the file
118752
118785
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
@@ -118764,18 +118797,18 @@ var ts;
118764
118797
  return structureIsReused;
118765
118798
  }
118766
118799
  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];
118800
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
118801
+ var oldFile = oldSourceFiles_3[_c];
118769
118802
  if (!ts.contains(modifiedFiles, oldFile)) {
118770
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
118771
- var moduleName = _d[_c];
118803
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
118804
+ var moduleName = _e[_d];
118772
118805
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
118773
118806
  }
118774
118807
  }
118775
118808
  }
118776
118809
  // 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;
118810
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
118811
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
118779
118812
  var moduleNames = getModuleNames(newSourceFile);
118780
118813
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
118781
118814
  // ensure that module resolution results are still correct
@@ -118802,14 +118835,14 @@ var ts;
118802
118835
  if (structureIsReused !== 2 /* Completely */) {
118803
118836
  return structureIsReused;
118804
118837
  }
118805
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
118838
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
118806
118839
  return 1 /* SafeModules */;
118807
118840
  }
118808
118841
  missingFilePaths = oldProgram.getMissingFilePaths();
118809
118842
  // update fileName -> file mapping
118810
118843
  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];
118844
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
118845
+ var newSourceFile = newSourceFiles_1[_h];
118813
118846
  filesByName.set(newSourceFile.path, newSourceFile);
118814
118847
  }
118815
118848
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -119592,13 +119625,16 @@ var ts;
119592
119625
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
119593
119626
  }
119594
119627
  }
119595
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
119628
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
119629
+ var _a;
119596
119630
  var redirect = Object.create(redirectTarget);
119597
119631
  redirect.fileName = fileName;
119598
119632
  redirect.path = path;
119599
119633
  redirect.resolvedPath = resolvedPath;
119600
119634
  redirect.originalFileName = originalFileName;
119601
119635
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
119636
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
119637
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
119602
119638
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
119603
119639
  Object.defineProperties(redirect, {
119604
119640
  id: {
@@ -119627,14 +119663,14 @@ var ts;
119627
119663
  // 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
119664
  // 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
119665
  // 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
- };
119666
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
119667
+ var languageVersion = ts.getEmitScriptTarget(options);
119668
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
119669
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
119670
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
119636
119671
  }
119637
119672
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
119673
+ var _a, _b;
119638
119674
  var path = toPath(fileName);
119639
119675
  if (useSourceOfProjectReferenceRedirect) {
119640
119676
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -119721,14 +119757,15 @@ var ts;
119721
119757
  }
119722
119758
  }
119723
119759
  // 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);
119760
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
119761
+ 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
119762
  if (packageId) {
119726
119763
  var packageIdKey = ts.packageIdToString(packageId);
119727
119764
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
119728
119765
  if (fileFromPackageId) {
119729
119766
  // Some other SourceFile already exists with this package name and version.
119730
119767
  // 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
119768
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
119732
119769
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
119733
119770
  addFileToFilesByName(dupFile, path, redirectedPath);
119734
119771
  addFileIncludeReason(dupFile, reason);
@@ -119749,6 +119786,8 @@ var ts;
119749
119786
  file.path = path;
119750
119787
  file.resolvedPath = toPath(fileName);
119751
119788
  file.originalFileName = originalFileName;
119789
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
119790
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
119752
119791
  addFileIncludeReason(file, reason);
119753
119792
  if (host.useCaseSensitiveFileNames()) {
119754
119793
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -120379,7 +120418,7 @@ var ts;
120379
120418
  fileIncludeReasons = undefined;
120380
120419
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
120381
120420
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
120382
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
120421
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
120383
120422
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
120384
120423
  return location && isReferenceFileLocation(location) ?
120385
120424
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -122684,7 +122723,7 @@ var ts;
122684
122723
  * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
122685
122724
  * @param dirPath
122686
122725
  */
122687
- function canWatchDirectory(dirPath) {
122726
+ function canWatchDirectoryOrFile(dirPath) {
122688
122727
  var rootLength = ts.getRootLength(dirPath);
122689
122728
  if (dirPath.length === rootLength) {
122690
122729
  // Ignore "/", "c:/"
@@ -122721,7 +122760,7 @@ var ts;
122721
122760
  }
122722
122761
  return true;
122723
122762
  }
122724
- ts.canWatchDirectory = canWatchDirectory;
122763
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
122725
122764
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
122726
122765
  var filesWithChangedSetOfUnresolvedImports;
122727
122766
  var filesWithInvalidatedResolutions;
@@ -122730,7 +122769,9 @@ var ts;
122730
122769
  var resolutionsWithFailedLookups = [];
122731
122770
  var resolutionsWithOnlyAffectingLocations = [];
122732
122771
  var resolvedFileToResolution = ts.createMultiMap();
122772
+ var impliedFormatPackageJsons = new ts.Map();
122733
122773
  var hasChangedAutomaticTypeDirectiveNames = false;
122774
+ var affectingPathChecksForFile;
122734
122775
  var affectingPathChecks;
122735
122776
  var failedLookupChecks;
122736
122777
  var startsWithPathChecks;
@@ -122770,7 +122811,7 @@ var ts;
122770
122811
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
122771
122812
  // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122772
122813
  // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122773
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
122814
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
122774
122815
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
122775
122816
  resolveModuleNames: resolveModuleNames,
122776
122817
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -122814,9 +122855,10 @@ var ts;
122814
122855
  startsWithPathChecks = undefined;
122815
122856
  isInDirectoryChecks = undefined;
122816
122857
  affectingPathChecks = undefined;
122817
- // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122818
- // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122819
- clearPerDirectoryResolutions();
122858
+ affectingPathChecksForFile = undefined;
122859
+ moduleResolutionCache.clear();
122860
+ typeReferenceDirectiveResolutionCache.clear();
122861
+ impliedFormatPackageJsons.clear();
122820
122862
  hasChangedAutomaticTypeDirectiveNames = false;
122821
122863
  }
122822
122864
  function startRecordingFilesWithChangedResolutions() {
@@ -122848,15 +122890,44 @@ var ts;
122848
122890
  return function (path) { return (!!collected && collected.has(path)) ||
122849
122891
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
122850
122892
  }
122851
- function clearPerDirectoryResolutions() {
122852
- moduleResolutionCache.clear();
122853
- typeReferenceDirectiveResolutionCache.clear();
122893
+ function startCachingPerDirectoryResolution() {
122894
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
122895
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
122896
+ // perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
122897
+ // (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
122854
122898
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122855
122899
  nonRelativeExternalModuleResolutions.clear();
122856
122900
  }
122857
- function finishCachingPerDirectoryResolution() {
122901
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
122858
122902
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
122859
- clearPerDirectoryResolutions();
122903
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122904
+ nonRelativeExternalModuleResolutions.clear();
122905
+ // Update file watches
122906
+ if (newProgram !== oldProgram) {
122907
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
122908
+ var _a, _b, _c;
122909
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
122910
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
122911
+ for (var i = existing.length; i < expected; i++) {
122912
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], /*forResolution*/ false);
122913
+ }
122914
+ if (existing.length > expected) {
122915
+ for (var i = expected; i < existing.length; i++) {
122916
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
122917
+ }
122918
+ }
122919
+ if (expected)
122920
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
122921
+ else
122922
+ impliedFormatPackageJsons.delete(newFile.path);
122923
+ });
122924
+ impliedFormatPackageJsons.forEach(function (existing, path) {
122925
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
122926
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
122927
+ impliedFormatPackageJsons.delete(path);
122928
+ }
122929
+ });
122930
+ }
122860
122931
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
122861
122932
  if (watcher.refCount === 0) {
122862
122933
  directoryWatchesOfFailedLookups.delete(path);
@@ -122864,7 +122935,7 @@ var ts;
122864
122935
  }
122865
122936
  });
122866
122937
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
122867
- if (watcher.refCount === 0) {
122938
+ if (watcher.files === 0 && watcher.resolutions === 0) {
122868
122939
  fileWatchesOfAffectingLocations.delete(path);
122869
122940
  watcher.watcher.close();
122870
122941
  // Ensure when watching symlinked package.json, we can close the actual file watcher only once
@@ -123095,7 +123166,7 @@ var ts;
123095
123166
  }
123096
123167
  // If the directory is node_modules use it to watch, always watch it recursively
123097
123168
  if (ts.isNodeModulesDirectory(dirPath)) {
123098
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123169
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
123099
123170
  }
123100
123171
  var nonRecursive = true;
123101
123172
  // Use some ancestor of the root directory
@@ -123113,7 +123184,7 @@ var ts;
123113
123184
  dir = ts.getDirectoryPath(dir);
123114
123185
  }
123115
123186
  }
123116
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123187
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
123117
123188
  }
123118
123189
  function isPathWithDefaultFailedLookupExtension(path) {
123119
123190
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -123184,46 +123255,58 @@ var ts;
123184
123255
  // Watch package json
123185
123256
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
123186
123257
  var affectingLocation = affectingLocations_1[_i];
123187
- createFileWatcherOfAffectingLocation(affectingLocation);
123258
+ createFileWatcherOfAffectingLocation(affectingLocation, /*forResolution*/ true);
123188
123259
  }
123189
123260
  }
123190
- function createFileWatcherOfAffectingLocation(affectingLocation) {
123191
- var path = resolutionHost.toPath(affectingLocation);
123192
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
123261
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
123262
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123193
123263
  if (fileWatcher) {
123194
- fileWatcher.refCount++;
123264
+ if (forResolution)
123265
+ fileWatcher.resolutions++;
123266
+ else
123267
+ fileWatcher.files++;
123195
123268
  return;
123196
123269
  }
123197
123270
  var locationToWatch = affectingLocation;
123198
- var locationToWatchPath = path;
123199
123271
  if (resolutionHost.realpath) {
123200
123272
  locationToWatch = resolutionHost.realpath(affectingLocation);
123201
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
123202
- if (path !== locationToWatchPath) {
123203
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
123273
+ if (affectingLocation !== locationToWatch) {
123274
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
123204
123275
  if (fileWatcher_1) {
123205
- fileWatcher_1.refCount++;
123206
- fileWatcher_1.paths.add(path);
123207
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
123276
+ if (forResolution)
123277
+ fileWatcher_1.resolutions++;
123278
+ else
123279
+ fileWatcher_1.files++;
123280
+ fileWatcher_1.paths.add(affectingLocation);
123281
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
123208
123282
  return;
123209
123283
  }
123210
123284
  }
123211
123285
  }
123212
123286
  var paths = new ts.Set();
123213
- paths.add(locationToWatchPath);
123287
+ paths.add(locationToWatch);
123214
123288
  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,
123289
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
123290
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
123291
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
123292
+ paths.forEach(function (path) {
123293
+ var _a;
123294
+ if (watcher.resolutions)
123295
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
123296
+ if (watcher.files)
123297
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
123298
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
123299
+ });
123300
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123301
+ }) : ts.noopFileWatcher,
123302
+ resolutions: forResolution ? 1 : 0,
123303
+ files: forResolution ? 0 : 1,
123221
123304
  paths: paths,
123222
123305
  };
123223
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
123224
- if (path !== locationToWatchPath) {
123225
- fileWatchesOfAffectingLocations.set(path, watcher);
123226
- paths.add(path);
123306
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
123307
+ if (affectingLocation !== locationToWatch) {
123308
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
123309
+ paths.add(affectingLocation);
123227
123310
  }
123228
123311
  }
123229
123312
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -123291,8 +123374,8 @@ var ts;
123291
123374
  }
123292
123375
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
123293
123376
  var affectingLocation = affectingLocations_2[_a];
123294
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
123295
- watcher.refCount--;
123377
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
123378
+ watcher.resolutions--;
123296
123379
  }
123297
123380
  }
123298
123381
  function removeDirectoryWatcher(dirPath) {
@@ -123346,7 +123429,7 @@ var ts;
123346
123429
  resolution.isInvalidated = invalidated = true;
123347
123430
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
123348
123431
  var containingFilePath = _b[_a];
123349
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123432
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
123350
123433
  // When its a file with inferred types resolution, invalidate type reference directive resolution
123351
123434
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
123352
123435
  }
@@ -123413,10 +123496,25 @@ var ts;
123413
123496
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
123414
123497
  }
123415
123498
  function invalidateResolutionsOfFailedLookupLocations() {
123499
+ var _a;
123500
+ var invalidated = false;
123501
+ if (affectingPathChecksForFile) {
123502
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
123503
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
123504
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
123505
+ invalidated = true;
123506
+ }
123507
+ });
123508
+ affectingPathChecksForFile = undefined;
123509
+ }
123416
123510
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
123417
- return false;
123511
+ return invalidated;
123512
+ }
123513
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
123514
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
123515
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
123516
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
123418
123517
  }
123419
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
123420
123518
  failedLookupChecks = undefined;
123421
123519
  startsWithPathChecks = undefined;
123422
123520
  isInDirectoryChecks = undefined;
@@ -123429,17 +123527,15 @@ var ts;
123429
123527
  return true;
123430
123528
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
123431
123529
  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
- });
123530
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
123531
+ }
123532
+ function isInvalidatedFailedLookup(locationPath) {
123533
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
123534
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
123535
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
123438
123536
  }
123439
123537
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
123440
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
123441
- return affectingPathChecks.has(resolutionHost.toPath(location));
123442
- });
123538
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
123443
123539
  }
123444
123540
  function closeTypeRootsWatch() {
123445
123541
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -123505,7 +123601,7 @@ var ts;
123505
123601
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
123506
123602
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
123507
123603
  var dirPath = resolutionHost.toPath(dir);
123508
- return dirPath === rootPath || canWatchDirectory(dirPath);
123604
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
123509
123605
  }
123510
123606
  }
123511
123607
  ts.createResolutionCache = createResolutionCache;
@@ -124478,23 +124574,46 @@ var ts;
124478
124574
  var file = _c[_i];
124479
124575
  write("" + toFileName(file, relativeFileName));
124480
124576
  (_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); });
124577
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
124482
124578
  }
124483
124579
  }
124484
124580
  ts.explainFiles = explainFiles;
124485
- function explainIfFileIsRedirect(file, fileNameConvertor) {
124581
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
124582
+ var _a;
124486
124583
  var result;
124487
124584
  if (file.path !== file.resolvedPath) {
124488
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124585
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124489
124586
  /*details*/ undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
124490
124587
  }
124491
124588
  if (file.redirectInfo) {
124492
- (result || (result = [])).push(ts.chainDiagnosticMessages(
124589
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124493
124590
  /*details*/ undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
124494
124591
  }
124592
+ if (ts.isExternalOrCommonJsModule(file)) {
124593
+ switch (file.impliedNodeFormat) {
124594
+ case ts.ModuleKind.ESNext:
124595
+ if (file.packageJsonScope) {
124596
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124597
+ /*details*/ undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124598
+ }
124599
+ break;
124600
+ case ts.ModuleKind.CommonJS:
124601
+ if (file.packageJsonScope) {
124602
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124603
+ /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ?
124604
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
124605
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
124606
+ }
124607
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
124608
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(
124609
+ /*details*/ undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
124610
+ }
124611
+ break;
124612
+ }
124613
+ }
124495
124614
  return result;
124496
124615
  }
124497
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
124616
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
124498
124617
  function getMatchedFileSpec(program, fileName) {
124499
124618
  var _a;
124500
124619
  var configFile = program.getCompilerOptions().configFile;
@@ -124704,6 +124823,7 @@ var ts;
124704
124823
  MissingFile: "Missing file",
124705
124824
  WildcardDirectory: "Wild card directory",
124706
124825
  FailedLookupLocations: "Failed Lookup Locations",
124826
+ AffectingFileLocation: "File location affecting resolution",
124707
124827
  TypeRoots: "Type roots",
124708
124828
  ConfigFileOfReferencedProject: "Config file of referened project",
124709
124829
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -125027,7 +125147,7 @@ var ts;
125027
125147
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
125028
125148
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
125029
125149
  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); };
125150
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
125031
125151
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
125032
125152
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
125033
125153
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -125061,6 +125181,9 @@ var ts;
125061
125181
  return host.resolveTypeReferenceDirectives.apply(host, args);
125062
125182
  }) :
125063
125183
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
125184
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
125185
+ ts.maybeBind(host, host.getModuleResolutionCache) :
125186
+ (function () { return resolutionCache.getModuleResolutionCache(); });
125064
125187
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
125065
125188
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
125066
125189
  synchronizeProgram();
@@ -125163,8 +125286,9 @@ var ts;
125163
125286
  resolutionCache.startCachingPerDirectoryResolution();
125164
125287
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
125165
125288
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
125289
+ var oldProgram = getCurrentProgram();
125166
125290
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
125167
- resolutionCache.finishCachingPerDirectoryResolution();
125291
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
125168
125292
  // Update watches
125169
125293
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
125170
125294
  if (needsUpdateInTypeRootWatch) {
@@ -125246,9 +125370,6 @@ var ts;
125246
125370
  sourceFilesCache.set(path, false);
125247
125371
  }
125248
125372
  }
125249
- if (sourceFile) {
125250
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
125251
- }
125252
125373
  return sourceFile;
125253
125374
  }
125254
125375
  return hostSourceFile.sourceFile;
@@ -125764,6 +125885,7 @@ var ts;
125764
125885
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
125765
125886
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
125766
125887
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
125888
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
125767
125889
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
125768
125890
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
125769
125891
  if (!compilerHost.resolveModuleNames) {
@@ -137982,60 +138104,64 @@ var ts;
137982
138104
  }
137983
138105
  return settingsOrHost;
137984
138106
  }
137985
- function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138107
+ function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137986
138108
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137987
138109
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137988
- return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138110
+ return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137989
138111
  }
137990
- function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137991
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
138112
+ function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138113
+ return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ true, scriptKind, languageVersionOrOptions);
137992
138114
  }
137993
- function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
138115
+ function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
137994
138116
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
137995
138117
  var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
137996
- return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
138118
+ return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions);
137997
138119
  }
137998
- function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
137999
- return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
138120
+ function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions) {
138121
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind, languageVersionOrOptions);
138000
138122
  }
138001
138123
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
138002
138124
  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
138125
  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
138126
  return entry;
138005
138127
  }
138006
- function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
138128
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind, languageVersionOrOptions) {
138007
138129
  var _a, _b, _c, _d;
138008
138130
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
138009
138131
  var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
138010
138132
  var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
138011
138133
  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
- };
138134
+ var sourceFileOptions = typeof languageVersionOrOptions === "object" ?
138135
+ languageVersionOrOptions :
138136
+ {
138137
+ languageVersion: scriptTarget,
138138
+ 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),
138139
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
138140
+ };
138141
+ sourceFileOptions.languageVersion = scriptTarget;
138017
138142
  var oldBucketCount = buckets.size;
138018
- var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
138143
+ var keyWithMode = getDocumentRegistryBucketKeyWithMode(key, sourceFileOptions.impliedNodeFormat);
138144
+ var bucket = ts.getOrUpdate(buckets, keyWithMode, function () { return new ts.Map(); });
138019
138145
  if (ts.tracing) {
138020
138146
  if (buckets.size > oldBucketCount) {
138021
138147
  // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
138022
138148
  // perhaps they are for two projects that don't have any overlap.
138023
138149
  // Bonus: these events can help us interpret the more interesting event below.
138024
- ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
138150
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: keyWithMode });
138025
138151
  }
138026
138152
  // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
138027
138153
  // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
138028
138154
  // Skip .d.ts files to reduce noise (should also cover most of node_modules).
138029
138155
  var otherBucketKey = !ts.isDeclarationFileName(path) &&
138030
- ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
138156
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== keyWithMode && bucket.has(path) && bucketKey; });
138031
138157
  if (otherBucketKey) {
138032
- ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
138158
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: keyWithMode });
138033
138159
  }
138034
138160
  }
138035
138161
  var bucketEntry = bucket.get(path);
138036
138162
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
138037
138163
  if (!entry && externalCache) {
138038
- var sourceFile = externalCache.getDocument(key, path);
138164
+ var sourceFile = externalCache.getDocument(keyWithMode, path);
138039
138165
  if (sourceFile) {
138040
138166
  ts.Debug.assert(acquiring);
138041
138167
  entry = {
@@ -138049,7 +138175,7 @@ var ts;
138049
138175
  // Have never seen this file with these settings. Create a new source file for it.
138050
138176
  var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
138051
138177
  if (externalCache) {
138052
- externalCache.setDocument(key, path, sourceFile);
138178
+ externalCache.setDocument(keyWithMode, path, sourceFile);
138053
138179
  }
138054
138180
  entry = {
138055
138181
  sourceFile: sourceFile,
@@ -138064,7 +138190,7 @@ var ts;
138064
138190
  if (entry.sourceFile.version !== version) {
138065
138191
  entry.sourceFile = ts.updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); // TODO: GH#18217
138066
138192
  if (externalCache) {
138067
- externalCache.setDocument(key, path, entry.sourceFile);
138193
+ externalCache.setDocument(keyWithMode, path, entry.sourceFile);
138068
138194
  }
138069
138195
  }
138070
138196
  // If we're acquiring, then this is the first time this LS is asking for this document.
@@ -138093,13 +138219,13 @@ var ts;
138093
138219
  }
138094
138220
  }
138095
138221
  }
138096
- function releaseDocument(fileName, compilationSettings, scriptKind) {
138222
+ function releaseDocument(fileName, compilationSettings, scriptKind, impliedNodeFormat) {
138097
138223
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
138098
138224
  var key = getKeyForCompilationSettings(compilationSettings);
138099
- return releaseDocumentWithKey(path, key, scriptKind);
138225
+ return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
138100
138226
  }
138101
- function releaseDocumentWithKey(path, key, scriptKind) {
138102
- var bucket = ts.Debug.checkDefined(buckets.get(key));
138227
+ function releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat) {
138228
+ var bucket = ts.Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
138103
138229
  var bucketEntry = bucket.get(path);
138104
138230
  var entry = getDocumentRegistryEntry(bucketEntry, scriptKind);
138105
138231
  entry.languageServiceRefCount--;
@@ -138156,6 +138282,9 @@ var ts;
138156
138282
  function getKeyForCompilationSettings(settings) {
138157
138283
  return ts.sourceFileAffectingCompilerOptions.map(function (option) { return compilerOptionValueToString(ts.getCompilerOptionValue(settings, option)); }).join("|") + (settings.pathsBasePath ? "|" + settings.pathsBasePath : undefined);
138158
138284
  }
138285
+ function getDocumentRegistryBucketKeyWithMode(key, mode) {
138286
+ return (mode ? key + "|" + mode : key);
138287
+ }
138159
138288
  })(ts || (ts = {}));
138160
138289
  /* Code for finding imports of an exported symbol. Used only by FindAllReferences. */
138161
138290
  /* @internal */
@@ -167399,12 +167528,12 @@ var ts;
167399
167528
  // not part of the new program.
167400
167529
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
167401
167530
  var oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions);
167402
- documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind);
167531
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167403
167532
  }
167404
- function getOrCreateSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
167405
- return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
167533
+ function getOrCreateSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
167534
+ return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersionOrOptions, onError, shouldCreateNewSourceFile);
167406
167535
  }
167407
- function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
167536
+ function getOrCreateSourceFileByPath(fileName, path, languageVersionOrOptions, _onError, shouldCreateNewSourceFile) {
167408
167537
  ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
167409
167538
  // The program is asking for this file, check first if the host can locate it.
167410
167539
  // If the host can not locate the file, then it does not exist. return undefined
@@ -167447,17 +167576,17 @@ var ts;
167447
167576
  // file's script kind, i.e. in one project some file is treated as ".ts"
167448
167577
  // and in another as ".js"
167449
167578
  if (scriptKind === oldSourceFile.scriptKind) {
167450
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
167579
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167451
167580
  }
167452
167581
  else {
167453
167582
  // 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);
167583
+ documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat);
167455
167584
  }
167456
167585
  }
167457
167586
  // We didn't already have the file. Fall through and acquire it from the registry.
167458
167587
  }
167459
167588
  // 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);
167589
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions);
167461
167590
  }
167462
167591
  }
167463
167592
  // TODO: GH#18217 frequently asserted as defined
@@ -167536,7 +167665,7 @@ var ts;
167536
167665
  // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host
167537
167666
  var key_1 = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions());
167538
167667
  ts.forEach(program.getSourceFiles(), function (f) {
167539
- return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind);
167668
+ return documentRegistry.releaseDocumentWithKey(f.resolvedPath, key_1, f.scriptKind, f.impliedNodeFormat);
167540
167669
  });
167541
167670
  program = undefined; // TODO: GH#18217
167542
167671
  }
@@ -168453,6 +168582,7 @@ var ts;
168453
168582
  getEmitOutput: getEmitOutput,
168454
168583
  getNonBoundSourceFile: getNonBoundSourceFile,
168455
168584
  getProgram: getProgram,
168585
+ getCurrentProgram: function () { return program; },
168456
168586
  getAutoImportProvider: getAutoImportProvider,
168457
168587
  updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
168458
168588
  getApplicableRefactors: getApplicableRefactors,
@@ -171670,7 +171800,7 @@ var ts;
171670
171800
  };
171671
171801
  /*@internal*/
171672
171802
  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);
171803
+ return this.projectService.watchFactory.watchFile(file, cb, ts.PollingInterval.High, this.projectService.getWatchOptions(this), ts.WatchType.AffectingFileLocation, this);
171674
171804
  };
171675
171805
  /*@internal*/
171676
171806
  Project.prototype.clearInvalidateResolutionOfFailedLookupTimer = function () {
@@ -172207,7 +172337,7 @@ var ts;
172207
172337
  };
172208
172338
  Project.prototype.updateGraphWorker = function () {
172209
172339
  var _this = this;
172210
- var oldProgram = this.program;
172340
+ var oldProgram = this.languageService.getCurrentProgram();
172211
172341
  ts.Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
172212
172342
  this.writeLog("Starting updateGraphWorker: Project: " + this.getProjectName());
172213
172343
  var start = ts.timestamp();
@@ -172216,7 +172346,7 @@ var ts;
172216
172346
  this.program = this.languageService.getProgram(); // TODO: GH#18217
172217
172347
  this.dirty = false;
172218
172348
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "finishCachingPerDirectoryResolution");
172219
- this.resolutionCache.finishCachingPerDirectoryResolution();
172349
+ this.resolutionCache.finishCachingPerDirectoryResolution(this.program, oldProgram);
172220
172350
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
172221
172351
  ts.Debug.assert(oldProgram === undefined || this.program !== undefined);
172222
172352
  // bump up the version if
@@ -174674,7 +174804,7 @@ var ts;
174674
174804
  // created when any of the script infos are added as root of inferred project
174675
174805
  if (this.configFileExistenceImpactsRootOfInferredProject(configFileExistenceInfo)) {
174676
174806
  // If we cannot watch config file existence without configured project, close the configured file watcher
174677
- if (!ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath))) {
174807
+ if (!ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath))) {
174678
174808
  configFileExistenceInfo.watcher.close();
174679
174809
  configFileExistenceInfo.watcher = noopConfigFileWatcher;
174680
174810
  }
@@ -174754,7 +174884,7 @@ var ts;
174754
174884
  // Set this file as the root of inferred project
174755
174885
  (configFileExistenceInfo.openFilesImpactedByConfigFile || (configFileExistenceInfo.openFilesImpactedByConfigFile = new ts.Map())).set(info.path, true);
174756
174886
  // If there is no configured project for this config file, add the file watcher
174757
- configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectory(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174887
+ configFileExistenceInfo.watcher || (configFileExistenceInfo.watcher = ts.canWatchDirectoryOrFile(ts.getDirectoryPath(canonicalConfigFilePath)) ?
174758
174888
  _this.watchFactory.watchFile(configFileName, function (_filename, eventKind) { return _this.onConfigFileChanged(canonicalConfigFilePath, eventKind); }, ts.PollingInterval.High, _this.hostConfiguration.watchOptions, ts.WatchType.ConfigFileForInferredRoot) :
174759
174889
  noopConfigFileWatcher);
174760
174890
  });