A few more questions about the current module proposal

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

On Thu, Jul 5, 2012 at 1:33 PM, Russell Leggett
<russell.leggett at gmail.com> wrote:
> Oh, I also meant to ask - I do have a question of my own. It seems so basic,
> but I can't figure it out. If I have a file that contains two modules -
> let's say in foo.js
> ------- foo.js ----------------
>     module Foo {
>         export let x = 42;
>     }
>     module Bar {
>         export let y = 12;
>     }
> and I try to do:
>     import y from "foo.js"
> What happens? Similar problem if I try to do
>     import "foo.js" as Foo
> Am I incorrect in thinking that there can be more than one top level module?
> Or is it that an imported file is automatically a module, and therefore Foo
> and Bar are nested modules in this case?

When you write:

    import A from "B.js";

that's implicity wrapping "B.js" in a module which you create (unnamed
here), and then importing `A` from it.  So yes, `Foo` and `Bar` are
nested modules.  It's important for the importer to control the outer
module in the import.

> Would I then have to say "export
> module Foo..." and later "import Foo from "foo.js;"?

Yes, that would be the correct way to write this example,
sam th
samth at ccs.neu.edu

More information about the es-discuss mailing list