Module Comments

Andreas Rossberg rossberg at
Sun Dec 9 04:09:53 PST 2012

On 9 December 2012 03:51, Domenic Denicola <domenic at> wrote:
>> From: Andreas Rossberg [mailto:rossberg at]
>> 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.
>> 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.
> Thanks for the feedback Andreas; this is really helpful. It took me a while to figure out what you meant by this, but I think I understand now. However, I think that since the bindings are const bindings, the difference between copying and aliasing is unobservable—is that right?

No, because what you are aliasing isn't const. Consider:

  module A {
    export let x = 4
    export function f() { x = 5 }

  import {x, f} from A
  print(x)  // 5

Moreover, it is still up in the air whether exported mutable bindings
should be mutable externally or not. V8, for example, currently allows
that, and although it doesn't implement 'import' yet you can access
the module directly:

  A.x = 6
  print(A.x)  // 6

That is the natural behaviour if you want to be able to use modules as
a name spacing mechanism. Same in TypeScript, by the way.

>> You could also consider imports always meaning copying, but then you exporting a variable will no longer be useful.
> This is the part that made me question whether I understand what you're saying. What do you mean by "exporting a variable" and "useful"?

I hope the example(s) clarify it. :)


More information about the es-discuss mailing list