Quantifying Default Exports

Guy Bedford guybedford at gmail.com
Tue Jul 22 21:16:33 PDT 2014


This is why I have previously posted asking for a function to determine if
a given object is a module object.

Given such a function, *Reflect.isModule* say, we can convert our code to
AMD or CommonJS like the following:

import p from 'module';

Converts to CommonJS:

var module = require('module');
if (!Reflect.isModule(module)) {
  module = { default: module };
}
var p = module['default'];

Now whether the module is an ES6 module or another CommonJS module, we get
what we expect.



On 22 July 2014 20:43, Kevin Smith <zenparsing at gmail.com> wrote:

>
>> We then conditionally add this wrapper based on detecting if the import
>> is an ES6 module. This is the same method we have for AMD compilations at
>> the moment, which seems to have been working well.
>>
>
> Just a side note, but for performance reasons in a real runtime system you
> can't pre-determine whether the target is an ES6 module or not - that would
> imply double-parsing and would necessarily be heuristic and incomplete.
>
> In the end, either the import side or some preconfigured application state
> will have to explicitly specify which targets are ES6 and which are not.
>
> I've worked though most of these issues already in es6now, which provides
> a complete picture of a backward compatible ES6 module system running on
> Node.
>
> https://github.com/zenparsing/es6now/blob/master/docs/modules.md
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140722/c66ea735/attachment.html>


More information about the es-discuss mailing list