@@ -27,6 +27,25 @@ function count(search: string, string: string): number {
27
27
return count ;
28
28
}
29
29
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
+
30
49
/**
31
50
* Turns a set of mapped <code>StackFrame</code>s back into their generated code position and enhances them with code.
32
51
* @param {string } fileUri The URI of the <code>bundle.js</code> file.
@@ -56,15 +75,15 @@ async function unmap(
56
75
}
57
76
let { fileName } = frame ;
58
77
if ( fileName ) {
59
- fileName = path . normalize ( fileName . replace ( / [ \\ ] + / g , '/' ) ) ;
78
+ fileName = normalizePath ( fileName ) ;
60
79
}
61
80
if ( fileName == null ) {
62
81
return frame ;
63
82
}
64
83
const fN : string = fileName ;
65
84
const source = map
66
85
. getSources ( )
67
- . map ( s => s . replace ( / [ \\ ] + / g , '/' ) )
86
+ . map ( normalizePath )
68
87
. filter ( p => {
69
88
p = path . normalize ( p ) ;
70
89
const i = p . lastIndexOf ( fN ) ;
0 commit comments