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
Fix plugin-transform-block-scoping const violations #13248
Fix plugin-transform-block-scoping const violations #13248
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 808a0e6:
|
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!
t.binaryExpression( | ||
violation.node.operator[0], | ||
violation.get("argument").node, | ||
t.numericLiteral(1), | ||
), |
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.
I think we can simplify this to t.unaryExpression("+", violation.get("argument").node)
(even if it saves literally a single byte).
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.
Yes, +c
has same effect of triggering .valueOf()
as c + 1
. Have added a commit to make this change.
I hadn't really bothered with optimization since in most cases code like this is a bug anyway.
Have also added another commit for the other most obvious optimization - shorten c = f()
to just f()
since the assignment will never be executed anyway. There are other optimizations which could be made (a += 'long_string'
to a + ''
for example), but in my view going further would add complexity for little gain.
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.
Added one more commit to shorten c &&= x++
-> c && x++
.
Thanks for merging. |
Fixes #13245.
Fix for #13245.
This PR fixes:
const c = 1; c = y++;
const c = 1; c += y++
const c = 1; c++
for in
- see addition tono-for-in/exec.js
test for what was previously failingThe tests are maybe written a bit weirdly. My intent was to keep
const
declarations in same function scope as they were previously, in case that's part of the purpose of the tests. It's a pain testing side effects of code that throws.I'm leaving the bugs with destructuring for someone else! When/if this PR is merged, I'll open a separate issue for that specifically.