@typescript-deploys/pr-build 5.1.0-pr-53714-11 → 5.1.0-pr-53943-7

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-insiders.20230418`;
21
+ var version = `${versionMajorMinor}.0-insiders.20230420`;
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);
@@ -39469,7 +39476,7 @@ function createBinder() {
39469
39476
  case 36 /* ExclamationEqualsToken */:
39470
39477
  case 37 /* EqualsEqualsEqualsToken */:
39471
39478
  case 38 /* ExclamationEqualsEqualsToken */:
39472
- return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) || isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) || (isBooleanLiteral(expr.right) && isNarrowingExpression(expr.left) || isBooleanLiteral(expr.left) && isNarrowingExpression(expr.right));
39479
+ return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) || isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right);
39473
39480
  case 104 /* InstanceOfKeyword */:
39474
39481
  return isNarrowableOperand(expr.left);
39475
39482
  case 103 /* InKeyword */:
@@ -65108,10 +65115,6 @@ function createTypeChecker(host) {
65108
65115
  }
65109
65116
  return type;
65110
65117
  }
65111
- function narrowTypeByBooleanComparison(type, expr, bool, operator, assumeTrue) {
65112
- assumeTrue = assumeTrue !== (bool.kind === 112 /* TrueKeyword */) !== (operator !== 38 /* ExclamationEqualsEqualsToken */ && operator !== 36 /* ExclamationEqualsToken */);
65113
- return narrowType(type, expr, assumeTrue);
65114
- }
65115
65118
  function narrowTypeByBinaryExpression(type, expr, assumeTrue) {
65116
65119
  switch (expr.operatorToken.kind) {
65117
65120
  case 64 /* EqualsToken */:
@@ -65159,12 +65162,6 @@ function createTypeChecker(host) {
65159
65162
  if (isMatchingConstructorReference(right)) {
65160
65163
  return narrowTypeByConstructor(type, operator, left, assumeTrue);
65161
65164
  }
65162
- if (isBooleanLiteral(right)) {
65163
- return narrowTypeByBooleanComparison(type, left, right, operator, assumeTrue);
65164
- }
65165
- if (isBooleanLiteral(left)) {
65166
- return narrowTypeByBooleanComparison(type, right, left, operator, assumeTrue);
65167
- }
65168
65165
  break;
65169
65166
  case 104 /* InstanceOfKeyword */:
65170
65167
  return narrowTypeByInstanceof(type, expr, assumeTrue);
@@ -67233,18 +67230,10 @@ function createTypeChecker(host) {
67233
67230
  function getJsxManagedAttributesFromLocatedAttributes(context, ns, attributesType) {
67234
67231
  const managedSym = getJsxLibraryManagedAttributes(ns);
67235
67232
  if (managedSym) {
67236
- const declaredManagedType = getDeclaredTypeOfSymbol(managedSym);
67237
67233
  const ctorType = getStaticTypeOfReferencedJsxConstructor(context);
67238
- if (managedSym.flags & 524288 /* TypeAlias */) {
67239
- const params = getSymbolLinks(managedSym).typeParameters;
67240
- if (length(params) >= 2) {
67241
- const args = fillMissingTypeArguments([ctorType, attributesType], params, 2, isInJSFile(context));
67242
- return getTypeAliasInstantiation(managedSym, args);
67243
- }
67244
- }
67245
- if (length(declaredManagedType.typeParameters) >= 2) {
67246
- const args = fillMissingTypeArguments([ctorType, attributesType], declaredManagedType.typeParameters, 2, isInJSFile(context));
67247
- return createTypeReference(declaredManagedType, args);
67234
+ const result = instantiateAliasOrInterfaceWithDefaults(managedSym, isInJSFile(context), ctorType, attributesType);
67235
+ if (result) {
67236
+ return result;
67248
67237
  }
67249
67238
  }
67250
67239
  return attributesType;
@@ -68131,6 +68120,9 @@ function createTypeChecker(host) {
68131
68120
  function getJsxLibraryManagedAttributes(jsxNamespace) {
68132
68121
  return jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.LibraryManagedAttributes, 788968 /* Type */);
68133
68122
  }
68123
+ function getJsxElementTypeSymbol(jsxNamespace) {
68124
+ return jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementType, 788968 /* Type */);
68125
+ }
68134
68126
  function getJsxElementPropertiesName(jsxNamespace) {
68135
68127
  return getNameFromJsxElementAttributesContainer(JsxNames.ElementAttributesPropertyNameContainer, jsxNamespace);
68136
68128
  }
@@ -68237,11 +68229,32 @@ function createTypeChecker(host) {
68237
68229
  }
68238
68230
  }
68239
68231
  function getJsxElementTypeTypeAt(location) {
68240
- const type = getJsxType(JsxNames.ElementType, location);
68241
- if (isErrorType(type))
68232
+ const ns = getJsxNamespaceAt(location);
68233
+ if (!ns)
68234
+ return void 0;
68235
+ const sym = getJsxElementTypeSymbol(ns);
68236
+ if (!sym)
68237
+ return void 0;
68238
+ const type = instantiateAliasOrInterfaceWithDefaults(sym, isInJSFile(location));
68239
+ if (!type || isErrorType(type))
68242
68240
  return void 0;
68243
68241
  return type;
68244
68242
  }
68243
+ function instantiateAliasOrInterfaceWithDefaults(managedSym, inJs, ...typeArguments) {
68244
+ const declaredManagedType = getDeclaredTypeOfSymbol(managedSym);
68245
+ if (managedSym.flags & 524288 /* TypeAlias */) {
68246
+ const params = getSymbolLinks(managedSym).typeParameters;
68247
+ if (length(params) >= typeArguments.length) {
68248
+ const args = fillMissingTypeArguments(typeArguments, params, typeArguments.length, inJs);
68249
+ return length(args) === 0 ? declaredManagedType : getTypeAliasInstantiation(managedSym, args);
68250
+ }
68251
+ }
68252
+ if (length(declaredManagedType.typeParameters) >= typeArguments.length) {
68253
+ const args = fillMissingTypeArguments(typeArguments, declaredManagedType.typeParameters, typeArguments.length, inJs);
68254
+ return createTypeReference(declaredManagedType, args);
68255
+ }
68256
+ return void 0;
68257
+ }
68245
68258
  function getJsxIntrinsicTagNamesAt(location) {
68246
68259
  const intrinsics = getJsxType(JsxNames.IntrinsicElements, location);
68247
68260
  return intrinsics ? getPropertiesOfType(intrinsics) : emptyArray;
@@ -113137,6 +113150,25 @@ function forEachProjectReference(projectReferences, resolvedProjectReferences, c
113137
113150
  }
113138
113151
  }
113139
113152
  var inferredTypesContainingFile = "__inferred type names__.ts";
113153
+ function getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName) {
113154
+ const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
113155
+ return combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
113156
+ }
113157
+ function getLibraryNameFromLibFileName(libFileName) {
113158
+ const components = libFileName.split(".");
113159
+ let path = components[1];
113160
+ let i = 2;
113161
+ while (components[i] && components[i] !== "d") {
113162
+ path += (i === 2 ? "/" : "-") + components[i];
113163
+ i++;
113164
+ }
113165
+ return "@typescript/lib-" + path;
113166
+ }
113167
+ function getLibFileNameFromLibReference(libReference) {
113168
+ const libName = toFileNameLowerCase(libReference.fileName);
113169
+ const libFileName = libMap.get(libName);
113170
+ return { libName, libFileName };
113171
+ }
113140
113172
  function isReferencedFile(reason) {
113141
113173
  switch (reason == null ? void 0 : reason.kind) {
113142
113174
  case 3 /* Import */:
@@ -113180,7 +113212,7 @@ function getReferencedFileLocation(getSourceFileByPath, ref) {
113180
113212
  }
113181
113213
  return { file, pos, end, packageId };
113182
113214
  }
113183
- function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion, fileExists, hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences) {
113215
+ function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion, fileExists, hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences) {
113184
113216
  if (!program || (hasChangedAutomaticTypeDirectiveNames == null ? void 0 : hasChangedAutomaticTypeDirectiveNames()))
113185
113217
  return false;
113186
113218
  if (!arrayIsEqualTo(program.getRootFileNames(), rootFileNames))
@@ -113195,6 +113227,8 @@ function isProgramUptoDate(program, rootFileNames, newOptions, getSourceVersion,
113195
113227
  const currentOptions = program.getCompilerOptions();
113196
113228
  if (!compareDataObjects(currentOptions, newOptions))
113197
113229
  return false;
113230
+ if (program.resolvedLibReferences && forEachEntry(program.resolvedLibReferences, (_value, libFileName) => hasInvalidatedLibResolutions(libFileName)))
113231
+ return false;
113198
113232
  if (currentOptions.configFile && newOptions.configFile)
113199
113233
  return currentOptions.configFile.text === newOptions.configFile.text;
113200
113234
  return true;
@@ -113377,6 +113411,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113377
113411
  let fileProcessingDiagnostics;
113378
113412
  let automaticTypeDirectiveNames;
113379
113413
  let automaticTypeDirectiveResolutions;
113414
+ let resolvedLibReferences;
113415
+ let resolvedLibProcessing;
113380
113416
  const maxNodeModuleJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 0;
113381
113417
  let currentNodeModulesDepth = 0;
113382
113418
  const modulesWithElidedImports = /* @__PURE__ */ new Map();
@@ -113464,6 +113500,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113464
113500
  createTypeReferenceResolutionLoader
113465
113501
  );
113466
113502
  }
113503
+ const hasInvalidatedLibResolutions = host.hasInvalidatedLibResolutions || returnFalse;
113504
+ let actualResolveLibrary;
113505
+ if (host.resolveLibrary) {
113506
+ actualResolveLibrary = host.resolveLibrary.bind(host);
113507
+ } else {
113508
+ const libraryResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, moduleResolutionCache == null ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
113509
+ actualResolveLibrary = (libraryName, resolveFrom, options2) => resolveLibrary(libraryName, resolveFrom, options2, host, libraryResolutionCache);
113510
+ }
113467
113511
  const packageIdToSourceFile = /* @__PURE__ */ new Map();
113468
113512
  let sourceFileToPackageName = /* @__PURE__ */ new Map();
113469
113513
  let redirectTargetsMap = createMultiMap();
@@ -113630,6 +113674,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113630
113674
  );
113631
113675
  }
113632
113676
  oldProgram = void 0;
113677
+ resolvedLibProcessing = void 0;
113633
113678
  const program = {
113634
113679
  getRootFileNames: () => rootNames,
113635
113680
  getSourceFile,
@@ -113671,6 +113716,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
113671
113716
  sourceFileToPackageName,
113672
113717
  redirectTargetsMap,
113673
113718
  usesUriStyleNodeCoreModules,
113719
+ resolvedLibReferences,
113674
113720
  isEmittedFile,
113675
113721
  getConfigFileParsingDiagnostics: getConfigFileParsingDiagnostics2,
113676
113722
  getProjectReferences,
@@ -114159,6 +114205,9 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114159
114205
  if (changesAffectingProgramStructure(oldOptions, options)) {
114160
114206
  return 1 /* SafeModules */;
114161
114207
  }
114208
+ if (oldProgram.resolvedLibReferences && forEachEntry(oldProgram.resolvedLibReferences, (resolution, libFileName) => pathForLibFileWorker(libFileName).actual !== resolution.actual)) {
114209
+ return 1 /* SafeModules */;
114210
+ }
114162
114211
  if (host.hasChangedAutomaticTypeDirectiveNames) {
114163
114212
  if (host.hasChangedAutomaticTypeDirectiveNames())
114164
114213
  return 1 /* SafeModules */;
@@ -114195,6 +114244,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114195
114244
  sourceFileToPackageName = oldProgram.sourceFileToPackageName;
114196
114245
  redirectTargetsMap = oldProgram.redirectTargetsMap;
114197
114246
  usesUriStyleNodeCoreModules = oldProgram.usesUriStyleNodeCoreModules;
114247
+ resolvedLibReferences = oldProgram.resolvedLibReferences;
114198
114248
  return 2 /* Completely */;
114199
114249
  }
114200
114250
  function getEmitHost(writeFileCallback) {
@@ -114304,7 +114354,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114304
114354
  if (!options.lib) {
114305
114355
  return equalityComparer(file.fileName, getDefaultLibraryFileName());
114306
114356
  } else {
114307
- return some(options.lib, (libFileName) => equalityComparer(file.fileName, pathForLibFile(libFileName)));
114357
+ return some(options.lib, (libFileName) => equalityComparer(file.fileName, resolvedLibReferences.get(libFileName).actual));
114308
114358
  }
114309
114359
  }
114310
114360
  function getTypeChecker() {
@@ -114895,11 +114945,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
114895
114945
  }
114896
114946
  }
114897
114947
  function getLibFileFromReference(ref) {
114898
- const libName = toFileNameLowerCase(ref.fileName);
114899
- const libFileName = libMap.get(libName);
114900
- if (libFileName) {
114901
- return getSourceFile(pathForLibFile(libFileName));
114902
- }
114948
+ var _a2;
114949
+ const { libFileName } = getLibFileNameFromLibReference(ref);
114950
+ const actualFileName = libFileName && ((_a2 = resolvedLibReferences == null ? void 0 : resolvedLibReferences.get(libFileName)) == null ? void 0 : _a2.actual);
114951
+ return actualFileName !== void 0 ? getSourceFile(actualFileName) : void 0;
114903
114952
  }
114904
114953
  function getSourceFileFromReference(referencingFile, ref) {
114905
114954
  return getSourceFileFromReferenceWorker(resolveTripleslashReference(ref.fileName, referencingFile.fileName), getSourceFile);
@@ -115324,25 +115373,55 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
115324
115373
  }
115325
115374
  }
115326
115375
  function pathForLibFile(libFileName) {
115327
- const components = libFileName.split(".");
115328
- let path = components[1];
115329
- let i = 2;
115330
- while (components[i] && components[i] !== "d") {
115331
- path += (i === 2 ? "/" : "-") + components[i];
115332
- i++;
115333
- }
115334
- const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
115335
- const resolveFrom = combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
115336
- const localOverrideModuleResult = resolveModuleName("@typescript/lib-" + path, resolveFrom, { moduleResolution: 2 /* Node10 */, traceResolution: options.traceResolution }, host, moduleResolutionCache);
115337
- if (localOverrideModuleResult == null ? void 0 : localOverrideModuleResult.resolvedModule) {
115338
- return localOverrideModuleResult.resolvedModule.resolvedFileName;
115339
- }
115340
- return combinePaths(defaultLibraryPath, libFileName);
115376
+ const existing = resolvedLibReferences == null ? void 0 : resolvedLibReferences.get(libFileName);
115377
+ if (existing)
115378
+ return existing.actual;
115379
+ const result = pathForLibFileWorker(libFileName);
115380
+ (resolvedLibReferences ?? (resolvedLibReferences = /* @__PURE__ */ new Map())).set(libFileName, result);
115381
+ return result.actual;
115382
+ }
115383
+ function pathForLibFileWorker(libFileName) {
115384
+ var _a2, _b2, _c2, _d2, _e2;
115385
+ const existing = resolvedLibProcessing == null ? void 0 : resolvedLibProcessing.get(libFileName);
115386
+ if (existing)
115387
+ return existing;
115388
+ if (structureIsReused !== 0 /* Not */ && oldProgram && !hasInvalidatedLibResolutions(libFileName)) {
115389
+ const oldResolution = (_a2 = oldProgram.resolvedLibReferences) == null ? void 0 : _a2.get(libFileName);
115390
+ if (oldResolution) {
115391
+ if (oldResolution.resolution && isTraceEnabled(options, host)) {
115392
+ const libraryName2 = getLibraryNameFromLibFileName(libFileName);
115393
+ const resolveFrom2 = getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName);
115394
+ trace(
115395
+ host,
115396
+ 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,
115397
+ libraryName2,
115398
+ getNormalizedAbsolutePath(resolveFrom2, currentDirectory),
115399
+ (_b2 = oldResolution.resolution.resolvedModule) == null ? void 0 : _b2.resolvedFileName,
115400
+ ((_c2 = oldResolution.resolution.resolvedModule) == null ? void 0 : _c2.packageId) && packageIdToString(oldResolution.resolution.resolvedModule.packageId)
115401
+ );
115402
+ }
115403
+ (resolvedLibProcessing ?? (resolvedLibProcessing = /* @__PURE__ */ new Map())).set(libFileName, oldResolution);
115404
+ return oldResolution;
115405
+ }
115406
+ }
115407
+ const libraryName = getLibraryNameFromLibFileName(libFileName);
115408
+ const resolveFrom = getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName);
115409
+ (_d2 = tracing) == null ? void 0 : _d2.push(tracing.Phase.Program, "resolveLibrary", { resolveFrom });
115410
+ mark("beforeResolveLibrary");
115411
+ const resolution = actualResolveLibrary(libraryName, resolveFrom, options, libFileName);
115412
+ mark("afterResolveLibrary");
115413
+ measure("ResolveLibrary", "beforeResolveLibrary", "afterResolveLibrary");
115414
+ (_e2 = tracing) == null ? void 0 : _e2.pop();
115415
+ const result = {
115416
+ resolution,
115417
+ actual: resolution.resolvedModule ? resolution.resolvedModule.resolvedFileName : combinePaths(defaultLibraryPath, libFileName)
115418
+ };
115419
+ (resolvedLibProcessing ?? (resolvedLibProcessing = /* @__PURE__ */ new Map())).set(libFileName, result);
115420
+ return result;
115341
115421
  }
115342
115422
  function processLibReferenceDirectives(file) {
115343
115423
  forEach(file.libReferenceDirectives, (libReference, index) => {
115344
- const libName = toFileNameLowerCase(libReference.fileName);
115345
- const libFileName = libMap.get(libName);
115424
+ const { libName, libFileName } = getLibFileNameFromLibReference(libReference);
115346
115425
  if (libFileName) {
115347
115426
  processRootFile(
115348
115427
  pathForLibFile(libFileName),
@@ -118309,7 +118388,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118309
118388
  let failedLookupChecks;
118310
118389
  let startsWithPathChecks;
118311
118390
  let isInDirectoryChecks;
118312
- let allResolutionsAreInvalidated = false;
118391
+ let allModuleAndTypeResolutionsAreInvalidated = false;
118313
118392
  const getCurrentDirectory = memoize(() => resolutionHost.getCurrentDirectory());
118314
118393
  const cachedDirectoryStructureHost = resolutionHost.getCachedDirectoryStructureHost();
118315
118394
  const resolvedModuleNames = /* @__PURE__ */ new Map();
@@ -118325,6 +118404,13 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118325
118404
  resolutionHost.getCompilationSettings(),
118326
118405
  moduleResolutionCache.getPackageJsonInfoCache()
118327
118406
  );
118407
+ const resolvedLibraries = /* @__PURE__ */ new Map();
118408
+ const libraryResolutionCache = createModuleResolutionCache(
118409
+ getCurrentDirectory(),
118410
+ resolutionHost.getCanonicalFileName,
118411
+ getOptionsForLibraryResolution(resolutionHost.getCompilationSettings()),
118412
+ moduleResolutionCache.getPackageJsonInfoCache()
118413
+ );
118328
118414
  const directoryWatchesOfFailedLookups = /* @__PURE__ */ new Map();
118329
118415
  const fileWatchesOfAffectingLocations = /* @__PURE__ */ new Map();
118330
118416
  const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory);
@@ -118341,6 +118427,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118341
118427
  finishCachingPerDirectoryResolution,
118342
118428
  resolveModuleNameLiterals,
118343
118429
  resolveTypeReferenceDirectiveReferences,
118430
+ resolveLibrary: resolveLibrary2,
118344
118431
  resolveSingleModuleNameWithoutWatching,
118345
118432
  removeResolutionsFromProjectReferenceRedirects,
118346
118433
  removeResolutionsOfFile,
@@ -118376,16 +118463,18 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118376
118463
  isInDirectoryChecks = void 0;
118377
118464
  affectingPathChecks = void 0;
118378
118465
  affectingPathChecksForFile = void 0;
118379
- allResolutionsAreInvalidated = false;
118466
+ allModuleAndTypeResolutionsAreInvalidated = false;
118380
118467
  moduleResolutionCache.clear();
118381
118468
  typeReferenceDirectiveResolutionCache.clear();
118382
118469
  moduleResolutionCache.update(resolutionHost.getCompilationSettings());
118383
118470
  typeReferenceDirectiveResolutionCache.update(resolutionHost.getCompilationSettings());
118471
+ libraryResolutionCache.clear();
118384
118472
  impliedFormatPackageJsons.clear();
118473
+ resolvedLibraries.clear();
118385
118474
  hasChangedAutomaticTypeDirectiveNames = false;
118386
118475
  }
118387
118476
  function onChangesAffectModuleResolution() {
118388
- allResolutionsAreInvalidated = true;
118477
+ allModuleAndTypeResolutionsAreInvalidated = true;
118389
118478
  moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
118390
118479
  typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
118391
118480
  moduleResolutionCache.update(resolutionHost.getCompilationSettings());
@@ -118406,24 +118495,45 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118406
118495
  const value = filesWithInvalidatedNonRelativeUnresolvedImports.get(path);
118407
118496
  return !!value && !!value.length;
118408
118497
  }
118409
- function createHasInvalidatedResolutions(customHasInvalidatedResolutions) {
118498
+ function createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidatedLibResolutions) {
118410
118499
  invalidateResolutionsOfFailedLookupLocations();
118411
118500
  const collected = filesWithInvalidatedResolutions;
118412
118501
  filesWithInvalidatedResolutions = void 0;
118413
- return (path) => customHasInvalidatedResolutions(path) || allResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path);
118502
+ return {
118503
+ hasInvalidatedResolutions: (path) => customHasInvalidatedResolutions(path) || allModuleAndTypeResolutionsAreInvalidated || !!(collected == null ? void 0 : collected.has(path)) || isFileWithInvalidatedNonRelativeUnresolvedImports(path),
118504
+ hasInvalidatedLibResolutions: (libFileName) => {
118505
+ var _a;
118506
+ return customHasInvalidatedLibResolutions(libFileName) || !!((_a = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName)) == null ? void 0 : _a.isInvalidated);
118507
+ }
118508
+ };
118414
118509
  }
118415
118510
  function startCachingPerDirectoryResolution() {
118416
118511
  moduleResolutionCache.clearAllExceptPackageJsonInfoCache();
118417
118512
  typeReferenceDirectiveResolutionCache.clearAllExceptPackageJsonInfoCache();
118513
+ libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
118418
118514
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
118419
118515
  nonRelativeExternalModuleResolutions.clear();
118420
118516
  }
118517
+ function cleanupLibResolutionWatching(newProgram) {
118518
+ resolvedLibraries.forEach((resolution, libFileName) => {
118519
+ var _a;
118520
+ if (!((_a = newProgram == null ? void 0 : newProgram.resolvedLibReferences) == null ? void 0 : _a.has(libFileName))) {
118521
+ stopWatchFailedLookupLocationOfResolution(
118522
+ resolution,
118523
+ resolutionHost.toPath(getInferredLibraryNameResolveFrom(newProgram.getCompilerOptions(), getCurrentDirectory(), libFileName)),
118524
+ getResolvedModule2
118525
+ );
118526
+ resolvedLibraries.delete(libFileName);
118527
+ }
118528
+ });
118529
+ }
118421
118530
  function finishCachingPerDirectoryResolution(newProgram, oldProgram) {
118422
118531
  filesWithInvalidatedNonRelativeUnresolvedImports = void 0;
118423
- allResolutionsAreInvalidated = false;
118532
+ allModuleAndTypeResolutionsAreInvalidated = false;
118424
118533
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
118425
118534
  nonRelativeExternalModuleResolutions.clear();
118426
118535
  if (newProgram !== oldProgram) {
118536
+ cleanupLibResolutionWatching(newProgram);
118427
118537
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
118428
118538
  var _a;
118429
118539
  const expected = isExternalOrCommonJsModule(newFile) ? ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0 : 0;
@@ -118532,7 +118642,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118532
118642
  const name = loader.nameAndMode.getName(entry);
118533
118643
  const mode = loader.nameAndMode.getMode(entry, containingSourceFile);
118534
118644
  let resolution = resolutionsInFile.get(name, mode);
118535
- if (!seenNamesInFile.has(name, mode) && (allResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
118645
+ if (!seenNamesInFile.has(name, mode) && (allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated || // If the name is unresolved import that was invalidated, recalculate
118536
118646
  hasInvalidatedNonRelativeUnresolvedImport && !isExternalModuleNameRelative(name) && shouldRetryResolution(resolution))) {
118537
118647
  const existingResolution = resolution;
118538
118648
  resolution = loader.resolve(name, mode);
@@ -118641,6 +118751,41 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118641
118751
  // Defer non relative resolution watch because we could be using ambient modules
118642
118752
  });
118643
118753
  }
118754
+ function resolveLibrary2(libraryName, resolveFrom, options, libFileName) {
118755
+ var _a;
118756
+ const host = ((_a = resolutionHost.getCompilerHost) == null ? void 0 : _a.call(resolutionHost)) || resolutionHost;
118757
+ let resolution = resolvedLibraries == null ? void 0 : resolvedLibraries.get(libFileName);
118758
+ if (!resolution || resolution.isInvalidated) {
118759
+ const existingResolution = resolution;
118760
+ resolution = resolveLibrary(libraryName, resolveFrom, options, host, libraryResolutionCache);
118761
+ const path = resolutionHost.toPath(resolveFrom);
118762
+ watchFailedLookupLocationsOfExternalModuleResolutions(
118763
+ libraryName,
118764
+ resolution,
118765
+ path,
118766
+ getResolvedModule2,
118767
+ /*deferWatchingNonRelativeResolution*/
118768
+ false
118769
+ );
118770
+ resolvedLibraries.set(libFileName, resolution);
118771
+ if (existingResolution) {
118772
+ stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolvedModule2);
118773
+ }
118774
+ } else {
118775
+ if (isTraceEnabled(options, host)) {
118776
+ const resolved = getResolvedModule2(resolution);
118777
+ trace(
118778
+ host,
118779
+ (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,
118780
+ libraryName,
118781
+ resolveFrom,
118782
+ resolved == null ? void 0 : resolved.resolvedFileName,
118783
+ (resolved == null ? void 0 : resolved.packageId) && packageIdToString(resolved.packageId)
118784
+ );
118785
+ }
118786
+ }
118787
+ return resolution;
118788
+ }
118644
118789
  function resolveSingleModuleNameWithoutWatching(moduleName, containingFile) {
118645
118790
  const path = resolutionHost.toPath(containingFile);
118646
118791
  const resolutionsInFile = resolvedModuleNames.get(path);
@@ -118963,9 +119108,12 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
118963
119108
  }
118964
119109
  function invalidateResolutionsOfFailedLookupLocations() {
118965
119110
  var _a;
118966
- if (allResolutionsAreInvalidated) {
119111
+ if (allModuleAndTypeResolutionsAreInvalidated) {
118967
119112
  affectingPathChecksForFile = void 0;
118968
119113
  invalidatePackageJsonMap();
119114
+ if (failedLookupChecks || startsWithPathChecks || isInDirectoryChecks || affectingPathChecks) {
119115
+ invalidateResolutions(resolvedLibraries, canInvalidateFailedLookupResolution);
119116
+ }
118969
119117
  failedLookupChecks = void 0;
118970
119118
  startsWithPathChecks = void 0;
118971
119119
  isInDirectoryChecks = void 0;
@@ -119842,9 +119990,11 @@ function createWatchProgram(host) {
119842
119990
  if (!compilerHost.resolveTypeReferenceDirectiveReferences && !compilerHost.resolveTypeReferenceDirectives) {
119843
119991
  compilerHost.resolveTypeReferenceDirectiveReferences = resolutionCache.resolveTypeReferenceDirectiveReferences.bind(resolutionCache);
119844
119992
  }
119993
+ compilerHost.resolveLibrary = !host.resolveLibrary ? resolutionCache.resolveLibrary.bind(resolutionCache) : host.resolveLibrary.bind(host);
119845
119994
  compilerHost.getModuleResolutionCache = host.resolveModuleNameLiterals || host.resolveModuleNames ? maybeBind(host, host.getModuleResolutionCache) : () => resolutionCache.getModuleResolutionCache();
119846
119995
  const userProvidedResolution = !!host.resolveModuleNameLiterals || !!host.resolveTypeReferenceDirectiveReferences || !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
119847
119996
  const customHasInvalidatedResolutions = userProvidedResolution ? maybeBind(host, host.hasInvalidatedResolutions) || returnTrue : returnFalse;
119997
+ const customHasInvalidLibResolutions = host.resolveLibrary ? maybeBind(host, host.hasInvalidatedLibResolutions) || returnTrue : returnFalse;
119848
119998
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
119849
119999
  synchronizeProgram();
119850
120000
  watchConfigFileWildCardDirectories();
@@ -119909,7 +120059,7 @@ function createWatchProgram(host) {
119909
120059
  resolutionCache.onChangesAffectModuleResolution();
119910
120060
  }
119911
120061
  }
119912
- const hasInvalidatedResolutions = resolutionCache.createHasInvalidatedResolutions(customHasInvalidatedResolutions);
120062
+ const { hasInvalidatedResolutions, hasInvalidatedLibResolutions } = resolutionCache.createHasInvalidatedResolutions(customHasInvalidatedResolutions, customHasInvalidLibResolutions);
119913
120063
  const {
119914
120064
  originalReadFile,
119915
120065
  originalFileExists,
@@ -119918,7 +120068,7 @@ function createWatchProgram(host) {
119918
120068
  originalWriteFile,
119919
120069
  readFileWithCache
119920
120070
  } = changeCompilerHostLikeToUseCache(compilerHost, toPath3);
119921
- if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, (path) => getSourceVersion(path, readFileWithCache), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
120071
+ if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, (path) => getSourceVersion(path, readFileWithCache), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
119922
120072
  if (hasChangedConfigFileParsingErrors) {
119923
120073
  if (reportFileChangeDetectedOnCreateProgram) {
119924
120074
  reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
@@ -119939,7 +120089,7 @@ function createWatchProgram(host) {
119939
120089
  if (reportFileChangeDetectedOnCreateProgram) {
119940
120090
  reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
119941
120091
  }
119942
- createNewProgram(hasInvalidatedResolutions);
120092
+ createNewProgram(hasInvalidatedResolutions, hasInvalidatedLibResolutions);
119943
120093
  }
119944
120094
  reportFileChangeDetectedOnCreateProgram = false;
119945
120095
  if (host.afterProgramCreate && program !== builderProgram) {
@@ -119952,7 +120102,7 @@ function createWatchProgram(host) {
119952
120102
  compilerHost.writeFile = originalWriteFile;
119953
120103
  return builderProgram;
119954
120104
  }
119955
- function createNewProgram(hasInvalidatedResolutions) {
120105
+ function createNewProgram(hasInvalidatedResolutions, hasInvalidatedLibResolutions) {
119956
120106
  writeLog("CreatingProgramWith::");
119957
120107
  writeLog(` roots: ${JSON.stringify(rootFileNames)}`);
119958
120108
  writeLog(` options: ${JSON.stringify(compilerOptions)}`);
@@ -119963,6 +120113,7 @@ function createWatchProgram(host) {
119963
120113
  hasChangedConfigFileParsingErrors = false;
119964
120114
  resolutionCache.startCachingPerDirectoryResolution();
119965
120115
  compilerHost.hasInvalidatedResolutions = hasInvalidatedResolutions;
120116
+ compilerHost.hasInvalidatedLibResolutions = hasInvalidatedLibResolutions;
119966
120117
  compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
119967
120118
  const oldProgram = getCurrentProgram();
119968
120119
  builderProgram = createProgram2(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
@@ -120515,6 +120666,7 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120515
120666
  compilerHost.getParsedCommandLine = (fileName) => parseConfigFile(state, fileName, toResolvedConfigFilePath(state, fileName));
120516
120667
  compilerHost.resolveModuleNameLiterals = maybeBind(host, host.resolveModuleNameLiterals);
120517
120668
  compilerHost.resolveTypeReferenceDirectiveReferences = maybeBind(host, host.resolveTypeReferenceDirectiveReferences);
120669
+ compilerHost.resolveLibrary = maybeBind(host, host.resolveLibrary);
120518
120670
  compilerHost.resolveModuleNames = maybeBind(host, host.resolveModuleNames);
120519
120671
  compilerHost.resolveTypeReferenceDirectives = maybeBind(host, host.resolveTypeReferenceDirectives);
120520
120672
  compilerHost.getModuleResolutionCache = maybeBind(host, host.getModuleResolutionCache);
@@ -120552,6 +120704,23 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120552
120704
  createTypeReferenceResolutionLoader
120553
120705
  );
120554
120706
  }
120707
+ let libraryResolutionCache;
120708
+ if (!compilerHost.resolveLibrary) {
120709
+ libraryResolutionCache = createModuleResolutionCache(
120710
+ compilerHost.getCurrentDirectory(),
120711
+ compilerHost.getCanonicalFileName,
120712
+ /*options*/
120713
+ void 0,
120714
+ moduleResolutionCache == null ? void 0 : moduleResolutionCache.getPackageJsonInfoCache()
120715
+ );
120716
+ compilerHost.resolveLibrary = (libraryName, resolveFrom, options2) => resolveLibrary(
120717
+ libraryName,
120718
+ resolveFrom,
120719
+ options2,
120720
+ host,
120721
+ libraryResolutionCache
120722
+ );
120723
+ }
120555
120724
  compilerHost.getBuildInfo = (fileName, configFilePath) => getBuildInfo3(
120556
120725
  state,
120557
120726
  fileName,
@@ -120583,6 +120752,7 @@ function createSolutionBuilderState(watch, hostOrHostWithWatch, rootNames, optio
120583
120752
  compilerHost,
120584
120753
  moduleResolutionCache,
120585
120754
  typeReferenceDirectiveResolutionCache,
120755
+ libraryResolutionCache,
120586
120756
  // Mutable state
120587
120757
  buildOrder: void 0,
120588
120758
  readFileWithCache: (f) => host.readFile(f),
@@ -120800,7 +120970,7 @@ function enableCache(state) {
120800
120970
  function disableCache(state) {
120801
120971
  if (!state.cache)
120802
120972
  return;
120803
- const { cache, host, compilerHost, extendedConfigCache, moduleResolutionCache, typeReferenceDirectiveResolutionCache } = state;
120973
+ const { cache, host, compilerHost, extendedConfigCache, moduleResolutionCache, typeReferenceDirectiveResolutionCache, libraryResolutionCache } = state;
120804
120974
  host.readFile = cache.originalReadFile;
120805
120975
  host.fileExists = cache.originalFileExists;
120806
120976
  host.directoryExists = cache.originalDirectoryExists;
@@ -120811,6 +120981,7 @@ function disableCache(state) {
120811
120981
  extendedConfigCache.clear();
120812
120982
  moduleResolutionCache == null ? void 0 : moduleResolutionCache.clear();
120813
120983
  typeReferenceDirectiveResolutionCache == null ? void 0 : typeReferenceDirectiveResolutionCache.clear();
120984
+ libraryResolutionCache == null ? void 0 : libraryResolutionCache.clear();
120814
120985
  state.cache = void 0;
120815
120986
  }
120816
120987
  function clearProjectStatus(state, resolved) {