diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6d4d7b5425..8ec821cb66 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1717,7 +1717,7 @@ namespace ts { } // If the emit is enabled make sure that every output file is unique and not overwriting any of the input files - if (!options.noEmit) { + if (!options.noEmit && !options.suppressOutputPathCheck) { const emitHost = getEmitHost(); const emitFilesSeen = createFileMap(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined); forEachExpectedEmitFile(emitHost, (emitFileNames, sourceFiles, isBundledEmit) => { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 60f9e0d0ce..5545fbd162 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2426,6 +2426,8 @@ namespace ts { // Skip checking lib.d.ts to help speed up tests. /* @internal */ skipDefaultLibCheck?: boolean; + // Do not perform validation of output file name in transpile scenarios + /* @internal */ suppressOutputPathCheck?: boolean; [option: string]: string | number | boolean | TsConfigOnlyOptions; } diff --git a/src/services/services.ts b/src/services/services.ts index 6d12f29d50..96d09fd060 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1876,6 +1876,9 @@ namespace ts { options.isolatedModules = true; + // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths. + options.suppressOutputPathCheck = true; + // Filename can be non-ts file. options.allowNonTsExtensions = true; diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index d9fdaeb32e..6f46bb5340 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -291,5 +291,14 @@ var x = 0;`, options: { compilerOptions: { jsx: JsxEmit.React, newLine: NewLineKind.LineFeed } } }) }); + it("transpile .js files", () => { + const input = "const a = 10;"; + const output = `"use strict";\nvar a = 10;\n`; + test(input, { + expectedOutput: output, + options: { compilerOptions: { newLine: NewLineKind.LineFeed, module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true }, + expectedDiagnosticCodes: [] + }); + }) }); }