simpler, sweeter syntax for modules

Axel Rauschmayer axel at rauschma.de
Wed Mar 21 16:05:40 PDT 2012


I like it, more in line with AMDs and Node.js modules.

Honest question: Are nested modules really needed?

On Mar 21, 2012, at 23:28 , David Herman wrote:

> H'lo,
> 
> Thanks to some a-maz-ing [1] work by Andreas Rossberg (I'll spare the gory algorithmic details), the linking process no longer needs the syntactic distinction that static module bindings are only created via the `module` (contextual) keyword. This frees us up to simplify the syntax, making much less use of the `module` keyword and much more use of `import`.
> 
> I've drafted a new syntax that is both much simpler and, I think, far more intuitive than the previous version.
> 
> Examples:
> 
> * importing an external module:
> 
>    import "foo.js" as Foo;
> 
> * importing a module's export:
> 
>    import foo from "foo.js";
>    import bar from Bar;
>    import baz from bar.mumble.quux;
> 
> * importing all exports:
> 
>    import * from Bar;
> 
> * importing with renaming:
> 
>    import { draw: drawGun }    from "cowboy.js",
>           { draw: drawWidget } from "widgets.js";
> 
> * defining a module (same as ever):
> 
>    module m { ... }
> 
> * aliasing a module for convenience:
> 
>    module m = foo.bar.baz;
> 
> This new syntax is up on the wiki:
> 
>    http://wiki.ecmascript.org/doku.php?id=harmony:modules
> 
> A couple conventions to note about this:
> 
> * the "as" contextual keyword signifies renaming the module *itself*
> 
> * the "from" contextual keyword always signifies extracting an export /from/ the module
> 
> * while "import" no longer strictly means extracting an export, it matches common spoken usage better -- "import" is used both to mean extracting exports /and/ loading external modules
> 
> * despite this overloading, a single "import" declaration is *only* ever importing modules or importing bindings, never both
> 
> Comments welcome [2],
> Dave
> 
> [1] Really. You have no idea.
> [2] Translation: Unleash the hounds of bikeshedding! ;-P
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120322/b03300dc/attachment-0001.html>


More information about the es-discuss mailing list