Import Attributes are an extension to the import syntax that allows specifying additional information to affect how the module is imported. This proposal, other than defining such syntax, also defines the first import attribtue: type, which is passed to the host to specify the expected type of the loaded module. See the explainer for more information.
+
+ Possible future extensions include:
+
+
a module attribute, to import an object representing the dependency's Module Record instead of evaluating it;
+
a defer attribute, to import a module without evaluating it immediately.
+
+
+
Not every import attribute needs to interact with host semantics, for example module and defer could be defined completely within ECMA-262.
Many productions operating on grammar are the same whether or not an AttributesClause/second ImportCall parameter is included; the new parameter is ignored. In this section, only the semantically significant changes are included, and the PR to merge into the main specification would fill in the straightforward details.
The host-defined abstract operation HostLoadImportedModule takes arguments referrer (a Script Record, a Cyclic Module Record, or a Realm Record), specifier (a String)moduleRequest (a ModuleRequest Record), hostDefined (anything), and payload (a GraphLoadingState Record or a PromiseCapability Record) and returns unused.
+
+ Note
+
An example of when referrer can be a Realm Record is in a web browser host. There, if a user clicks on a control given by
there will be no active script or module at the time the import() expression runs. More generally, this can happen in any situation where the host pushes execution contexts with null ScriptOrModule components onto the execution context stack.
+
+
+
An implementation of HostLoadImportedModule must conform to the following requirements:
+
+
+ The host environment must perform FinishLoadingImportedModule(referrer, specifiermoduleRequest, payload, result), where result is either a normal completion containing the loaded Module Record or a throw completion, either synchronously or asynchronously.
+
+
+
If this operation is called multiple times with the same (referrer, specifier) pair(referrer, moduleRequest.[[Specifier]], moduleRequest.[[Type]]) triple and it performs FinishLoadingImportedModule(referrer, specifiermoduleRequest, payload, result) where result is a normal completion, then it must perform FinishLoadingImportedModule(referrer, specifiermoduleRequest, payload, result) with the same result each time.
+
+
+ The operation must treat payload as an opaque value to be passed through to FinishLoadingImportedModule.
+
+
+
+
+
+
2.3 FinishLoadingImportedModule ( referrer, specifiermoduleRequest, payload, result )
+
The abstract operation FinishLoadingImportedModule takes arguments referrer (a Script Record, a Cyclic Module Record, or a Realm Record), specifier (a String)moduleRequest (a ModuleRequest Record), payload (a GraphLoadingState Record or a PromiseCapability Record), and result (either a normal completion containing a Module Record or a throw completion) and returns unused.
+
+
If result is a normal completion, then
If referrer.[[LoadedModules]] contains a Recordrecord such that record.[[Specifier]] is moduleRequest.[[Specifier]] and record.[[Type]] is moduleRequest.[[Type]], then
In general, this proposal replaces places where module specifiers are passed around with ModuleRequest Records. For example, several syntax-directed operations, such as ModuleRequests produce Lists of ModuleRequest Records rather than Lists of Strings which are interpreted as module specifiers. Some algorithms like ImportEntries and ImportEntriesForModule pass around ModuleRequest Records rather than Strings, in a way which doesn't require any particular textual change. Additionally, record fields in Cyclic Module Records and Source Text Module Records which contained Lists of Strings are replaced by Lists of ModuleRequest Records, as indicated above.
+
+
+
Table 2: Additional Fields of Cyclic Module Records
+
+ A completion of type throw representing the exception that occurred during evaluation. undefined if no exception occurred or if [[Status]] is not evaluated.
+
+ Auxiliary field used during Link and Evaluate only.
+ If [[Status]] is linking or evaluating, this nonnegative number records the point at which the module was first visited during the ongoing depth-first traversal of the dependency graph.
+
+ Auxiliary field used during Link and Evaluate only. If [[Status]] is linking or evaluating, this is either the module's own [[DFSIndex]] or that of an "earlier" module in the same strongly connected component.
+
+ A List of all the ModuleSpecifier strings with the corresponding type import attribute used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered.
+
+
+
+
+
+
+
An ImportEntry Record is a Record that digests information about a single declarative import. Each ImportEntry Record has the fields defined in Table 3:
+ The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. The value "*" indicates that the import request is for the target module's namespace object.
+
+
+
+
+ [[LocalName]]
+
+
+ String
+
+
+ The name that is used to locally access the imported value from within the importing module.
+
The import attributes proposal is intended to give key information about how modules are interpreted to hosts. For the Web embedding and environments which aim to be similar to it, the string is interpreted as the "module type". This is not the primary way the module type is determined (which, on the Web, would be the MIME type, and in other environments may be the file extension), but rather a secondary check which is required to pass for the module graph to load.
+
+
In the Web embedding, the following changes would be made to the HTML specification for import attributes:
+
+
+
The module script would have an additional item, which would be the module type, as a string (e.g., "json"), or undefined for a JavaScript module.
+
HostLoadImportedModule would take a ModuleRequest Record parameter in place of a specifier string, which would be passed down through several abstract operations to reach the fetch a single module script algorithm. Somewhere near the entrypoint, if the ModuleRequest Record's [[Type]] field has an element entry such that entry.[[Key]] is "type", then let type be entry.[[Value]]; otherwise let type be undefined. If the type is invalid, then an exception is thrown and module loading fails. Otherwise, this will equal the module type, if the module can be successfully fetched with a matching MIME type.
+
In the fetch the descendents of a module script algorithm, when iterating over [[RequestedModules]], the elements are ModuleRequest Records rather than just specifier strings; these Records is passed on to the internal module script graph fetching procedure (which sends it to "fetch a single module script". Other usage sites of [[RequestedModules]] ignore the assertion.
+
"Fetch a single module script" would check the assertion in two places:
+
+
The module map is keyed with both the absolute URL and the module type, so an existing entry will be found only if its type matches.
+
When a new module is fetched, before writing it into the module map, the MIME type is checked to ensure that it matches type. (Note that the interpretation of the module is still driven by the MIME type, but once the MIME type is established, this is checked against the type.) If they differ, then an exception is thrown and module loading fails. The type is written into the module script as the type.
+
+
+
+
+
The module map is keyed by the absolute URL and the type. Initially no other import attributes are supported, so they are not present.
+
+
\ No newline at end of file
diff --git a/spec.html b/spec.html
index 28fbff6..580388f 100644
--- a/spec.html
+++ b/spec.html
@@ -2,9 +2,9 @@
-import assertions
+Import Attributes
- title: Import assertions
+ title: Import attributes
status: proposal
stage: 3
location: https://github.com/tc39/proposal-import-assertions
@@ -12,8 +12,16 @@
contributors: Sven Sauleau, Myles Borins, Daniel Ehrenberg, Daniel Clark
Import Attributes are an extension to the import syntax that allows specifying additional information to affect how the module is imported. This proposal, other than defining such syntax, also defines the first import attribtue: `type`, which is passed to the host to specify the expected type of the loaded module. See the explainer for more information.
+
+ Possible future extensions include:
+
+
a `module` attribute, to import an object representing the dependency's Module Record instead of evaluating it;
+
a `defer` attribute, to import a module without evaluating it immediately.
+
+
+
Not every import attribute needs to interact with host semantics, for example `module` and `defer` could be defined completely within ECMA-262.
Many productions operating on grammar are the same whether or not an |AssertClause|/second |ImportCall| parameter is included; the new parameter is ignored. In this section, only the semantically significant changes are included, and the PR to merge into the main specification would fill in the straightforward details.
+
Many productions operating on grammar are the same whether or not an |AttributesClause|/second |ImportCall| parameter is included; the new parameter is ignored. In this section, only the semantically significant changes are included, and the PR to merge into the main specification would fill in the straightforward details.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _specifierString_ be ToString(_specifier_).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
- 1. Let _assertions_ be a new empty List.
+ 1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Type]]: ~empty~ }.
1. If _options_ is not *undefined*, then
1. If Type(_options_) is not Object,
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
- 1. Let _assertionsObj_ be Get(_options_, *"assert"*).
- 1. IfAbruptRejectPromise(_assertionsObj_, _promiseCapability_).
- 1. If _assertionsObj_ is not *undefined*,
- 1. If Type(_assertionsObj_) is not Object,
+ 1. Let _attributesObj_ be Get(_options_, *"with"*).
+ 1. IfAbruptRejectPromise(_attributesObj_, _promiseCapability_).
+ 1. If _attributesObj_ is not *undefined*,
+ 1. If Type(_attributesObj_) is not Object,
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
- 1. Let _keys_ be EnumerableOwnPropertyNames(_assertionsObj_, ~key~).
+ 1. Let _keys_ be EnumerableOwnPropertyNames(_attributesObj_, ~key~).
1. IfAbruptRejectPromise(_keys_, _promiseCapability_).
- 1. Let _supportedAssertions_ be ! HostGetSupportedImportAssertions().
1. For each String _key_ of _keys_,
- 1. Let _value_ be Get(_assertionsObj_, _key_).
+ 1. Let _value_ be Get(_attributesObj_, _key_).
1. IfAbruptRejectPromise(_value_, _promiseCapability_).
1. If Type(_value_) is not String, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
- 1. If _supportedAssertions_ contains _key_, then
- 1. Append { [[Key]]: _key_, [[Value]]: _value_ } to _assertions_.
- 1. Sort _assertions_ by the code point order of the [[Key]] of each element. NOTE: This sorting is observable only in that hosts are prohibited from distinguishing among assertions by the order they occur in.
- 1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Assertions]]: _assertions_ }.
+ 1. If _key_ is *"type"*, then
+ 1. Assert: _moduleRequest_.[[Type]] is ~empty~.
+ 1. Set _moduleRequest_.[[Type]] to _value_.
+ 1. TODO: Throw on unknown keys?
1. Perform HostLoadImportedModule(_referrer_, _moduleRequest_, ~empty~, _promiseCapability_).
1. Return _promiseCapability_.[[Promise]].
@@ -138,35 +148,12 @@
HostLoadImportedModule ( _referrer_, _specifier__moduleReque
The host environment must perform FinishLoadingImportedModule(_referrer_, _specifier__moduleRequest_, _payload_, _result_), where _result_ is either a normal completion containing the loaded Module Record or a throw completion, either synchronously or asynchronously.
-
If this operation is called multiple times with the same (_referrer_, _specifier_) pair(_referrer_, _moduleRequest_.[[Specifier]], _moduleRequest_.[[Assertions]]) triple and it performs FinishLoadingImportedModule(_referrer_, _specifier__moduleRequest_, _payload_, _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, _specifier__moduleRequest_, _payload_, _result_) with the same _result_ each time.
-
-
It is recommended but not required that implementations additionally conform to the following stronger constraint:
-
-
- If this operation is called multiple times with the same (_referrer_, _moduleRequest_.[[Specifier]]) pair and it performs FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_) with the same _result_ each time.
-
-
-
-
- _moduleRequest_.[[Assertions]] must not influence the interpretation of the module or the module specifier; instead, it may be used to determine whether the algorithm completes normally or with an abrupt completion.
+
If this operation is called multiple times with the same (_referrer_, _specifier_) pair(_referrer_, _moduleRequest_.[[Specifier]], _moduleRequest_.[[Type]]) triple and it performs FinishLoadingImportedModule(_referrer_, _specifier__moduleRequest_, _payload_, _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, _specifier__moduleRequest_, _payload_, _result_) with the same _result_ each time.
The operation must treat _payload_ as an opaque value to be passed through to FinishLoadingImportedModule.
-
-
The actual process performed is host-defined, but typically consists of performing whatever I/O operations are necessary to load the appropriate Module Record. Multiple different (_referrer_, _specifier__moduleRequest_.[[Specifier]]) pairs may map to the same Module Record instance. The actual mapping semantic is host-defined but typically a normalization process is applied to _specifier__moduleRequest_.[[Specifier]] as part of the mapping process. A typical normalization process would include actions such as expansion of relative and abbreviated path specifiers.
-
-
-
The above text implies that is recommended but not required that hosts do not use _moduleRequest_.[[Assertions]] as part of the module cache key. In either case, an exception thrown from an import with a given assertion list does not rule out success of another import with the same specifier but a different assertion list.
-
Assertions do not affect the contents of the module. Future follow-up proposals may relax this restriction with "evaluator attributes" that would change the contents of the module. There are three possible ways to handle multiple imports of the same module with "evaluator attributes":
-
-
Race and use the attribute that was requested by the first import. This seems broken--the second usage is ignored.
-
Reject the module graph and don't load if attributes differ. This seems bad for composition--using two unrelated packages together could break, if they load the same module with disagreeing attributes.
-
Clone and make two copies of the module, for the different ways it's transformed. In this case, the attributes would have to be part of the cache key. These semantics would run counter to the intuition that there is just one copy of a module.
-
-
It's possible that one of these three options may make sense for a module load, on a case-by-case basis by attribute, but it's worth careful thought before making this choice.
-
@@ -175,9 +162,9 @@
FinishLoadingImportedModule ( _referrer_, _specifier__module
1. If _result_ is a normal completion, then
- 1. If _referrer_.[[LoadedModules]] contains a Record _record_ such that _record_.[[Specifier]] is _moduleRequest_.[[Specifier]] and AssertionsEqual(_record_.[[Assertions]], _moduleRequest_.[[Assertions]]) is *true*, then
+ 1. If _referrer_.[[LoadedModules]] contains a Record _record_ such that _record_.[[Specifier]] is _moduleRequest_.[[Specifier]] and _record_.[[Type]] is _moduleRequest_.[[Type]], then
1. Assert: _record_.[[Module]] is _result_.[[Value]].
- 1. Else, add Record { [[Specifier]]: _moduleRequest_.[[Specifier]], [[Assertions]]: _moduleRequest_.[[Assertions]], [[Module]]: _result_.[[Value]] } to _referrer_.[[LoadedModules]].
+ 1. Else, add Record { [[Specifier]]: _moduleRequest_.[[Specifier]], [[Type]]: _moduleRequest_.[[Type]], [[Module]]: _result_.[[Value]] } to _referrer_.[[LoadedModules]].
1. If _payload_ is a GraphLoadingState Record, then
1. Perform ContinueModuleLoading(_payload_, _result_).
1. Else,
@@ -186,109 +173,32 @@
The description of the [[LoadedModules]] field of Realm Record, Script Record, and Cyclic Module Record should be updated to include the [[Assertions]] field.
+
The description of the [[LoadedModules]] field of Realm Record, Script Record, and Cyclic Module Record should be updated to include the [[Type]] field.
-
-
-
AssertionsEqual(_left_, _right_)
-
The abstract operation AssertionsEqual takes arguments _left_ and _right_ (two Lists of Records { [[Key]]: a String, [[Value]]: a String }), and returns a Boolean.
-
-
- 1. If the number of elements in _left_ is not the same as the number of elements in _right_, return *false*.
- 1. For each Record { [[Key]], [[Value]] } _r_ of _left_, do
- 1. Let _found_ be *false*.
- 1. For each Record { [[Key]], [[Value]] } _s_ of _right_, do
- 1. If _r_.[[Key]] is _s_.[[Key]] and _r_.[[Value]] is _s_.[[Value]], then
- 1. Set _found_ to *true*.
- 1. If _found_ is *false*, return *false*.
- 1. Return *true*.
-
-
- HostGetSupportedImportAssertions is a host-defined abstract operation that allows host environments to specify which import assertions they support.
- Only assertions with supported keys will be provided to the host.
-
-
-
The implementation of HostGetSupportedImportAssertions must conform to the following requrements:
-
-
-
It must return a List whose values are all StringValues, each indicating a supported assertion.
-
-
Each time this operation is called, it must return the same List instance with the same contents.
-
-
An implementation of HostGetSupportedImportAssertions must always complete normally (i.e., not return an abrupt completion).
-
-
-
The default implementation of HostGetSupportedImportAssertions is to return an empty List.
-
- The purpose of requiring the host to specify its supported import assertions, rather than passing all assertions to the host and letting it then choose which ones it wants to handle, is to ensure that unsupported assertions are handled in a consistent way across different hosts.
-
-
-
-
It is a Syntax Error if AssertClauseToAssertions of |AssertClause| has two entries _a_ and _b_ such that _a_.[[Key]] is _b_.[[Key]].
-
-
-
-
-
Static Semantics: AssertClauseToAssertions
- AssertClause : `assert` `{` `}`
-
- 1. Return a new empty List.
-
-
- AssertClause : `assert` `{` AssertEntries `,`? `}`
-
- 1. Let _assertions_ be AssertClauseToAssertions of |AssertEntries|.
- 1. Sort _assertions_ by the code point order of the [[Key]] of each element. NOTE: This sorting is observable only in that hosts are prohibited from distinguishing among assertions by the order they occur in.
- 1. Return _assertions_.
-
-
- AssertEntries : AssertionKey `:` StringLiteral
+
+
+ AttributeEntries : AttributeEntries `,` AttributeEntry
- 1. Let _supportedAssertions_ be !HostGetSupportedImportAssertions().
- 1. Let _key_ be StringValue of |AssertionKey|.
- 1. If _supportedAssertions_ contains _key_,
- 1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
- 1. Return a new List containing the single element, _entry_.
- 1. Otherwise, return a new empty List.
+ 1. Perform CollectImportAttributes of |AttributeEntries| with parameters « _moduleRequest_ ».
+ 1. Perform CollectImportAttributes of |AttributeEntry| with parameters « _moduleRequest_ ».
- AssertEntries : AssertionKey `:` StringLiteral `,` AssertEntries
+ AttributeEntry : AttributeKey `:` StringLiteral
- 1. Let _supportedAssertions_ be !HostGetSupportedImportAssertions().
- 1. Let _key_ be StringValue of |AssertionKey|.
- 1. If _supportedAssertions_ contains _key_,
- 1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
- 1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
- 1. Return a new List containing _entry_ followed by the elements of _rest_.
- 1. Otherwise, return AssertClauseToAssertions of |AssertEntries|.
-
-
-
-
-
Static Semantics: StringValue
- AssertionKey : IdentifierName
-
- 1. Return the StringValue of |IdentifierName|.
-
-
- AssertionKey : StringLiteral
-
- 1. Return the StringValue of |StringLiteral|.
+ 1. Let _key_ be StringValue of |AttributeKey|.
+ 1. If _key_ is *"type"*, then
+ 1. If _moduleRequest_.[[Type]] is not ~empty~, throw a SyntaxError exception.
+ 1. Set _moduleRequest_.[[Type]] to the StringValue of |StringLiteral|.
+ 1. TODO: Throw on unknown keys?
ModuleRequest Records
-
A ModuleRequest Record represents the request to import a module with given import assertions. It consists of the following fields:
+
A ModuleRequest Record represents the request to import a module with given import attributes. It consists of the following fields:
@@ -316,13 +226,13 @@
ModuleRequest Records
- [[Assertions]]
+ [[Type]]
- a List of Records { [[Key]]: a String, [[Value]]: a String }
+ a String, or ~empty~
- The import assertions
+ The `type` attribute of this import
@@ -399,7 +309,7 @@
ModuleRequest Records
List of StringModuleRequest Record
- A List of all the |ModuleSpecifier| strings and import assertions used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered.
+ A List of all the |ModuleSpecifier| strings with the corresponding `type` import attribute used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered.
@@ -431,7 +341,7 @@
ModuleRequest Records
String value of the |ModuleSpecifier| of the |ImportDeclaration|.
- ModuleRequest Record representing the |ModuleSpecifier| and import assertions of the |ImportDeclaration|.
+ ModuleRequest Record representing the |ModuleSpecifier| and the `type` import attribute of the |ImportDeclaration|.
@@ -466,14 +376,15 @@
Static Semantics: ModuleRequests
ImportDeclaration : `import` ImportClause FromClause `;`
1. Return ModuleRequests of |FromClause|.
- 1. Let _specifier_ be StringValue of the |StringLiteral| contained in |FromClause|.
- 1. Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: an empty List }.
+ 1. Let _specifier_ be StringValue of |FromClause|.
+ 1. Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Type]]: ~empty~ }.
- ImportDeclaration : `import` ImportClause FromClause AssertClause `;`
+ ImportDeclaration : `import` ImportClause FromClause AttributesClause `;`
- 1. Let _specifier_ be StringValue of the |StringLiteral| contained in |FromClause|.
- 1. Let _assertions_ be AssertClauseToAssertions of |AssertClause|.
- 1. Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: _assertions_ }.
+ 1. Let _specifier_ be StringValue of |FromClause|.
+ 1. Let _request_ be the ModuleRequest Record { [[Specifer]]: _specifier_, [[Type]]: ~empty~ }.
+ 1. Perform CollectImportAttributes of |AttributesClause| with argument _request_.
+ 1. Return _request_.
Module : [empty]
@@ -487,10 +398,9 @@
Static Semantics: ModuleRequests
1. Let _moduleNames_ be ModuleRequests of |ModuleItemList|.
1. Let _additionalNames_ be ModuleRequests of |ModuleItem|.
- 1. Append to _moduleNames_ each element of _additionalNames_ that is not already an element of _moduleNames_.
+ 1. Append to _moduleNames_ each element of _additionalNames_ that is not already an element of _moduleNames_.
1. Return _moduleNames_.
- Deletion of duplicates is an unnecessary "spec optimization" that would be more complicated to explain in terms of examining import assertion records, and can be simply removed.ModuleItem : StatementListItem
1. Return a new empty List.
@@ -500,16 +410,17 @@
Static Semantics: ModuleRequests
1. Return ModuleRequests of |FromClause|.
- 1. Let _specifier_ be StringValue of the |StringLiteral| contained in |FromClause|.
- 1. Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: an empty List }.
+ 1. Let _specifier_ be StringValue of |FromClause|.
+ 1. Return the ModuleRequest Record { [[Specifer]]: _specifier_, [[Type]]: ~empty~ }.
- ExportDeclaration : `export` ExportFromClause FromClause AssertClause `;`
+ ExportDeclaration : `export` ExportFromClause FromClause AttributesClause `;`
1. Let _specifier_ be StringValue of the |StringLiteral| contained in |FromClause|.
- 1. Let _assertions_ be AssertClauseToAssertions of |AssertClause|.
- 1. Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: _assertions_ }.
+ 1. Let _request_ be the ModuleRequest Record { [[Specifer]]: _specifier_, [[Type]]: ~empty~ }.
+ 1. Perform CollectImportAttributes of |AttributesClause| with argument _request_.
+ 1. Return _request_.
ExportDeclaration :
@@ -529,13 +440,13 @@
Static Semantics: ModuleRequests
Sample host integration: The Web embedding
-
The import assertions proposal is intended to give key information about how modules are interpreted to hosts. For the Web embedding and environments which aim to be similar to it, the string is interpreted as the "module type". This is not the primary way the module type is determined (which, on the Web, would be the MIME type, and in other environments may be the file extension), but rather a secondary check which is required to pass for the module graph to load.
+
The import attributes proposal is intended to give key information about how modules are interpreted to hosts. For the Web embedding and environments which aim to be similar to it, the string is interpreted as the "module type". This is not the primary way the module type is determined (which, on the Web, would be the MIME type, and in other environments may be the file extension), but rather a secondary check which is required to pass for the module graph to load.
-
In the Web embedding, the following changes would be made to the HTML specification for import assertions:
+
In the Web embedding, the following changes would be made to the HTML specification for import attributes:
The module script would have an additional item, which would be the module type, as a string (e.g., *"json"*), or *undefined* for a JavaScript module.
-
HostLoadImportedModule would take a ModuleRequest Record parameter in place of a specifier string, which would be passed down through several abstract operations to reach the fetch a single module script algorithm. Somewhere near the entrypoint, if the ModuleRequest Record's [[Assertions]] field has an element _entry_ such that _entry_.[[Key]] is *"type"*, then let _type_ be _entry_.[[Value]]; otherwise let _type_ be *undefined*. If the type is invalid, then an exception is thrown and module loading fails. Otherwise, this will equal the module type, if the module can be successfully fetched with a matching MIME type.
+
HostLoadImportedModule would take a ModuleRequest Record parameter in place of a specifier string, which would be passed down through several abstract operations to reach the fetch a single module script algorithm. Somewhere near the entrypoint, if the ModuleRequest Record's [[Type]] field has an element _entry_ such that _entry_.[[Key]] is *"type"*, then let _type_ be _entry_.[[Value]]; otherwise let _type_ be *undefined*. If the type is invalid, then an exception is thrown and module loading fails. Otherwise, this will equal the module type, if the module can be successfully fetched with a matching MIME type.
In the fetch the descendents of a module script algorithm, when iterating over [[RequestedModules]], the elements are ModuleRequest Records rather than just specifier strings; these Records is passed on to the internal module script graph fetching procedure (which sends it to "fetch a single module script". Other usage sites of [[RequestedModules]] ignore the assertion.
"Fetch a single module script" would check the assertion in two places:
@@ -545,5 +456,5 @@
Sample host integration: The Web embedding
-
The module map is keyed by the absolute URL and the _type_. Initially no other import assertions are supported, so they are not present.
+
The module map is keyed by the absolute URL and the _type_. Initially no other import attributes are supported, so they are not present.