mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:08:13 +00:00
LibJS: Implement tagged template literals (foobar
)
To make processing tagged template literals easier, template literals will now add one empty StringLiteral before and after each template expression *if* there's no other string - e.g.: `${foo}` -> "", foo, "" `test${foo}${bar}test` -> "test", foo, "", bar, "test" This also matches the behaviour of many other parsers.
This commit is contained in:
parent
eea62dd365
commit
4d20cf57db
4 changed files with 161 additions and 3 deletions
|
@ -786,6 +786,24 @@ private:
|
|||
const NonnullRefPtrVector<Expression> m_expressions;
|
||||
};
|
||||
|
||||
class TaggedTemplateLiteral final : public Expression {
|
||||
public:
|
||||
TaggedTemplateLiteral(NonnullRefPtr<Expression> tag, NonnullRefPtr<TemplateLiteral> template_literal)
|
||||
: m_tag(move(tag))
|
||||
, m_template_literal(move(template_literal))
|
||||
{
|
||||
}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "TaggedTemplateLiteral"; }
|
||||
|
||||
const NonnullRefPtr<Expression> m_tag;
|
||||
const NonnullRefPtr<TemplateLiteral> m_template_literal;
|
||||
};
|
||||
|
||||
class MemberExpression final : public Expression {
|
||||
public:
|
||||
MemberExpression(NonnullRefPtr<Expression> object, NonnullRefPtr<Expression> property, bool computed = false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue