Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import.meta.resolve() #5572

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 43 additions & 6 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-cleanup-finalization-registry">CleanupFinalizationRegistry</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-construct">Construct</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-copydatablockbytes">CopyDataBlockBytes</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-createbuiltinfunction">CreateBuiltinFunction</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-createbytedatablock">CreateByteDataBlock</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-createdataproperty">CreateDataProperty</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-detacharraybuffer">DetachArrayBuffer</dfn> abstract operation</li>
Expand Down Expand Up @@ -93995,14 +93996,27 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
world, from the classic-script world.</p>
</dd>

<dt><code data-x=""><var>url</var> = <span data-x="import.meta">import.meta </span><span data-x="">.url</span></code></dt>
<dt><code data-x=""><var>url</var> = <span data-x="import.meta">import.meta</span>.<span data-x="import-meta-url">url</span></code></dt>

<dd>
<p>Returns the <span data-x="active script">active module script</span>'s <span
data-x="concept-script-base-url">base URL</span>.</p>

<p>This syntax can only be used inside <span data-x="module script">module scripts</span>.</p>
</dd>

<dt><code data-x=""><var>url</var> = <span data-x="import.meta">import.meta</span>.<span data-x="import-meta-resolve">resolve</span>(<var>specifier</var>)</code></dt>

<dd>
<p>Returns <var>specifier</var>, <span data-x="resolve a module specifier">resolved</span>
relative to the <span>active script</span>'s <span data-x="concept-script-base-url">base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify that the active script here is the active script at the time of obtaining import.meta and not the active script at the time of resolve() call? e.g.

window.resolve = import.meta.resolve; // A.js
// ... in another calling context ...
url = window.resolve(specifier); // B.js

Then the specifier is resolved relative to A.js (= active script at the time of import.meta ), not B.js (that of resolve() call).

URL</span>. That is, this returns the URL that would be imported by using <code
data-x="import()">import(<var>specifier</var>)</code>.</p>

<p>Throws a <code>TypeError</code> exception if an invalid specifier is given.</p>

<p>This syntax can only be used inside <span data-x="module script">module scripts</span>.</p>
</dd>
</dl>

<p><span w-nodev>A <dfn>module map</dfn> is a <span data-x="ordered map">map</span> keyed by <span
Expand Down Expand Up @@ -94186,17 +94200,40 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
User agents must use the following implementation: <ref spec=JAVASCRIPT></p>

<ol>
<li><p>Let <var>module script</var> be <var>moduleRecord</var>.[[HostDefined]].</p></li>
<li><p>Let <var>moduleScript</var> be <var>moduleRecord</var>.[[HostDefined]].</p></li>

<li><p>Assert: <var>module script</var>'s <span data-x="concept-script-base-url">base
URL</span> is not null, as <var>module script</var> is a <span>JavaScript module
<li><p>Assert: <var>moduleScript</var>'s <span data-x="concept-script-base-url">base
URL</span> is not null, as <var>moduleScript</var> is a <span>JavaScript module
script</span>.</p></li>

<li><p>Let <var>urlString</var> be <var>module script</var>'s <span
<li><p>Let <var>urlString</var> be <var>moduleScript</var>'s <span
data-x="concept-script-base-url">base URL</span>, <span
data-x="concept-url-serializer">serialized</span>.</p></li>

<li><p>Return « Record { [[Key]]: "url", [[Value]]: <var>urlString</var> } ».</p></li>
<li>
<p>Let <var>steps</var> be the following steps, given the argument <var>specifier</var>:</p>

<ol>
<li><p>Set <var>specifier</var> to ? <span>ToString</span>(<var>specifier</var>).</p></li>

<li><p>Let <var>url</var> be the result of <span data-x="resolve a module specifier">resolving
a module specifier</span> given <var>moduleScript</var>'s <span
data-x="concept-script-base-url">base URL</span> and <var>specifier</var>.</p></li>

<li><p>If <var>url</var> is failure, then throw a <code>TypeError</code> exception.</p></li>

<li><p>Return the <span data-x="concept-url-serializer">serialization</span> of
<var>url</var>.</p></li>
</ol>
</li>

<li><p>Let <var>resolveFunction</var> be ! <span>CreateBuiltinFunction</span>(<var>steps</var>, 1,
"<code data-x="">resolve</code>", « »).</p></li>

<li><p>Return « Record { [[Key]]: "<dfn><code data-x="import-meta-url">url</code></dfn>",
[[Value]]: <var>urlString</var> }, Record { [[Key]]: "<dfn><code
data-x="import-meta-resolve">resolve</code></dfn>", [[Value]]: <var>resolveFunction</var> }
».</p></li>
</ol>

<h6><dfn>HostImportModuleDynamically</dfn>(<var>referencingScriptOrModule</var>,
Expand Down