Stage 1 Draft / July 25, 2017

ECMAScript export ns from

Introduction

This proposal adds a new form of "export from" which exports another module's namespace exotic object as an exported name of another, filling a use case similar to the use cases for existing "export from" forms.

See the proposal repository for motivations and more information.

Note 1

This proposal is closely related to the export default from proposal.

Note 2

This spec proposal is written as a diff against the existing ECMAScript specification.

1ECMAScript Language: Scripts and Modules

Note
This is Chapter 15 in the current spec.

1.1Modules

1.1.1Module Semantics

1.1.1.1Source Text Module Records

Note

Table 42 gives examples of the ExportEntry record fields used to represent the syntactic export forms:

Table 1 (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
export * as ns from "mod"; null "mod" "*" "ns"

1.1.2Exports

Syntax

ExportDeclaration:exportVariableStatement exportDeclaration exportdefaultHoistableDeclaration[Default] exportdefaultClassDeclaration[Default] exportdefault[lookahead ∉ { function, class }]AssignmentExpression[In]; ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; ExportFromClause:* NamedExports NameSpaceExport NameSpaceExport:*asIdentifierName ExportClause:{} {ExportsList} {ExportsList,} NamedExports:{} {ExportsList} {ExportsList,} Note
Renaming ExportClause to NamedExports reflects the similarly named NamedImports, and should be reflected throughout the spec.
ExportsList:ExportSpecifier ExportsList,ExportSpecifier ExportSpecifier:IdentifierName IdentifierNameasIdentifierName

1.1.2.1Static Semantics: BoundNames

ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports;
  1. Return a new empty List.

1.1.2.2Static Semantics: ExportedBindings

ExportDeclaration:exportExportClauseFromClause; export*FromClause; ExportDeclaration:exportExportFromClauseFromClause;
  1. Return a new empty List.

1.1.2.3Static Semantics: ExportedNames

ExportDeclaration:export*FromClause;
  1. Return a new empty List.
ExportDeclaration:exportExportClauseFromClause; exportExportClause;
  1. Return the ExportedNames of ExportClause.
ExportDeclaration:exportExportFromClauseFromClause;
  1. Return the ExportedNames of ExportFromClause.
ExportFromClause:*
  1. Return a new empty List.
ExportFromClause:NamedExports
  1. Return the ExportedNames of NamedExports.
ExportFromClause:NameSpaceExport
  1. Return the ExportedNames of NameSpaceExport.

1.1.2.4Static Semantics: ExportEntries

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:exportExportClauseFromClause;
  1. Let module be the sole element of ModuleRequests of FromClause.
  2. Return ExportEntriesForModule of ExportClause with argument module.
ExportDeclaration:exportExportFromClauseFromClause;
  1. Let module be the sole element of ModuleRequests of FromClause.
  2. Return ExportEntriesForModule of ExportFromClause with argument module.

1.1.2.5Static Semantics: ExportEntriesForModule

With parameter module.

ExportFromClause:*
  1. Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: null }.
NameSpaceExport:*asIdentifierName
  1. Let exportName be the StringValue of IdentifierName.
  2. Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: null, [[ExportName]]: _exportName_ }.

1.1.2.6Static Semantics: IsConstantDeclaration

ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; exportdefaultAssignmentExpression; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; exportdefaultAssignmentExpression;
  1. Return false.

1.1.2.7Static Semantics: LexicallyScopedDeclarations

ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; exportVariableStatement ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; exportVariableStatement
  1. Return a new empty List.

1.1.2.8Static Semantics: ModuleRequests

ExportDeclaration:export*FromClause; ExportDeclaration:exportExportClauseFromClause; ExportDeclaration:exportExportFromClauseFromClause;
  1. Return the ModuleRequests of FromClause.

1.1.2.9Runtime Semantics: Evaluation

ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports;
  1. Return NormalCompletion(empty).