Module naming and declarations

Sam Tobin-Hochstadt samth at ccs.neu.edu
Wed May 8 10:44:16 PDT 2013


On Wed, May 8, 2013 at 1:03 PM, Domenic Denicola
<domenic at domenicdenicola.com> wrote:
> From: Jason Orendorff [jason.orendorff at gmail.com]
>
>> Here's what you would do under the proposal:
>>
>> ```js
>> // import a module in the same package/project
>> import "./controllers" as controllers;
>>
>> // import some other package
>> import "backbone" as backbone;
>> ```
>>
>> The surface syntax deliberately follows Node. The first import is relative and the second is absolute, within the tree of module names (not URLs; neither of those module names is a URL).
>
> That is not my understanding of Sam's message at https://mail.mozilla.org/pipermail/es-discuss/2013-May/030553.html. Following those steps for `"backbone"` would, according to that message,
>
> 1. Split the module name on "/", url-encode, and re-join (yielding `"backbone"`).
> 2. Append ".js" to the module name (yielding `"backbone.js"`).
> 3. Use the URL parser with the  base URL to produce an absolute URL (yielding `"http://example.com/path/to/base/backbone.js"`).
> 4. Pass the absolute URL to the fetch hook.

How is this in disagreement with what Jason said?  His point is that
if you're in the module "a/b/c", "./controllers" refers to
"a/b/controllers", and "backbone" refers to "backbone". Once you have
a module name, there's a default resolution semantics to produce a URL
for the fetch hook, which you describe accurately.

Sam


More information about the es-discuss mailing list