Inline ES Modules

Isiah Meadows isiahmeadows at
Tue Jun 19 07:09:24 UTC 2018

Few thoughts:

1. Almost all of my actual use cases for inline modules have been
solvable via just creating a new file.
2. If you need a file for a bunch of constants, that's not really a
problem, and in my experience is more maintainable.
3. If you need to group those constants, you have a few options:
either prefix the constants, put them in objects, or put them in
another file by themselves.
4. If you really need modules, conditionally creating namespaces for
them, you should really be considering using objects instead. If
they're complex enough, you can put them in another file and export a
factory returning what you need.
5. This idea will be of zero assistance to bundlers supporting ES6,
who already know to rename variables to retain proper encapsulation
without creating new closures. (The only way you can observe it is
with the presence of `eval`, and a bundler could warn about that if
necessary.) They also know that module namespace objects are basically
frozen objects whose entries happen to generally have descriptors with
`[[Writable]]: true` (a mild lie). It doesn't affect transpiler
writers beyond that of having to process the new syntax.


Isiah Meadows
me at

On Mon, Jun 18, 2018 at 9:04 AM, Mike Samuel <mikesamuel at> 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> 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
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list