Bug 231166 - "Can't find variable" that's let-declared within `with` statement when executing function that's declared within same `with` statement
Summary: "Can't find variable" that's let-declared within `with` statement when execut...
Status: RESOLVED DUPLICATE of bug 163209
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 15
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-10-04 04:28 PDT by yanahij531
Modified: 2023-09-24 13:59 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yanahij531 2021-10-04 04:28:34 PDT
In Firefox and Chrome the following code works fine, but Safari throws an error saying that the variable `a` cannot be found.

```
with({}) {
  let a = 1;
  function foo() {
    console.log(a);
  }
  foo();
}
```

https://jsbin.com/hiwihiyaxi/edit?html,console
Comment 1 Kevin Neal 2021-10-05 10:13:51 PDT
Thanks for filing. I was able to reproduce the bug in Safari. The appropriate engineers have been notified.
Comment 2 Radar WebKit Bug Importer 2021-10-05 10:14:10 PDT
<rdar://problem/83892140>
Comment 3 Alexey Shvayka 2023-09-24 13:59:23 PDT
Thank you for reporting!

This bug arises because block-level function declarations in global code, which are subject to currently unimplemented legacy Annex B hoisting, always receive top-level scope instead of lexical one.

https://bugs.webkit.org/show_bug.cgi?id=163209 implements Annex B function hoisting for global code, fixing this issue.

*** This bug has been marked as a duplicate of bug 163209 ***