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 option to block-scoping to throw on slow code #5236
Conversation
@spicyj, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hzoo, @ryb73 and @jayphelps to be potential reviewers. |
Codecov Report
@@ Coverage Diff @@
## master #5236 +/- ##
=========================================
Coverage ? 89.23%
=========================================
Files ? 203
Lines ? 9844
Branches ? 2625
=========================================
Hits ? 8784
Misses ? 1060
Partials ? 0
Continue to review full report at Codecov.
|
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.
Approach looks fine to me - Dono how much we want to change the error message is all?
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.
👍
Actually can you also update the readme for this option? (wish that check could be automated) Can use https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-es2015-classes/README.md#usage as a reference (usage/options explanation) |
85e52aa
to
27b7dc6
Compare
README updated. |
Happy to change the error message too if you like. It feels a little long to me. |
@@ -15,9 +15,19 @@ npm install --save-dev babel-plugin-transform-es2015-block-scoping | |||
**.babelrc** | |||
|
|||
```json | |||
// without options |
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.
Sorry, but since were using json now, can we move the without options outside like in https://github.com/babel/babel/pull/5194/files?
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.
(y)
Cool 👍 maybe cc @gaearon for suggestions as well |
27b7dc6
to
1e2ee42
Compare
Hey @spicyj! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
Can ignore ^, looks like timeout issues for babel-cli? |
^^ I assume these timeouts are random?
|
What about:
|
Excuse my ignorance, but are there any notes around on why a function is required over variable renaming in some cases? |
@glenjamin the only way to avoid a function in the loop case is by loop unrolling, which can only be done when all iteration variable values can be statically known. |
However, there are cases, like with a forEach rather than a setTimeout, where the closure behavior is not necessary and the code can be written in a different way without. |
Indeed - in that case the forEach already takes a function, so there's already a closure available. |
@ljharb when it escapes, there is no way for the transform to know if the closure call is sync or async. If there is any chance of it being async, the block needs to go through a closure layer to save the value. We could hardcode some names but that would still be a trap. For example, while Array.prototype.map is sync, require('bluebird').prototype.map isn't. |
@@ -14,12 +14,24 @@ npm install --save-dev babel-plugin-transform-es2015-block-scoping | |||
|
|||
**.babelrc** | |||
|
|||
Without options: |
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.
Could you add a new line before the code block, otherwise it won't be formatted correctly on the website.
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.
Addressed.
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 was just copying https://github.com/babel/babel/pull/5194/files like I was asked. :) Updated and cut the error message down a bit.
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.
Oops, sorry. I think GH collapsed that comment and I only saw the newer one. 😞
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.
@spicyj yeah. I'm sure we had issue with it.
Thanks for the update :)
The let/const plugin can add closures where you don't expect them. This is undesirable in some perf-sensitive projects (ex: React). I added an option that throws whenever the plugin adds a function (as opposed to simply renaming variables when converting to var).
bf2521a
to
53e694c
Compare
Test Plan: Patch in babel/babel#5236, run `grunt build:modules` with no errors.
Is this good to merge? |
Thanks @spicyj! 🙂 |
Thank you! |
The let/const plugin can add closures where you don't expect them. This is undesirable in some perf-sensitive projects (ex: React). I added an option that throws whenever the plugin adds a function (as opposed to simply renaming variables when converting to var).
The let/const plugin can add closures where you don't expect them. This is undesirable in some perf-sensitive projects (ex: React). I added an option that throws whenever the plugin adds a function (as opposed to simply renaming variables when converting to var).