Module Comments

Andreas Rossberg rossberg at
Thu Dec 6 08:30:39 PST 2012

On 6 December 2012 16:44, Domenic Denicola <domenic at> wrote:
> For the record, here's the idea Yehuda and I worked out:
> I would *really* appreciate if people read it (it's easy reading, I
> promise!) and incorporated some of our concerns and ideas into their
> thinking on module syntax.

I strongly agree with having the

import x from ...
import {x, y} from ...

symmetry and consistent binding on the left. However, the more radical
parts of your proposal (allowing arbitrary export expressions, and
arbitrary import patterns) do not work.

The problem is that imports are not normal variable assignments. They
do not copy values, like normal destructuring, they are aliasing
bindings! If you were to allow arbitrary expressions and patterns,
then this would imply aliasing of arbitrary object properties. Not
only is this a completely new feature, it also is rather questionable
-- the aliased location might disappear, because objects are mutable.


  module A {
    let o = {
      x: [1, 2],
      f() { o.x = 666 }
    export o

  import {x: [a, b], f} from A
  a = 3  // is this supposed to modify the array?
  print(a)  // x is no longer an array, a doesn't even exist

In other words, what you are proposing has no longer anything to do
with static scoping.

You could arguably make this saner by interpreting nested patterns in
an import as copying, not aliasing, but I think mixing meanings like
that would be rather confusing and surprising.

You could also consider imports always meaning copying, but then you
exporting a variable will no longer be useful.


More information about the es-discuss mailing list