-
Notifications
You must be signed in to change notification settings - Fork 2k
Properly update location data when setting a call to use new
#4445
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
Properly update location data when setting a call to use new
#4445
Conversation
This is an upstream port of decaffeinate#24 In a case like `new A().b(c)`, the jison structure ends up being different from the resulting AST. To the jison parser, this is the `new` unary operator applied to the expression `A().b(c)`. When the unary operator is applied, the `Call.prototype.newInstance` function traverses into the leftmost function call and sets the `isNew` flag to true, and the `Op` constructor returns the `Call` node so that the call is used in place of the unary operator. However, the code wasn't updating the node location data, so this commit fixes that. It's sort of hard to get the location data in `newInstance`, so we set a flag on every affected node in `newInstance` and override `updateLocationDataIfMissing` (which is called with the location data after the fact) so that it updates just the starting position.
|
|
||
| assertColumnRange assign, 0, 15 | ||
| assertColumnRange outerCall, 4, 15 | ||
| assertColumnRange innerValue, 4, 12 |
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.
Why 12 here? (I'm having a bit of a difficulty mapping outerCall, innerValue and innerCall to the corresponding parts of source.)
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.
outerCall is new B().c(d)
innerValue is new B().c
innerCall is new B()
All three of these needed to have their locations updated by this change, since previously they ignored the new on the left.
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, looks like I got those right after all. And when counting again, I get it to 12, too. False alarm!
lydell
left a comment
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.
LGTM
|
@alangpierce I’ve merged this into the |
|
@GeoffreyBooth ok, I looked into it and put up #4447. |
…ocation-data Properly update location data when setting a call to use `new`
This is an upstream port of decaffeinate#24
In a case like
new A().b(c), the jison structure ends up being different fromthe resulting AST. To the jison parser, this is the
newunary operator appliedto the expression
A().b(c). When the unary operator is applied, theCall.prototype.newInstancefunction traverses into the leftmost function calland sets the
isNewflag to true, and theOpconstructor returns theCallnode so that the call is used in place of the unary operator. However, the code
wasn't updating the node location data, so this commit fixes that.
It's sort of hard to get the location data in
newInstance, so we set a flag onevery affected node in
newInstanceand overrideupdateLocationDataIfMissing(which is called with the location data after the fact) so that it updates just
the starting position.