Skip to content

Commit d77e161

Browse files
committed
use path library to normalize filepath
1 parent d80710b commit d77e161

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

scripts/jest/ts-preprocessor.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ function compile(content, contentFilename) {
1919
var output = null;
2020
var compilerHost = {
2121
getSourceFile: function(filename, languageVersion) {
22-
var source, reactRegex;
22+
var source;
2323

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+
);
3130

3231
if (filename === 'lib.d.ts') {
3332
source = fs.readFileSync(

0 commit comments

Comments
 (0)