File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
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" ) ;
9
10
10
11
const { editWithAST, addWithAST } = require ( "@webassemblyjs/wasm-edit" ) ;
11
12
const t = require ( "@webassemblyjs/ast" ) ;
@@ -243,7 +244,7 @@ const addInitFunction = ({
243
244
244
245
class WebAssemblyGenerator extends Generator {
245
246
generate ( module ) {
246
- const ast = module . _ast ;
247
+ const ast = WebAssemblyParser . getAst ( module ) ;
247
248
const bin = module . originalSource ( ) . source ( ) ;
248
249
249
250
const importedGlobals = getImportedGlobals ( ast ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ const { decode } = require("@webassemblyjs/wasm-parser");
10
10
const { Tapable } = require ( "tapable" ) ;
11
11
const WebAssemblyImportDependency = require ( "../dependencies/WebAssemblyImportDependency" ) ;
12
12
13
+ /** @typedef {import("../Module") } Module */
14
+
13
15
/**
14
16
* @param {t.ModuleImport } n the import
15
17
* @returns {boolean } true, if a memory was imported
@@ -27,20 +29,30 @@ const decoderOpts = {
27
29
ignoreDataSection : true
28
30
} ;
29
31
32
+ /** @type {WeakMap<Module, TODO> } */
33
+ const astStore = new WeakMap ( ) ;
34
+
30
35
class WebAssemblyParser extends Tapable {
31
36
constructor ( options ) {
32
37
super ( ) ;
33
38
this . hooks = { } ;
34
39
this . options = options ;
35
40
}
36
41
42
+ static getAst ( module ) {
43
+ return astStore . get ( module ) ;
44
+ }
45
+
37
46
parse ( binary , state ) {
38
47
// flag it as ESM
39
48
state . module . buildMeta . exportsType = "namespace" ;
40
49
41
50
// parse it
42
51
const ast = decode ( binary , decoderOpts ) ;
43
52
53
+ // cache it to be available for generators
54
+ astStore . set ( state . module , ast ) ;
55
+
44
56
// extract imports and exports
45
57
const exports = ( state . module . buildMeta . providedExports = [ ] ) ;
46
58
t . traverse ( ast , {
@@ -70,8 +82,6 @@ class WebAssemblyParser extends Tapable {
70
82
}
71
83
} ) ;
72
84
73
- state . module . _ast = ast ;
74
-
75
85
return state ;
76
86
}
77
87
}
You can’t perform that action at this time.
0 commit comments