From 2fd5ac80ebd3c6d8493370fd14b281f48dba84f7 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Thu, 7 Jul 2016 18:14:42 -0400 Subject: [PATCH] Editorial: Re-factor ExportSpecifier 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. --- spec.html | 111 ++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 66 deletions(-) diff --git a/spec.html b/spec.html index 3c9c9b1dfc..d7d743dd1f 100644 --- a/spec.html +++ b/spec.html @@ -21759,42 +21759,30 @@

Syntax

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 <! {`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 - - -

Static Semantics: Early Errors

- ExportDeclaration : `export` ExportClause `;` - - -

The above rule means that each ReferencedBindings of |ExportClause| is treated as an |IdentifierReference|.

-
-
-

Static Semantics: BoundNames

@@ -21878,6 +21866,13 @@

Static Semantics: ExportedBindings

1. Append to _names_ the elements of the ExportedBindings of |ExportSpecifier|. 1. Return _names_. + + ExportSpecifier : IdentifierReference + + ExportSpecifier : IdentifierReference `as` IdentifierName + + 1. Return a List containing the StringValue of |IdentifierReference|. + ExportSpecifier : IdentifierName 1. Return a List containing the StringValue of |IdentifierName|. @@ -21932,7 +21927,15 @@

Static Semantics: ExportedNames

1. Append to _names_ the elements of the ExportedNames of |ExportSpecifier|. 1. Return _names_.
- ExportSpecifier : IdentifierName + ExportSpecifier : IdentifierReference + + 1. Return a List containing the StringValue of |IdentifierReference|. + + + ExportSpecifier : IdentifierReference `as` IdentifierName + + ExportSpecifier : IdentifierName + 1. Return a List containing the StringValue of |IdentifierName|. @@ -22013,28 +22016,27 @@

Static Semantics: ExportEntriesForModule

1. Append to _specs_ the elements of the ExportEntriesForModule of |ExportSpecifier| with argument _module_. 1. Return _specs_. + ExportSpecifier : IdentifierReference + + 1. Let _sourceName_ be the StringValue of |IdentifierReference|. + 1. Return a new List containing the Record {[[ModuleRequest]]: *null*, [[ImportName]]: *null*, [[LocalName]]: _sourceName_, [[ExportName]]: _sourceName_ }. + ExportSpecifier : IdentifierName 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_ }. + + ExportSpecifier : IdentifierReference `as` IdentifierName + + 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_ }. ExportSpecifier : IdentifierName `as` IdentifierName - 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_ }.
@@ -22115,29 +22117,6 @@

Static Semantics: ModuleRequests

- - -

Static Semantics: ReferencedBindings

- ExportClause : `{` `}` - - 1. Return a new empty List. - - ExportsList : ExportsList `,` ExportSpecifier - - 1. Let _names_ be the ReferencedBindings of |ExportsList|. - 1. Append to _names_ the elements of the ReferencedBindings of |ExportSpecifier|. - 1. Return _names_. - - ExportSpecifier : IdentifierName - - 1. Return a List containing the |IdentifierName|. - - ExportSpecifier : IdentifierName `as` IdentifierName - - 1. Return a List containing the first |IdentifierName|. - -
-

Runtime Semantics: Evaluation