Skip to content

Commit e2c8f3d

Browse files
committed
remove passing AST, redecode AST in Generator
1 parent 38456ea commit e2c8f3d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

lib/wasm/WebAssemblyGenerator.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
const Generator = require("../Generator");
88
const { RawSource } = require("webpack-sources");
9-
const WebAssemblyParser = require("./WebAssemblyParser");
109

1110
const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
11+
const { decode } = require("@webassemblyjs/wasm-parser");
1212
const t = require("@webassemblyjs/ast");
1313

1414
function compose(...fns) {
@@ -244,9 +244,13 @@ const addInitFunction = ({
244244

245245
class WebAssemblyGenerator extends Generator {
246246
generate(module) {
247-
const ast = WebAssemblyParser.getAst(module);
248247
const bin = module.originalSource().source();
249248

249+
const ast = decode(bin, {
250+
ignoreDataSection: true,
251+
ignoreCodeSection: true
252+
});
253+
250254
const importedGlobals = getImportedGlobals(ast);
251255
const countImportedFunc = getCountImportedFunc(ast);
252256
const startAtFuncIndex = getStartFuncIndex(ast);

lib/wasm/WebAssemblyParser.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,20 @@ const decoderOpts = {
2929
ignoreDataSection: true
3030
};
3131

32-
/** @type {WeakMap<Module, TODO>} */
33-
const astStore = new WeakMap();
34-
3532
class WebAssemblyParser extends Tapable {
3633
constructor(options) {
3734
super();
3835
this.hooks = {};
3936
this.options = options;
4037
}
4138

42-
static getAst(module) {
43-
return astStore.get(module);
44-
}
45-
4639
parse(binary, state) {
4740
// flag it as ESM
4841
state.module.buildMeta.exportsType = "namespace";
4942

5043
// parse it
5144
const ast = decode(binary, decoderOpts);
5245

53-
// cache it to be available for generators
54-
astStore.set(state.module, ast);
55-
5646
// extract imports and exports
5747
const exports = (state.module.buildMeta.providedExports = []);
5848
t.traverse(ast, {

0 commit comments

Comments
 (0)