typescript 5.5.0-dev.20240602 → 5.6.0-dev.20240604

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/typescript.js CHANGED
@@ -2370,8 +2370,8 @@ __export(typescript_exports, {
2370
2370
  module.exports = __toCommonJS(typescript_exports);
2371
2371
 
2372
2372
  // src/compiler/corePublic.ts
2373
- var versionMajorMinor = "5.5";
2374
- var version = `${versionMajorMinor}.0-dev.20240602`;
2373
+ var versionMajorMinor = "5.6";
2374
+ var version = `${versionMajorMinor}.0-dev.20240604`;
2375
2375
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2376
2376
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2377
2377
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -56313,10 +56313,11 @@ function createTypeChecker(host) {
56313
56313
  return result ? setTextRange2(context, result, node) : void 0;
56314
56314
  }
56315
56315
  function createRecoveryBoundary() {
56316
+ let trackedSymbols;
56316
56317
  let unreportedErrors;
56317
56318
  const oldTracker = context.tracker;
56318
56319
  const oldTrackedSymbols = context.trackedSymbols;
56319
- context.trackedSymbols = [];
56320
+ context.trackedSymbols = void 0;
56320
56321
  const oldEncounteredError = context.encounteredError;
56321
56322
  context.tracker = new SymbolTrackerImpl(context, {
56322
56323
  ...oldTracker.inner,
@@ -56336,17 +56337,7 @@ function createTypeChecker(host) {
56336
56337
  markError(() => oldTracker.reportNonSerializableProperty(name));
56337
56338
  },
56338
56339
  trackSymbol(sym, decl, meaning) {
56339
- const accessibility = isSymbolAccessible(
56340
- sym,
56341
- decl,
56342
- meaning,
56343
- /*shouldComputeAliasesToMakeVisible*/
56344
- false
56345
- );
56346
- if (accessibility.accessibility !== 0 /* Accessible */) {
56347
- (context.trackedSymbols ?? (context.trackedSymbols = [])).push([sym, decl, meaning]);
56348
- return true;
56349
- }
56340
+ (trackedSymbols ?? (trackedSymbols = [])).push([sym, decl, meaning]);
56350
56341
  return false;
56351
56342
  },
56352
56343
  moduleResolverHost: context.tracker.moduleResolverHost
@@ -56360,13 +56351,12 @@ function createTypeChecker(host) {
56360
56351
  (unreportedErrors ?? (unreportedErrors = [])).push(unreportedError);
56361
56352
  }
56362
56353
  function startRecoveryScope2() {
56363
- var _a;
56364
- const initialTrackedSymbolsTop = ((_a = context.trackedSymbols) == null ? void 0 : _a.length) ?? 0;
56354
+ const trackedSymbolsTop = (trackedSymbols == null ? void 0 : trackedSymbols.length) ?? 0;
56365
56355
  const unreportedErrorsTop = (unreportedErrors == null ? void 0 : unreportedErrors.length) ?? 0;
56366
56356
  return () => {
56367
56357
  hadError = false;
56368
- if (context.trackedSymbols) {
56369
- context.trackedSymbols.length = initialTrackedSymbolsTop;
56358
+ if (trackedSymbols) {
56359
+ trackedSymbols.length = trackedSymbolsTop;
56370
56360
  }
56371
56361
  if (unreportedErrors) {
56372
56362
  unreportedErrors.length = unreportedErrorsTop;
@@ -56375,14 +56365,13 @@ function createTypeChecker(host) {
56375
56365
  }
56376
56366
  function finalizeBoundary2() {
56377
56367
  context.tracker = oldTracker;
56378
- const newTrackedSymbols = context.trackedSymbols;
56379
56368
  context.trackedSymbols = oldTrackedSymbols;
56380
56369
  context.encounteredError = oldEncounteredError;
56381
56370
  unreportedErrors == null ? void 0 : unreportedErrors.forEach((fn) => fn());
56382
56371
  if (hadError) {
56383
56372
  return false;
56384
56373
  }
56385
- newTrackedSymbols == null ? void 0 : newTrackedSymbols.forEach(
56374
+ trackedSymbols == null ? void 0 : trackedSymbols.forEach(
56386
56375
  ([symbol, enclosingDeclaration, meaning]) => context.tracker.trackSymbol(
56387
56376
  symbol,
56388
56377
  enclosingDeclaration,
@@ -56395,6 +56384,57 @@ function createTypeChecker(host) {
56395
56384
  function onEnterNewScope(node) {
56396
56385
  return enterNewScope(context, node, getParametersInScope(node), getTypeParametersInScope(node));
56397
56386
  }
56387
+ function tryVisitSimpleTypeNode(node) {
56388
+ const innerNode = skipTypeParentheses(node);
56389
+ switch (innerNode.kind) {
56390
+ case 183 /* TypeReference */:
56391
+ return tryVisitTypeReference(innerNode);
56392
+ case 186 /* TypeQuery */:
56393
+ return tryVisitTypeQuery(innerNode);
56394
+ case 199 /* IndexedAccessType */:
56395
+ return tryVisitIndexedAccess(innerNode);
56396
+ case 198 /* TypeOperator */:
56397
+ const typeOperatorNode = innerNode;
56398
+ if (typeOperatorNode.operator === 143 /* KeyOfKeyword */) {
56399
+ return tryVisitKeyOf(typeOperatorNode);
56400
+ }
56401
+ }
56402
+ return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
56403
+ }
56404
+ function tryVisitIndexedAccess(node) {
56405
+ const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
56406
+ if (resultObjectType === void 0) {
56407
+ return void 0;
56408
+ }
56409
+ return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
56410
+ }
56411
+ function tryVisitKeyOf(node) {
56412
+ Debug.assertEqual(node.operator, 143 /* KeyOfKeyword */);
56413
+ const type = tryVisitSimpleTypeNode(node.type);
56414
+ if (type === void 0) {
56415
+ return void 0;
56416
+ }
56417
+ return factory.updateTypeOperatorNode(node, type);
56418
+ }
56419
+ function tryVisitTypeQuery(node) {
56420
+ const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
56421
+ if (!introducesError) {
56422
+ return factory.updateTypeQueryNode(
56423
+ node,
56424
+ exprName,
56425
+ visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
56426
+ );
56427
+ }
56428
+ const serializedName = serializeTypeName(
56429
+ context,
56430
+ node.exprName,
56431
+ /*isTypeOf*/
56432
+ true
56433
+ );
56434
+ if (serializedName) {
56435
+ return setTextRange2(context, serializedName, node.exprName);
56436
+ }
56437
+ }
56398
56438
  function tryVisitTypeReference(node) {
56399
56439
  if (canReuseTypeNode(context, node)) {
56400
56440
  const { introducesError, node: newName } = trackExistingEntityName(node.typeName, context);
@@ -56528,13 +56568,13 @@ function createTypeChecker(host) {
56528
56568
  visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode)
56529
56569
  );
56530
56570
  }
56531
- if (isIndexedAccessTypeNode(node) && isTypeReferenceNode(node.objectType)) {
56532
- const objectType = tryVisitTypeReference(node.objectType);
56533
- if (!objectType) {
56571
+ if (isIndexedAccessTypeNode(node)) {
56572
+ const result = tryVisitIndexedAccess(node);
56573
+ if (!result) {
56534
56574
  hadError = true;
56535
56575
  return node;
56536
56576
  }
56537
- return factory.updateIndexedAccessTypeNode(node, objectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
56577
+ return result;
56538
56578
  }
56539
56579
  if (isTypeReferenceNode(node)) {
56540
56580
  const result = tryVisitTypeReference(node);
@@ -56577,25 +56617,12 @@ function createTypeChecker(host) {
56577
56617
  return visited;
56578
56618
  }
56579
56619
  if (isTypeQueryNode(node)) {
56580
- const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
56581
- if (introducesError) {
56582
- const serializedName = serializeTypeName(
56583
- context,
56584
- node.exprName,
56585
- /*isTypeOf*/
56586
- true
56587
- );
56588
- if (serializedName) {
56589
- return setTextRange2(context, serializedName, node.exprName);
56590
- }
56620
+ const result = tryVisitTypeQuery(node);
56621
+ if (!result) {
56591
56622
  hadError = true;
56592
56623
  return node;
56593
56624
  }
56594
- return factory.updateTypeQueryNode(
56595
- node,
56596
- exprName,
56597
- visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
56598
- );
56625
+ return result;
56599
56626
  }
56600
56627
  if (isComputedPropertyName(node) && isEntityNameExpression(node.expression)) {
56601
56628
  const { node: result, introducesError } = trackExistingEntityName(node.expression, context);
@@ -56660,14 +56687,12 @@ function createTypeChecker(host) {
56660
56687
  return node;
56661
56688
  }
56662
56689
  } else if (node.operator === 143 /* KeyOfKeyword */) {
56663
- if (isTypeReferenceNode(node.type)) {
56664
- const type = tryVisitTypeReference(node.type);
56665
- if (!type) {
56666
- hadError = true;
56667
- return node;
56668
- }
56669
- return factory.updateTypeOperatorNode(node, type);
56690
+ const result = tryVisitKeyOf(node);
56691
+ if (!result) {
56692
+ hadError = true;
56693
+ return node;
56670
56694
  }
56695
+ return result;
56671
56696
  }
56672
56697
  }
56673
56698
  return visitEachChild2(node, visitExistingNodeTreeSymbols);
@@ -117717,16 +117742,16 @@ function isBuildInfoFile(file) {
117717
117742
  function forEachEmittedFile(host, action, sourceFilesOrTargetSourceFile, forceDtsEmit = false, onlyBuildInfo, includeBuildInfo) {
117718
117743
  const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile, forceDtsEmit);
117719
117744
  const options = host.getCompilerOptions();
117720
- if (options.outFile) {
117721
- if (sourceFiles.length) {
117722
- const bundle = factory.createBundle(sourceFiles);
117723
- const result = action(getOutputPathsFor(bundle, host, forceDtsEmit), bundle);
117724
- if (result) {
117725
- return result;
117745
+ if (!onlyBuildInfo) {
117746
+ if (options.outFile) {
117747
+ if (sourceFiles.length) {
117748
+ const bundle = factory.createBundle(sourceFiles);
117749
+ const result = action(getOutputPathsFor(bundle, host, forceDtsEmit), bundle);
117750
+ if (result) {
117751
+ return result;
117752
+ }
117726
117753
  }
117727
- }
117728
- } else {
117729
- if (!onlyBuildInfo) {
117754
+ } else {
117730
117755
  for (const sourceFile of sourceFiles) {
117731
117756
  const result = action(getOutputPathsFor(sourceFile, host, forceDtsEmit), sourceFile);
117732
117757
  if (result) {
@@ -117734,14 +117759,14 @@ function forEachEmittedFile(host, action, sourceFilesOrTargetSourceFile, forceDt
117734
117759
  }
117735
117760
  }
117736
117761
  }
117737
- if (includeBuildInfo) {
117738
- const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
117739
- if (buildInfoPath) return action(
117740
- { buildInfoPath },
117741
- /*sourceFileOrBundle*/
117742
- void 0
117743
- );
117744
- }
117762
+ }
117763
+ if (includeBuildInfo) {
117764
+ const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
117765
+ if (buildInfoPath) return action(
117766
+ { buildInfoPath },
117767
+ /*sourceFileOrBundle*/
117768
+ void 0
117769
+ );
117745
117770
  }
117746
117771
  }
117747
117772
  function getTsBuildInfoEmitOutputFilePath(options) {
@@ -117770,8 +117795,7 @@ function getOutputPathsForBundle(options, forceDtsPaths) {
117770
117795
  const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
117771
117796
  const declarationFilePath = forceDtsPaths || getEmitDeclarations(options) ? removeFileExtension(outPath) + ".d.ts" /* Dts */ : void 0;
117772
117797
  const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : void 0;
117773
- const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
117774
- return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath };
117798
+ return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath };
117775
117799
  }
117776
117800
  function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
117777
117801
  const options = host.getCompilerOptions();
@@ -117785,7 +117809,7 @@ function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
117785
117809
  const sourceMapFilePath = !jsFilePath || isJsonSourceFile(sourceFile) ? void 0 : getSourceMapFilePath(jsFilePath, options);
117786
117810
  const declarationFilePath = forceDtsPaths || getEmitDeclarations(options) && !isJsonFile ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : void 0;
117787
117811
  const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : void 0;
117788
- return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath: void 0 };
117812
+ return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath };
117789
117813
  }
117790
117814
  }
117791
117815
  function getSourceMapFilePath(jsFilePath, options) {
@@ -117834,7 +117858,7 @@ function createAddOutput() {
117834
117858
  }
117835
117859
  }
117836
117860
  function getSingleOutputFileNames(configFile, addOutput) {
117837
- const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(
117861
+ const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(
117838
117862
  configFile.options,
117839
117863
  /*forceDtsPaths*/
117840
117864
  false
@@ -117843,7 +117867,6 @@ function getSingleOutputFileNames(configFile, addOutput) {
117843
117867
  addOutput(sourceMapFilePath);
117844
117868
  addOutput(declarationFilePath);
117845
117869
  addOutput(declarationMapPath);
117846
- addOutput(buildInfoPath);
117847
117870
  }
117848
117871
  function getOwnOutputFileNames(configFile, inputFileName, ignoreCase, addOutput, getCommonSourceDirectory2) {
117849
117872
  if (isDeclarationFileName(inputFileName)) return;
@@ -117894,8 +117917,8 @@ function getAllProjectOutputs(configFile, ignoreCase) {
117894
117917
  for (const inputFileName of configFile.fileNames) {
117895
117918
  getOwnOutputFileNames(configFile, inputFileName, ignoreCase, addOutput, getCommonSourceDirectory2);
117896
117919
  }
117897
- addOutput(getTsBuildInfoEmitOutputFilePath(configFile.options));
117898
117920
  }
117921
+ addOutput(getTsBuildInfoEmitOutputFilePath(configFile.options));
117899
117922
  return getOutputs();
117900
117923
  }
117901
117924
  function getOutputFileNames(commandLine, inputFileName, ignoreCase) {
@@ -117935,7 +117958,7 @@ function getFirstProjectOutput(configFile, ignoreCase) {
117935
117958
  function emitResolverSkipsTypeChecking(emitOnly, forceDtsEmit) {
117936
117959
  return !!forceDtsEmit && !!emitOnly;
117937
117960
  }
117938
- function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, declarationTransformers }, emitOnly, onlyBuildInfo, forceDtsEmit) {
117961
+ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, declarationTransformers }, emitOnly, onlyBuildInfo, forceDtsEmit, skipBuildInfo) {
117939
117962
  var compilerOptions = host.getCompilerOptions();
117940
117963
  var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions) ? [] : void 0;
117941
117964
  var emittedFilesList = compilerOptions.listEmittedFiles ? [] : void 0;
@@ -117951,7 +117974,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
117951
117974
  getSourceFilesToEmit(host, targetSourceFile, forceDtsEmit),
117952
117975
  forceDtsEmit,
117953
117976
  onlyBuildInfo,
117954
- !targetSourceFile
117977
+ !targetSourceFile && !skipBuildInfo
117955
117978
  );
117956
117979
  exit();
117957
117980
  return {
@@ -117973,7 +117996,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
117973
117996
  (_f = tracing) == null ? void 0 : _f.pop();
117974
117997
  }
117975
117998
  function emitBuildInfo(buildInfoPath) {
117976
- if (!buildInfoPath || targetSourceFile || emitSkipped) return;
117999
+ if (!buildInfoPath || targetSourceFile) return;
117977
118000
  if (host.isEmitBlocked(buildInfoPath)) {
117978
118001
  emitSkipped = true;
117979
118002
  return;
@@ -124972,7 +124995,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
124972
124995
  }
124973
124996
  function emitBuildInfo(writeFileCallback) {
124974
124997
  var _a2, _b2;
124975
- Debug.assert(!options.outFile);
124976
124998
  (_a2 = tracing) == null ? void 0 : _a2.push(
124977
124999
  tracing.Phase.Emit,
124978
125000
  "emitBuildInfo",
@@ -125027,7 +125049,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
125027
125049
  function getTypeChecker() {
125028
125050
  return typeChecker || (typeChecker = createTypeChecker(program));
125029
125051
  }
125030
- function emit(sourceFile, writeFileCallback, cancellationToken, emitOnly, transformers, forceDtsEmit) {
125052
+ function emit(sourceFile, writeFileCallback, cancellationToken, emitOnly, transformers, forceDtsEmit, skipBuildInfo) {
125031
125053
  var _a2, _b2;
125032
125054
  (_a2 = tracing) == null ? void 0 : _a2.push(
125033
125055
  tracing.Phase.Emit,
@@ -125036,14 +125058,25 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
125036
125058
  /*separateBeginAndEnd*/
125037
125059
  true
125038
125060
  );
125039
- const result = runWithCancellationToken(() => emitWorker(program, sourceFile, writeFileCallback, cancellationToken, emitOnly, transformers, forceDtsEmit));
125061
+ const result = runWithCancellationToken(
125062
+ () => emitWorker(
125063
+ program,
125064
+ sourceFile,
125065
+ writeFileCallback,
125066
+ cancellationToken,
125067
+ emitOnly,
125068
+ transformers,
125069
+ forceDtsEmit,
125070
+ skipBuildInfo
125071
+ )
125072
+ );
125040
125073
  (_b2 = tracing) == null ? void 0 : _b2.pop();
125041
125074
  return result;
125042
125075
  }
125043
125076
  function isEmitBlocked(emitFileName) {
125044
125077
  return hasEmitBlockingDiagnostics.has(toPath3(emitFileName));
125045
125078
  }
125046
- function emitWorker(program2, sourceFile, writeFileCallback, cancellationToken, emitOnly, customTransformers, forceDtsEmit) {
125079
+ function emitWorker(program2, sourceFile, writeFileCallback, cancellationToken, emitOnly, customTransformers, forceDtsEmit, skipBuildInfo) {
125047
125080
  if (!forceDtsEmit) {
125048
125081
  const result = handleNoEmitOptions(program2, sourceFile, writeFileCallback, cancellationToken);
125049
125082
  if (result) return result;
@@ -125065,7 +125098,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
125065
125098
  emitOnly,
125066
125099
  /*onlyBuildInfo*/
125067
125100
  false,
125068
- forceDtsEmit
125101
+ forceDtsEmit,
125102
+ skipBuildInfo
125069
125103
  )
125070
125104
  );
125071
125105
  mark("afterEmit");
@@ -127197,7 +127231,7 @@ function handleNoEmitOptions(program, sourceFile, writeFile2, cancellationToken)
127197
127231
  const options = program.getCompilerOptions();
127198
127232
  if (options.noEmit) {
127199
127233
  program.getSemanticDiagnostics(sourceFile, cancellationToken);
127200
- return sourceFile || options.outFile ? emitSkippedWithNoDiagnostics : program.emitBuildInfo(writeFile2, cancellationToken);
127234
+ return sourceFile ? emitSkippedWithNoDiagnostics : program.emitBuildInfo(writeFile2, cancellationToken);
127201
127235
  }
127202
127236
  if (!options.noEmitOnError) return void 0;
127203
127237
  let diagnostics = [
@@ -127215,7 +127249,7 @@ function handleNoEmitOptions(program, sourceFile, writeFile2, cancellationToken)
127215
127249
  }
127216
127250
  if (!diagnostics.length) return void 0;
127217
127251
  let emittedFiles;
127218
- if (!sourceFile && !options.outFile) {
127252
+ if (!sourceFile) {
127219
127253
  const emitResult = program.emitBuildInfo(writeFile2, cancellationToken);
127220
127254
  if (emitResult.diagnostics) diagnostics = [...diagnostics, ...emitResult.diagnostics];
127221
127255
  emittedFiles = emitResult.emittedFiles;
@@ -127723,17 +127757,17 @@ function createBuilderProgramState(newProgram, oldState) {
127723
127757
  const compilerOptions = newProgram.getCompilerOptions();
127724
127758
  state.compilerOptions = compilerOptions;
127725
127759
  const outFilePath = compilerOptions.outFile;
127726
- if (!outFilePath) {
127727
- state.semanticDiagnosticsPerFile = /* @__PURE__ */ new Map();
127728
- } else if (compilerOptions.composite && (oldState == null ? void 0 : oldState.outSignature) && outFilePath === oldState.compilerOptions.outFile) {
127760
+ state.semanticDiagnosticsPerFile = /* @__PURE__ */ new Map();
127761
+ if (outFilePath && compilerOptions.composite && (oldState == null ? void 0 : oldState.outSignature) && outFilePath === oldState.compilerOptions.outFile) {
127729
127762
  state.outSignature = oldState.outSignature && getEmitSignatureFromOldSignature(compilerOptions, oldState.compilerOptions, oldState.outSignature);
127730
127763
  }
127731
127764
  state.changedFilesSet = /* @__PURE__ */ new Set();
127732
127765
  state.latestChangedDtsFile = compilerOptions.composite ? oldState == null ? void 0 : oldState.latestChangedDtsFile : void 0;
127733
127766
  const useOldState = BuilderState.canReuseOldState(state.referencedMap, oldState);
127734
127767
  const oldCompilerOptions = useOldState ? oldState.compilerOptions : void 0;
127735
- const canCopySemanticDiagnostics = useOldState && oldState.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile && !compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldCompilerOptions);
127768
+ let canCopySemanticDiagnostics = useOldState && !compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldCompilerOptions);
127736
127769
  const canCopyEmitSignatures = compilerOptions.composite && (oldState == null ? void 0 : oldState.emitSignatures) && !outFilePath && !compilerOptionsAffectDeclarationPath(compilerOptions, oldState.compilerOptions);
127770
+ let canCopyEmitDiagnostics = true;
127737
127771
  if (useOldState) {
127738
127772
  (_a = oldState.changedFilesSet) == null ? void 0 : _a.forEach((value) => state.changedFilesSet.add(value));
127739
127773
  if (!outFilePath && ((_b = oldState.affectedFilesPendingEmit) == null ? void 0 : _b.size)) {
@@ -127741,6 +127775,10 @@ function createBuilderProgramState(newProgram, oldState) {
127741
127775
  state.seenAffectedFiles = /* @__PURE__ */ new Set();
127742
127776
  }
127743
127777
  state.programEmitPending = oldState.programEmitPending;
127778
+ if (outFilePath && state.changedFilesSet.size) {
127779
+ canCopySemanticDiagnostics = false;
127780
+ canCopyEmitDiagnostics = false;
127781
+ }
127744
127782
  } else {
127745
127783
  state.buildInfoEmitPending = true;
127746
127784
  }
@@ -127758,10 +127796,10 @@ function createBuilderProgramState(newProgram, oldState) {
127758
127796
  oldInfo.impliedFormat !== info.impliedFormat || // Referenced files changed
127759
127797
  !hasSameKeys(newReferences = referencedMap && referencedMap.getValues(sourceFilePath), oldReferencedMap && oldReferencedMap.getValues(sourceFilePath)) || // Referenced file was deleted in the new program
127760
127798
  newReferences && forEachKey(newReferences, (path) => !state.fileInfos.has(path) && oldState.fileInfos.has(path))) {
127761
- addFileToChangeSet(state, sourceFilePath);
127799
+ addFileToChangeSet(sourceFilePath);
127762
127800
  } else {
127763
127801
  const sourceFile = newProgram.getSourceFileByPath(sourceFilePath);
127764
- const emitDiagnostics = (_a2 = oldState.emitDiagnosticsPerFile) == null ? void 0 : _a2.get(sourceFilePath);
127802
+ const emitDiagnostics = canCopyEmitDiagnostics ? (_a2 = oldState.emitDiagnosticsPerFile) == null ? void 0 : _a2.get(sourceFilePath) : void 0;
127765
127803
  if (emitDiagnostics) {
127766
127804
  (state.emitDiagnosticsPerFile ?? (state.emitDiagnosticsPerFile = /* @__PURE__ */ new Map())).set(
127767
127805
  sourceFilePath,
@@ -127790,16 +127828,16 @@ function createBuilderProgramState(newProgram, oldState) {
127790
127828
  });
127791
127829
  if (useOldState && forEachEntry(oldState.fileInfos, (info, sourceFilePath) => {
127792
127830
  if (state.fileInfos.has(sourceFilePath)) return false;
127793
- if (outFilePath || info.affectsGlobalScope) return true;
127831
+ if (info.affectsGlobalScope) return true;
127794
127832
  state.buildInfoEmitPending = true;
127795
- return false;
127833
+ return !!outFilePath;
127796
127834
  })) {
127797
127835
  BuilderState.getAllFilesExcludingDefaultLibraryFile(
127798
127836
  state,
127799
127837
  newProgram,
127800
127838
  /*firstSourceFile*/
127801
127839
  void 0
127802
- ).forEach((file) => addFileToChangeSet(state, file.resolvedPath));
127840
+ ).forEach((file) => addFileToChangeSet(file.resolvedPath));
127803
127841
  } else if (oldCompilerOptions) {
127804
127842
  const pendingEmitKind = compilerOptionsAffectEmit(compilerOptions, oldCompilerOptions) ? getBuilderFileEmit(compilerOptions) : getPendingEmitKind(compilerOptions, oldCompilerOptions);
127805
127843
  if (pendingEmitKind !== 0 /* None */) {
@@ -127815,18 +127853,25 @@ function createBuilderProgramState(newProgram, oldState) {
127815
127853
  });
127816
127854
  Debug.assert(!state.seenAffectedFiles || !state.seenAffectedFiles.size);
127817
127855
  state.seenAffectedFiles = state.seenAffectedFiles || /* @__PURE__ */ new Set();
127818
- state.buildInfoEmitPending = true;
127819
- } else {
127856
+ } else if (!state.changedFilesSet.size) {
127820
127857
  state.programEmitPending = state.programEmitPending ? state.programEmitPending | pendingEmitKind : pendingEmitKind;
127821
127858
  }
127859
+ state.buildInfoEmitPending = true;
127822
127860
  }
127823
127861
  }
127824
127862
  return state;
127825
- }
127826
- function addFileToChangeSet(state, path) {
127827
- state.changedFilesSet.add(path);
127828
- state.buildInfoEmitPending = true;
127829
- state.programEmitPending = void 0;
127863
+ function addFileToChangeSet(path) {
127864
+ state.changedFilesSet.add(path);
127865
+ if (outFilePath) {
127866
+ canCopySemanticDiagnostics = false;
127867
+ canCopyEmitDiagnostics = false;
127868
+ state.semanticDiagnosticsFromOldState = void 0;
127869
+ state.semanticDiagnosticsPerFile.clear();
127870
+ state.emitDiagnosticsPerFile = void 0;
127871
+ }
127872
+ state.buildInfoEmitPending = true;
127873
+ state.programEmitPending = void 0;
127874
+ }
127830
127875
  }
127831
127876
  function getEmitSignatureFromOldSignature(options, oldOptions, oldEmitSignature) {
127832
127877
  return !!options.declarationMap === !!oldOptions.declarationMap ? (
@@ -127899,6 +127944,7 @@ function backupBuilderProgramEmitState(state) {
127899
127944
  return {
127900
127945
  affectedFilesPendingEmit: state.affectedFilesPendingEmit && new Map(state.affectedFilesPendingEmit),
127901
127946
  seenEmittedFiles: state.seenEmittedFiles && new Map(state.seenEmittedFiles),
127947
+ seenProgramEmit: state.seenProgramEmit,
127902
127948
  programEmitPending: state.programEmitPending,
127903
127949
  emitSignatures: state.emitSignatures && new Map(state.emitSignatures),
127904
127950
  outSignature: state.outSignature,
@@ -127912,6 +127958,7 @@ function backupBuilderProgramEmitState(state) {
127912
127958
  function restoreBuilderProgramEmitState(state, savedEmitState) {
127913
127959
  state.affectedFilesPendingEmit = savedEmitState.affectedFilesPendingEmit;
127914
127960
  state.seenEmittedFiles = savedEmitState.seenEmittedFiles;
127961
+ state.seenProgramEmit = savedEmitState.seenProgramEmit;
127915
127962
  state.programEmitPending = savedEmitState.programEmitPending;
127916
127963
  state.emitSignatures = savedEmitState.emitSignatures;
127917
127964
  state.outSignature = savedEmitState.outSignature;
@@ -127920,6 +127967,10 @@ function restoreBuilderProgramEmitState(state, savedEmitState) {
127920
127967
  state.buildInfoEmitPending = savedEmitState.buildInfoEmitPending;
127921
127968
  state.emitDiagnosticsPerFile = savedEmitState.emitDiagnosticsPerFile;
127922
127969
  if (savedEmitState.changedFilesSet) state.changedFilesSet = savedEmitState.changedFilesSet;
127970
+ if (state.compilerOptions.outFile && state.changedFilesSet.size) {
127971
+ state.semanticDiagnosticsPerFile.clear();
127972
+ state.emitDiagnosticsPerFile = void 0;
127973
+ }
127923
127974
  }
127924
127975
  function assertSourceFileOkWithoutNextAffectedCall(state, sourceFile) {
127925
127976
  Debug.assert(!sourceFile || !state.affectedFiles || state.affectedFiles[state.affectedFilesIndex - 1] !== sourceFile || !state.semanticDiagnosticsPerFile.has(sourceFile.resolvedPath));
@@ -127957,10 +128008,7 @@ function getNextAffectedFile(state, cancellationToken, host) {
127957
128008
  }
127958
128009
  const program = Debug.checkDefined(state.program);
127959
128010
  const compilerOptions = program.getCompilerOptions();
127960
- if (compilerOptions.outFile) {
127961
- Debug.assert(!state.semanticDiagnosticsPerFile);
127962
- return program;
127963
- }
128011
+ if (compilerOptions.outFile) return program;
127964
128012
  state.affectedFiles = BuilderState.getFilesAffectedByWithOldState(
127965
128013
  state,
127966
128014
  program,
@@ -127974,14 +128022,22 @@ function getNextAffectedFile(state, cancellationToken, host) {
127974
128022
  }
127975
128023
  }
127976
128024
  function clearAffectedFilesPendingEmit(state, emitOnlyDtsFiles) {
127977
- var _a;
127978
- if (!((_a = state.affectedFilesPendingEmit) == null ? void 0 : _a.size)) return;
127979
- if (!emitOnlyDtsFiles) return state.affectedFilesPendingEmit = void 0;
127980
- state.affectedFilesPendingEmit.forEach((emitKind, path) => {
128025
+ var _a, _b;
128026
+ if (!((_a = state.affectedFilesPendingEmit) == null ? void 0 : _a.size) && !state.programEmitPending) return;
128027
+ if (!emitOnlyDtsFiles) {
128028
+ state.affectedFilesPendingEmit = void 0;
128029
+ state.programEmitPending = void 0;
128030
+ }
128031
+ (_b = state.affectedFilesPendingEmit) == null ? void 0 : _b.forEach((emitKind, path) => {
127981
128032
  const pending = emitKind & 7 /* AllJs */;
127982
128033
  if (!pending) state.affectedFilesPendingEmit.delete(path);
127983
128034
  else state.affectedFilesPendingEmit.set(path, pending);
127984
128035
  });
128036
+ if (state.programEmitPending) {
128037
+ const pending = state.programEmitPending & 7 /* AllJs */;
128038
+ if (!pending) state.programEmitPending = void 0;
128039
+ else state.programEmitPending = pending;
128040
+ }
127985
128041
  }
127986
128042
  function getNextAffectedFilePendingEmit(state, emitOnlyDtsFiles) {
127987
128043
  var _a;
@@ -128173,24 +128229,21 @@ function handleDtsMayChangeOfFileAndExportsOfFile(state, filePath, invalidateJsF
128173
128229
  );
128174
128230
  return void 0;
128175
128231
  }
128176
- function getSemanticDiagnosticsOfFile(state, sourceFile, cancellationToken) {
128232
+ function getSemanticDiagnosticsOfFile(state, sourceFile, cancellationToken, semanticDiagnosticsPerFile) {
128177
128233
  return concatenate(
128178
- getBinderAndCheckerDiagnosticsOfFile(state, sourceFile, cancellationToken),
128234
+ getBinderAndCheckerDiagnosticsOfFile(state, sourceFile, cancellationToken, semanticDiagnosticsPerFile),
128179
128235
  Debug.checkDefined(state.program).getProgramDiagnostics(sourceFile)
128180
128236
  );
128181
128237
  }
128182
- function getBinderAndCheckerDiagnosticsOfFile(state, sourceFile, cancellationToken) {
128238
+ function getBinderAndCheckerDiagnosticsOfFile(state, sourceFile, cancellationToken, semanticDiagnosticsPerFile) {
128239
+ semanticDiagnosticsPerFile ?? (semanticDiagnosticsPerFile = state.semanticDiagnosticsPerFile);
128183
128240
  const path = sourceFile.resolvedPath;
128184
- if (state.semanticDiagnosticsPerFile) {
128185
- const cachedDiagnostics = state.semanticDiagnosticsPerFile.get(path);
128186
- if (cachedDiagnostics) {
128187
- return filterSemanticDiagnostics(cachedDiagnostics, state.compilerOptions);
128188
- }
128241
+ const cachedDiagnostics = semanticDiagnosticsPerFile.get(path);
128242
+ if (cachedDiagnostics) {
128243
+ return filterSemanticDiagnostics(cachedDiagnostics, state.compilerOptions);
128189
128244
  }
128190
128245
  const diagnostics = Debug.checkDefined(state.program).getBindAndCheckDiagnostics(sourceFile, cancellationToken);
128191
- if (state.semanticDiagnosticsPerFile) {
128192
- state.semanticDiagnosticsPerFile.set(path, diagnostics);
128193
- }
128246
+ semanticDiagnosticsPerFile.set(path, diagnostics);
128194
128247
  return filterSemanticDiagnostics(diagnostics, state.compilerOptions);
128195
128248
  }
128196
128249
  function isProgramBundleEmitBuildInfo(info) {
@@ -128218,6 +128271,9 @@ function getBuildInfo2(state) {
128218
128271
  root,
128219
128272
  resolvedRoot: toResolvedRoot(),
128220
128273
  options: convertToProgramBuildInfoCompilerOptions(state.compilerOptions),
128274
+ semanticDiagnosticsPerFile: convertToProgramBuildInfoDiagnostics(),
128275
+ emitDiagnosticsPerFile: convertToProgramBuildInfoEmitDiagnostics(),
128276
+ changeFileSet: toChangeFileSet(),
128221
128277
  outSignature: state.outSignature,
128222
128278
  latestChangedDtsFile,
128223
128279
  pendingEmit: !state.programEmitPending ? void 0 : (
@@ -128308,13 +128364,6 @@ function getBuildInfo2(state) {
128308
128364
  }
128309
128365
  }
128310
128366
  }
128311
- let changeFileSet;
128312
- if (state.changedFilesSet.size) {
128313
- for (const path of arrayFrom(state.changedFilesSet.keys()).sort(compareStringsCaseSensitive)) {
128314
- changeFileSet = append(changeFileSet, toFileId(path));
128315
- }
128316
- }
128317
- const emitDiagnosticsPerFile = convertToProgramBuildInfoEmitDiagnostics();
128318
128367
  const program = {
128319
128368
  fileNames,
128320
128369
  fileInfos,
@@ -128324,9 +128373,9 @@ function getBuildInfo2(state) {
128324
128373
  fileIdsList,
128325
128374
  referencedMap,
128326
128375
  semanticDiagnosticsPerFile,
128327
- emitDiagnosticsPerFile,
128376
+ emitDiagnosticsPerFile: convertToProgramBuildInfoEmitDiagnostics(),
128328
128377
  affectedFilesPendingEmit,
128329
- changeFileSet,
128378
+ changeFileSet: toChangeFileSet(),
128330
128379
  emitSignatures,
128331
128380
  latestChangedDtsFile
128332
128381
  };
@@ -128409,8 +128458,7 @@ function getBuildInfo2(state) {
128409
128458
  function convertToProgramBuildInfoDiagnostics() {
128410
128459
  let result;
128411
128460
  state.fileInfos.forEach((_value, key) => {
128412
- var _a2;
128413
- const value = (_a2 = state.semanticDiagnosticsPerFile) == null ? void 0 : _a2.get(key);
128461
+ const value = state.semanticDiagnosticsPerFile.get(key);
128414
128462
  if (!value) {
128415
128463
  if (!state.changedFilesSet.has(key)) result = append(result, toFileId(key));
128416
128464
  } else if (value.length) {
@@ -128479,6 +128527,15 @@ function getBuildInfo2(state) {
128479
128527
  return result;
128480
128528
  }) || array;
128481
128529
  }
128530
+ function toChangeFileSet() {
128531
+ let changeFileSet;
128532
+ if (state.changedFilesSet.size) {
128533
+ for (const path of arrayFrom(state.changedFilesSet.keys()).sort(compareStringsCaseSensitive)) {
128534
+ changeFileSet = append(changeFileSet, toFileId(path));
128535
+ }
128536
+ }
128537
+ return changeFileSet;
128538
+ }
128482
128539
  }
128483
128540
  var BuilderProgramKind = /* @__PURE__ */ ((BuilderProgramKind2) => {
128484
128541
  BuilderProgramKind2[BuilderProgramKind2["SemanticDiagnosticsBuilderProgram"] = 0] = "SemanticDiagnosticsBuilderProgram";
@@ -128582,14 +128639,16 @@ function createBuilderProgram(kind, { newProgram, host, oldProgram, configFilePa
128582
128639
  return emitSkippedWithNoDiagnostics;
128583
128640
  }
128584
128641
  function emitNextAffectedFile(writeFile2, cancellationToken, emitOnlyDtsFiles, customTransformers) {
128585
- var _a, _b, _c;
128642
+ var _a, _b, _c, _d;
128586
128643
  let affected = getNextAffectedFile(state, cancellationToken, host);
128587
128644
  const programEmitKind = getBuilderFileEmit(state.compilerOptions);
128588
128645
  let emitKind = emitOnlyDtsFiles ? programEmitKind & 24 /* AllDts */ : programEmitKind;
128589
128646
  if (!affected) {
128590
128647
  if (!state.compilerOptions.outFile) {
128591
128648
  const pendingAffectedFile = getNextAffectedFilePendingEmit(state, emitOnlyDtsFiles);
128592
- if (!pendingAffectedFile) {
128649
+ if (pendingAffectedFile) {
128650
+ ({ affectedFile: affected, emitKind } = pendingAffectedFile);
128651
+ } else {
128593
128652
  const pendingForDiagnostics = getNextPendingEmitDiagnosticsFile(state);
128594
128653
  if (pendingForDiagnostics) {
128595
128654
  (state.seenEmittedFiles ?? (state.seenEmittedFiles = /* @__PURE__ */ new Map())).set(pendingForDiagnostics.affectedFile.resolvedPath, pendingForDiagnostics.seenKind | 24 /* AllDts */);
@@ -128598,48 +128657,73 @@ function createBuilderProgram(kind, { newProgram, host, oldProgram, configFilePa
128598
128657
  affected: pendingForDiagnostics.affectedFile
128599
128658
  };
128600
128659
  }
128601
- if (!state.buildInfoEmitPending) return void 0;
128602
- const affected2 = state.program;
128603
- const result2 = affected2.emitBuildInfo(writeFile2 || maybeBind(host, host.writeFile), cancellationToken);
128604
- state.buildInfoEmitPending = false;
128605
- return { result: result2, affected: affected2 };
128606
128660
  }
128607
- ({ affectedFile: affected, emitKind } = pendingAffectedFile);
128608
128661
  } else {
128609
- if (!state.programEmitPending) return void 0;
128610
- emitKind = state.programEmitPending;
128611
- if (emitOnlyDtsFiles) emitKind = emitKind & 24 /* AllDts */;
128612
- if (!emitKind) return void 0;
128613
- affected = state.program;
128662
+ if (state.programEmitPending) {
128663
+ emitKind = state.programEmitPending;
128664
+ if (emitOnlyDtsFiles) emitKind = emitKind & 24 /* AllDts */;
128665
+ if (emitKind) affected = state.program;
128666
+ }
128667
+ if (!affected && ((_a = state.emitDiagnosticsPerFile) == null ? void 0 : _a.size)) {
128668
+ const seenKind = state.seenProgramEmit || 0 /* None */;
128669
+ if (!(seenKind & 24 /* AllDts */)) {
128670
+ state.seenProgramEmit = 24 /* AllDts */ | seenKind;
128671
+ const diagnostics = [];
128672
+ state.emitDiagnosticsPerFile.forEach((d) => addRange(diagnostics, d));
128673
+ return {
128674
+ result: { emitSkipped: true, diagnostics },
128675
+ affected: state.program
128676
+ };
128677
+ }
128678
+ }
128679
+ }
128680
+ if (!affected) {
128681
+ if (!state.buildInfoEmitPending) return void 0;
128682
+ const affected2 = state.program;
128683
+ const result2 = affected2.emitBuildInfo(writeFile2 || maybeBind(host, host.writeFile), cancellationToken);
128684
+ state.buildInfoEmitPending = false;
128685
+ return { result: result2, affected: affected2 };
128614
128686
  }
128615
128687
  }
128616
128688
  let emitOnly;
128617
128689
  if (emitKind & 7 /* AllJs */) emitOnly = 0 /* Js */;
128618
128690
  if (emitKind & 24 /* AllDts */) emitOnly = emitOnly === void 0 ? 1 /* Dts */ : void 0;
128619
- if (affected === state.program) {
128620
- state.programEmitPending = state.changedFilesSet.size ? getPendingEmitKind(programEmitKind, emitKind) : state.programEmitPending ? getPendingEmitKind(state.programEmitPending, emitKind) : void 0;
128621
- }
128622
128691
  const result = state.program.emit(
128623
128692
  affected === state.program ? void 0 : affected,
128624
128693
  getWriteFileCallback(writeFile2, customTransformers),
128625
128694
  cancellationToken,
128626
128695
  emitOnly,
128627
- customTransformers
128696
+ customTransformers,
128697
+ /*forceDtsEmit*/
128698
+ void 0,
128699
+ /*skipBuildInfo*/
128700
+ true
128628
128701
  );
128629
128702
  if (affected !== state.program) {
128630
128703
  const affectedSourceFile = affected;
128631
128704
  state.seenAffectedFiles.add(affectedSourceFile.resolvedPath);
128632
128705
  if (state.affectedFilesIndex !== void 0) state.affectedFilesIndex++;
128633
128706
  state.buildInfoEmitPending = true;
128634
- const existing = ((_a = state.seenEmittedFiles) == null ? void 0 : _a.get(affectedSourceFile.resolvedPath)) || 0 /* None */;
128707
+ const existing = ((_b = state.seenEmittedFiles) == null ? void 0 : _b.get(affectedSourceFile.resolvedPath)) || 0 /* None */;
128635
128708
  (state.seenEmittedFiles ?? (state.seenEmittedFiles = /* @__PURE__ */ new Map())).set(affectedSourceFile.resolvedPath, emitKind | existing);
128636
- const existingPending = ((_b = state.affectedFilesPendingEmit) == null ? void 0 : _b.get(affectedSourceFile.resolvedPath)) || programEmitKind;
128709
+ const existingPending = ((_c = state.affectedFilesPendingEmit) == null ? void 0 : _c.get(affectedSourceFile.resolvedPath)) || programEmitKind;
128637
128710
  const pendingKind = getPendingEmitKind(existingPending, emitKind | existing);
128638
128711
  if (pendingKind) (state.affectedFilesPendingEmit ?? (state.affectedFilesPendingEmit = /* @__PURE__ */ new Map())).set(affectedSourceFile.resolvedPath, pendingKind);
128639
- else (_c = state.affectedFilesPendingEmit) == null ? void 0 : _c.delete(affectedSourceFile.resolvedPath);
128712
+ else (_d = state.affectedFilesPendingEmit) == null ? void 0 : _d.delete(affectedSourceFile.resolvedPath);
128640
128713
  if (result.diagnostics.length) (state.emitDiagnosticsPerFile ?? (state.emitDiagnosticsPerFile = /* @__PURE__ */ new Map())).set(affectedSourceFile.resolvedPath, result.diagnostics);
128641
128714
  } else {
128642
128715
  state.changedFilesSet.clear();
128716
+ state.programEmitPending = state.changedFilesSet.size ? getPendingEmitKind(programEmitKind, emitKind) : state.programEmitPending ? getPendingEmitKind(state.programEmitPending, emitKind) : void 0;
128717
+ state.seenProgramEmit = emitKind | (state.seenProgramEmit || 0 /* None */);
128718
+ let emitDiagnosticsPerFile;
128719
+ result.diagnostics.forEach((d) => {
128720
+ if (!d.file) return;
128721
+ let diagnostics = emitDiagnosticsPerFile == null ? void 0 : emitDiagnosticsPerFile.get(d.file.resolvedPath);
128722
+ if (!diagnostics) (emitDiagnosticsPerFile ?? (emitDiagnosticsPerFile = /* @__PURE__ */ new Map())).set(d.file.resolvedPath, diagnostics = []);
128723
+ diagnostics.push(d);
128724
+ });
128725
+ if (emitDiagnosticsPerFile) state.emitDiagnosticsPerFile = emitDiagnosticsPerFile;
128726
+ state.buildInfoEmitPending = true;
128643
128727
  }
128644
128728
  return { result, affected };
128645
128729
  }
@@ -128761,28 +128845,37 @@ function createBuilderProgram(kind, { newProgram, host, oldProgram, configFilePa
128761
128845
  state.buildInfoEmitPending = true;
128762
128846
  if (!result) continue;
128763
128847
  } else {
128764
- result = state.program.getSemanticDiagnostics(
128765
- /*sourceFile*/
128766
- void 0,
128767
- cancellationToken
128848
+ let diagnostics;
128849
+ const semanticDiagnosticsPerFile = /* @__PURE__ */ new Map();
128850
+ state.program.getSourceFiles().forEach(
128851
+ (sourceFile) => diagnostics = addRange(
128852
+ diagnostics,
128853
+ getSemanticDiagnosticsOfFile(
128854
+ state,
128855
+ sourceFile,
128856
+ cancellationToken,
128857
+ semanticDiagnosticsPerFile
128858
+ )
128859
+ )
128768
128860
  );
128861
+ state.semanticDiagnosticsPerFile = semanticDiagnosticsPerFile;
128862
+ result = diagnostics || emptyArray;
128769
128863
  state.changedFilesSet.clear();
128770
128864
  state.programEmitPending = getBuilderFileEmit(state.compilerOptions);
128865
+ state.buildInfoEmitPending = true;
128771
128866
  }
128772
128867
  return { result, affected };
128773
128868
  }
128774
128869
  }
128775
128870
  function getSemanticDiagnostics(sourceFile, cancellationToken) {
128776
128871
  assertSourceFileOkWithoutNextAffectedCall(state, sourceFile);
128777
- const compilerOptions = Debug.checkDefined(state.program).getCompilerOptions();
128778
- if (compilerOptions.outFile) {
128779
- Debug.assert(!state.semanticDiagnosticsPerFile);
128780
- return Debug.checkDefined(state.program).getSemanticDiagnostics(sourceFile, cancellationToken);
128781
- }
128782
128872
  if (sourceFile) {
128783
128873
  return getSemanticDiagnosticsOfFile(state, sourceFile, cancellationToken);
128784
128874
  }
128785
- while (getSemanticDiagnosticsOfNextAffectedFile(cancellationToken)) {
128875
+ while (true) {
128876
+ const affectedResult = getSemanticDiagnosticsOfNextAffectedFile(cancellationToken);
128877
+ if (!affectedResult) break;
128878
+ if (affectedResult.affected === state.program) return affectedResult.result;
128786
128879
  }
128787
128880
  let diagnostics;
128788
128881
  for (const sourceFile2 of Debug.checkDefined(state.program).getSourceFiles()) {
@@ -128815,8 +128908,9 @@ function createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, hos
128815
128908
  const filePaths = (_a = program.fileNames) == null ? void 0 : _a.map(toPathInBuildInfoDirectory);
128816
128909
  let filePathsSetList;
128817
128910
  const latestChangedDtsFile = program.latestChangedDtsFile ? toAbsolutePath(program.latestChangedDtsFile) : void 0;
128911
+ const fileInfos = /* @__PURE__ */ new Map();
128912
+ const changedFilesSet = new Set(map(program.changeFileSet, toFilePath));
128818
128913
  if (isProgramBundleEmitBuildInfo(program)) {
128819
- const fileInfos = /* @__PURE__ */ new Map();
128820
128914
  program.fileInfos.forEach((fileInfo, index) => {
128821
128915
  const path = toFilePath(index + 1);
128822
128916
  fileInfos.set(path, isString(fileInfo) ? { version: fileInfo, signature: void 0, affectsGlobalScope: void 0, impliedFormat: void 0 } : fileInfo);
@@ -128824,13 +128918,16 @@ function createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, hos
128824
128918
  state = {
128825
128919
  fileInfos,
128826
128920
  compilerOptions: program.options ? convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath) : {},
128921
+ semanticDiagnosticsPerFile: toPerFileSemanticDiagnostics(program.semanticDiagnosticsPerFile),
128922
+ emitDiagnosticsPerFile: toPerFileEmitDiagnostics(program.emitDiagnosticsPerFile),
128923
+ hasReusableDiagnostic: true,
128924
+ changedFilesSet,
128827
128925
  latestChangedDtsFile,
128828
128926
  outSignature: program.outSignature,
128829
128927
  programEmitPending: program.pendingEmit === void 0 ? void 0 : toProgramEmitPending(program.pendingEmit, program.options)
128830
128928
  };
128831
128929
  } else {
128832
128930
  filePathsSetList = (_b = program.fileIdsList) == null ? void 0 : _b.map((fileIds) => new Set(fileIds.map(toFilePath)));
128833
- const fileInfos = /* @__PURE__ */ new Map();
128834
128931
  const emitSignatures = ((_c = program.options) == null ? void 0 : _c.composite) && !program.options.outFile ? /* @__PURE__ */ new Map() : void 0;
128835
128932
  program.fileInfos.forEach((fileInfo, index) => {
128836
128933
  const path = toFilePath(index + 1);
@@ -128851,13 +128948,12 @@ function createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, hos
128851
128948
  );
128852
128949
  }
128853
128950
  });
128854
- const changedFilesSet = new Set(map(program.changeFileSet, toFilePath));
128855
128951
  const fullEmitForOptions = program.affectedFilesPendingEmit ? getBuilderFileEmit(program.options || {}) : void 0;
128856
128952
  state = {
128857
128953
  fileInfos,
128858
128954
  compilerOptions: program.options ? convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath) : {},
128859
128955
  referencedMap: toManyToManyPathMap(program.referencedMap, program.options ?? {}),
128860
- semanticDiagnosticsPerFile: toPerFileSemanticDiagnostics(program.semanticDiagnosticsPerFile, fileInfos, changedFilesSet),
128956
+ semanticDiagnosticsPerFile: toPerFileSemanticDiagnostics(program.semanticDiagnosticsPerFile),
128861
128957
  emitDiagnosticsPerFile: toPerFileEmitDiagnostics(program.emitDiagnosticsPerFile),
128862
128958
  hasReusableDiagnostic: true,
128863
128959
  affectedFilesPendingEmit: program.affectedFilesPendingEmit && arrayToMap(program.affectedFilesPendingEmit, (value) => toFilePath(isNumber(value) ? value : value[0]), (value) => toBuilderFileEmit(value, fullEmitForOptions)),
@@ -128909,7 +129005,7 @@ function createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, hos
128909
129005
  referenceMap.forEach(([fileId, fileIdListId]) => map2.set(toFilePath(fileId), toFilePathsSet(fileIdListId)));
128910
129006
  return map2;
128911
129007
  }
128912
- function toPerFileSemanticDiagnostics(diagnostics, fileInfos, changedFilesSet) {
129008
+ function toPerFileSemanticDiagnostics(diagnostics) {
128913
129009
  const semanticDiagnostics = new Map(
128914
129010
  mapDefinedIterator(
128915
129011
  fileInfos.keys(),
@@ -128920,7 +129016,7 @@ function createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, hos
128920
129016
  if (isNumber(value)) semanticDiagnostics.delete(toFilePath(value));
128921
129017
  else semanticDiagnostics.set(toFilePath(value[0]), value[1]);
128922
129018
  });
128923
- return semanticDiagnostics.size ? semanticDiagnostics : void 0;
129019
+ return semanticDiagnostics;
128924
129020
  }
128925
129021
  function toPerFileEmitDiagnostics(diagnostics) {
128926
129022
  return diagnostics && arrayToMap(diagnostics, (value) => toFilePath(value[0]), (value) => value[1]);
@@ -132096,8 +132192,6 @@ function createBuildOrUpdateInvalidedProject(state, project, projectPath, projec
132096
132192
  ({ buildResult, step } = buildErrors(
132097
132193
  state,
132098
132194
  projectPath,
132099
- program,
132100
- config,
132101
132195
  diagnostics,
132102
132196
  errorFlags,
132103
132197
  errorType
@@ -132160,8 +132254,6 @@ function createBuildOrUpdateInvalidedProject(state, project, projectPath, projec
132160
132254
  ({ buildResult, step } = buildErrors(
132161
132255
  state,
132162
132256
  projectPath,
132163
- program,
132164
- config,
132165
132257
  declDiagnostics,
132166
132258
  32 /* DeclarationEmitErrors */,
132167
132259
  "Declaration file"
@@ -132224,8 +132316,6 @@ function createBuildOrUpdateInvalidedProject(state, project, projectPath, projec
132224
132316
  ({ buildResult, step } = buildErrors(
132225
132317
  state,
132226
132318
  projectPath,
132227
- program,
132228
- config,
132229
132319
  emitDiagnostics,
132230
132320
  64 /* EmitErrors */,
132231
132321
  "Emit"
@@ -132405,13 +132495,10 @@ function afterProgramDone(state, program) {
132405
132495
  }
132406
132496
  state.projectCompilerOptions = state.baseCompilerOptions;
132407
132497
  }
132408
- function buildErrors(state, resolvedPath, program, config, diagnostics, buildResult, errorType) {
132409
- const canEmitBuildInfo = program && !program.getCompilerOptions().outFile;
132498
+ function buildErrors(state, resolvedPath, diagnostics, buildResult, errorType) {
132410
132499
  reportAndStoreErrors(state, resolvedPath, diagnostics);
132411
132500
  state.projectStatus.set(resolvedPath, { type: 0 /* Unbuildable */, reason: `${errorType} errors` });
132412
- if (canEmitBuildInfo) return { buildResult, step: 4 /* EmitBuildInfo */ };
132413
- afterProgramDone(state, program);
132414
- return { buildResult, step: 5 /* QueueReferencingProjects */ };
132501
+ return { buildResult, step: 4 /* EmitBuildInfo */ };
132415
132502
  }
132416
132503
  function isFileWatcherWithModifiedTime(value) {
132417
132504
  return !!value.watcher;
@@ -132586,7 +132673,7 @@ function getUpToDateStatusWorker(state, project, resolvedPath) {
132586
132673
  };
132587
132674
  }
132588
132675
  if (buildInfo.program) {
132589
- if (((_a = buildInfo.program.changeFileSet) == null ? void 0 : _a.length) || (!project.options.noEmit ? ((_b = buildInfo.program.affectedFilesPendingEmit) == null ? void 0 : _b.length) || ((_c = buildInfo.program.emitDiagnosticsPerFile) == null ? void 0 : _c.length) : (_d = buildInfo.program.semanticDiagnosticsPerFile) == null ? void 0 : _d.length)) {
132676
+ if (((_a = buildInfo.program.changeFileSet) == null ? void 0 : _a.length) || (!project.options.noEmit ? ((_b = buildInfo.program.affectedFilesPendingEmit) == null ? void 0 : _b.length) || ((_c = buildInfo.program.emitDiagnosticsPerFile) == null ? void 0 : _c.length) || buildInfo.program.pendingEmit !== void 0 : (_d = buildInfo.program.semanticDiagnosticsPerFile) == null ? void 0 : _d.length)) {
132590
132677
  return {
132591
132678
  type: 7 /* OutOfDateBuildInfo */,
132592
132679
  buildInfoFile: buildInfoPath
@@ -136867,12 +136954,12 @@ function isInReferenceCommentWorker(sourceFile, position, shouldBeReference) {
136867
136954
  );
136868
136955
  return !!range && shouldBeReference === tripleSlashDirectivePrefixRegex.test(sourceFile.text.substring(range.pos, range.end));
136869
136956
  }
136870
- function getReplacementSpanForContextToken(contextToken) {
136957
+ function getReplacementSpanForContextToken(contextToken, position) {
136871
136958
  if (!contextToken) return void 0;
136872
136959
  switch (contextToken.kind) {
136873
136960
  case 11 /* StringLiteral */:
136874
136961
  case 15 /* NoSubstitutionTemplateLiteral */:
136875
- return createTextSpanFromStringLiteralLikeContent(contextToken);
136962
+ return createTextSpanFromStringLiteralLikeContent(contextToken, position);
136876
136963
  default:
136877
136964
  return createTextSpanFromNode(contextToken);
136878
136965
  }
@@ -136880,11 +136967,11 @@ function getReplacementSpanForContextToken(contextToken) {
136880
136967
  function createTextSpanFromNode(node, sourceFile, endNode2) {
136881
136968
  return createTextSpanFromBounds(node.getStart(sourceFile), (endNode2 || node).getEnd());
136882
136969
  }
136883
- function createTextSpanFromStringLiteralLikeContent(node) {
136970
+ function createTextSpanFromStringLiteralLikeContent(node, position) {
136884
136971
  let replacementEnd = node.getEnd() - 1;
136885
136972
  if (node.isUnterminated) {
136886
136973
  if (node.getStart() === replacementEnd) return void 0;
136887
- replacementEnd = node.getEnd();
136974
+ replacementEnd = Math.min(position, node.getEnd());
136888
136975
  }
136889
136976
  return createTextSpanFromBounds(node.getStart() + 1, replacementEnd);
136890
136977
  }
@@ -158687,6 +158774,7 @@ function withContext(context, typePrintMode, cb) {
158687
158774
  textChanges: changeTracker.getChanges()
158688
158775
  };
158689
158776
  function addTypeAnnotation(span) {
158777
+ context.cancellationToken.throwIfCancellationRequested();
158690
158778
  const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
158691
158779
  const expandoFunction = findExpandoFunction(nodeWithDiag);
158692
158780
  if (expandoFunction) {
@@ -158758,6 +158846,7 @@ function withContext(context, typePrintMode, cb) {
158758
158846
  return factory.createAsExpression(factory.createSatisfiesExpression(node, getSynthesizedDeepClone(type)), type);
158759
158847
  }
158760
158848
  function addInlineAssertion(span) {
158849
+ context.cancellationToken.throwIfCancellationRequested();
158761
158850
  const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
158762
158851
  const expandoFunction = findExpandoFunction(nodeWithDiag);
158763
158852
  if (expandoFunction) return;
@@ -158815,6 +158904,7 @@ function withContext(context, typePrintMode, cb) {
158815
158904
  return [Diagnostics.Add_satisfies_and_an_inline_type_assertion_with_0, typeToStringForDiag(typeNode)];
158816
158905
  }
158817
158906
  function extractAsVariable(span) {
158907
+ context.cancellationToken.throwIfCancellationRequested();
158818
158908
  const nodeWithDiag = getTokenAtPosition(sourceFile, span.start);
158819
158909
  const targetNode = findBestFittingNode(nodeWithDiag, span);
158820
158910
  if (!targetNode || isValueSignatureDeclaration(targetNode) || isValueSignatureDeclaration(targetNode.parent)) return;
@@ -163311,7 +163401,7 @@ function createCompletionEntry(symbol, sortText, replacementToken, contextToken,
163311
163401
  var _a, _b;
163312
163402
  let insertText;
163313
163403
  let filterText;
163314
- let replacementSpan = getReplacementSpanForContextToken(replacementToken);
163404
+ let replacementSpan = getReplacementSpanForContextToken(replacementToken, position);
163315
163405
  let data;
163316
163406
  let isSnippet;
163317
163407
  let source = getSourceFromOrigin(origin);
@@ -166305,7 +166395,7 @@ function convertStringLiteralCompletions(completion, contextToken, sourceFile, h
166305
166395
  if (completion === void 0) {
166306
166396
  return void 0;
166307
166397
  }
166308
- const optionalReplacementSpan = createTextSpanFromStringLiteralLikeContent(contextToken);
166398
+ const optionalReplacementSpan = createTextSpanFromStringLiteralLikeContent(contextToken, position);
166309
166399
  switch (completion.kind) {
166310
166400
  case 0 /* Paths */:
166311
166401
  return convertPathCompletions(completion.paths);
@@ -166359,7 +166449,7 @@ function convertStringLiteralCompletions(completion, contextToken, sourceFile, h
166359
166449
  kindModifiers: "" /* none */,
166360
166450
  kind: "string" /* string */,
166361
166451
  sortText: SortText.LocationPriority,
166362
- replacementSpan: getReplacementSpanForContextToken(contextToken)
166452
+ replacementSpan: getReplacementSpanForContextToken(contextToken, position)
166363
166453
  }));
166364
166454
  return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: completion.isNewIdentifier, optionalReplacementSpan, entries };
166365
166455
  }