Skip to content

Commit 4897baa

Browse files
authoredMar 15, 2025··
chore(engine): Simplify compile_class_static_field (#597)
1 parent 6a109c7 commit 4897baa

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed
 

‎nova_vm/src/engine/bytecode/bytecode_compiler.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,10 @@ impl<'a, 'gc, 'scope> CompileContext<'a, 'gc, 'scope> {
106106
/// current context.
107107
pub(crate) fn compile_class_static_field(
108108
&mut self,
109-
property_key: &ast::PropertyKey<'_>,
110-
value: &Option<ast::Expression<'_>>,
109+
identifier_name: &ast::IdentifierName,
110+
value: &Option<ast::Expression>,
111111
) {
112-
let identifier = match property_key {
113-
ast::PropertyKey::StaticIdentifier(identifier_name) => {
114-
String::from_str(self.agent, identifier_name.name.as_str(), self.gc)
115-
}
116-
ast::PropertyKey::PrivateIdentifier(_private_identifier) => todo!(),
117-
ast::PropertyKey::BooleanLiteral(_boolean_literal) => todo!(),
118-
ast::PropertyKey::NullLiteral(_null_literal) => todo!(),
119-
ast::PropertyKey::NumericLiteral(_numeric_literal) => todo!(),
120-
ast::PropertyKey::BigIntLiteral(_big_int_literal) => todo!(),
121-
ast::PropertyKey::RegExpLiteral(_reg_exp_literal) => todo!(),
122-
ast::PropertyKey::StringLiteral(_string_literal) => todo!(),
123-
ast::PropertyKey::TemplateLiteral(_template_literal) => todo!(),
124-
_ => unreachable!(),
125-
};
112+
let identifier = String::from_str(self.agent, identifier_name.name.as_str(), self.gc);
126113
// Turn the static name to a 'this' property access.
127114
self.add_instruction(Instruction::ResolveThisBinding);
128115
self.add_instruction_with_identifier(
@@ -2267,16 +2254,6 @@ impl CompileEvaluation for ast::VariableDeclaration<'_> {
22672254
}
22682255
}
22692256

2270-
impl CompileEvaluation for ast::Declaration<'_> {
2271-
fn compile(&self, ctx: &mut CompileContext) {
2272-
match self {
2273-
ast::Declaration::VariableDeclaration(x) => x.compile(ctx),
2274-
ast::Declaration::FunctionDeclaration(x) => x.compile(ctx),
2275-
other => todo!("{other:?}"),
2276-
}
2277-
}
2278-
}
2279-
22802257
impl CompileEvaluation for ast::BlockStatement<'_> {
22812258
fn compile(&self, ctx: &mut CompileContext) {
22822259
if self.body.is_empty() {

‎nova_vm/src/engine/bytecode/bytecode_compiler/class_definition_evaluation.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,12 @@ impl CompileEvaluation for ast::Class<'_> {
372372
&property_definition.value,
373373
);
374374
} else {
375+
let ast::PropertyKey::StaticIdentifier(key) = &property_definition.key
376+
else {
377+
unreachable!()
378+
};
375379
instance_fields.push(PropertyInitializerField::Static((
376-
&property_definition.key,
380+
key,
377381
&property_definition.value,
378382
)));
379383
}
@@ -521,7 +525,7 @@ impl CompileEvaluation for ast::Class<'_> {
521525

522526
#[derive(Debug)]
523527
enum PropertyInitializerField<'a, 'gc> {
524-
Static((&'a ast::PropertyKey<'a>, &'a Option<ast::Expression<'a>>)),
528+
Static((&'a ast::IdentifierName<'a>, &'a Option<ast::Expression<'a>>)),
525529
Computed((String<'gc>, &'a Option<ast::Expression<'a>>)),
526530
}
527531

0 commit comments

Comments
 (0)
Please sign in to comment.