`import` and hoisting

caridy caridy at gmail.com
Wed Mar 25 16:15:28 UTC 2015


yes, they will work. "hoisting of function initialization happens across the whole module linkage graph before any module initialization code starts executing." quoting @dherman.

there is one thing to keep in mind though: many edge cases cannot be transpile into CJS, AMD, etc., the only format that preserves all the semantics of the module system is the `system` format, which is an experimental format we came up with a while ago. those two examples might fail in babeljs, but they definitely work on esnext module transpiler (which is already deprecated), but at least will give you an idea of how things work internally: http://bit.ly/1ETGVDA

/caridy

> On Mar 20, 2015, at 2:20 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
> 
> As far as I can tell, `import` is hoisted (due to `ModuleDeclarationInstantiation`). Is the following code OK, then? No temporal dead zone?
> 
> ```js
> bar();
> 
> import {foo} from 'mymodule';
> 
> function bar() { // hoisted!
>     foo(); // already initialized?
> }
> ```
> 
> How about this code?
> 
> ```js
> foo();
> 
> import {foo} from 'mymodule';
> ```
> 
> Thanks!
> 
> Axel
> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de
> rauschma.de
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list