Module import/export bindings

André Bargull andre.bargull at
Sun Mar 15 12:52:35 UTC 2015

>  From my current understanding (based on other threads), this module:
> ```js
> var foo = 42;
> export default foo;
> export foo;
> foo = 10;

I guess you'd intended to write `export {foo as default}` instead of `export default foo`, because 
the latter exports the value of the expression when it gets evaluated. IOW it's the same as `export 
default 42`.

> However, I am curious if this binding is 2-way or only 1-way. What happens if I do:
> ```js
> import foo, * as FOO from "coolmodule";
> foo = 100;
> FOO.default = 200;
> = 300;

All three assignments throw a TypeError exception:
- The first assignment throws a TypeError in SetMutableBinding, step 6. (Import bindings 
are immutable - CreateImportBinding, step 5.)
- The second and third assignment throw a TypeError in PutValue, step 6.d. (Module namespace 
objects always return false from [[Set]] - [[Set]].)

More information about the es-discuss mailing list