From a64e5ad3f3fd20017d1e02a8e7c73bd66538d399 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 1 Feb 2019 18:40:04 -0800 Subject: [PATCH] Even though .d.ts doesnt change, the map file most likely changes, so emit that --- src/compiler/emitter.ts | 25 +++++++++------ src/testRunner/unittests/tsbuild/outFile.ts | 34 +++++---------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 034392db24b..a318b374e1f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -469,7 +469,7 @@ namespace ts { /*@internal*/ export function emitUsingBuildInfo(config: ParsedCommandLine, host: EmitUsingBuildInfoHost, getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined): EmitUsingBuildInfoResult { - const { buildInfoPath, jsFilePath, sourceMapFilePath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false, config.projectReferences); + const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false, config.projectReferences); const buildInfoText = host.readFile(Debug.assertDefined(buildInfoPath)); if (!buildInfoText) return buildInfoPath!; const jsFileText = host.readFile(Debug.assertDefined(jsFilePath)); @@ -477,31 +477,34 @@ namespace ts { const sourceMapText = sourceMapFilePath && host.readFile(sourceMapFilePath); // error if no source map or for now if inline sourcemap if ((sourceMapFilePath && !sourceMapText) || config.options.inlineSourceMap) return sourceMapFilePath || "inline sourcemap decoding"; + const declarationMapText = declarationMapPath && host.readFile(declarationMapPath); + // error if no source map or for now if inline sourcemap + if ((declarationMapPath && !declarationMapText) || config.options.inlineSourceMap) return declarationMapPath || "inline sourcemap decoding"; + // read declaration text + const declarationText = declarationMapText && host.readFile(declarationFilePath!); + if (declarationMapText && !declarationText) return declarationFilePath!; const buildInfo = JSON.parse(buildInfoText) as BuildInfo; const ownPrependInput = createInputFiles( jsFileText, - /*declarationText*/ undefined!, + declarationText!, sourceMapFilePath, sourceMapText, - /*declarationMapPath*/ undefined!, - /*declarationMaptext*/ undefined!, + declarationMapPath, + declarationMapText, jsFilePath, - /*declarationPath*/ undefined, + declarationFilePath, buildInfoPath, buildInfo, /*onlyOwnText*/ true ); - const optionsWithoutDeclaration = clone(config.options); - optionsWithoutDeclaration.declaration = false; - optionsWithoutDeclaration.composite = false; const outputFiles: OutputFile[] = []; const emitHost: EmitHost = { getPrependNodes: () => createPrependNodes(config.projectReferences, getCommandLine, f => host.readFile(f)). concat(ownPrependInput), getProjectReferences: () => config.projectReferences, getCanonicalFileName: host.getCanonicalFileName, getCommonSourceDirectory: () => buildInfo.commonSourceDirectory, - getCompilerOptions: () => optionsWithoutDeclaration, + getCompilerOptions: () => config.options, getCurrentDirectory: () => host.getCurrentDirectory(), getNewLine: () => host.getNewLine(), getSourceFile: notImplemented, @@ -510,6 +513,8 @@ namespace ts { getLibFileFromReference: notImplemented, isSourceFileFromExternalLibrary: notImplemented, writeFile: (name, text, writeByteOrderMark) => { + // no need to write dts file + if (fileExtensionIs(name, Extension.Dts)) return; if (name === buildInfoPath) { // Add dts and sources build info since we are not touching that file const newBuildInfo = JSON.parse(text) as BuildInfo; @@ -530,7 +535,7 @@ namespace ts { emitHost, /*targetSourceFile*/ undefined, /*emitOnlyDtsFiles*/ false, - getTransformers(optionsWithoutDeclaration) + getTransformers(config.options) ); return outputFiles; } diff --git a/src/testRunner/unittests/tsbuild/outFile.ts b/src/testRunner/unittests/tsbuild/outFile.ts index 22194a0124d..6746a2147e1 100644 --- a/src/testRunner/unittests/tsbuild/outFile.ts +++ b/src/testRunner/unittests/tsbuild/outFile.ts @@ -275,19 +275,10 @@ Mismatch Actual: ${JSON.stringify(mapDefined(arrayFrom(actualReadFileMap.entries // Additional source Files ...(additionalSourceFiles && additionalSourceFiles.length === 3 ? [additionalSourceFiles[project.first]] : emptyArray), - // outputs without d.ts since we just update js - outputFiles[project.first][ext.js], - outputFiles[project.first][ext.jsmap], - outputFiles[project.first][ext.dts], - outputFiles[project.first][ext.buildinfo], - outputFiles[project.second][ext.js], - outputFiles[project.second][ext.jsmap], - outputFiles[project.second][ext.buildinfo], - - // To prepend:: - outputFiles[project.third][ext.buildinfo], - outputFiles[project.third][ext.js], - outputFiles[project.third][ext.jsmap] + // outputs to prepend + ...outputFiles[project.first], + ...outputFiles[project.second], + ...outputFiles[project.third] ], fs => appendFileContent(fs, relSources[project.first][source.ts][part.one], "console.log(s);"), [ @@ -345,19 +336,10 @@ Mismatch Actual: ${JSON.stringify(mapDefined(arrayFrom(actualReadFileMap.entries // Additional source Files ...(additionalSourceFiles || emptyArray), - // outputs without d.ts since we just update js - outputFiles[project.first][ext.js], - outputFiles[project.first][ext.jsmap], - outputFiles[project.first][ext.dts], - outputFiles[project.first][ext.buildinfo], - outputFiles[project.second][ext.js], - outputFiles[project.second][ext.jsmap], - outputFiles[project.second][ext.buildinfo], - - // To prepend:: - outputFiles[project.third][ext.buildinfo], - outputFiles[project.third][ext.js], - outputFiles[project.third][ext.jsmap] + // outputs to prepend + ...outputFiles[project.first], + ...outputFiles[project.second], + ...outputFiles[project.third] ], fs => modifyAgainFs(fs), [