Skip to content

Commit 486db15

Browse files
committed
refactor: use webassemblyjs tools
1 parent 8e8649f commit 486db15

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

‎lib/WebAssemblyParser.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55
"use strict";
66

7-
const Tools = require("webassembly-interpreter/lib/tools");
7+
const traverse = require("@webassemblyjs/ast").traverse;
8+
const decode = require("@webassemblyjs/wasm-parser").decode;
89

910
const Tapable = require("tapable").Tapable;
1011
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
@@ -16,16 +17,16 @@ class WebAssemblyParser extends Tapable {
1617
this.options = options;
1718
}
1819

19-
parse(source, state) {
20+
parse(binary, state) {
2021
// flag it as ESM
2122
state.module.buildMeta.exportsType = "namespace";
2223

2324
// parse it
24-
const ast = Tools.parsers.parseWASM(source);
25+
const ast = decode(binary);
2526

2627
// extract imports and exports
2728
const exports = state.module.buildMeta.providedExports = [];
28-
Tools.traverse(ast, {
29+
traverse(ast, {
2930
ModuleExport({
3031
node
3132
}) {

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
66
"license": "MIT",
77
"dependencies": {
8+
"@webassemblyjs/ast": "^1.0.0",
9+
"@webassemblyjs/wasm-parser": "^1.0.0",
810
"acorn": "^5.0.0",
911
"acorn-dynamic-import": "^3.0.0",
1012
"ajv": "^6.1.0",
@@ -22,7 +24,6 @@
2224
"tapable": "^1.0.0-beta.5",
2325
"uglifyjs-webpack-plugin": "^1.1.1",
2426
"watchpack": "^1.4.0",
25-
"webassembly-interpreter": "^0.0.31",
2627
"webpack-sources": "^1.0.1"
2728
},
2829
"devDependencies": {

‎yarn.lock‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@
1616
esutils "^2.0.2"
1717
js-tokens "^3.0.0"
1818

19+
"@webassemblyjs/ast@1.0.0", "@webassemblyjs/ast@^1.0.0":
20+
version "1.0.0"
21+
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.0.0.tgz#e6953dd785b6827ac5ce2fab479b1358f35f7df4"
22+
dependencies:
23+
"@webassemblyjs/wast-parser" "1.0.0"
24+
webassembly-floating-point-hex-parser "0.1.2"
25+
webassemblyjs "1.0.0"
26+
27+
"@webassemblyjs/wasm-parser@1.0.0", "@webassemblyjs/wasm-parser@^1.0.0":
28+
version "1.0.0"
29+
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.0.0.tgz#79e3e45f907a57c7a8bb74e746ee7bab7b77041a"
30+
dependencies:
31+
"@webassemblyjs/ast" "1.0.0"
32+
"@webassemblyjs/wasm-parser" "1.0.0"
33+
webassemblyjs "1.0.0"
34+
35+
"@webassemblyjs/wast-parser@1.0.0":
36+
version "1.0.0"
37+
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.0.0.tgz#d874e2dcb1726d31868518be7807f8f2ff358425"
38+
dependencies:
39+
"@babel/code-frame" "^7.0.0-beta.36"
40+
"@webassemblyjs/ast" "1.0.0"
41+
long "^3.2.0"
42+
webassembly-floating-point-hex-parser "0.1.2"
43+
webassemblyjs "1.0.0"
44+
1945
abbrev@1:
2046
version "1.1.1"
2147
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
@@ -4298,11 +4324,13 @@ webassembly-floating-point-hex-parser@0.1.2:
42984324
version "0.1.2"
42994325
resolved "https://registry.yarnpkg.com/webassembly-floating-point-hex-parser/-/webassembly-floating-point-hex-parser-0.1.2.tgz#85bb01f54e68690c2645ea0cfad26c1110fdf988"
43004326

4301-
webassembly-interpreter@^0.0.31:
4302-
version "0.0.31"
4303-
resolved "https://registry.yarnpkg.com/webassembly-interpreter/-/webassembly-interpreter-0.0.31.tgz#535ee84523dd664c5c96f032ebf1c23dbe7f5f89"
4327+
webassemblyjs@1.0.0:
4328+
version "1.0.0"
4329+
resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.0.0.tgz#8d26a6a205e4418b236611030e83bb375827c9ef"
43044330
dependencies:
4305-
"@babel/code-frame" "^7.0.0-beta.36"
4331+
"@webassemblyjs/ast" "1.0.0"
4332+
"@webassemblyjs/wasm-parser" "1.0.0"
4333+
"@webassemblyjs/wast-parser" "1.0.0"
43064334
long "^3.2.0"
43074335
webassembly-floating-point-hex-parser "0.1.2"
43084336

0 commit comments

Comments
 (0)