mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 01:48:11 +00:00
LibJS/Bytecode: Add some basic codegen for ExportStatement
This is by no means complete, but at least a bunch of test-js and test262 tests start working. :^)
This commit is contained in:
parent
5d79431859
commit
06ac768c8b
2 changed files with 28 additions and 0 deletions
|
@ -470,6 +470,8 @@ public:
|
||||||
|
|
||||||
virtual void dump(int indent) const override;
|
virtual void dump(int indent) const override;
|
||||||
|
|
||||||
|
virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
|
||||||
|
|
||||||
bool has_export(DeprecatedFlyString const& export_name) const;
|
bool has_export(DeprecatedFlyString const& export_name) const;
|
||||||
|
|
||||||
bool has_statement() const { return m_statement; }
|
bool has_statement() const { return m_statement; }
|
||||||
|
|
|
@ -2743,4 +2743,30 @@ Bytecode::CodeGenerationErrorOr<void> ImportCall::generate_bytecode(Bytecode::Ge
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bytecode::CodeGenerationErrorOr<void> ExportStatement::generate_bytecode(Bytecode::Generator& generator) const
|
||||||
|
{
|
||||||
|
if (!is_default_export()) {
|
||||||
|
if (m_statement) {
|
||||||
|
return m_statement->generate_bytecode(generator);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
VERIFY(m_statement);
|
||||||
|
|
||||||
|
if (is<FunctionDeclaration>(*m_statement) || is<ClassDeclaration>(*m_statement)) {
|
||||||
|
return m_statement->generate_bytecode(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is<ClassExpression>(*m_statement)) {
|
||||||
|
TODO();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExportDeclaration : export default AssignmentExpression ;
|
||||||
|
VERIFY(is<Expression>(*m_statement));
|
||||||
|
TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<Expression const&>(*m_statement), DeprecatedFlyString("default"sv)));
|
||||||
|
generator.emit<Bytecode::Op::SetVariable>(generator.intern_identifier("default"sv));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue