Skip to content

Commit

Permalink
Handle unused imported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Mar 15, 2021
1 parent 41dae7a commit 3de60b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/tests/unused-import/asc.ts
@@ -0,0 +1,5 @@
declare function other(): void;

export function thing(): i8 {
return -1;
}
6 changes: 6 additions & 0 deletions test/tests/unused-import/test.js
@@ -0,0 +1,6 @@
describe("as-bind", function() {
it("should handle unused imported functions gracefully", async function() {
const instance = await AsBind.instantiate(this.rawModule);
assert(instance.exports.thing() === -1);
});
});
5 changes: 5 additions & 0 deletions transform.js
Expand Up @@ -86,6 +86,11 @@ class AsBindTransform extends Transform {
const typeIds = {};
const importedFunctions = {};
for (let importedFunction of flatImportedFunctions) {
// An imported function with no instances is an unused imported function.
// Skip it.
if (!importedFunction.instances) {
continue;
}
if (
importedFunction.instances.size > 1 ||
!importedFunction.instances.has("")
Expand Down

0 comments on commit 3de60b4

Please sign in to comment.