typescript 5.1.0-dev.20230419 → 5.1.0-dev.20230421

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
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.1";
21
- var version = `${versionMajorMinor}.0-dev.20230419`;
21
+ var version = `${versionMajorMinor}.0-dev.20230421`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -32360,7 +32360,9 @@ var Parser;
32360
32360
  const usedBrace = parseOptional(19 /* OpenBraceToken */);
32361
32361
  const pos = getNodePos();
32362
32362
  const expression = parsePropertyAccessEntityNameExpression();
32363
+ scanner.setInJSDocType(true);
32363
32364
  const typeArguments = tryParseTypeArguments();
32365
+ scanner.setInJSDocType(false);
32364
32366
  const node = factory2.createExpressionWithTypeArguments(expression, typeArguments);
32365
32367
  const res = finishNode(node, pos);
32366
32368
  if (usedBrace) {
@@ -37140,13 +37142,12 @@ function createModuleOrTypeReferenceResolutionCache(currentDirectory, getCanonic
37140
37142
  nonRelativeNameResolutionCache.update(options2);
37141
37143
  }
37142
37144
  }
37143
- function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options) {
37145
+ function createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, packageJsonInfoCache) {
37144
37146
  const result = createModuleOrTypeReferenceResolutionCache(
37145
37147
  currentDirectory,
37146
37148
  getCanonicalFileName,
37147
37149
  options,
37148
- /*packageJsonInfoCache*/
37149
- void 0,
37150
+ packageJsonInfoCache,
37150
37151
  getOriginalOrResolvedModuleFileName
37151
37152
  );
37152
37153
  result.getOrCreateCacheForModuleName = (nonRelativeName, mode, redirectedReference) => result.getOrCreateCacheForNonRelativeName(nonRelativeName, mode, redirectedReference);
@@ -37161,6 +37162,12 @@ function createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanoni
37161
37162
  getOriginalOrResolvedTypeReferenceFileName
37162
37163
  );
37163
37164
  }
37165
+ function getOptionsForLibraryResolution(options) {
37166
+ return { moduleResolution: 2 /* Node10 */, traceResolution: options.traceResolution };
37167
+ }
37168
+ function resolveLibrary(libraryName, resolveFrom, compilerOptions, host, cache) {
37169
+ return resolveModuleName(libraryName, resolveFrom, getOptionsForLibraryResolution(compilerOptions), host, cache);
37170
+ }
37164
37171
  function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) {
37165
37172
  var _a, _b, _c;
37166
37173
  const traceEnabled = isTraceEnabled(compilerOptions, host);
@@ -54309,7 +54316,8 @@ function createTypeChecker(host) {
54309
54316
  thisParameter = createSymbolWithType(createSymbol(1 /* FunctionScopedVariable */, "this" /* This */), getTypeFromTypeNode(thisTag.typeExpression));
54310
54317
  }
54311
54318
  }
54312
- const classType = declaration.kind === 175 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(declaration.parent.symbol)) : void 0;
54319
+ const hostDeclaration = isJSDocSignature(declaration) ? getEffectiveJSDocHost(declaration) : declaration;
54320
+ const classType = hostDeclaration && isConstructorDeclaration(hostDeclaration) ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(hostDeclaration.parent.symbol)) : void 0;
54313
54321
  const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration);
54314
54322
  if (hasRestParameter(declaration) || isInJSFile(declaration) && maybeAddJsSyntheticRestParameter(declaration, parameters)) {
54315
54323
  flags |= 1 /* HasRestParameter */;
@@ -113127,6 +113135,25 @@ function forEachProjectReference(projectReferences, resolvedProjectReferences, c
113127
113135
  }
113128
113136
  }
113129
113137
  var inferredTypesContainingFile = "__inferred type names__.ts";
113138
+ function getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName) {
113139
+ const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
113140
+ return combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
113141
+ }
113142
+ function getLibraryNameFromLibFileName(libFileName) {
113143
+ const components = libFileName.split(".");
113144
+ let path = components[1];
113145
+ let i = 2;
113146
+ while (components[i] && components[i] !== "d") {
113147
+ path += (i === 2 ? "/" : "-") + components[i];
113148
+ i++;
113149
+ }
113150
+ return "@typescript/lib-" + path;
113151
+ }
113152
+ function getLibFileNameFromLibReference(libReference) {
113153
+ const libName = toFileNameLowerCase(libReference.fileName);
113154
+ const libFileName = libMap.get(libName);
113155
+ return { libName, libFileName };
113156
+ }
113130
113157
  function isReferencedFile(reason) {
113131
113158
  switch (reason == null ? void 0 : reason.kind) {
113132
113159
  case 3 /* Import */:
@@ -113170,7 +113197,7 @@ function getReferencedFileLocation(getSourceFileByPath, ref) {
113170
113197
  }
113171
113198
  return { file, pos, end, packageId };
113172
113199
  }
113173
- function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion, fileExists, hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences) {
113200
+ function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion, fileExists, hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences) {
113174
113201
  if (!program || (hasChangedAutomaticTypeDirectiveNames == null ? void 0 : hasChangedAutomaticTypeDirectiveNames()))
113175
113202
  return false;
113176
113203
  if (!arrayIsEqualTo(program.getRootFileNames(), rootFileNames))
@@ -113185,6 +113212,8 @@ function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion,
113185
113212
  const currentOptions = program.getCompilerOptions();
113186
113213
  if (!compareDataObjects(currentOptions, newOptions))
113187
113214
  return false;
113215
+ if (program.resolvedLibReferences && forEachEntry(program.resolvedLibReferences, (_value, libFileName) => hasInvalidatedLibResolutions(libFileName)))
113216
+ return false;
113188
113217
  if (currentOptions.configFile && newOptions.configFile)
113189
113218
  return currentOptions.configFile.text === newOptions.configFile.text;
113190
113219
  return true;
@@ -113367,6 +113396,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113367
113396
  let fileProcessingDiagnostics;
113368
113397
  let automaticTypeDirectiveNames;
113369
113398
  let automaticTypeDirectiveResolutions;
113399
+ let resolvedLibReferences;
113400
+ let resolvedLibProcessing;
113370
113401
  const maxNodeModuleJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 0;
113371
113402
  let currentNodeModulesDepth = 0;
113372
113403
  const modulesWithElidedImports = /* @__PURE__ */ new Map();
@@ -113454,6 +113485,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113454
113485
  createTypeReferenceResolutionLoader
113455
113486
  );
113456
113487
  }
113488
+ const hasInvalidatedLibResolutions = host.hasInvalidatedLibResolutions || returnFalse;
113489
+ let actualResolveLibrary;
113490
+ if (host.resolveLibrary) {
113491
+ actualResolveLibrary = host.resolveLibrary.bind(host);
113492
+ } else {
113493
+ const libraryResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, moduleResolutionCache == null ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
113494
+ actualResolveLibrary = (libraryName, resolveFrom, options2) => resolveLibrary(libraryName, resolveFrom, options2, host, libraryResolutionCache);
113495
+ }
113457
113496
  const packageIdToSourceFile = /* @__PURE__ */ new Map();
113458
113497
  let sourceFileToPackageName = /* @__PURE__ */ new Map();
113459
113498
  let redirectTargetsMap = createMultiMap();
@@ -113620,6 +113659,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113620
113659
  );
113621
113660
  }
113622
113661
  oldProgram = void 0;
113662
+ resolvedLibProcessing = void 0;
113623
113663
  const program = {
113624
113664
  getRootFileNames: () => rootNames,
113625
113665
  getSourceFile,
@@ -113661,6 +113701,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113661
113701
  sourceFileToPackageName,
113662
113702
  redirectTargetsMap,
113663
113703
  usesUriStyleNodeCoreModules,
113704
+ resolvedLibReferences,
113664
113705
  isEmittedFile,
113665
113706
  getConfigFileParsingDiagnostics: getConfigFileParsingDiagnostics2,
113666
113707
  getProjectReferences,
@@ -114149,6 +114190,9 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114149
114190
  if (changesAffectingProgramStructure(oldOptions, options)) {
114150
114191
  return 1 /* SafeModules */;
114151
114192
  }
114193
+ if (oldProgram.resolvedLibReferences && forEachEntry(oldProgram.resolvedLibReferences, (resolution, libFileName) => pathForLibFileWorker(libFileName).actual !== resolution.actual)) {
114194
+ return 1 /* SafeModules */;
114195
+ }
114152
114196
  if (host.hasChangedAutomaticTypeDirectiveNames) {
114153
114197
  if (host.hasChangedAutomaticTypeDirectiveNames())
114154
114198
  return 1 /* SafeModules */;
@@ -114185,6 +114229,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114185
114229
  sourceFileToPackageName = oldProgram.sourceFileToPackageName;
114186
114230
  redirectTargetsMap = oldProgram.redirectTargetsMap;
114187
114231
  usesUriStyleNodeCoreModules = oldProgram.usesUriStyleNodeCoreModules;
114232
+ resolvedLibReferences = oldProgram.resolvedLibReferences;
114188
114233
  return 2 /* Completely */;
114189
114234
  }
114190
114235
  function getEmitHost(writeFileCallback) {
@@ -114294,7 +114339,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114294
114339
  if (!options.lib) {
114295
114340
  return equalityComparer(file.fileName, getDefaultLibraryFileName());
114296
114341
  } else {
114297
- return some(options.lib, (libFileName) => equalityComparer(file.fileName, pathForLibFile(libFileName)));
114342
+ return some(options.lib, (libFileName) => equalityComparer(file.fileName, resolvedLibReferences.get(libFileName).actual));
114298
114343
  }
114299
114344
  }
114300
114345
  function getTypeChecker() {
@@ -114885,11 +114930,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114885
114930
  }
114886
114931
  }
114887
114932
  function getLibFileFromReference(ref) {
114888
- const libName = toFileNameLowerCase(ref.fileName);
114889
- const libFileName = libMap.get(libName);
114890
- if (libFileName) {
114891
- return getSourceFile(pathForLibFile(libFileName));
114892
- }
114933
+ var _a2;
114934
+ const { libFileName } = getLibFileNameFromLibReference(ref);
114935
+ const actualFileName = libFileName && ((_a2 = resolvedLibReferences == null ? void 0 : resolvedLibReferences.get(libFileName)) == null ? void 0 : _a2.actual);
114936
+ return actualFileName !== void 0 ? getSourceFile(actualFileName) : void 0;
114893
114937
  }
114894
114938
  function getSourceFileFromReference(referencingFile, ref) {
114895
114939
  return getSourceFileFromReferenceWorker(resolveTripleslashReference(ref.fileName, referencingFile.fileName), getSourceFile);
@@ -115314,25 +115358,55 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
115314
115358
  }
115315
115359
  }
115316
115360
  function pathForLibFile(libFileName) {
115317
- const components = libFileName.split(".");
115318
- let path = components[1];
115319
- let i = 2;
115320
- while (components[i] && components[i] !== "d") {
115321
- path += (i === 2 ? "/" : "-") + components[i];
115322
- i++;
115323
- }
115324
- const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
115325
- const resolveFrom = combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
115326
- const localOverrideModuleResult = resolveModuleName("@typescript/lib-" + path, resolveFrom, { moduleResolution: 2 /* Node10 */, traceResolution: options.traceResolution }, host, moduleResolutionCache);
115327
- if (localOverrideModuleResult == null ? void 0 : localOverrideModuleResult.resolvedModule) {
115328
- return localOverrideModuleResult.resolvedModule.resolvedFileName;
115329
- }
115330
- return combinePaths(defaultLibraryPath, libFileName);
115361
+ const existing = resolvedLibReferences == null ? void 0 : resolvedLibReferences.get(libFileName);
115362
+ if (existing)
115363
+ return existing.actual;
115364
+ const result = pathForLibFileWorker(libFileName);
115365
+ (resolvedLibReferences ?? (resolvedLibReferences = /* @__PURE__ */ new Map())).set(libFileName, result);
115366
+ return result.actual;
115367
+ }
115368
+ function pathForLibFileWorker(libFileName) {
115369
+ var _a2, _b2, _c2, _d2, _e2;
115370
+ const existing = resolvedLibProcessing == null ? void 0 : resolvedLibProcessing.get(libFileName);
115371
+ if (existing)
115372
+ return existing;
115373
+ if (structureIsReused !== 0 /* Not */ && oldProgram && !hasInvalidatedLibResolutions(libFileName)) {
115374
+ const oldResolution = (_a2 = oldProgram.resolvedLibReferences) == null ? void 0 : _a2.get(libFileName);
115375
+ if (oldResolution) {
115376
+ if (oldResolution.resolution && isTraceEnabled(options, host)) {
115377
+ const libraryName2 = getLibraryNameFromLibFileName(libFileName);
115378
+ const resolveFrom2 = getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName);
115379
+ trace(
115380
+ host,
115381
+ oldResolution.resolution.resolvedModule ? oldResolution.resolution.resolvedModule.packageId ? Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2_with_Package_ID_3 : Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2 : Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_not_resolved,
115382
+ libraryName2,
115383
+ getNormalizedAbsolutePath(resolveFrom2, currentDirectory),
115384
+ (_b2 = oldResolution.resolution.resolvedModule) == null ? void 0 : _b2.resolvedFileName,
115385
+ ((_c2 = oldResolution.resolution.resolvedModule) == null ? void 0 : _c2.packageId) && packageIdToString(oldResolution.resolution.resolvedModule.packageId)
115386
+ );
115387
+ }
115388
+ (resolvedLibProcessing ?? (resolvedLibProcessing = /* @__PURE__ */ new Map())).set(libFileName, oldResolution);
115389
+ return oldResolution;
115390
+ }
115391
+ }
115392
+ const libraryName = getLibraryNameFromLibFileName(libFileName);
115393
+ const resolveFrom = getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName);
115394
+ (_d2 = tracing) == null ? void 0 : _d2.push(tracing.Phase.Program, "resolveLibrary", { resolveFrom });
115395
+ mark("beforeResolveLibrary");
115396
+ const resolution = actualResolveLibrary(libraryName, resolveFrom, options, libFileName);
115397
+ mark("afterResolveLibrary");
115398
+ measure("ResolveLibrary", "beforeResolveLibrary", "afterResolveLibrary");
115399
+ (_e2 = tracing) == null ? void 0 : _e2.pop();
115400
+ const result = {
115401
+ resolution,
115402
+ actual: resolution.resolvedModule ? resolution.resolvedModule.resolvedFileName : combinePaths(defaultLibraryPath, libFileName)
115403
+ };
115404
+ (resolvedLibProcessing ?? (resolvedLibProcessing = /* @__PURE__ */ new Map())).set(libFileName, result);
115405
+ return result;
115331
115406
  }
115332
115407
  function processLibReferenceDirectives(file) {
115333
115408
  forEach(file.libReferenceDirectives, (libReference, index) => {
115334
- const libName = toFileNameLowerCase(libReference.fileName);
115335
- const libFileName = libMap.get(libName);
115409
+ const { libName, libFileName } = getLibFileNameFromLibReference(libReference);
115336
115410
  if (libFileName) {
115337
115411
  processRootFile(
115338
115412
  pathForLibFile(libFileName),
@@ -118299,7 +118373,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118299
118373
  let failedLookupChecks;
118300
118374
  let startsWithPathChecks;
118301
118375
  let isInDirectoryChecks;
118302
- let allResolutionsAreInvalidated = false;
118376
+ let allModuleAndTypeResolutionsAreInvalidated = false;
118303
118377
  const getCurrentDirectory = memoize(() => resolutionHost.getCurrentDirectory());
118304
118378
  const cachedDirectoryStructureHost = resolutionHost.getCachedDirectoryStructureHost();
118305
118379
  const resolvedModuleNames = /* @__PURE__ */ new Map();
@@ -118315,6 +118389,13 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118315
118389
  resolutionHost.getCompilationSettings(),
118316
118390
  moduleResolutionCache.getPackageJsonInfoCache()
118317
118391
  );
118392
+ const resolvedLibraries = /* @__PURE__ */ new Map();
118393
+ const libraryResolutionCache = createModuleResolutionCache(
118394
+ getCurrentDirectory(),
118395
+ resolutionHost.getCanonicalFileName,
118396
+ getOptionsForLibraryResolution(resolutionHost.getCompilationSettings()),
118397
+ moduleResolutionCache.getPackageJsonInfoCache()
118398
+ );
118318
118399
  const directoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
118319
118400
  const fileWatchesOfAffectingLocations = /* @__PURE__ */ new Map();
118320
118401
  const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory);
@@ -118331,6 +118412,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118331
118412
  finishCachingPerDirectoryResolution,
118332
118413
  resolveModuleNameLiterals,
118333
118414
  resolveTypeReferenceDirectiveReferences,
118415
+ resolveLibrary: resolveLibrary2,
118334
118416
  resolveSingleModuleNameWithoutWatching,
118335
118417
  removeResolutionsFromProjectReferenceRedirects,
118336
118418
  removeResolutionsOfFile,
@@ -118366,16 +118448,18 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118366
118448
  isInDirectoryChecks = void 0;
118367
118449
  affectingPathChecks = void 0;
118368
118450
  affectingPathChecksForFile = void 0;
118369
- allResolutionsAreInvalidated = false;
118451
+ allModuleAndTypeResolutionsAreInvalidated = false;
118370
118452
  moduleResolutionCache.clear();
118371
118453
  typeReferenceDirectiveResolutionCache.clear();
118372
118454
  moduleResolutionCache.update(resolutionHost.getCompilationSettings());
118373
118455
  typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
118456
+ libraryResolutionCache.clear();
118374
118457
  impliedFormatPackageJsons.clear();
118458
+ resolvedLibraries.clear();
118375
118459
  hasChangedAutomaticTypeDirectiveNames = false;
118376
118460
  }
118377
118461
  function onChangesAffectModuleResolution() {
118378
- allResolutionsAreInvalidated = true;
118462
+ allModuleAndTypeResolutionsAreInvalidated = true;
118379
118463
  moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
118380
118464
  typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
118381
118465
  moduleResolutionCache.update(resolutionHost.getCompilationSettings());
@@ -118396,24 +118480,45 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118396
118480
  const value = filesWithInvalidatedNonRelativeUnresolvedImports.get(path);
118397
118481
  return !!value && !!value.length;
118398
118482
  }
118399
- function createHasInvalidatedResolutions(customHasInvalidatedResolutions) {
118483
+ function createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidatedLibResolutions) {
118400
118484
  invalidateResolutionsOfFailedLookupLocations();
118401
118485
  const collected = filesWithInvalidatedResolutions;
118402
118486
  filesWithInvalidatedResolutions = void 0;
118403
- return (path) => customHasInvalidatedResolutions(path) || allResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path);
118487
+ return {
118488
+ hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path),
118489
+ hasInvalidatedLibResolutions: (libFileName) => {
118490
+ var _a;
118491
+ return customHasInvalidatedLibResolutions(libFileName) || !!((_a = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName)) == null ? void 0 : _a.isInvalidated);
118492
+ }
118493
+ };
118404
118494
  }
118405
118495
  function startCachingPerDirectoryResolution() {
118406
118496
  moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
118407
118497
  typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
118498
+ libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
118408
118499
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
118409
118500
  nonRelativeExternalModuleResolutions.clear();
118410
118501
  }
118502
+ function cleanupLibResolutionWatching(newProgram) {
118503
+ resolvedLibraries.forEach((resolution, libFileName) => {
118504
+ var _a;
118505
+ if (!((_a = newProgram == null ? void 0 : newProgram.resolvedLibReferences) == null ? void 0 : _a.has(libFileName))) {
118506
+ stopWatchFailedLookupLocationOfResolution(
118507
+ resolution,
118508
+ resolutionHost.toPath(getInferredLibraryNameResolveFrom(newProgram.getCompilerOptions(), getCurrentDirectory(), libFileName)),
118509
+ getResolvedModule2
118510
+ );
118511
+ resolvedLibraries.delete(libFileName);
118512
+ }
118513
+ });
118514
+ }
118411
118515
  function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
118412
118516
  filesWithInvalidatedNonRelativeUnresolvedImports = void 0;
118413
- allResolutionsAreInvalidated = false;
118517
+ allModuleAndTypeResolutionsAreInvalidated = false;
118414
118518
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
118415
118519
  nonRelativeExternalModuleResolutions.clear();
118416
118520
  if (newProgram !== oldProgram) {
118521
+ cleanupLibResolutionWatching(newProgram);
118417
118522
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
118418
118523
  var _a;
118419
118524
  const expected = isExternalOrCommonJsModule(newFile) ? ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0 : 0;
@@ -118522,7 +118627,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118522
118627
  const name = loader.nameAndMode.getName(entry);
118523
118628
  const mode = loader.nameAndMode.getMode(entry, containingSourceFile);
118524
118629
  let resolution = resolutionsInFile.get(name, mode);
118525
- if (!seenNamesInFile.has(name, mode) && (allResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
118630
+ if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
118526
118631
  hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution))) {
118527
118632
  const existingResolution = resolution;
118528
118633
  resolution = loader.resolve(name, mode);
@@ -118631,6 +118736,41 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118631
118736
  // Defer non relative resolution watch because we could be using ambient modules
118632
118737
  });
118633
118738
  }
118739
+ function resolveLibrary2(libraryName, resolveFrom, options, libFileName) {
118740
+ var _a;
118741
+ const host = ((_a = resolutionHost.getCompilerHost) == null ? void 0 : _a.call(resolutionHost)) || resolutionHost;
118742
+ let resolution = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName);
118743
+ if (!resolution || resolution.isInvalidated) {
118744
+ const existingResolution = resolution;
118745
+ resolution = resolveLibrary(libraryName, resolveFrom, options, host, libraryResolutionCache);
118746
+ const path = resolutionHost.toPath(resolveFrom);
118747
+ watchFailedLookupLocationsOfExternalModuleResolutions(
118748
+ libraryName,
118749
+ resolution,
118750
+ path,
118751
+ getResolvedModule2,
118752
+ /*deferWatchingNonRelativeResolution*/
118753
+ false
118754
+ );
118755
+ resolvedLibraries.set(libFileName, resolution);
118756
+ if (existingResolution) {
118757
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolvedModule2);
118758
+ }
118759
+ } else {
118760
+ if (isTraceEnabled(options, host)) {
118761
+ const resolved = getResolvedModule2(resolution);
118762
+ trace(
118763
+ host,
118764
+ (resolved == null ? void 0 : resolved.resolvedFileName) ? resolved.packageId ? Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2_with_Package_ID_3 : Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2 : Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_not_resolved,
118765
+ libraryName,
118766
+ resolveFrom,
118767
+ resolved == null ? void 0 : resolved.resolvedFileName,
118768
+ (resolved == null ? void 0 : resolved.packageId) && packageIdToString(resolved.packageId)
118769
+ );
118770
+ }
118771
+ }
118772
+ return resolution;
118773
+ }
118634
118774
  function resolveSingleModuleNameWithoutWatching(moduleName, containingFile) {
118635
118775
  const path = resolutionHost.toPath(containingFile);
118636
118776
  const resolutionsInFile = resolvedModuleNames.get(path);
@@ -118953,9 +119093,12 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118953
119093
  }
118954
119094
  function invalidateResolutionsOfFailedLookupLocations() {
118955
119095
  var _a;
118956
- if (allResolutionsAreInvalidated) {
119096
+ if (allModuleAndTypeResolutionsAreInvalidated) {
118957
119097
  affectingPathChecksForFile = void 0;
118958
119098
  invalidatePackageJsonMap();
119099
+ if (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks || affectingPathChecks) {
119100
+ invalidateResolutions(resolvedLibraries, canInvalidateFailedLookupResolution);
119101
+ }
118959
119102
  failedLookupChecks = void 0;
118960
119103
  startsWithPathChecks = void 0;
118961
119104
  isInDirectoryChecks = void 0;
@@ -119832,9 +119975,11 @@ function createWatchProgram(host) {
119832
119975
  if (!compilerHost.resolveTypeReferenceDirectiveReferences && !compilerHost.resolveTypeReferenceDirectives) {
119833
119976
  compilerHost.resolveTypeReferenceDirectiveReferences = resolutionCache.resolveTypeReferenceDirectiveReferences.bind(resolutionCache);
119834
119977
  }
119978
+ compilerHost.resolveLibrary = !host.resolveLibrary ? resolutionCache.resolveLibrary.bind(resolutionCache) : host.resolveLibrary.bind(host);
119835
119979
  compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.getModuleResolutionCache();
119836
119980
  const userProvidedResolution = !!host.resolveModuleNameLiterals || !!host.resolveTypeReferenceDirectiveReferences || !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
119837
119981
  const customHasInvalidatedResolutions = userProvidedResolution ? maybeBind(host, host.hasInvalidatedResolutions) || returnTrue : returnFalse;
119982
+ const customHasInvalidLibResolutions = host.resolveLibrary ? maybeBind(host, host.hasInvalidatedLibResolutions) || returnTrue : returnFalse;
119838
119983
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
119839
119984
  synchronizeProgram();
119840
119985
  watchConfigFileWildCardDirectories();
@@ -119899,7 +120044,7 @@ function createWatchProgram(host) {
119899
120044
  resolutionCache.onChangesAffectModuleResolution();
119900
120045
  }
119901
120046
  }
119902
- const hasInvalidatedResolutions = resolutionCache.createHasInvalidatedResolutions(customHasInvalidatedResolutions);
120047
+ const { hasInvalidatedResolutions, hasInvalidatedLibResolutions } = resolutionCache.createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidLibResolutions);
119903
120048
  const {
119904
120049
  originalReadFile,
119905
120050
  originalFileExists,
@@ -119908,7 +120053,7 @@ function createWatchProgram(host) {
119908
120053
  originalWriteFile,
119909
120054
  readFileWithCache
119910
120055
  } = changeCompilerHostLikeToUseCache(compilerHost, toPath3);
119911
- if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, (path) => getSourceVersion(path, readFileWithCache), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
120056
+ if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, (path) => getSourceVersion(path, readFileWithCache), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
119912
120057
  if (hasChangedConfigFileParsingErrors) {
119913
120058
  if (reportFileChangeDetectedOnCreateProgram) {
119914
120059
  reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
@@ -119929,7 +120074,7 @@ function createWatchProgram(host) {
119929
120074
  if (reportFileChangeDetectedOnCreateProgram) {
119930
120075
  reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
119931
120076
  }
119932
- createNewProgram(hasInvalidatedResolutions);
120077
+ createNewProgram(hasInvalidatedResolutions, hasInvalidatedLibResolutions);
119933
120078
  }
119934
120079
  reportFileChangeDetectedOnCreateProgram = false;
119935
120080
  if (host.afterProgramCreate && program !== builderProgram) {
@@ -119942,7 +120087,7 @@ function createWatchProgram(host) {
119942
120087
  compilerHost.writeFile = originalWriteFile;
119943
120088
  return builderProgram;
119944
120089
  }
119945
- function createNewProgram(hasInvalidatedResolutions) {
120090
+ function createNewProgram(hasInvalidatedResolutions, hasInvalidatedLibResolutions) {
119946
120091
  writeLog("CreatingProgramWith::");
119947
120092
  writeLog(` roots: ${JSON.stringify(rootFileNames)}`);
119948
120093
  writeLog(` options: ${JSON.stringify(compilerOptions)}`);
@@ -119953,6 +120098,7 @@ function createWatchProgram(host) {
119953
120098
  hasChangedConfigFileParsingErrors = false;
119954
120099
  resolutionCache.startCachingPerDirectoryResolution();
119955
120100
  compilerHost.hasInvalidatedResolutions = hasInvalidatedResolutions;
120101
+ compilerHost.hasInvalidatedLibResolutions = hasInvalidatedLibResolutions;
119956
120102
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
119957
120103
  const oldProgram = getCurrentProgram();
119958
120104
  builderProgram = createProgram2(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
@@ -120505,6 +120651,7 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120505
120651
  compilerHost.getParsedCommandLine = (fileName) => parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName));
120506
120652
  compilerHost.resolveModuleNameLiterals = maybeBind(host, host.resolveModuleNameLiterals);
120507
120653
  compilerHost.resolveTypeReferenceDirectiveReferences = maybeBind(host, host.resolveTypeReferenceDirectiveReferences);
120654
+ compilerHost.resolveLibrary = maybeBind(host, host.resolveLibrary);
120508
120655
  compilerHost.resolveModuleNames = maybeBind(host, host.resolveModuleNames);
120509
120656
  compilerHost.resolveTypeReferenceDirectives = maybeBind(host, host.resolveTypeReferenceDirectives);
120510
120657
  compilerHost.getModuleResolutionCache = maybeBind(host, host.getModuleResolutionCache);
@@ -120542,6 +120689,23 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120542
120689
  createTypeReferenceResolutionLoader
120543
120690
  );
120544
120691
  }
120692
+ let libraryResolutionCache;
120693
+ if (!compilerHost.resolveLibrary) {
120694
+ libraryResolutionCache = createModuleResolutionCache(
120695
+ compilerHost.getCurrentDirectory(),
120696
+ compilerHost.getCanonicalFileName,
120697
+ /*options*/
120698
+ void 0,
120699
+ moduleResolutionCache == null ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()
120700
+ );
120701
+ compilerHost.resolveLibrary = (libraryName, resolveFrom, options2) => resolveLibrary(
120702
+ libraryName,
120703
+ resolveFrom,
120704
+ options2,
120705
+ host,
120706
+ libraryResolutionCache
120707
+ );
120708
+ }
120545
120709
  compilerHost.getBuildInfo = (fileName, configFilePath) => getBuildInfo3(
120546
120710
  state,
120547
120711
  fileName,
@@ -120573,6 +120737,7 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120573
120737
  compilerHost,
120574
120738
  moduleResolutionCache,
120575
120739
  typeReferenceDirectiveResolutionCache,
120740
+ libraryResolutionCache,
120576
120741
  // Mutable state
120577
120742
  buildOrder: void 0,
120578
120743
  readFileWithCache: (f) => host.readFile(f),
@@ -120790,7 +120955,7 @@ function enableCache(state) {
120790
120955
  function disableCache(state) {
120791
120956
  if (!state.cache)
120792
120957
  return;
120793
- const { cache, host, compilerHost, extendedConfigCache, moduleResolutionCache, typeReferenceDirectiveResolutionCache } = state;
120958
+ const { cache, host, compilerHost, extendedConfigCache, moduleResolutionCache, typeReferenceDirectiveResolutionCache, libraryResolutionCache } = state;
120794
120959
  host.readFile = cache.originalReadFile;
120795
120960
  host.fileExists = cache.originalFileExists;
120796
120961
  host.directoryExists = cache.originalDirectoryExists;
@@ -120801,6 +120966,7 @@ function disableCache(state) {
120801
120966
  extendedConfigCache.clear();
120802
120967
  moduleResolutionCache == null ? void 0 : moduleResolutionCache.clear();
120803
120968
  typeReferenceDirectiveResolutionCache == null ? void 0 : typeReferenceDirectiveResolutionCache.clear();
120969
+ libraryResolutionCache == null ? void 0 : libraryResolutionCache.clear();
120804
120970
  state.cache = void 0;
120805
120971
  }
120806
120972
  function clearProjectStatus(state, resolved) {