mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
LibJS: Don't treat yield after void as identifier in generator functions
This commit is contained in:
parent
a1308bfc60
commit
c8e80690a7
2 changed files with 15 additions and 0 deletions
|
@ -1548,6 +1548,9 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
|
||||||
return create_ast_node<UnaryExpression>({ m_state.current_token.filename(), rule_start.position(), position() }, UnaryOp::Typeof, parse_expression(precedence, associativity));
|
return create_ast_node<UnaryExpression>({ m_state.current_token.filename(), rule_start.position(), position() }, UnaryOp::Typeof, parse_expression(precedence, associativity));
|
||||||
case TokenType::Void:
|
case TokenType::Void:
|
||||||
consume();
|
consume();
|
||||||
|
// FIXME: This check is really hiding the fact that we don't deal with different expressions correctly.
|
||||||
|
if (match(TokenType::Yield) && m_state.in_generator_function_context)
|
||||||
|
syntax_error("'yield' is not an identifier in generator function context");
|
||||||
return create_ast_node<UnaryExpression>({ m_state.current_token.filename(), rule_start.position(), position() }, UnaryOp::Void, parse_expression(precedence, associativity));
|
return create_ast_node<UnaryExpression>({ m_state.current_token.filename(), rule_start.position(), position() }, UnaryOp::Void, parse_expression(precedence, associativity));
|
||||||
case TokenType::Delete: {
|
case TokenType::Delete: {
|
||||||
consume();
|
consume();
|
||||||
|
|
|
@ -12,3 +12,15 @@ test("basic functionality", () => {
|
||||||
expect(void (() => "hello friends")()).toBeUndefined();
|
expect(void (() => "hello friends")()).toBeUndefined();
|
||||||
expect((() => void "hello friends")()).toBeUndefined();
|
expect((() => void "hello friends")()).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("treats yield in generator as non variable", () => {
|
||||||
|
expect("function f() { void yield; }").toEval();
|
||||||
|
expect("async function f() { void yield; }").toEval();
|
||||||
|
expect("function *f() { void yield; }").not.toEval();
|
||||||
|
expect("async function *f() { void yield; }").not.toEval();
|
||||||
|
|
||||||
|
expect("class C { *f() { void yield; } }").not.toEval();
|
||||||
|
expect("var obj = { async function *f() { void yield; } }").not.toEval();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue