Skip to content

Commit 24cb8ea

Browse files
authored
fix: missing mapping after a line break with hires: 'boundary' (#298)
* fix: missing mapping after line break with `hires: 'boundary'` * chore: remove console.log
1 parent dad9569 commit 24cb8ea

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/utils/Mappings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class Mappings {
6161
this.raw[this.generatedCodeLine] = this.rawSegments = [];
6262
this.generatedCodeColumn = 0;
6363
first = true;
64+
charInHiresBoundary = false;
6465
} else {
6566
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
6667
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];

test/MagicString.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,36 @@ describe('MagicString', () => {
487487
assert.equal(loc.column, 33);
488488
});
489489

490+
it('generates segments per word boundary with hires "boundary" in the next line', () => {
491+
const s = new MagicString('// foo\nconsole.log("bar")');
492+
493+
// rename bar to hello
494+
s.overwrite(20, 23, 'hello');
495+
496+
const map = s.generateMap({
497+
file: 'output.js',
498+
source: 'input.js',
499+
includeContent: true,
500+
hires: 'boundary',
501+
});
502+
503+
assert.equal(
504+
map.mappings,
505+
'AAAA,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,GAAG,CAAC,CAAC,KAAG,CAAC',
506+
);
507+
508+
const smc = new SourceMapConsumer(map);
509+
let loc;
510+
511+
loc = smc.originalPositionFor({ line: 2, column: 2 });
512+
assert.equal(loc.line, 2);
513+
assert.equal(loc.column, 0);
514+
515+
loc = smc.originalPositionFor({ line: 2, column: 12 });
516+
assert.equal(loc.line, 2);
517+
assert.equal(loc.column, 12);
518+
});
519+
490520
it('generates a correct source map with update using a content containing a new line', () => {
491521
const s = new MagicString('foobar');
492522
s.update(3, 4, '\nbb');

0 commit comments

Comments
 (0)