1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:27:35 +00:00

LibJS: Correctly parse yield-from expressions

This commit implements parsing for `yield *expr`, and the multiple
ways something can or can't be parsed like that.
Also makes yield-from a TODO in the bytecode generator.
Behold, the glory of javascript syntax:
```js
// 'yield' = expression in generators.
function* foo() {
    yield
    *bar; // <- Syntax error here, expression can't start with *
}

// 'yield' = identifier anywhere else.
function foo() {
    yield
    *bar; // Perfectly fine, this is just `yield * bar`
}
```
This commit is contained in:
Ali Mohammad Pur 2021-06-14 15:46:41 +04:30 committed by Linus Groh
parent d374295a26
commit 3194177dce
5 changed files with 67 additions and 42 deletions

View file

@ -348,13 +348,15 @@ public:
class YieldExpression final : public Expression {
public:
explicit YieldExpression(SourceRange source_range, RefPtr<Expression> argument)
explicit YieldExpression(SourceRange source_range, RefPtr<Expression> argument, bool is_yield_from)
: Expression(move(source_range))
, m_argument(move(argument))
, m_is_yield_from(is_yield_from)
{
}
Expression const* argument() const { return m_argument; }
bool is_yield_from() const { return m_is_yield_from; }
virtual Value execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override;
@ -362,6 +364,7 @@ public:
private:
RefPtr<Expression> m_argument;
bool m_is_yield_from { false };
};
class ReturnStatement final : public Statement {