A few more questions about the current module proposal

Sam Tobin-Hochstadt samth at ccs.neu.edu
Thu Jul 5 11:17:29 PDT 2012

On Thu, Jul 5, 2012 at 1:06 PM, 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. Looking at the proposal, that doesn't sound like it, though.

I don't think we should ban `import` from `eval` -- `eval` is a
powerful feature that has been used to good effect in lots of ways,
and we don't want to cripple it.

> Let's take the "loadFromUrl" out of the equation.
>     import foo from "baz"
>     var code = 'import foo from "bar"';
>     eval(code);
>     console.log(foo);
> There is a reason why import got special syntax, and it wasn't just so that
> it would be easier to type. Putting it inside eval eliminates any ability
> for static analysis to happen upfront during the parse before actually
> executing. The import dependency cannot be seen, and in this case there is a
> collision on "foo" which should have been detected at compilation time. I
> can think of a dozen other reasons why imports should not be allowed in
> eval, but that's just one which seems like a pretty clear problem.

This problem is already there if I write `code` as `'var foo = "bar"'`
(how's that for excessive quotation?).  Direct `eval` is powerful and
potentially scary already.  We could specify the semantics of `eval`
such that your example doesn't bind `foo` in code after the `eval`,
but I don't think that has much to do with the other issues here.
sam th
samth at ccs.neu.edu

More information about the es-discuss mailing list