Skip to content

Commit

Permalink
Remove panics on module compilation (#2730)
Browse files Browse the repository at this point in the history
This Pull Request fixes the current panics on module compilation to prepare for the next release.
  • Loading branch information
jedel1043 committed Mar 23, 2023
1 parent d448e8e commit 9cfb68d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions boa_engine/src/bytecompiler/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::ByteCompiler;
use crate::{js_string, vm::Opcode};

use super::{ByteCompiler, Literal};
use boa_ast::{ModuleItem, ModuleItemList};

impl ByteCompiler<'_, '_> {
Expand All @@ -12,14 +14,19 @@ impl ByteCompiler<'_, '_> {

/// Compiles a [`ModuleItem`].
#[inline]
#[allow(unused_variables, clippy::missing_panics_doc)] // Unimplemented
#[allow(clippy::single_match_else)]
pub fn compile_module_item(&mut self, item: &ModuleItem, configurable_globals: bool) {
match item {
ModuleItem::ImportDeclaration(import) => todo!("import declaration compilation"),
ModuleItem::ExportDeclaration(export) => todo!("export declaration compilation"),
ModuleItem::StatementListItem(stmt) => {
self.compile_stmt_list_item(stmt, false, configurable_globals);
}
_ => {
// TODO: Remove after implementing modules.
let msg = self.get_or_insert_literal(Literal::String(js_string!(
"modules are unimplemented"
)));
self.emit(Opcode::ThrowNewTypeError, &[msg]);
}
}
}

Expand All @@ -36,18 +43,17 @@ impl ByteCompiler<'_, '_> {

/// Creates the declarations from a [`ModuleItem`].
#[inline]
#[allow(unused_variables)] // Unimplemented
pub(crate) fn create_decls_from_module_item(
&mut self,
item: &ModuleItem,
configurable_globals: bool,
) -> bool {
match item {
ModuleItem::ImportDeclaration(import) => todo!("import declaration generation"),
ModuleItem::ExportDeclaration(export) => todo!("export declaration generation"),
ModuleItem::StatementListItem(stmt) => {
self.create_decls_from_stmt_list_item(stmt, configurable_globals)
}
// TODO: Implement modules
_ => false,
}
}
}
2 changes: 1 addition & 1 deletion boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Test {
Outcome::Negative {
phase: Phase::Resolution,
error_type: _,
} => todo!("check module resolution errors"),
} => (false, "Modules are not implemented yet".to_string()),
Outcome::Negative {
phase: Phase::Runtime,
error_type,
Expand Down

0 comments on commit 9cfb68d

Please sign in to comment.