From 9ec643289e4982d3bb1923658d01364b28f6c612 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 26 Sep 2019 17:25:57 +0800 Subject: [PATCH] fix sourcemap of append/prepend when hire false --- src/utils/Mappings.js | 3 ++- test/MagicString.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils/Mappings.js b/src/utils/Mappings.js index bf872eb..5467e78 100644 --- a/src/utils/Mappings.js +++ b/src/utils/Mappings.js @@ -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]; diff --git a/test/MagicString.js b/test/MagicString.js index 206c1db..d3b65fc 100644 --- a/test/MagicString.js +++ b/test/MagicString.js @@ -203,6 +203,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);');