15 ECMAScript Language: Scripts and Modules

15.1 Scripts

Syntax

Script :
ScriptBodyopt
ScriptBody :
StatementList

15.1.1 Static Semantics: Early Errors

Script : ScriptBody
  • 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.

ScriptBody : StatementList
  • 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.

15.1.2 Static Semantics: IsStrict

ScriptBody : StatementList
  1. If the DirectivePrologue of StatementList contains a Use Strict Directive, return true; otherwise, return false.

15.1.3 Static Semantics: LexicallyDeclaredNames

See also: 13.2.5, 13.12.5, 13.13.6, 14.1.13, 14.2.10, 15.2.1.11.

ScriptBody : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.

NOTE At the top level of a Script, function declarations are treated like var declarations rather than like lexical declarations.

15.1.4 Static Semantics: LexicallyScopedDeclarations

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.

ScriptBody : StatementList
  1. Return TopLevelLexicallyScopedDeclarations of StatementList.

15.1.5 Static Semantics: VarDeclaredNames

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.

ScriptBody : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.

15.1.6 Static Semantics: VarScopedDeclarations

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.

ScriptBody : StatementList
  1. Return TopLevelVarScopedDeclarations of StatementList.

15.1.7 Runtime Semantics: ScriptEvaluation

With argument realm.

Script : ScriptBodyopt
  1. If ScriptBody is not present, return NormalCompletion(empty).
  2. Let globalEnv be realm.[[globalEnv]].
  3. Let scriptCxt be a new ECMAScript code execution context.
  4. Set the Function of scriptCxt to null.
  5. Set the Realm of scriptCxt to realm.
  6. Set the VariableEnvironment of scriptCxt to globalEnv.
  7. Set the LexicalEnvironment of scriptCxt to globalEnv.
  8. Suspend the currently running execution context.
  9. Push scriptCxt on to the execution context stack; scriptCxt is now the running execution context.
  10. Let result be GlobalDeclarationInstantiation(ScriptBody, globalEnv).
  11. If result.[[type]] is normal, then
    1. Let result be the result of evaluating ScriptBody.
  12. If result.[[type]] is normal and result.[[value]] is empty, then
    1. Let result be NormalCompletion(undefined).
  13. Suspend scriptCxt and remove it from the execution context stack.
  14. Assert: the execution context stack is not empty.
  15. Resume the context that is now on the top of the execution context stack as the running execution context.
  16. Return Completion(result).

15.1.8 Runtime Semantics: GlobalDeclarationInstantiation (script, env)

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.

  1. Let envRec be env's EnvironmentRecord.
  2. Assert: envRec is a global Environment Record.
  3. Let lexNames be the LexicallyDeclaredNames of script.
  4. Let varNames be the VarDeclaredNames of script.
  5. For each name in lexNames, do
    1. If envRec.HasVarDeclaration(name) is true, throw a SyntaxError exception.
    2. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError exception.
    3. Let hasRestrictedGlobal be envRec.HasRestrictedGlobalProperty(name).
    4. ReturnIfAbrupt(hasRestrictedGlobal).
    5. If hasRestrictedGlobal is true, throw a SyntaxError exception.
  6. For each name in varNames, do
    1. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError exception.
  7. Let varDeclarations be the VarScopedDeclarations of script.
  8. Let functionsToInitialize be an empty List.
  9. Let declaredFunctionNames be an empty List.
  10. For each d in varDeclarations, in reverse list order do
    1. If d is neither a VariableDeclaration or a ForBinding, then
      1. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
      2. NOTE If there are multiple FunctionDeclarations for the same name, the last declaration is used.
      3. Let fn be the sole element of the BoundNames of d.
      4. If fn is not an element of declaredFunctionNames, then
        1. Let fnDefinable be envRec.CanDeclareGlobalFunction(fn).
        2. If fnDefinable is false, throw TypeError exception.
        3. Append fn to declaredFunctionNames.
        4. Insert d as the first element of functionsToInitialize.
  11. Let declaredVarNames be an empty List.
  12. For each d in varDeclarations, do
    1. If d is a VariableDeclaration or a ForBinding, then
      1. For each String vn in the BoundNames of d, do
        1. If vn is not an element of declaredFunctionNames, then
          1. Let vnDefinable be envRec.CanDeclareGlobalVar(vn).
          2. ReturnIfAbrupt(vnDefinable).
          3. If vnDefinable is false, throw TypeError exception.
          4. If vn is not an element of declaredVarNames, then
            1. Append vn to declaredVarNames.
  13. NOTE: No abnormal terminations occur after this algorithm step if the global object is an ordinary object. However, if the global object is a Proxy exotic object it may exhibit behaviours that cause abnormal terminations in some of the following steps.
  14. Let lexDeclarations be the LexicallyScopedDeclarations of script.
  15. For each element d in lexDeclarations do
    1. NOTE Lexically declared names are only instantiated here but not initialized.
    2. For each element dn of the BoundNames of d do
      1. If IsConstantDeclaration of d is true, then
        1. Let status be envRec.CreateImmutableBinding(dn, true).
      2. Else,
        1. Let status be envRec.CreateMutableBinding(dn, false).
      3. ReturnIfAbrupt(status).
  16. For each production f in functionsToInitialize, do
    1. Let fn be the sole element of the BoundNames of f.
    2. Let fo be the result of performing InstantiateFunctionObject for f with argument env.
    3. Let status be envRec.CreateGlobalFunctionBinding(fn, fo, false).
    4. ReturnIfAbrupt(status).
  17. For each String vn in declaredVarNames, in list order do
    1. Let status be envRec.CreateGlobalVarBinding(vn, false).
    2. ReturnIfAbrupt(status).
  18. Return NormalCompletion(empty)

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.

15.1.9 Runtime Semantics: ScriptEvaluationJob ( sourceText )

The job ScriptEvaluationJob with parameter sourceText parses, validates, and evaluates sourceText as a Script.

  1. Assert: sourceText is an ECMAScript source text (see clause 10).
  2. Parse sourceText using Script as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let code be the resulting parse tree. Otherwise, let code be an indication of one or more parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parse or early error is present, the number and ordering of reported errors is implementation dependent but at least one error must be reported.
  3. If code is an error indication, then
    1. Report or log the error(s) in an implementation dependent manner.
    2. Let status be NormalCompletion(undefined).
  4. Else,
    1. Let realm be the running execution context's Realm.
    2. Let status be the result of ScriptEvaluation of code with argument realm.
  5. NextJob Completion(status).

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.

15.2 Modules

Syntax

Module :
ModuleBodyopt
ModuleBody :
ModuleItemList
ModuleItemList :
ModuleItem
ModuleItemList ModuleItem
ModuleItem :
ImportDeclaration
ExportDeclaration
StatementListItem

15.2.1 Module Semantics

15.2.1.1 Static Semantics: Early Errors

ModuleBody : ModuleItemList
  • 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.

15.2.1.2 Static Semantics: ContainsDuplicateLabels

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.

ModuleItemList : ModuleItemList ModuleItem
  1. Let hasDuplicates be ContainsDuplicateLabels of ModuleItemList with argument labelSet.
  2. If hasDuplicates is true return true.
  3. Return ContainsDuplicateLabels of ModuleItem with argument labelSet.
ModuleItem :
ImportDeclaration
ExportDeclaration
  1. Return false.

15.2.1.3 Static Semantics: ContainsUndefinedBreakTarget

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.

ModuleItemList : ModuleItemList ModuleItem
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of ModuleItemList with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of ModuleItem with argument labelSet.
ModuleItem :
ImportDeclaration
ExportDeclaration
  1. Return false.

15.2.1.4 Static Semantics: ContainsUndefinedContinueTarget

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.

ModuleItemList : ModuleItemList ModuleItem
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of ModuleItemList with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of ModuleItem with arguments iterationSet and « ».
ModuleItem :
ImportDeclaration
ExportDeclaration
  1. Return false.

15.2.1.5 Static Semantics: ExportedBindings

See also: 15.2.3.3.

NOTE ExportedBindings are the locally bound names that are explicitly associated with a Module’s ExportedNames.

ModuleItemList : ModuleItemList ModuleItem
  1. Let names be ExportedBindings of ModuleItemList.
  2. Append to names the elements of the ExportedBindings of ModuleItem.
  3. Return names.
ModuleItem :
ImportDeclaration
StatementListItem
  1. Return a new empty List.

15.2.1.6 Static Semantics: 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.

ModuleItemList : ModuleItemList ModuleItem
  1. Let names be ExportedNames of ModuleItemList.
  2. Append to names the elements of the ExportedNames of ModuleItem.
  3. Return names.
ModuleItem : ExportDeclaration
  1. Return the ExportedNames of ExportDeclaration.
ModuleItem :
ImportDeclaration
StatementListItem
  1. Return a new empty List.

15.2.1.7 Static Semantics: ExportEntries

See also: 15.2.3.5.

Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let entries be ExportEntries of ModuleItemList.
  2. Append to entries the elements of the ExportEntries of ModuleItem.
  3. Return entries.
ModuleItem :
ImportDeclaration
StatementListItem
  1. Return a new empty List.

15.2.1.8 Static Semantics: ImportEntries

See also: 15.2.2.3.

Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let entries be ImportEntries of ModuleItemList.
  2. Append to entries the elements of the ImportEntries of ModuleItem.
  3. Return entries.
ModuleItem :
ExportDeclaration
StatementListItem
  1. Return a new empty List.

15.2.1.9 Static Semantics: ImportedLocalNames ( importEntries )

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:

  1. Let localNames be a new empty List.
  2. For each ImportEntry Record i in importEntries, do
    1. Append i.[[LocalName]] to localNames.
  3. Return localNames.

15.2.1.10 Static Semantics: ModuleRequests

See also: 15.2.2.5,15.2.3.9.

Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItem
  1. Return ModuleRequests of ModuleItem.
ModuleItemList : ModuleItemList ModuleItem
  1. Let moduleNames be ModuleRequests of ModuleItemList.
  2. Let additionalNames be ModuleRequests of ModuleItem.
  3. Append to moduleNames each element of additionalNames that is not already an element of moduleNames.
  4. Return moduleNames.
ModuleItem : StatementListItem
  1. Return a new empty List.

15.2.1.11 Static Semantics: LexicallyDeclaredNames

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.

ModuleItemList : ModuleItemList ModuleItem
  1. Let names be LexicallyDeclaredNames of ModuleItemList.
  2. Append to names the elements of the LexicallyDeclaredNames of ModuleItem.
  3. Return names.
ModuleItem : ImportDeclaration
  1. Return the BoundNames of ImportDeclaration.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return a new empty List.
  2. Return the BoundNames of ExportDeclaration.
ModuleItem : StatementListItem
  1. Return LexicallyDeclaredNames of StatementListItem.

NOTE 2 At the top level of a Module, function declarations are treated like lexical declarations rather than like var declarations.

15.2.1.12 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.3.8.

Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations be LexicallyScopedDeclarations of ModuleItemList.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of ModuleItem.
  3. Return declarations.
ModuleItem : ImportDeclaration
  1. Return a new empty List.

15.2.1.13 Static Semantics: VarDeclaredNames

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.

Module : [empty]
  1. Return an empty List.

ModuleItemList : ModuleItemList ModuleItem

  1. Let names be VarDeclaredNames of ModuleItemList.
  2. Append to names the elements of the VarDeclaredNames of ModuleItem.
  3. Return names.
ModuleItem : ImportDeclaration
  1. Return an empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return BoundNames of ExportDeclaration.
  2. Return a new empty List.

15.2.1.14 Static Semantics: VarScopedDeclarations

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.

Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations be VarScopedDeclarations of ModuleItemList.
  2. Append to declarations the elements of the VarScopedDeclarations of ModuleItem.
  3. Return declarations.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return VarScopedDeclarations of VariableStatement.
  2. Return a new empty List.

15.2.1.15 Abstract Module Records

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.

Table 36 — Module Record Fields
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.
Table 37 — Abstract Methods of Module Records
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.

15.2.1.16 Source Text Module Records

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.

Table 38 — Additional Fields of Source Text Module Records
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:

Table 39 — ImportEntry Record Fields
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:

Table 40 (Informative) — Import Forms Mappings to ImportEntry Records

Import Statement Form

[[ModuleRequest]]

[[ImportName]]

[[LocalName]]

import v from "mod";

"mod"

"default"

"v"

import * as ns from "mod";

"mod"

"*"

"ns"

import {x} from "mod";

"mod"

"x"

"x"

import {x as v} from "mod";

"mod"

"x"

"v"

import "mod";

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:

Table 41 — ExportEntry Record Fields
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:

Table 42 (Informative) — Export Forms Mappings to ExportEntry Records

Export Statement Form

[[ExportName]]

[[ModuleRequest]]

[[ImportName]]

[[LocalName]]

export var v;

"v"

null

null

"v"

export default function f(){};

"default"

null

null

"f"

export default function(){};

"default"

null

null

"*default*"

export default 42;

"default"

null

null

"*default*"

export {x};

"x"

null

null

"x"

export {v as x};

"x"

null

null

"v"

export {x} from "mod";

"x"

"mod"

"x"

null

export {v as x} from "mod";

"x"

"mod"

"v"

null

export * from "mod";

null

"mod"

"*"

null

The following definitions specify the required concrete methods and other abstract operations for Source Text Module Records

15.2.1.16.1 Runtime Semantics: ParseModule ( sourceText )

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:

  1. Assert: sourceText is an ECMAScript source text (see clause 10).
  2. Parse sourceText using Module as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let body be the resulting parse tree. Otherwise, let body be an indication of one or more parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parse or early error is present, the number and ordering of reported errors is implementation dependent but at least one error must be reported.
  3. If body is an abrupt completion or error indication, then
    1. Throw a SyntaxError exception.
  4. Let requestedModules be the ModuleRequests of body.
  5. Let importEntries be ImportEntries of body.
  6. Let importedBoundNames be ImportedLocalNames(importEntries).
  7. Let indirectExportEntries be a new empty List.
  8. Let localExportEntries be a new empty List.
  9. Let starExportEntries be a new empty List.
  10. Let exportEntries be ExportEntries of body.
  11. For each record ee in exportEntries, do
    1. If ee.[[ModuleRequest]] is null, then
      1. If ee.[[LocalName]] is not an element of importedBoundNames, then
        1. Append ee to localExportEntries.
      2. Else
        1. Let ie be the element of importEntries whose [[LocalName]] is the same as ee.[[LocalName]].
        2. If ie.[[ImportName]] is "*", then
          1. Assert: this is a re-export of an imported module namespace object.
          2. Append ee to localExportEntries.
        3. Else, this is a re-export of a single name
          1. Append to indirectExportEntries the Record {[[ModuleRequest]]: ie.[[ModuleRequest]], [[ImportName]]: ie.[[ImportName]], [[LocalName]]: null, [[ExportName]]: ee.[[ExportName]] }.
    2. Else, if ee.[[ImportName]] is "*", then
      1. Append ee to starExportEntries.
    3. Else,
      1. Append ee to indirectExportEntries.
  12. Return Source Text Module Record {[[Realm]]: undefined, [[Environment]]: undefined, [[Namespace]]: undefined, [[Evaluated]]: false, [[ECMAScriptCode]]: body, [[RequestedModules]]: requestedModules, [[ImportEntries]]: importEntries, [[LocalExportEntries]]: localExportEntries, [[StarExportEntries]]: starExportEntries, [[IndirectExportEntries]]: indirectExportEntries}.

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.

15.2.1.16.2 GetExportedNames( exportStarSet ) Concrete Method

The GetExportedNames concrete method of a Source Text Module Record with argument exportStarSet performs the following steps:

  1. Let module be this Source Text Module Record.
  2. If exportStarSet contains module, then
    1. Assert: We’ve reached the starting point of an import * circularity.
    2. Return a new empty List.
  3. Append module to exportStarSet.
  4. Let exportedNames be a new empty List.
  5. For each ExportEntry Record e in module.[[LocalExportEntries]], do
    1. Assert: module provides the direct binding for this export.
    2. Append e.[[ExportName]] to exportedNames.
  6. For each ExportEntry Record e in module.[[IndirectExportEntries]], do
    1. Assert: module imports a specific binding for this export.
    2. Append e.[[ExportName]] to exportedNames.
  7. For each ExportEntry Record e in module.[[StarExportEntries]], do
    1. Let requestedModule be HostResolveImportedModule(module, e.[[ModuleRequest]]).
    2. ReturnIfAbrupt(requestedModule).
    3. Let starNames be requestedModule.GetExportedNames(exportStarSet).
    4. For each element n of starNames, do
      1. If SameValue(n, "default") is false, then
        1. If n is not an element of exportedNames, then
          1. Append n to exportedNames.
  8. Return exportedNames.

NOTE GetExportedNames does not filter out or throw an exception for names that have ambiguous star export bindings.

15.2.1.16.3 ResolveExport( exportName, resolveSet, exportStarSet ) Concrete Method

The ResolveExport concrete method of a Source Text Module Record with arguments exportName, resolveSet, and exportStarSet performs the following steps:

  1. Let module be this Source Text Module Record.
  2. For each Record {[[module]], [[exportName]]} r in resolveSet, do:
    1. If module and r.[[module]] are the same Module Record and SameValue(exportName, r.[[exportName]]) is true, then
      1. Assert: this is a circular import request.
      2. Return null.
  3. Append the Record {[[module]]: module, [[exportName]]: exportName} to resolveSet.
  4. For each ExportEntry Record e in module.[[LocalExportEntries]], do
    1. If SameValue(exportName, e.[[ExportName]]) is true, then
      1. Assert: module provides the direct binding for this export.
      2. Return Record{[[module]]: module, [[bindingName]]: e.[[LocalName]]}.
  5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do
    1. If SameValue(exportName, e.[[ExportName]]) is true, then
      1. Assert: module imports a specific binding for this export.
      2. Let importedModule be HostResolveImportedModule(module, e.[[ModuleRequest]]).
      3. ReturnIfAbrupt(importedModule).
      4. Let indirectResolution be importedModule.ResolveExport(e.[[ImportName]], resolveSet, exportStarSet).
      5. ReturnIfAbrupt(indirectResolution).
      6. If indirectResolution is not null, return indirectResolution.
  6. If SameValue(exportName, "default") is true, then
    1. Assert: A default export was not explicitly defined by this module.
    2. Throw a SyntaxError exception.
    3. NOTE A default export cannot be provided by an export *.
  7. If exportStarSet contains module, then return null.
  8. Append module to exportStarSet.
  9. Let starResolution be null.
  10. For each ExportEntry Record e in module.[[StarExportEntries]], do
    1. Let importedModule be HostResolveImportedModule(module, e.[[ModuleRequest]]).
    2. ReturnIfAbrupt(importedModule).
    3. Let resolution be importedModule.ResolveExport(exportName, resolveSet, exportStarSet).
    4. ReturnIfAbrupt(resolution).
    5. If resolution is "ambiguous", return "ambiguous".
    6. If resolution is not null, then
      1. If starResolution is null, let starResolution be resolution.
      2. Else
        1. Assert: there is more than one * import that includes the requested name.
        2. If resolution.[[module]] and starResolution.[[module]] are not the same Module Record or SameValue(resolution.[[exportName]], starResolution.[[exportName]]) is false, return "ambiguous".
  11. Return starResolution.

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.

15.2.1.16.4 ModuleDeclarationInstantiation( ) Concrete Method

The ModuleDeclarationInstantiation concrete method of a Source Text Module Record performs the following steps:

  1. Let module be this Source Text Module Record.
  2. Let realm be module.[[Realm]].
  3. Assert: realm is not undefined.
  4. Let code be module.[[ECMAScriptCode]].
  5. If module.[[Environment]] is not undefined, return NormalCompletion(empty).
  6. Let env be NewModuleEnvironment(realm.[[globalEnv]]).
  7. Set module.[[Environment]] to env.
  8. For each String required that is an element of module.[[RequestedModules]] do,
    1. NOTE: Before instantiating a module, all of the modules it requested must be available. An implementation may perform this test at any time prior to this point,
    2. Let requiredModule be HostResolveImportedModule(module, required).
    3. ReturnIfAbrupt(requiredModule).
    4. Let status be requiredModule.ModuleDeclarationInstantiation().
    5. ReturnIfAbrupt(status).
  9. For each ExportEntry Record e in module.[[IndirectExportEntries]], do
    1. Let resolution be module.ResolveExport(e.[[ExportName]], «‍ », «‍ »).
    2. ReturnIfAbrupt(resolution).
    3. If resolution is null or resolution is "ambiguous", throw a SyntaxError exception.
  10. Assert: all named exports from module are resolvable.
  11. Let envRec be env's EnvironmentRecord.
  12. For each ImportEntry Record in in module.[[ImportEntries]], do
    1. Let importedModule be HostResolveImportedModule(module, in.[[ModuleRequest]]).
    2. ReturnIfAbrupt(importedModule).
    3. If in.[[ImportName]] is "*", then
      1. Let namespace be GetModuleNamespace(importedModule).
      2. ReturnIfAbrupt(module).
      3. Let status be envRec.CreateImmutableBinding(in.[[LocalName]], true).
      4. Assert: status is not an abrupt completion.
      5. Call envRec.InitializeBinding(in.[[LocalName]], namespace).
    4. else,
      1. Let resolution be importedModule.ResolveExport(in.[[ImportName]], « », «‍ »).
      2. ReturnIfAbrupt(resolution).
      3. If resolution is null or resolution is "ambiguous", throw a SyntaxError exception.
      4. Call envRec.CreateImportBinding(in.[[LocalName]], resolution.[[module]], resolution.[[bindingName]]).
  13. Let varDeclarations be the VarScopedDeclarations of code.
  14. For each element d in varDeclarations do
    1. For each element dn of the BoundNames of d do
      1. Let status be envRec.CreateMutableBinding(dn, false).
      2. Assert: status is not an abrupt completion.
      3. Call envRec.InitializeBinding(dn, undefined).
  15. Let lexDeclarations be the LexicallyScopedDeclarations of code.
  16. For each element d in lexDeclarations do
    1. For each element dn of the BoundNames of d do
      1. If IsConstantDeclaration of d is true, then
        1. Let status be envRec.CreateImmutableBinding(dn, true).
      2. Else,
        1. Let status be envRec.CreateMutableBinding(dn, false).
      3. Assert: status is not an abrupt completion.
      4. If d is a GeneratorDeclaration production or a FunctionDeclaration production, then
        1. Let fo be the result of performing InstantiateFunctionObject for d with argument env.
        2. Call envRec.InitializeBinding(dn, fo).
  17. Return NormalCompletion(empty).

15.2.1.16.5 ModuleEvaluation() Concrete Method

The ModuleEvaluation concrete method of a Source Text Module Record performs the following steps:

  1. Let module be this Source Text Module Record.
  2. Assert: ModuleDeclarationInstantiation has already been invoked on module and successfully completed.
  3. Assert: module.[[Realm]] is not undefined.
  4. If module.[[Evaluated]] is true, return undefined.
  5. Set module.[[Evaluated]] to true.
  6. For each String required that is an element of module.[[RequestedModules]] do,
    1. Let requiredModule be HostResolveImportedModule(module, required).
    2. ReturnIfAbrupt(requiredModule).
    3. Let status be requiredModule.ModuleEvaluation().
    4. ReturnIfAbrupt(status).
  7. Let moduleCxt be a new ECMAScript code execution context.
  8. Set the Function of moduleCxt to null.
  9. Set the Realm of moduleCxt to module.[[Realm]].
  10. Assert: module has been linked and declarations in its module environment have been instantiated.
  11. Set the VariableEnvironment of moduleCxt to module.[[Environment]].
  12. Set the LexicalEnvironment of moduleCxt to module.[[Environment]].
  13. Suspend the currently running execution context.
  14. Push moduleCxt on to the execution context stack; moduleCxt is now the running execution context.
  15. Let result be the result of evaluating module.[[ECMAScriptCode]].
  16. Suspend moduleCxt and remove it from the execution context stack.
  17. Resume the context that is now on the top of the execution context stack as the running execution context.
  18. Return Completion(result).

15.2.1.17 Runtime Semantics: HostResolveImportedModule (referencingModule, specifier )

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.

15.2.1.18 Runtime Semantics: GetModuleNamespace( module )

The abstract operation GetModuleNamespace called with argument module performs the following steps:

  1. Assert: module is an instance of a concrete subclass of Module Record.
  2. Let namespace be module.[[Namespace]].
  3. If namespace is undefined, then
    1. Let exportedNames be module.GetExportedNames(« »).
    2. ReturnIfAbrupt(exportedNames).
    3. Let unambiguousNames be a new empty List.
    4. For each name that is an element of exportedNames,
      1. Let resolution be module.ResolveExport(name, « », « »).
      2. ReturnIfAbrupt(resolution).
      3. If resolution is null, throw a SyntaxError exception.
      4. If resolution is not "ambiguous", append name to unambiguousNames.
    5. Let namespace be ModuleNamespaceCreate(module, unambiguousNames).
  4. Return namespace.

15.2.1.19 Runtime Semantics: TopLevelModuleEvaluationJob ( sourceText)

A TopLevelModuleEvaluationJob with parameter sourceText is a job that parses, validates, and evaluates sourceText as a Module.

  1. Assert: sourceText is an ECMAScript source text (see clause 10).
  2. Let realm be the running execution context's Realm.
  3. Let m be ParseModule(sourceText).
  4. If m is an abrupt completion or any other implementation defined error indication, then
    1. Report or log the error(s) in an implementation dependent manner.
    2. NextJob NormalCompletion(undefined).
  5. Set m.[[Realm]] to realm.
  6. Let status be m.ModuleDeclarationInstantiation().
  7. If status is not an abrupt completion, then
    1. Assert: all dependencies of m have been transitively resolved and m is ready for evaluation.
    2. Let status be m.ModuleEvaluation().
  8. NextJob Completion(status).

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.

15.2.1.20 Runtime Semantics: Evaluation

Module : [empty]
  1. Return NormalCompletion(undefined).
ModuleBody : ModuleItemList
  1. Let result be the result of evaluating ModuleItemList.
  2. If result.[[type]] is normal and result.[[value]] is empty, then
    1. Return NormalCompletion(undefined).
  3. Return Completion(result).
ModuleItemList : ModuleItemList ModuleItem
  1. Let sl be the result of evaluating ModuleItemList.
  2. ReturnIfAbrupt(sl).
  3. Let s be the result of evaluating ModuleItem.
  4. Return Completion(UpdateEmpty(s, sl.[[value]])).

NOTE The value of a ModuleItemList is the value of the last value producing item in the ModuleItemList.

ModuleItem : ImportDeclaration
  1. Return NormalCompletion(empty).

15.2.2 Imports

Syntax

ImportDeclaration :
import ImportClause FromClause ;
import ModuleSpecifier ;
ImportClause :
ImportedDefaultBinding
NameSpaceImport
NamedImports
ImportedDefaultBinding , NameSpaceImport
ImportedDefaultBinding , NamedImports
ImportedDefaultBinding :
ImportedBinding
NameSpaceImport :
* as ImportedBinding
NamedImports :
{ }
{ ImportsList }
{ ImportsList , }
FromClause :
from ModuleSpecifier
ImportsList :
ImportSpecifier
ImportsList , ImportSpecifier
ImportSpecifier :
ImportedBinding
IdentifierName as ImportedBinding
ModuleSpecifier :
StringLiteral
ImportedBinding :
BindingIdentifier

15.2.2.1 Static Semantics: Early Errors

ModuleItem : ImportDeclaration
  • It is a Syntax Error if the BoundNames of ImportDeclaration contains any duplicate entries.

15.2.2.2 Static Semantics: BoundNames

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.

ImportDeclaration : import ImportClause FromClause ;
  1. Return the BoundNames of ImportClause.
ImportDeclaration : import ModuleSpecifier ;
  1. Return a new empty List.
ImportClause : ImportedDefaultBinding , NameSpaceImport
  1. Let names be the BoundNames of ImportedDefaultBinding.
  2. Append to names the elements of the BoundNames of NameSpaceImport.
  3. Return names.
ImportClause : ImportedDefaultBinding , NamedImports
  1. Let names be the BoundNames of ImportedDefaultBinding.
  2. Append to names the elements of the BoundNames of NamedImports.
  3. Return names.
NamedImports : { }
  1. Return a new empty List.
ImportsList : ImportsList , ImportSpecifier
  1. Let names be the BoundNames of ImportsList.
  2. Append to names the elements of the BoundNames of ImportSpecifier.
  3. Return names.
ImportSpecifier : IdentifierName as ImportedBinding
  1. Return the BoundNames of ImportedBinding.

15.2.2.3 Static Semantics: ImportEntries

See also: 15.2.1.8.

ImportDeclaration : import ImportClause FromClause ;
  1. Let module be the sole element of ModuleRequests of FromClause.
  2. Return ImportEntriesForModule of ImportClause with argument module.
ImportDeclaration : import ModuleSpecifier ;
  1. Return a new empty List.

15.2.2.4 Static Semantics: ImportEntriesForModule

With parameter module.

ImportClause : ImportedDefaultBinding , NameSpaceImport
  1. Let entries be ImportEntriesForModule of ImportedDefaultBinding with argument module.
  2. Append to entries the elements of the ImportEntriesForModule of NameSpaceImport with argument module.
  3. Return entries.
ImportClause : ImportedDefaultBinding , NamedImports
  1. Let entries be ImportEntriesForModule of ImportedDefaultBinding with argument module.
  2. Append to entries the elements of the ImportEntriesForModule of NamedImports with argument module.
  3. Return entries.

ImportedDefaultBinding : ImportedBinding

  1. Let localName be the sole element of BoundNames of ImportedBinding.
  2. Let defaultEntry be the Record {[[ModuleRequest]]: module, [[ImportName]]: "default", [[LocalName]]: localName }.
  3. Return a new List containing defaultEntry.
NameSpaceImport : * as ImportedBinding
  1. Let localName be the StringValue of ImportedBinding.
  2. Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: localName }.
  3. Return a new List containing entry.
NamedImports : { }
  1. Return a new empty List.
ImportsList : ImportsList , ImportSpecifier
  1. Let specs be the ImportEntriesForModule of ImportsList with argument module.
  2. Append to specs the elements of the ImportEntriesForModule of ImportSpecifier with argument module.
  3. Return specs.
ImportSpecifier : ImportedBinding
  1. Let localName be the sole element of BoundNames of ImportedBinding.
  2. Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: localName , [[LocalName]]: localName }.
  3. Return a new List containing entry.
ImportSpecifier : IdentifierName as ImportedBinding
  1. Let importName be the StringValue of IdentifierName.
  2. Let localName be the StringValue of ImportedBinding.
  3. Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: importName, [[LocalName]]: localName }.
  4. Return a new List containing entry.

15.2.2.5 Static Semantics: ModuleRequests

See also: 15.2.1.10,15.2.3.9.

ImportDeclaration : import ImportClause FromClause ;
  1. Return ModuleRequests of FromClause.
ModuleSpecifier : StringLiteral
  1. Return a List containing the StringValue of StringLiteral.

15.2.3 Exports

Syntax

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration[Default]
export default ClassDeclaration[Default]
export default [lookahead ∉ {function, class}] AssignmentExpression[In] ;
ExportClause :
{ }
{ ExportsList }
{ ExportsList , }
ExportsList :
ExportSpecifier
ExportsList , ExportSpecifier
ExportSpecifier :
IdentifierName
IdentifierName as IdentifierName

15.2.3.1 Static Semantics: Early Errors

ExportDeclaration : export 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.

15.2.3.2 Static Semantics: BoundNames

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.

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
  1. Return a new empty List.
ExportDeclaration : export VariableStatement
  1. Return the BoundNames of VariableStatement.
ExportDeclaration : export Declaration
  1. Return the BoundNames of Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Let declarationNames be the BoundNames of HoistableDeclaration.
  2. If declarationNames does not include the element "*default*", append "*default*" to declarationNames.
  3. Return declarationNames.
ExportDeclaration : export default ClassDeclaration
  1. Let declarationNames be the BoundNames of ClassDeclaration.
  2. If declarationNames does not include the element "*default*", append "*default*" to declarationNames.
  3. Return declarationNames.

ExportDeclaration : export default AssignmentExpression ;

  1. Return «"*default*"».

15.2.3.3 Static Semantics: ExportedBindings

See also: 15.2.1.5.

ExportDeclaration :
export ExportClause FromClause ;
export * FromClause ;
  1. Return a new empty List.
ExportDeclaration : export ExportClause ;
  1. Return the ExportedBindings of ExportClause.
ExportDeclaration : export VariableStatement
  1. Return the BoundNames of VariableStatement.
ExportDeclaration : export Declaration
  1. Return the BoundNames of Declaration.

ExportDeclaration : export default HoistableDeclaration
ExportDeclaration : export default ClassDeclaration
ExportDeclaration : export default AssignmentExpression ;

  1. Return the BoundNames of this ExportDeclaration.
ExportClause : { }
  1. Return a new empty List.
ExportsList : ExportsList , ExportSpecifier
  1. Let names be the ExportedBindings of ExportsList.
  2. Append to names the elements of the ExportedBindings of ExportSpecifier.
  3. Return names.
ExportSpecifier : IdentifierName
  1. Return a List containing the StringValue of IdentifierName.
ExportSpecifier : IdentifierName as IdentifierName
  1. Return a List containing the StringValue of the first IdentifierName.

15.2.3.4 Static Semantics: ExportedNames

See also: 15.2.1.6.

ExportDeclaration : export * FromClause ;
  1. Return a new empty List.
ExportDeclaration :
export ExportClause FromClause ;
export ExportClause ;
  1. Return the ExportedNames of ExportClause.
ExportDeclaration : export VariableStatement
  1. Return the BoundNames of VariableStatement.
ExportDeclaration : export Declaration
  1. Return the BoundNames of Declaration.

ExportDeclaration : export default HoistableDeclaration
ExportDeclaration : export default ClassDeclaration
ExportDeclaration : export default AssignmentExpression ;

  1. Return «"default"».
ExportClause : { }
  1. Return a new empty List.
ExportsList : ExportsList , ExportSpecifier
  1. Let names be the ExportedNames of ExportsList.
  2. Append to names the elements of the ExportedNames of ExportSpecifier.
  3. Return names.
ExportSpecifier : IdentifierName
  1. Return a List containing the StringValue of IdentifierName.
ExportSpecifier : IdentifierName as IdentifierName
  1. Return a List containing the StringValue of the second IdentifierName.

15.2.3.5 Static Semantics: ExportEntries

See also: 15.2.1.7.

ExportDeclaration : export * FromClause ;
  1. Let module be the sole element of ModuleRequests of FromClause.
  2. Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: null }.
  3. Return a new List containing entry.
ExportDeclaration : export ExportClause FromClause ;
  1. Let module be the sole element of ModuleRequests of FromClause.
  2. Return ExportEntriesForModule of ExportClause with argument module.
ExportDeclaration : export ExportClause ;
  1. Return ExportEntriesForModule of ExportClause with argument null.
ExportDeclaration : export VariableStatement
  1. Let entries be a new empty List.
  2. Let names be the BoundNames of VariableStatement.
  3. Repeat for each name in names,
    1. Append to entries the Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: name, [[ExportName]]: name }.
  4. Return entries.
ExportDeclaration : export Declaration
  1. Let entries be a new empty List.
  2. Let names be the BoundNames of Declaration.
  3. Repeat for each name in names,
    1. Append to entries the Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: name, [[ExportName]]: name }.
  4. Return entries.
ExportDeclaration : export default HoistableDeclaration
  1. Let names be BoundNames of HoistableDeclaration.
  2. Let localName be the sole element of names.
  3. Return a new List containing the Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: localName, [[ExportName]]: "default"}.
ExportDeclaration : export default ClassDeclaration
  1. Let names be BoundNames of ClassDeclaration.
  2. Let localName be the sole element of names.
  3. Return a new List containing the Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: localName, [[ExportName]]: "default"}.

ExportDeclaration : export default AssignmentExpression;

  1. Let entry be the Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: "*default*", [[ExportName]]: "default"}.
  2. Return a new List containing entry.

NOTE "*default*" is used within this specification as a synthetic name for anonymous default export values.

15.2.3.6 Static Semantics: ExportEntriesForModule

With parameter module.

ExportClause : { }
  1. Return a new empty List.
ExportsList : ExportsList , ExportSpecifier
  1. Let specs be the ExportEntriesForModule of ExportsList with argument module.
  2. Append to specs the elements of the ExportEntriesForModule of ExportSpecifier with argument module.
  3. Return specs.
ExportSpecifier : IdentifierName
  1. Let sourceName be the StringValue of IdentifierName.
  2. If module is null, then
    1. Let localName be sourceName.
    2. Let importName be null.
  3. Else
    1. Let localName be null.
    2. Let importName be sourceName.
  4. Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: importName, [[LocalName]]: localName, [[ExportName]]: sourceName }.
ExportSpecifier : IdentifierName as IdentifierName
  1. Let sourceName be the StringValue of the first IdentifierName.
  2. Let exportName be the StringValue of the second IdentifierName.
  3. If module is null, then
    1. Let localName be sourceName.
    2. Let importName be null.
  4. Else
    1. Let localName be null.
    2. Let importName be sourceName.
  5. Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: importName, [[LocalName]]: localName, [[ExportName]]: exportName }.

15.2.3.7 Static Semantics: IsConstantDeclaration

See also: 13.3.1.3, 14.1.10, 14.4.8, 14.5.7.

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export default AssignmentExpression ;
  1. Return false.

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.

15.2.3.8 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.1.12.

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
  1. Return a new empty List.
ExportDeclaration : export Declaration
  1. Return a new List containing DeclarationPart of Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Return a new List containing DeclarationPart of HoistableDeclaration.
ExportDeclaration : export default ClassDeclaration
  1. Return a new List containing ClassDeclaration.

ExportDeclaration : export default AssignmentExpression ;

  1. Return a new List containing this ExportDeclaration.

15.2.3.9 Static Semantics: ModuleRequests

See also: 15.2.1.10, 15.2.2.5.

ExportDeclaration : export * FromClause ;

ExportDeclaration : export ExportClause FromClause ;
  1. Return the ModuleRequests of FromClause.
ExportDeclaration :
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration
export default ClassDeclaration
export default AssignmentExpression ;
  1. Return a new empty List.

15.2.3.10 Static Semantics: ReferencedBindings

ExportClause : { }
  1. Return a new empty List.
ExportsList : ExportsList , ExportSpecifier
  1. Let names be the ReferencedBindings of ExportsList.
  2. Append to names the elements of the ReferencedBindings of ExportSpecifier.
  3. Return names.
ExportSpecifier : IdentifierName
  1. Return a List containing the IdentifierName.
ExportSpecifier : IdentifierName as IdentifierName
  1. Return a List containing the first IdentifierName.

15.2.3.11 Runtime Semantics: Evaluation

ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
  1. Return NormalCompletion(empty).
ExportDeclaration : export VariableStatement
  1. Return the result of evaluating VariableStatement.
ExportDeclaration : export Declaration
  1. Return the result of evaluating Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Return the result of evaluating HoistableDeclaration.
ExportDeclaration : export default ClassDeclaration
  1. Let value be the result of BindingClassDeclarationEvaluation of ClassDeclaration.
  2. ReturnIfAbrupt(value).
  3. Let className be the sole element of BoundNames of ClassDeclaration.
  4. If className is "*default*", then
    1. Let hasNameProperty be HasOwnProperty(value, "name").
    2. ReturnIfAbrupt(hasNameProperty).
    3. If hasNameProperty is false, perform SetFunctionName(value, "default").
    4. Let env be the running execution context's LexicalEnvironment.
    5. Let status be InitializeBoundName("*default*", value, env).
    6. ReturnIfAbrupt(status).
  5. Return NormalCompletion(empty).

ExportDeclaration : export default AssignmentExpression ;

  1. Let rhs be the result of evaluating AssignmentExpression.
  2. Let value be GetValue(rhs).
  3. ReturnIfAbrupt(value).
  4. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then
    1. Let hasNameProperty be HasOwnProperty(value, "name").
    2. ReturnIfAbrupt(hasNameProperty).
    3. If hasNameProperty is false, perform SetFunctionName(value, "default").
  5. Let env be the running execution context's LexicalEnvironment.
  6. Let status be InitializeBoundName("*default*", value, env).
  7. Return NormalCompletion(empty).