Skip to content

Commit d7ce0ea

Browse files
Merge pull request microsoft#25524 from RyanCavanaugh/useGetEmitDeclarations
Use getEmitDeclarations instead of .declarations
2 parents 72be715 + 1b1ffe9 commit d7ce0ea

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

src/compiler/emitter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts {
4343
if (sourceFile.kind === SyntaxKind.Bundle) {
4444
const jsFilePath = options.outFile || options.out!;
4545
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
46-
const declarationFilePath = (forceDtsPaths || options.declaration) ? removeFileExtension(jsFilePath) + Extension.Dts : undefined;
46+
const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(jsFilePath) + Extension.Dts : undefined;
4747
const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
4848
const bundleInfoPath = options.references && jsFilePath ? (removeFileExtension(jsFilePath) + infoExtension) : undefined;
4949
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath };
@@ -53,7 +53,7 @@ namespace ts {
5353
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
5454
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
5555
const isJs = isSourceFileJavaScript(sourceFile);
56-
const declarationFilePath = ((forceDtsPaths || options.declaration) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
56+
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
5757
const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
5858
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath: undefined };
5959
}
@@ -192,7 +192,7 @@ namespace ts {
192192
// Setup and perform the transformation to retrieve declarations from the input files
193193
const nonJsFiles = filter(sourceFiles, isSourceFileNotJavaScript);
194194
const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : nonJsFiles;
195-
if (emitOnlyDtsFiles && !compilerOptions.declaration) {
195+
if (emitOnlyDtsFiles && !getEmitDeclarations(compilerOptions)) {
196196
// Checker wont collect the linked aliases since thats only done when declaration is enabled.
197197
// Do that here when emitting only dts files
198198
nonJsFiles.forEach(collectLinkedAliases);

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ namespace ts {
25002500
}
25012501
}
25022502

2503-
if (options.declarationMap && !options.declaration) {
2503+
if (options.declarationMap && !getEmitDeclarations(options)) {
25042504
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationMap", "declaration");
25052505
}
25062506

src/compiler/tsbuild.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ namespace ts {
304304

305305
const outputs: string[] = [];
306306
outputs.push(getOutputJavaScriptFileName(inputFileName, configFile));
307-
if (configFile.options.declaration && !fileExtensionIs(inputFileName, Extension.Json)) {
307+
if (getEmitDeclarations(configFile.options) && !fileExtensionIs(inputFileName, Extension.Json)) {
308308
const dts = getOutputDeclarationFileName(inputFileName, configFile);
309309
outputs.push(dts);
310310
if (configFile.options.declarationMap) {
@@ -320,7 +320,7 @@ namespace ts {
320320
}
321321
const outputs: string[] = [];
322322
outputs.push(project.options.outFile);
323-
if (project.options.declaration) {
323+
if (getEmitDeclarations(project.options)) {
324324
const dts = changeExtension(project.options.outFile, Extension.Dts);
325325
outputs.push(dts);
326326
if (project.options.declarationMap) {
@@ -769,7 +769,10 @@ namespace ts {
769769
const program = createProgram(programOptions);
770770

771771
// Don't emit anything in the presence of syntactic errors or options diagnostics
772-
const syntaxDiagnostics = [...program.getOptionsDiagnostics(), ...program.getSyntacticDiagnostics()];
772+
const syntaxDiagnostics = [
773+
...program.getOptionsDiagnostics(),
774+
...program.getConfigFileParsingDiagnostics(),
775+
...program.getSyntacticDiagnostics()];
773776
if (syntaxDiagnostics.length) {
774777
resultFlags |= BuildResultFlags.SyntaxErrors;
775778
for (const diag of syntaxDiagnostics) {
@@ -780,7 +783,7 @@ namespace ts {
780783
}
781784

782785
// Don't emit .d.ts if there are decl file errors
783-
if (program.getCompilerOptions().declaration) {
786+
if (getEmitDeclarations(program.getCompilerOptions())) {
784787
const declDiagnostics = program.getDeclarationDiagnostics();
785788
if (declDiagnostics.length) {
786789
resultFlags |= BuildResultFlags.DeclarationEmitErrors;

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6915,7 +6915,7 @@ namespace ts {
69156915
}
69166916

69176917
export function getAreDeclarationMapsEnabled(options: CompilerOptions) {
6918-
return !!(options.declaration && options.declarationMap);
6918+
return !!(getEmitDeclarations(options) && options.declarationMap);
69196919
}
69206920

69216921
export function getAllowSyntheticDefaultImports(compilerOptions: CompilerOptions) {

tests/projects/outfile-concat/first/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"strict": false,
77
"sourceMap": true,
88
"declarationMap": true,
9-
"declaration": true,
109
"outFile": "./bin/first-output.js"
1110
},
1211
"files": [

0 commit comments

Comments
 (0)