Chris Toshok toshok at
Thu Jun 19 11:06:39 PDT 2014

On Thu, Jun 19, 2014 at 10:53 AM, Matthew Robb <matthewwrobb at>

> What if the `import "module/id";` form was an expression that evaluated to
> the module instance object.
> This means everything stays as it is now except we remove the ModuleImport
> form and if you want to use the module instance object you can do: `var foo
> = import "foo";`. You could also do `var { bar } = import "foo";`
This is essentially identical to System.get("foo"), other than the
restriction on the argument being a string.  It lends itself to imperative
code when what you're after is a declarative syntax.

Making it an expression also means it's not a toplevel form in the grammar,
and so you could do things like this:

function foo() {
  if (someCondition)
    return import "module1";
    return import "module2";

or even similar to your examples:

var { bar } = someCondition ? import "foo" : import "bar";

which would make precise and static computation of the set of imports
impossible, and likely complicate module resolution as well.

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

More information about the es-discuss mailing list