mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-17 16:42:54 +00:00
LibJS: Fix scope detection for ids in default function params
This change fixes an issue where identifiers used in default function parameters were being "registered" in the function's parent scope instead of its own scope. This bug resulted in incorrectly detected local variables. (Variables used in the default function parameter expression should be considered 'captured by nested function'.) To resolve this issue, the function scope is now created before parsing function parameters. Since function parameters can no longer be passed in the constructor, a setter function has been introduced to set them later, when they are ready.
This commit is contained in:
parent
996c020b0d
commit
2f85faef0f
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 2f85faef0f
Pull-request: https://github.com/SerenityOS/serenity/pull/19873
4 changed files with 164 additions and 114 deletions
|
@ -141,3 +141,13 @@ test("parameter with an object default value", () => {
|
|||
expect(arrowFunc()).toBe("bar");
|
||||
expect(arrowFunc({ foo: "baz" })).toBe("baz");
|
||||
});
|
||||
|
||||
test("use variable as default function parameter", () => {
|
||||
let a = 1;
|
||||
|
||||
function func(param = a) {
|
||||
return param;
|
||||
}
|
||||
|
||||
expect(func()).toBe(a);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue