Modules: Curly Free

Kevin Smith zenparsing at
Tue Apr 16 06:06:37 PDT 2013

Currently, curly braces are used within import and export declarations:

    import { something } from "url";
    import { something: renamed } from "url";
    import { a, b, c } from "url";

    export { something };
    export { renamed: something };
    export { a, b, c };

The import and export curlies are analogies for destructing and object
literal syntax, respectively.  This analogy is problematic for the
following reasons:

1) Destructuring declarations create new variables, whereas import
declarations create aliases for existing variables.  This distinction is
subtle and can lead to misunderstandings about module semantics.

2) Beginners tend to get the "direction" of renaming wrong with
destructuring syntax:

    let { myX: x } = { x: "value" }; // Oops!

Since destructuring is an intermediate to advanced feature, it's not a big
problem in that context.  But importing is one of the most basic features
in the language.  We don't want to have a stumbling block right at the
front door.

3) Curly braces within export declarations suggest a false semantics in
which an object literal expression can be exported:

    // Since is ok:
    export { exportedA: a };

    // It leads one to believe that this is ok:
    export { exportedA: "some-value" };

Given those considerations, I think we should find a curly-free syntax for
import and export declarations.  Here is a proposal:

    import something from "url";
    import something as renamed from "url";
    import a, b, c from "url";

    export something;
    export something as renamed;
    export a, b, c;

In the above syntax, "as" becomes the unified keyword for renaming module

For an analysis of the ASI issues, see:

{ Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list