-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix sourcemaps failing on refresh #1755
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,12 +79,14 @@ class SourceMap { | |
} | ||
|
||
addMapping(mapping, lineOffset = 0, columnOffset = 0) { | ||
mapping.generated = { | ||
line: mapping.generated.line + lineOffset, | ||
column: mapping.generated.column + columnOffset | ||
}; | ||
|
||
this.mappings.push(mapping); | ||
this.mappings.push({ | ||
source: mapping.source, | ||
original: mapping.original, | ||
generated: { | ||
line: mapping.generated.line + lineOffset, | ||
column: mapping.generated.column + columnOffset | ||
} | ||
}); | ||
} | ||
|
||
addConsumerMapping(mapping, lineOffset = 0, columnOffset = 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, the handling below here seems questionable. Mappings with no original location are still important because they terminate the end of a conceptual range over the generated file by saying that a generated location points at nothing. By discarding mappings with no original location, you're essentially force-extending every generated mapping to instead extend to the end of the line/next original-location mapping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this would be an issue, if code is generated it shouldn't have a mapping right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite. Sourcemaps are conceptually ranges over the generated code, but the actual mappings passed from the consumer are single points of data, from one generated line/col to an original line/col (optionally). It's the fact that the original part is option that is critical here, and that is getting lost with the check in
Imagine a generated piece of code like this:
If I want to map just the
to say that the start of the word "console" (line 0, column 0) maps to the original file, also at line 0 column 0. So far so good, but nothing sets an end position, so that mapping on its own would also apply to the That's where non-
to say that, starting at line 0, column 7, the code maps to nothing in the original file. By discarding that information, you've essentially made the original line 0 column 0 mapping apply to the whole of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ow I never saw that as an issue but I'll definitely look into it. Thank you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, I'm happy to answer any other sourcemap questions if you have them. Babel has had it's fair share of questionable mapping logic over the ears too. |
||
|
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.
Not familiar with this API, but does this
mapping
have a.name
? I see it used inaddConsumerMapping
, but not this one.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.
Ow it should, thanks for noticing