Skip to content

Commit 742bace

Browse files
committed
Add comment for posterity
1 parent 014fd4d commit 742bace

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/react-error-overlay/src/utils/unmapper.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ function count(search: string, string: string): number {
2727
return count;
2828
}
2929

30+
function normalizePath(_path: string): string {
31+
// `path.normalize` cleans a file path, (e.g. /foo//baz/..//bar/ becomes
32+
// /foo/bar/).
33+
// The web version of this module only provides POSIX support, so Windows
34+
// paths like C:\foo\\baz\..\\bar\ cannot be normalized.
35+
// A simple solution to this is to replace all `\` with `/`, then normalize
36+
// afterwards.
37+
//
38+
// Note:
39+
// `path.normalize` supports POSIX forward slashes on Windows, but not the
40+
// other way around. Converting all backslashes to forward slashes before
41+
// normalizing makes this cross platform if it were isomorphic (used server
42+
// side).
43+
return path.normalize(
44+
// Match contiguous backslashes
45+
_path.replace(/[\\]+/g, '/')
46+
);
47+
}
48+
3049
/**
3150
* Turns a set of mapped <code>StackFrame</code>s back into their generated code position and enhances them with code.
3251
* @param {string} fileUri The URI of the <code>bundle.js</code> file.
@@ -56,15 +75,15 @@ async function unmap(
5675
}
5776
let { fileName } = frame;
5877
if (fileName) {
59-
fileName = path.normalize(fileName.replace(/[\\]+/g, '/'));
78+
fileName = normalizePath(fileName);
6079
}
6180
if (fileName == null) {
6281
return frame;
6382
}
6483
const fN: string = fileName;
6584
const source = map
6685
.getSources()
67-
.map(s => s.replace(/[\\]+/g, '/'))
86+
.map(normalizePath)
6887
.filter(p => {
6988
p = path.normalize(p);
7089
const i = p.lastIndexOf(fN);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy