Skip to content

Commit

Permalink
Don't emit source mappings for removed strings. (#159)
Browse files Browse the repository at this point in the history
Fixes #149

Also fixes two incorrect test results and the rollup issue:
rollup/rollup#3001
  • Loading branch information
kzc authored and mourner committed Oct 4, 2019
1 parent 2702447 commit 0c4d32f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/utils/Mappings.js
Expand Up @@ -48,7 +48,9 @@ export default class Mappings {
originalCharIndex += 1;
}

this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
this.pending = sourceIndex > 0
? [this.generatedCodeColumn, sourceIndex, loc.line, loc.column]
: null;
}

advance(str) {
Expand Down
10 changes: 5 additions & 5 deletions test/MagicString.js
Expand Up @@ -193,10 +193,10 @@ describe('MagicString', () => {
assert.equal(map.file, 'output.md');
assert.deepEqual(map.sources, ['input.md']);
assert.deepEqual(map.sourcesContent, ['abcdefghijkl']);
assert.equal(map.mappings, 'AAAA,CAAC,CAAC,CAAC,AAAM,CAAC,CAAC');
assert.equal(map.mappings, 'AAAA,CAAC,CAAC,CAAO,CAAC,CAAC');

assert.equal(map.toString(), '{"version":3,"file":"output.md","sources":["input.md"],"sourcesContent":["abcdefghijkl"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAC,AAAM,CAAC,CAAC"}');
assert.equal(map.toUrl(), 'data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0Lm1kIiwic291cmNlcyI6WyJpbnB1dC5tZCJdLCJzb3VyY2VzQ29udGVudCI6WyJhYmNkZWZnaGlqa2wiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsQ0FBQyxDQUFDLENBQUMsQUFBTSxDQUFDLENBQUMifQ==');
assert.equal(map.toString(), '{"version":3,"file":"output.md","sources":["input.md"],"sourcesContent":["abcdefghijkl"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAO,CAAC,CAAC"}');
assert.equal(map.toUrl(), 'data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0Lm1kIiwic291cmNlcyI6WyJpbnB1dC5tZCJdLCJzb3VyY2VzQ29udGVudCI6WyJhYmNkZWZnaGlqa2wiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsQ0FBQyxDQUFDLENBQU8sQ0FBQyxDQUFDIn0=');

const smc = new SourceMapConsumer(map);
let loc;
Expand Down Expand Up @@ -264,8 +264,8 @@ describe('MagicString', () => {
assert.deepEqual(map.sources, ['input.md']);
assert.deepEqual(map.sourcesContent, ['abcdefghijkl']);

assert.equal(map.toString(), '{"version":3,"file":"output.md","sources":["input.md"],"sourcesContent":["abcdefghijkl"],"names":[],"mappings":"AAAA,GAAG,GAAG,AAAG,CAAC"}');
assert.equal(map.toUrl(), 'data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0Lm1kIiwic291cmNlcyI6WyJpbnB1dC5tZCJdLCJzb3VyY2VzQ29udGVudCI6WyJhYmNkZWZnaGlqa2wiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxHQUFHLEFBQUcsQ0FBQyJ9');
assert.equal(map.toString(), '{"version":3,"file":"output.md","sources":["input.md"],"sourcesContent":["abcdefghijkl"],"names":[],"mappings":"AAAA,GAAG,GAAM,CAAC"}');
assert.equal(map.toUrl(), 'data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0Lm1kIiwic291cmNlcyI6WyJpbnB1dC5tZCJdLCJzb3VyY2VzQ29udGVudCI6WyJhYmNkZWZnaGlqa2wiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxHQUFNLENBQUMifQ==');

const smc = new SourceMapConsumer(map);
let loc;
Expand Down

0 comments on commit 0c4d32f

Please sign in to comment.