Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overwrite segments for removed code #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
10 changes: 9 additions & 1 deletion src/utils/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ export default class Mappings {
let originalCharIndex = chunk.start;
let first = true;

let len = this.rawSegments.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rather call this something more explanatory, perhaps:

let checkDuplicateSegmentIndex = this.rawSegments.length - 1;

while (originalCharIndex < chunk.end) {
if (this.hires || first || sourcemapLocations[originalCharIndex]) {
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
if (len !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would then become if (checkDuplpicateSegmentIndex !== -1)

const segment = this.rawSegments[len - 1];
if (segment[0] === this.generatedCodeColumn) {
len -= 1; // overwrite segments for removed code
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes to len can be unnecessary if you just modify the last segment directly:

this.rawSegments[checkDuplicateSegmentIndex] = [...];

}
}
this.rawSegments[len++] = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
Copy link
Contributor

Choose a reason for hiding this comment

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

The default path should be able to then revert to a .push as before.

}

if (original[originalCharIndex] === '\n') {
len = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

And this becomes checkDuplicateSegmentIndex = -1 making it clearer this is a switch on the loop.

loc.line += 1;
loc.column = 0;
this.generatedCodeLine += 1;
Expand Down