It is a Syntax Error if the LexicallyDeclaredNames of ScriptBody contains any duplicate entries.
It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList also occurs in the VarDeclaredNames of ScriptBody.
It is a Syntax Error if StatementList Contains super
unless the source code containing super
is eval code that is
being processed by a direct eval
that is contained in function code that is not the function code of an
ArrowFunction.
It is a Syntax Error if StatementList Contains NewTarget unless the source code containing NewTarget is eval code that is being processed by a direct eval
that is contained in
function code that is not the function code of an ArrowFunction.
It is a Syntax Error if ContainsDuplicateLabels of StatementList with argument « » is true.
It is a Syntax Error if ContainsUndefinedBreakTarget of StatementList with argument « » is true.
It is a Syntax Error if ContainsUndefinedContinueTarget of StatementList with arguments « » and « » is true.
See also: 13.2.5, 13.12.5, 13.13.6, 14.1.13, 14.2.10, 15.2.1.11.
NOTE At the top level of a Script, function declarations are treated like var declarations rather than like lexical declarations.
See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.2.1.12, 15.2.3.8.
See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.2.1.13.
See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.2.1.14.
With argument realm.
NOTE When an execution context is established for evaluating scripts, declarations are instantiated in the current global environment. Each global binding declared in the code is instantiated.
GlobalDeclarationInstantiation is performed as follows using arguments script and env. script is the ScriptBody for which the execution context is being established. env is the global lexical environment in which bindings are to be created.
NOTE Early errors specified in 15.1.1 prevent name conflicts between function/var declarations and let/const/class declarations as well as redeclaration of let/const/class bindings for declaration contained within a single Script. However, such conflicts and redeclarations that span more than one Script are detected as runtime errors during GlobalDeclarationInstantiation. If any such errors are detected, no bindings are instantiated for the script. However, if the global object is defined using Proxy exotic objects then the runtime tests for conflicting declarations may be unreliable resulting in an abrupt completion and some global declarations not being instantiated. If this occurs, the code for the Script is not evaluated.
Unlike explicit var or function declarations, properties that are directly created on the global object result in global bindings that may be shadowed by let/const/class declarations.
The job ScriptEvaluationJob with parameter sourceText parses, validates, and evaluates sourceText as a Script.
NOTE An implementation may parse a sourceText as a Script and analyze it for Early Error conditions prior to the execution of the ScriptEvaluationJob for that sourceText. However, the reporting of any errors must be deferred until the ScriptEvaluationJob is actually executed.
It is a Syntax Error if the LexicallyDeclaredNames of ModuleItemList contains any duplicate entries.
It is a Syntax Error if any element of the LexicallyDeclaredNames of ModuleItemList also occurs in the VarDeclaredNames of ModuleItemList.
It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
It is a Syntax Error if any element of the ExportedBindings of ModuleItemList does not also occur in either the VarDeclaredNames of ModuleItemList, or the LexicallyDeclaredNames of ModuleItemList.
It is a Syntax Error if ModuleItemList Contains super
.
It is a Syntax Error if ModuleItemList Contains NewTarget
It is a Syntax Error if ContainsDuplicateLabels of ModuleItemList with argument « » is true.
It is a Syntax Error if ContainsUndefinedBreakTarget of ModuleItemList with argument « » is true.
It is a Syntax Error if ContainsUndefinedContinueTarget of ModuleItemList with arguments « » and « » is true.
NOTE The duplicate ExportedNames rule implies that multiple export default
ExportDeclaration items within a ModuleBody is a Syntax Error. Additional
error conditions relating to conflicting or duplicate declarations are checked during module linking prior to evaluation
of a Module. If any such errors are detected the Module is not
evaluated.
With argument labelSet.
See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2.
With argument labelSet.
See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3.
With arguments iterationSet and labelSet.
See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4, 13.15.4.
See also: 15.2.3.3.
NOTE ExportedBindings are the locally bound names that are explicitly associated with a Module’s ExportedNames.
See also: 15.2.3.4.
NOTE ExportedNames are the externally visible names that a Module explicitly maps to one of its local name bindings.
See also: 15.2.3.5.
See also: 15.2.2.3.
The abstract operation ImportedLocalNames with argument importEntries creates a List of all of the local name bindings defined by a List of ImportEntry Records (see Table 39). ImportedLocalNames performs the following steps:
See also: 13.2.5, 13.12.5, 13.13.6, 14.1.13, 14.2.10, 15.1.3.
NOTE 1 The LexicallyDeclaredNames of a Module includes the names of all of its imported bindings.
export
VariableStatement, return a new empty List.NOTE 2 At the top level of a Module, function declarations are treated like lexical declarations rather than like var declarations.
See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.3.8.
See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5.
ModuleItemList : ModuleItemList ModuleItem
export
VariableStatement, return BoundNames of
ExportDeclaration.See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6.
export
VariableStatement, return VarScopedDeclarations of
VariableStatement.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 Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with concrete subclasses. This specification only defines a single Module Record concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.
Module Record defines the fields listed in Table 36. All Module Definition subclasses include at least those fields. Module Record also defines the abstract method list in Table 37. All Module definition subclasses must provide concrete implementations of these abstract methods.
Field Name | Value Type | Meaning |
---|---|---|
[[Realm]] | Realm Record | undefined | The Realm within which this module was created. undefined if not yet assigned. |
[[Environment]] | Lexical Environment | undefined | The Lexical Environment containing the top level bindings for this module. This field is set when the module is instantiated. |
[[Namespace]] | Object | undefined | The Module Namespace Object (26.3) if one has been created for this module. Otherwise undefined. |
[[Evaluated]] | Boolean | Initially false, true if evaluation of this module has started. Remains true when evaluation completes, even if it is an abrupt completion. |
Method | Purpose |
---|---|
GetExportedNames(exportStarSet) | Return a list of all names that are either directly or indirectly exported from this module. |
ResolveExport(exportName, resolveSet, exportStarSet) | Return the binding of a name exported by this modules. Bindings are represented by a Record of the form {[[module]]: Module Record, [[bindingName]]: String} |
ModuleDeclarationInstantiation() | Transitively resolve all module dependencies and create a module Environment Record for the module. |
ModuleEvaluation() |
Do nothing if this module has already been evaluated. Otherwise, transitively evaluate all module dependences of this module and then evaluate this module. ModuleDeclarationInstantiation must be completed prior to invoking this method. |
A Source Text Module Record is used to represent information about a module that was defined from ECMAScript source text (10) that was parsed using the goal symbol Module. Its fields contain digested information about the names that are imported by the module and its concrete methods use this digest to link, instantiate, and evaluate the module.
In addition to the fields, defined in Table 36, Source Text Module Records have the additional fields listed in Table 38. Each of these fields initially has the value undefined.
Field Name | Value Type | Meaning |
---|---|---|
[[ECMAScriptCode]] | a parse result | The result of parsing the source text of this module using Module as the goal symbol. |
[[RequestedModules]] | List of String | A List of all the ModuleSpecifier strings used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered. |
[[ImportEntries]] | List of ImportEntry Records | A List of ImportEntry records derived from the code of this module. |
[[LocalExportEntries]] | List of ExportEntry Records | A List of ExportEntry records derived from the code of this module that correspond to declarations that occur within the module. |
[[IndirectExportEntries]] | List of ExportEntry Records | A List of ExportEntry records derived from the code of this module that correspond to reexported imports that occur within the module. |
[[StarExportEntries]] | List of ExportEntry Records | A List of ExportEntry records derived from the code of this module that correspond to export * declarations that occur within the module. |
An ImportEntry Record is a Record that digests information about a single declarative import. Each ImportEntry Record has the fields defined in Table 39:
Field Name | Value Type | Meaning |
---|---|---|
[[ModuleRequest]] | String | String value of the ModuleSpecifier of the ImportDeclaration. |
[[ImportName]] | String | The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. The value "*" indicates that the import request is for the target module's namespace object. |
[[LocalName]] | String | The name that is used to locally access the imported value from within the importing module. |
NOTE 1 Table 40 gives examples of ImportEntry records fields used to represent the syntactic import forms:
Import Statement Form |
[[ModuleRequest]] |
[[ImportName]] |
[[LocalName]] |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
An ImportEntry Record is not created. |
An ExportEntry Record is a Record that digests information about a single declarative export. Each ExportEntry Record has the fields defined in Table 41:
Field Name | Value Type | Meaning |
---|---|---|
[[ExportName]] | String | The name used to export this binding by this module. |
[[ModuleRequest]] | String | null | The String value of the ModuleSpecifier of the ExportDeclaration. null if the ExportDeclaration does not have a ModuleSpecifier. |
[[ImportName]] | String | null | The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. null if the ExportDeclaration does not have a ModuleSpecifier. "*" indicates that the export request is for all exported bindings. |
[[LocalName]] | String | null | The name that is used to locally access the exported value from within the importing module. null if the exported value is not locally accessible from within the module. |
NOTE 2 Table 42 gives examples of the ExportEntry record fields used to represent the syntactic export forms:
Export Statement Form |
[[ExportName]] |
[[ModuleRequest]] |
[[ImportName]] |
[[LocalName]] |
---|---|---|---|---|
|
|
null |
null |
|
|
|
null |
null |
|
|
|
null |
null |
|
|
|
null |
null |
|
|
|
null |
null |
|
|
|
null |
null |
|
|
|
|
|
null |
|
|
|
|
null |
|
null |
|
|
null |
The following definitions specify the required concrete methods and other abstract operations for Source Text Module Records
The abstract operation ParseModule with argument sourceText creates a Source Text Module Record based upon the result of parsing sourceText as a Module. ParseModule performs the following steps:
"*"
, then
"*"
, then
NOTE An implementation may parse module source text and analyze 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 Source Text Module Record with argument exportStarSet performs the following steps:
"default"
) is false, then
NOTE GetExportedNames does not filter out or throw an exception for names that have ambiguous star export bindings.
The ResolveExport concrete method of a Source Text Module Record with arguments exportName, resolveSet, and exportStarSet performs the following steps:
"default"
) is true, then
default
export was not explicitly defined by
this module.default
export cannot be provided by an export *
."ambiguous"
, return "ambiguous"
."ambiguous"
.NOTE 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 Module Record this method was invoked on or some other module that is imported by that module. The parameter resolveSet is use to detect unresolved circular import/export paths. If a pair consisting of specific Module Record and exportName is reached that is already in resolveSet, an import circularity has been encountered. Before recursively calling ResolveExport, a pair consisting of module and exportName is added to resolveSet.
If a defining module is found a Record {[[module]], [[bindingName]]} is returned. This record identifies the
resolved binding of the originally requested export. If no definition was found or the request is found to be
circular, null is returned. If the request is found to be ambiguous, the string
"ambiguous"
is returned.
The ModuleDeclarationInstantiation concrete method of a Source Text Module Record performs the following steps:
"ambiguous"
, throw a
SyntaxError exception."*"
, then
"ambiguous"
, throw a
SyntaxError exception.The ModuleEvaluation concrete method of a Source Text Module Record performs the following steps:
HostResolveImportedModule is an implementation defined abstract operation that provides the concrete Module Record subclass instance that corresponds to the ModuleSpecifier String, specifier, occurring within the context of the module represented by the Module Record referencingModule.
The implementation of HostResolveImportedModule must conform to the following requirements:
The normal return value must be an instance of a concrete subclass of Module Record.
If a Module Record corresponding to the pair referencingModule, specifier does not exist or cannot be created, an exception must be thrown.
This operation must be idempotent if it completes normally. Each time it is called with a specific referencingModule, specifier pair as arguments it must return the same Module Record instance.
Multiple different referencingModule, specifier pairs may map to the same Module Record instance. The actual mapping semantic is implementation defined but typically a normalization process is applied to specifier as part of the mapping process. A typical normalization process would include actions such as alphabetic case folding and expansion of relative and abbreviated path specifiers.
The abstract operation GetModuleNamespace called with argument module performs the following steps:
"ambiguous"
, append name to unambiguousNames.A TopLevelModuleEvaluationJob with parameter sourceText is a job that parses, validates, and evaluates sourceText as a Module.
NOTE An implementation may parse a sourceText as a Module, analyze it for Early Error conditions, and instantiate it prior to the execution of the TopLevelModuleEvaluationJob for that sourceText. An implementation may also resolve, pre-parse and pre-analyze, and pre-instantiate module dependencies of sourceText. However, the reporting of any errors detected by these actions must be deferred until the TopLevelModuleEvaluationJob is actually executed.
NOTE The value of a ModuleItemList is the value of the last value producing item in the ModuleItemList.
import
ImportClause FromClause ;
import
ModuleSpecifier ;
,
NameSpaceImport,
NamedImports*
as
ImportedBinding{
}
{
ImportsList }
{
ImportsList ,
}
from
ModuleSpecifier,
ImportSpecifieras
ImportedBindingIt is a Syntax Error if the BoundNames of ImportDeclaration contains any duplicate entries.
See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.3.2.
import
ImportClause FromClause ;
import
ModuleSpecifier ;
,
NameSpaceImport,
NamedImports{
}
,
ImportSpecifieras
ImportedBindingSee also: 15.2.1.8.
import
ImportClause FromClause ;
import
ModuleSpecifier ;
With parameter module.
,
NameSpaceImport,
NamedImportsImportedDefaultBinding : ImportedBinding
"default"
,
[[LocalName]]: localName }.*
as
ImportedBinding"*"
, [[LocalName]]:
localName }.{
}
,
ImportSpecifieras
ImportedBindingimport
ImportClause FromClause ;
export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclaration[Default]export
default
ClassDeclaration[Default]export
default
[lookahead ∉ {function
, class
}] AssignmentExpression[In] ;
{
}
{
ExportsList }
{
ExportsList ,
}
,
ExportSpecifieras
IdentifierNameexport
ExportClause ;
For each IdentifierName n in ReferencedBindings of ExportClause : It is
a
Syntax Error if
StringValue of
n is a ReservedWord
or if the StringValue of n is one of: "implements"
, "interface"
,
"let"
, "package"
, "private"
, "protected"
, "public"
,
"static"
, or "yield"
.
NOTE The above rule means that each ReferencedBindings of ExportClause is treated as an IdentifierReference.
See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2.
export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclaration"*default*"
, append "*default*"
to
declarationNames.export
default
ClassDeclaration"*default*"
, append "*default*"
to
declarationNames.ExportDeclaration : export default
AssignmentExpression
;
"*default*"
».See also: 15.2.1.5.
export
ExportClause FromClause ;
export
*
FromClause ;
export
ExportClause ;
export
VariableStatementexport
DeclarationExportDeclaration : export
default
HoistableDeclaration
ExportDeclaration : export
default
ClassDeclaration
ExportDeclaration : export
default
AssignmentExpression ;
{
}
,
ExportSpecifieras
IdentifierNameSee also: 15.2.1.6.
export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
DeclarationExportDeclaration : export
default
HoistableDeclaration
ExportDeclaration : export
default
ClassDeclaration
ExportDeclaration : export
default
AssignmentExpression ;
"default"
».{
}
,
ExportSpecifieras
IdentifierNameSee also: 15.2.1.7.
export
*
FromClause ;
"*"
, [[LocalName]]:
null, [[ExportName]]: null }.export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclaration"default"
}.export
default
ClassDeclaration"default"
}.ExportDeclaration : export default
AssignmentExpression;
"*default*"
, [[ExportName]]: "default"
}.NOTE "*default*"
is used within this specification as a synthetic name for
anonymous default export values.
With parameter module.
{
}
,
ExportSpecifieras
IdentifierNameSee also: 13.3.1.3, 14.1.10, 14.4.8, 14.5.7.
export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
default
AssignmentExpression ;
NOTE It is not necessary to treat export
default
AssignmentExpression as a constant declaration because there is no syntax that permits assignment to
the internal bound name used to reference a module's default object.
See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.1.12.
export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclarationexport
default
ClassDeclarationExportDeclaration : export default
AssignmentExpression
;
See also: 15.2.1.10, 15.2.2.5.
ExportDeclaration : export
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclarationexport
default
ClassDeclarationexport
default
AssignmentExpression ;
{
}
,
ExportSpecifieras
IdentifierNameexport
*
FromClause ;
export
ExportClause FromClause ;
export
ExportClause ;
export
VariableStatementexport
Declarationexport
default
HoistableDeclarationexport
default
ClassDeclaration"*default*"
, then
"name"
)."default"
)."*default*"
,
value, env).ExportDeclaration : export default
AssignmentExpression
;
"name"
)."default"
)."*default*"
,
value, env).