Fix plugin-transform-block-scoping const violations#13248
Fix plugin-transform-block-scoping const violations#13248JLHwung merged 5 commits intobabel:mainfrom
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:
|
| t.binaryExpression( | ||
| violation.node.operator[0], | ||
| violation.get("argument").node, | ||
| t.numericLiteral(1), | ||
| ), |
There was a problem hiding this comment.
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.
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.
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.jstest for what was previously failingThe tests are maybe written a bit weirdly. My intent was to keep
constdeclarations 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.