From d77e161f99d09c55ca3134419cc2428df331d96e Mon Sep 17 00:00:00 2001 From: Thomas Broadley Date: Sat, 31 Oct 2015 07:38:47 +0900 Subject: [PATCH] use path library to normalize filepath --- scripts/jest/ts-preprocessor.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/jest/ts-preprocessor.js b/scripts/jest/ts-preprocessor.js index ec10c03109..ecfa149d89 100644 --- a/scripts/jest/ts-preprocessor.js +++ b/scripts/jest/ts-preprocessor.js @@ -19,15 +19,14 @@ function compile(content, contentFilename) { var output = null; var compilerHost = { getSourceFile: function(filename, languageVersion) { - var source, reactRegex; + var source; - // 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$/; - } + // `path.normalize` and `path.join` are used to turn forward slashes in + // the file path into backslashes on Windows. + filename = path.normalize(filename); + var reactRegex = new RegExp( + path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$') + ); if (filename === 'lib.d.ts') { source = fs.readFileSync(