Skip to content

Commit fbeb665

Browse files
authored
Merge pull request webpack#6610 from xtuc/feature/wasm-parser-tooling
refactor: use webassemblyjs tools
2 parents 2721ba7 + a78d93f commit fbeb665

3 files changed

Lines changed: 52 additions & 11 deletions

File tree

‎lib/WebAssemblyParser.js‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,40 @@
44
*/
55
"use strict";
66

7-
const Tools = require("webassembly-interpreter/lib/tools");
8-
9-
const Tapable = require("tapable").Tapable;
7+
const {
8+
traverse
9+
} = require("@webassemblyjs/ast");
10+
const {
11+
decode
12+
} = require("@webassemblyjs/wasm-parser");
13+
14+
const {
15+
Tapable
16+
} = require("tapable");
1017
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
1118

19+
const decoderOpts = {
20+
ignoreCodeSection: true,
21+
ignoreDataSection: true,
22+
};
23+
1224
class WebAssemblyParser extends Tapable {
1325
constructor(options) {
1426
super();
1527
this.hooks = {};
1628
this.options = options;
1729
}
1830

19-
parse(source, state) {
31+
parse(binary, state) {
2032
// flag it as ESM
2133
state.module.buildMeta.exportsType = "namespace";
2234

2335
// parse it
24-
const ast = Tools.parsers.parseWASM(source);
36+
const ast = decode(binary, decoderOpts);
2537

2638
// extract imports and exports
2739
const exports = state.module.buildMeta.providedExports = [];
28-
Tools.traverse(ast, {
40+
traverse(ast, {
2941
ModuleExport({
3042
node
3143
}) {

‎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)