In implementing the Python module mechanism on top of ES6 modules for the Transcrypt Python to JavaScript compiler, I am faced with the following problem:
There are a large number of standard functions imported from the Python runtime module, like e.g. the Python input
function (implemented in JS), which can be made available using named imports (since they shouldn't have to be prefixed with anything in the user code, so input
rather than __runtime__.input
, to be consistent with Python).
In Python it's allowed to rebind named imports. So I define another function input
, which will override the one from the runtime. But if I do so in JS, I get an error:
Identifier 'input' has already been declared
It seems that all imported names are regarded as JS consts, so non-rebindable according to this article. I can think of several clever workarounds, like importing under an alias and then assigning to a module global var rather than const, but like to keep things simple, so my question is:
- Am I right that JS named imports are consts, so non-rebindable (and if so, just curious, anyone knows WHY)? Where can I find details on this?
- Is there a simple way to circumvent that and still put them in the global namespace of the importing module, but override them at will?