Using Transcrypt for python to javascript compiling I have 2 modules that need each other. For example:
myTest.py:
import myTest2
def test():
myTest2.test()
someConstant = 1
and myTest2.py:
import myTest
def test():
console.log(myTest.someConstant)
After compiling to javascript, and calling myTest.test()
I get an RangeError: Maximum call stack size exceeded.
How can I avoid this, but keep 2 modules which use each other?
Thanks in advance.
In Transcrypt imports are resolved at compile time rather than runtime, since the compiler must know which modules to include in the generated JavaScript. Moreover, import resolution happens in one pass. This fact that resolution happens in a single pass means that mutual (or in general cyclic) imports are not supported.
So if you have two modules that require something of each other, the way to go is to factor that something out and put in in a third module, imported by both.
The fact that resolution happens at compile time also means that there's no point in runtime conditional imports, using 'if'. For conditional imports use __pragma__ ('ifdef', ...) which does its work compile time.
Restrictions like this are explained at:
http://www.transcrypt.org/docs/html/special_facilities.html#transcrypt-s-module-mechanism