8000 allow backslashes in fileName argument of the transpile function · DINKIN/TypeScript@9a78b66 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a78b66

Browse files
committed
allow backslashes in fileName argument of the transpile function
1 parent 690b87c commit 9a78b66

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ namespace ts {
18661866
let sourceMapText: string;
18671867
// Create a compilerHost object to allow the compiler to read and write files
18681868
let compilerHost: CompilerHost = {
1869-
getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined,
1869+
getSourceFile: (fileName, target) => fileName === normalizeSlashes(inputFileName) ? sourceFile : undefined,
18701870
writeFile: (name, text, writeByteOrderMark) => {
18711871
if (fileExtensionIs(name, ".map")) {
18721872
Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`);

tests/cases/unittests/transpile.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ module ts {
6464
let transpileModuleResultWithSourceMap = transpileModule(input, transpileOptions);
6565
assert.isTrue(transpileModuleResultWithSourceMap.sourceMapText !== undefined);
6666

67-
let expectedSourceMapFileName = removeFileExtension(transpileOptions.fileName) + ".js.map";
68-
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
67+
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName))) + ".js.map";
68+
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
6969

7070
if (testSettings.expectedOutput !== undefined) {
7171
assert.equal(transpileModuleResultWithSourceMap.outputText, testSettings.expectedOutput + expectedSourceMappingUrlLine);
@@ -270,5 +270,9 @@ var x = 0;`,
270270
expectedOutput: output
271271
});
272272
});
273+
274+
it("Supports backslashes in file name", () => {
275+
test("var x", { expectedOutput: "var x;\r\n", options: { fileName: "a\\b.ts" }});
276+
});
273277
});
274278
}

0 commit comments

Comments
 (0)
0