On Wed, Jun 20, 2018 at 10:44 AM Sultan <thysul...@gmail.com> wrote:

>
> Additionally there are aspects that bundlers have a hard time replicating
> when using ES modules as an authoring format. Consider the following
> example, where ES modules might maintain a "live" binding.
>
> ```
> // a.js
> import {b} from './b.js'
>
> setTimeout(() => console.log(b), 400)
>
> // b.js
> export var b = 1
>
> setTimeout(() => b++, 200)
> ```
>
> A bundler on the other hand might be forced to produce static bindings.
>
> ```
> var $b1 = 1
>
> setTimeout(() => $b1++, 200)
>
> var $b2 = $b1
>
> setTimeout(() => console.log($b1), 400)
> ```
>

 Or recognize bindings that might be reassigned and use the mangled export
binding directly instead of introducing a local for the import bindings:

```
var $b1 = 1
setTimeout(() => $b1++, 200)

setTimeout(() => console.log($b1), 400)
```

Or allocate a cell for reassignable bindings:

```
var $b1 = [1]
setTimeout(() => $b1[0]++, 200)

var $b2 = $b1
setTimeout(() => console.log($b2[0]), 400)
```

No?

Maybe I'm treading on "sufficiently smart transpiler" territory but it
seems to me that live bindings can be handled simply with a bit of overhead
that can be often eliminated in the common case with only local analysis.

And to the degree that this is a problem, it's a problem as long as there's
a gap between inline module support becoming available and bundlers
end-of-lifing support for previous versions of EcmaScript as an output
language option.

Unless I'm missing something,  inline modules are unnecessary for live
bindings and insufficient given the need to support older versions as
output languages for at least some time.

----

Did you address my question about importing inline modules?  If so, I
must've missed it.

----

> They would act akin to hoisted functions declarations in that regard,

I'm also unclear what function hoisting has to do with module declarations
inside loops or conditionals if that's allowed.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to