-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CS2] Optimize do (...args) ->
blocks to use let
#4514
Comments
@isiahmeadows do you have some example current vs. desirable output? |
We need to make sure |
@vendethiel That was implied. I was just referring to |
do
blocks to use let
do (...args) ->
blocks to use let
Can you please provide examples? |
Here's an example: # CoffeeScript
res = do (i = 0) ->
while i < len
i += 1 if someCondition((s) -> i < s)
i += 1
i // Current JS
var res;
res = (function (i) {
while (i < len) {
if (someCondition(function (s) { return i < s })) i += 1;
i += 1;
}
return i;
})(0);
// Proposed JS
var res;
{
let i = 0;
while (i < len) {
if (someCondition(function (s) { return i < s })) i += 1;
i += 1;
}
res = i;
} (I know the ability to expand functions like that exists, because of how |
Basically this is a refactor of If you’d like to implement this as a PR I suppose it would be an improvement. I’m not going to keep the issue open though because I don’t think this is something the maintainers would prioritize for one of us to tackle; though if you want to give it a shot, by all means please submit a PR. |
I think this is pretty interesting, especially in the context of #2518. Something to consider though is that something = -> alert 'woah'
do something |
Blocks with
let
implicitly create closures, so you could optimize non-globaldo
blocks to uselet
rather than IIFEs to generate smaller, cleaner code.The text was updated successfully, but these errors were encountered: