File tree 2 files changed +6
-12
lines changed 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 6
6
7
7
const Generator = require ( "../Generator" ) ;
8
8
const { RawSource } = require ( "webpack-sources" ) ;
9
- const WebAssemblyParser = require ( "./WebAssemblyParser" ) ;
10
9
11
10
const { editWithAST, addWithAST } = require ( "@webassemblyjs/wasm-edit" ) ;
11
+ const { decode } = require ( "@webassemblyjs/wasm-parser" ) ;
12
12
const t = require ( "@webassemblyjs/ast" ) ;
13
13
14
14
function compose ( ...fns ) {
@@ -244,9 +244,13 @@ const addInitFunction = ({
244
244
245
245
class WebAssemblyGenerator extends Generator {
246
246
generate ( module ) {
247
- const ast = WebAssemblyParser . getAst ( module ) ;
248
247
const bin = module . originalSource ( ) . source ( ) ;
249
248
249
+ const ast = decode ( bin , {
250
+ ignoreDataSection : true ,
251
+ ignoreCodeSection : true
252
+ } ) ;
253
+
250
254
const importedGlobals = getImportedGlobals ( ast ) ;
251
255
const countImportedFunc = getCountImportedFunc ( ast ) ;
252
256
const startAtFuncIndex = getStartFuncIndex ( ast ) ;
Original file line number Diff line number Diff line change @@ -29,30 +29,20 @@ const decoderOpts = {
29
29
ignoreDataSection : true
30
30
} ;
31
31
32
- /** @type {WeakMap<Module, TODO> } */
33
- const astStore = new WeakMap ( ) ;
34
-
35
32
class WebAssemblyParser extends Tapable {
36
33
constructor ( options ) {
37
34
super ( ) ;
38
35
this . hooks = { } ;
39
36
this . options = options ;
40
37
}
41
38
42
- static getAst ( module ) {
43
- return astStore . get ( module ) ;
44
- }
45
-
46
39
parse ( binary , state ) {
47
40
// flag it as ESM
48
41
state . module . buildMeta . exportsType = "namespace" ;
49
42
50
43
// parse it
51
44
const ast = decode ( binary , decoderOpts ) ;
52
45
53
- // cache it to be available for generators
54
- astStore . set ( state . module , ast ) ;
55
-
56
46
// extract imports and exports
57
47
const exports = ( state . module . buildMeta . providedExports = [ ] ) ;
58
48
t . traverse ( ast , {
You can’t perform that action at this time.
0 commit comments