@@ -24,6 +24,25 @@ const isMemoryImport = n => n.descr.type === "Memory";
2424 */
2525const isTableImport = n => n . descr . type === "Table" ;
2626
27+ const JS_COMPAT_TYPES = new Set ( [ "i32" , "u32" , "f32" ] ) ;
28+
29+ /**
30+ * @param {t.ModuleImport } moduleImport the import
31+ * @returns {null | string } the type incompatible with js types
32+ */
33+ const getJsIncompatibleType = moduleImport => {
34+ if ( moduleImport . descr . type !== "FuncImportDescr" ) return null ;
35+ const signature = moduleImport . descr . signature ;
36+ for ( const param of signature . params ) {
37+ if ( ! JS_COMPAT_TYPES . has ( param . valtype ) )
38+ return `${ param . valtype } as parameter` ;
39+ }
40+ for ( const type of signature . results ) {
41+ if ( ! JS_COMPAT_TYPES . has ( type ) ) return `${ type } as result` ;
42+ }
43+ return null ;
44+ } ;
45+
2746const decoderOpts = {
2847 ignoreCodeSection : true ,
2948 ignoreDataSection : true
@@ -51,14 +70,18 @@ class WebAssemblyParser extends Tapable {
5170 } ,
5271
5372 ModuleImport ( { node } ) {
73+ /** @type {false | string } */
5474 let onlyDirectImport = false ;
5575
5676 if ( isMemoryImport ( node ) === true ) {
57- onlyDirectImport = true ;
58- }
59-
60- if ( isTableImport ( node ) === true ) {
61- onlyDirectImport = true ;
77+ onlyDirectImport = "Memory" ;
78+ } else if ( isTableImport ( node ) === true ) {
79+ onlyDirectImport = "Table" ;
80+ } else {
81+ const incompatibleType = getJsIncompatibleType ( node ) ;
82+ if ( incompatibleType ) {
83+ onlyDirectImport = `Non-JS-compatible Func Sigurature (${ incompatibleType } )` ;
84+ }
6285 }
6386
6487 const dep = new WebAssemblyImportDependency (
0 commit comments