Skip to content

Commit 11fd654

Browse files
committed
Separate emitOnlyDtsFiles and forcing dts emit (for builder signature detection where we want it irrespective of settings)
1 parent 8521002 commit 11fd654

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

src/compiler/builderState.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace ts {
1515
/*@internal*/
1616
namespace ts {
1717
export function getFileEmitOutput(program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean,
18-
cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): EmitOutput {
18+
cancellationToken?: CancellationToken, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitOutput {
1919
const outputFiles: OutputFile[] = [];
20-
const emitResult = program.emit(sourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
20+
const emitResult = program.emit(sourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers, forceDtsEmit);
2121
return { outputFiles, emitSkipped: emitResult.emitSkipped, exportedModulesFromDeclarationEmit: emitResult.exportedModulesFromDeclarationEmit };
2222

2323
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean) {
@@ -344,7 +344,14 @@ namespace ts.BuilderState {
344344
}
345345
}
346346
else {
347-
const emitOutput = getFileEmitOutput(programOfThisState, sourceFile, /*emitOnlyDtsFiles*/ true, cancellationToken);
347+
const emitOutput = getFileEmitOutput(
348+
programOfThisState,
349+
sourceFile,
350+
/*emitOnlyDtsFiles*/ true,
351+
cancellationToken,
352+
/*customTransformers*/ undefined,
353+
/*forceDtsEmit*/ true
354+
);
348355
const firstDts = emitOutput.outputFiles &&
349356
programOfThisState.getCompilerOptions().declarationMap ?
350357
emitOutput.outputFiles.length > 1 ? emitOutput.outputFiles[1] : undefined :

src/compiler/emitter.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ts {
2020
export function forEachEmittedFile<T>(
2121
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle | undefined) => T,
2222
sourceFilesOrTargetSourceFile?: ReadonlyArray<SourceFile> | SourceFile,
23-
emitOnlyDtsFiles = false,
23+
forceDtsEmit = false,
2424
onlyBuildInfo?: boolean,
2525
includeBuildInfo?: boolean) {
2626
const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile);
@@ -29,7 +29,7 @@ namespace ts {
2929
const prepends = host.getPrependNodes();
3030
if (sourceFiles.length || prepends.length) {
3131
const bundle = createBundle(sourceFiles, prepends);
32-
const result = action(getOutputPathsFor(bundle, host, emitOnlyDtsFiles), bundle);
32+
const result = action(getOutputPathsFor(bundle, host, forceDtsEmit), bundle);
3333
if (result) {
3434
return result;
3535
}
@@ -38,7 +38,7 @@ namespace ts {
3838
else {
3939
if (!onlyBuildInfo) {
4040
for (const sourceFile of sourceFiles) {
41-
const result = action(getOutputPathsFor(sourceFile, host, emitOnlyDtsFiles), sourceFile);
41+
const result = action(getOutputPathsFor(sourceFile, host, forceDtsEmit), sourceFile);
4242
if (result) {
4343
return result;
4444
}
@@ -227,7 +227,7 @@ namespace ts {
227227

228228
/*@internal*/
229229
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
230-
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile | undefined, { scriptTransformers, declarationTransformers }: EmitTransformers, emitOnlyDtsFiles?: boolean, onlyBuildInfo?: boolean): EmitResult {
230+
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile | undefined, { scriptTransformers, declarationTransformers }: EmitTransformers, emitOnlyDtsFiles?: boolean, onlyBuildInfo?: boolean, forceDtsEmit?: boolean): EmitResult {
231231
const compilerOptions = host.getCompilerOptions();
232232
const sourceMapDataList: SourceMapEmitResult[] | undefined = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined;
233233
const emittedFilesList: string[] | undefined = compilerOptions.listEmittedFiles ? [] : undefined;
@@ -241,7 +241,14 @@ namespace ts {
241241

242242
// Emit each output file
243243
enter();
244-
forEachEmittedFile(host, emitSourceFileOrBundle, getSourceFilesToEmit(host, targetSourceFile), emitOnlyDtsFiles, onlyBuildInfo, !targetSourceFile);
244+
forEachEmittedFile(
245+
host,
246+
emitSourceFileOrBundle,
247+
getSourceFilesToEmit(host, targetSourceFile),
248+
forceDtsEmit,
249+
onlyBuildInfo,
250+
!targetSourceFile
251+
);
245252
exit();
246253

247254

@@ -400,7 +407,7 @@ namespace ts {
400407
});
401408
const declBlocked = (!!declarationTransform.diagnostics && !!declarationTransform.diagnostics.length) || !!host.isEmitBlocked(declarationFilePath) || !!compilerOptions.noEmit;
402409
emitSkipped = emitSkipped || declBlocked;
403-
if (!declBlocked || emitOnlyDtsFiles) {
410+
if (!declBlocked || forceDtsEmit) {
404411
Debug.assert(declarationTransform.transformed.length === 1, "Should only see one output from the decl transform");
405412
printSourceFileOrBundle(
406413
declarationFilePath,
@@ -415,7 +422,7 @@ namespace ts {
415422
// Explicitly do not passthru either `inline` option
416423
}
417424
);
418-
if (emitOnlyDtsFiles && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
425+
if (forceDtsEmit && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
419426
const sourceFile = declarationTransform.transformed[0];
420427
exportedModulesFromDeclarationEmit = sourceFile.exportedModulesFromDeclarationEmit;
421428
}

src/compiler/program.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,18 +1533,18 @@ namespace ts {
15331533
return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false));
15341534
}
15351535

1536-
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, transformers?: CustomTransformers): EmitResult {
1537-
return runWithCancellationToken(() => emitWorker(program, sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers));
1536+
function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, transformers?: CustomTransformers, forceDtsEmit?: boolean): EmitResult {
1537+
return runWithCancellationToken(() => emitWorker(program, sourceFile, writeFileCallback, cancellationToken, emitOnlyDtsFiles, transformers, forceDtsEmit));
15381538
}
15391539

15401540
function isEmitBlocked(emitFileName: string): boolean {
15411541
return hasEmitBlockingDiagnostics.has(toPath(emitFileName));
15421542
}
15431543

1544-
function emitWorker(program: Program, sourceFile: SourceFile | undefined, writeFileCallback: WriteFileCallback | undefined, cancellationToken: CancellationToken | undefined, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult {
1544+
function emitWorker(program: Program, sourceFile: SourceFile | undefined, writeFileCallback: WriteFileCallback | undefined, cancellationToken: CancellationToken | undefined, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitResult {
15451545
let declarationDiagnostics: ReadonlyArray<Diagnostic> = [];
15461546

1547-
if (!emitOnlyDtsFiles) {
1547+
if (!forceDtsEmit) {
15481548
if (options.noEmit) {
15491549
return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: undefined, emitSkipped: true };
15501550
}
@@ -1593,6 +1593,8 @@ namespace ts {
15931593
sourceFile,
15941594
getTransformers(options, customTransformers, emitOnlyDtsFiles),
15951595
emitOnlyDtsFiles,
1596+
/*onlyBuildInfo*/ false,
1597+
forceDtsEmit
15961598
);
15971599

15981600
performance.mark("afterEmit");

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,8 @@ namespace ts {
29802980
* will be invoked when writing the JavaScript and declaration files.
29812981
*/
29822982
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult;
2983+
/*@internal*/
2984+
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitResult; // tslint:disable-line unified-signatures
29832985

29842986
getOptionsDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
29852987
getGlobalDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;

0 commit comments

Comments
 (0)