Skip to content

Commit b0b0712

Browse files
committed
suppress validation of output paths in transpile scenarios
1 parent 202c1e6 commit b0b0712

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ namespace ts {
17171717
}
17181718

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

src/compiler/types.ts

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

24272427
// Skip checking lib.d.ts to help speed up tests.
24282428
/* @internal */ skipDefaultLibCheck?: boolean;
2429+
// Do not perform validation of output file name in transpile scenarios
2430+
/* @internal */ suppressOutputPathCheck?: boolean;
24292431

24302432
[option: string]: string | number | boolean | TsConfigOnlyOptions;
24312433
}

src/services/services.ts

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

18771877
options.isolatedModules = true;
18781878

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

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)