A few more questions about the current module proposal

Andreas Rossberg rossberg at google.com
Fri Jul 6 02:00:14 PDT 2012


On 5 July 2012 19:06, Russell Leggett <russell.leggett at gmail.com> wrote:

> So I guess my take on it is that any import statement should be illegal
> inside of eval.
>

Dave and I have been discussing modules vs eval a while ago. My take is
that we should actually disallow any kind of module construct inside eval,
because it is not clear what it should mean in general. In particular, it
seems to be introducing local modules through the back door. The problem is
actually amplified by 1JS, because you could write an old-school direct
eval as in

// non-strict mode
function f() {
  eval("module A { ... }");
  ...
}

and the only sane interpretation of this (under lexical scoping) would be
that you have created a module in the local scope of f. Since local modules
induce quite a number of additional complications, I don't think going that
route is well-advised for the time being (we can always decide to relax the
language later, once we have more experience with modules).


On 5 July 2012 19:34, Jussi Kalliokoski <jussi.kalliokoski at gmail.com> wrote:

> The implications of banning import in eval is that modules for an existing
> evaling module loader can't adopt the new modules system, quite possibly
> incurring this decision to projects using those modules as well. How much
> this would allegedly slow down adoption, I can't tell. Maybe it's
> insignificant.
>
> Another thing it means is that eval() would no longer do what it says on
> the box, i.e. evaluate an expression of JS, as the code inside eval() would
> be a whole different JS.
>

No, that is not actually true. It is merely a question of what you are
parsing the eval string as. Roughly, it would be a function body, not a
program. In ES5, there is no difference, but in ES6 there will be (because
modules are global only), so we can make a choice. Since eval can occur
locally, it is very natural to allow local declarations only (especially
under 1JS, see my example above).

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


More information about the es-discuss mailing list