-
Notifications
You must be signed in to change notification settings - Fork 12
Description
My project includes Haxe abstract over js.lib.Set, e.g. abstract Set<T>(js.lib.Set<T>) ... and also defines an iterator() method. The generated javascript for a call to iterator does not use the alias added to the import statement
e.g.
import {Set as Set__1} from "./Set.js"
...
let copy = Set__1.copy(this1);
let _g = Set_Impl_.iterator(other); // <---wrong symbol
I did a bit of investigation, and it looks like the issue is in a special case for iterators in ExprEmitter.hx lines 134-145. This code writes the Haxe class name directly (c.get().name) instead of emitting the value expression which would use the proper import alias. To fix, replace lines 136-138:
case FStatic(c, cf):
write(c.get().name); // Wrong: writes "Set_Impl_"
write(".iterator");
With:
case FStatic(c, cf):
emitValue(x); // Correct: uses import alias "Set__1"
emitField("iterator");
Also it wasn't immediately clear why the original code used write when other places use emitField, so I tried changing that too for consistency and it produces the correct result.
Happy to put up a PR if that would be helpful!