Skip to content

Commit

Permalink
Update references from "import assertions" to "import attributes"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicolo-ribaudo committed Mar 24, 2023
1 parent e9bb6cf commit d131bfa
Showing 1 changed file with 35 additions and 46 deletions.
81 changes: 35 additions & 46 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2926,7 +2926,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x="js-HostEnqueuePromiseJob" data-x-href="https://tc39.es/ecma262/#sec-hostenqueuepromisejob">HostEnqueuePromiseJob</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostEnsureCanAddPrivateElement" data-x-href="https://tc39.es/ecma262/#sec-hostensurecanaddprivateelement">HostEnsureCanAddPrivateElement</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.es/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostLoadImportedModule" data-x-href="https://tc39.es/ecma262/#sec-HostLoadImportedModule">HostLoadImportedModule</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostLoadImportedModule" data-x-href="https://tc39.es/proposal-import-attributes/#sec-HostLoadImportedModule">HostLoadImportedModule</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostMakeJobCallback" data-x-href="https://tc39.es/ecma262/#sec-hostmakejobcallback">HostMakeJobCallback</dfn> abstract operation</li>
<li>The <dfn data-x="js-HostPromiseRejectionTracker" data-x-href="https://tc39.es/ecma262/#sec-host-promise-rejection-tracker">HostPromiseRejectionTracker</dfn> abstract operation</li>
<li>The <dfn data-x="js-InitializeHostDefinedRealm" data-x-href="https://tc39.es/ecma262/#sec-initializehostdefinedrealm">InitializeHostDefinedRealm</dfn> abstract operation</li>
Expand Down Expand Up @@ -2989,13 +2989,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<p>Users agents that support JavaScript must also implement <cite>ECMAScript
Internationalization API</cite>. <ref spec=JSINTL></p>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down Expand Up @@ -100740,15 +100740,10 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
import "https://example.com/module";
&lt;/script&gt;
&lt;script type=module&gt;
import "https://example.com/module" assert { type: "css" };
import "https://example.com/module" with { type: "css" };
&lt;/script&gt;</code></pre>

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

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

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

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

<pre><code class="html">&lt;script type="module">
// All of the following will fail, assuming that the imported .mjs files are served with a
// JavaScript MIME type. JavaScript module scripts are the default and cannot be imported with
// any import type assertion.
import foo from "./foo.mjs" assert { type: "javascript" };
import foo2 from "./foo2.mjs" assert { type: "js" };
import foo3 from "./foo3.mjs" assert { type: "" };
await import("./foo4.mjs", { assert: { type: null } });
await import("./foo5.mjs", { assert: { type: undefined } });
// any import type attribute.
import foo from "./foo.mjs" with { type: "javascript" };
import foo2 from "./foo2.mjs" with { type: "js" };
import foo3 from "./foo3.mjs" with { type: "" };
await import("./foo4.mjs", { with: { type: null } });
await import("./foo5.mjs", { with: { type: undefined } });
&lt;/script></code></pre>
</div>

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

<h6 id="hostgetsupportedimportassertions"><dfn>HostGetSupportedImportAssertions</dfn>()</h6>
<h6 id="hostgetsupportedimportattributes"><span id="hostgetsupportedimportassertions"></span><dfn>HostGetSupportedImportAttributes</dfn>()</h6>

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

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

<p class="note">This specification expects the second parameter to be a <span>ModuleRequest
Record</span>, instead of a string as specified by ECMA-262. This is under the assumption that the
<cite>import assertions</cite> proposal, when updated to use <span>HostLoadImportedModule</span>
instead of the previous module loading hooks, will update the abstract operation passing a
<span>ModuleRequest Record</span>. <ref spec=JSIMPORTASSERTIONS></p>

<ol>
<li><p>Let <var>settingsObject</var> be the <span>current settings object</span>.</p></li>

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

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

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

0 comments on commit d131bfa

Please sign in to comment.