typescript 4.8.0-dev.20220801 → 4.8.0-dev.20220802

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsc.js CHANGED
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  var ts;
70
70
  (function (ts) {
71
71
  ts.versionMajorMinor = "4.8";
72
- ts.version = ts.versionMajorMinor + ".0-dev.20220801";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220802";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -5727,6 +5727,10 @@ var ts;
5727
5727
  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."),
5728
5728
  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`."),
5729
5729
  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 '**/*'"),
5730
+ 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\""),
5731
+ 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\""),
5732
+ 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\""),
5733
+ 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"),
5730
5734
  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."),
5731
5735
  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."),
5732
5736
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -35334,7 +35338,7 @@ var ts;
35334
35338
  ts.createCacheWithRedirects = createCacheWithRedirects;
35335
35339
  function createPackageJsonInfoCache(currentDirectory, getCanonicalFileName) {
35336
35340
  var cache;
35337
- return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries };
35341
+ return { getPackageJsonInfo: getPackageJsonInfo, setPackageJsonInfo: setPackageJsonInfo, clear: clear, entries: entries, getInternalMap: getInternalMap };
35338
35342
  function getPackageJsonInfo(packageJsonPath) {
35339
35343
  return cache === null || cache === void 0 ? void 0 : cache.get(ts.toPath(packageJsonPath, currentDirectory, getCanonicalFileName));
35340
35344
  }
@@ -35348,6 +35352,9 @@ var ts;
35348
35352
  var iter = cache === null || cache === void 0 ? void 0 : cache.entries();
35349
35353
  return iter ? ts.arrayFrom(iter) : [];
35350
35354
  }
35355
+ function getInternalMap() {
35356
+ return cache;
35357
+ }
35351
35358
  }
35352
35359
  function getOrCreateCache(cacheWithRedirects, redirectedReference, key, create) {
35353
35360
  var cache = cacheWithRedirects.getOrCreateMapOfCacheRedirects(redirectedReference);
@@ -35446,15 +35453,18 @@ var ts;
35446
35453
  }
35447
35454
  ts.zipToModeAwareCache = zipToModeAwareCache;
35448
35455
  function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, directoryToModuleNameMap, moduleNameToDirectoryMap) {
35449
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
35456
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
35450
35457
  moduleNameToDirectoryMap || (moduleNameToDirectoryMap = createCacheWithRedirects(options));
35451
35458
  var packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName);
35452
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; } });
35459
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { getOrCreateCacheForModuleName: getOrCreateCacheForModuleName, clear: clear, update: update, getPackageJsonInfoCache: function () { return packageJsonInfoCache; }, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
35453
35460
  function clear() {
35454
- preDirectoryResolutionCache.clear();
35455
- moduleNameToDirectoryMap.clear();
35461
+ clearAllExceptPackageJsonInfoCache();
35456
35462
  packageJsonInfoCache.clear();
35457
35463
  }
35464
+ function clearAllExceptPackageJsonInfoCache() {
35465
+ perDirectoryResolutionCache.clear();
35466
+ moduleNameToDirectoryMap.clear();
35467
+ }
35458
35468
  function update(options) {
35459
35469
  updateRedirectsMap(options, directoryToModuleNameMap, moduleNameToDirectoryMap);
35460
35470
  }
@@ -35511,13 +35521,16 @@ var ts;
35511
35521
  }
35512
35522
  ts.createModuleResolutionCache = createModuleResolutionCache;
35513
35523
  function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache, directoryToModuleNameMap) {
35514
- var preDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
35524
+ var perDirectoryResolutionCache = createPerDirectoryResolutionCache(currentDirectory, getCanonicalFileName, directoryToModuleNameMap || (directoryToModuleNameMap = createCacheWithRedirects(options)));
35515
35525
  packageJsonInfoCache || (packageJsonInfoCache = createPackageJsonInfoCache(currentDirectory, getCanonicalFileName));
35516
- return __assign(__assign(__assign({}, packageJsonInfoCache), preDirectoryResolutionCache), { clear: clear });
35526
+ return __assign(__assign(__assign({}, packageJsonInfoCache), perDirectoryResolutionCache), { clear: clear, clearAllExceptPackageJsonInfoCache: clearAllExceptPackageJsonInfoCache });
35517
35527
  function clear() {
35518
- preDirectoryResolutionCache.clear();
35528
+ clearAllExceptPackageJsonInfoCache();
35519
35529
  packageJsonInfoCache.clear();
35520
35530
  }
35531
+ function clearAllExceptPackageJsonInfoCache() {
35532
+ perDirectoryResolutionCache.clear();
35533
+ }
35521
35534
  }
35522
35535
  ts.createTypeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache;
35523
35536
  function resolveModuleNameFromCache(moduleName, containingFile, cache, mode) {
@@ -42105,10 +42118,6 @@ var ts;
42105
42118
  checkExpressionCached(expression);
42106
42119
  return getNodeLinks(expression).resolvedSymbol;
42107
42120
  }
42108
- function getTargetOfPropertyAssignment(node, dontRecursivelyResolve) {
42109
- var expression = node.initializer;
42110
- return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
42111
- }
42112
42121
  function getTargetOfAccessExpression(node, dontRecursivelyResolve) {
42113
42122
  if (!(ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63)) {
42114
42123
  return undefined;
@@ -42140,7 +42149,7 @@ var ts;
42140
42149
  case 297:
42141
42150
  return resolveEntityName(node.name, 111551 | 788968 | 1920, true, dontRecursivelyResolve);
42142
42151
  case 296:
42143
- return getTargetOfPropertyAssignment(node, dontRecursivelyResolve);
42152
+ return getTargetOfAliasLikeExpression(node.initializer, dontRecursivelyResolve);
42144
42153
  case 207:
42145
42154
  case 206:
42146
42155
  return getTargetOfAccessExpression(node, dontRecursivelyResolve);
@@ -46951,7 +46960,7 @@ var ts;
46951
46960
  (resolvedSymbol || symbol).exports.forEach(function (s, name) {
46952
46961
  var _a;
46953
46962
  var exportedMember = members_4.get(name);
46954
- if (exportedMember && exportedMember !== s) {
46963
+ if (exportedMember && exportedMember !== s && !(s.flags & 2097152)) {
46955
46964
  if (s.flags & 111551 && exportedMember.flags & 111551) {
46956
46965
  if (s.valueDeclaration && exportedMember.valueDeclaration && ts.getSourceFileOfNode(s.valueDeclaration) !== ts.getSourceFileOfNode(exportedMember.valueDeclaration)) {
46957
46966
  var unescapedName = ts.unescapeLeadingUnderscores(s.escapedName);
@@ -52630,6 +52639,7 @@ var ts;
52630
52639
  }
52631
52640
  }
52632
52641
  function getTypeFromImportTypeNode(node) {
52642
+ var _a;
52633
52643
  var links = getNodeLinks(node);
52634
52644
  if (!links.resolvedType) {
52635
52645
  if (node.isTypeOf && node.typeArguments) {
@@ -52648,6 +52658,7 @@ var ts;
52648
52658
  links.resolvedSymbol = unknownSymbol;
52649
52659
  return links.resolvedType = errorType;
52650
52660
  }
52661
+ var isExportEquals = !!((_a = innerModuleSymbol.exports) === null || _a === void 0 ? void 0 : _a.get("export="));
52651
52662
  var moduleSymbol = resolveExternalModuleSymbol(innerModuleSymbol, false);
52652
52663
  if (!ts.nodeIsMissing(node.qualifier)) {
52653
52664
  var nameStack = getIdentifierChain(node.qualifier);
@@ -52656,9 +52667,11 @@ var ts;
52656
52667
  while (current = nameStack.shift()) {
52657
52668
  var meaning = nameStack.length ? 1920 : targetMeaning;
52658
52669
  var mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
52659
- var next = node.isTypeOf
52670
+ var symbolFromVariable = node.isTypeOf || ts.isInJSFile(node) && isExportEquals
52660
52671
  ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText, false, true)
52661
- : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
52672
+ : undefined;
52673
+ var symbolFromModule = node.isTypeOf ? undefined : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
52674
+ var next = symbolFromModule !== null && symbolFromModule !== void 0 ? symbolFromModule : symbolFromVariable;
52662
52675
  if (!next) {
52663
52676
  error(current, ts.Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), ts.declarationNameToString(current));
52664
52677
  return links.resolvedType = errorType;
@@ -68947,7 +68960,9 @@ var ts;
68947
68960
  }
68948
68961
  if (isGenericObjectType(type)) {
68949
68962
  var baseConstraint = getBaseConstraintOfType(type);
68950
- if (!baseConstraint || (baseConstraint.flags & 3) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
68963
+ if (baseConstraint ?
68964
+ baseConstraint.flags & 3 || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
68965
+ maybeTypeOfKind(type, 8650752)) {
68951
68966
  return true;
68952
68967
  }
68953
68968
  }
@@ -79586,10 +79601,11 @@ var ts;
79586
79601
  }
79587
79602
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
79588
79603
  if (node.operator === 45 || node.operator === 46) {
79589
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
79604
+ var operand = ts.skipParentheses(node.operand);
79605
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
79590
79606
  var info = void 0;
79591
- if (info = accessPrivateIdentifier(node.operand.name)) {
79592
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
79607
+ if (info = accessPrivateIdentifier(operand.name)) {
79608
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
79593
79609
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
79594
79610
  var expression = createPrivateIdentifierAccess(info, readExpression);
79595
79611
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -79605,36 +79621,36 @@ var ts;
79605
79621
  }
79606
79622
  }
79607
79623
  else if (shouldTransformSuperInStaticInitializers &&
79608
- ts.isSuperProperty(node.operand) &&
79624
+ ts.isSuperProperty(operand) &&
79609
79625
  currentStaticPropertyDeclarationOrStaticBlock &&
79610
79626
  currentClassLexicalEnvironment) {
79611
79627
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
79612
79628
  if (facts & 1) {
79613
- var operand = visitInvalidSuperProperty(node.operand);
79629
+ var expression = visitInvalidSuperProperty(operand);
79614
79630
  return ts.isPrefixUnaryExpression(node) ?
79615
- factory.updatePrefixUnaryExpression(node, operand) :
79616
- factory.updatePostfixUnaryExpression(node, operand);
79631
+ factory.updatePrefixUnaryExpression(node, expression) :
79632
+ factory.updatePostfixUnaryExpression(node, expression);
79617
79633
  }
79618
79634
  if (classConstructor && superClassReference) {
79619
79635
  var setterName = void 0;
79620
79636
  var getterName = void 0;
79621
- if (ts.isPropertyAccessExpression(node.operand)) {
79622
- if (ts.isIdentifier(node.operand.name)) {
79623
- getterName = setterName = factory.createStringLiteralFromNode(node.operand.name);
79637
+ if (ts.isPropertyAccessExpression(operand)) {
79638
+ if (ts.isIdentifier(operand.name)) {
79639
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
79624
79640
  }
79625
79641
  }
79626
79642
  else {
79627
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
79628
- getterName = setterName = node.operand.argumentExpression;
79643
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
79644
+ getterName = setterName = operand.argumentExpression;
79629
79645
  }
79630
79646
  else {
79631
79647
  getterName = factory.createTempVariable(hoistVariableDeclaration);
79632
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
79648
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
79633
79649
  }
79634
79650
  }
79635
79651
  if (setterName && getterName) {
79636
79652
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
79637
- ts.setTextRange(expression, node.operand);
79653
+ ts.setTextRange(expression, operand);
79638
79654
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
79639
79655
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
79640
79656
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -97323,6 +97339,11 @@ var ts;
97323
97339
  }
97324
97340
  ts.getConfigFileParsingDiagnostics = getConfigFileParsingDiagnostics;
97325
97341
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
97342
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
97343
+ return typeof result === "object" ? result.impliedNodeFormat : result;
97344
+ }
97345
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
97346
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
97326
97347
  switch (ts.getEmitModuleResolutionKind(options)) {
97327
97348
  case ts.ModuleResolutionKind.Node16:
97328
97349
  case ts.ModuleResolutionKind.NodeNext:
@@ -97334,11 +97355,16 @@ var ts;
97334
97355
  return undefined;
97335
97356
  }
97336
97357
  function lookupFromPackageJson() {
97337
- var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
97338
- return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
97358
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
97359
+ var packageJsonLocations = [];
97360
+ state.failedLookupLocations = packageJsonLocations;
97361
+ state.affectingLocations = packageJsonLocations;
97362
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
97363
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
97364
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
97339
97365
  }
97340
97366
  }
97341
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
97367
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
97342
97368
  ts.plainJSErrors = new ts.Set([
97343
97369
  ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0.code,
97344
97370
  ts.Diagnostics.A_module_cannot_have_multiple_default_exports.code,
@@ -97616,7 +97642,7 @@ var ts;
97616
97642
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
97617
97643
  var oldSourceFile = oldSourceFiles_1[_i];
97618
97644
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
97619
- if (shouldCreateNewSourceFile || !newFile ||
97645
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
97620
97646
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
97621
97647
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
97622
97648
  }
@@ -97946,7 +97972,7 @@ var ts;
97946
97972
  });
97947
97973
  }
97948
97974
  function tryReuseStructureFromOldProgram() {
97949
- var _a;
97975
+ var _a, _b;
97950
97976
  if (!oldProgram) {
97951
97977
  return 0;
97952
97978
  }
@@ -97974,12 +98000,15 @@ var ts;
97974
98000
  var seenPackageNames = new ts.Map();
97975
98001
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
97976
98002
  var oldSourceFile = oldSourceFiles_2[_i];
98003
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
97977
98004
  var newSourceFile = host.getSourceFileByPath
97978
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), undefined, shouldCreateNewSourceFile)
97979
- : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), undefined, shouldCreateNewSourceFile);
98005
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
98006
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat);
97980
98007
  if (!newSourceFile) {
97981
98008
  return 0;
97982
98009
  }
98010
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
98011
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
97983
98012
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
97984
98013
  var fileChanged = void 0;
97985
98014
  if (oldSourceFile.redirectInfo) {
@@ -98012,27 +98041,32 @@ var ts;
98012
98041
  seenPackageNames.set(packageName, newKind);
98013
98042
  }
98014
98043
  if (fileChanged) {
98015
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
98016
- structureIsReused = 1;
98017
- }
98018
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
98019
- structureIsReused = 1;
98020
- }
98021
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
98044
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
98022
98045
  structureIsReused = 1;
98023
98046
  }
98024
- collectExternalModuleReferences(newSourceFile);
98025
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
98047
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
98026
98048
  structureIsReused = 1;
98027
98049
  }
98028
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
98050
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
98029
98051
  structureIsReused = 1;
98030
98052
  }
98031
- if ((oldSourceFile.flags & 6291456) !== (newSourceFile.flags & 6291456)) {
98053
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
98032
98054
  structureIsReused = 1;
98033
98055
  }
98034
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
98035
- structureIsReused = 1;
98056
+ else {
98057
+ collectExternalModuleReferences(newSourceFile);
98058
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
98059
+ structureIsReused = 1;
98060
+ }
98061
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
98062
+ structureIsReused = 1;
98063
+ }
98064
+ else if ((oldSourceFile.flags & 6291456) !== (newSourceFile.flags & 6291456)) {
98065
+ structureIsReused = 1;
98066
+ }
98067
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
98068
+ structureIsReused = 1;
98069
+ }
98036
98070
  }
98037
98071
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
98038
98072
  }
@@ -98046,17 +98080,17 @@ var ts;
98046
98080
  return structureIsReused;
98047
98081
  }
98048
98082
  var modifiedFiles = modifiedSourceFiles.map(function (f) { return f.oldFile; });
98049
- for (var _b = 0, oldSourceFiles_3 = oldSourceFiles; _b < oldSourceFiles_3.length; _b++) {
98050
- var oldFile = oldSourceFiles_3[_b];
98083
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
98084
+ var oldFile = oldSourceFiles_3[_c];
98051
98085
  if (!ts.contains(modifiedFiles, oldFile)) {
98052
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
98053
- var moduleName = _d[_c];
98086
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
98087
+ var moduleName = _e[_d];
98054
98088
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
98055
98089
  }
98056
98090
  }
98057
98091
  }
98058
- for (var _e = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _e < modifiedSourceFiles_1.length; _e++) {
98059
- var _f = modifiedSourceFiles_1[_e], oldSourceFile = _f.oldFile, newSourceFile = _f.newFile;
98092
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
98093
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
98060
98094
  var moduleNames = getModuleNames(newSourceFile);
98061
98095
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
98062
98096
  var resolutionsChanged = ts.hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, oldSourceFile, ts.moduleResolutionIsEqualTo);
@@ -98081,13 +98115,13 @@ var ts;
98081
98115
  if (structureIsReused !== 2) {
98082
98116
  return structureIsReused;
98083
98117
  }
98084
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
98118
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
98085
98119
  return 1;
98086
98120
  }
98087
98121
  missingFilePaths = oldProgram.getMissingFilePaths();
98088
98122
  ts.Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
98089
- for (var _g = 0, newSourceFiles_1 = newSourceFiles; _g < newSourceFiles_1.length; _g++) {
98090
- var newSourceFile = newSourceFiles_1[_g];
98123
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
98124
+ var newSourceFile = newSourceFiles_1[_h];
98091
98125
  filesByName.set(newSourceFile.path, newSourceFile);
98092
98126
  }
98093
98127
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -98787,13 +98821,16 @@ var ts;
98787
98821
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
98788
98822
  }
98789
98823
  }
98790
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
98824
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
98825
+ var _a;
98791
98826
  var redirect = Object.create(redirectTarget);
98792
98827
  redirect.fileName = fileName;
98793
98828
  redirect.path = path;
98794
98829
  redirect.resolvedPath = resolvedPath;
98795
98830
  redirect.originalFileName = originalFileName;
98796
98831
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
98832
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
98833
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
98797
98834
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
98798
98835
  Object.defineProperties(redirect, {
98799
98836
  id: {
@@ -98818,14 +98855,14 @@ var ts;
98818
98855
  return result;
98819
98856
  }
98820
98857
  function getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options) {
98821
- var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
98822
- return {
98823
- languageVersion: ts.getEmitScriptTarget(options),
98824
- impliedNodeFormat: impliedNodeFormat,
98825
- setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
98826
- };
98858
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
98859
+ var languageVersion = ts.getEmitScriptTarget(options);
98860
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
98861
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
98862
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
98827
98863
  }
98828
98864
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
98865
+ var _a, _b;
98829
98866
  var path = toPath(fileName);
98830
98867
  if (useSourceOfProjectReferenceRedirect) {
98831
98868
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -98895,12 +98932,13 @@ var ts;
98895
98932
  redirectedPath = toPath(redirect);
98896
98933
  }
98897
98934
  }
98898
- var file = host.getSourceFile(fileName, getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options), function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile);
98935
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
98936
+ var file = host.getSourceFile(fileName, sourceFileOptions, function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(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));
98899
98937
  if (packageId) {
98900
98938
  var packageIdKey = ts.packageIdToString(packageId);
98901
98939
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
98902
98940
  if (fileFromPackageId) {
98903
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName);
98941
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
98904
98942
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
98905
98943
  addFileToFilesByName(dupFile, path, redirectedPath);
98906
98944
  addFileIncludeReason(dupFile, reason);
@@ -98920,6 +98958,8 @@ var ts;
98920
98958
  file.path = path;
98921
98959
  file.resolvedPath = toPath(fileName);
98922
98960
  file.originalFileName = originalFileName;
98961
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
98962
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
98923
98963
  addFileIncludeReason(file, reason);
98924
98964
  if (host.useCaseSensitiveFileNames()) {
98925
98965
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -99496,7 +99536,7 @@ var ts;
99496
99536
  fileIncludeReasons = undefined;
99497
99537
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
99498
99538
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
99499
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
99539
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
99500
99540
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
99501
99541
  return location && isReferenceFileLocation(location) ?
99502
99542
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -101463,7 +101503,7 @@ var ts;
101463
101503
  path;
101464
101504
  }
101465
101505
  ts.removeIgnoredPath = removeIgnoredPath;
101466
- function canWatchDirectory(dirPath) {
101506
+ function canWatchDirectoryOrFile(dirPath) {
101467
101507
  var rootLength = ts.getRootLength(dirPath);
101468
101508
  if (dirPath.length === rootLength) {
101469
101509
  return false;
@@ -101495,7 +101535,7 @@ var ts;
101495
101535
  }
101496
101536
  return true;
101497
101537
  }
101498
- ts.canWatchDirectory = canWatchDirectory;
101538
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
101499
101539
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
101500
101540
  var filesWithChangedSetOfUnresolvedImports;
101501
101541
  var filesWithInvalidatedResolutions;
@@ -101504,7 +101544,9 @@ var ts;
101504
101544
  var resolutionsWithFailedLookups = [];
101505
101545
  var resolutionsWithOnlyAffectingLocations = [];
101506
101546
  var resolvedFileToResolution = ts.createMultiMap();
101547
+ var impliedFormatPackageJsons = new ts.Map();
101507
101548
  var hasChangedAutomaticTypeDirectiveNames = false;
101549
+ var affectingPathChecksForFile;
101508
101550
  var affectingPathChecks;
101509
101551
  var failedLookupChecks;
101510
101552
  var startsWithPathChecks;
@@ -101530,7 +101572,7 @@ var ts;
101530
101572
  getModuleResolutionCache: function () { return moduleResolutionCache; },
101531
101573
  startRecordingFilesWithChangedResolutions: startRecordingFilesWithChangedResolutions,
101532
101574
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
101533
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
101575
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
101534
101576
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
101535
101577
  resolveModuleNames: resolveModuleNames,
101536
101578
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -101574,7 +101616,10 @@ var ts;
101574
101616
  startsWithPathChecks = undefined;
101575
101617
  isInDirectoryChecks = undefined;
101576
101618
  affectingPathChecks = undefined;
101577
- clearPerDirectoryResolutions();
101619
+ affectingPathChecksForFile = undefined;
101620
+ moduleResolutionCache.clear();
101621
+ typeReferenceDirectiveResolutionCache.clear();
101622
+ impliedFormatPackageJsons.clear();
101578
101623
  hasChangedAutomaticTypeDirectiveNames = false;
101579
101624
  }
101580
101625
  function startRecordingFilesWithChangedResolutions() {
@@ -101603,15 +101648,41 @@ var ts;
101603
101648
  return function (path) { return (!!collected && collected.has(path)) ||
101604
101649
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
101605
101650
  }
101606
- function clearPerDirectoryResolutions() {
101607
- moduleResolutionCache.clear();
101608
- typeReferenceDirectiveResolutionCache.clear();
101651
+ function startCachingPerDirectoryResolution() {
101652
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
101653
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
101609
101654
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
101610
101655
  nonRelativeExternalModuleResolutions.clear();
101611
101656
  }
101612
- function finishCachingPerDirectoryResolution() {
101657
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
101613
101658
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
101614
- clearPerDirectoryResolutions();
101659
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
101660
+ nonRelativeExternalModuleResolutions.clear();
101661
+ if (newProgram !== oldProgram) {
101662
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
101663
+ var _a, _b, _c;
101664
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
101665
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
101666
+ for (var i = existing.length; i < expected; i++) {
101667
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], false);
101668
+ }
101669
+ if (existing.length > expected) {
101670
+ for (var i = expected; i < existing.length; i++) {
101671
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
101672
+ }
101673
+ }
101674
+ if (expected)
101675
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
101676
+ else
101677
+ impliedFormatPackageJsons.delete(newFile.path);
101678
+ });
101679
+ impliedFormatPackageJsons.forEach(function (existing, path) {
101680
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
101681
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
101682
+ impliedFormatPackageJsons.delete(path);
101683
+ }
101684
+ });
101685
+ }
101615
101686
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
101616
101687
  if (watcher.refCount === 0) {
101617
101688
  directoryWatchesOfFailedLookups.delete(path);
@@ -101619,7 +101690,7 @@ var ts;
101619
101690
  }
101620
101691
  });
101621
101692
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
101622
- if (watcher.refCount === 0) {
101693
+ if (watcher.files === 0 && watcher.resolutions === 0) {
101623
101694
  fileWatchesOfAffectingLocations.delete(path);
101624
101695
  watcher.watcher.close();
101625
101696
  watcher.watcher = ts.noopFileWatcher;
@@ -101828,7 +101899,7 @@ var ts;
101828
101899
  dirPath = ts.getDirectoryPath(dirPath);
101829
101900
  }
101830
101901
  if (ts.isNodeModulesDirectory(dirPath)) {
101831
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
101902
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
101832
101903
  }
101833
101904
  var nonRecursive = true;
101834
101905
  var subDirectoryPath, subDirectory;
@@ -101845,7 +101916,7 @@ var ts;
101845
101916
  dir = ts.getDirectoryPath(dir);
101846
101917
  }
101847
101918
  }
101848
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
101919
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
101849
101920
  }
101850
101921
  function isPathWithDefaultFailedLookupExtension(path) {
101851
101922
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -101912,46 +101983,58 @@ var ts;
101912
101983
  resolutionsWithOnlyAffectingLocations.push(resolution);
101913
101984
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
101914
101985
  var affectingLocation = affectingLocations_1[_i];
101915
- createFileWatcherOfAffectingLocation(affectingLocation);
101986
+ createFileWatcherOfAffectingLocation(affectingLocation, true);
101916
101987
  }
101917
101988
  }
101918
- function createFileWatcherOfAffectingLocation(affectingLocation) {
101919
- var path = resolutionHost.toPath(affectingLocation);
101920
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
101989
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
101990
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
101921
101991
  if (fileWatcher) {
101922
- fileWatcher.refCount++;
101992
+ if (forResolution)
101993
+ fileWatcher.resolutions++;
101994
+ else
101995
+ fileWatcher.files++;
101923
101996
  return;
101924
101997
  }
101925
101998
  var locationToWatch = affectingLocation;
101926
- var locationToWatchPath = path;
101927
101999
  if (resolutionHost.realpath) {
101928
102000
  locationToWatch = resolutionHost.realpath(affectingLocation);
101929
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
101930
- if (path !== locationToWatchPath) {
101931
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
102001
+ if (affectingLocation !== locationToWatch) {
102002
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
101932
102003
  if (fileWatcher_1) {
101933
- fileWatcher_1.refCount++;
101934
- fileWatcher_1.paths.add(path);
101935
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
102004
+ if (forResolution)
102005
+ fileWatcher_1.resolutions++;
102006
+ else
102007
+ fileWatcher_1.files++;
102008
+ fileWatcher_1.paths.add(affectingLocation);
102009
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
101936
102010
  return;
101937
102011
  }
101938
102012
  }
101939
102013
  }
101940
102014
  var paths = new ts.Set();
101941
- paths.add(locationToWatchPath);
102015
+ paths.add(locationToWatch);
101942
102016
  var watcher = {
101943
- watcher: resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
101944
- cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, path, eventKind);
101945
- paths.forEach(function (path) { return (affectingPathChecks || (affectingPathChecks = new ts.Set())).add(path); });
101946
- resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
101947
- }),
101948
- refCount: 1,
102017
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
102018
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
102019
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
102020
+ paths.forEach(function (path) {
102021
+ var _a;
102022
+ if (watcher.resolutions)
102023
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
102024
+ if (watcher.files)
102025
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
102026
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
102027
+ });
102028
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102029
+ }) : ts.noopFileWatcher,
102030
+ resolutions: forResolution ? 1 : 0,
102031
+ files: forResolution ? 0 : 1,
101949
102032
  paths: paths,
101950
102033
  };
101951
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
101952
- if (path !== locationToWatchPath) {
101953
- fileWatchesOfAffectingLocations.set(path, watcher);
101954
- paths.add(path);
102034
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
102035
+ if (affectingLocation !== locationToWatch) {
102036
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
102037
+ paths.add(affectingLocation);
101955
102038
  }
101956
102039
  }
101957
102040
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -102019,8 +102102,8 @@ var ts;
102019
102102
  }
102020
102103
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
102021
102104
  var affectingLocation = affectingLocations_2[_a];
102022
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
102023
- watcher.refCount--;
102105
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
102106
+ watcher.resolutions--;
102024
102107
  }
102025
102108
  }
102026
102109
  function removeDirectoryWatcher(dirPath) {
@@ -102069,7 +102152,7 @@ var ts;
102069
102152
  resolution.isInvalidated = invalidated = true;
102070
102153
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
102071
102154
  var containingFilePath = _b[_a];
102072
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
102155
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
102073
102156
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
102074
102157
  }
102075
102158
  }
@@ -102122,10 +102205,25 @@ var ts;
102122
102205
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102123
102206
  }
102124
102207
  function invalidateResolutionsOfFailedLookupLocations() {
102208
+ var _a;
102209
+ var invalidated = false;
102210
+ if (affectingPathChecksForFile) {
102211
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
102212
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
102213
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
102214
+ invalidated = true;
102215
+ }
102216
+ });
102217
+ affectingPathChecksForFile = undefined;
102218
+ }
102125
102219
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
102126
- return false;
102220
+ return invalidated;
102221
+ }
102222
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
102223
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
102224
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
102225
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
102127
102226
  }
102128
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
102129
102227
  failedLookupChecks = undefined;
102130
102228
  startsWithPathChecks = undefined;
102131
102229
  isInDirectoryChecks = undefined;
@@ -102138,17 +102236,15 @@ var ts;
102138
102236
  return true;
102139
102237
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
102140
102238
  return false;
102141
- return resolution.failedLookupLocations.some(function (location) {
102142
- var locationPath = resolutionHost.toPath(location);
102143
- return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
102144
- ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
102145
- ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
102146
- });
102239
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
102240
+ }
102241
+ function isInvalidatedFailedLookup(locationPath) {
102242
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
102243
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
102244
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
102147
102245
  }
102148
102246
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
102149
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
102150
- return affectingPathChecks.has(resolutionHost.toPath(location));
102151
- });
102247
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
102152
102248
  }
102153
102249
  function closeTypeRootsWatch() {
102154
102250
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -102194,7 +102290,7 @@ var ts;
102194
102290
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
102195
102291
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
102196
102292
  var dirPath = resolutionHost.toPath(dir);
102197
- return dirPath === rootPath || canWatchDirectory(dirPath);
102293
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
102198
102294
  }
102199
102295
  }
102200
102296
  ts.createResolutionCache = createResolutionCache;
@@ -103039,21 +103135,41 @@ var ts;
103039
103135
  var file = _c[_i];
103040
103136
  write("" + toFileName(file, relativeFileName));
103041
103137
  (_a = reasons.get(file.path)) === null || _a === void 0 ? void 0 : _a.forEach(function (reason) { return write(" " + fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText); });
103042
- (_b = explainIfFileIsRedirect(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
103138
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
103043
103139
  }
103044
103140
  }
103045
103141
  ts.explainFiles = explainFiles;
103046
- function explainIfFileIsRedirect(file, fileNameConvertor) {
103142
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
103143
+ var _a;
103047
103144
  var result;
103048
103145
  if (file.path !== file.resolvedPath) {
103049
- (result || (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
103146
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_is_output_of_project_reference_source_0, toFileName(file.originalFileName, fileNameConvertor)));
103050
103147
  }
103051
103148
  if (file.redirectInfo) {
103052
- (result || (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
103149
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
103150
+ }
103151
+ if (ts.isExternalOrCommonJsModule(file)) {
103152
+ switch (file.impliedNodeFormat) {
103153
+ case ts.ModuleKind.ESNext:
103154
+ if (file.packageJsonScope) {
103155
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_is_ECMAScript_module_because_0_has_field_type_with_value_module, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
103156
+ }
103157
+ break;
103158
+ case ts.ModuleKind.CommonJS:
103159
+ if (file.packageJsonScope) {
103160
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, file.packageJsonScope.packageJsonContent.type ?
103161
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
103162
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
103163
+ }
103164
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
103165
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
103166
+ }
103167
+ break;
103168
+ }
103053
103169
  }
103054
103170
  return result;
103055
103171
  }
103056
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
103172
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
103057
103173
  function getMatchedFileSpec(program, fileName) {
103058
103174
  var _a;
103059
103175
  var configFile = program.getCompilerOptions().configFile;
@@ -103246,6 +103362,7 @@ var ts;
103246
103362
  MissingFile: "Missing file",
103247
103363
  WildcardDirectory: "Wild card directory",
103248
103364
  FailedLookupLocations: "Failed Lookup Locations",
103365
+ AffectingFileLocation: "File location affecting resolution",
103249
103366
  TypeRoots: "Type roots",
103250
103367
  ConfigFileOfReferencedProject: "Config file of referened project",
103251
103368
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -103547,7 +103664,7 @@ var ts;
103547
103664
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
103548
103665
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
103549
103666
  compilerHost.watchDirectoryOfFailedLookupLocation = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.FailedLookupLocations); };
103550
- compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.PackageJson); };
103667
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
103551
103668
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
103552
103669
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
103553
103670
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -103578,6 +103695,9 @@ var ts;
103578
103695
  return host.resolveTypeReferenceDirectives.apply(host, args);
103579
103696
  }) :
103580
103697
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
103698
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
103699
+ ts.maybeBind(host, host.getModuleResolutionCache) :
103700
+ (function () { return resolutionCache.getModuleResolutionCache(); });
103581
103701
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
103582
103702
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
103583
103703
  synchronizeProgram();
@@ -103676,8 +103796,9 @@ var ts;
103676
103796
  resolutionCache.startCachingPerDirectoryResolution();
103677
103797
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
103678
103798
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
103799
+ var oldProgram = getCurrentProgram();
103679
103800
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
103680
- resolutionCache.finishCachingPerDirectoryResolution();
103801
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
103681
103802
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
103682
103803
  if (needsUpdateInTypeRootWatch) {
103683
103804
  resolutionCache.updateTypeRootsWatch();
@@ -103747,9 +103868,6 @@ var ts;
103747
103868
  sourceFilesCache.set(path, false);
103748
103869
  }
103749
103870
  }
103750
- if (sourceFile) {
103751
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
103752
- }
103753
103871
  return sourceFile;
103754
103872
  }
103755
103873
  return hostSourceFile.sourceFile;
@@ -104202,6 +104320,7 @@ var ts;
104202
104320
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
104203
104321
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
104204
104322
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
104323
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
104205
104324
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
104206
104325
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
104207
104326
  if (!compilerHost.resolveModuleNames) {