A few more questions about the current module proposal

Russell Leggett russell.leggett at gmail.com
Thu Jul 5 10:33:54 PDT 2012

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? Would I then have to
say "export module Foo..." and later "import Foo from "foo.js;"?

Also, I have a suggestion. It has recently been discussed about how to work
with legacy code. For example, the classic example of wanting to import
jQuery even if it is not defined as a module. What if we just allowed for
the syntax:

    import "jquery.js"

with no "as" or "from". This would assume jquery.js is not a module file.
It would fail early if there were any imports or exports, and it would
execute in the global scope just like a script tag. The value of it,
though, would be to allow for a declaration of the dependency, and the
ability to load it without putting in a script tag. If multiple modules
import it, it would only be loaded once, and executed in the first place it
was needed, all without needing to include it with a script tag. Because it
is not allowed to contain imports, it would not be capable of causing
circular dependency issues, and because it does not have exports, it cannot
be interpreted as a module and used with the from/as syntax.

- Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120705/99521f1a/attachment.html>

More information about the es-discuss mailing list