stealjs / transpile

Transpiles from everything to everything else

Home Page:https://www.npmjs.com/package/transpile

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slim exports break variable context

m-mujica opened this issue · comments

for a module like:

const locales = ['en', 'es', 'hi', 'zh', 'ar'];

export default locales[getRandomInt(0, locales.length)];

function getRandomInt(min, max) { ... }

The slim output is:

[
  2,
  function(stealRequire, stealExports, stealModule) {
    Object.defineProperty(stealExports, "__esModule", { value: true });
    stealExports.default = locales[getRandomInt(0, locales.length)];
    var locales = ["en", "es", "hi", "zh", "ar"];
    function getRandomInt(min, max) { ... }
  }
];

This line stealExports.default = locales[getRandomInt(0, locales.length)]; breaks because the locales var definition is after the variable is used.

The slim output places exports before imports so the exported values are available in circular dependencies, we have to find a way of keeping the behaviour without breaking context.