fix for TypeScript test on Windows

This commit is contained in:
Thomas Broadley
2015-10-30 10:22:50 +09:00
parent b8f502b224
commit d80710b0ae

View File

@@ -19,7 +19,16 @@ function compile(content, contentFilename) {
var output = null;
var compilerHost = {
getSourceFile: function(filename, languageVersion) {
var source;
var source, reactRegex;
// Accomodations for backslashes in Windows file paths.
if (process.platform === 'win32') {
filename = filename.replace(/\//g, '\\');
reactRegex = /\\(?:React|ReactDOM)(?:\.d)?\.ts$/;
} else {
reactRegex = /\/(?:React|ReactDOM)(?:\.d)?\.ts$/;
}
if (filename === 'lib.d.ts') {
source = fs.readFileSync(
require.resolve('typescript/bin/lib.d.ts')
@@ -30,7 +39,7 @@ function compile(content, contentFilename) {
).toString();
} else if (filename === contentFilename) {
source = content;
} else if (/\/(?:React|ReactDOM)(?:\.d)?\.ts$/.test(filename)) {
} else if (reactRegex.test(filename)) {
// TypeScript will look for the .d.ts files in each ancestor directory,
// so there may not be a file at the referenced path as it climbs the
// hierarchy.