Module import/export bindings

André Bargull andre.bargull at udo.edu
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;
> FOO.foo = 300;

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



More information about the es-discuss mailing list