mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 01:22:43 +02:00
The C++ parser was not rejecting duplicate parameter names across
destructuring patterns in non-simple parameter lists. For example,
`function f({ bar, ...a }, { bar, ...b }) {}` was accepted despite
being a syntax error per spec.
The existing inline duplicate check only ran for identifier parameters,
missing the case where both parameters are binding patterns. Add a
post-parse pass that collects all bound names and checks for duplicates
when the parameter list is non-simple (or in strict mode/arrows).
Also fix existing tests that relied on the incorrect behavior and add
new test coverage for destructuring duplicate detection.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
test("function with duplicate parameter names", () => {
|
|
function foo(bar, _, bar) {
|
|
return bar;
|
|
}
|
|
expect(foo(1, 2, 3)).toBe(3);
|
|
});
|
|
|
|
test("syntax errors", () => {
|
|
// Regular function in strict mode
|
|
expect(`
|
|
"use strict";
|
|
function foo(bar, bar) {}
|
|
`).not.toEval();
|
|
|
|
// Arrow function in strict mode
|
|
expect(`
|
|
"use strict";
|
|
const foo = (bar, bar) => {};
|
|
`).not.toEval();
|
|
|
|
// Arrow function in non-strict mode
|
|
expect(`
|
|
const foo = (bar, bar) => {};
|
|
`).not.toEval();
|
|
|
|
// Regular function with rest parameter
|
|
expect(`
|
|
function foo(bar, ...bar) {}
|
|
`).not.toEval();
|
|
|
|
// Arrow function with rest parameter
|
|
expect(`
|
|
const foo = (bar, ...bar) => {};
|
|
`).not.toEval();
|
|
|
|
// Regular function with default parameter
|
|
expect(`
|
|
function foo(bar, bar = 1) {}
|
|
`).not.toEval();
|
|
|
|
// Arrow function with default parameter
|
|
expect(`
|
|
const foo = (bar, bar = 1) => {};
|
|
`).not.toEval();
|
|
|
|
// Duplicate across destructuring parameters
|
|
expect(`
|
|
function foo({ bar }, { bar }) {}
|
|
`).not.toEval();
|
|
|
|
// Duplicate between identifier and destructuring parameter
|
|
expect(`
|
|
function foo(bar, { bar }) {}
|
|
`).not.toEval();
|
|
|
|
// Duplicate between destructuring and identifier parameter
|
|
expect(`
|
|
function foo({ bar }, bar) {}
|
|
`).not.toEval();
|
|
});
|