Skip to content

Commit

Permalink
fix: missing mapping after line break with hires: 'boundary'
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 16, 2024
1 parent dad9569 commit 6247e9b
Show file tree
Hide file tree
Showing 2 changed files with 32 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
31 changes: 31 additions & 0 deletions test/MagicString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,37 @@ 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 });
console.log(loc.source)

Check failure on line 512 in test/MagicString.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*, ubuntu-latest)

Unexpected console statement

Check failure on line 512 in test/MagicString.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*, windows-latest)

Unexpected console statement

Check failure on line 512 in test/MagicString.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*, macos-latest)

Unexpected console statement
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 6247e9b

Please # to comment.