diff --git a/src/passes/J2CLOpts.cpp b/src/passes/J2CLOpts.cpp index d0df446e1ff..9cec5936ea4 100644 --- a/src/passes/J2CLOpts.cpp +++ b/src/passes/J2CLOpts.cpp @@ -88,6 +88,10 @@ class GlobalAssignmentCollector : assignmentCounts(assignmentCounts) {} void visitGlobal(Global* curr) { + // Ignore imported globals, e.g., JS prototypes. + if (curr->imported()) { + return; + } if (isInitialValue(curr->init)) { return; } diff --git a/test/lit/passes/j2cl.wast b/test/lit/passes/j2cl.wast index e17d9f43c1c..2c566dcd804 100644 --- a/test/lit/passes/j2cl.wast +++ b/test/lit/passes/j2cl.wast @@ -351,3 +351,10 @@ ) ) ) + +;; Imported globals are ignored +(module + ;; CHECK: (import "a" "b" (global $a.b (ref extern))) + (import "a" "b" (global $a.b (ref extern))) +) +