Skip to content

Commit 3c711cd

Browse files
committed
feat(x_google_ignoreList): initial support for ignore lists
This patch introduces support for the `x_google_ignoreList` field to the `SourceMap` class. This extension was added to the Source Map Revision 3 Proposal[^1] to allow build tools to provide hints to debuggers (e.g. browser DevTools) about which files contain library or framework, and should thus be ignored by default for the purpose of stepping, break on exceptions, and the like[^2]. With this change it's possible for consumers of magic-string's `SourceMap` class to thread through and serialize the newly added `x_google_ignoreList` field (for example this is needed for rollup to support `x_google_ignoreList`). In a follow up change, we will also add support to the `Bundle` class to mark certain sources as ignore listed. [^1]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k [^2]: https://developer.chrome.com/blog/devtools-better-angular-debugging/
1 parent c2b652a commit 3c711cd

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface DecodedSourceMap {
3838
sourcesContent: (string | null)[];
3939
names: string[];
4040
mappings: SourceMapSegment[][];
41+
x_google_ignoreList?: number[];
4142
}
4243

4344
export class SourceMap {
@@ -49,6 +50,7 @@ export class SourceMap {
4950
sourcesContent: (string | null)[];
5051
names: string[];
5152
mappings: string;
53+
x_google_ignoreList?: number[];
5254

5355
/**
5456
* Returns the equivalent of `JSON.stringify(map)`

src/SourceMap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export default class SourceMap {
2222
this.sourcesContent = properties.sourcesContent;
2323
this.names = properties.names;
2424
this.mappings = encode(properties.mappings);
25+
if (typeof properties.x_google_ignoreList !== 'undefined') {
26+
this.x_google_ignoreList = properties.x_google_ignoreList;
27+
}
2528
}
2629

2730
toString() {

test/MagicString.SourceMap.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const assert = require('assert');
2+
const MagicString = require('../');
3+
4+
require('source-map-support').install();
5+
6+
describe('MagicString.SourceMap', () => {
7+
describe('options', () => {
8+
it('preserves ignore list information', () => {
9+
const map = new MagicString.SourceMap({
10+
file: 'foo.min.js',
11+
sources: ['foo.js'],
12+
sourcesContent: ['42'],
13+
names: [],
14+
mappings: [[0, 0]],
15+
x_google_ignoreList: [0]
16+
});
17+
18+
assert.deepEqual(map.x_google_ignoreList, [0]);
19+
});
20+
});
21+
22+
describe('toString', () => {
23+
it('serializes ignore list information', () => {
24+
const map = new MagicString.SourceMap({
25+
file: 'foo.min.js',
26+
sources: ['foo.js'],
27+
sourcesContent: ['42'],
28+
names: [],
29+
mappings: [[0, 0]],
30+
x_google_ignoreList: [0]
31+
});
32+
33+
assert.equal(map.toString(), '{"version":3,"file":"foo.min.js","sources":["foo.js"],"sourcesContent":["42"],"names":[],"mappings":"AAAAA,AAAAA","x_google_ignoreList":[0]}');
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)