Skip to content

Commit

Permalink
fix: missing mapping after a line break with hires: 'boundary' (#298)
Browse files Browse the repository at this point in the history
* fix: missing mapping after line break with `hires: 'boundary'`

* chore: remove console.log
  • Loading branch information
sapphi-red authored Dec 16, 2024
1 parent dad9569 commit 24cb8ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class Mappings {
this.raw[this.generatedCodeLine] = this.rawSegments = [];
this.generatedCodeColumn = 0;
first = true;
charInHiresBoundary = false;
} else {
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
Expand Down
30 changes: 30 additions & 0 deletions test/MagicString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,36 @@ describe('MagicString', () => {
assert.equal(loc.column, 33);
});

it('generates segments per word boundary with hires "boundary" in the next line', () => {
const s = new MagicString('// foo\nconsole.log("bar")');

// rename bar to hello
s.overwrite(20, 23, 'hello');

const map = s.generateMap({
file: 'output.js',
source: 'input.js',
includeContent: true,
hires: 'boundary',
});

assert.equal(
map.mappings,
'AAAA,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,GAAG,CAAC,CAAC,KAAG,CAAC',
);

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

loc = smc.originalPositionFor({ line: 2, column: 2 });
assert.equal(loc.line, 2);
assert.equal(loc.column, 0);

loc = smc.originalPositionFor({ line: 2, column: 12 });
assert.equal(loc.line, 2);
assert.equal(loc.column, 12);
});

it('generates a correct source map with update using a content containing a new line', () => {
const s = new MagicString('foobar');
s.update(3, 4, '\nbb');
Expand Down

0 comments on commit 24cb8ea

Please sign in to comment.