Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using 'active script' for determining import: URL scope is brittle #77

Closed
bicknellr opened this issue Nov 16, 2018 · 2 comments
Closed

Comments

@bicknellr
Copy link

bicknellr commented Nov 16, 2018

(relevant text: https://github.com/domenic/import-maps/blob/e4dd5e3b070ca5bd56bf65bfa01085045207a52c/spec.md#modifications-to-the-url-parser-for-import-urls)

Using 'active script' to determine the scope for a particular import: URL seems to break down easily when passing URLs from scripts in one scope to scripts in another:

./lib.js, in scope A:

export makeImage = url => {
  const image = document.createElement('img');
  image.src = url;
  return src;
}

./caller.js, in scope B:

import {makeImage} from "lib/lib.js";
document.body.appendChild(makeImage("import:somewhere/image.png"));

If caller.js and lib.js are in separate scopes, but the deciding factor for which scope applies to a particular import: URL is based on the 'active script' at the time the import: URL string would be consumed for resolution, then import:somewhere/image.png would be resolved in scope A, used by lib.js, rather than scope B. How can a caller one scope provide an import: URL to another scope that resolves to the network URL expected by the caller?

I think this would require some kind of URL resolution function ("import.resolve") but doing so seems to be currently precluded by other problems (CORS, async).

@domenic
Copy link
Collaborator

domenic commented Nov 17, 2018

This seems like a dupe of #75, do you agree?

@bicknellr
Copy link
Author

Yup, this is a dupe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants