ModuleImport

Brian Di Palma offler at gmail.com
Thu Jul 3 01:41:44 PDT 2014


> So sometimes someone can need it, so we must have good support? Is that how we operate these days?

Imagine a large codebase which already has transitive cyclic dependencies.
If the module system has poor support for them it might still work
with them until one day a developer reordered the import statements.
How would you feel if such a simple operation caused you issues?

Or upgrading to the latest version of a popular utility toolchain like
lo-dash could introduce an issue purely because the upgrade created a
transitive cyclic dependency.
And the fix for that would be to reorder your import statements and
add comments in your module telling people not to change the order.
Again, how would you feel?

TC39 has decided to spare us all those special moments by including
good cyclic dependency support.

> // I don't actually know how someone would even access the default exports from the module object

Like so,

```
System.import("MyClass")
    .then(function (myClassModule) {
        myClassModule.default
    });
```

Default import and exports are purely sugar over

```
import {default as MyClass} from 'MyClass';
```

It saves you a few character typing out when importing from legacy
module system.

```
import MyClass from 'MyClass';
```

Those two are the same thing.

>From birth the brand new module system is going to have this
superfluous appendage to support module systems that 10 years from now
people will struggle to remember.


More information about the es-discuss mailing list