From 55c85768c38d45368d23637be76c9e2bcbdb4401 Mon Sep 17 00:00:00 2001 From: Victor Tuekam Date: Tue, 28 Apr 2020 20:16:18 +0200 Subject: [PATCH] create boa-wasm package (#352) --- Cargo.lock | 9 ++++++++- Cargo.toml | 1 + boa/Cargo.toml | 2 -- boa/src/lib.rs | 5 ----- boa_cli/Cargo.toml | 2 +- boa_wasm/Cargo.toml | 20 ++++++++++++++++++++ boa/src/wasm.rs => boa_wasm/src/lib.rs | 2 +- index.js | 2 +- webpack.config.js | 4 ++-- 9 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 boa_wasm/Cargo.toml rename boa/src/wasm.rs => boa_wasm/src/lib.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index a5306cfe37..26caaa1618 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,7 +12,6 @@ dependencies = [ "regex", "serde", "serde_json", - "wasm-bindgen", ] [[package]] @@ -65,6 +64,14 @@ dependencies = [ "structopt", ] +[[package]] +name = "boa_wasm" +version = "0.1.0" +dependencies = [ + "Boa", + "wasm-bindgen", +] + [[package]] name = "bstr" version = "0.2.12" diff --git a/Cargo.toml b/Cargo.toml index 347477474e..c250459bb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "boa", "boa_cli", + "boa_wasm", ] # The release profile, used for `cargo build`. diff --git a/boa/Cargo.toml b/boa/Cargo.toml index 1e2fb59aad..cab2701742 100644 --- a/boa/Cargo.toml +++ b/boa/Cargo.toml @@ -12,7 +12,6 @@ edition = "2018" [features] serde-ast = ["serde"] -default = ["wasm-bindgen"] [dependencies] gc = "0.3.3" @@ -22,7 +21,6 @@ rand = "0.7.3" regex = "1.3.6" # Optional Dependencies -wasm-bindgen = { version = "0.2.60", optional = true } serde = { version = "1.0.106", features = ["derive"], optional = true } [dev-dependencies] diff --git a/boa/src/lib.rs b/boa/src/lib.rs index ccd89d4254..3c0c9e3dbd 100644 --- a/boa/src/lib.rs +++ b/boa/src/lib.rs @@ -38,11 +38,6 @@ pub mod environment; pub mod exec; pub mod realm; pub mod syntax; -#[cfg(feature = "wasm-bindgen")] -mod wasm; - -#[cfg(feature = "wasm-bindgen")] -pub use crate::wasm::*; use crate::{ builtins::value::ResultValue, exec::{Executor, Interpreter}, diff --git a/boa_cli/Cargo.toml b/boa_cli/Cargo.toml index 18262687d3..07dcb68d3d 100644 --- a/boa_cli/Cargo.toml +++ b/boa_cli/Cargo.toml @@ -11,7 +11,7 @@ exclude = ["../.vscode/*", "../Dockerfile", "../Makefile", "../.editorConfig"] edition = "2018" [dependencies] -Boa = { path = "../boa", features = ["serde-ast"], default-features = false } +Boa = { path = "../boa", features = ["serde-ast"] } structopt = "0.3.13" [target.x86_64-unknown-linux-gnu.dependencies] diff --git a/boa_wasm/Cargo.toml b/boa_wasm/Cargo.toml new file mode 100644 index 0000000000..96292ec514 --- /dev/null +++ b/boa_wasm/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "boa_wasm" +version = "0.1.0" +authors = ["Jason Williams "] +description = "Boa is a Javascript lexer, parser and Just-in-Time compiler written in Rust. Currently, it has support for some of the language." +repository = "https://github.com/jasonwilliams/boa" +keywords = ["javascript", "compiler", "lexer", "parser", "js"] +categories = ["wasm"] +license = "Unlicense/MIT" +exclude = ["../.vscode/*", "../Dockerfile", "../Makefile", "../.editorConfig"] +edition = "2018" + +[dependencies] +Boa = { path = "../boa" } +wasm-bindgen = { version = "0.2.60" } + +[lib] +crate-type = ["cdylib", "lib"] +name = "boa_wasm" +bench = false diff --git a/boa/src/wasm.rs b/boa_wasm/src/lib.rs similarity index 98% rename from boa/src/wasm.rs rename to boa_wasm/src/lib.rs index 2bb8f7391e..c8e8872619 100644 --- a/boa/src/wasm.rs +++ b/boa_wasm/src/lib.rs @@ -1,4 +1,4 @@ -use crate::{ +use boa::{ exec::{Executor, Interpreter}, realm::Realm, syntax::{ast::node::Node, lexer::Lexer, parser::Parser}, diff --git a/index.js b/index.js index b7d41bc3b6..c5b4e26133 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ // Note that a dynamic `import` statement here is required due to // webpack/webpack#6615, but in theory `import { greet } from './pkg/hello_world';` // will work here one day as well! -const rust = import("./boa/pkg"); +const rust = import("./boa_wasm/pkg"); import * as monaco from "monaco-editor"; self.MonacoEnvironment = { diff --git a/webpack.config.js b/webpack.config.js index 156c4abc71..d49fbdfacd 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -18,8 +18,8 @@ module.exports = { template: "index.html", }), new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, "./boa/"), - outDir: path.resolve(__dirname, "./boa/pkg/"), + crateDirectory: path.resolve(__dirname, "./boa_wasm/"), + outDir: path.resolve(__dirname, "./boa_wasm/pkg/"), }), new CopyWebpackPlugin([ {