-
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
Inconsistent default handling in destructured arrays and arguments #4408
Comments
ES2015 for comparison: // throws: ReferenceError: bar is not defined
let meth = (foo = bar, bar) => console.log(foo, bar)
meth(undefined, "bar") // throws: ReferenceError: bar is not defined
// or, if using var: logs: undefined 'bar'
let [foo = bar, bar] = [undefined, "bar"]
console.log(foo, bar) // logs: foo foo
let meth = (foo, bar = foo) => console.log(foo, bar)
meth("foo", undefined) // logs: foo foo
let [foo, bar = foo] = ["foo", undefined]
console.log(foo, bar) |
Is this issue for 1.12.2 or for 2? |
1.12, though it might be an issue in 2 as well (I haven't tested) |
I think you could use the case from #4406 (destructured arguments) to show the same issue. The first example is definitely something else, though, since the params aren't destructured. That may actually be fixed in Edit: Except that you'd have to pass |
In #4478 your example compiles to (with var bar, foo, meth;
meth = function(foo = bar, bar) {
return console.log(foo, bar);
};
meth(void 0, "bar");
[foo = bar, bar] = [void 0, "bar"];
console.log(foo, bar);
meth = function(foo, bar = foo) {
return console.log(foo, bar);
};
meth("foo", void 0);
[foo, bar = foo] = ["foo", void 0];
console.log(foo, bar); Running it generates the same output as @lydell’s ES2015 example (first two are I would consider this to be fixed in CS2 via #4478. I don’t plan on many (if any) more bug fixes for CS1, but pull requests are welcome 😄 |
So, is reference error to be expected? Asking because I expect I'll need to update my linter soon enough |
Yes, in the first two when you have |
Possibly related to #4406
The text was updated successfully, but these errors were encountered: