External and internal modules

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Mon Sep 9 11:32:14 PDT 2013

On Mon, Sep 9, 2013 at 6:26 AM, Sam Tobin-Hochstadt <samth at cs.indiana.edu>wrote:

> On Mon, Sep 9, 2013 at 3:33 AM, Dmitry Soshnikov
> <dmitry.soshnikov at gmail.com> wrote:
> > 2. As I understand, this `module "foo" { ... }` way of defining is
> either for inner modules (inside a parent external modules), or inside an
> external file which is not a module, but a script (and therefore, cannot be
> loaded as module).
> >
> > The first case isn't that useful -- I defined an inner module inside a
> parent external module, and then what? -- import it exactly in the same
> file? What is that mean? Naming collisions happen not that often inside a
> module (this is why it's a module), that sub-devide it on sub-modules.
> >
> > Or can I probably export this inner submodule from the parent? How this
> double import will look like, if it's even possible? First import the inner
> module form the parent, then bindings from the inner?
> There are no nested modules.
Thanks, let me understand further:

So, technically, if I have an external file "foo.js" like this:

export function foo() {};
module "bar" {}

then it's illegal (I have a nested module "bar" inside module "foo"
represented by "foo.js")?

What if "foo.js" doesn't contain "export" statements?

function foo() {};
module "bar" {}

Is it a bundled module collection now (with the only module "bar" inside)?
And this file can be loaded only via module loader as you mention below,
but not using "import" or "module" statement?

> > If the parent file is not actually a module, but a script -- how this
> script is loaded? On the web using <script>? On Node.js? -- using
> ..."require"? Two module systems?
> Bundled collections of modules are loaded primarily by loading them or
> referencing them using a module loader, and then importing from the
> individual modules they define.
To double-check:

File "foo.js":

export default function foo() {}

can be loaded as:

import foo from "foo";


module foo from "foo";

But the file "bar.js":

module "bar" {
  export default function bar() {}

Cannot be loaded as:

import bar from "bar";


module bar from "bar";


In other words, everything we want to be loaded via "import" or "module"
statements, _should_ be file-modules, not inner modules with "module"
directive, correct?

> 3. For external modules, will it be possible to omit filename extension?
> `import foo from "foo.js"` -- sounds obsolete, unless we'll be able to
> import modules written on different languages.
> In the browser (this is not intended to be part of the language
> semantics), the default rule for going from a module name like "foo"
> to a URL like "http://example.com/foo.js" will add ".js".

> > 4. What is export from module?
> >
> > import {foo} from "foo.js";
> > export {foo} from "foo.js"
> >
> > First makes sense to me (well, syntax is debatable, but anyways), the
> second I don't understand. Can I, as a caller, re-export (i.e. make public)
> something from not my module, and that was specially not exported?
> No, you can't.  The latter means the same as:
>     import { foo } from "foo";
>     export { foo };
> except without adding `foo` to the local scope.  It doesn't expose
> anything unexported.

I see, so it's just further propagation passing export of not my module
through from my module, as it would be my export; thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130909/9ed84126/attachment.html>

More information about the es-discuss mailing list