mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:57:42 +00:00
LibJS: Rest parameter in setter functions is a syntax error
This commit is contained in:
parent
6331d45a6f
commit
1e86379327
3 changed files with 7 additions and 1 deletions
|
@ -1278,7 +1278,7 @@ Vector<FunctionNode::Parameter> Parser::parse_function_parameters(int& function_
|
||||||
while (match(TokenType::Identifier) || match(TokenType::TripleDot)) {
|
while (match(TokenType::Identifier) || match(TokenType::TripleDot)) {
|
||||||
if (parse_options & FunctionNodeParseOptions::IsGetterFunction)
|
if (parse_options & FunctionNodeParseOptions::IsGetterFunction)
|
||||||
syntax_error("Getter function must have no arguments");
|
syntax_error("Getter function must have no arguments");
|
||||||
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && parameters.size() >= 1)
|
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && (parameters.size() >= 1 || match(TokenType::TripleDot)))
|
||||||
syntax_error("Setter function must have one argument");
|
syntax_error("Setter function must have one argument");
|
||||||
if (match(TokenType::TripleDot)) {
|
if (match(TokenType::TripleDot)) {
|
||||||
consume();
|
consume();
|
||||||
|
|
|
@ -70,6 +70,11 @@ describe("syntax errors", () => {
|
||||||
class A {
|
class A {
|
||||||
set foo(bar, baz) {
|
set foo(bar, baz) {
|
||||||
}
|
}
|
||||||
|
}`).not.toEval();
|
||||||
|
expect(`
|
||||||
|
class A {
|
||||||
|
set foo(...bar) {
|
||||||
|
}
|
||||||
}`).not.toEval();
|
}`).not.toEval();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,7 @@ describe("errors", () => {
|
||||||
expect("({ get ...[foo] })").not.toEval();
|
expect("({ get ...[foo] })").not.toEval();
|
||||||
expect("({ get foo(bar) {} })").not.toEval();
|
expect("({ get foo(bar) {} })").not.toEval();
|
||||||
expect("({ set foo() {} })").not.toEval();
|
expect("({ set foo() {} })").not.toEval();
|
||||||
|
expect("({ set foo(...bar) {} })").not.toEval();
|
||||||
expect("({ set foo(bar, baz) {} })").not.toEval();
|
expect("({ set foo(bar, baz) {} })").not.toEval();
|
||||||
expect("({ ...foo: bar })").not.toEval();
|
expect("({ ...foo: bar })").not.toEval();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue