Merge pull request #4627 from Microsoft/backslashesInTranspile

allow backslashes in fileName argument of the transpile function
This commit is contained in:
Vladimir Matveev 2015-09-03 13:29:27 -07:00
commit 4f4c8ee12d
2 changed files with 7 additions and 3 deletions

View File

@ -1866,7 +1866,7 @@ namespace ts {
let sourceMapText: string;
// Create a compilerHost object to allow the compiler to read and write files
let compilerHost: CompilerHost = {
getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined,
getSourceFile: (fileName, target) => fileName === normalizeSlashes(inputFileName) ? sourceFile : undefined,
writeFile: (name, text, writeByteOrderMark) => {
if (fileExtensionIs(name, ".map")) {
Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`);

View File

@ -64,8 +64,8 @@ module ts {
let transpileModuleResultWithSourceMap = transpileModule(input, transpileOptions);
assert.isTrue(transpileModuleResultWithSourceMap.sourceMapText !== undefined);
let expectedSourceMapFileName = removeFileExtension(transpileOptions.fileName) + ".js.map";
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName))) + ".js.map";
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
if (testSettings.expectedOutput !== undefined) {
assert.equal(transpileModuleResultWithSourceMap.outputText, testSettings.expectedOutput + expectedSourceMappingUrlLine);
@ -270,5 +270,9 @@ var x = 0;`,
expectedOutput: output
});
});
it("Supports backslashes in file name", () => {
test("var x", { expectedOutput: "var x;\r\n", options: { fileName: "a\\b.ts" }});
});
});
}