tc39 / proposal-import-attributes

Proposal for syntax to import ES modules with assertions
https://tc39.es/proposal-import-attributes/
Apache License 2.0
599 stars 26 forks source link

What syntax could be used to pass attributes to other subresources on the web? #9

Open littledan opened 5 years ago

littledan commented 5 years ago

Although module types only make sense in module contexts, other attributes (e.g., fetch options) may make sense for all sorts of subresources (e.g., <link> elements and @import in CSS). It would be ideal if we had a uniform way to pass these same flags to those contexts as well.

Otherwise, we're sort of back to shoving something into URLs, for those cases. Although this is really sort of a web platform issue, it affects the viability of using these options out of the URL, so I want to suggest that we start discussion here.

Let's try to write down the different subresources in the web platform, and see if we can find syntax for them to accept an options bag for further parameters, analogous to what this proposal does for JavaScript.

h/t to @slightlyoff for raising this issue offline

bmeck commented 5 years ago

Is this not something that a host could choose to attach to import.meta already?

littledan commented 5 years ago

This issue is used to track non-module subresources, so I don't think it relates to import.meta. However, that suggestion may be interesting to discuss in a different issue.

bmeck commented 5 years ago

@littledan I must be misunderstanding this issue, can you explain? Is this just tracking how to inject something like import.meta into non-JS languages?

littledan commented 5 years ago

@bmeck I don't see how this relates to import.meta. It's about new attributes defined in this repository (where we didn't yet propose any mapping to import.meta).

bmeck commented 5 years ago

@littledan I'm more confused now, are you saying this proposal is seeking to only provide a whitelist of key/value pairs; or, are you saying that this proposal isn't going to directly expose the key/value pair to the host so it can pass it to other languages?

littledan commented 5 years ago

I was imagining we'd expose the k/v pairs to the host so it can decide what to do with them. It's still sort of an open question what we would do with unrecognized keys, but I wasn't really thinking about a whitelist. But I would like to keep hosts somehow vaguely aligned (#10 ). (This sounds like a third topic; I don't see how it relates to import.meta or the start of this thread.)

littledan commented 4 years ago

While it may be important to pass attributes to other kinds of subresources, there are some that are really specific to the ES module context, and this includes the module type. Therefore, I don't think we should be blocked by coming up with a more general solution, but it will be good to continue discussion.