Skip to content

Commit f55f28f

Browse files
committed
Merge pull request #6789 from Microsoft/transpileJs
suppress validation of output paths in transpile scenarios
1 parent 774b17b commit f55f28f

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ namespace ts {
13591359
}
13601360

13611361
// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
1362-
if (!options.noEmit) {
1362+
if (!options.noEmit && !options.suppressOutputPathCheck) {
13631363
const emitHost = getEmitHost();
13641364
const emitFilesSeen = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined);
13651365
forEachExpectedEmitFile(emitHost, (emitFileNames, sourceFiles, isBundledEmit) => {

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,8 @@ namespace ts {
24382438

24392439
// Skip checking lib.d.ts to help speed up tests.
24402440
/* @internal */ skipDefaultLibCheck?: boolean;
2441+
// Do not perform validation of output file name in transpile scenarios
2442+
/* @internal */ suppressOutputPathCheck?: boolean;
24412443

24422444
[option: string]: string | number | boolean;
24432445
}

src/services/services.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,9 @@ namespace ts {
18751875

18761876
options.isolatedModules = true;
18771877

1878+
// transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
1879+
options.suppressOutputPathCheck = true;
1880+
18781881
// Filename can be non-ts file.
18791882
options.allowNonTsExtensions = true;
18801883

tests/cases/unittests/transpile.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,14 @@ var x = 0;`,
291291
options: { compilerOptions: { jsx: JsxEmit.React, newLine: NewLineKind.LineFeed } }
292292
})
293293
});
294+
it("transpile .js files", () => {
295+
const input = "const a = 10;";
296+
const output = `"use strict";\nvar a = 10;\n`;
297+
test(input, {
298+
expectedOutput: output,
299+
options: { compilerOptions: { newLine: NewLineKind.LineFeed, module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true },
300+
expectedDiagnosticCodes: []
301+
});
302+
})
294303
});
295304
}

0 commit comments

Comments
 (0)