Skip to content

Commit

Permalink
Merge pull request #481 from bomsy/master
Browse files Browse the repository at this point in the history
Add support for the sourcemaps ignorelist
  • Loading branch information
bomsy committed Apr 4, 2023
2 parents 4e304db + b2ddafe commit 6cc15e1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -240,6 +240,10 @@ following attributes:

- `file`: Optional. The generated filename this source map is associated with.

- `x_google_ignoreList`: Optional. An additional extension field which is an array
of indices refering to urls in the sources array. This is used to identify third-party
sources, that the developer might want to avoid when debugging. [Read more](https://developer.chrome.com/articles/x-google-ignore-list/)

The promise of the constructed souce map consumer is returned.

When the `SourceMapConsumer` will no longer be used anymore, you must call its
Expand Down
6 changes: 6 additions & 0 deletions lib/source-map-consumer.js
Expand Up @@ -187,6 +187,11 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
const sourcesContent = util.getArg(sourceMap, "sourcesContent", null);
const mappings = util.getArg(sourceMap, "mappings");
const file = util.getArg(sourceMap, "file", null);
const x_google_ignoreList = util.getArg(
sourceMap,
"x_google_ignoreList",
null
);

// Once again, Sass deviates from the spec and supplies the version as a
// string rather than a number, so we use loose equality checking here.
Expand Down Expand Up @@ -215,6 +220,7 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
that._mappings = mappings;
that._sourceMapURL = aSourceMapURL;
that.file = file;
that.x_google_ignoreList = x_google_ignoreList;

that._computedColumnSpans = false;
that._mappingsPtr = 0;
Expand Down
11 changes: 11 additions & 0 deletions test/test-source-map-consumer.js
Expand Up @@ -88,6 +88,17 @@ exports["test that the `sources` field has the original sources"] =
map.destroy();
};

exports["test that the SourceMapConsumer supports the ignoreList"] =
async function (assert) {
const map = await new SourceMapConsumer(util.testMapWithIgnoreList);
const sources = map.sources;
const ignoreList = map.x_google_ignoreList;
assert.equal(ignoreList.length, 1);
assert.equal(ignoreList[0], 0);
assert.equal(sources[ignoreList[0]], "/the/root/one.js");
map.destroy();
};

exports["test that the source root is reflected in a mapping's source field"] =
async function (assert) {
let map;
Expand Down
12 changes: 12 additions & 0 deletions test/util.js
Expand Up @@ -37,6 +37,18 @@ exports.testMap = {
mappings:
"CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA",
};

exports.testMapWithIgnoreList = {
version: 3,
file: "min.js",
names: ["bar", "baz", "n"],
sources: ["one.js", "two.js"],
sourceRoot: "/the/root",
mappings:
"CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA",
x_google_ignoreList: [0],
};

exports.testMapNoSourceRoot = {
version: 3,
file: "min.js",
Expand Down
Binary file added wasm-mappings/.DS_Store
Binary file not shown.

0 comments on commit 6cc15e1

Please sign in to comment.