Closed domenic closed 1 year ago
We took a look at this today and are generally favorable. Some questions though regarding the sync/async decision, what happens if the author calls this while there's a pending load for an import map? Does it throw or return the wrong value? If the author needs to wait until the import map(s) are fully loaded, how do they do that?
Right now import maps are always inline and cannot be loaded. It's unclear whether that will change in the future; implementer interest is low, although I personally think it'd be nice.
In such a future, it would return the current value. It would not throw. It's not clear whether the current value would be considered "wrong"; if you do import.meta.resolve(x); import(x);
while an import map is being loaded, the import()
statement will import the same URL returned by import.meta.resolve(x)
(i.e., the current value).
If an author needs to wait for import maps in such a future, it depends on how we expose external import map loading, but probably the simplest way would be to wait for that import map <script>
element's load
event.
We looked at this again today during a breakout. Even without import map loading, authors can always dynamically add import maps by creating new <script>
elements and appending them to the document. So even if the API were async, it could not possibly account for all future import maps. Therefore we're fine with a sync API, that is easier to reason about as resolving the specifier based on whatever the current state of import maps is, and we're going to close this. Thank you for flying TAG!
Wotcher TAG!
I'm requesting a TAG review of import.meta.resolve().
import.meta.resolve(specifier)
returns the URL to whichspecifier
would resolve in the context of the current script. That is, it returns the URL that would be imported if you didimport(specifier)
.This is a quite small feature (a single function, with only a few lines of spec text which exposes an already-existing spec algorithm).
Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify @domenic