Truly independent web browser
LibJS: Don't make a var of a block function named like a parameter
Shannon Boothe305d6f94df0
diff --git a/Libraries/LibJS/Rust/src/parser/base.rs b/Libraries/LibJS/Rust/src/parser/base.rsindex 339ad218505..07ea37cf41d 100644--- a/Libraries/LibJS/Rust/src/parser/base.rs+++ b/Libraries/LibJS/Rust/src/parser/base.rs@@ -1266,10 +1266,12 @@ impl<'a, U: Unit> Parser<'a, U> {}}if row == NONE {- self.add_declaration(hoist.name, top, decl::ANNEX_B);- if self.records_summaries {- let d = self.decls.len() - 1;- self.decls[d].summary_slot = SUMMARY_SLOT_EARLY;+ if !is_parameter {+ self.add_declaration(hoist.name, top, decl::ANNEX_B);+ if self.records_summaries {+ let d = self.decls.len() - 1;+ self.decls[d].summary_slot = SUMMARY_SLOT_EARLY;+ }}} else if flags & !decl::FUNCTION_NAME == 0 {// NB: The name of a function expression is bound outside of the function, which gets a `var` of its own.diff --git a/Tests/LibJS/Runtime/functions-parameter-scope.js b/Tests/LibJS/Runtime/functions-parameter-scope.jsindex fc432c48c23..954e317c642 100644--- a/Tests/LibJS/Runtime/functions-parameter-scope.js+++ b/Tests/LibJS/Runtime/functions-parameter-scope.js@@ -192,6 +192,24 @@ test("a function in a block does not get hoisted to a parameter of the same namereturn [before, g];}expect(f()).toEqual([123, 123]);++ function g(a = 1, read = () => a) {+ {+ function a() {}+ }+ a = 5;+ return read();+ }+ expect(g()).toBe(5);++ function h(a = 1, write = value => (a = value)) {+ {+ function a() {}+ }+ write(9);+ return a;+ }+ expect(h()).toBe(9);});test("a function in the parameters checks the dead zone of a parameter that a var of the body has the name of", () => {