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

Handle logical assignment in super property transforms #14164

Merged
merged 6 commits into from Jan 17, 2022
Merged

Handle logical assignment in super property transforms #14164

merged 6 commits into from Jan 17, 2022

Conversation

magic-akari
Copy link
Contributor

@magic-akari magic-akari commented Jan 17, 2022

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

@magic-akari magic-akari marked this pull request as ready for review Jan 17, 2022
_superprop_getFoo = () => super.foo;
(function () {
_superprop_setFoo(_superprop_getFoo() ?? 4);
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Jan 17, 2022

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);

Copy link
Contributor Author

@magic-akari magic-akari Jan 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Thanks

@magic-akari magic-akari marked this pull request as draft Jan 17, 2022
@magic-akari magic-akari marked this pull request as ready for review Jan 17, 2022
@magic-akari magic-akari requested a review from nicolo-ribaudo Jan 17, 2022
@magic-akari magic-akari marked this pull request as draft Jan 17, 2022
@magic-akari magic-akari marked this pull request as ready for review Jan 17, 2022
@JLHwung JLHwung added PR: Bug Fix 🐛 Spec: Classes Spec: Logical Assignment Spec: Class Fields and removed Spec: Classes labels Jan 17, 2022
Copy link
Contributor

@JLHwung JLHwung left a comment

Thanks.

const value = assignmentPath.node.right;

assignmentPath.node.operator = "=";
const isLogicalAssignment = op === "||" || op === "&&" || op === "??";
Copy link
Contributor

@JLHwung JLHwung Jan 17, 2022

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.

Copy link
Contributor Author

@magic-akari magic-akari Jan 17, 2022

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.

@magic-akari magic-akari requested a review from JLHwung Jan 17, 2022
type LogicalOp = Parameters<typeof logicalExpression>[0];
type BinaryOp = Parameters<typeof binaryExpression>[0];

function isLogicalOp(op: string): op is LogicalOp {
return LOGICAL_OPERATORS.includes(op);
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Jan 17, 2022

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.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit a6ca39c into babel:main Jan 17, 2022
25 checks passed
@magic-akari magic-akari deleted the fix/super-logical-assignment branch Feb 4, 2022
@github-actions github-actions bot added the outdated label May 6, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR: Bug Fix 🐛 Spec: Class Fields Spec: Logical Assignment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants