Skip to content

Commit 3de60b4

Browse files
committed
Handle unused imported functions
1 parent 41dae7a commit 3de60b4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

test/tests/unused-import/asc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare function other(): void;
2+
3+
export function thing(): i8 {
4+
return -1;
5+
}

test/tests/unused-import/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe("as-bind", function() {
2+
it("should handle unused imported functions gracefully", async function() {
3+
const instance = await AsBind.instantiate(this.rawModule);
4+
assert(instance.exports.thing() === -1);
5+
});
6+
});

transform.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class AsBindTransform extends Transform {
8686
const typeIds = {};
8787
const importedFunctions = {};
8888
for (let importedFunction of flatImportedFunctions) {
89+
// An imported function with no instances is an unused imported function.
90+
// Skip it.
91+
if (!importedFunction.instances) {
92+
continue;
93+
}
8994
if (
9095
importedFunction.instances.size > 1 ||
9196
!importedFunction.instances.has("")

0 commit comments

Comments
 (0)