Skip to content

Commit

Permalink
fix(plugin): soft warning when failed to parse wasm modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 16, 2024
1 parent 3273a03 commit 7852aa2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ const unplugin = createUnplugin<UnwasmPluginOptions>((opts) => {
if (_parseCache[name]) {
return _parseCache[name];
}
const parsed = parseWasm(source, { name });
const imports: Record<string, string[]> = Object.create(null);
const exports: string[] = [];
for (const mod of parsed.modules) {
exports.push(...mod.exports.map((e) => e.name));
for (const imp of mod.imports) {
if (!imports[imp.module]) {
imports[imp.module] = [];

try {
const parsed = parseWasm(source, { name });
for (const mod of parsed.modules) {
exports.push(...mod.exports.map((e) => e.name));
for (const imp of mod.imports) {
if (!imports[imp.module]) {
imports[imp.module] = [];
}
imports[imp.module].push(imp.name);
}
imports[imp.module].push(imp.name);
}
} catch (error) {
console.warn(`[unwasm] Failed to parse WASM module ${name}:`, error);
}

_parseCache[name] = {
imports,
exports,
Expand Down

0 comments on commit 7852aa2

Please sign in to comment.