-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Handle logical assignment in super property transforms #14164
Handle logical assignment in super property transforms #14164
Conversation
magic-akari
commented
Jan 17, 2022
•
edited by gitpod-io
bot
Loading
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #14163 |
Patch: Bug Fix? | 👍 |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
_superprop_getFoo = () => super.foo; | ||
|
||
(function () { | ||
_superprop_setFoo(_superprop_getFoo() ?? 4); |
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.
Logical expressions short-circuit, so this should become something like
_superprop_getFoo() ?? _superprop_setFoo(4);
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.
Ah, Thanks
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.
const value = assignmentPath.node.right; | ||
|
||
assignmentPath.node.operator = "="; | ||
const isLogicalAssignment = op === "||" || op === "&&" || op === "??"; |
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.
nit: @babel/types
exports LOGICAL_OPERATORS
so we don't have to hardcode them.
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.
Updated.
Type narrowing is hard.
type LogicalOp = Parameters<typeof logicalExpression>[0]; | ||
type BinaryOp = Parameters<typeof binaryExpression>[0]; | ||
|
||
function isLogicalOp(op: string): op is LogicalOp { | ||
return LOGICAL_OPERATORS.includes(op); |
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.
If TS allows const
and type
with the same name, we could even export type LOGICAL_OPERATORS = "||" | "&&" | "??"
from @babel/types
.
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!