@@ -37,11 +37,23 @@ function getAscArgs(sources: string[], outputWasm: string, outputWat: string, fl
3737 return ascArgv ;
3838}
3939
40+ function combineWithEntryFiles ( {
41+ testCodePaths,
42+ entryFiles,
43+ } : {
44+ testCodePaths : string [ ] ;
45+ entryFiles : string [ ] ;
46+ } ) : string [ ] {
47+ // Because AS has recursive import resolution issue.
48+ // put entryFiles firstly will force ASC compile entry file firstly, which can avoid compilation failed due to test files import ordering
49+ return entryFiles . concat ( testCodePaths ) ;
50+ }
51+
4052async function unifiedCompile ( testCodePaths : string [ ] , entryFiles : string [ ] , option : CompileOption ) : Promise < string > {
4153 const { outputFolder, flags } = option ;
4254 const outputWasm = join ( outputFolder , "test.wasm" ) . replaceAll ( / \\ / g, "/" ) ;
4355 const outputWat = join ( outputFolder , "test.wat" ) . replaceAll ( / \\ / g, "/" ) ;
44- const ascArgv = getAscArgs ( testCodePaths . concat ( entryFiles ) , outputWasm , outputWat , flags ) ;
56+ const ascArgv = getAscArgs ( combineWithEntryFiles ( { testCodePaths , entryFiles } ) , outputWasm , outputWat , flags ) ;
4557 await ascMain ( ascArgv , false ) ;
4658 return outputWasm ;
4759}
@@ -58,7 +70,12 @@ async function separatedCompile(
5870 const outputWasm = getNewPath ( outputFolder , root , testCodePath ) . slice ( 0 , - 2 ) . concat ( "wasm" ) ;
5971 wasm . push ( outputWasm ) ;
6072 const outputWat = getNewPath ( outputFolder , root , testCodePath ) . slice ( 0 , - 2 ) . concat ( "wat" ) ;
61- const ascArgv = getAscArgs ( [ testCodePath , ...entryFiles ] , outputWasm , outputWat , flags ) ;
73+ const ascArgv = getAscArgs (
74+ combineWithEntryFiles ( { testCodePaths : [ testCodePath ] , entryFiles } ) ,
75+ outputWasm ,
76+ outputWat ,
77+ flags
78+ ) ;
6279 await ascMain ( ascArgv , false ) ;
6380 } ;
6481
0 commit comments