Truly independent web browser
LibJS: Isolate class static blocks from enclosing binding patterns
Tim Ledbetterd5b3a5a0946a
diff --git a/Libraries/LibJS/Rust/src/parser/declarations.rs b/Libraries/LibJS/Rust/src/parser/declarations.rsindex a0036edb5fd..3bb4fac261d 100644--- a/Libraries/LibJS/Rust/src/parser/declarations.rs+++ b/Libraries/LibJS/Rust/src/parser/declarations.rs@@ -958,7 +958,11 @@ impl Parser<'_> {self.flags.allow_super_property_lookup = true;self.flags.new_target_is_valid = true;self.scope_collector.open_static_init_scope(None);+ // Save pattern_bound_names so that destructuring patterns in the+ // static block don't steal names from an outer binding context.+ let saved_pattern_bound_names = std::mem::take(&mut self.pattern_bound_names);let children = self.parse_statement_list(false);+ self.pattern_bound_names = saved_pattern_bound_names;self.flags = saved_flags;self.consume_token(TokenType::CurlyClose);let scope = self.make_scope(children);diff --git a/Tests/LibJS/Runtime/classes/class-static-initializers.js b/Tests/LibJS/Runtime/classes/class-static-initializers.jsindex 1e5d3ea9bd9..ca929c61898 100644--- a/Tests/LibJS/Runtime/classes/class-static-initializers.js+++ b/Tests/LibJS/Runtime/classes/class-static-initializers.js@@ -112,3 +112,39 @@ test("await binding names in static blocks without a function boundary", () => {expect(`class A { static { await => 0; } }`).not.toEval();expect(`class A { static { async function await() {} } }`).not.toEval();});++describe("static blocks inside a destructuring declaration", () => {+ test("destructuring declaration with another name", () => {+ function f() {+ const [+ a = class {+ static {+ let [b] = [];+ }+ },+ ] = [];+ return typeof a;+ }+ expect(f()).toBe("function");+ });++ test("destructuring declaration with the same name", () => {+ expect("const [a = class { static { let [a] = []; } }] = [];").toEval();+ });++ test("destructured catch parameter", () => {+ function f() {+ const {+ a,+ b = class {+ static {+ try {+ } catch ({ message }) {}+ }+ },+ } = { a: 1 };+ return a;+ }+ expect(f()).toBe(1);+ });+});