mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 07:32:07 +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
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