Skip to content

Commit

Permalink
extend metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 9, 2024
1 parent 1ed8d34 commit 8f6b183
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ Returns metadata about the modular structure of the module:
```ts
interface ModuleMetadata {
imports: Import[],
topLevelAwait: bool,
hasDynamicImport: bool,
hasImportMeta: bool,
hasTopLevelAwait: bool,
}
```
Expand All @@ -143,7 +145,10 @@ interface Import {
}
```
`topLevelAwait` is *true* if and only if there is usage of top-level await in the module.
* `hasDynamicImport` is *true* if and only if there is usage of dynamic import.
* `hasImportMeta` is *true* if and only if there is usage of import meta.
* `hasTopLevelAwait` is *true* if and only if there is usage of top-level await in the module.
### Dynamic Import
Expand Down
75 changes: 74 additions & 1 deletion spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,28 @@ contributors: Luca Casonato, Guy Bedford
Whether this module is individually asynchronous (for example, if it's a Source Text Module Record containing a top-level await). Having an asynchronous dependency does not mean this field is *true*. This field must not change after the module is parsed.
</td>
</tr>
<tr>
<td>
<ins>[[HasImportMeta]]</ins>
</td>
<td>
<ins>a Boolean</ins>
</td>
<td>
<ins>Whether this module contains an `import.meta` expression.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[HasDynamicImport]]</ins>
</td>
<td>
<ins>a Boolean</ins>
</td>
<td>
<ins>Whether this module contains a dynamic `import()` or phased dynamic import expression.</ins>
</td>
</tr>
<tr>
<td>
[[AsyncEvaluation]]
Expand Down Expand Up @@ -1254,7 +1276,9 @@ contributors: Luca Casonato, Guy Bedford
1. Append _import_ to _imports_.
1. Let _importsArray_ be CreateArrayFromList(_imports_).
1. Perform ! CreateDataPropertyOrThrow(_metadata_, *"imports"*, _importsArray_).
1. Perform ! CreateDataPropertyOrThrow(_metadata_, *"topLevelAwait"*, _module_.[[HasTLA]]).
1. Perform ! CreateDataPropertyOrThrow(_metadata_, *"hasDynamicImport"*, _module_.[[HasDynamicImport]]).
1. Perform ! CreateDataPropertyOrThrow(_metadata_, *"hasImportMeta"*, _module_.[[HasImportMeta]]).
1. Perform ! CreateDataPropertyOrThrow(_metadata_, *"hasTopLevelAwait"*, _module_.[[HasTLA]]).
1. Return _metadata_.
</emu-alg>
</emu-clause>
Expand All @@ -1263,6 +1287,55 @@ contributors: Luca Casonato, Guy Bedford
<emu-clause id="sec-source-text-module-records">
<h1>Source Text Module Records</h1>

<emu-clause id="sec-parsemodule" type="abstract operation">
<h1>
ParseModule (
_sourceText_: ECMAScript source text,
_realm_: a Realm Record,
_hostDefined_: anything,
): a Source Text Module Record or a non-empty List of *SyntaxError* objects
</h1>
<dl class="header">
<dt>description</dt>
<dd>It creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|.</dd>
</dl>
<emu-alg>
1. Let _body_ be ParseText(_sourceText_, |Module|).
1. If _body_ is a List of errors, return _body_.
1. Let _requestedModules_ be the ModuleRequests of _body_.
1. Let _importEntries_ be ImportEntries of _body_.
1. Let _importedBoundNames_ be ImportedLocalNames(_importEntries_).
1. Let _indirectExportEntries_ be a new empty List.
1. Let _localExportEntries_ be a new empty List.
1. Let _starExportEntries_ be a new empty List.
1. Let _exportEntries_ be ExportEntries of _body_.
1. For each ExportEntry Record _ee_ of _exportEntries_, do
1. If _ee_.[[ModuleRequest]] is *null*, then
1. If _importedBoundNames_ does not contain _ee_.[[LocalName]], then
1. Append _ee_ to _localExportEntries_.
1. Else,
1. Let _ie_ be the element of _importEntries_ whose [[LocalName]] is _ee_.[[LocalName]].
1. If _ie_.[[ImportName]] is ~namespace-object~, then
1. NOTE: This is a re-export of an imported module namespace object.
1. Append _ee_ to _localExportEntries_.
1. Else,
1. NOTE: This is a re-export of a single name.
1. Append the ExportEntry Record { [[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_.
1. Else if _ee_.[[ImportName]] is ~all-but-default~, then
1. Assert: _ee_.[[ExportName]] is *null*.
1. Append _ee_ to _starExportEntries_.
1. Else,
1. Append _ee_ to _indirectExportEntries_.
1. Let _async_ be _body_ Contains `await`.
1. <ins>Let _importMeta_ be _body_ Contains |ImportMeta|</ins>.
1. <ins>Let _dynamicImport_ be _body_ Contains |ImportCall|</ins>.
1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[ModuleSource]]: ~empty~, [[CycleRoot]]: ~empty~, [[HasTLA]]: _async_, <ins>[[HasImportMeta]]: _importMeta_, [[HasDynamicImport]]: _dynamicImport_, </ins>[[AsyncEvaluation]]: *false*, [[TopLevelCapability]]: ~empty~, [[AsyncParentModules]]: « », [[PendingAsyncDependencies]]: ~empty~, [[Status]]: ~new~, [[EvaluationError]]: ~empty~, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[Context]]: ~empty~, [[ImportMeta]]: ~empty~, [[RequestedModules]]: _requestedModules_, [[LoadedModules]]: « », [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSIndex]]: ~empty~, [[DFSAncestorIndex]]: ~empty~ }.
</emu-alg>
<emu-note>
<p>An implementation may parse module source text and analyse it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-source-text-module-record-getmodulesource" type="concrete method">
<h1>
GetModuleSource ( ): either a normal completion containing an Object or a throw completion
Expand Down

0 comments on commit 8f6b183

Please sign in to comment.