Skip to content

Commit

Permalink
chore: apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Dec 13, 2023
1 parent bfdfb21 commit bf019aa
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/rollup/plugins/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function wasmImport(): Plugin {
return null;
}
if (id.startsWith(WASM_ID_PREFIX)) {
return id
return id;
}

// Resolve the source file real path
Expand Down Expand Up @@ -78,24 +78,21 @@ export function wasmImport(): Plugin {
if (asset) {
return {
code: `export default "${asset.id}";`,
map: null
}
map: null,
};
}
},
renderChunk(code, chunk) {
if (
!chunk.moduleIds.some(id => id.startsWith(WASM_ID_PREFIX)) ||
!chunk.moduleIds.some((id) => id.startsWith(WASM_ID_PREFIX)) ||
!code.includes(WASM_ID_PREFIX)
) {
return null;
}
const s = new MagicString(code);
const ReplaceRE = new RegExp(`"(${WASM_ID_PREFIX}[^"]+)"`, "g");
const resolveImport = (id) => {
if (
typeof id !== "string" ||
!id.startsWith(WASM_ID_PREFIX)
) {
if (typeof id !== "string" || !id.startsWith(WASM_ID_PREFIX)) {
return null;
}
const asset = wasmImports.get(id);
Expand All @@ -110,8 +107,10 @@ export function wasmImport(): Plugin {
for (const match of code.matchAll(ReplaceRE)) {
const resolved = resolveImport(match[1]);
if (!resolved) {
console.warn(`Failed to resolve WASM import: ${JSON.stringify(match[1])}`);
continue
console.warn(
`Failed to resolve WASM import: ${JSON.stringify(match[1])}`
);
continue;
}
s.overwrite(
match.index,
Expand All @@ -122,10 +121,10 @@ export function wasmImport(): Plugin {
if (s.hasChanged()) {
return {
code: s.toString(),
map: s.generateMap({ includeContent: true })
map: s.generateMap({ includeContent: true }),
};
}
}
},
};
}

Expand Down

0 comments on commit bf019aa

Please sign in to comment.