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

Conversation

aleclarson
Copy link

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.

Not sure how useful this is yet.
@mourner
Copy link
Collaborator

mourner commented Jun 18, 2018

@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.

Copy link
Contributor

@guybedford guybedford left a 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;
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)

if (len !== 0) {
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] = [...];

len -= 1; // overwrite segments for removed code
}
}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants