-
Notifications
You must be signed in to change notification settings - Fork 115
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
base: master
Are you sure you want to change the base?
Conversation
Not sure how useful this is yet.
@guybedford @lukastaegert what do you think? I'm not sure I fully understand the implications of this change for downstream users, so I'd refer to others for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for much @aleclarson for this PR.
This looks great in principle to me, but the test needs to be updated, and it would ideally come with another test that considers if there are any pathological edge cases of this behaviour - let me know if you can think of any interesting things that may come up here.
@@ -27,12 +27,20 @@ export default class Mappings { | |||
let originalCharIndex = chunk.start; | |||
let first = true; | |||
|
|||
let len = this.rawSegments.length; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
if (len !== 0) { | ||
const segment = this.rawSegments[len - 1]; | ||
if (segment[0] === this.generatedCodeColumn) { | ||
len -= 1; // overwrite segments for removed code |
There was a problem hiding this comment.
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] = [...];
len -= 1; // overwrite segments for removed code | ||
} | ||
} | ||
this.rawSegments[len++] = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Removed ranges create two source map segments that refer to the same generated column. I consider this bloat if there isn't a good reason behind it. Generally, there shouldn't be segments for removed code (not including the segment for the characters after, whose source column is the removed range's end column).
What's your take on this, @mourner and/or @Rich-Harris?
Figured I should get feedback before writing any tests.