Stage 1 Draft / July 25, 2017

ECMAScript export default from

Introduction

This proposal adds a new form of "export from" which exports another module's default export 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 ns 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 v from "mod"; null "mod" "default" "v"

1.1.2Exports

Syntax

ExportDeclaration:exportVariableStatement exportDeclaration exportdefaultHoistableDeclaration[Default] exportdefaultClassDeclaration[Default] ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; exportdefault[lookahead ∉ { function, class }]AssignmentExpression[In]; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; exportdefault[lookahead ∉ { function, class, from }]AssignmentExpression[In]; ExportFromClause:* ExportedDefaultBinding NamedExports NameSpaceExport ExportedDefaultBinding,NamedExports ExportedDefaultBinding,NameSpaceExport ExportedDefaultBinding:IdentifierName Note 1
The addition of from to the lookahead after export default allows for the disambiguation of export default from "mod", which is the proposed syntactic form for exporting "mod"'s default export as this module's default export, from export default from, which is the potentially confusing export of a local named variable from.
Note 2
The NameSpaceExport is not explicitly part of this proposal, but part of the related export ns from proposal, shown here for how the two overlap should both proposals be accepted, the static semantics below also include this compound case. The remaining grammar changes are identical to the export ns from proposal.
ExportClause:{} {ExportsList} {ExportsList,} NamedExports:{} {ExportsList} {ExportsList,} Note 3
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

Note
This change is the same as proposed by export ns from.
ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports;
  1. Return a new empty List.

1.1.2.2Static Semantics: ExportedBindings

Note
This change is the same as proposed by export ns from.
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:ExportedDefaultBinding
  1. Return the ExportedNames of ExportedDefaultBinding.
ExportFromClause:ExportedDefaultBinding,NameSpaceExport
  1. Let names be the ExportedNames of ExportedDefaultBinding.
  2. Append to names the elements of the ExportedNames of NameSpaceExport.
  3. Return names.
ExportFromClause:ExportedDefaultBinding,NamedExports
  1. Let names be the ExportedNames of ExportedDefaultBinding.
  2. Append to names the elements of the ExportedNames of NamedExports.
  3. Return names.

1.1.2.4Static Semantics: ExportEntries

Note
This change is the same as proposed by export ns from.
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 }.
ExportedDefaultBinding:IdentifierName
  1. Let exportName be the StringValue of IdentifierName.
  2. Return a new List containing the Record {[[ModuleRequest]]: module, [[ImportName]]: "default", [[LocalName]]: null, [[ExportName]]: exportName }.
ExportFromClause:ExportedDefaultBinding,NameSpaceExport
  1. Let entries be ExportEntriesForModule of ExportedDefaultBinding with argument module.
  2. Append to entries the elements of the ExportEntriesForModule of NameSpaceExport with argument module.
  3. Return entries.
ExportFromClause:ExportedDefaultBinding,NamedExports
  1. Let entries be ExportEntriesForModule of ExportedDefaultBinding with argument module.
  2. Append to entries the elements of the ExportEntriesForModule of NamedExports with argument module.
  3. Return entries.

1.1.2.6Static Semantics: IsConstantDeclaration

Note
This change is the same as proposed by export ns from.
ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; exportdefaultAssignmentExpression; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; exportdefaultAssignmentExpression;
  1. Return false.

1.1.2.7Static Semantics: LexicallyScopedDeclarations

Note
This change is the same as proposed by export ns from.
ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; exportVariableStatement ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports; exportVariableStatement
  1. Return a new empty List.

1.1.2.8Static Semantics: ModuleRequests

Note
This change is the same as proposed by export ns from.
ExportDeclaration:export*FromClause; ExportDeclaration:exportExportClauseFromClause; ExportDeclaration:exportExportFromClauseFromClause;
  1. Return the ModuleRequests of FromClause.

1.1.2.9Runtime Semantics: Evaluation

Note
This change is the same as proposed by export ns from.
ExportDeclaration:export*FromClause; exportExportClauseFromClause; exportExportClause; ExportDeclaration:exportExportFromClauseFromClause; exportNamedExports;
  1. Return NormalCompletion(empty).