Skip to content

Commit 8852c8d

Browse files
authored
fix: this.outro need to be mapped (#300)
1 parent fd1d887 commit 8852c8d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/MagicString.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ export default class MagicString {
168168
if (chunk.outro.length) mappings.advance(chunk.outro);
169169
});
170170

171+
if (this.outro) {
172+
mappings.advance(this.outro);
173+
}
174+
171175
return {
172176
file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
173177
sources: [

test/MagicString.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ describe('MagicString', () => {
279279
assert.equal(originLoc.column, 0);
280280
});
281281

282+
it('should generate a correct sourcemap including correct lines', () => {
283+
const s = new MagicString(
284+
'var answer = 42;\nconsole.log("the answer is %s", answer);'
285+
);
286+
s.append('\n\n\n\n}).call(global);');
287+
assert.equal(
288+
// output lines
289+
s.toString().split('\n').length,
290+
// sourcemap lines
291+
s.generateDecodedMap().mappings.length
292+
);
293+
});
294+
282295
it('should generate a sourcemap using specified locations', () => {
283296
const s = new MagicString('abcdefghijkl');
284297

0 commit comments

Comments
 (0)