Bug 1887677: Correctly compute inClass predicate when validating unbound private...
commitac737a1ac59680dbe497bda1eaea1c02f80b4983
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 27 Mar 2024 07:35:40 +0000 (27 07:35 +0000)
committerAndré Bargull <andre.bargull@gmail.com>
Wed, 27 Mar 2024 07:35:40 +0000 (27 07:35 +0000)
tree7e870e7737b6331ca183afa2e871441001fb4bf5
parent50db8db480eca00bcd6b62b31695a0729d56d768
Bug 1887677: Correctly compute inClass predicate when validating unbound private names. r=dminor

`SharedContext::inClass()` returns whether the current `SharedContext` is within
a class definition. A class definition itself doesn't create a new `SharedContext`,
so an inner nested class definition within a computed property key of an outer
class definition was treated as if it wasn't nested within a class definition. This
led to reporting a SyntaxError when checking for unbound private names.

Calling `ParseContext::findInnermostStatement()` in addition to `SharedContext::inClass()`
fixes this issue. (We need to keep `SharedContext::inClass()` to correctly handle
lazily parsed classes.)

Differential Revision: https://phabricator.services.mozilla.com/D205609
js/src/frontend/Parser.cpp
js/src/tests/non262/PrivateName/nested-class-in-computed-property-key.js [new file with mode: 0644]