From fc7de74b124ef4b12461a5c71e9b11f8ba4ccb98 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 28 Jun 2023 00:53:08 +0200 Subject: [PATCH] LibJS/Bytecode: Improve export statement handling This adds support for exporting class expressions, which was previously TODO'd. We now correctly set the binding name of exports to `"*default*"` if they are unnamed. I'm not sure what the difference between the `InitializationMode` kinds is, but using `Initialize` fixes a bunch of tests. Note that some export tests (e.g. `eval-export-dflt-expr-cls-named.js`) still fail, as we don't set the "name" property of exported classes correctly. 176 new passes on test262 --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index a11d9e64b0..42e2cc8b01 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -2857,13 +2857,18 @@ Bytecode::CodeGenerationErrorOr ExportStatement::generate_bytecode(Bytecod } if (is(*m_statement)) { - TODO(); + TRY(m_statement->generate_bytecode(generator)); + + if (!static_cast(*m_statement).has_name()) + generator.emit(generator.intern_identifier(ExportStatement::local_name_for_default), Bytecode::Op::SetVariable::InitializationMode::Initialize); + + return {}; } // ExportDeclaration : export default AssignmentExpression ; VERIFY(is(*m_statement)); TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast(*m_statement), DeprecatedFlyString("default"sv))); - generator.emit(generator.intern_identifier("default"sv)); + generator.emit(generator.intern_identifier(ExportStatement::local_name_for_default), Bytecode::Op::SetVariable::InitializationMode::Initialize); return {}; }