ModuleImport

David Herman dherman at mozilla.com
Thu Jun 19 07:04:59 PDT 2014


On Jun 19, 2014, at 3:31 AM, Michał Gołębiowski <m.goleb at gmail.com> wrote:

> Thanks, Dave, for bringing that up, it shows you're open for feedback. That said (bikeshed begins),

lol :)

> what's wrong with:
> ```js
> import "fs" as fs;
> ```

Indeed we've talked about that one before. Some objected to the inconsistency of having the binding appear at the end and not having the module name at the end (all other import forms have the binding on the left and the module name at the end). But more importantly, this doesn't help with the problem of visually disambiguating from importing the default export. To put it another way, the `*` is critical in the `* as _` syntax, because it makes it explicit that we're talking about the named exports.

> ? I feel that a lot of effort went in ES6 into reducing boilerplate via e.g. arrow functions, classes etc. but if you start with Node's require, this adds clutter. Compare these 3 forms of importing all the module "lodash" bindings to an object _:
> ```js
> var _ = require("lodash"); // Node
> import * as _ from "lodash"; // Dave's syntax
> import "lodash" as _;
> ```

My feeling is that the clutter is small, and it's acceptable to have it be slightly less minimal than default export since that is the case we are favoring. This isn't so cluttered as to be downright *punishing* multi-export utility modules (it's literally only two characters longer than your Node code, albeit admittedly a little chattier), but it's good that default import is the winner.

Dave



More information about the es-discuss mailing list