RESOLVED DUPLICATE of bug 223533 182414
Async arrow function with var declaration has incorrect shadowing
https://bugs.webkit.org/show_bug.cgi?id=182414
Summary Async arrow function with var declaration has incorrect shadowing
Adam Klein
Reported 2018-02-01 17:02:21 PST
The following code, run in the shell, should print "7", but prints "undefined": (async (v) => { print(v); var v; })(7) Without "async", this gets the right answer.
Attachments
GSkachkov
Comment 1 2018-02-02 12:01:29 PST
Hmm, the same for common async function ``` (async function (v) { print(v); var v; })(7); ```
GSkachkov
Comment 2 2018-02-02 12:04:19 PST
Yeah and the same for generator and async generators
Yusuke Suzuki
Comment 3 2018-02-02 12:21:24 PST
Hm, shoud it print 7? Why doesn’t “var” hide?
GSkachkov
Comment 4 2018-02-02 12:59:07 PST
(In reply to Yusuke Suzuki from comment #3) > Hm, shoud it print 7? Why doesn’t “var” hide? I cann't find this rule in current spec but it was in ES5, there is a exist old tests: ``` https://github.com/tc39/test262/blob/master/test/language/function-code/S10.2.1_A5.2_T1.js https://github.com/tc39/test262/blob/master/test/language/function-code/S10.2.1_A5.1_T2.js ```
Adam Klein
Comment 5 2018-02-02 13:15:06 PST
See step 27 of https://tc39.github.io/ecma262/#sec-functiondeclarationinstantiation. Basically, if a var-declared name has the same name as a parameter (and there aren't any parameter expressions, i.e., default parameter values or destructuring), the var declaration is ignored.
Mats Åhlberg
Comment 6 2021-05-14 04:34:21 PDT
When running code through uglify-js it generates this type of code which breaks. var b=async (t,a,r)=> { console.log(a); var a = a; console.log(t); console.log(a); console.log(r); return { t, a, r }; }; b(1, 2, 3); replacing the var a = 1; with a=a works. the first console log says undefined when the var is left. the code works in firefox and chrome. so is this a bug in webkit or the other browsers?
Radar WebKit Bug Importer
Comment 7 2023-08-14 18:46:59 PDT
Alexey Shvayka
Comment 8 2023-10-15 11:58:56 PDT
*** This bug has been marked as a duplicate of bug 223533 ***
Note You need to log in before you can comment on or make changes to this bug.