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: Avoid internally generating negative source maps columns #15719
Conversation
liuxingbaoyu
commented
Jun 23, 2023
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #15712 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | √ |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
it("should not throw when loc.column === 0 with inputSourceMap", () => { | ||
const ast = parseExpression("a(\n)"); | ||
|
||
ast.loc.end.column = 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.
Can we construct a test without AST location mutations? If not it may point to a downstream issue and we can provide a better error message.
The current _normalizePosition
implementation will also throw if any external tool sets ast.loc.end.line
to -1
. If we decide to mute such errors, we should also handle the .line
info.
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 happened in a complex Angular project, and I thought it was a downstream bug, but since it's a regression, I took this approach.
The current _normalizePosition implementation will also throw if any external tool sets ast.loc.end.line to -1. If we decide to mute such errors, we should also handle the .line info.
You are right, but the reason for this regression is that we internally added columnOffset
resulting in a possible -1
, and lineOffset
is not currently actually used, I'm not sure about doing the same.
Maybe we can remove lineOffset
?
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.
Anything new here ? It would be awesome to have this fix :)
target.line = pos.line + lineOffset; | ||
target.column = pos.column + columnOffset; | ||
target.line = pos.line; | ||
target.column = Math.max(pos.column + columnOffset, 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.
Can you add a note here to #15712? So that we can investigate this issue in the future.
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 changes look good, but I would like to learn more about the underlying cause of this problem (not a blocker for this PR)