use path library to normalize filepath
Thomas Broadley committed
Oct 31, 2015 at 07:38 UTC
d77e161f99d09c55ca3134419cc2428df331d96e
1 file changed
+7
-8
scripts/jest/ts-preprocessor.js
+7
-8
@@ -19,15 +19,14 @@ function compile(content, contentFilename) {
19
var output = null;
20
var compilerHost = {
21
getSourceFile: function(filename, languageVersion) {
22
- var source, reactRegex;
22
+ var source;
23
24
- // Accomodations for backslashes in Windows file paths.
25
- if (process.platform === 'win32') {
26
- filename = filename.replace(/\//g, '\\');
27
- reactRegex = /\\(?:React|ReactDOM)(?:\.d)?\.ts$/;
28
- } else {
29
- reactRegex = /\/(?:React|ReactDOM)(?:\.d)?\.ts$/;
30
- }
24
+ // `path.normalize` and `path.join` are used to turn forward slashes in
25
+ // the file path into backslashes on Windows.
26
+ filename = path.normalize(filename);
27
+ var reactRegex = new RegExp(
28
+ path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$')
29
+ );
30
31
if (filename === 'lib.d.ts') {
32
source = fs.readFileSync(