Skip to content

Commit

Permalink
Editorial: Re-factor ExportSpecifier (#637)
Browse files Browse the repository at this point in the history
In prior editions, the ExportSpecifier production was defined using only
IdentifierName. However, when the ExportSpecifier is part of an "local"
ExportDeclaration, the IdentifierName was interpreted as an
IdentifierReference through an Early Error rule. The rule was
undesirable for a number of reasons:

- it duplicated the definition of IdentifierReference
- it relied on an abstract operation, ReferencedBindings, which was
  otherwise unused
- it was not technically necessary (a separate Early Error rule for
  ModuleBody requires that all ExportedBindings are declared within the
  module itself, and it is not possible to create a such a binding)

These details made interpreting ExportSpecifier difficult and tended to
obscure the motivation for the use of IdentifierName.

Re-factor ExportSpecifier with a production parameter describing whether
it belongs to a "local" or "indirect" ExportDeclaration. This allows for
the definition of dedicated grammar productions, obviating the need for
an explicit early error, and removing branching logic from the static
semantics rule ExportEntriesForModule. It also more clearly communicates
the intent behind related definitions of the production.
  • Loading branch information
jugglinmike authored and bterlson committed Nov 23, 2016
1 parent 88a48ec commit 5d5fdab
Showing 1 changed file with 45 additions and 66 deletions.
111 changes: 45 additions & 66 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -21758,42 +21758,30 @@ <h2>Syntax</h2>
<emu-grammar>
ExportDeclaration :
`export` `*` FromClause `;`
`export` ExportClause FromClause `;`
`export` ExportClause `;`
`export` ExportClause[~Local] FromClause `;`
`export` ExportClause[+Local] `;`
`export` VariableStatement[~Yield, ~Await]
`export` Declaration[~Yield, ~Await]
`export` `default` HoistableDeclaration[~Yield, ~Await, +Default]
`export` `default` ClassDeclaration[~Yield, ~Await, +Default]
`export` `default` [lookahead &lt;! {`function`, `async` [no |LineTerminator| here] `function`, `class`}] AssignmentExpression[+In, ~Yield, ~Await] `;`

ExportClause :
ExportClause[Local] :
`{` `}`
`{` ExportsList `}`
`{` ExportsList `,` `}`

ExportsList :
ExportSpecifier
ExportsList `,` ExportSpecifier

ExportSpecifier :
IdentifierName
IdentifierName `as` IdentifierName
`{` ExportsList[?Local] `}`
`{` ExportsList[?Local] `,` `}`

ExportsList[Local] :
ExportSpecifier[?Local]
ExportsList[?Local] `,` ExportSpecifier[?Local]

ExportSpecifier[Local] :
[+Local] IdentifierReference
[+Local] IdentifierReference `as` IdentifierName
[~Local] IdentifierName
[~Local] IdentifierName `as` IdentifierName
</emu-grammar>

<!-- es6num="15.2.3.1" -->
<emu-clause id="sec-exports-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>ExportDeclaration : `export` ExportClause `;`</emu-grammar>
<ul>
<li>
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"`, or `"static"`.
</li>
</ul>
<emu-note>
<p>The above rule means that each ReferencedBindings of |ExportClause| is treated as an |IdentifierReference|.</p>
</emu-note>
</emu-clause>

<!-- es6num="15.2.3.2" -->
<emu-clause id="sec-exports-static-semantics-boundnames">
<h1>Static Semantics: BoundNames</h1>
Expand Down Expand Up @@ -21877,6 +21865,13 @@ <h1>Static Semantics: ExportedBindings</h1>
1. Append to _names_ the elements of the ExportedBindings of |ExportSpecifier|.
1. Return _names_.
</emu-alg>
<emu-grammar>
ExportSpecifier : IdentifierReference

ExportSpecifier : IdentifierReference `as` IdentifierName
<emu-alg>
1. Return a List containing the StringValue of |IdentifierReference|.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName</emu-grammar>
<emu-alg>
1. Return a List containing the StringValue of |IdentifierName|.
Expand Down Expand Up @@ -21931,7 +21926,15 @@ <h1>Static Semantics: ExportedNames</h1>
1. Append to _names_ the elements of the ExportedNames of |ExportSpecifier|.
1. Return _names_.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName</emu-grammar>
<emu-grammar>ExportSpecifier : IdentifierReference</emu-grammar>
<emu-alg>
1. Return a List containing the StringValue of |IdentifierReference|.
</emu-alg>
<emu-grammar>
ExportSpecifier : IdentifierReference `as` IdentifierName

ExportSpecifier : IdentifierName
</emu-grammar>
<emu-alg>
1. Return a List containing the StringValue of |IdentifierName|.
</emu-alg>
Expand Down Expand Up @@ -22012,28 +22015,27 @@ <h1>Static Semantics: ExportEntriesForModule</h1>
1. Append to _specs_ the elements of the ExportEntriesForModule of |ExportSpecifier| with argument _module_.
1. Return _specs_.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierReference</emu-grammar>
<emu-alg>
1. Let _sourceName_ be the StringValue of |IdentifierReference|.
1. Return a new List containing the Record {[[ModuleRequest]]: *null*, [[ImportName]]: *null*, [[LocalName]]: _sourceName_, [[ExportName]]: _sourceName_ }.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName</emu-grammar>
<emu-alg>
1. Let _sourceName_ be the StringValue of |IdentifierName|.
1. If _module_ is *null*, then
1. Let _localName_ be _sourceName_.
1. Let _importName_ be *null*.
1. Else,
1. Let _localName_ be *null*.
1. Let _importName_ be _sourceName_.
1. Return a new List containing the Record {[[ModuleRequest]]: _module_, [[ImportName]]: _importName_, [[LocalName]]: _localName_, [[ExportName]]: _sourceName_ }.
1. Return a new List containing the Record {[[ModuleRequest]]: _module_, [[ImportName]]: _sourceName_, [[LocalName]]: *null*, [[ExportName]]: _sourceName_ }.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierReference `as` IdentifierName</emu-grammar>
<emu-alg>
1. Let _localName_ be the StringValue of |IdentifierReference|.
1. Let _exportName_ be the StringValue of |IdentifierName|.
1. Return a new List containing the Record {[[ModuleRequest]]: *null*, [[ImportName]]: *null*, [[LocalName]]: _localName_, [[ExportName]]: _exportName_ }.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName `as` IdentifierName</emu-grammar>
<emu-alg>
1. Let _sourceName_ be the StringValue of the first |IdentifierName|.
1. Let _importName_ be the StringValue of the first |IdentifierName|.
1. Let _exportName_ be the StringValue of the second |IdentifierName|.
1. If _module_ is *null*, then
1. Let _localName_ be _sourceName_.
1. Let _importName_ be *null*.
1. Else,
1. Let _localName_ be *null*.
1. Let _importName_ be _sourceName_.
1. Return a new List containing the Record {[[ModuleRequest]]: _module_, [[ImportName]]: _importName_, [[LocalName]]: _localName_, [[ExportName]]: _exportName_ }.
1. Return a new List containing the Record {[[ModuleRequest]]: _module_, [[ImportName]]: _importName_, [[LocalName]]: *null*, [[ExportName]]: _exportName_ }.
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -22114,29 +22116,6 @@ <h1>Static Semantics: ModuleRequests</h1>
</emu-alg>
</emu-clause>

<!-- es6num="15.2.3.10" -->
<emu-clause id="sec-static-semantics-referencedbindings">
<h1>Static Semantics: ReferencedBindings</h1>
<emu-grammar>ExportClause : `{` `}`</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>ExportsList : ExportsList `,` ExportSpecifier</emu-grammar>
<emu-alg>
1. Let _names_ be the ReferencedBindings of |ExportsList|.
1. Append to _names_ the elements of the ReferencedBindings of |ExportSpecifier|.
1. Return _names_.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName</emu-grammar>
<emu-alg>
1. Return a List containing the |IdentifierName|.
</emu-alg>
<emu-grammar>ExportSpecifier : IdentifierName `as` IdentifierName</emu-grammar>
<emu-alg>
1. Return a List containing the first |IdentifierName|.
</emu-alg>
</emu-clause>

<!-- es6num="15.2.3.11" -->
<emu-clause id="sec-exports-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
Expand Down

0 comments on commit 5d5fdab

Please sign in to comment.