File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed
Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 66
77const Generator = require ( "../Generator" ) ;
88const { RawSource } = require ( "webpack-sources" ) ;
9- const WebAssemblyParser = require ( "./WebAssemblyParser" ) ;
109
1110const { editWithAST, addWithAST } = require ( "@webassemblyjs/wasm-edit" ) ;
11+ const { decode } = require ( "@webassemblyjs/wasm-parser" ) ;
1212const t = require ( "@webassemblyjs/ast" ) ;
1313
1414function compose ( ...fns ) {
@@ -244,9 +244,13 @@ const addInitFunction = ({
244244
245245class 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 ) ;
Original file line number Diff line number Diff line change @@ -29,30 +29,20 @@ const decoderOpts = {
2929 ignoreDataSection : true
3030} ;
3131
32- /** @type {WeakMap<Module, TODO> } */
33- const astStore = new WeakMap ( ) ;
34-
3532class 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 , {
You can’t perform that action at this time.
0 commit comments