Skip to content

Commit c65364d

Browse files
author
Brian Vaughn
committed
Updated normalizeSourcePath() to match source-map-js implementation
1 parent 8f69464 commit c65364d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/react-devtools-extensions/src/SourceMapMetadataConsumer.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ const REACT_SOURCES_EXTENSION_KEY = 'x_react_sources';
2727
const FB_SOURCES_EXTENSION_KEY = 'x_facebook_sources';
2828

2929
/**
30-
* Extracted from the logic in [email protected]'s SourceMapConsumer.
31-
* By default, source names are normalized using the same logic that the
32-
* `[email protected]` package uses internally. This is crucial for keeping the
33-
* sources list in sync with a `SourceMapConsumer` instance.
30+
* Extracted from the logic in [email protected]'s SourceMapConsumer.
31+
* By default, source names are normalized using the same logic that the `[email protected]` package uses internally.
32+
* This is crucial for keeping the sources list in sync with a `SourceMapConsumer` instance.
3433
*/
3534
function normalizeSourcePath(
3635
sourceInput: string,
@@ -41,6 +40,18 @@ function normalizeSourcePath(
4140

4241
// eslint-disable-next-line react-internal/no-primitive-constructors
4342
source = String(source);
43+
// Some source maps produce relative source paths like "./foo.js" instead of
44+
// "foo.js". Normalize these first so that future comparisons will succeed.
45+
// See bugzil.la/1090768.
46+
source = util.normalize(source);
47+
// Always ensure that absolute sources are internally stored relative to
48+
// the source root, if the source root is absolute. Not doing this would
49+
// be particularly problematic when the source root is a prefix of the
50+
// source (valid, but why??). See github issue #199 and bugzil.la/1188982.
51+
source =
52+
sourceRoot != null && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
53+
? util.relative(sourceRoot, source)
54+
: source;
4455
return util.computeSourceURL(sourceRoot, source);
4556
}
4657

0 commit comments

Comments
 (0)