Skip to content

Commit d72f7c6

Browse files
committed
feat: store wasm ast on the module
1 parent d491fdc commit d72f7c6

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

lib/wasm/WebAssemblyGenerator.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const Generator = require("../Generator");
88
const { RawSource } = require("webpack-sources");
99

1010
const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
11-
const { decode } = require("@webassemblyjs/wasm-parser");
1211
const t = require("@webassemblyjs/ast");
1312

1413
function compose(...fns) {
@@ -244,15 +243,9 @@ const addInitFunction = ({
244243

245244
class WebAssemblyGenerator extends Generator {
246245
generate(module) {
246+
const ast = module._ast;
247247
const bin = module.originalSource().source();
248248

249-
// FIXME(sven): this module is parsed twice, we could preserve the AST
250-
// from wasm/WebAssemblyParser.js
251-
const ast = decode(bin, {
252-
ignoreDataSection: true,
253-
ignoreCodeSection: true
254-
});
255-
256249
const importedGlobals = getImportedGlobals(ast);
257250
const countImportedFunc = getCountImportedFunc(ast);
258251
const startAtFuncIndex = getStartFuncIndex(ast);

lib/wasm/WebAssemblyParser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class WebAssemblyParser extends Tapable {
7373
}
7474
});
7575

76+
state.module._ast = ast;
77+
7678
return state;
7779
}
7880
}

0 commit comments

Comments
 (0)