Skip to content

Commit

Permalink
Updated normalizeSourcePath() to match source-map-js implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 19, 2021
1 parent 8f69464 commit c65364d
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ const REACT_SOURCES_EXTENSION_KEY = 'x_react_sources';
const FB_SOURCES_EXTENSION_KEY = 'x_facebook_sources';

/**
* Extracted from the logic in source-map@0.8.0-beta.0's SourceMapConsumer.
* By default, source names are normalized using the same logic that the
* `source-map@0.8.0-beta.0` package uses internally. This is crucial for keeping the
* sources list in sync with a `SourceMapConsumer` instance.
* Extracted from the logic in source-map-js@0.6.2's SourceMapConsumer.
* By default, source names are normalized using the same logic that the `source-map-js@0.6.2` package uses internally.
* This is crucial for keeping the sources list in sync with a `SourceMapConsumer` instance.
*/
function normalizeSourcePath(
sourceInput: string,
Expand All @@ -41,6 +40,18 @@ function normalizeSourcePath(

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

Expand Down

0 comments on commit c65364d

Please sign in to comment.