ModuleImport

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


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

> 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";
  else
    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.

-c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140619/29d7754c/attachment.html>


More information about the es-discuss mailing list