From 2d47dccc9f96b2f90a7a6e4574a0158ffd99122b Mon Sep 17 00:00:00 2001
From: Domenic Denicola A number of schemes and protocols are referenced by this specification also: The following terms are defined in Console: application/x-www-form-urlencoded
formatapplication/x-www-form-urlencoded
serializernavigator.credentials.get()
+
+
@@ -59579,6 +59596,13 @@ interface HTMLScriptElement : HTMLElement {
data-x="attr-script-async">async attribute (regardless of the state of the src
attribute).
Setting the attribute to an ASCII case-insensitive match for the string
+ "importmap
" means that the script is an import map,
+ containing JSON that will be used to control the behavior of module specifier resolution. Import maps can only be inline, i.e., the src
attribute must not be used with them. As such, most other
+ attributes also are meaningless and not to be used.
Setting the attribute to any other value means that the script is a data
block, which is not processed. None of the script
attributes (except type
itself) have any effect on data blocks. Authors must use
@@ -59614,6 +59638,16 @@ interface HTMLScriptElement : HTMLElement {
The contents of the external script resource for JSON module scripts must conform to the requirements of the JSON specification .
+The contents of inline script
elements for import
+ maps must conform with the import map authoring requirements.
For import map script
elements, the src
, async
, nomodule
, defer
,
+ crossorigin
, integrity
, and referrerpolicy
attributes must not be specified.
When used to include data blocks, the data must be embedded
inline, the format of the data must be given using the type
attribute, and the contents of the script
element must conform to the requirements
@@ -59794,9 +59828,10 @@ interface HTMLScriptElement : HTMLElement {
HTMLScriptElement
.supports(type)
Returns true if the given type is a script type supported by the user agent.
- The possible script types in this specification are "classic
" and
- "module
", but others might be added in the future.
+
Returns true if the given type is a script type supported by the user agent. The
+ possible script types in this specification are "classic
", "module
", and "importmap
", but others might be added in
+ the future.
If type is "module
", then return
true.
If type is "importmap
", then return
+ true.
Return false.
A script
element has a type, which is
- either null, "classic
", or "module
", initially
- null. It is determined when the element is prepared, based on the type
attribute of
- the element at that time.
classic
", "module
", or "importmap
", initially null. It is determined when the element is prepared, based on the type
attribute of the element at that time.
A script
element has a result, which is either "uninitialized
", null (representing an error), or a script. It is initially "uninitialized
".
uninitialized
".
A script
element has steps to run when the result
is ready, which are a series of steps or null, initially null. To mark as ready a
script
element el given a script-or-null result:
Set el's result to
@@ -60191,6 +60231,11 @@ o............A....e
el's type to "module
".
Otherwise, if the script block's type string is an ASCII
+ case-insensitive match for the string "importmap
", then set
+ el's type to "importmap
".
Otherwise, return. (No script is executed, and el's type is left as null.)
If el has a src
content attribute, then:
If el's type is "importmap
", then queue an element task on the DOM
+ manipulation task source given el to fire
+ an event named error
at el, and
+ return.
External import map scripts are not currently supported.
+Let src be the value of el's src
attribute.
importmap
"If el's relevant global object's import maps
+ allowed is false, then queue an element task on the DOM
+ manipulation task source given el to fire an event named error
at el, and return.
Set el's relevant global object's import maps + allowed to false.
Let result be the result of creating an import map parse result given source text and + base URL.
Mark as ready el given result.
importmap
"Register an import map given el's relevant global + object and el's result.
Disallow further import maps given settings object.
Fetch a single module script given url, settings
object, "script
", options, settings object,
"client
", and with the top-level module fetch flag set. If the
@@ -93345,13 +93431,15 @@ document.querySelector("button").addEventListener("click", bound);
To fetch an import() module script graph given a moduleRequest, a - base URL, a settings object, and some options, run these steps. + script, a settings object, and some options, run these steps. The algorithm will asynchronously complete with either null (on failure) or a module script (on success).
Disallow further import maps given settings object.
Let url be the result of resolving a - module specifier given base URL and moduleRequest.[[Specifier]].
If url is failure, then asynchronously complete this algorithm with null, and return.
Disallow further import maps given settings object.
Fetch a single module script given url, settings
object, destination, options, settings object, "client
", and with the top-level module fetch flag set. Wait until
@@ -93427,6 +93517,8 @@ document.querySelector("button").addEventListener("click", bound);
success).
Disallow further import maps given settings object.
Let script be the result of creating a JavaScript module script using source text, settings object, base URL, and options.
Let url be the result of resolving - a module specifier given module script's base URL and + a module specifier given module script and requested.[[Specifier]].
Assert: url is never failure, because resolving a module specifier must have been previously successful with these same two arguments.
For each moduleRequest in moduleRequests, perform the internal module script graph fetching procedure given moduleRequest, fetch client settings object, - destination, options, module script's settings - object, visited set, and module script's base URL. If the caller of this - algorithm specified custom perform the - fetch steps, pass those along while performing the internal module script graph - fetching procedure.
+ destination, options, module script, and visited + set. If the caller of this algorithm specified custom perform the fetch steps, pass those along while + performing the internal module script graph fetching procedure.These invocations of the internal module script graph fetching procedure should be performed in parallel to each other.
@@ -93777,17 +93866,17 @@ document.querySelector("button").addEventListener("click", bound);To perform the internal module script graph fetching procedure given a moduleRequest, a fetch client settings object, a destination, - some options, a module map settings object, a visited set, and a - referrer, perform these steps. The algorithm will asynchronously complete with either - null (on failure) or a module script (on success).
+ some options, a referringScript, and a visited set, perform + these steps. The algorithm will asynchronously complete with either null (on failure) or a + module script (on success).Let url be the result of resolving - a module specifier given referrer and + a module specifier given refereringScript and moduleRequest.[[Specifier]].
Assert: url is never failure, because resolving a module specifier must have been Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two
arguments.
Assert: visited set contains (url, moduleType).
Fetch a single module script given url, fetch client settings - object, destination, options, module map settings object, - referrer, moduleRequest, and with the +
Fetch a single module script given url, fetch client + settings object, destination, options, referringScript's + settings object, referringScript's base URL, moduleRequest, and with the top-level module fetch flag unset. If the caller of this algorithm specified custom perform the fetch steps, pass those along while fetching a single module script.
@@ -93978,11 +94068,10 @@ document.querySelector("button").addEventListener("click", bound);Let childURL be the result of resolving a module specifier given moduleScript's base URL and moduleRequest.[[Specifier]]. - (This will never fail, as otherwise moduleScript would have been marked as itself having a parse - error.)
Let moduleType be the result of running the module type from module request steps given moduleRequest.
Let url be the result of resolving - a module specifier given script's base - URL and requested.[[Specifier]].
If the previous step threw an exception, then:
+ +Set script's parse error + to that exception.
Return script.
Let moduleType be the result of running the module type from module request steps given requested.
If url is failure, or if the result of running the module type - allowed steps given moduleType and settings is false, then:
+If the result of running the module type allowed steps given + moduleType and settings is false, then:
+Let error be a new TypeError
exception.
An import map parse result is a struct that is similar to a script, and also can be stored in a script
element's
+ result, but is not counted as a script for other purposes. It has the following items:
To create an import map parse result given a string input + and a URL baseURL:
+ +Let result be an import map parse result whose import map is null and whose error to rethrow is null.
Parse an import map string given input and baseURL, + catching any exceptions. If this threw an exception, then set result's error to rethrow to that exception. Otherwise, set + result's import map to the return + value.
Assert: exactly one of result's items is + non-null.
Return result.
To register an import map given a Window
global and an
+ import map parse result result:
If result's error to rethrow is + not null, then report the exception given by result's error to rethrow and return.
Assert: global's import map is + an empty import map.
Set global's import map to + result's import map.
The resolve a module specifier algorithm is the primary entry point for + converting module specifier strings into URLs. When no import maps are involved, it is relatively straightforward, and + reduces to resolving a URL-like module specifier.
+ +When there is a non-empty import map present, the behavior is more complex. It + checks candidate entries from all applicable module specifier + maps, from most-specific to least-specific scopes (falling back to the top-level unscoped imports), and from most-specific to least-specific + prefixes. For each candidate, the resolve an imports + match algorithm will give on the following results:
+ +Successful resolution of the specifier to a URL. Then the resolve a + module specifier algorithm will return that URL.
Throwing an exception. Then the resolve a module specifier will rethrow that + exception, without any further fallbacks.
Failing to resolve, without an error. In this case the outer resolve a module + specifier algorithm will move on to the next candidate.
In the end, if no successful resolution is found via any of the candidate module specifier maps, resolve a module specifier will throw + an exception. Thus the result is always either a URL or a thrown exception.
+ +To resolve a module specifier given a script-or-null + referringScript and a string specifier:
+ +Let settingsObject be the current settings object.
Let baseURL be settingsObject's API base URL.
If referringScript is not null, then:
+ +Set settingsObject to referringScript's settings + object.
Set baseURL to referringScript's base URL.
Let importMap be an empty import map.
If settingsObject's global
+ object implements Window
, then set importMap to
+ settingsObject's global object's
+ import map.
Let baseURLString be baseURL, serialized.
Let asURL be the result of resolving a URL-like module specifier + given specifier and baseURL.
Let normalizedSpecifier be the serialization of asURL, if asURL is + non-null; otherwise, specifier.
For each scopePrefix → scopeImports + of importMap's scopes:
+ +If scopePrefix is baseURLString, or if scopePrefix ends + with U+002F (/) and scopePrefix is a code unit prefix of + baseURLString, then:
+ +Let scopeImportsMatch be the result of resolving an imports + match given normalizedSpecifier, asURL, and + scopeImports.
If scopeImportsMatch is not null, then return + scopeImportsMatch.
Let topLevelImportsMatch be the result of resolving an imports + match given normalizedSpecifier, asURL, and importMap's + imports.
If topLevelImportsMatch is not null, then return + topLevelImportsMatch.
At this point, specifier wasn't remapped to anything by + importMap, but it might have been able to be turned into a URL.
+ +If asURL is not null, then return asURL.
+Throw a TypeError
indicating that specifier was a bare specifier,
+ but was not remapped to anything by importMap.
To resolve an imports match, given a + string normalizedSpecifier, a URL-or-null asURL, + and a module specifier map specifierMap:
+ +For each specifierKey → + resolutionResult of specifierMap:
+ +If specifierKey is normalizedSpecifier, then:
+ +If resolutionResult is null, then throw a TypeError
indicating
+ that resolution of specifierKey was blocked by a null entry.
This will terminate the entire resolve a module specifier + algorithm, without any further fallbacks.
+Assert: resolutionResult is a URL.
Return resolutionResult.
If all of the following are true:
+ +then:
+ +If resolutionResult is null, then throw a TypeError
indicating
+ that the resolution of specifierKey was blocked by a null entry.
This will terminate the entire resolve a module specifier + algorithm, without any further fallbacks.
+Assert: resolutionResult is a URL.
Let afterPrefix be the portion of normalizedSpecifier after the + initial specifierKey prefix.
Assert: resolutionResult, serialized, ends with U+002F (/), as enforced during + parsing.
Let url be the result of URL parsing + afterPrefix with resolutionResult.
If url is failure, then throw a TypeError
indicating that
+ resolution of normalizedSpecifier was blocked since the afterPrefix
+ portion could not be URL-parsed relative to the resolutionResult mapped to by
+ the specifierKey prefix.
This will terminate the entire resolve a module specifier + algorithm, without any further fallbacks.
+Assert: url is a URL.
If the serialization of
+ resolutionResult is not a code unit prefix of the serialization of url, then throw a
+ TypeError
indicating that the resolution of normalizedSpecifier was
+ blocked due to it backtracking above its prefix specifierKey.
This will terminate the entire resolve a module specifier + algorithm, without any further fallbacks.
+Return url.
Return null.
+ +The resolve a module specifier algorithm will fall back to a
+ less-specific scope, or to "imports
", if possible.
To resolve a URL-like module + specifier, given a string specifier and a URL + baseURL:
+ +If specifier starts with "/
", "./
", or "../
", then:
Let url be the result of URL parsing + specifier with baseURL.
If url is failure, then return null.
+ +One way this could happen is if specifier is "../foo
" and baseURL is a data:
URL.
Return url.
This includes cases where specifier starts with "//
", i.e., scheme-relative URLs. Thus, url might end up with a
+ different host than baseURL.
Let url be the result of URL parsing + specifier (with no base URL).
If url is failure, then return null.
Return url.
+An import map allows control over module specifier resolution. Import maps are
+ delivered via inline script
elements with their type
attribute set to "importmap
", and
+ with their child text content containing a JSON representation of the import
+ map.
Only one import map is processed per Document
. After the first import map is
+ seen, others will be ignored, with their corresponding script
elements generating
+ error
events. Similarly, once any modules have been imported,
+ e.g., via import()
expressions or script
elements with their type
attribute set to "module
", further
+ import maps will be ignored.
These restrictions, as well as the lack of support for external import maps, are + in place to keep the initial version of the feature simple. They might be lifted over time as + implementer bandwidth allows.
+ +The simplest use of import maps is to globally remap a bare module specifier:
+ +{
+ "imports": {
+ "moment": "/node_modules/moment/src/moment.js"
+ }
+}
+
+ This enables statements like import moment from "moment";
to
+ work, fetching and evaluating the JavaScript module at the /node_modules/moment/src/moment.js
+ URL.
An import map can remap a class of module specifiers into a class of URLs by using trailing slashes, like so:
+ +{
+ "imports": {
+ "moment/": "/node_modules/moment/src/"
+ }
+}
+
+ This enables statements like import localeData from "moment/locale/zh-cn.js";
to
+ work, fetching and evaluating the JavaScript module at the /node_modules/moment/src/moment/locale/zh-cn.js
+ URL. Such trailing-slash mappings are often combined with bare-specifier mappings, e.g.
{
+ "imports": {
+ "moment": "/node_modules/moment/src/moment.js"
+ "moment/": "/node_modules/moment/src/"
+ }
+}
+
+ so that both the "main module" specified by "moment
" and the "submodules" specified by paths such as "moment/locale/zh-cn.js
" are available.
Bare specifiers are not the only type of module specifiers which import maps can remap. "URL-like" specifiers, i.e.
+ those that are either parseable as absolute URLs or start with "/
", "./
", or "../
", can be remapped as well:
{
+ "imports": {
+ "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "/node_modules/vue/dist/vue.runtime.esm.js"
+ "/js/app.mjs": "/js/app-8e0d62a03.mjs",
+ "../helpers/": "https://cdn.example/helpers/"
+ }
+}
+
+ Note how the URL to be remapped, as well as the URL being mapped to, can be specified as either absolute URLs, or as a relatives URL starting with "/
", "./
", or "../
". (They cannot be specified as relative URLs without those special starting sigils, as those help distinguish from bare module specifiers.) Also note how the trailing slash mapping works in this context as well.
Such remappings operate on the post-canonicalization URL, and do not require a match between the literal strings supplied in the import map key and the imported module specifier. So for example, if this import map was included on https://example.com/app.html
, then not only would import "/js/app.mjs"
be remapped, but so would import "./js/app.mjs"
and import "./foo/../js/app.mjs"
.
All previous examples have globally remapped module specifiers, by using the top-level "imports
" key in the import map. The top-level "scopes
" key can be used to provide localized remappings, which only apply when the referring module matches a specific URL prefix. For example:
{
+ "scopes": {
+ "/a/" : {
+ "moment": "/node_modules/moment/src/moment.js"
+ },
+ "/b/" : {
+ "moment": "https://www.unpkg.com/moment/src/moment.js"
+ }
+ }
+}
+
+ With this import map, the statement import "moment"
will have different meanings depending on which referrer script contains the statement:
Inside scripts located under /a/
, this will import /node_modules/moment/src/moment.js
.
Inside scripts located under /b/
, this will import https://www.unpkg.com/moment/src/moment.js
.
Inside scripts located under /c/
, this will fail to resolve and thus throw an exception.
A typical usage of scopes is to allow multiple versions of the "same" module to exist in a web application, with some parts of the module graph importing one version, and other parts importing another version. +
Scopes can overlap each other, and overlap the global "imports
" specifier map. At resolution time, scopes are consulted in order of most- to least-specific, where specificity is measured by sorting the scopes using the code unit less than operation. So, for example, "/scope2/scope3/
" is treated as more specific than "/scope2/
", which is treated as more specific than the top-level (unscoped) mappings.
The following import map illustrates this:
+ +{
+ "imports": {
+ "a": "/a-1.mjs",
+ "b": "/b-1.mjs",
+ "c": "/c-1.mjs"
+ },
+ "scopes": {
+ "/scope2/": {
+ "a": "/a-2.mjs"
+ },
+ "/scope2/scope3/": {
+ "b": "/b-3.mjs"
+ }
+ }
+}
+
+ This results in the following resolutions (using relative URLs for brevity):
+ ++ | Specifier + | |||
---|---|---|---|---|
"a "
+ | "b "
+ | "c "
+ | ||
Referrer + | /scope1/r.mjs
+ | /a-1.mjs
+ | /b-1.mjs
+ | /c-1.mjs
+ |
/scope2/r.mjs
+ | /a-2.mjs
+ | /b-1.mjs
+ | /c-1.mjs
+ | |
/scope2/scope3/r.mjs
+ | /a-2.mjs
+ | /b-3.mjs
+ | /c-1.mjs
+ |
The child text content of a script
element representing an
+ import map must match the following import map authoring
+ requirements:
The JSON must represent a JSON object, with at most the two keys "imports
" and "scopes
".
The values corresponding to the "imports
" and "scopes
" keys, if present, must themselves be JSON objects.
The value corresponding to the "imports
" key, if present, must be
+ a valid module specifier map.
The value corresponding to the "scopes
" key, if present, must be a
+ JSON object, whose keys are valid URL strings and whose
+ values are valid module specifier
+ maps.
A valid module specifier map is a JSON object that meets the following + requirements:
+ +All of its keys must be nonempty.
All of its values must be strings.
Each value must be either a valid absolute URL or a
+ valid URL string that starts with "/
", "./
", or "../
".
If a given key ends with "/
", then the corresponding
+ value must also.
Formally, an import map is a struct with two items:
+ +imports, a module specifier + map; and
scopes, an ordered map of + URLs to module specifier + maps.
+A module specifier map is an ordered map whose keys are strings and whose values are either URLs or nulls.
+ +An empty import map is an import map with its imports and scopes both being empty maps.
+ +Each Window
has an import map,
+ initially an empty import map.
Each Window
has an import maps allowed boolean, initially true.
To disallow further import maps given an environment settings object + settingsObject:
+ +Let global be settingsObject's global object.
If global does not implement Window
, then return.
Set global's import maps allowed to false.
Import maps are currently disallowed once any module loading has started, or once + a single import map is loaded. These restrictions might be lifted in future specification + revisions.
+ +To parse an import map string, given a string input and a + URL baseURL:
+ +Let parsed be the result of parsing a JSON string to an Infra value given input.
If parsed is not an ordered map, then throw a
+ TypeError
indicating that the top-level value needs to be a JSON object.
Let sortedAndNormalizedImports be an empty ordered map.
If parsed["imports
"] exists, then:
If parsed["imports
"] is not an ordered
+ map, then throw a TypeError
indicating that the value for the "imports
" top-level key needs to be a JSON object.
Set sortedAndNormalizedImports to the result of sorting and
+ normalizing a module specifier map given parsed["imports
"] and baseURL.
Let sortedAndNormalizedScopes be an empty ordered map.
If parsed["scopes
"] exists, then:
If parsed["scopes
"] is not an ordered
+ map, then throw a TypeError
indicating that the value for the "scopes
" top-level key needs to be a JSON object.
Set sortedAndNormalizedScopes to the result of sorting and normalizing
+ scopes given parsed["scopes
"] and
+ baseURL.
If parsed's keys contains any items besides "imports
" or "scopes
", then the user agent should report a warning to the
+ console indicating that an invalid top-level key was present in the import map.
This can help detect typos. It is not an error, because that would prevent any + future extensions from being added backward-compatibly.
+Return an import map whose imports are sortedAndNormalizedImports and + whose scopes are + sortedAndNormalizedScopes.
The import map that results from this parsing algorithm is highly normalized.
+ For example, given a base URL of https://example.com/base/page.html
, the
+ input
{
+ "imports": {
+ "/app/helper": "node_modules/helper/index.mjs",
+ "lodash": "/node_modules/lodash-es/lodash.js"
+ }
+}
+
+ will generate an import map with imports of
+ +«[
+ "https://example.com/app/helper" → https://example.com/base/node_modules/helper/index.mjs
+ "lodash" → https://example.com/node_modules/lodash-es/lodash.js
+]»
+
+ and (despite nothing being present in the input string) an empty ordered map for + its scopes.
+To sort and normalize a module + specifier map, given an ordered map originalMap and a + URL baseURL:
+ +Let normalized be an empty ordered map.
For each specifierKey → value of + originalMap:
+ +Let normalizedSpecifierKey be the result of normalizing a specifier + key given specifierKey and baseURL.
If normalizedSpecifierKey is null, then continue.
If value is not a string, then:
+ +The user agent may report a warning to the console indicating that + addresses need to be strings.
Set normalized[normalizedSpecifierKey] to null.
Continue.
Let addressURL be the result of resolving a URL-like module + specifier given value and baseURL.
If addressURL is null, then:
+ +The user agent may report a warning to the console indicating that the + address was invalid.
Set normalized[normalizedSpecifierKey] to null.
Continue.
If specifierKey ends with U+002F (/), and the serialization of addressURL does not end + with U+002F (/), then:
+ +The user agent may report a warning to the console indicating that an + invalid address was given for the specifier key specifierKey; since + specifierKey ends with a slash, the address needs to as well.
Set normalized[normalizedSpecifierKey] to null.
Continue.
Set normalized[normalizedSpecifierKey] to + addressURL.
Return the result of sorting in descending order + normalized, with an entry a being less than an entry b if + a's key is code unit less than + b's key.
To sort and normalize scopes, given an + ordered map originalMap and a URL baseURL:
+ +Let normalized be an empty ordered map.
For each scopePrefix → + potentialSpecifierMap of originalMap:
+ +If potentialSpecifierMap is not an ordered map, then throw a
+ TypeError
indicating that the value of the scope with prefix
+ scopePrefix needs to be a JSON object.
Let scopePrefixURL be the result of URL + parsing scopePrefix with baseURL.
If scopePrefixURL is failure, then:
+ +The user agent may report a warning to the console that the scope prefix + URL was not parseable.
Continue.
Let normalizedScopePrefix be the serialization of scopePrefixURL.
Set normalized[normalizedScopePrefix] to the result of + sorting and normalizing a module specifier map given + potentialSpecifierMap and baseURL.
Return the result of sorting in descending + order normalized, with an entry a being less than an entry + b if a's key is code unit less + than b's key.
In the above two algorithms, sorting keys and scopes in descending order has the
+ effect of putting "foo/bar/
" before "foo/
". This in
+ turn gives "foo/bar/
" a higher priority than "foo/
"
+ during module specifier resolution.
To normalize a specifier key, given a string specifierKey and a URL baseURL:
+ +If specifierKey is the empty string, then:
+ +The user agent may report a warning to the console indicating that specifier keys may not be the empty string.
Return null.
Let url be the result of resolving a URL-like module specifier, given specifierKey and baseURL.
If url is not null, then return the serialization of url.
Return specifierKey.
The JavaScript specification contains a number of implementation-defined abstract
@@ -95079,7 +95960,7 @@ dictionary PromiseRejectionEventInit : EventInitspecifier. This allows dynamic importing of module scripts at runtime,
instead of statically using the import
statement form. The specifier will
be resolved relative to the active
- script's base URL.
The returned promise will be rejected if an invalid specifier is given, or if a failure is
encountered while fetching or PromiseRejectionEventInit : EventInit
Returns specifier, resolved
- relative to the active script's base
- URL. That is, this returns the URL that would be imported by using import(specifier)
.import(specifier)
.
Throws a TypeError
exception if an invalid specifier is given.
To resolve a module specifier given a URL base URL and a - string specifier, perform the following steps. It will return either a - URL record or failure.
- -Apply the URL parser to specifier. If the result is not failure, - return the result.
If specifier does not start with the character U+002F SOLIDUS (/
), the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./
), or the three-character sequence U+002E FULL STOP, U+002E FULL STOP,
- U+002F SOLIDUS (../
), return failure.
This restriction is in place so that in the future we can allow custom module
- loaders to give special meaning to "bare" import specifiers, like import "jquery"
or import "web/crypto"
. For now any
- such imports will fail, instead of being treated as relative URLs.
Return the result of applying the URL parser to specifier with - base URL.
The following are valid module specifiers according to the above - algorithm:
- -https://example.com/apples.mjs
http:example.com\pears.js
(becomes http://example.com/pears.js
as step 1 parses with no base
- URL)//example.com/bananas
./strawberries.mjs.cgi
../lychees
/limes.jsx
data:text/javascript,export default 'grapes';
blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f
The following are valid module specifiers according to the above algorithm, but will - invariably cause failures when they are fetched:
- -javascript:export default 'artichokes';
data:text/plain,export default 'kale';
about:legumes
wss://example.com/celery
The following are not valid module specifiers according to the above algorithm:
- -https://eggplant:b/c
pumpkins.js
.tomato
..zucchini.mjs
.\yam.es
Set specifier to ? ToString(specifier).
Let url be the result of resolving - a module specifier given moduleScript's base URL and specifier.
If url is failure, then throw a TypeError
exception.
Return the serialization of url.
Let base URL be settings object's API base - URL.
Let referencing script be null.
Let fetch options be the default classic script fetch options.
If referencingScriptOrModule is not null, then:
Let referencing script be +
Set referencing script to referencingScriptOrModule.[[HostDefined]].
Set settings object to referencing script's settings object.
Set base URL to referencing script's base URL.
Set fetch options to the descendant script fetch options for referencing script's fetch options.
Assert: Neither base URL nor fetch options is null, as - referencing script is a classic script or a JavaScript module - script.
Assert: fetch options is not null, as referencing script is a + classic script or a JavaScript module script.
As explained above for HostResolveImportedModule, in the common +
As explained for HostResolveImportedModule, in the common case, referencingScriptOrModule is non-null.
Fetch an import() module script graph given moduleRequest, - base URL, settings object, and fetch options. Wait until the - algorithm asynchronously completes with result.
Let promise be null. @@ -95416,14 +96208,13 @@ import "https://example.com/foo/../module2.mjs";
Let settings object be the current settings object.
Let base URL be settings object's API base - URL.
Let referencing script be null.
If referencingScriptOrModule is not null, then:
Let referencing script be +
Set referencing script to referencingScriptOrModule.[[HostDefined]].
Set settings object to referencing script's settings @@ -95455,13 +96246,14 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-settings-object-module-map">module map.
Let url be the result of resolving a - module specifier given base URL and + module specifier given referencing script and moduleRequest.[[Specifier]].
Assert: url is never failure, because resolving a module specifier must have been previously successful with these - same two arguments (either while creating the - corresponding module script, or in fetch an import() module script graph).
Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with + these same two arguments (either while creating + the corresponding module script, or in fetch an import() module script + graph).
Let moduleType be the result of running the module type from module request steps given moduleRequest.
Part of the revision history of the import maps feature can be found in the WICG/import-maps
+ repository, which is available under the W3C Software and
+ Document License.
Copyright © WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a Creative Commons Attribution 4.0
International License. To the extent portions of it are incorporated into source code, such
diff --git a/styles.css b/styles.css
index a152c0fcbde..268b85d8321 100644
--- a/styles.css
+++ b/styles.css
@@ -35,6 +35,8 @@ td.eg { border-width: thin; text-align: center; }
#table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
#table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
+#table-import-map-scopes-example th[row="3"] { writing-mode: vertical-rl; }
+
#table-fa { border-top: solid; }
#table-fa .example {
margin: 2em 0 1.5em 0;
From c5dc31322304594a1a40fafc8c92e2c328d316cf Mon Sep 17 00:00:00 2001
From: Domenic Denicola Disallow further import maps given settings object. Let url be the result of resolving a
- module specifier given script and moduleRequest.[[Specifier]].
If url is failure, then asynchronously complete this algorithm with null, and - return.
If the previous step threw an exception, then asynchronously complete this algorithm with + null, and return.
Assert: moduleRequest.[[Assertions]] does not contain any Record
entry such that entry.[[Key]] is not "type
", because
@@ -93813,8 +93814,8 @@ document.querySelector("button").addEventListener("click", bound);
a module specifier given module script and
requested.[[Specifier]].
Assert: the previous step never throws, because resolving a module specifier must have been Assert: the previous step never throws an exception, because resolving a module specifier must have been previously successful with these same two
arguments.
When inserted using the document.write()
+ method, script
elements usually
+ execute (typically blocking further script execution or HTML parsing). When inserted using the
+ innerHTML
and outerHTML
+ attributes, they do not execute at all.
The defer
attribute may be specified even if the async
attribute is specified, to cause legacy web browsers that
only support defer
(and not HTMLScriptElement : HTMLElement {
When inserted using the document.write()
- method, script
elements usually
- execute (typically blocking further script execution or HTML parsing). When inserted using the
- innerHTML
and outerHTML
- attributes, they do not execute at all.
The supports(type)
method steps are:
Return false.
The type argument has to exactly match these values; we do not
perform an ASCII case-insensitive match. This is different from how type
content attribute values are treated, and how
@@ -94911,15 +94915,14 @@ dictionary PromiseRejectionEventInit : EventInit, from most-specific to least-specific scopes (falling back to the top-level unscoped imports), and from most-specific to least-specific
- prefixes. For each candidate, the resolve an imports
- match algorithm will give on the following results:
Successful resolution of the specifier to a URL. Then the resolve a - module specifier algorithm will return that URL.
Successful resolution of the specifier to a URL. Then the + resolve a module specifier algorithm will return that URL.
Throwing an exception. Then the resolve a module specifier will rethrow that - exception, without any further fallbacks.
Throwing an exception. Then the resolve a module specifier algorithm will + rethrow that exception, without any further fallbacks.
Failing to resolve, without an error. In this case the outer resolve a module specifier algorithm will move on to the next candidate.
The JavaScript specification defines Jobs to be scheduled and run later by the host, as well as @@ -95939,6 +95940,8 @@ dictionary PromiseRejectionEventInit : EventInitscript execution context } }.
error
at el, and
return.
- External import map scripts are not currently supported.
+External import map scripts are not currently supported. See WICG/import-maps issue #235 for + discussions on adding support.
Let src be the value of el's This enables statements like This enables statements like An import map can remap a class of module specifiers into a class of URLs by using trailing slashes, like so: An import map can remap a class of module specifiers into a class of URLs by using trailing
+ slashes, like so: This enables statements like This enables statements like so that both the "main module" specified by " so that both the "main module" specified by " Bare specifiers are not the only type of module specifiers which import maps can remap. "URL-like" specifiers, i.e.
- those that are either parseable as absolute URLs or start with " Bare specifiers are not the only type of module specifiers which import maps can remap.
+ "URL-like" specifiers, i.e. those that are either parseable as absolute URLs or start with
+ " Note how the URL to be remapped, as well as the URL being mapped to, can be specified as either absolute URLs, or as a relatives URL starting with " Note how the URL to be remapped, as well as the URL being mapped to, can be specified either
+ as absolute URLs, or as relative URLs starting with " Such remappings operate on the post-canonicalization URL, and do not require a match between the literal strings supplied in the import map key and the imported module specifier. So for example, if this import map was included on Such remappings operate on the post-canonicalization URL, and do not require a match between
+ the literal strings supplied in the import map key and the imported module specifier. So for
+ example, if this import map was included on All previous examples have globally remapped module specifiers, by using the top-level " All previous examples have globally remapped module specifiers, by using the top-level " With this import map, the statement With this import map, the statement Inside scripts located under Inside scripts located under Inside scripts located under Inside scripts located under Inside scripts located under Inside scripts located under A typical usage of scopes is to allow multiple versions of the "same" module to exist in a web application, with some parts of the module graph importing one version, and other parts importing another version.
+ A typical usage of scopes is to allow multiple versions of the "same" module to exist in a
+ web application, with some parts of the module graph importing one version, and other parts
+ importing another version.
Scopes can overlap each other, and overlap the global " Scopes can overlap each other, and overlap the global " The following import map illustrates this: If el is parser-inserted, and either the parser that created
- el is an XML parser or it's an HTML parser whose
- script nesting level is not greater than one, and el's parser
- document has a style sheet that is blocking scripts: If all of the following are true: then: Set el's parser document's pending parsing-blocking
From 46ed84a50bc5371d9d3bbc4759edb3b15e977aac Mon Sep 17 00:00:00 2001
From: Domenic Denicola Assert: exactly one of result's items is
- non-null. Return result. Setting the attribute to an ASCII case-insensitive match for the string
- " Setting the attribute to an ASCII case-insensitive match for " Setting the attribute to an ASCII case-insensitive match for the string
- " Setting the attribute to any other value means that the script is a data
block, which is not processed. None of the A document must not have more than one import map When used to include data blocks, the data must be embedded
inline, the format of the data must be given using the An import map allows control over module specifier resolution. Import maps are
- delivered via inline Bare specifiers are not the only type of module specifiers which import maps can remap.
- "URL-like" specifiers, i.e. those that are either parseable as absolute URLs or start with
+ "URL-like" specifiers, i.e., those that are either parseable as absolute URLs or start with
"PromiseRejectionEventInit : EventInit
-
import moment from "moment";
to
- work, fetching and evaluating the JavaScript module at the /node_modules/moment/src/moment.js
- URL.import moment from "moment";
+ to work, fetching and evaluating the JavaScript module at the /node_modules/moment/src/moment.js
URL.
- {
"imports": {
@@ -95193,9 +95196,10 @@ dictionary PromiseRejectionEventInit : EventInit
import localeData from "moment/locale/zh-cn.js";
to
- work, fetching and evaluating the JavaScript module at the /node_modules/moment/src/moment/locale/zh-cn.js
- URL. Such trailing-slash mappings are often combined with bare-specifier mappings, e.g.import localeData from
+ "moment/locale/zh-cn.js";
to work, fetching and evaluating the JavaScript module at the
+ /node_modules/moment/src/moment/locale/zh-cn.js
URL. Such trailing-slash
+ mappings are often combined with bare-specifier mappings, e.g.
- {
"imports": {
@@ -95204,28 +95208,45 @@ dictionary PromiseRejectionEventInit : EventInit
moment
" and the "submodules" specified by paths such as "moment/locale/zh-cn.js
" are available.moment
" and the
+ "submodules" specified by paths such as "moment/locale/zh-cn.js
" are
+ available./
", "./
", or "../
", can be remapped as well:/
", "./
", or "../
", can be
+ remapped as well:
- {
"imports": {
- "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "/node_modules/vue/dist/vue.runtime.esm.js"
+ "https://cdn.example.com/vue/dist/vue.runtime.esm.js": "/node_modules/vue/dist/vue.runtime.esm.js"
"/js/app.mjs": "/js/app-8e0d62a03.mjs",
"../helpers/": "https://cdn.example/helpers/"
}
}
/
", "./
", or "../
". (They cannot be specified as relative URLs without those special starting sigils, as those help distinguish from bare module specifiers.) Also note how the trailing slash mapping works in this context as well./
", "./
", or "../
". (They cannot be specified as relative
+ URLs without those starting sigils, as those help distinguish from bare module specifiers.) Also
+ note how the trailing slash mapping works in
+ this context as well.https://example.com/app.html
, then not only would import "/js/app.mjs"
be remapped, but so would import "./js/app.mjs"
and import "./foo/../js/app.mjs"
.https://example.com/app.html
,
+ then not only would import "/js/app.mjs"
be remapped, but so
+ would import "./js/app.mjs"
and import "./foo/../js/app.mjs"
.imports
" key in the import map. The top-level "scopes
" key can be used to provide localized remappings, which only apply when the referring module matches a specific URL prefix. For example:imports
" key in the import map. The top-level "scopes
"
+ key can be used to provide localized remappings, which only apply when the referring module
+ matches a specific URL prefix. For example:
- {
"scopes": {
@@ -95233,26 +95254,37 @@ dictionary PromiseRejectionEventInit : EventInit
import "moment"
will have different meanings depending on which referrer script contains the statement:import "moment"
will have
+ different meanings depending on which referrer script contains the statement:
-
- /a/
, this will import /node_modules/moment/src/moment.js
./a/
, this will import /node_modules/moment/src/moment.js
./b/
, this will import https://www.unpkg.com/moment/src/moment.js
./b/
, this will import https://cdn.example.com/moment/src/moment.js
./c/
, this will fail to resolve and thus throw an exception./c/
, this will fail to resolve and
+ thus throw an exception.imports
" specifier map. At resolution time, scopes are consulted in order of most- to least-specific, where specificity is measured by sorting the scopes using the code unit less than operation. So, for example, "/scope2/scope3/
" is treated as more specific than "/scope2/
", which is treated as more specific than the top-level (unscoped) mappings.imports
"
+ specifier map. At resolution time, scopes are consulted in order of most- to least-specific,
+ where specificity is measured by sorting the scopes using the code unit less than
+ operation. So, for example, "/scope2/scope3/
" is treated as more specific
+ than "/scope2/
", which is treated as more specific than the top-level
+ (unscoped) mappings.uninitialized
".
+
+
+ classic
";
From 06cc728959eb96b0b51600f14f605e5bd09145c4 Mon Sep 17 00:00:00 2001
From: Domenic Denicola type
attribute instead of
redundantly setting it.module
" means that the script is a JavaScript module
- script, to be interpreted according to the JavaScript Module top-level production. Module scripts are not affected by the
- defer
attribute, but are affected by the module
" means that the script is a JavaScript module script, to
+ be interpreted according to the JavaScript Module top-level
+ production. Module scripts are not affected by the defer
attribute, but are affected by the async
attribute (regardless of the state of the src
attribute).importmap
" means that the script is an import map,
- containing JSON that will be used to control the behavior of importmap" means that the script is an import map, containing
+ JSON that will be used to control the behavior of module specifier resolution. Import maps can only be inline, i.e., the src
attribute must not be used with them. As such, most other
- attributes also are meaningless and not to be used.script
attributes (except HTMLScriptElement : HTMLElement {
data-x="attr-script-integrity">integrity
, and referrerpolicy
attributes must not be specified.script
element.type
attribute, and the contents of the script
element must conform to the requirements
@@ -95165,8 +95167,8 @@ dictionary PromiseRejectionEventInit : EventInitImport maps
- script
elements with their An import map allows control over module specifier resolution. Import maps
+ are delivered via inline
script
elements with their type
attribute set to "importmap
", and
with their child text content containing a JSON representation of the import
map./
", "./
", or "../
", can be
remapped as well: