ast树参考 parse.html
# lib.rs 生成 webassembly
# 安装所需工具
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
npm i wasm-opt -g
# 编译wasm
cargo build --target wasm32-unknown-unknown --release --lib
wasm-opt -Oz -o target/wasm32-unknown-unknown/release/jsparser.wasm target/wasm32-unknown-unknown/release/jsparser.wasm #压缩
wasm-bindgen target/wasm32-unknown-unknown/release/jsparser.wasm --out-dir ./pkg --web
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jsparser</title>
</head>
<body>
<script type="module">
import init, { run_code } from './jsparser.js';
~(async()=>{
await init();
run_code(`
for(let i=0;i<10;i++){
log(i)
}
`)
})();
</script>
</body>
</html>