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 January 17, 2022 04:19
_superprop_getFoo = () => super.foo;

(function () {
_superprop_setFoo(_superprop_getFoo() ?? 4);
Copy link
Member

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

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 January 17, 2022 09:38
@magic-akari magic-akari marked this pull request as ready for review January 17, 2022 13:37
@magic-akari magic-akari marked this pull request as draft January 17, 2022 14:45
@magic-akari magic-akari marked this pull request as ready for review January 17, 2022 15:11
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Classes Spec: Logical Assignment Spec: Class Fields and removed Spec: Classes labels Jan 17, 2022
Copy link
Contributor

@JLHwung JLHwung left a 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 === "??";
Copy link
Contributor

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

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.

Comment on lines +402 to +406
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

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

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit a6ca39c into babel:main Jan 17, 2022
@magic-akari magic-akari deleted the fix/super-logical-assignment branch February 4, 2022 03:26
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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 A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields Spec: Logical Assignment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: logical assignment not handled in super property transforms
3 participants