Skip to content

Commit

Permalink
fix: detect exported objects as JS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelmmiguel committed Oct 16, 2023
1 parent fd15aa5 commit b8877c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kits/javascript/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ enum JSWorkerType {

/// Identify the worker source code to run it properly.
fn identify_type(src: &str) -> JSWorkerType {
// Detect default exported functions
// Detect default exported functions and objects
let default_regex = Regex::new(r"export\s+default\s+\w+;?").unwrap();
// Detect default exported object
let default_block_regex = Regex::new(r"export\s+default\s*\{(\s.+)*\};?").unwrap();
// Detect exported functions with the "as" syntax like "export { app as default }";
let default_as_regex = Regex::new(r"export\s*\{\s*\w+\s+(as default){1}\s*\};?").unwrap();

if default_regex.is_match(src) || default_as_regex.is_match(src) {
if default_regex.is_match(src)
|| default_block_regex.is_match(src)
|| default_as_regex.is_match(src)
{
JSWorkerType::DefaultExport
} else {
JSWorkerType::Global
Expand Down
Binary file modified kits/javascript/wasm-workers-quick-js-engine.wasm
Binary file not shown.

0 comments on commit b8877c3

Please sign in to comment.