mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 18:28:10 +00:00
LibJS: Share parameter parsing between regular and arrow functions
This simplifies try_parse_arrow_function_expression() and fixes a few cases that should not produce an arrow function AST but did: (a,,) => {} (a b) => {} (a ...b) => {} (...b a) => {} The new parsing logic checks whether parens are expected and uses parse_function_parameters() if so, rolling back if a new syntax error occurs during that. Otherwise it's just an identifier in which case we parse the single parameter ourselves.
This commit is contained in:
parent
aa68de3530
commit
965d952ff3
3 changed files with 56 additions and 70 deletions
|
@ -148,3 +148,16 @@ test("cannot be constructed", () => {
|
|||
new foo();
|
||||
}).toThrowWithMessage(TypeError, "foo is not a constructor");
|
||||
});
|
||||
|
||||
test("syntax errors", () => {
|
||||
expect("a, => {}").not.toEval();
|
||||
expect("(a, => {}").not.toEval();
|
||||
expect("(,) => {}").not.toEval();
|
||||
expect("(,,) => {}").not.toEval();
|
||||
expect("(a,,) => {}").not.toEval();
|
||||
expect("(a,,b) => {}").not.toEval();
|
||||
expect("(a, ...b, ...c) => {}").not.toEval();
|
||||
expect("(a b) => {}").not.toEval();
|
||||
expect("(a ...b) => {}").not.toEval();
|
||||
expect("(a = 1 = 2) => {}").not.toEval();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue