Skip to content

Commit 8a3ca7d

Browse files
authored
Update modules code to the latest spec (#5271)
Just a small cleanup to update some paths that changed from the spec.
1 parent fab099a commit 8a3ca7d

4 files changed

Lines changed: 308 additions & 269 deletions

File tree

core/engine/src/bytecompiler/module.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,27 @@ impl ByteCompiler<'_> {
4242
ExportDeclaration::VarStatement(var) => self.compile_var_decl(var),
4343
ExportDeclaration::Declaration(decl) => self.compile_decl(decl, false),
4444
ExportDeclaration::DefaultClassDeclaration(cl) => {
45-
self.compile_class(cl.as_ref().into(), None);
45+
// 2. Let className be the sole element of BoundNames of ClassDeclaration.
46+
// 3. If className is "*default*", then
47+
if cl.name().sym() == Sym::DEFAULT_EXPORT {
48+
let class = self.register_allocator.alloc();
49+
50+
// 1. Let value be ? BindingClassDeclarationEvaluation of ClassDeclaration.
51+
self.compile_class(cl.as_ref().into(), Some(&class));
52+
53+
// a. Let env be the running execution context's LexicalEnvironment.
54+
// b. Perform ? InitializeBoundName("*default*", value, env).
55+
let default_export = self
56+
.interner()
57+
.resolve_expect(Sym::DEFAULT_EXPORT)
58+
.into_common(false);
59+
self.emit_binding(BindingOpcode::InitLexical, default_export, &class);
60+
61+
self.register_allocator.dealloc(class);
62+
} else {
63+
// 1. Let value be ? BindingClassDeclarationEvaluation of ClassDeclaration.
64+
self.compile_class(cl.as_ref().into(), None);
65+
}
4666
}
4767
ExportDeclaration::DefaultAssignmentExpression(expr) => {
4868
let function = self.register_allocator.alloc();

0 commit comments

Comments
 (0)