15 ECMAScript Language: Scripts and Modules
September 22, 2015 · View on GitHub
Note: This document is written as a delta against the ES6 RC4 specification. Headers illustrate the location in the specification. The use of ins and
delillustrate addition and removal to existing sections. Shaded blocks followed by content indicates an existing portion of content to be replaced by the followed content. Unadorned content is new or contextually unalterned. Omitted content should be assumed irrelevant to this proposal unless otherwise noted.
15 ECMAScript Language: Scripts and Modules
15.2 Modules
15.2.1 Module Semantics
15.2.1.15 Source Text Module Records
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 v from "mod"; | "v" | "mod" | "default" | null |
export * as ns from "mod"; | "ns" | "mod" | "*" | null |
export {x} from "mod"; | "x" | "mod" | "x" | null |
export {v as x} from "mod"; | "x" | "mod" | "v" | null |
export * from "mod"; | null | "mod" | "*" | null |
15.2.3 Exports
Syntax
Note: ExportClause has been renamed to NamedExports for clarity and symmetry with NamedImports. This rename should be reflected throughout the entire ECMA spec document, which this delta document does not fully cover.
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportClause;exportExportFromClause FromClause;exportNamedExports;exportVariableStatementexportDeclarationexportdefaultHoistableDeclaration[Default]exportdefaultClassDeclaration[Default]exportdefault[lookahead ∉ {function,class,from}] AssignmentExpression[In];
ExportFromClause :
*- ExportedDefaultBinding
- NameSpaceExport
- NamedExports
- ExportedDefaultBinding
,NameSpaceExport - ExportedDefaultBinding
,NamedExports
ExportedDefaultBinding :
- IdentifierName
NameSpaceExport :
*asIdentifierName
ExportClauseNamedExports :
{}{ExportsList}{ExportsList,}
ExportsList :
- ExportSpecifier
- ExportsList
,ExportSpecifier
ExportSpecifier :
- IdentifierName
- IdentifierName
asIdentifierName
15.2.3.2 Static Semantics: BoundNames
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportClause;exportExportFromClause FromClause;exportNamedExports;
- Return a new empty List.
15.2.3.3 Static Semantics: ExportedBindings
ExportDeclaration :
exportExportClause FromClause;export*FromClause;exportExportFromClause FromClause;
- Return a new empty List.
15.2.3.4 Static Semantics: ExportedNames
ExportDeclaration :
export*FromClause;
- Return a new empty List.
ExportDeclaration :
exportExportClause FromClause;
exportExportClause;
- Return the ExportedNames of ExportClause.
ExportDeclaration : export ExportFromClause FromClause ;
- Return the ExportedNames of ExportFromClause.
ExportFromClause : *
- Return a new empty List.
ExportFromClause : ExportedDefaultBinding , NameSpaceExport
- Let names be the ExportedNames of ExportedDefaultBinding.
- Append to names the elements of the ExportedNames of NameSpaceExport.
- Return names.
ExportFromClause : ExportedDefaultBinding , NamedExports
- Let names be the ExportedNames of ExportedDefaultBinding.
- Append to names the elements of the ExportedNames of NamedExports.
- Return names.
15.2.3.5 Static Semantics: ExportEntries
ExportDeclaration :
export*FromClause;
- Let module be the sole element of ModuleRequests of FromClause.
- Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: null }.
- Return a new List containing entry.
ExportDeclaration :
exportExportClause FromClause;
- Let module be the sole element of ModuleRequests of FromClause.
- Return ExportEntriesForModule of ExportClause with argument module.
ExportDeclaration : export ExportFromClause FromClause ;
- Let module be the sole element of ModuleRequests of FromClause.
- Return ExportEntriesForModule of ExportFromClause with argument module.
15.2.3.6 Static Semantics: ExportEntriesForModule
ExportFromClause : *
- Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: null }.
ExportFromClause : ExportedDefaultBinding , NameSpaceExport
- Let entries be ExportEntriesForModule of ExportedDefaultBinding with argument module.
- Append to entries the elements of the ExportEntriesForModule of NameSpaceExport with argument module.
- Return entries.
ExportFromClause : ExportedDefaultBinding , NamedExports
- Let entries be ExportEntriesForModule of ExportedDefaultBinding with argument module.
- Append to entries the elements of the ExportEntriesForModule of NamedExports with argument module.
- Return entries.
ExportedDefaultBinding : IdentifierName
- Let exportName be the StringValue of IdentifierName.
- Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "default", [[LocalName]]: null, [[ExportName]]: exportName }.
NameSpaceExport : * as IdentifierName
- Let exportName be the StringValue of IdentifierName.
- Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: exportName }.
15.2.3.7 Static Semantics: IsConstantDeclaration
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportClause;exportExportFromClause FromClause;exportNamedExports;exportdefaultAssignmentExpression;
- Return false.
15.2.3.8 Static Semantics: LexicallyScopedDeclarations
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportClause;exportExportFromClause FromClause;exportNamedExports;exportVariableStatement
- Return a new empty List.
15.2.3.9 Static Semantics: ModuleRequests
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportFromClause FromClause;
- Return the ModuleRequests of FromClause.
15.2.3.11 Runtime Semantics: Evaluation
ExportDeclaration :
export*FromClause;exportExportClause FromClause;exportExportClause;exportExportFromClause FromClause;exportNamedExports;
- Return NormalCompletion(empty).
Annex A (informative) Grammar Summary
A.5 Scripts and Modules
Note: See alterations in 15.2.3.