Skip to content

Commit d131bfa

Browse files
Update references from "import assertions" to "import attributes"
See recent changes to https://github.com/tc39/proposal-import-attributes. Notably: * Import attributes can affect how a module is loaded and can be part of the cache key. This removes the willful violation HTML had in its usage of import assertions, and unblocks #7233. * The keyword has been changed from assert to with. Due to existing support in Chrome/Node.js/Deno the assert keyword will stick around for a while, and the V8 team will investigate the possibility of removing it.
1 parent e9bb6cf commit d131bfa

File tree

1 file changed

+35
-46
lines changed

1 file changed

+35
-46
lines changed

source

+35-46
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
29262926
<li>The <dfn data-x="js-HostEnqueuePromiseJob" data-x-href="https://tc39.es/ecma262/#sec-hostenqueuepromisejob">HostEnqueuePromiseJob</dfn> abstract operation</li>
29272927
<li>The <dfn data-x="js-HostEnsureCanAddPrivateElement" data-x-href="https://tc39.es/ecma262/#sec-hostensurecanaddprivateelement">HostEnsureCanAddPrivateElement</dfn> abstract operation</li>
29282928
<li>The <dfn data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.es/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
2929-
<li>The <dfn data-x="js-HostLoadImportedModule" data-x-href="https://tc39.es/ecma262/#sec-HostLoadImportedModule">HostLoadImportedModule</dfn> abstract operation</li>
2929+
<li>The <dfn data-x="js-HostLoadImportedModule" data-x-href="https://tc39.es/proposal-import-attributes/#sec-HostLoadImportedModule">HostLoadImportedModule</dfn> abstract operation</li>
29302930
<li>The <dfn data-x="js-HostMakeJobCallback" data-x-href="https://tc39.es/ecma262/#sec-hostmakejobcallback">HostMakeJobCallback</dfn> abstract operation</li>
29312931
<li>The <dfn data-x="js-HostPromiseRejectionTracker" data-x-href="https://tc39.es/ecma262/#sec-host-promise-rejection-tracker">HostPromiseRejectionTracker</dfn> abstract operation</li>
29322932
<li>The <dfn data-x="js-InitializeHostDefinedRealm" data-x-href="https://tc39.es/ecma262/#sec-initializehostdefinedrealm">InitializeHostDefinedRealm</dfn> abstract operation</li>
@@ -2989,13 +2989,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
29892989
<p>Users agents that support JavaScript must also implement <cite>ECMAScript
29902990
Internationalization API</cite>. <ref spec=JSINTL></p>
29912991

2992-
<p>User agents that support JavaScript must also implement the <cite>Import Assertions</cite>
2992+
<p>User agents that support JavaScript must also implement the <cite>Import Attributes</cite>
29932993
proposal. The following terms are defined there, and used in this specification: <ref
2994-
spec=JSIMPORTASSERTIONS></p>
2994+
spec=JSIMPORTATTRIBUTES></p>
29952995

29962996
<ul class="brief">
2997-
<li>The <dfn data-x-href="https://tc39.es/proposal-import-assertions/#sec-modulerequest-record">ModuleRequest Record</dfn> specification type</li>
2998-
<li>The <dfn data-x="js-HostGetSupportedImportAssertions" data-x-href="https://tc39.es/proposal-import-assertions/#sec-hostgetsupportedimportassertions">HostGetSupportedImportAssertions</dfn> abstract operation</li>
2997+
<li>The <dfn data-x-href="https://tc39.es/proposal-import-attributes/#sec-modulerequest-record">ModuleRequest Record</dfn> specification type</li>
2998+
<li>The <dfn data-x="js-HostGetSupportedImportAttributes" data-x-href="https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes">HostGetSupportedImportAttributes</dfn> abstract operation</li>
29992999
</ul>
30003000

30013001
<p>User agents that support JavaScript must also implement the <cite>JSON modules</cite>
@@ -60851,7 +60851,7 @@ o............A....e
6085160851
a <span>JavaScript module script</span>:</p>
6085260852

6085360853
<pre><code class="html" data-x="">&lt;script type="module">
60854-
import peopleInSpace from "http://api.open-notify.org/astros.json" assert { type: "json" };
60854+
import peopleInSpace from "http://api.open-notify.org/astros.json" with { type: "json" };
6085560855

6085660856
const list = document.querySelector("#people-in-space");
6085760857
for (const { craft, name } of peopleInSpace.people) {
@@ -60864,7 +60864,7 @@ o............A....e
6086460864
<p>MIME type checking for module scripts is strict. In order for the fetch of the <span>JSON
6086560865
module script</span> to succeed, the HTTP response must have a <span>JSON MIME type</span>, for
6086660866
example <code data-x="">Content-Type: text/json</code>. On the other hand, if the <code
60867-
data-x="">assert { type: "json" }</code> part of the statement is omitted, it is assumed that the
60867+
data-x="">with { type: "json" }</code> part of the statement is omitted, it is assumed that the
6086860868
intent is to import a <span>JavaScript module script</span>, and the fetch will fail if the HTTP
6086960869
response has a MIME type that is not a <span>JavaScript MIME type</span>.</p>
6087060870
</div>
@@ -98594,7 +98594,7 @@ document.querySelector("button").addEventListener("click", bound);
9859498594
<li><p><span>Assert</span>: the result of running the <span>module type allowed</span> steps given
9859598595
<var>moduleType</var> and <var>module map settings object</var> is true. Otherwise we would not
9859698596
have reached this point because a failure would have been raised when inspecting
98597-
<var>moduleRequest</var>.[[Assertions]] in <a href="#validate-requested-module-specifiers">create
98597+
<var>moduleRequest</var>.[[Attributes]] in <a href="#validate-requested-module-specifiers">create
9859898598
a JavaScript module script</a> or <span>fetch a single imported module script</span>.</p></li>
9859998599

9860098600
<li><p>Let <var>moduleMap</var> be <var>module map settings object</var>'s <span
@@ -98715,10 +98715,10 @@ document.querySelector("button").addEventListener("click", bound);
9871598715
<span>module script</span> (on success).</p>
9871698716

9871798717
<ol>
98718-
<li><p><span>Assert</span>: <var>moduleRequest</var>.[[Assertions]] does not contain any <span>Record</span>
98718+
<li><p><span>Assert</span>: <var>moduleRequest</var>.[[Attributes]] does not contain any <span>Record</span>
9871998719
<var>entry</var> such that <var>entry</var>.[[Key]] is not "<code data-x="">type</code>", because
98720-
we only asked for "<code data-x="">type</code>" assertions in
98721-
<span>HostGetSupportedImportAssertions</span>.</p></li>
98720+
we only asked for "<code data-x="">type</code>" attributes in
98721+
<span>HostGetSupportedImportAttributes</span>.</p></li>
9872298722

9872398723
<li><p>Let <var>moduleType</var> be the result of running the <span>module type from module
9872498724
request</span> steps given <var>moduleRequest</var>.</p></li>
@@ -98840,10 +98840,10 @@ document.querySelector("button").addEventListener("click", bound);
9884098840
</ol>
9884198841
</li>
9884298842

98843-
<li><p><span>Assert</span>: <var>requested</var>.[[Assertions]] does not contain any
98843+
<li><p><span>Assert</span>: <var>requested</var>.[[Attributes]] does not contain any
9884498844
<span>Record</span> <var>entry</var> such that <var>entry</var>.[[Key]] is not "<code
98845-
data-x="">type</code>", because we only asked for "<code data-x="">type</code>" assertions in
98846-
<span>HostGetSupportedImportAssertions</span>.</p></li>
98845+
data-x="">type</code>", because we only asked for "<code data-x="">type</code>" attributes in
98846+
<span>HostGetSupportedImportAttributes</span>.</p></li>
9884798847

9884898848
<li id="validate-requested-module-specifiers">
9884998849
<p><span data-x="list iterate">For each</span> <span>ModuleRequest record</span>
@@ -98884,8 +98884,8 @@ document.querySelector("button").addEventListener("click", bound);
9888498884
</ol>
9888598885

9888698886
<p class="note">This step is essentially validating all of the requested module specifiers and
98887-
type assertions. We treat a module with unresolvable module specifiers or unsupported type
98888-
assertions the same as one that cannot be parsed; in both cases, a syntactic issue makes it
98887+
type attributes. We treat a module with unresolvable module specifiers or unsupported type
98888+
attributes the same as one that cannot be parsed; in both cases, a syntactic issue makes it
9888998889
impossible to ever contemplate linking the module later.</p>
9889098890
</li>
9889198891

@@ -98970,7 +98970,7 @@ document.querySelector("button").addEventListener("click", bound);
9897098970
<li><p>Let <var>moduleType</var> be "<code data-x="">javascript</code>".</p></li>
9897198971

9897298972
<li>
98973-
<p>If <var>moduleRequest</var>.[[Assertions]] has a <span>Record</span> <var>entry</var> such
98973+
<p>If <var>moduleRequest</var>.[[Attributes]] has a <span>Record</span> <var>entry</var> such
9897498974
that <var>entry</var>.[[Key]] is "<code data-x="">type</code>", then:</p>
9897598975

9897698976
<ol>
@@ -98981,7 +98981,7 @@ document.querySelector("button").addEventListener("click", bound);
9898198981
<p class="note">This specification uses the "<code data-x="">javascript</code>" module type
9898298982
internally for <span data-x="JavaScript module script">JavaScript module scripts</span>, so
9898398983
this step is needed to prevent modules from being imported using a "<code
98984-
data-x="">javascript</code>" type assertion (a null <var>moduleType</var> will cause the
98984+
data-x="">javascript</code>" type attribute (a null <var>moduleType</var> will cause the
9898598985
<span>module type allowed</span> check to fail).</p>
9898698986
</li>
9898798987

@@ -100740,15 +100740,10 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
100740100740
import "https://example.com/module";
100741100741
&lt;/script&gt;
100742100742
&lt;script type=module&gt;
100743-
import "https://example.com/module" assert { type: "css" };
100743+
import "https://example.com/module" with { type: "css" };
100744100744
&lt;/script&gt;</code></pre>
100745100745

100746-
<p>This can result in two separate fetches and two separate module evaluations being performed.
100747-
This is a <span>willful violation</span> of a constraint recommended (but not required) by the
100748-
import assertions specification stating that each call to <span>HostLoadImportedModule</span>
100749-
with the same (<var>referrer</var>, <var>moduleRequest</var>.[[Specifier]]) pair
100750-
must return the same <span data-x="Source Text Module Record">Module Record</span>. <ref
100751-
spec=JSIMPORTASSERTIONS></p>
100746+
<p>This can result in two separate fetches and two separate module evaluations being performed.</p>
100752100747

100753100748
<p class="XXX">In practice, due to the as-yet-unspecified memory cache (see issue <a
100754100749
href="https://github.com/whatwg/html/issues/6110">#6110</a>) the resource may only be fetched
@@ -100757,26 +100752,26 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
100757100752
least one of the imports, so at most one module evaluation will occur.</p>
100758100753

100759100754
<p>The purpose of including the type in the <span>module map</span> key is so that an import
100760-
with the wrong type assertion does not prevent a different import of the same specifier but with
100755+
with the wrong type attribute does not prevent a different import of the same specifier but with
100761100756
the correct type from succeeding.</p>
100762100757
</div>
100763100758

100764100759
<div class="example">
100765100760
<p>JavaScript module scripts are the default import type when importing from another JavaScript
100766100761
module; that is, when an <code data-x="">import</code> statement lacks a <code
100767-
data-x="">type</code> import assertion the imported module script's type will be JavaScript.
100762+
data-x="">type</code> import attribute the imported module script's type will be JavaScript.
100768100763
Attempting to import a JavaScript resource using an <code data-x="">import</code> statement with
100769-
a <code data-x="">type</code> import assertion will fail:</p>
100764+
a <code data-x="">type</code> import attribute will fail:</p>
100770100765

100771100766
<pre><code class="html">&lt;script type="module">
100772100767
// All of the following will fail, assuming that the imported .mjs files are served with a
100773100768
// JavaScript MIME type. JavaScript module scripts are the default and cannot be imported with
100774-
// any import type assertion.
100775-
import foo from "./foo.mjs" assert { type: "javascript" };
100776-
import foo2 from "./foo2.mjs" assert { type: "js" };
100777-
import foo3 from "./foo3.mjs" assert { type: "" };
100778-
await import("./foo4.mjs", { assert: { type: null } });
100779-
await import("./foo5.mjs", { assert: { type: undefined } });
100769+
// any import type attribute.
100770+
import foo from "./foo.mjs" with { type: "javascript" };
100771+
import foo2 from "./foo2.mjs" with { type: "js" };
100772+
import foo3 from "./foo3.mjs" with { type: "" };
100773+
await import("./foo4.mjs", { with: { type: null } });
100774+
await import("./foo5.mjs", { with: { type: undefined } });
100780100775
&lt;/script></code></pre>
100781100776
</div>
100782100777

@@ -100824,12 +100819,12 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
100824100819
».</p></li>
100825100820
</ol>
100826100821

100827-
<h6 id="hostgetsupportedimportassertions"><dfn>HostGetSupportedImportAssertions</dfn>()</h6>
100822+
<h6 id="hostgetsupportedimportattributes"><span id="hostgetsupportedimportassertions"></span><dfn>HostGetSupportedImportAttributes</dfn>()</h6>
100828100823

100829-
<p>The <cite>Import Assertions</cite> proposal contains an <span>implementation-defined</span>
100830-
<span data-x="js-HostGetSupportedImportAssertions">HostGetSupportedImportAssertions</span>
100824+
<p>The <cite>Import Attributes</cite> proposal contains an <span>implementation-defined</span>
100825+
<span data-x="js-HostGetSupportedImportAttributes">HostGetSupportedImportAttributes</span>
100831100826
abstract operation. User agents must use the following implementation: <ref
100832-
spec=JSIMPORTASSERTIONS></p>
100827+
spec=JSIMPORTATTRIBUTES></p>
100833100828

100834100829
<ol>
100835100830
<li><p>Return « "<code data-x="">type</code>" ».</p></li>
@@ -100842,12 +100837,6 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
100842100837
data-x="js-HostLoadImportedModule">HostLoadImportedModule</span> abstract operation. User agents
100843100838
must use the following implementation: <ref spec=JAVASCRIPT></p>
100844100839

100845-
<p class="note">This specification expects the second parameter to be a <span>ModuleRequest
100846-
Record</span>, instead of a string as specified by ECMA-262. This is under the assumption that the
100847-
<cite>import assertions</cite> proposal, when updated to use <span>HostLoadImportedModule</span>
100848-
instead of the previous module loading hooks, will update the abstract operation passing a
100849-
<span>ModuleRequest Record</span>. <ref spec=JSIMPORTASSERTIONS></p>
100850-
100851100840
<ol>
100852100841
<li><p>Let <var>settingsObject</var> be the <span>current settings object</span>.</p></li>
100853100842

@@ -133360,8 +133349,8 @@ INSERT INTERFACES HERE
133360133349
<dt id="refsJSERRORSTACKS">[JSERRORSTACKS]</dt>
133361133350
<dd>(Non-normative) <cite><a href="https://tc39.es/proposal-error-stacks/">Error Stacks</a></cite>. Ecma International.</dd>
133362133351

133363-
<dt id="refsJSIMPORTASSERTIONS">[JSIMPORTASSERTIONS]</dt>
133364-
<dd><cite><a href="https://tc39.es/proposal-import-assertions/">Import Assertions</a></cite>. Ecma International.</dd>
133352+
<dt id="refsJSIMPORTATTRIBUTES">[JSIMPORTATTRIBUTES]</dt>
133353+
<dd><cite><a href="https://tc39.es/proposal-import-attributes/">Import attributes</a></cite>. Ecma International.</dd>
133365133354

133366133355
<dt id="refsJSJSONMODULES">[JSJSONMODULES]</dt>
133367133356
<dd><cite><a href="https://tc39.es/proposal-json-modules/">JSON Modules</a></cite>. Ecma International.</dd>

0 commit comments

Comments
 (0)