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

Provide read-only access to the parsed mapping object #128

Open
bahrus opened this issue Apr 26, 2019 · 2 comments
Open

Provide read-only access to the parsed mapping object #128

bahrus opened this issue Apr 26, 2019 · 2 comments

Comments

@bahrus
Copy link

bahrus commented Apr 26, 2019

It would only take a single line of code for application logic to parse the JSON string of the importmap:

const p = JSON.parse(document.head.querySelector('script[type="importmap"]').innerHTML)

But assuming the browser will parse it, could it not expose the parsed object in some way?

I know the intention is to not allow for adding metadata, but scheming developers like me will still probably be quite tempted to add metadata (for example, appending #myMetaInfo= after the path to a js file).

Any harm done in exposing the parsed object? That could reduce cpu a bit.

@ljharb
Copy link

ljharb commented Apr 26, 2019

Unless it was a getter that returned a new object every time, then I’d wonder what happens if you mutate that object - and if the object is mutable for future accesses, then the only robust thing is to manually parse anyways, so the object access seems to lose its value :-/

@domenic
Copy link
Collaborator

domenic commented Apr 26, 2019

Yeah, I think we not rush into a solution here, to leave open the door for a future, mutable-in-a-controlled-way, "import map object model" API that allows runtime changes to import mapping.

For example, such an API would probably be a per-realm representation of the merged import maps, and not per-script element. So we wouldn't want to provide the functionality equivalent to the OP since that wouldn't mesh well with the future work.

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

3 participants