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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/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.20220731";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220803";
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;
@@ -55213,6 +55226,12 @@ var ts;
55213
55226
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
55214
55227
  var saveErrorInfo = captureErrorCalculationState();
55215
55228
  var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
55229
+ if (!result && (source.flags & 2097152 || source.flags & 262144 && target.flags & 1048576)) {
55230
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 ? source.types : [source], !!(target.flags & 1048576));
55231
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) {
55232
+ result = isRelatedTo(constraint, target, 1, false, undefined, intersectionState);
55233
+ }
55234
+ }
55216
55235
  if (result) {
55217
55236
  resetErrorInfo(saveErrorInfo);
55218
55237
  }
@@ -55269,14 +55288,6 @@ var ts;
55269
55288
  if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
55270
55289
  return result;
55271
55290
  }
55272
- if (source.flags & 2097152 || source.flags & 262144 && target.flags & 1048576) {
55273
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 ? source.types : [source], !!(target.flags & 1048576));
55274
- if (constraint && everyType(constraint, function (c) { return c !== source; })) {
55275
- if (result = isRelatedTo(constraint, target, 1, false, undefined, intersectionState)) {
55276
- return result;
55277
- }
55278
- }
55279
- }
55280
55291
  if (!(sourceFlags & 465829888 ||
55281
55292
  sourceFlags & 524288 && targetFlags & 1048576 ||
55282
55293
  sourceFlags & 2097152 && targetFlags & (524288 | 1048576 | 465829888))) {
@@ -68947,7 +68958,9 @@ var ts;
68947
68958
  }
68948
68959
  if (isGenericObjectType(type)) {
68949
68960
  var baseConstraint = getBaseConstraintOfType(type);
68950
- if (!baseConstraint || (baseConstraint.flags & 3) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) {
68961
+ if (baseConstraint ?
68962
+ baseConstraint.flags & 3 || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint) :
68963
+ maybeTypeOfKind(type, 8650752)) {
68951
68964
  return true;
68952
68965
  }
68953
68966
  }
@@ -79586,10 +79599,11 @@ var ts;
79586
79599
  }
79587
79600
  function visitPreOrPostfixUnaryExpression(node, valueIsDiscarded) {
79588
79601
  if (node.operator === 45 || node.operator === 46) {
79589
- if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(node.operand)) {
79602
+ var operand = ts.skipParentheses(node.operand);
79603
+ if (shouldTransformPrivateElementsOrClassStaticBlocks && ts.isPrivateIdentifierPropertyAccessExpression(operand)) {
79590
79604
  var info = void 0;
79591
- if (info = accessPrivateIdentifier(node.operand.name)) {
79592
- var receiver = ts.visitNode(node.operand.expression, visitor, ts.isExpression);
79605
+ if (info = accessPrivateIdentifier(operand.name)) {
79606
+ var receiver = ts.visitNode(operand.expression, visitor, ts.isExpression);
79593
79607
  var _a = createCopiableReceiverExpr(receiver), readExpression = _a.readExpression, initializeExpression = _a.initializeExpression;
79594
79608
  var expression = createPrivateIdentifierAccess(info, readExpression);
79595
79609
  var temp = ts.isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
@@ -79605,36 +79619,36 @@ var ts;
79605
79619
  }
79606
79620
  }
79607
79621
  else if (shouldTransformSuperInStaticInitializers &&
79608
- ts.isSuperProperty(node.operand) &&
79622
+ ts.isSuperProperty(operand) &&
79609
79623
  currentStaticPropertyDeclarationOrStaticBlock &&
79610
79624
  currentClassLexicalEnvironment) {
79611
79625
  var classConstructor = currentClassLexicalEnvironment.classConstructor, superClassReference = currentClassLexicalEnvironment.superClassReference, facts = currentClassLexicalEnvironment.facts;
79612
79626
  if (facts & 1) {
79613
- var operand = visitInvalidSuperProperty(node.operand);
79627
+ var expression = visitInvalidSuperProperty(operand);
79614
79628
  return ts.isPrefixUnaryExpression(node) ?
79615
- factory.updatePrefixUnaryExpression(node, operand) :
79616
- factory.updatePostfixUnaryExpression(node, operand);
79629
+ factory.updatePrefixUnaryExpression(node, expression) :
79630
+ factory.updatePostfixUnaryExpression(node, expression);
79617
79631
  }
79618
79632
  if (classConstructor && superClassReference) {
79619
79633
  var setterName = void 0;
79620
79634
  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);
79635
+ if (ts.isPropertyAccessExpression(operand)) {
79636
+ if (ts.isIdentifier(operand.name)) {
79637
+ getterName = setterName = factory.createStringLiteralFromNode(operand.name);
79624
79638
  }
79625
79639
  }
79626
79640
  else {
79627
- if (ts.isSimpleInlineableExpression(node.operand.argumentExpression)) {
79628
- getterName = setterName = node.operand.argumentExpression;
79641
+ if (ts.isSimpleInlineableExpression(operand.argumentExpression)) {
79642
+ getterName = setterName = operand.argumentExpression;
79629
79643
  }
79630
79644
  else {
79631
79645
  getterName = factory.createTempVariable(hoistVariableDeclaration);
79632
- setterName = factory.createAssignment(getterName, ts.visitNode(node.operand.argumentExpression, visitor, ts.isExpression));
79646
+ setterName = factory.createAssignment(getterName, ts.visitNode(operand.argumentExpression, visitor, ts.isExpression));
79633
79647
  }
79634
79648
  }
79635
79649
  if (setterName && getterName) {
79636
79650
  var expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor);
79637
- ts.setTextRange(expression, node.operand);
79651
+ ts.setTextRange(expression, operand);
79638
79652
  var temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration);
79639
79653
  expression = ts.expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp);
79640
79654
  expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor);
@@ -97323,6 +97337,11 @@ var ts;
97323
97337
  }
97324
97338
  ts.getConfigFileParsingDiagnostics = getConfigFileParsingDiagnostics;
97325
97339
  function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, options) {
97340
+ var result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
97341
+ return typeof result === "object" ? result.impliedNodeFormat : result;
97342
+ }
97343
+ ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
97344
+ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
97326
97345
  switch (ts.getEmitModuleResolutionKind(options)) {
97327
97346
  case ts.ModuleResolutionKind.Node16:
97328
97347
  case ts.ModuleResolutionKind.NodeNext:
@@ -97334,11 +97353,16 @@ var ts;
97334
97353
  return undefined;
97335
97354
  }
97336
97355
  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;
97356
+ var state = ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
97357
+ var packageJsonLocations = [];
97358
+ state.failedLookupLocations = packageJsonLocations;
97359
+ state.affectingLocations = packageJsonLocations;
97360
+ var packageJsonScope = ts.getPackageScopeForPath(fileName, state);
97361
+ var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
97362
+ return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope };
97339
97363
  }
97340
97364
  }
97341
- ts.getImpliedNodeFormatForFile = getImpliedNodeFormatForFile;
97365
+ ts.getImpliedNodeFormatForFileWorker = getImpliedNodeFormatForFileWorker;
97342
97366
  ts.plainJSErrors = new ts.Set([
97343
97367
  ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0.code,
97344
97368
  ts.Diagnostics.A_module_cannot_have_multiple_default_exports.code,
@@ -97616,7 +97640,7 @@ var ts;
97616
97640
  for (var _i = 0, oldSourceFiles_1 = oldSourceFiles; _i < oldSourceFiles_1.length; _i++) {
97617
97641
  var oldSourceFile = oldSourceFiles_1[_i];
97618
97642
  var newFile = getSourceFileByPath(oldSourceFile.resolvedPath);
97619
- if (shouldCreateNewSourceFile || !newFile ||
97643
+ if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
97620
97644
  (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
97621
97645
  host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
97622
97646
  }
@@ -97946,7 +97970,7 @@ var ts;
97946
97970
  });
97947
97971
  }
97948
97972
  function tryReuseStructureFromOldProgram() {
97949
- var _a;
97973
+ var _a, _b;
97950
97974
  if (!oldProgram) {
97951
97975
  return 0;
97952
97976
  }
@@ -97974,12 +97998,15 @@ var ts;
97974
97998
  var seenPackageNames = new ts.Map();
97975
97999
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
97976
98000
  var oldSourceFile = oldSourceFiles_2[_i];
98001
+ var sourceFileOptions = getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options);
97977
98002
  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);
98003
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, sourceFileOptions, undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat)
98004
+ : host.getSourceFile(oldSourceFile.fileName, sourceFileOptions, undefined, shouldCreateNewSourceFile || sourceFileOptions.impliedNodeFormat !== oldSourceFile.impliedNodeFormat);
97980
98005
  if (!newSourceFile) {
97981
98006
  return 0;
97982
98007
  }
98008
+ newSourceFile.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
98009
+ newSourceFile.packageJsonScope = sourceFileOptions.packageJsonScope;
97983
98010
  ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
97984
98011
  var fileChanged = void 0;
97985
98012
  if (oldSourceFile.redirectInfo) {
@@ -98012,27 +98039,32 @@ var ts;
98012
98039
  seenPackageNames.set(packageName, newKind);
98013
98040
  }
98014
98041
  if (fileChanged) {
98015
- if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
98042
+ if (oldSourceFile.impliedNodeFormat !== newSourceFile.impliedNodeFormat) {
98016
98043
  structureIsReused = 1;
98017
98044
  }
98018
- if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
98045
+ else if (!ts.arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
98019
98046
  structureIsReused = 1;
98020
98047
  }
98021
- if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
98048
+ else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
98022
98049
  structureIsReused = 1;
98023
98050
  }
98024
- collectExternalModuleReferences(newSourceFile);
98025
- if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
98051
+ else if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
98026
98052
  structureIsReused = 1;
98027
98053
  }
98028
- if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
98029
- structureIsReused = 1;
98030
- }
98031
- if ((oldSourceFile.flags & 6291456) !== (newSourceFile.flags & 6291456)) {
98032
- structureIsReused = 1;
98033
- }
98034
- if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
98035
- structureIsReused = 1;
98054
+ else {
98055
+ collectExternalModuleReferences(newSourceFile);
98056
+ if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
98057
+ structureIsReused = 1;
98058
+ }
98059
+ else if (!ts.arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) {
98060
+ structureIsReused = 1;
98061
+ }
98062
+ else if ((oldSourceFile.flags & 6291456) !== (newSourceFile.flags & 6291456)) {
98063
+ structureIsReused = 1;
98064
+ }
98065
+ else if (!ts.arrayIsEqualTo(oldSourceFile.typeReferenceDirectives, newSourceFile.typeReferenceDirectives, fileReferenceIsEqualTo)) {
98066
+ structureIsReused = 1;
98067
+ }
98036
98068
  }
98037
98069
  modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
98038
98070
  }
@@ -98046,17 +98078,17 @@ var ts;
98046
98078
  return structureIsReused;
98047
98079
  }
98048
98080
  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];
98081
+ for (var _c = 0, oldSourceFiles_3 = oldSourceFiles; _c < oldSourceFiles_3.length; _c++) {
98082
+ var oldFile = oldSourceFiles_3[_c];
98051
98083
  if (!ts.contains(modifiedFiles, oldFile)) {
98052
- for (var _c = 0, _d = oldFile.ambientModuleNames; _c < _d.length; _c++) {
98053
- var moduleName = _d[_c];
98084
+ for (var _d = 0, _e = oldFile.ambientModuleNames; _d < _e.length; _d++) {
98085
+ var moduleName = _e[_d];
98054
98086
  ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
98055
98087
  }
98056
98088
  }
98057
98089
  }
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;
98090
+ for (var _f = 0, modifiedSourceFiles_1 = modifiedSourceFiles; _f < modifiedSourceFiles_1.length; _f++) {
98091
+ var _g = modifiedSourceFiles_1[_f], oldSourceFile = _g.oldFile, newSourceFile = _g.newFile;
98060
98092
  var moduleNames = getModuleNames(newSourceFile);
98061
98093
  var resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
98062
98094
  var resolutionsChanged = ts.hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, oldSourceFile, ts.moduleResolutionIsEqualTo);
@@ -98081,13 +98113,13 @@ var ts;
98081
98113
  if (structureIsReused !== 2) {
98082
98114
  return structureIsReused;
98083
98115
  }
98084
- if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_a = host.hasChangedAutomaticTypeDirectiveNames) === null || _a === void 0 ? void 0 : _a.call(host))) {
98116
+ if (ts.changesAffectingProgramStructure(oldOptions, options) || ((_b = host.hasChangedAutomaticTypeDirectiveNames) === null || _b === void 0 ? void 0 : _b.call(host))) {
98085
98117
  return 1;
98086
98118
  }
98087
98119
  missingFilePaths = oldProgram.getMissingFilePaths();
98088
98120
  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];
98121
+ for (var _h = 0, newSourceFiles_1 = newSourceFiles; _h < newSourceFiles_1.length; _h++) {
98122
+ var newSourceFile = newSourceFiles_1[_h];
98091
98123
  filesByName.set(newSourceFile.path, newSourceFile);
98092
98124
  }
98093
98125
  var oldFilesByNameMap = oldProgram.getFilesByNameMap();
@@ -98787,13 +98819,16 @@ var ts;
98787
98819
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, [fileName, existingFile.fileName]);
98788
98820
  }
98789
98821
  }
98790
- function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName) {
98822
+ function createRedirectSourceFile(redirectTarget, unredirected, fileName, path, resolvedPath, originalFileName, sourceFileOptions) {
98823
+ var _a;
98791
98824
  var redirect = Object.create(redirectTarget);
98792
98825
  redirect.fileName = fileName;
98793
98826
  redirect.path = path;
98794
98827
  redirect.resolvedPath = resolvedPath;
98795
98828
  redirect.originalFileName = originalFileName;
98796
98829
  redirect.redirectInfo = { redirectTarget: redirectTarget, unredirected: unredirected };
98830
+ redirect.packageJsonLocations = ((_a = sourceFileOptions.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) ? sourceFileOptions.packageJsonLocations : undefined;
98831
+ redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
98797
98832
  sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
98798
98833
  Object.defineProperties(redirect, {
98799
98834
  id: {
@@ -98818,14 +98853,14 @@ var ts;
98818
98853
  return result;
98819
98854
  }
98820
98855
  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
- };
98856
+ var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
98857
+ var languageVersion = ts.getEmitScriptTarget(options);
98858
+ var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options);
98859
+ return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) :
98860
+ { languageVersion: languageVersion, impliedNodeFormat: result, setExternalModuleIndicator: setExternalModuleIndicator };
98827
98861
  }
98828
98862
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
98863
+ var _a, _b;
98829
98864
  var path = toPath(fileName);
98830
98865
  if (useSourceOfProjectReferenceRedirect) {
98831
98866
  var source = getSourceOfProjectReferenceRedirect(path);
@@ -98895,12 +98930,13 @@ var ts;
98895
98930
  redirectedPath = toPath(redirect);
98896
98931
  }
98897
98932
  }
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);
98933
+ var sourceFileOptions = getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options);
98934
+ 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
98935
  if (packageId) {
98900
98936
  var packageIdKey = ts.packageIdToString(packageId);
98901
98937
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
98902
98938
  if (fileFromPackageId) {
98903
- var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName);
98939
+ var dupFile = createRedirectSourceFile(fileFromPackageId, file, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
98904
98940
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
98905
98941
  addFileToFilesByName(dupFile, path, redirectedPath);
98906
98942
  addFileIncludeReason(dupFile, reason);
@@ -98920,6 +98956,8 @@ var ts;
98920
98956
  file.path = path;
98921
98957
  file.resolvedPath = toPath(fileName);
98922
98958
  file.originalFileName = originalFileName;
98959
+ file.packageJsonLocations = ((_b = sourceFileOptions.packageJsonLocations) === null || _b === void 0 ? void 0 : _b.length) ? sourceFileOptions.packageJsonLocations : undefined;
98960
+ file.packageJsonScope = sourceFileOptions.packageJsonScope;
98923
98961
  addFileIncludeReason(file, reason);
98924
98962
  if (host.useCaseSensitiveFileNames()) {
98925
98963
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -99496,7 +99534,7 @@ var ts;
99496
99534
  fileIncludeReasons = undefined;
99497
99535
  var location = locationReason && getReferencedFileLocation(getSourceFileByPath, locationReason);
99498
99536
  var fileIncludeReasonDetails = fileIncludeReasons && ts.chainDiagnosticMessages(fileIncludeReasons, ts.Diagnostics.The_file_is_in_the_program_because_Colon);
99499
- var redirectInfo = file && ts.explainIfFileIsRedirect(file);
99537
+ var redirectInfo = file && ts.explainIfFileIsRedirectAndImpliedFormat(file);
99500
99538
  var chain = ts.chainDiagnosticMessages.apply(void 0, __spreadArray([redirectInfo ? fileIncludeReasonDetails ? __spreadArray([fileIncludeReasonDetails], redirectInfo, true) : redirectInfo : fileIncludeReasonDetails, diagnostic], args || ts.emptyArray, false));
99501
99539
  return location && isReferenceFileLocation(location) ?
99502
99540
  ts.createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) :
@@ -101463,7 +101501,7 @@ var ts;
101463
101501
  path;
101464
101502
  }
101465
101503
  ts.removeIgnoredPath = removeIgnoredPath;
101466
- function canWatchDirectory(dirPath) {
101504
+ function canWatchDirectoryOrFile(dirPath) {
101467
101505
  var rootLength = ts.getRootLength(dirPath);
101468
101506
  if (dirPath.length === rootLength) {
101469
101507
  return false;
@@ -101495,7 +101533,7 @@ var ts;
101495
101533
  }
101496
101534
  return true;
101497
101535
  }
101498
- ts.canWatchDirectory = canWatchDirectory;
101536
+ ts.canWatchDirectoryOrFile = canWatchDirectoryOrFile;
101499
101537
  function createResolutionCache(resolutionHost, rootDirForResolution, logChangesWhenResolvingModule) {
101500
101538
  var filesWithChangedSetOfUnresolvedImports;
101501
101539
  var filesWithInvalidatedResolutions;
@@ -101504,7 +101542,9 @@ var ts;
101504
101542
  var resolutionsWithFailedLookups = [];
101505
101543
  var resolutionsWithOnlyAffectingLocations = [];
101506
101544
  var resolvedFileToResolution = ts.createMultiMap();
101545
+ var impliedFormatPackageJsons = new ts.Map();
101507
101546
  var hasChangedAutomaticTypeDirectiveNames = false;
101547
+ var affectingPathChecksForFile;
101508
101548
  var affectingPathChecks;
101509
101549
  var failedLookupChecks;
101510
101550
  var startsWithPathChecks;
@@ -101530,7 +101570,7 @@ var ts;
101530
101570
  getModuleResolutionCache: function () { return moduleResolutionCache; },
101531
101571
  startRecordingFilesWithChangedResolutions: startRecordingFilesWithChangedResolutions,
101532
101572
  finishRecordingFilesWithChangedResolutions: finishRecordingFilesWithChangedResolutions,
101533
- startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
101573
+ startCachingPerDirectoryResolution: startCachingPerDirectoryResolution,
101534
101574
  finishCachingPerDirectoryResolution: finishCachingPerDirectoryResolution,
101535
101575
  resolveModuleNames: resolveModuleNames,
101536
101576
  getResolvedModuleWithFailedLookupLocationsFromCache: getResolvedModuleWithFailedLookupLocationsFromCache,
@@ -101574,7 +101614,10 @@ var ts;
101574
101614
  startsWithPathChecks = undefined;
101575
101615
  isInDirectoryChecks = undefined;
101576
101616
  affectingPathChecks = undefined;
101577
- clearPerDirectoryResolutions();
101617
+ affectingPathChecksForFile = undefined;
101618
+ moduleResolutionCache.clear();
101619
+ typeReferenceDirectiveResolutionCache.clear();
101620
+ impliedFormatPackageJsons.clear();
101578
101621
  hasChangedAutomaticTypeDirectiveNames = false;
101579
101622
  }
101580
101623
  function startRecordingFilesWithChangedResolutions() {
@@ -101603,15 +101646,41 @@ var ts;
101603
101646
  return function (path) { return (!!collected && collected.has(path)) ||
101604
101647
  isFileWithInvalidatedNonRelativeUnresolvedImports(path); };
101605
101648
  }
101606
- function clearPerDirectoryResolutions() {
101607
- moduleResolutionCache.clear();
101608
- typeReferenceDirectiveResolutionCache.clear();
101649
+ function startCachingPerDirectoryResolution() {
101650
+ moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
101651
+ typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
101609
101652
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
101610
101653
  nonRelativeExternalModuleResolutions.clear();
101611
101654
  }
101612
- function finishCachingPerDirectoryResolution() {
101655
+ function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
101613
101656
  filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
101614
- clearPerDirectoryResolutions();
101657
+ nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
101658
+ nonRelativeExternalModuleResolutions.clear();
101659
+ if (newProgram !== oldProgram) {
101660
+ newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFiles().forEach(function (newFile) {
101661
+ var _a, _b, _c;
101662
+ var expected = ts.isExternalOrCommonJsModule(newFile) ? (_b = (_a = newFile.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
101663
+ var existing = (_c = impliedFormatPackageJsons.get(newFile.path)) !== null && _c !== void 0 ? _c : ts.emptyArray;
101664
+ for (var i = existing.length; i < expected; i++) {
101665
+ createFileWatcherOfAffectingLocation(newFile.packageJsonLocations[i], false);
101666
+ }
101667
+ if (existing.length > expected) {
101668
+ for (var i = expected; i < existing.length; i++) {
101669
+ fileWatchesOfAffectingLocations.get(existing[i]).files--;
101670
+ }
101671
+ }
101672
+ if (expected)
101673
+ impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations);
101674
+ else
101675
+ impliedFormatPackageJsons.delete(newFile.path);
101676
+ });
101677
+ impliedFormatPackageJsons.forEach(function (existing, path) {
101678
+ if (!(newProgram === null || newProgram === void 0 ? void 0 : newProgram.getSourceFileByPath(path))) {
101679
+ existing.forEach(function (location) { return fileWatchesOfAffectingLocations.get(location).files--; });
101680
+ impliedFormatPackageJsons.delete(path);
101681
+ }
101682
+ });
101683
+ }
101615
101684
  directoryWatchesOfFailedLookups.forEach(function (watcher, path) {
101616
101685
  if (watcher.refCount === 0) {
101617
101686
  directoryWatchesOfFailedLookups.delete(path);
@@ -101619,7 +101688,7 @@ var ts;
101619
101688
  }
101620
101689
  });
101621
101690
  fileWatchesOfAffectingLocations.forEach(function (watcher, path) {
101622
- if (watcher.refCount === 0) {
101691
+ if (watcher.files === 0 && watcher.resolutions === 0) {
101623
101692
  fileWatchesOfAffectingLocations.delete(path);
101624
101693
  watcher.watcher.close();
101625
101694
  watcher.watcher = ts.noopFileWatcher;
@@ -101828,7 +101897,7 @@ var ts;
101828
101897
  dirPath = ts.getDirectoryPath(dirPath);
101829
101898
  }
101830
101899
  if (ts.isNodeModulesDirectory(dirPath)) {
101831
- return canWatchDirectory(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
101900
+ return canWatchDirectoryOrFile(ts.getDirectoryPath(dirPath)) ? { dir: dir, dirPath: dirPath } : undefined;
101832
101901
  }
101833
101902
  var nonRecursive = true;
101834
101903
  var subDirectoryPath, subDirectory;
@@ -101845,7 +101914,7 @@ var ts;
101845
101914
  dir = ts.getDirectoryPath(dir);
101846
101915
  }
101847
101916
  }
101848
- return canWatchDirectory(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
101917
+ return canWatchDirectoryOrFile(dirPath) ? { dir: subDirectory || dir, dirPath: subDirectoryPath || dirPath, nonRecursive: nonRecursive } : undefined;
101849
101918
  }
101850
101919
  function isPathWithDefaultFailedLookupExtension(path) {
101851
101920
  return ts.fileExtensionIsOneOf(path, failedLookupDefaultExtensions);
@@ -101912,46 +101981,58 @@ var ts;
101912
101981
  resolutionsWithOnlyAffectingLocations.push(resolution);
101913
101982
  for (var _i = 0, affectingLocations_1 = affectingLocations; _i < affectingLocations_1.length; _i++) {
101914
101983
  var affectingLocation = affectingLocations_1[_i];
101915
- createFileWatcherOfAffectingLocation(affectingLocation);
101984
+ createFileWatcherOfAffectingLocation(affectingLocation, true);
101916
101985
  }
101917
101986
  }
101918
- function createFileWatcherOfAffectingLocation(affectingLocation) {
101919
- var path = resolutionHost.toPath(affectingLocation);
101920
- var fileWatcher = fileWatchesOfAffectingLocations.get(path);
101987
+ function createFileWatcherOfAffectingLocation(affectingLocation, forResolution) {
101988
+ var fileWatcher = fileWatchesOfAffectingLocations.get(affectingLocation);
101921
101989
  if (fileWatcher) {
101922
- fileWatcher.refCount++;
101990
+ if (forResolution)
101991
+ fileWatcher.resolutions++;
101992
+ else
101993
+ fileWatcher.files++;
101923
101994
  return;
101924
101995
  }
101925
101996
  var locationToWatch = affectingLocation;
101926
- var locationToWatchPath = path;
101927
101997
  if (resolutionHost.realpath) {
101928
101998
  locationToWatch = resolutionHost.realpath(affectingLocation);
101929
- locationToWatchPath = resolutionHost.toPath(locationToWatch);
101930
- if (path !== locationToWatchPath) {
101931
- var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatchPath);
101999
+ if (affectingLocation !== locationToWatch) {
102000
+ var fileWatcher_1 = fileWatchesOfAffectingLocations.get(locationToWatch);
101932
102001
  if (fileWatcher_1) {
101933
- fileWatcher_1.refCount++;
101934
- fileWatcher_1.paths.add(path);
101935
- fileWatchesOfAffectingLocations.set(path, fileWatcher_1);
102002
+ if (forResolution)
102003
+ fileWatcher_1.resolutions++;
102004
+ else
102005
+ fileWatcher_1.files++;
102006
+ fileWatcher_1.paths.add(affectingLocation);
102007
+ fileWatchesOfAffectingLocations.set(affectingLocation, fileWatcher_1);
101936
102008
  return;
101937
102009
  }
101938
102010
  }
101939
102011
  }
101940
102012
  var paths = new ts.Set();
101941
- paths.add(locationToWatchPath);
102013
+ paths.add(locationToWatch);
101942
102014
  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,
102015
+ watcher: canWatchDirectoryOrFile(resolutionHost.toPath(locationToWatch)) ?
102016
+ resolutionHost.watchAffectingFileLocation(locationToWatch, function (fileName, eventKind) {
102017
+ cachedDirectoryStructureHost === null || cachedDirectoryStructureHost === void 0 ? void 0 : cachedDirectoryStructureHost.addOrDeleteFile(fileName, resolutionHost.toPath(locationToWatch), eventKind);
102018
+ paths.forEach(function (path) {
102019
+ var _a;
102020
+ if (watcher.resolutions)
102021
+ (affectingPathChecks !== null && affectingPathChecks !== void 0 ? affectingPathChecks : (affectingPathChecks = new ts.Set())).add(path);
102022
+ if (watcher.files)
102023
+ (affectingPathChecksForFile !== null && affectingPathChecksForFile !== void 0 ? affectingPathChecksForFile : (affectingPathChecksForFile = new ts.Set())).add(path);
102024
+ (_a = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap()) === null || _a === void 0 ? void 0 : _a.delete(resolutionHost.toPath(path));
102025
+ });
102026
+ resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102027
+ }) : ts.noopFileWatcher,
102028
+ resolutions: forResolution ? 1 : 0,
102029
+ files: forResolution ? 0 : 1,
101949
102030
  paths: paths,
101950
102031
  };
101951
- fileWatchesOfAffectingLocations.set(locationToWatchPath, watcher);
101952
- if (path !== locationToWatchPath) {
101953
- fileWatchesOfAffectingLocations.set(path, watcher);
101954
- paths.add(path);
102032
+ fileWatchesOfAffectingLocations.set(locationToWatch, watcher);
102033
+ if (affectingLocation !== locationToWatch) {
102034
+ fileWatchesOfAffectingLocations.set(affectingLocation, watcher);
102035
+ paths.add(affectingLocation);
101955
102036
  }
101956
102037
  }
101957
102038
  function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions, name) {
@@ -102019,8 +102100,8 @@ var ts;
102019
102100
  }
102020
102101
  for (var _a = 0, affectingLocations_2 = affectingLocations; _a < affectingLocations_2.length; _a++) {
102021
102102
  var affectingLocation = affectingLocations_2[_a];
102022
- var watcher = fileWatchesOfAffectingLocations.get(resolutionHost.toPath(affectingLocation));
102023
- watcher.refCount--;
102103
+ var watcher = fileWatchesOfAffectingLocations.get(affectingLocation);
102104
+ watcher.resolutions--;
102024
102105
  }
102025
102106
  }
102026
102107
  function removeDirectoryWatcher(dirPath) {
@@ -102069,7 +102150,7 @@ var ts;
102069
102150
  resolution.isInvalidated = invalidated = true;
102070
102151
  for (var _a = 0, _b = ts.Debug.checkDefined(resolution.files); _a < _b.length; _a++) {
102071
102152
  var containingFilePath = _b[_a];
102072
- (filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
102153
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(containingFilePath);
102073
102154
  hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || ts.endsWith(containingFilePath, ts.inferredTypesContainingFile);
102074
102155
  }
102075
102156
  }
@@ -102122,10 +102203,25 @@ var ts;
102122
102203
  resolutionHost.scheduleInvalidateResolutionsOfFailedLookupLocations();
102123
102204
  }
102124
102205
  function invalidateResolutionsOfFailedLookupLocations() {
102206
+ var _a;
102207
+ var invalidated = false;
102208
+ if (affectingPathChecksForFile) {
102209
+ (_a = resolutionHost.getCurrentProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFiles().forEach(function (f) {
102210
+ if (ts.some(f.packageJsonLocations, function (location) { return affectingPathChecksForFile.has(location); })) {
102211
+ (filesWithInvalidatedResolutions !== null && filesWithInvalidatedResolutions !== void 0 ? filesWithInvalidatedResolutions : (filesWithInvalidatedResolutions = new ts.Set())).add(f.path);
102212
+ invalidated = true;
102213
+ }
102214
+ });
102215
+ affectingPathChecksForFile = undefined;
102216
+ }
102125
102217
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
102126
- return false;
102218
+ return invalidated;
102219
+ }
102220
+ invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution) || invalidated;
102221
+ var packageJsonMap = moduleResolutionCache.getPackageJsonInfoCache().getInternalMap();
102222
+ if (packageJsonMap && (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks)) {
102223
+ packageJsonMap.forEach(function (_value, path) { return isInvalidatedFailedLookup(path) ? packageJsonMap.delete(path) : undefined; });
102127
102224
  }
102128
- var invalidated = invalidateResolutions(resolutionsWithFailedLookups, canInvalidateFailedLookupResolution);
102129
102225
  failedLookupChecks = undefined;
102130
102226
  startsWithPathChecks = undefined;
102131
102227
  isInDirectoryChecks = undefined;
@@ -102138,17 +102234,15 @@ var ts;
102138
102234
  return true;
102139
102235
  if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks)
102140
102236
  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
- });
102237
+ return resolution.failedLookupLocations.some(function (location) { return isInvalidatedFailedLookup(resolutionHost.toPath(location)); });
102238
+ }
102239
+ function isInvalidatedFailedLookup(locationPath) {
102240
+ return (failedLookupChecks === null || failedLookupChecks === void 0 ? void 0 : failedLookupChecks.has(locationPath)) ||
102241
+ ts.firstDefinedIterator((startsWithPathChecks === null || startsWithPathChecks === void 0 ? void 0 : startsWithPathChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return ts.startsWith(locationPath, fileOrDirectoryPath) ? true : undefined; }) ||
102242
+ ts.firstDefinedIterator((isInDirectoryChecks === null || isInDirectoryChecks === void 0 ? void 0 : isInDirectoryChecks.keys()) || ts.emptyIterator, function (fileOrDirectoryPath) { return isInDirectoryPath(fileOrDirectoryPath, locationPath) ? true : undefined; });
102147
102243
  }
102148
102244
  function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution) {
102149
- return !!affectingPathChecks && resolution.affectingLocations.some(function (location) {
102150
- return affectingPathChecks.has(resolutionHost.toPath(location));
102151
- });
102245
+ return !!affectingPathChecks && resolution.affectingLocations.some(function (location) { return affectingPathChecks.has(location); });
102152
102246
  }
102153
102247
  function closeTypeRootsWatch() {
102154
102248
  ts.clearMap(typeRootsWatches, ts.closeFileWatcher);
@@ -102194,7 +102288,7 @@ var ts;
102194
102288
  function directoryExistsForTypeRootWatch(nodeTypesDirectory) {
102195
102289
  var dir = ts.getDirectoryPath(ts.getDirectoryPath(nodeTypesDirectory));
102196
102290
  var dirPath = resolutionHost.toPath(dir);
102197
- return dirPath === rootPath || canWatchDirectory(dirPath);
102291
+ return dirPath === rootPath || canWatchDirectoryOrFile(dirPath);
102198
102292
  }
102199
102293
  }
102200
102294
  ts.createResolutionCache = createResolutionCache;
@@ -103039,21 +103133,41 @@ var ts;
103039
103133
  var file = _c[_i];
103040
103134
  write("" + toFileName(file, relativeFileName));
103041
103135
  (_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); });
103136
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) === null || _b === void 0 ? void 0 : _b.forEach(function (d) { return write(" " + d.messageText); });
103043
103137
  }
103044
103138
  }
103045
103139
  ts.explainFiles = explainFiles;
103046
- function explainIfFileIsRedirect(file, fileNameConvertor) {
103140
+ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
103141
+ var _a;
103047
103142
  var result;
103048
103143
  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)));
103144
+ (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
103145
  }
103051
103146
  if (file.redirectInfo) {
103052
- (result || (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
103147
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_redirects_to_file_0, toFileName(file.redirectInfo.redirectTarget, fileNameConvertor)));
103148
+ }
103149
+ if (ts.isExternalOrCommonJsModule(file)) {
103150
+ switch (file.impliedNodeFormat) {
103151
+ case ts.ModuleKind.ESNext:
103152
+ if (file.packageJsonScope) {
103153
+ (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)));
103154
+ }
103155
+ break;
103156
+ case ts.ModuleKind.CommonJS:
103157
+ if (file.packageJsonScope) {
103158
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, file.packageJsonScope.packageJsonContent.type ?
103159
+ ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module :
103160
+ ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor)));
103161
+ }
103162
+ else if ((_a = file.packageJsonLocations) === null || _a === void 0 ? void 0 : _a.length) {
103163
+ (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, ts.Diagnostics.File_is_CommonJS_module_because_package_json_was_not_found));
103164
+ }
103165
+ break;
103166
+ }
103053
103167
  }
103054
103168
  return result;
103055
103169
  }
103056
- ts.explainIfFileIsRedirect = explainIfFileIsRedirect;
103170
+ ts.explainIfFileIsRedirectAndImpliedFormat = explainIfFileIsRedirectAndImpliedFormat;
103057
103171
  function getMatchedFileSpec(program, fileName) {
103058
103172
  var _a;
103059
103173
  var configFile = program.getCompilerOptions().configFile;
@@ -103246,6 +103360,7 @@ var ts;
103246
103360
  MissingFile: "Missing file",
103247
103361
  WildcardDirectory: "Wild card directory",
103248
103362
  FailedLookupLocations: "Failed Lookup Locations",
103363
+ AffectingFileLocation: "File location affecting resolution",
103249
103364
  TypeRoots: "Type roots",
103250
103365
  ConfigFileOfReferencedProject: "Config file of referened project",
103251
103366
  ExtendedConfigOfReferencedProject: "Extended config file of referenced project",
@@ -103547,7 +103662,7 @@ var ts;
103547
103662
  compilerHost.getCompilationSettings = function () { return compilerOptions; };
103548
103663
  compilerHost.useSourceOfProjectReferenceRedirect = ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect);
103549
103664
  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); };
103665
+ compilerHost.watchAffectingFileLocation = function (file, cb) { return watchFile(file, cb, ts.PollingInterval.High, watchOptions, ts.WatchType.AffectingFileLocation); };
103551
103666
  compilerHost.watchTypeRootsDirectory = function (dir, cb, flags) { return watchDirectory(dir, cb, flags, watchOptions, ts.WatchType.TypeRoots); };
103552
103667
  compilerHost.getCachedDirectoryStructureHost = function () { return cachedDirectoryStructureHost; };
103553
103668
  compilerHost.scheduleInvalidateResolutionsOfFailedLookupLocations = scheduleInvalidateResolutionsOfFailedLookupLocations;
@@ -103578,6 +103693,9 @@ var ts;
103578
103693
  return host.resolveTypeReferenceDirectives.apply(host, args);
103579
103694
  }) :
103580
103695
  (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
103696
+ compilerHost.getModuleResolutionCache = host.resolveModuleNames ?
103697
+ ts.maybeBind(host, host.getModuleResolutionCache) :
103698
+ (function () { return resolutionCache.getModuleResolutionCache(); });
103581
103699
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
103582
103700
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
103583
103701
  synchronizeProgram();
@@ -103676,8 +103794,9 @@ var ts;
103676
103794
  resolutionCache.startCachingPerDirectoryResolution();
103677
103795
  compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
103678
103796
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
103797
+ var oldProgram = getCurrentProgram();
103679
103798
  builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
103680
- resolutionCache.finishCachingPerDirectoryResolution();
103799
+ resolutionCache.finishCachingPerDirectoryResolution(builderProgram.getProgram(), oldProgram);
103681
103800
  ts.updateMissingFilePathsWatch(builderProgram.getProgram(), missingFilesMap || (missingFilesMap = new ts.Map()), watchMissingFilePath);
103682
103801
  if (needsUpdateInTypeRootWatch) {
103683
103802
  resolutionCache.updateTypeRootsWatch();
@@ -103747,9 +103866,6 @@ var ts;
103747
103866
  sourceFilesCache.set(path, false);
103748
103867
  }
103749
103868
  }
103750
- if (sourceFile) {
103751
- sourceFile.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
103752
- }
103753
103869
  return sourceFile;
103754
103870
  }
103755
103871
  return hostSourceFile.sourceFile;
@@ -104202,6 +104318,7 @@ var ts;
104202
104318
  compilerHost.getParsedCommandLine = function (fileName) { return parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName)); };
104203
104319
  compilerHost.resolveModuleNames = ts.maybeBind(host, host.resolveModuleNames);
104204
104320
  compilerHost.resolveTypeReferenceDirectives = ts.maybeBind(host, host.resolveTypeReferenceDirectives);
104321
+ compilerHost.getModuleResolutionCache = ts.maybeBind(host, host.getModuleResolutionCache);
104205
104322
  var moduleResolutionCache = !compilerHost.resolveModuleNames ? ts.createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
104206
104323
  var typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()) : undefined;
104207
104324
  if (!compilerHost.resolveModuleNames) {