Understanding the 'normalize' Loader hook

John Barton johnjbarton at google.com
Tue Aug 12 15:43:11 PDT 2014


On Tue, Aug 12, 2014 at 3:26 PM, Ian Hickson <ian at hixie.ch> wrote:

> On Tue, 12 Aug 2014, John Barton wrote:...
> > > (only if the last segment is part of the "path" part of the URL and
> > > doesn't contain a "."?).
> >
> > No such restriction is applied in our code.
>
> Sure. What do we want for the default Web loader though?
>

Be consistent with URLs.which.allow.dots


>
>
> > > Is that more or less right? (There's also the loader.paths stuff. Why
> > > is that in "locate" rather than "normalize"?)
> >
> > Because the paths processing can produce arbitrary addresses (to cache,
> > CDN, I guess)
>
> Sure but presumably if someone explicitly puts in the long URL, they still
> don't want it to cause a second load, right?
>
> I mean, if you do:
>
>    loader.paths = {
>      'foo': 'scripts/foo',
>    };
>
>    // in a different module
>
>    import "foo";
>
>    // in a different module
>
>    import "scripts/foo";
>
> ...surely you want just one module loaded. No?
>

One module, but my point was more that the right hand side can be an
absolute path.


>
> Come to think of it, maybe you actually just want one loaded even if
> someone does:
>
>    import "scripts/foo.js";
>

In my opinion this should be an error. Either we have .js or we don't, not
half-baked.


>
> ...or even:
>
>    // assuming the base URL the whole time has been
>    // http://www.example.com/
>    import "http://www.example.com/scripts/foo.js";
>

Also an error.


>
> Is there any time we'd want all those imports to result in separate module
> loads?
>

FWIW, most of the time I expect to write relative paths in imports:
  import "./foo/bar";

If I see
  import "foo/bar";
I expect foo to be remapped to a package.

Or to put it another way, we need a story for packages.

jjb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140812/3b4cab9e/attachment.html>


More information about the es-discuss mailing list