Bug 182414 - Async arrow function with var declaration has incorrect shadowing
Summary: Async arrow function with var declaration has incorrect shadowing
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2018-02-01 17:02 PST by Adam Klein
Modified: 2021-05-14 04:34 PDT (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Adam Klein 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.
Comment 1 GSkachkov 2018-02-02 12:01:29 PST
Hmm, the same for common async function
(async function (v) { print(v); var v; })(7);
Comment 2 GSkachkov 2018-02-02 12:04:19 PST
Yeah and the same for generator and async generators
Comment 3 Yusuke Suzuki 2018-02-02 12:21:24 PST
Hm, shoud it print 7? Why doesn’t “var” hide?
Comment 4 GSkachkov 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:
Comment 5 Adam Klein 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.
Comment 6 Mats Åhlberg 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)=> {
   var a = a;
   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?