-
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
Fix #1403: Variables inconsistently masked inside of do
#4854
Conversation
Before we jettison I did some testing, and on
I pulled those tests into their own file and compiled them into JS using both A minimal case seems to be this: for i in [1..3] then do -> console.log i On var fn, i, j;
fn = function() {
return console.log(i);
};
for (i = j = 1; j <= 3; i = ++j) {
fn();
} Per this PR: var i, j;
for (i = j = 1; j <= 3; i = ++j) {
(function() {
return console.log(i);
})();
} Both versions print 4e39e2e has this test added, in obsolete CoffeeScript syntax: # If the last expression is dynamic call,
# define it outside and pass loop variables to it.
fs = for i from 0 to 2 when i > 0
void
do ->
{callee} = arguments
-> [i, callee]
[one, two] = (f() for f in fs)
eq one[0], 1
eq two[0], 2
eq one[1], two[1] Even converting this into modern syntax: fs = for i in [0..2] when i > 0
do ->
{callee} = arguments
-> [i, callee]
[one, two] = (f() for f in fs)
eq one[0], 1
eq two[0], 2
eq one[1], two[1] none of these tests pass, assuming I converted it correctly. Perhaps |
@GeoffreyBooth my memory is a bit fuzzy because it's been a long time... But AFAIK not defining the function inside the loop is an optimization (see coco's wiki page "Additions"). |
Also, paging @satyr about some reasoning from 2010 is probably not going to work... |
Ah, an optimization makes sense. Well, it's not really worth keeping if it's buggy, which it appears to be; and it's an optimization the user could do themselves. If they want the function defined before the loop and referenced in the loop, they could write their code as such. So this looks good to me. @vendethiel, any notes? And have we lost @satyr? |
LGTM. As for @satyr, I think their last commit was a few years back, so we'd have to wait for a while. |
This may lead to non-trivial performance degradations for code using the old for a in [1, 2, 3] then do ->
setTimeout (-> console.log a), 1000 |
…ariables (#4853) * fix #2047 * Additional check for 'step'; tests * Fix #4105 (#4855) * Update output * Throw warning for unsupported runtimes, e.g. Node < 6 (#4839) * fix #1403 (#4854) * Update output * [Change]: Destructuring with non-final spread should still use rest syntax (#4517) (#4825) * destructuring optimization * refactor * minor improvement, fix errors * minor refactoring * improvements * Update output * Update output * Fix #4843: bad output when assigning to @prop in destructuring assignment with defaults (#4848) * fix #4843 * improvements * typo * small fix * Fix #3441: parentheses wrapping expression throw invalid error (#4849) * fix #3441 * improvements * refactor * Fix #1726: expression in property access causes unexpected results (#4851) * fix #1726 * Explain what's happening, rather than just linking to an issue * Updated output * Optimization * Update output * remove casting to number * cleanup tests
Fixes #1403.
It seems that
For::pluckDirectCall
isn't needed.Examples from #1403