Is there a way to have Transcrypt export all imported symbols in a module?

113 Views Asked by At

I have a medium-sized Python project that I'm trying to Transcrypt into ES6. One portion of the project is a lot of internals, and I've stashed it away in a "private" package (bezoar._model). I have a roll-up Python module bezoar.model that exports the front-facing components in bezoar._model by simply importing them. In Python, anything that is imported is implicitly exported. And I have noticed this seems (?) to be a standard practice, including some modules provided by the standard library in CPython.

In ES6, the same is not true. One must explicitly export foo from jsmodule to re-export symbols from another module. I hand-modified the generated ES6 to replace import foo from jsmodule with export foo from jsmodule and it worked as expected.

Is there any way to convince Transcrypt to do this for me?

I tried using __pragma__('js', ...), but it inserted the code after the import section, which wasn't (apparently) allowed by ES6.

Example

_modfoo.py:

def foo():
    pass

rollup.py:

from _modfoo import foo

transcrypt generated rollup.js:

import {foo} from './_modfoo.js'
var __name__ = 'rollup'

rexporting version of rollup.js:

export {foo} from './_modfoo.js'
var __name__ = 'rollup'
1

There are 1 best solutions below

0
David Ghandehari On

Somehow I missed this from transcrypt -h:

  -xr, --xreex          re-export all imported names

Works as advertised.