Skip to content

Commit

Permalink
fix sourcemap of append/prepend when hire false (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe authored and mourner committed Oct 4, 2019
1 parent 51e7f5f commit 9f93acf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ export default class Mappings {
this.generatedCodeLine += 1;
this.raw[this.generatedCodeLine] = this.rawSegments = [];
this.generatedCodeColumn = 0;
first = true;
} else {
loc.column += 1;
this.generatedCodeColumn += 1;
first = false;
}

originalCharIndex += 1;
first = false;
}

this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
Expand Down
12 changes: 12 additions & 0 deletions test/MagicString.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ describe('MagicString', () => {
assert.equal(loc.column, 10);
});

it('should generate a correct sourcemap for prepend content when hires = false', () => {
const s = new MagicString('x\nq');

s.prepend('y\n');

const map = s.generateMap({
includeContent: true,
});

assert.equal(map.mappings,';AAAA;AACA');
});

it('should generate a correct sourcemap for indented content', () => {
const s = new MagicString('var answer = 42;\nconsole.log("the answer is %s", answer);');

Expand Down

0 comments on commit 9f93acf

Please sign in to comment.