Skip to content

Commit

Permalink
LibJS/Bytecode: Add some basic codegen for ExportStatement
Browse files Browse the repository at this point in the history
This is by no means complete, but at least a bunch of test-js and
test262 tests start working. :^)
  • Loading branch information
awesomekling committed Jun 24, 2023
1 parent 7ea4cba commit e2cbf19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Userland/Libraries/LibJS/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ class ExportStatement final : public Statement {

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_statement() const { return m_statement; }
Expand Down
26 changes: 26 additions & 0 deletions Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2743,4 +2743,30 @@ Bytecode::CodeGenerationErrorOr<void> ImportCall::generate_bytecode(Bytecode::Ge
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 {};
}

}

0 comments on commit e2cbf19

Please sign in to comment.