Skip to content

akarikun/rust-jsparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rust实现JS解析

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

pkg/index.html
<!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>

About

Rust实现JS解析

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages