Skip to content

Commit b48c5f7

Browse files
authored
fix: put entry files as first entry point of ASC to avoid recursive import issue (#98)
1 parent 6c25d93 commit b48c5f7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/core/compile.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4052
async 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

Comments
 (0)