Skip to content

Commit c4af1f5

Browse files
committed
Handle emitOnlyDts for now since #58364 is yet to be merged for js emit to be done without type checking
1 parent 0a23381 commit c4af1f5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2428,10 +2428,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
24282428
return visitEachChild(node, markAsSynthetic, /*context*/ undefined);
24292429
}
24302430

2431-
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken, forceDtsEmit?: boolean) {
2431+
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken, skipDiagnostics?: boolean) {
24322432
// Ensure we have all the type information in place for this file so that all the
24332433
// emitter questions of this resolver will return the right information.
2434-
if (!forceDtsEmit) getDiagnostics(sourceFile, cancellationToken);
2434+
if (!skipDiagnostics) getDiagnostics(sourceFile, cancellationToken);
24352435
return emitResolver;
24362436
}
24372437

src/compiler/emitter.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ export function getFirstProjectOutput(configFile: ParsedCommandLine, ignoreCase:
717717
return Debug.fail(`project ${configFile.options.configFilePath} expected to have at least one output`);
718718
}
719719

720+
/** @internal */
721+
export function emitResolverSkipsTypeChecking(emitOnly: boolean | EmitOnly | undefined, forceDtsEmit: boolean | undefined) {
722+
return !!forceDtsEmit && !!emitOnly;
723+
}
724+
720725
/** @internal */
721726
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
722727
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile | undefined, { scriptTransformers, declarationTransformers }: EmitTransformers, emitOnly?: boolean | EmitOnly, onlyBuildInfo?: boolean, forceDtsEmit?: boolean): EmitResult {
@@ -848,7 +853,11 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
848853
const filesForEmit = forceDtsEmit ? sourceFiles : filter(sourceFiles, isSourceFileNotJson);
849854
// Setup and perform the transformation to retrieve declarations from the input files
850855
const inputListOrBundle = compilerOptions.outFile ? [factory.createBundle(filesForEmit)] : filesForEmit;
851-
if ((emitOnly && !getEmitDeclarations(compilerOptions)) || compilerOptions.noCheck || forceDtsEmit) {
856+
if (
857+
(emitOnly && !getEmitDeclarations(compilerOptions)) ||
858+
compilerOptions.noCheck ||
859+
emitResolverSkipsTypeChecking(emitOnly, forceDtsEmit)
860+
) {
852861
// Checker wont collect the linked aliases since thats only done when declaration is enabled and checking is performed.
853862
// Do that here when emitting only dts files
854863
filesForEmit.forEach(collectLinkedAliases);

src/compiler/program.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
EmitHost,
6969
emitModuleKindIsNonNodeESM,
7070
EmitOnly,
71+
emitResolverSkipsTypeChecking,
7172
EmitResult,
7273
emptyArray,
7374
ensureTrailingDirectorySeparator,
@@ -2874,7 +2875,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
28742875
const emitResolver = typeChecker.getEmitResolver(
28752876
options.outFile ? undefined : sourceFile,
28762877
cancellationToken,
2877-
forceDtsEmit,
2878+
emitResolverSkipsTypeChecking(emitOnly, forceDtsEmit),
28782879
);
28792880

28802881
performance.mark("beforeEmit");

0 commit comments

Comments
 (0)