super unless the source code containing super is eval code that is being processed by a super within A Script Record encapsulates information about a script being evaluated. Each script record contains the fields listed in
| Field Name | Value Type | Meaning |
|---|---|---|
| [[Realm]] |
|
The |
| [[Environment]] |
|
The |
| [[ECMAScriptCode]] |
a |
The result of parsing the source text of this script using |
| [[HostDefined]] |
Any, default value is |
Field reserved for use by |
The abstract operation ParseScript takes arguments sourceText, realm, and hostDefined. It creates a
An implementation may parse script source text and analyse it for Early Error conditions prior to evaluation of ParseScript for that script source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseScript upon that source text.
The abstract operation ScriptEvaluation takes argument scriptRecord. It performs the following steps when called:
When an
The abstract operation GlobalDeclarationInstantiation takes arguments script (a
Early errors specified in
Unlike explicit var or function declarations, properties that are directly created on the
super.
The duplicate export default
The abstract operation ImportedLocalNames takes argument importEntries (a
A Module Record encapsulates structural information about the imports and exports of a single module. This information is used to link the imports and exports of sets of connected modules. A Module Record includes four fields that are only used when evaluating a module.
For specification purposes Module Record values are values of the
Module Record defines the fields listed in
| Field Name | Value Type | Meaning |
|---|---|---|
| [[Realm]] |
|
The |
| [[Environment]] |
|
The |
| [[Namespace]] |
Object | |
The Module Namespace Object ( |
| [[HostDefined]] |
Any, default value is |
Field reserved for use by |
| Method | Purpose |
|---|---|
| GetExportedNames([exportStarSet]) | Return a list of all names that are either directly or indirectly exported from this module. |
| ResolveExport(exportName [, resolveSet]) |
Return the binding of a name exported by this module. Bindings are represented by a ResolvedBinding Record, of the form { [[Module]]: Each time this operation is called with a specific exportName, resolveSet pair as arguments it must return the same result if it completes normally. |
| Link() |
Prepare the module for evaluation by transitively resolving all module dependencies and creating a |
| Evaluate() |
If this module has already been evaluated successfully, return Link must have completed successfully prior to invoking this method. |
A Cyclic Module Record is used to represent information about a module that can participate in dependency cycles with other modules that are subclasses of the
In addition to the fields defined in
| Field Name | Value Type | Meaning |
|---|---|---|
| [[Status]] |
|
Initially |
| [[EvaluationError]] |
An |
A completion of type |
| [[DFSIndex]] |
|
Auxiliary field used during Link and Evaluate only.
If [[Status]] is |
| [[DFSAncestorIndex]] |
|
Auxiliary field used during Link and Evaluate only. If [[Status]] is |
| [[RequestedModules]] |
|
A |
In addition to the methods defined in
| Method | Purpose |
|---|---|
|
|
Initialize the |
|
|
Evaluate the module's code within its |
The Link concrete method of a
The abstract operation InnerModuleLinking takes arguments module (a
The Evaluate concrete method of a
The abstract operation InnerModuleEvaluation takes arguments module (a
This non-normative section gives a series of examples of the linking and evaluation of a few common module graphs, with a specific focus on how errors can occur.
First consider the following simple module graph:
Let's first assume that there are no error conditions. When a
Consider then cases involving linking errors. If
Finally, consider a case involving evaluation errors. If
The difference here between linking and evaluation errors is due to how evaluation must be only performed once, as it can cause side effects; it is thus important to remember whether evaluation has already been performed, even if unsuccessfully. (In the error case, it makes sense to also remember the exception because otherwise subsequent Evaluate() calls would have to synthesize a new one.) Linking, on the other hand, is side-effect-free, and thus even if it fails, it can be retried at a later time with no issues.
Now consider a different type of error condition:
In this scenario, module A declares a dependency on some other module, but no
Lastly, consider a module graph with a cycle:
Here we assume that the entry point is module A, so that the
An analogous story occurs for the evaluation phase of a cyclic module graph, in the success case.
Now consider a case where A has an linking error; for example, it tries to import a binding from C that does not exist. In that case, the above steps still occur, including the early return from the second call to
Finally, consider a case where A has an evaluation error; for example, its source code throws an exception. In that case, the evaluation-time analog of the above steps still occurs, including the early return from the second call to
A Source Text Module Record is used to represent information about a module that was defined from ECMAScript source text (
A
In addition to the fields defined in
| Field Name | Value Type | Meaning |
|---|---|---|
| [[ECMAScriptCode]] |
a |
The result of parsing the source text of this module using |
| [[Context]] |
An ECMAScript |
The |
| [[ImportMeta]] | Object |
An object exposed through the import.meta meta property. It is |
| [[ImportEntries]] |
|
A |
| [[LocalExportEntries]] |
|
A |
| [[IndirectExportEntries]] |
|
A export * as namespace declarations.
|
| [[StarExportEntries]] |
|
A export * declarations that occur within the module, not including export * as namespace declarations.
|
An ImportEntry Record is a
| Field Name | Value Type | Meaning |
|---|---|---|
| [[ModuleRequest]] | String |
String value of the |
| [[ImportName]] | String |
The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. The value |
| [[LocalName]] | String | The name that is used to locally access the imported value from within the importing module. |
| Import Statement Form | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
|---|---|---|---|
import v from "mod";
|
|
|
|
import * as ns from "mod";
|
|
|
|
import {x} from "mod";
|
|
|
|
import {x as v} from "mod";
|
|
|
|
import "mod";
|
An |
||
An ExportEntry Record is a
| Field Name | Value Type | Meaning |
|---|---|---|
| [[ExportName]] | String | null | The name used to export this binding by this module. |
| [[ModuleRequest]] | String | null |
The String value of the |
| [[ImportName]] | String | null |
The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. |
| [[LocalName]] | String | null |
The name that is used to locally access the exported value from within the importing module. |
| Export Statement Form | [[ExportName]] | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
|---|---|---|---|---|
export var v;
|
|
|
|
|
export default function f() {}
|
|
|
|
|
export default function () {}
|
|
|
|
|
export default 42;
|
|
|
|
|
export {x};
|
|
|
|
|
export {v as x};
|
|
|
|
|
export {x} from "mod";
|
|
|
|
|
export {v as x} from "mod";
|
|
|
|
|
export * from "mod";
|
|
|
|
|
export * as ns from "mod";
|
|
|
|
|
The following definitions specify the required concrete methods and other
The abstract operation ParseModule takes arguments sourceText (ECMAScript source text), realm, and hostDefined. It creates a
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.
The GetExportedNames concrete method of a
GetExportedNames does not filter out or throw an exception for names that have ambiguous star export bindings.
The ResolveExport concrete method of a
ResolveExport attempts to resolve an imported binding to the actual defining module and local binding name. The defining module may be the module represented by the
If a defining module is found, a
This concrete method performs the following steps when called:
default export was not explicitly defined by this module.default export cannot be provided by an export * or export * from "mod" declaration.* import that includes the requested name.The InitializeEnvironment concrete method of a
The ExecuteModule concrete method of a
The import()
An example of when referencingScriptOrModule can be
<button type="button" onclick="import('./foo.mjs')">Click me</button>
there will be no import()
The implementation of HostResolveImportedModule must conform to the following requirements:
Multiple different referencingScriptOrModule, specifier pairs may map to the same
The import()
The implementation of HostImportModuleDynamically must conform to the following requirements:
The actual process performed is
The abstract operation FinishDynamicImport takes arguments referencingScriptOrModule, specifier, promiseCapability (a import()
The abstract operation GetModuleNamespace takes argument module. It retrieves the Module Namespace Object representing module's exports, lazily creating it the first time it was requested, and storing it in module.[[Namespace]] for future retrieval. It performs the following steps when called:
The only way GetModuleNamespace can throw is via one of the triggered
The value of a
With parameter module.
The above rule means that each
ExportedBindings are the locally bound names that are explicitly associated with a
ExportedNames are the externally visible names that a
With parameter module.