typescript 5.8.0-dev.20250109 → 5.8.0-dev.20250110

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.8";
21
- var version = `${versionMajorMinor}.0-dev.20250109`;
21
+ var version = `${versionMajorMinor}.0-dev.20250110`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -5501,23 +5501,105 @@ function resolvePath(path, ...paths) {
5501
5501
  function getNormalizedPathComponents(path, currentDirectory) {
5502
5502
  return reducePathComponents(getPathComponents(path, currentDirectory));
5503
5503
  }
5504
- function getNormalizedAbsolutePath(fileName, currentDirectory) {
5505
- return getPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
5504
+ function getNormalizedAbsolutePath(path, currentDirectory) {
5505
+ let rootLength = getRootLength(path);
5506
+ if (rootLength === 0 && currentDirectory) {
5507
+ path = combinePaths(currentDirectory, path);
5508
+ rootLength = getRootLength(path);
5509
+ } else {
5510
+ path = normalizeSlashes(path);
5511
+ }
5512
+ const simpleNormalized = simpleNormalizePath(path);
5513
+ if (simpleNormalized !== void 0) {
5514
+ return simpleNormalized.length > rootLength ? removeTrailingDirectorySeparator(simpleNormalized) : simpleNormalized;
5515
+ }
5516
+ const length2 = path.length;
5517
+ const root = path.substring(0, rootLength);
5518
+ let normalized;
5519
+ let index = rootLength;
5520
+ let segmentStart = index;
5521
+ let normalizedUpTo = index;
5522
+ let seenNonDotDotSegment = rootLength !== 0;
5523
+ while (index < length2) {
5524
+ segmentStart = index;
5525
+ let ch = path.charCodeAt(index);
5526
+ while (ch === 47 /* slash */ && index + 1 < length2) {
5527
+ index++;
5528
+ ch = path.charCodeAt(index);
5529
+ }
5530
+ if (index > segmentStart) {
5531
+ normalized ?? (normalized = path.substring(0, segmentStart - 1));
5532
+ segmentStart = index;
5533
+ }
5534
+ let segmentEnd = path.indexOf(directorySeparator, index + 1);
5535
+ if (segmentEnd === -1) {
5536
+ segmentEnd = length2;
5537
+ }
5538
+ const segmentLength = segmentEnd - segmentStart;
5539
+ if (segmentLength === 1 && path.charCodeAt(index) === 46 /* dot */) {
5540
+ normalized ?? (normalized = path.substring(0, normalizedUpTo));
5541
+ } else if (segmentLength === 2 && path.charCodeAt(index) === 46 /* dot */ && path.charCodeAt(index + 1) === 46 /* dot */) {
5542
+ if (!seenNonDotDotSegment) {
5543
+ if (normalized !== void 0) {
5544
+ normalized += normalized.length === rootLength ? ".." : "/..";
5545
+ } else {
5546
+ normalizedUpTo = index + 2;
5547
+ }
5548
+ } else if (normalized === void 0) {
5549
+ if (normalizedUpTo - 2 >= 0) {
5550
+ normalized = path.substring(0, Math.max(rootLength, path.lastIndexOf(directorySeparator, normalizedUpTo - 2)));
5551
+ } else {
5552
+ normalized = path.substring(0, normalizedUpTo);
5553
+ }
5554
+ } else {
5555
+ const lastSlash = normalized.lastIndexOf(directorySeparator);
5556
+ if (lastSlash !== -1) {
5557
+ normalized = normalized.substring(0, Math.max(rootLength, lastSlash));
5558
+ } else {
5559
+ normalized = root;
5560
+ }
5561
+ if (normalized.length === rootLength) {
5562
+ seenNonDotDotSegment = rootLength !== 0;
5563
+ }
5564
+ }
5565
+ } else if (normalized !== void 0) {
5566
+ if (normalized.length !== rootLength) {
5567
+ normalized += directorySeparator;
5568
+ }
5569
+ seenNonDotDotSegment = true;
5570
+ normalized += path.substring(segmentStart, segmentEnd);
5571
+ } else {
5572
+ seenNonDotDotSegment = true;
5573
+ normalizedUpTo = segmentEnd;
5574
+ }
5575
+ index = segmentEnd + 1;
5576
+ }
5577
+ return normalized ?? (length2 > rootLength ? removeTrailingDirectorySeparator(path) : path);
5506
5578
  }
5507
5579
  function normalizePath(path) {
5508
5580
  path = normalizeSlashes(path);
5581
+ let normalized = simpleNormalizePath(path);
5582
+ if (normalized !== void 0) {
5583
+ return normalized;
5584
+ }
5585
+ normalized = getNormalizedAbsolutePath(path, "");
5586
+ return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
5587
+ }
5588
+ function simpleNormalizePath(path) {
5509
5589
  if (!relativePathSegmentRegExp.test(path)) {
5510
5590
  return path;
5511
5591
  }
5512
- const simplified = path.replace(/\/\.\//g, "/").replace(/^\.\//, "");
5592
+ let simplified = path.replace(/\/\.\//g, "/");
5593
+ if (simplified.startsWith("./")) {
5594
+ simplified = simplified.slice(2);
5595
+ }
5513
5596
  if (simplified !== path) {
5514
5597
  path = simplified;
5515
5598
  if (!relativePathSegmentRegExp.test(path)) {
5516
5599
  return path;
5517
5600
  }
5518
5601
  }
5519
- const normalized = getPathFromPathComponents(reducePathComponents(getPathComponents(path)));
5520
- return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
5602
+ return void 0;
5521
5603
  }
5522
5604
  function getPathWithoutRoot(pathComponents2) {
5523
5605
  if (pathComponents2.length === 0) return "";
@@ -14262,9 +14344,6 @@ function forEachPropertyAssignment(objectLiteral, key, callback, key2) {
14262
14344
  return key === propName || key2 && key2 === propName ? callback(property) : void 0;
14263
14345
  });
14264
14346
  }
14265
- function getPropertyArrayElementValue(objectLiteral, propKey, elementValue) {
14266
- return forEachPropertyAssignment(objectLiteral, propKey, (property) => isArrayLiteralExpression(property.initializer) ? find(property.initializer.elements, (element) => isStringLiteral(element) && element.text === elementValue) : void 0);
14267
- }
14268
14347
  function getTsConfigObjectLiteralExpression(tsConfigSourceFile) {
14269
14348
  if (tsConfigSourceFile && tsConfigSourceFile.statements.length) {
14270
14349
  const expression = tsConfigSourceFile.statements[0].expression;
@@ -19862,6 +19941,64 @@ function getNodeAtPosition(sourceFile, position, includeJSDoc) {
19862
19941
  function isNewScopeNode(node) {
19863
19942
  return isFunctionLike(node) || isJSDocSignature(node) || isMappedTypeNode(node);
19864
19943
  }
19944
+ function getLibNameFromLibReference(libReference) {
19945
+ return toFileNameLowerCase(libReference.fileName);
19946
+ }
19947
+ function getLibFileNameFromLibReference(libReference) {
19948
+ const libName = getLibNameFromLibReference(libReference);
19949
+ return libMap.get(libName);
19950
+ }
19951
+ function forEachResolvedProjectReference(resolvedProjectReferences, cb) {
19952
+ return forEachProjectReference(
19953
+ /*projectReferences*/
19954
+ void 0,
19955
+ resolvedProjectReferences,
19956
+ (resolvedRef, parent) => resolvedRef && cb(resolvedRef, parent)
19957
+ );
19958
+ }
19959
+ function forEachProjectReference(projectReferences, resolvedProjectReferences, cbResolvedRef, cbRef) {
19960
+ let seenResolvedRefs;
19961
+ return worker(
19962
+ projectReferences,
19963
+ resolvedProjectReferences,
19964
+ /*parent*/
19965
+ void 0
19966
+ );
19967
+ function worker(projectReferences2, resolvedProjectReferences2, parent) {
19968
+ if (cbRef) {
19969
+ const result = cbRef(projectReferences2, parent);
19970
+ if (result) return result;
19971
+ }
19972
+ let skipChildren;
19973
+ return forEach(
19974
+ resolvedProjectReferences2,
19975
+ (resolvedRef, index) => {
19976
+ if (resolvedRef && (seenResolvedRefs == null ? void 0 : seenResolvedRefs.has(resolvedRef.sourceFile.path))) {
19977
+ (skipChildren ?? (skipChildren = /* @__PURE__ */ new Set())).add(resolvedRef);
19978
+ return void 0;
19979
+ }
19980
+ const result = cbResolvedRef(resolvedRef, parent, index);
19981
+ if (result || !resolvedRef) return result;
19982
+ (seenResolvedRefs || (seenResolvedRefs = /* @__PURE__ */ new Set())).add(resolvedRef.sourceFile.path);
19983
+ }
19984
+ ) || forEach(
19985
+ resolvedProjectReferences2,
19986
+ (resolvedRef) => resolvedRef && !(skipChildren == null ? void 0 : skipChildren.has(resolvedRef)) ? worker(resolvedRef.commandLine.projectReferences, resolvedRef.references, resolvedRef) : void 0
19987
+ );
19988
+ }
19989
+ }
19990
+ function getOptionsSyntaxByArrayElementValue(optionsObject, name, value) {
19991
+ return optionsObject && getPropertyArrayElementValue(optionsObject, name, value);
19992
+ }
19993
+ function getPropertyArrayElementValue(objectLiteral, propKey, elementValue) {
19994
+ return forEachPropertyAssignment(objectLiteral, propKey, (property) => isArrayLiteralExpression(property.initializer) ? find(property.initializer.elements, (element) => isStringLiteral(element) && element.text === elementValue) : void 0);
19995
+ }
19996
+ function getOptionsSyntaxByValue(optionsObject, name, value) {
19997
+ return forEachOptionsSyntaxByName(optionsObject, name, (property) => isStringLiteral(property.initializer) && property.initializer.text === value ? property.initializer : void 0);
19998
+ }
19999
+ function forEachOptionsSyntaxByName(optionsObject, name, callback) {
20000
+ return forEachPropertyAssignment(optionsObject, name, callback);
20001
+ }
19865
20002
 
19866
20003
  // src/compiler/factory/baseNodeFactory.ts
19867
20004
  function createBaseNodeFactory() {
@@ -120881,45 +121018,6 @@ function loadWithModeAwareCache(entries, containingFile, redirectedReference, op
120881
121018
  }
120882
121019
  return resolutions;
120883
121020
  }
120884
- function forEachResolvedProjectReference(resolvedProjectReferences, cb) {
120885
- return forEachProjectReference(
120886
- /*projectReferences*/
120887
- void 0,
120888
- resolvedProjectReferences,
120889
- (resolvedRef, parent) => resolvedRef && cb(resolvedRef, parent)
120890
- );
120891
- }
120892
- function forEachProjectReference(projectReferences, resolvedProjectReferences, cbResolvedRef, cbRef) {
120893
- let seenResolvedRefs;
120894
- return worker(
120895
- projectReferences,
120896
- resolvedProjectReferences,
120897
- /*parent*/
120898
- void 0
120899
- );
120900
- function worker(projectReferences2, resolvedProjectReferences2, parent) {
120901
- if (cbRef) {
120902
- const result = cbRef(projectReferences2, parent);
120903
- if (result) return result;
120904
- }
120905
- let skipChildren;
120906
- return forEach(
120907
- resolvedProjectReferences2,
120908
- (resolvedRef, index) => {
120909
- if (resolvedRef && (seenResolvedRefs == null ? void 0 : seenResolvedRefs.has(resolvedRef.sourceFile.path))) {
120910
- (skipChildren ?? (skipChildren = /* @__PURE__ */ new Set())).add(resolvedRef);
120911
- return void 0;
120912
- }
120913
- const result = cbResolvedRef(resolvedRef, parent, index);
120914
- if (result || !resolvedRef) return result;
120915
- (seenResolvedRefs || (seenResolvedRefs = /* @__PURE__ */ new Set())).add(resolvedRef.sourceFile.path);
120916
- }
120917
- ) || forEach(
120918
- resolvedProjectReferences2,
120919
- (resolvedRef) => resolvedRef && !(skipChildren == null ? void 0 : skipChildren.has(resolvedRef)) ? worker(resolvedRef.commandLine.projectReferences, resolvedRef.references, resolvedRef) : void 0
120920
- );
120921
- }
120922
- }
120923
121021
  var inferredTypesContainingFile = "__inferred type names__.ts";
120924
121022
  function getInferredLibraryNameResolveFrom(options, currentDirectory, libFileName) {
120925
121023
  const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory;
@@ -120935,13 +121033,6 @@ function getLibraryNameFromLibFileName(libFileName) {
120935
121033
  }
120936
121034
  return "@typescript/lib-" + path;
120937
121035
  }
120938
- function getLibNameFromLibReference(libReference) {
120939
- return toFileNameLowerCase(libReference.fileName);
120940
- }
120941
- function getLibFileNameFromLibReference(libReference) {
120942
- const libName = getLibNameFromLibReference(libReference);
120943
- return libMap.get(libName);
120944
- }
120945
121036
  function isReferencedFile(reason) {
120946
121037
  switch (reason == null ? void 0 : reason.kind) {
120947
121038
  case 3 /* Import */:
@@ -121172,16 +121263,12 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121172
121263
  let processingOtherFiles;
121173
121264
  let files;
121174
121265
  let symlinks;
121175
- let commonSourceDirectory;
121176
121266
  let typeChecker;
121177
121267
  let classifiableNames;
121178
- let fileReasons = createMultiMap();
121179
121268
  let filesWithReferencesProcessed;
121180
- let fileReasonsToChain;
121181
- let reasonToRelatedInfo;
121182
121269
  let cachedBindAndCheckDiagnosticsForFile;
121183
121270
  let cachedDeclarationDiagnosticsForFile;
121184
- let fileProcessingDiagnostics;
121271
+ const programDiagnostics = createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax);
121185
121272
  let automaticTypeDirectiveNames;
121186
121273
  let automaticTypeDirectiveResolutions;
121187
121274
  let resolvedLibReferences;
@@ -121208,8 +121295,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121208
121295
  let skipDefaultLib = options.noLib;
121209
121296
  const getDefaultLibraryFileName = memoize(() => host.getDefaultLibFileName(options));
121210
121297
  const defaultLibraryPath = host.getDefaultLibLocation ? host.getDefaultLibLocation() : getDirectoryPath(getDefaultLibraryFileName());
121211
- const programDiagnostics = createDiagnosticCollection();
121212
- let lazyProgramDiagnosticExplainingFile = [];
121298
+ let skipVerifyCompilerOptions = false;
121213
121299
  const currentDirectory = host.getCurrentDirectory();
121214
121300
  const supportedExtensions = getSupportedExtensions(options);
121215
121301
  const supportedExtensionsWithJsonIfResolveJsonModule = getSupportedExtensionsWithJsonIfResolveJsonModule(options, supportedExtensions);
@@ -121487,7 +121573,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121487
121573
  getTypeCount: () => getTypeChecker().getTypeCount(),
121488
121574
  getInstantiationCount: () => getTypeChecker().getInstantiationCount(),
121489
121575
  getRelationCacheSizes: () => getTypeChecker().getRelationCacheSizes(),
121490
- getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
121576
+ getFileProcessingDiagnostics: () => programDiagnostics.getFileProcessingDiagnostics(),
121491
121577
  getAutomaticTypeDirectiveNames: () => automaticTypeDirectiveNames,
121492
121578
  getAutomaticTypeDirectiveResolutions: () => automaticTypeDirectiveResolutions,
121493
121579
  isSourceFileFromExternalLibrary,
@@ -121503,6 +121589,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121503
121589
  resolvedModules,
121504
121590
  resolvedTypeReferenceDirectiveNames,
121505
121591
  resolvedLibReferences,
121592
+ getProgramDiagnosticsContainer: () => programDiagnostics,
121506
121593
  getResolvedModule,
121507
121594
  getResolvedModuleFromModuleSpecifier,
121508
121595
  getResolvedTypeReferenceDirective,
@@ -121535,70 +121622,19 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121535
121622
  realpath: (_o = host.realpath) == null ? void 0 : _o.bind(host),
121536
121623
  useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
121537
121624
  getCanonicalFileName,
121538
- getFileIncludeReasons: () => fileReasons,
121625
+ getFileIncludeReasons: () => programDiagnostics.getFileReasons(),
121539
121626
  structureIsReused,
121540
121627
  writeFile: writeFile2,
121541
121628
  getGlobalTypingsCacheLocation: maybeBind(host, host.getGlobalTypingsCacheLocation)
121542
121629
  };
121543
121630
  onProgramCreateComplete();
121544
- verifyCompilerOptions();
121631
+ if (!skipVerifyCompilerOptions) {
121632
+ verifyCompilerOptions();
121633
+ }
121545
121634
  mark("afterProgram");
121546
121635
  measure("Program", "beforeProgram", "afterProgram");
121547
121636
  (_p = tracing) == null ? void 0 : _p.pop();
121548
121637
  return program;
121549
- function updateAndGetProgramDiagnostics() {
121550
- if (lazyProgramDiagnosticExplainingFile) {
121551
- fileProcessingDiagnostics == null ? void 0 : fileProcessingDiagnostics.forEach((diagnostic) => {
121552
- switch (diagnostic.kind) {
121553
- case 1 /* FilePreprocessingFileExplainingDiagnostic */:
121554
- return programDiagnostics.add(
121555
- createDiagnosticExplainingFile(
121556
- diagnostic.file && getSourceFileByPath(diagnostic.file),
121557
- diagnostic.fileProcessingReason,
121558
- diagnostic.diagnostic,
121559
- diagnostic.args || emptyArray
121560
- )
121561
- );
121562
- case 0 /* FilePreprocessingLibReferenceDiagnostic */:
121563
- return programDiagnostics.add(filePreprocessingLibreferenceDiagnostic(diagnostic));
121564
- case 2 /* ResolutionDiagnostics */:
121565
- return diagnostic.diagnostics.forEach((d) => programDiagnostics.add(d));
121566
- default:
121567
- Debug.assertNever(diagnostic);
121568
- }
121569
- });
121570
- lazyProgramDiagnosticExplainingFile.forEach(
121571
- ({ file, diagnostic, args }) => programDiagnostics.add(
121572
- createDiagnosticExplainingFile(
121573
- file,
121574
- /*fileProcessingReason*/
121575
- void 0,
121576
- diagnostic,
121577
- args
121578
- )
121579
- )
121580
- );
121581
- lazyProgramDiagnosticExplainingFile = void 0;
121582
- fileReasonsToChain = void 0;
121583
- reasonToRelatedInfo = void 0;
121584
- }
121585
- return programDiagnostics;
121586
- }
121587
- function filePreprocessingLibreferenceDiagnostic({ reason }) {
121588
- const { file, pos, end } = getReferencedFileLocation(program, reason);
121589
- const libReference = file.libReferenceDirectives[reason.index];
121590
- const libName = getLibNameFromLibReference(libReference);
121591
- const unqualifiedLibName = removeSuffix(removePrefix(libName, "lib."), ".d.ts");
121592
- const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity);
121593
- return createFileDiagnostic(
121594
- file,
121595
- Debug.checkDefined(pos),
121596
- Debug.checkDefined(end) - pos,
121597
- suggestion ? Diagnostics.Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics.Cannot_find_lib_definition_for_0,
121598
- libName,
121599
- suggestion
121600
- );
121601
- }
121602
121638
  function getResolvedModule(file, moduleName, mode) {
121603
121639
  var _a2;
121604
121640
  return (_a2 = resolvedModules == null ? void 0 : resolvedModules.get(file.path)) == null ? void 0 : _a2.get(moduleName, mode);
@@ -121647,7 +121683,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121647
121683
  function addResolutionDiagnostics(resolution) {
121648
121684
  var _a2;
121649
121685
  if (!((_a2 = resolution.resolutionDiagnostics) == null ? void 0 : _a2.length)) return;
121650
- (fileProcessingDiagnostics ?? (fileProcessingDiagnostics = [])).push({
121686
+ programDiagnostics.addFileProcessingDiagnostic({
121651
121687
  kind: 2 /* ResolutionDiagnostics */,
121652
121688
  diagnostics: resolution.resolutionDiagnostics
121653
121689
  });
@@ -121741,16 +121777,19 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121741
121777
  return toPath(fileName, currentDirectory, getCanonicalFileName);
121742
121778
  }
121743
121779
  function getCommonSourceDirectory2() {
121744
- if (commonSourceDirectory === void 0) {
121745
- const emittedFiles = filter(files, (file) => sourceFileMayBeEmitted(file, program));
121746
- commonSourceDirectory = getCommonSourceDirectory(
121747
- options,
121748
- () => mapDefined(emittedFiles, (file) => file.isDeclarationFile ? void 0 : file.fileName),
121749
- currentDirectory,
121750
- getCanonicalFileName,
121751
- (commonSourceDirectory2) => checkSourceFilesBelongToPath(emittedFiles, commonSourceDirectory2)
121752
- );
121780
+ let commonSourceDirectory = programDiagnostics.getCommonSourceDirectory();
121781
+ if (commonSourceDirectory !== void 0) {
121782
+ return commonSourceDirectory;
121753
121783
  }
121784
+ const emittedFiles = filter(files, (file) => sourceFileMayBeEmitted(file, program));
121785
+ commonSourceDirectory = getCommonSourceDirectory(
121786
+ options,
121787
+ () => mapDefined(emittedFiles, (file) => file.isDeclarationFile ? void 0 : file.fileName),
121788
+ currentDirectory,
121789
+ getCanonicalFileName,
121790
+ (commonSourceDirectory2) => checkSourceFilesBelongToPath(emittedFiles, commonSourceDirectory2)
121791
+ );
121792
+ programDiagnostics.setCommonSourceDirectory(commonSourceDirectory);
121754
121793
  return commonSourceDirectory;
121755
121794
  }
121756
121795
  function getClassifiableNames() {
@@ -122061,9 +122100,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122061
122100
  }
122062
122101
  filesByName.set(path, filesByName.get(oldFile.path));
122063
122102
  });
122103
+ const isConfigIdentical = oldOptions.configFile && oldOptions.configFile === options.configFile || !oldOptions.configFile && !options.configFile && !optionsHaveChanges(oldOptions, options, optionDeclarations);
122104
+ programDiagnostics.reuseStateFromOldProgram(oldProgram.getProgramDiagnosticsContainer(), isConfigIdentical);
122105
+ skipVerifyCompilerOptions = isConfigIdentical;
122064
122106
  files = newSourceFiles;
122065
- fileReasons = oldProgram.getFileIncludeReasons();
122066
- fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics();
122067
122107
  automaticTypeDirectiveNames = oldProgram.getAutomaticTypeDirectiveNames();
122068
122108
  automaticTypeDirectiveResolutions = oldProgram.getAutomaticTypeDirectiveResolutions();
122069
122109
  sourceFileToPackageName = oldProgram.sourceFileToPackageName;
@@ -122279,7 +122319,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122279
122319
  if (skipTypeChecking(sourceFile, options, program)) {
122280
122320
  return emptyArray;
122281
122321
  }
122282
- const programDiagnosticsInFile = updateAndGetProgramDiagnostics().getDiagnostics(sourceFile.fileName);
122322
+ const programDiagnosticsInFile = programDiagnostics.getCombinedDiagnostics(program).getDiagnostics(sourceFile.fileName);
122283
122323
  if (!((_a2 = sourceFile.commentDirectives) == null ? void 0 : _a2.length)) {
122284
122324
  return programDiagnosticsInFile;
122285
122325
  }
@@ -122637,15 +122677,15 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122637
122677
  }
122638
122678
  function getOptionsDiagnostics() {
122639
122679
  return sortAndDeduplicateDiagnostics(concatenate(
122640
- updateAndGetProgramDiagnostics().getGlobalDiagnostics(),
122680
+ programDiagnostics.getCombinedDiagnostics(program).getGlobalDiagnostics(),
122641
122681
  getOptionsDiagnosticsOfConfigFile()
122642
122682
  ));
122643
122683
  }
122644
122684
  function getOptionsDiagnosticsOfConfigFile() {
122645
122685
  if (!options.configFile) return emptyArray;
122646
- let diagnostics = updateAndGetProgramDiagnostics().getDiagnostics(options.configFile.fileName);
122686
+ let diagnostics = programDiagnostics.getCombinedDiagnostics(program).getDiagnostics(options.configFile.fileName);
122647
122687
  forEachResolvedProjectReference2((resolvedRef) => {
122648
- diagnostics = concatenate(diagnostics, updateAndGetProgramDiagnostics().getDiagnostics(resolvedRef.sourceFile.fileName));
122688
+ diagnostics = concatenate(diagnostics, programDiagnostics.getCombinedDiagnostics(program).getDiagnostics(resolvedRef.sourceFile.fileName));
122649
122689
  });
122650
122690
  return diagnostics;
122651
122691
  }
@@ -122852,7 +122892,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122852
122892
  );
122853
122893
  }
122854
122894
  function reportFileNamesDifferOnlyInCasingError(fileName, existingFile, reason) {
122855
- const hasExistingReasonToReportErrorOn = !isReferencedFile(reason) && some(fileReasons.get(existingFile.path), isReferencedFile);
122895
+ const hasExistingReasonToReportErrorOn = !isReferencedFile(reason) && some(programDiagnostics.getFileReasons().get(existingFile.path), isReferencedFile);
122856
122896
  if (hasExistingReasonToReportErrorOn) {
122857
122897
  addFilePreprocessingFileExplainingDiagnostic(existingFile, reason, Diagnostics.Already_included_file_name_0_differs_from_file_name_1_only_in_casing, [existingFile.fileName, fileName]);
122858
122898
  } else {
@@ -123039,7 +123079,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123039
123079
  }
123040
123080
  function addFileIncludeReason(file, reason, checkExisting) {
123041
123081
  if (file && (!checkExisting || !isReferencedFile(reason) || !(filesWithReferencesProcessed == null ? void 0 : filesWithReferencesProcessed.has(reason.file)))) {
123042
- fileReasons.add(file.path, reason);
123082
+ programDiagnostics.getFileReasons().add(file.path, reason);
123043
123083
  return true;
123044
123084
  }
123045
123085
  return false;
@@ -123238,7 +123278,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123238
123278
  { kind: 7 /* LibReferenceDirective */, file: file.path, index }
123239
123279
  );
123240
123280
  } else {
123241
- (fileProcessingDiagnostics || (fileProcessingDiagnostics = [])).push({
123281
+ programDiagnostics.addFileProcessingDiagnostic({
123242
123282
  kind: 0 /* FilePreprocessingLibReferenceDiagnostic */,
123243
123283
  reason: { kind: 7 /* LibReferenceDirective */, file: file.path, index }
123244
123284
  });
@@ -123301,10 +123341,11 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123301
123341
  if (!sourceFile.isDeclarationFile) {
123302
123342
  const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
123303
123343
  if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
123304
- addLazyProgramDiagnosticExplainingFile(
123344
+ programDiagnostics.addLazyConfigDiagnostic(
123305
123345
  sourceFile,
123306
123346
  Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files,
123307
- [sourceFile.fileName, rootDirectory]
123347
+ sourceFile.fileName,
123348
+ rootDirectory
123308
123349
  );
123309
123350
  allFilesBelongToPath = false;
123310
123351
  }
@@ -123419,7 +123460,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123419
123460
  }
123420
123461
  const outputFile = options.outFile;
123421
123462
  if (!options.tsBuildInfoFile && options.incremental && !outputFile && !options.configFilePath) {
123422
- programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
123463
+ programDiagnostics.addConfigDiagnostic(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
123423
123464
  }
123424
123465
  verifyDeprecatedCompilerOptions();
123425
123466
  verifyProjectReferences();
@@ -123427,10 +123468,11 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123427
123468
  const rootPaths = new Set(rootNames.map(toPath3));
123428
123469
  for (const file of files) {
123429
123470
  if (sourceFileMayBeEmitted(file, program) && !rootPaths.has(file.path)) {
123430
- addLazyProgramDiagnosticExplainingFile(
123471
+ programDiagnostics.addLazyConfigDiagnostic(
123431
123472
  file,
123432
123473
  Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
123433
- [file.fileName, options.configFilePath || ""]
123474
+ file.fileName,
123475
+ options.configFilePath || ""
123434
123476
  );
123435
123477
  }
123436
123478
  }
@@ -123521,14 +123563,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123521
123563
  }
123522
123564
  } else if (firstNonAmbientExternalModuleSourceFile && languageVersion < 2 /* ES2015 */ && options.module === 0 /* None */) {
123523
123565
  const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
123524
- programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
123566
+ programDiagnostics.addConfigDiagnostic(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
123525
123567
  }
123526
123568
  if (outputFile && !options.emitDeclarationOnly) {
123527
123569
  if (options.module && !(options.module === 2 /* AMD */ || options.module === 4 /* System */)) {
123528
123570
  createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, "outFile", "module");
123529
123571
  } else if (options.module === void 0 && firstNonAmbientExternalModuleSourceFile) {
123530
123572
  const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
123531
- programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, "outFile"));
123573
+ programDiagnostics.addConfigDiagnostic(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, "outFile"));
123532
123574
  }
123533
123575
  }
123534
123576
  if (getResolveJsonModule(options)) {
@@ -123780,90 +123822,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123780
123822
  }
123781
123823
  });
123782
123824
  }
123783
- function createDiagnosticExplainingFile(file, fileProcessingReason, diagnostic, args) {
123784
- let seenReasons;
123785
- const reasons = file && fileReasons.get(file.path);
123786
- let fileIncludeReasons;
123787
- let relatedInfo;
123788
- let locationReason = isReferencedFile(fileProcessingReason) ? fileProcessingReason : void 0;
123789
- let fileIncludeReasonDetails;
123790
- let redirectInfo;
123791
- let cachedChain = file && (fileReasonsToChain == null ? void 0 : fileReasonsToChain.get(file.path));
123792
- let chain;
123793
- if (cachedChain) {
123794
- if (cachedChain.fileIncludeReasonDetails) {
123795
- seenReasons = new Set(reasons);
123796
- reasons == null ? void 0 : reasons.forEach(populateRelatedInfo);
123797
- } else {
123798
- reasons == null ? void 0 : reasons.forEach(processReason);
123799
- }
123800
- redirectInfo = cachedChain.redirectInfo;
123801
- } else {
123802
- reasons == null ? void 0 : reasons.forEach(processReason);
123803
- redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file));
123804
- }
123805
- if (fileProcessingReason) processReason(fileProcessingReason);
123806
- const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length);
123807
- if (locationReason && (seenReasons == null ? void 0 : seenReasons.size) === 1) seenReasons = void 0;
123808
- if (seenReasons && cachedChain) {
123809
- if (cachedChain.details && !processedExtraReason) {
123810
- chain = chainDiagnosticMessages(cachedChain.details, diagnostic, ...args || emptyArray);
123811
- } else if (cachedChain.fileIncludeReasonDetails) {
123812
- if (!processedExtraReason) {
123813
- if (!cachedFileIncludeDetailsHasProcessedExtraReason()) {
123814
- fileIncludeReasonDetails = cachedChain.fileIncludeReasonDetails;
123815
- } else {
123816
- fileIncludeReasons = cachedChain.fileIncludeReasonDetails.next.slice(0, reasons.length);
123817
- }
123818
- } else {
123819
- if (!cachedFileIncludeDetailsHasProcessedExtraReason()) {
123820
- fileIncludeReasons = [...cachedChain.fileIncludeReasonDetails.next, fileIncludeReasons[0]];
123821
- } else {
123822
- fileIncludeReasons = append(cachedChain.fileIncludeReasonDetails.next.slice(0, reasons.length), fileIncludeReasons[0]);
123823
- }
123824
- }
123825
- }
123826
- }
123827
- if (!chain) {
123828
- if (!fileIncludeReasonDetails) fileIncludeReasonDetails = seenReasons && chainDiagnosticMessages(fileIncludeReasons, Diagnostics.The_file_is_in_the_program_because_Colon);
123829
- chain = chainDiagnosticMessages(
123830
- redirectInfo ? fileIncludeReasonDetails ? [fileIncludeReasonDetails, ...redirectInfo] : redirectInfo : fileIncludeReasonDetails,
123831
- diagnostic,
123832
- ...args || emptyArray
123833
- );
123834
- }
123835
- if (file) {
123836
- if (cachedChain) {
123837
- if (!cachedChain.fileIncludeReasonDetails || !processedExtraReason && fileIncludeReasonDetails) {
123838
- cachedChain.fileIncludeReasonDetails = fileIncludeReasonDetails;
123839
- }
123840
- } else {
123841
- (fileReasonsToChain ?? (fileReasonsToChain = /* @__PURE__ */ new Map())).set(file.path, cachedChain = { fileIncludeReasonDetails, redirectInfo });
123842
- }
123843
- if (!cachedChain.details && !processedExtraReason) cachedChain.details = chain.next;
123844
- }
123845
- const location = locationReason && getReferencedFileLocation(program, locationReason);
123846
- return location && isReferenceFileLocation(location) ? createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) : createCompilerDiagnosticFromMessageChain(chain, relatedInfo);
123847
- function processReason(reason) {
123848
- if (seenReasons == null ? void 0 : seenReasons.has(reason)) return;
123849
- (seenReasons ?? (seenReasons = /* @__PURE__ */ new Set())).add(reason);
123850
- (fileIncludeReasons ?? (fileIncludeReasons = [])).push(fileIncludeReasonToDiagnostics(program, reason));
123851
- populateRelatedInfo(reason);
123852
- }
123853
- function populateRelatedInfo(reason) {
123854
- if (!locationReason && isReferencedFile(reason)) {
123855
- locationReason = reason;
123856
- } else if (locationReason !== reason) {
123857
- relatedInfo = append(relatedInfo, getFileIncludeReasonToRelatedInformation(reason));
123858
- }
123859
- }
123860
- function cachedFileIncludeDetailsHasProcessedExtraReason() {
123861
- var _a2;
123862
- return ((_a2 = cachedChain.fileIncludeReasonDetails.next) == null ? void 0 : _a2.length) !== (reasons == null ? void 0 : reasons.length);
123863
- }
123864
- }
123865
123825
  function addFilePreprocessingFileExplainingDiagnostic(file, fileProcessingReason, diagnostic, args) {
123866
- (fileProcessingDiagnostics || (fileProcessingDiagnostics = [])).push({
123826
+ programDiagnostics.addFileProcessingDiagnostic({
123867
123827
  kind: 1 /* FilePreprocessingFileExplainingDiagnostic */,
123868
123828
  file: file && file.path,
123869
123829
  fileProcessingReason,
@@ -123871,99 +123831,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123871
123831
  args
123872
123832
  });
123873
123833
  }
123874
- function addLazyProgramDiagnosticExplainingFile(file, diagnostic, args) {
123875
- lazyProgramDiagnosticExplainingFile.push({ file, diagnostic, args });
123876
- }
123877
- function getFileIncludeReasonToRelatedInformation(reason) {
123878
- let relatedInfo = reasonToRelatedInfo == null ? void 0 : reasonToRelatedInfo.get(reason);
123879
- if (relatedInfo === void 0) (reasonToRelatedInfo ?? (reasonToRelatedInfo = /* @__PURE__ */ new Map())).set(reason, relatedInfo = fileIncludeReasonToRelatedInformation(reason) ?? false);
123880
- return relatedInfo || void 0;
123881
- }
123882
- function fileIncludeReasonToRelatedInformation(reason) {
123883
- if (isReferencedFile(reason)) {
123884
- const referenceLocation = getReferencedFileLocation(program, reason);
123885
- let message2;
123886
- switch (reason.kind) {
123887
- case 3 /* Import */:
123888
- message2 = Diagnostics.File_is_included_via_import_here;
123889
- break;
123890
- case 4 /* ReferenceFile */:
123891
- message2 = Diagnostics.File_is_included_via_reference_here;
123892
- break;
123893
- case 5 /* TypeReferenceDirective */:
123894
- message2 = Diagnostics.File_is_included_via_type_library_reference_here;
123895
- break;
123896
- case 7 /* LibReferenceDirective */:
123897
- message2 = Diagnostics.File_is_included_via_library_reference_here;
123898
- break;
123899
- default:
123900
- Debug.assertNever(reason);
123901
- }
123902
- return isReferenceFileLocation(referenceLocation) ? createFileDiagnostic(
123903
- referenceLocation.file,
123904
- referenceLocation.pos,
123905
- referenceLocation.end - referenceLocation.pos,
123906
- message2
123907
- ) : void 0;
123908
- }
123909
- if (!options.configFile) return void 0;
123910
- let configFileNode;
123911
- let message;
123912
- switch (reason.kind) {
123913
- case 0 /* RootFile */:
123914
- if (!options.configFile.configFileSpecs) return void 0;
123915
- const fileName = getNormalizedAbsolutePath(rootNames[reason.index], currentDirectory);
123916
- const matchedByFiles = getMatchedFileSpec(program, fileName);
123917
- if (matchedByFiles) {
123918
- configFileNode = getTsConfigPropArrayElementValue(options.configFile, "files", matchedByFiles);
123919
- message = Diagnostics.File_is_matched_by_files_list_specified_here;
123920
- break;
123921
- }
123922
- const matchedByInclude = getMatchedIncludeSpec(program, fileName);
123923
- if (!matchedByInclude || !isString(matchedByInclude)) return void 0;
123924
- configFileNode = getTsConfigPropArrayElementValue(options.configFile, "include", matchedByInclude);
123925
- message = Diagnostics.File_is_matched_by_include_pattern_specified_here;
123926
- break;
123927
- case 1 /* SourceFromProjectReference */:
123928
- case 2 /* OutputFromProjectReference */:
123929
- const referencedResolvedRef = Debug.checkDefined(resolvedProjectReferences == null ? void 0 : resolvedProjectReferences[reason.index]);
123930
- const referenceInfo = forEachProjectReference(
123931
- projectReferences,
123932
- resolvedProjectReferences,
123933
- (resolvedRef, parent, index2) => resolvedRef === referencedResolvedRef ? { sourceFile: (parent == null ? void 0 : parent.sourceFile) || options.configFile, index: index2 } : void 0
123934
- );
123935
- if (!referenceInfo) return void 0;
123936
- const { sourceFile, index } = referenceInfo;
123937
- const referencesSyntax = forEachTsConfigPropArray(sourceFile, "references", (property) => isArrayLiteralExpression(property.initializer) ? property.initializer : void 0);
123938
- return referencesSyntax && referencesSyntax.elements.length > index ? createDiagnosticForNodeInSourceFile(
123939
- sourceFile,
123940
- referencesSyntax.elements[index],
123941
- reason.kind === 2 /* OutputFromProjectReference */ ? Diagnostics.File_is_output_from_referenced_project_specified_here : Diagnostics.File_is_source_from_referenced_project_specified_here
123942
- ) : void 0;
123943
- case 8 /* AutomaticTypeDirectiveFile */:
123944
- if (!options.types) return void 0;
123945
- configFileNode = getOptionsSyntaxByArrayElementValue("types", reason.typeReference);
123946
- message = Diagnostics.File_is_entry_point_of_type_library_specified_here;
123947
- break;
123948
- case 6 /* LibFile */:
123949
- if (reason.index !== void 0) {
123950
- configFileNode = getOptionsSyntaxByArrayElementValue("lib", options.lib[reason.index]);
123951
- message = Diagnostics.File_is_library_specified_here;
123952
- break;
123953
- }
123954
- const target = getNameOfScriptTarget(getEmitScriptTarget(options));
123955
- configFileNode = target ? getOptionsSyntaxByValue("target", target) : void 0;
123956
- message = Diagnostics.File_is_default_library_for_target_specified_here;
123957
- break;
123958
- default:
123959
- Debug.assertNever(reason);
123960
- }
123961
- return configFileNode && createDiagnosticForNodeInSourceFile(
123962
- options.configFile,
123963
- configFileNode,
123964
- message
123965
- );
123966
- }
123967
123834
  function verifyProjectReferences() {
123968
123835
  const buildInfoPath = !options.suppressOutputPathCheck ? getTsBuildInfoEmitOutputFilePath(options) : void 0;
123969
123836
  forEachProjectReference(
@@ -123999,7 +123866,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
123999
123866
  forEachPropertyAssignment(pathProp.initializer, key, (keyProps) => {
124000
123867
  const initializer = keyProps.initializer;
124001
123868
  if (isArrayLiteralExpression(initializer) && initializer.elements.length > valueIndex) {
124002
- programDiagnostics.add(createDiagnosticForNodeInSourceFile(options.configFile, initializer.elements[valueIndex], message, ...args));
123869
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeInSourceFile(options.configFile, initializer.elements[valueIndex], message, ...args));
124003
123870
  needCompilerDiagnostic = false;
124004
123871
  }
124005
123872
  });
@@ -124028,18 +123895,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124028
123895
  createCompilerOptionsDiagnostic(message, ...args);
124029
123896
  }
124030
123897
  }
124031
- function forEachOptionsSyntaxByName(name, callback) {
124032
- return forEachPropertyAssignment(getCompilerOptionsObjectLiteralSyntax(), name, callback);
124033
- }
124034
123898
  function forEachOptionPathsSyntax(callback) {
124035
- return forEachOptionsSyntaxByName("paths", callback);
124036
- }
124037
- function getOptionsSyntaxByValue(name, value) {
124038
- return forEachOptionsSyntaxByName(name, (property) => isStringLiteral(property.initializer) && property.initializer.text === value ? property.initializer : void 0);
124039
- }
124040
- function getOptionsSyntaxByArrayElementValue(name, value) {
124041
- const compilerOptionsObjectLiteralSyntax = getCompilerOptionsObjectLiteralSyntax();
124042
- return compilerOptionsObjectLiteralSyntax && getPropertyArrayElementValue(compilerOptionsObjectLiteralSyntax, name, value);
123899
+ return forEachOptionsSyntaxByName(getCompilerOptionsObjectLiteralSyntax(), "paths", callback);
124043
123900
  }
124044
123901
  function createDiagnosticForOptionName(message, option1, option2, option3) {
124045
123902
  createDiagnosticForOption(
@@ -124067,9 +123924,9 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124067
123924
  function createDiagnosticForReference(sourceFile, index, message, ...args) {
124068
123925
  const referencesSyntax = forEachTsConfigPropArray(sourceFile || options.configFile, "references", (property) => isArrayLiteralExpression(property.initializer) ? property.initializer : void 0);
124069
123926
  if (referencesSyntax && referencesSyntax.elements.length > index) {
124070
- programDiagnostics.add(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile, referencesSyntax.elements[index], message, ...args));
123927
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile, referencesSyntax.elements[index], message, ...args));
124071
123928
  } else {
124072
- programDiagnostics.add(createCompilerDiagnostic(message, ...args));
123929
+ programDiagnostics.addConfigDiagnostic(createCompilerDiagnostic(message, ...args));
124073
123930
  }
124074
123931
  }
124075
123932
  function createDiagnosticForOption(onKey, option1, option2, message, ...args) {
@@ -124083,14 +123940,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124083
123940
  const compilerOptionsProperty = getCompilerOptionsPropertySyntax();
124084
123941
  if (compilerOptionsProperty) {
124085
123942
  if ("messageText" in message) {
124086
- programDiagnostics.add(createDiagnosticForNodeFromMessageChain(options.configFile, compilerOptionsProperty.name, message));
123943
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeFromMessageChain(options.configFile, compilerOptionsProperty.name, message));
124087
123944
  } else {
124088
- programDiagnostics.add(createDiagnosticForNodeInSourceFile(options.configFile, compilerOptionsProperty.name, message, ...args));
123945
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeInSourceFile(options.configFile, compilerOptionsProperty.name, message, ...args));
124089
123946
  }
124090
123947
  } else if ("messageText" in message) {
124091
- programDiagnostics.add(createCompilerDiagnosticFromMessageChain(message));
123948
+ programDiagnostics.addConfigDiagnostic(createCompilerDiagnosticFromMessageChain(message));
124092
123949
  } else {
124093
- programDiagnostics.add(createCompilerDiagnostic(message, ...args));
123950
+ programDiagnostics.addConfigDiagnostic(createCompilerDiagnostic(message, ...args));
124094
123951
  }
124095
123952
  }
124096
123953
  function getCompilerOptionsObjectLiteralSyntax() {
@@ -124114,9 +123971,9 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124114
123971
  let needsCompilerDiagnostic = false;
124115
123972
  forEachPropertyAssignment(objectLiteral, key1, (prop) => {
124116
123973
  if ("messageText" in message) {
124117
- programDiagnostics.add(createDiagnosticForNodeFromMessageChain(options.configFile, onKey ? prop.name : prop.initializer, message));
123974
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeFromMessageChain(options.configFile, onKey ? prop.name : prop.initializer, message));
124118
123975
  } else {
124119
- programDiagnostics.add(createDiagnosticForNodeInSourceFile(options.configFile, onKey ? prop.name : prop.initializer, message, ...args));
123976
+ programDiagnostics.addConfigDiagnostic(createDiagnosticForNodeInSourceFile(options.configFile, onKey ? prop.name : prop.initializer, message, ...args));
124120
123977
  }
124121
123978
  needsCompilerDiagnostic = true;
124122
123979
  }, key2);
@@ -124124,7 +123981,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124124
123981
  }
124125
123982
  function blockEmittingOfFile(emitFileName, diag2) {
124126
123983
  hasEmitBlockingDiagnostics.set(toPath3(emitFileName), true);
124127
- programDiagnostics.add(diag2);
123984
+ programDiagnostics.addConfigDiagnostic(diag2);
124128
123985
  }
124129
123986
  function isEmittedFile(file) {
124130
123987
  if (options.noEmit) {
@@ -124447,6 +124304,293 @@ function getModuleNameStringLiteralAt({ imports, moduleAugmentations }, index) {
124447
124304
  Debug.fail("should never ask for module name at index higher than possible module name");
124448
124305
  }
124449
124306
 
124307
+ // src/compiler/programDiagnostics.ts
124308
+ function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax) {
124309
+ let computedDiagnostics;
124310
+ let fileReasons = createMultiMap();
124311
+ let fileProcessingDiagnostics;
124312
+ let commonSourceDirectory;
124313
+ let configDiagnostics;
124314
+ let lazyConfigDiagnostics;
124315
+ let fileReasonsToChain;
124316
+ let reasonToRelatedInfo;
124317
+ return {
124318
+ addConfigDiagnostic(diag2) {
124319
+ Debug.assert(computedDiagnostics === void 0, "Cannot modify program diagnostic state after requesting combined diagnostics");
124320
+ (configDiagnostics ?? (configDiagnostics = createDiagnosticCollection())).add(diag2);
124321
+ },
124322
+ addLazyConfigDiagnostic(file, message, ...args) {
124323
+ Debug.assert(computedDiagnostics === void 0, "Cannot modify program diagnostic state after requesting combined diagnostics");
124324
+ (lazyConfigDiagnostics ?? (lazyConfigDiagnostics = [])).push({ file, diagnostic: message, args });
124325
+ },
124326
+ addFileProcessingDiagnostic(diag2) {
124327
+ Debug.assert(computedDiagnostics === void 0, "Cannot modify program diagnostic state after requesting combined diagnostics");
124328
+ (fileProcessingDiagnostics ?? (fileProcessingDiagnostics = [])).push(diag2);
124329
+ },
124330
+ setCommonSourceDirectory(directory) {
124331
+ commonSourceDirectory = directory;
124332
+ },
124333
+ reuseStateFromOldProgram(oldProgramDiagnostics, isConfigIdentical) {
124334
+ fileReasons = oldProgramDiagnostics.getFileReasons();
124335
+ fileProcessingDiagnostics = oldProgramDiagnostics.getFileProcessingDiagnostics();
124336
+ if (isConfigIdentical) {
124337
+ commonSourceDirectory = oldProgramDiagnostics.getCommonSourceDirectory();
124338
+ configDiagnostics = oldProgramDiagnostics.getConfigDiagnostics();
124339
+ lazyConfigDiagnostics = oldProgramDiagnostics.getLazyConfigDiagnostics();
124340
+ }
124341
+ },
124342
+ getFileProcessingDiagnostics() {
124343
+ return fileProcessingDiagnostics;
124344
+ },
124345
+ getFileReasons() {
124346
+ return fileReasons;
124347
+ },
124348
+ getCommonSourceDirectory() {
124349
+ return commonSourceDirectory;
124350
+ },
124351
+ getConfigDiagnostics() {
124352
+ return configDiagnostics;
124353
+ },
124354
+ getLazyConfigDiagnostics() {
124355
+ return lazyConfigDiagnostics;
124356
+ },
124357
+ getCombinedDiagnostics(program) {
124358
+ if (computedDiagnostics) {
124359
+ return computedDiagnostics;
124360
+ }
124361
+ computedDiagnostics = createDiagnosticCollection();
124362
+ configDiagnostics == null ? void 0 : configDiagnostics.getDiagnostics().forEach((d) => computedDiagnostics.add(d));
124363
+ fileProcessingDiagnostics == null ? void 0 : fileProcessingDiagnostics.forEach((diagnostic) => {
124364
+ switch (diagnostic.kind) {
124365
+ case 1 /* FilePreprocessingFileExplainingDiagnostic */:
124366
+ return computedDiagnostics.add(
124367
+ createDiagnosticExplainingFile(
124368
+ program,
124369
+ diagnostic.file && program.getSourceFileByPath(diagnostic.file),
124370
+ diagnostic.fileProcessingReason,
124371
+ diagnostic.diagnostic,
124372
+ diagnostic.args || emptyArray
124373
+ )
124374
+ );
124375
+ case 0 /* FilePreprocessingLibReferenceDiagnostic */:
124376
+ return computedDiagnostics.add(filePreprocessingLibreferenceDiagnostic(program, diagnostic));
124377
+ case 2 /* ResolutionDiagnostics */:
124378
+ return diagnostic.diagnostics.forEach((d) => computedDiagnostics.add(d));
124379
+ default:
124380
+ Debug.assertNever(diagnostic);
124381
+ }
124382
+ });
124383
+ lazyConfigDiagnostics == null ? void 0 : lazyConfigDiagnostics.forEach(
124384
+ ({ file, diagnostic, args }) => computedDiagnostics.add(
124385
+ createDiagnosticExplainingFile(
124386
+ program,
124387
+ file,
124388
+ /*fileProcessingReason*/
124389
+ void 0,
124390
+ diagnostic,
124391
+ args
124392
+ )
124393
+ )
124394
+ );
124395
+ fileReasonsToChain = void 0;
124396
+ reasonToRelatedInfo = void 0;
124397
+ return computedDiagnostics;
124398
+ }
124399
+ };
124400
+ function filePreprocessingLibreferenceDiagnostic(program, { reason }) {
124401
+ const { file, pos, end } = getReferencedFileLocation(program, reason);
124402
+ const libReference = file.libReferenceDirectives[reason.index];
124403
+ const libName = getLibNameFromLibReference(libReference);
124404
+ const unqualifiedLibName = removeSuffix(removePrefix(libName, "lib."), ".d.ts");
124405
+ const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity);
124406
+ return createFileDiagnostic(
124407
+ file,
124408
+ Debug.checkDefined(pos),
124409
+ Debug.checkDefined(end) - pos,
124410
+ suggestion ? Diagnostics.Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics.Cannot_find_lib_definition_for_0,
124411
+ libName,
124412
+ suggestion
124413
+ );
124414
+ }
124415
+ function createDiagnosticExplainingFile(program, file, fileProcessingReason, diagnostic, args) {
124416
+ let seenReasons;
124417
+ let fileIncludeReasons;
124418
+ let relatedInfo;
124419
+ let fileIncludeReasonDetails;
124420
+ let redirectInfo;
124421
+ let chain;
124422
+ const reasons = file && fileReasons.get(file.path);
124423
+ let locationReason = isReferencedFile(fileProcessingReason) ? fileProcessingReason : void 0;
124424
+ let cachedChain = file && (fileReasonsToChain == null ? void 0 : fileReasonsToChain.get(file.path));
124425
+ if (cachedChain) {
124426
+ if (cachedChain.fileIncludeReasonDetails) {
124427
+ seenReasons = new Set(reasons);
124428
+ reasons == null ? void 0 : reasons.forEach(populateRelatedInfo);
124429
+ } else {
124430
+ reasons == null ? void 0 : reasons.forEach(processReason);
124431
+ }
124432
+ redirectInfo = cachedChain.redirectInfo;
124433
+ } else {
124434
+ reasons == null ? void 0 : reasons.forEach(processReason);
124435
+ redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file));
124436
+ }
124437
+ if (fileProcessingReason) processReason(fileProcessingReason);
124438
+ const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length);
124439
+ if (locationReason && (seenReasons == null ? void 0 : seenReasons.size) === 1) seenReasons = void 0;
124440
+ if (seenReasons && cachedChain) {
124441
+ if (cachedChain.details && !processedExtraReason) {
124442
+ chain = chainDiagnosticMessages(cachedChain.details, diagnostic, ...args ?? emptyArray);
124443
+ } else if (cachedChain.fileIncludeReasonDetails) {
124444
+ if (!processedExtraReason) {
124445
+ if (!cachedFileIncludeDetailsHasProcessedExtraReason()) {
124446
+ fileIncludeReasonDetails = cachedChain.fileIncludeReasonDetails;
124447
+ } else {
124448
+ fileIncludeReasons = cachedChain.fileIncludeReasonDetails.next.slice(0, reasons.length);
124449
+ }
124450
+ } else {
124451
+ if (!cachedFileIncludeDetailsHasProcessedExtraReason()) {
124452
+ fileIncludeReasons = [...cachedChain.fileIncludeReasonDetails.next, fileIncludeReasons[0]];
124453
+ } else {
124454
+ fileIncludeReasons = append(cachedChain.fileIncludeReasonDetails.next.slice(0, reasons.length), fileIncludeReasons[0]);
124455
+ }
124456
+ }
124457
+ }
124458
+ }
124459
+ if (!chain) {
124460
+ if (!fileIncludeReasonDetails) fileIncludeReasonDetails = seenReasons && chainDiagnosticMessages(fileIncludeReasons, Diagnostics.The_file_is_in_the_program_because_Colon);
124461
+ chain = chainDiagnosticMessages(
124462
+ redirectInfo ? fileIncludeReasonDetails ? [fileIncludeReasonDetails, ...redirectInfo] : redirectInfo : fileIncludeReasonDetails,
124463
+ diagnostic,
124464
+ ...args || emptyArray
124465
+ );
124466
+ }
124467
+ if (file) {
124468
+ if (cachedChain) {
124469
+ if (!cachedChain.fileIncludeReasonDetails || !processedExtraReason && fileIncludeReasonDetails) {
124470
+ cachedChain.fileIncludeReasonDetails = fileIncludeReasonDetails;
124471
+ }
124472
+ } else {
124473
+ (fileReasonsToChain ?? (fileReasonsToChain = /* @__PURE__ */ new Map())).set(file.path, cachedChain = { fileIncludeReasonDetails, redirectInfo });
124474
+ }
124475
+ if (!cachedChain.details && !processedExtraReason) cachedChain.details = chain.next;
124476
+ }
124477
+ const location = locationReason && getReferencedFileLocation(program, locationReason);
124478
+ return location && isReferenceFileLocation(location) ? createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) : createCompilerDiagnosticFromMessageChain(chain, relatedInfo);
124479
+ function processReason(reason) {
124480
+ if (seenReasons == null ? void 0 : seenReasons.has(reason)) return;
124481
+ (seenReasons ?? (seenReasons = /* @__PURE__ */ new Set())).add(reason);
124482
+ (fileIncludeReasons ?? (fileIncludeReasons = [])).push(fileIncludeReasonToDiagnostics(program, reason));
124483
+ populateRelatedInfo(reason);
124484
+ }
124485
+ function populateRelatedInfo(reason) {
124486
+ if (!locationReason && isReferencedFile(reason)) {
124487
+ locationReason = reason;
124488
+ } else if (locationReason !== reason) {
124489
+ relatedInfo = append(relatedInfo, getFileIncludeReasonToRelatedInformation(program, reason));
124490
+ }
124491
+ }
124492
+ function cachedFileIncludeDetailsHasProcessedExtraReason() {
124493
+ var _a;
124494
+ return ((_a = cachedChain.fileIncludeReasonDetails.next) == null ? void 0 : _a.length) !== (reasons == null ? void 0 : reasons.length);
124495
+ }
124496
+ }
124497
+ function getFileIncludeReasonToRelatedInformation(program, reason) {
124498
+ let relatedInfo = reasonToRelatedInfo == null ? void 0 : reasonToRelatedInfo.get(reason);
124499
+ if (relatedInfo === void 0) (reasonToRelatedInfo ?? (reasonToRelatedInfo = /* @__PURE__ */ new Map())).set(reason, relatedInfo = fileIncludeReasonToRelatedInformation(program, reason) ?? false);
124500
+ return relatedInfo || void 0;
124501
+ }
124502
+ function fileIncludeReasonToRelatedInformation(program, reason) {
124503
+ if (isReferencedFile(reason)) {
124504
+ const referenceLocation = getReferencedFileLocation(program, reason);
124505
+ let message2;
124506
+ switch (reason.kind) {
124507
+ case 3 /* Import */:
124508
+ message2 = Diagnostics.File_is_included_via_import_here;
124509
+ break;
124510
+ case 4 /* ReferenceFile */:
124511
+ message2 = Diagnostics.File_is_included_via_reference_here;
124512
+ break;
124513
+ case 5 /* TypeReferenceDirective */:
124514
+ message2 = Diagnostics.File_is_included_via_type_library_reference_here;
124515
+ break;
124516
+ case 7 /* LibReferenceDirective */:
124517
+ message2 = Diagnostics.File_is_included_via_library_reference_here;
124518
+ break;
124519
+ default:
124520
+ Debug.assertNever(reason);
124521
+ }
124522
+ return isReferenceFileLocation(referenceLocation) ? createFileDiagnostic(
124523
+ referenceLocation.file,
124524
+ referenceLocation.pos,
124525
+ referenceLocation.end - referenceLocation.pos,
124526
+ message2
124527
+ ) : void 0;
124528
+ }
124529
+ const currentDirectory = program.getCurrentDirectory();
124530
+ const rootNames = program.getRootFileNames();
124531
+ const options = program.getCompilerOptions();
124532
+ if (!options.configFile) return void 0;
124533
+ let configFileNode;
124534
+ let message;
124535
+ switch (reason.kind) {
124536
+ case 0 /* RootFile */:
124537
+ if (!options.configFile.configFileSpecs) return void 0;
124538
+ const fileName = getNormalizedAbsolutePath(rootNames[reason.index], currentDirectory);
124539
+ const matchedByFiles = getMatchedFileSpec(program, fileName);
124540
+ if (matchedByFiles) {
124541
+ configFileNode = getTsConfigPropArrayElementValue(options.configFile, "files", matchedByFiles);
124542
+ message = Diagnostics.File_is_matched_by_files_list_specified_here;
124543
+ break;
124544
+ }
124545
+ const matchedByInclude = getMatchedIncludeSpec(program, fileName);
124546
+ if (!matchedByInclude || !isString(matchedByInclude)) return void 0;
124547
+ configFileNode = getTsConfigPropArrayElementValue(options.configFile, "include", matchedByInclude);
124548
+ message = Diagnostics.File_is_matched_by_include_pattern_specified_here;
124549
+ break;
124550
+ case 1 /* SourceFromProjectReference */:
124551
+ case 2 /* OutputFromProjectReference */:
124552
+ const resolvedProjectReferences = program.getResolvedProjectReferences();
124553
+ const projectReferences = program.getProjectReferences();
124554
+ const referencedResolvedRef = Debug.checkDefined(resolvedProjectReferences == null ? void 0 : resolvedProjectReferences[reason.index]);
124555
+ const referenceInfo = forEachProjectReference(
124556
+ projectReferences,
124557
+ resolvedProjectReferences,
124558
+ (resolvedRef, parent, index2) => resolvedRef === referencedResolvedRef ? { sourceFile: (parent == null ? void 0 : parent.sourceFile) || options.configFile, index: index2 } : void 0
124559
+ );
124560
+ if (!referenceInfo) return void 0;
124561
+ const { sourceFile, index } = referenceInfo;
124562
+ const referencesSyntax = forEachTsConfigPropArray(sourceFile, "references", (property) => isArrayLiteralExpression(property.initializer) ? property.initializer : void 0);
124563
+ return referencesSyntax && referencesSyntax.elements.length > index ? createDiagnosticForNodeInSourceFile(
124564
+ sourceFile,
124565
+ referencesSyntax.elements[index],
124566
+ reason.kind === 2 /* OutputFromProjectReference */ ? Diagnostics.File_is_output_from_referenced_project_specified_here : Diagnostics.File_is_source_from_referenced_project_specified_here
124567
+ ) : void 0;
124568
+ case 8 /* AutomaticTypeDirectiveFile */:
124569
+ if (!options.types) return void 0;
124570
+ configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference);
124571
+ message = Diagnostics.File_is_entry_point_of_type_library_specified_here;
124572
+ break;
124573
+ case 6 /* LibFile */:
124574
+ if (reason.index !== void 0) {
124575
+ configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "lib", options.lib[reason.index]);
124576
+ message = Diagnostics.File_is_library_specified_here;
124577
+ break;
124578
+ }
124579
+ const target = getNameOfScriptTarget(getEmitScriptTarget(options));
124580
+ configFileNode = target ? getOptionsSyntaxByValue(getCompilerOptionsObjectLiteralSyntax(), "target", target) : void 0;
124581
+ message = Diagnostics.File_is_default_library_for_target_specified_here;
124582
+ break;
124583
+ default:
124584
+ Debug.assertNever(reason);
124585
+ }
124586
+ return configFileNode && createDiagnosticForNodeInSourceFile(
124587
+ options.configFile,
124588
+ configFileNode,
124589
+ message
124590
+ );
124591
+ }
124592
+ }
124593
+
124450
124594
  // src/compiler/builderState.ts
124451
124595
  var BuilderState;
124452
124596
  ((BuilderState2) => {