diff --git a/README.md b/README.md index 3e78caf0..9498bade 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,12 @@ following attributes: 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/) +A `BasicSourceMapConsumer` also exposes the standard `ignoreList` field described +in the [source map specification](https://tc39.es/ecma426/#sec-source-map-format). +It falls back to `x_google_ignoreList` only when `ignoreList` is absent, or `null` +when neither is present. An explicit empty array takes precedence over the +legacy field. The `x_google_ignoreList` property retains the legacy field's value. + The promise of the constructed souce map consumer is returned. When the `SourceMapConsumer` will no longer be used anymore, you must call its diff --git a/lib/source-map-consumer.js b/lib/source-map-consumer.js index 7381a668..6c95a91c 100644 --- a/lib/source-map-consumer.js +++ b/lib/source-map-consumer.js @@ -220,6 +220,11 @@ class BasicSourceMapConsumer extends SourceMapConsumer { that._mappings = mappings; that._sourceMapURL = aSourceMapURL; that.file = file; + that.ignoreList = util.getArg( + sourceMap, + "ignoreList", + x_google_ignoreList + ); that.x_google_ignoreList = x_google_ignoreList; that._computedColumnSpans = false; diff --git a/source-map.d.ts b/source-map.d.ts index 45646052..59f6256e 100644 --- a/source-map.d.ts +++ b/source-map.d.ts @@ -20,6 +20,8 @@ export interface RawSourceMap { sourcesContent?: string[]; mappings: string; file: string; + ignoreList?: number[]; + x_google_ignoreList?: number[]; } export interface RawIndexMap extends StartOfSourceMap { @@ -294,6 +296,8 @@ export interface BasicSourceMapConsumer extends SourceMapConsumer { sourceRoot: string; sources: string[]; sourcesContent: string[]; + ignoreList: number[] | null; + x_google_ignoreList: number[] | null; } export interface BasicSourceMapConsumerConstructor { diff --git a/test/test-ignore-list.js b/test/test-ignore-list.js new file mode 100644 index 00000000..1caf6753 --- /dev/null +++ b/test/test-ignore-list.js @@ -0,0 +1,49 @@ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + +const { SourceMapConsumer } = require("../source-map"); + +const cases = [ + ["standard field", { ignoreList: [1] }, [1]], + ["legacy fallback", { x_google_ignoreList: [0] }, [0]], + ["standard precedence", { ignoreList: [1], x_google_ignoreList: [0] }, [1]], + ["empty standard field", { ignoreList: [], x_google_ignoreList: [0] }, []], + ["absent fields", {}, null], +]; + +for (const [name, fields, expected] of cases) { + exports["test ignoreList " + name] = async function (assert) { + const raw = { + version: 3, + sources: ["app.js", "vendor.js"], + names: [], + mappings: "AAAA,CCAA", + ...fields, + }; + for (const input of [raw, JSON.stringify(raw)]) { + await SourceMapConsumer.with(input, null, consumer => { + if (expected === null) { + assert.strictEqual(consumer.ignoreList, null); + } else { + assert.ok(Array.isArray(consumer.ignoreList)); + assert.equal(consumer.ignoreList.length, expected.length); + expected.forEach((sourceIndex, i) => { + assert.equal(consumer.ignoreList[i], sourceIndex); + assert.equal( + consumer.sources[sourceIndex], + raw.sources[sourceIndex] + ); + }); + } + // The legacy property continues to reflect only the legacy input. + assert.equal( + JSON.stringify(consumer.x_google_ignoreList), + JSON.stringify(fields.x_google_ignoreList || null) + ); + }); + } + }; +}