export must be static. For conditional exports, CommonJS and exports modules can be used.
It should be processed using ES6 modules as follows:
export let Foo; if (window.Foo === undefined) { Foo = class Foo { ... } } else { Foo = window.Foo; }
For a platform-independent solution ( this may not be global in the converted code), the window can be replaced with
const root = (() => eval)()('this'); if (root.Foo === undefined) { ...
This uses the ES6 module binding function, which was designed in this way to handle circular dependencies and has greatly explained.
The code above translates to
... var Foo = exports.Foo = void 0; if (window.Foo === undefined) { exports.Foo = Foo = function Foo() { _classCallCheck(this, Foo); }; } else { exports.Foo = Foo = window.Foo; }
In this case, the export is not conditional, but the value of Foo associated with this export is conditional.
estus
source share