Inline ES Modules
Sultan
thysultan at gmail.com
Wed Jun 20 14:44:27 UTC 2018
They would act akin to hoisted functions declarations in that regard, For
example
```
import {getPersonType} from School
if (Math.random() < 0.5) {
module School {
export function getPersonType() {}
}
}
```
Largely yes, the utility is in providing bundlers and authors with a
encapsulated order-independent "concat-able" standard format to output to,
considering the hurdles presented with the "waterfall of requests" problem
that can afflict current native ES modules.
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)
```
On Mon, Jun 18, 2018 at 4:04 PM, Mike Samuel <mikesamuel at gmail.com> wrote:
> How would an inline module be imported? Module descriptors are roughly
> relative URLs so can refer to a JavaScript source file, but it sounds like
> you'd need something more fine-grained to refer to an inline module. Using
> fragments to refer to a passage within a document instead of a location
> might have unintended effects.
>
> Also, assuming that problem is solved, does the below mean anything
> if (Math.random() < 0.5) {
> module School {
> export function getPersonType() {}
> }
> }
>
> If not, if inline modules are defined eagerly, what advantages, besides
> making life easier for transpiler writers, would inline modules have over
> exporting frozen namespaces?
>
>
>
> On Sun, Jun 17, 2018 at 10:34 AM Sultan <thysultan at gmail.com> wrote:
>
>> Are there any open proposals/discussions related to creating ES modules
>> inline? For example:
>>
>> ```
>> import getPersonType from School
>>
>> module School {
>> export function getPersonType (person) {
>> switch (person) {
>> case 'Teacher': return 'A teacher'
>> case 'Director': return 'A director'
>> }
>> }
>> }
>> ```
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180620/72d01369/attachment.html>
More information about the es-discuss
mailing list