Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix source map with multibyte characters #5988

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/source-map-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ var SourceMapUtils = {
var column = 0;

source.forEach(function (character) {
let loc = { line, column };
if (character === "\n") {
line += 1;
column = -1;

mapping.push({
loc = {
line: line,
column: 0
});
} else {
mapping.push({
line: line,
column: column
});
};
}

for (let i = 0; i < Buffer.from(character).length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a comment on this loop. Something like, "because our offsets are given in bytes rather than in characters, we pad out the line/column map as per the UTF-8 length of the character". I think that will make this clearer for future maintainers.

mapping.push(loc);
}
column += 1;
});

Expand Down