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
add support for logical assignments with private properties #11702
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 25bfbf4:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/26333/ |
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.
awesome work, separating out logical/binary expression and a test case. I guess the others must be tested already? (||= &&=
)
@hzoo right, I'll add more tests for those. |
@hzoo PTAL now, I suppose this should suffice. Let me know if it needs any more work. |
packages/babel-helper-member-expression-to-functions/src/index.js
Outdated
Show resolved
Hide resolved
packages/babel-helper-member-expression-to-functions/src/index.js
Outdated
Show resolved
Hide resolved
We already support private properties and logical assignment, just not together. Would it be ok for you to mark this as a "Bug fix" (since it's just an integration problem) and merge it in a patch release? |
Right, I was unsure, thanks for letting me know. |
Thanks @nicolo-ribaudo @JLHwung and others, I fixed the code and the PR body. Hope this is better. |
...es/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js
Outdated
Show resolved
Hide resolved
Replace a hardcoded check for logical assignment operators with the LOGICAL_OPERATORS constant in plugin-proposal-logical-assignment-operators. Refs: babel#11702 (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.
Thanks!
...es/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js
Show resolved
Hide resolved
@@ -0,0 +1,11 @@ | |||
class Foo { |
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.
Please also duplicate the test to test/fixtures/private-loose
.
Friendly ping @ryzokuken :) |
Sorry @JLHwung, I'll finish it up this weekend. |
@jridgewell I pushed the test you asked for, but I still don't quite understand how to fix the memoization issue. Could you please elaborate what needs to be done in that regard? |
@@ -0,0 +1,6 @@ | |||
{ | |||
"plugins": [ | |||
"proposal-logical-assignment-operators", |
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 loose: true
to both plugins?
{
"plugins": [
["proposal-logical-assignment-operators", { "loose": true }],
["proposal-class-properties", { "loose": true }]
]
}
The private-loose
folder is test cases about loose
options so we are sure that both loose
and non-loose (default) are working.
@ryzokuken The memoization is done in babel/packages/babel-helper-member-expression-to-functions/src/index.js Lines 285 to 288 in 1dd94e8
The second argument // obj.self().#a = obj.self().#a + 1
classFieldSet($objSelf = obj.self(), a, classFieldGet($objSelf, a) + 1) via this.set(member, t.binaryExpression("+", this.get(member), value)) We should memoize However // obj.self().#a ?? (obj.self().#a = 1)
classFieldGet($objSelf = obj.self(), a) ?? classFieldSet($objSelf, a, 1)
// current PR
classFieldGet($objSelf, a) ?? classFieldSet($objSelf = obj.self(), a, 1) via t.LogicalExpression("??", this.get(member), this.set(member)) Note that the call sequence is unchanged -- // add some comment about why 1 is chosen for logical expressions
this.memoise(member, 1); |
Thank you for explaining @JLHwung, that's extremely thorough! |
@ryzokuken 🏓️ Logical Assignment is seeking advancement in July meeting, will be great if we can ship this bug fix after that. |
@JLHwung my bad, I'll get that done. |
Update: I've made the change, I'll push this in a bit, sorry for the delay. I got super busy with all sorts of weird things. |
@JLHwung does this look good enough? Let me know if it does and I'll autosquash and force push. |
@ryzokuken Can you update the test case (config/fixture) w.r.t. |
_classPrivateFieldGet(this, _nullish) ?? _classPrivateFieldSet(this, _nullish, 42); | ||
_classPrivateFieldGet(this, _and) && _classPrivateFieldSet(this, _and, 0); | ||
_classPrivateFieldGet(this, _or) || _classPrivateFieldSet(this, _or, 0); | ||
_classPrivateFieldGet(_this$self, _nullish) ?? _classPrivateFieldSet(_this$self = this.self(), _nullish, 42); |
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 test still needs to be updated. I believe the transform code is correct, the test is just out of date now.
@jridgewell @JLHwung the tests should be updated now. Sorry for the delay again, I noticed the stage advancement yesterday. |
The e2e was fixed on upstream main. Can you rebase? |
Replace a hardcoded check for logical assignment operators with the LOGICAL_OPERATORS constant in plugin-proposal-logical-assignment-operators. Refs: babel#11702 (comment)
Patches the logic for handling assignment operators and adds support for handling the logical assignment operators appropriately. Fixes: babel#11646
Replace a hardcoded check for logical assignment operators with the LOGICAL_OPERATORS constant in plugin-proposal-logical-assignment-operators. Refs: babel#11702 (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.
Justin's concern has been addressed. @ryzokuken Thanks for all the efforts!
Thanks for all the help on this, everyone! |
Patches the logic for handling assignment operators and adds support for
handling the logical assignment operators appropriately.