Skip to content

Commit de013f3

Browse files
committed
misc(jest-haste-map): simplified checking of the beginning of a pathname
1 parent 7cf3b8d commit de013f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/jest-haste-map/src/lib/fast_path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99

1010
// rootDir and filename must be absolute paths (resolved)
1111
export function relative(rootDir: string, filename: string): string {
12-
return filename.indexOf(rootDir + path.sep) === 0
12+
return filename.startsWith(rootDir + path.sep)
1313
? filename.slice(rootDir.length + 1)
1414
: path.relative(rootDir, filename);
1515
}
@@ -19,7 +19,7 @@ const INDIRECTION_FRAGMENT = `..${path.sep}`;
1919
// rootDir must be an absolute path and relativeFilename must be simple
2020
// (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar)
2121
export function resolve(rootDir: string, relativeFilename: string): string {
22-
return relativeFilename.indexOf(INDIRECTION_FRAGMENT) === 0
22+
return relativeFilename.startsWith(INDIRECTION_FRAGMENT)
2323
? path.resolve(rootDir, relativeFilename)
2424
: rootDir + path.sep + relativeFilename;
2525
}

0 commit comments

Comments
 (0)