Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Re-factor ExportSpecifier #637

Merged
merged 1 commit into from
Nov 23, 2016
Merged

Conversation

jugglinmike
Copy link
Contributor

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.


Note that while this patch improves a few aspects of the grammar, there is one
somewhat counterintuitive aspect that it does not address. Both ES2016 and this
modified version contain a use of "ExportEntriesForModule" where the "module"
value is "null". We could move the definitions for the "local" production into
"ExportEntries", but that would require additional considerations for
ExportsList. Maybe there's a better name for ExportEntriesForModule?

@littledan
Copy link
Member

What do you think of this change, @GeorgNeis ?

@GeorgNeis
Copy link
Contributor

I see the point, but I don't like that it introduces yet another grammar parameter. Can someone provide some background on why IdentifierName was used in the first place (rather than IdentifierReference)?

@jugglinmike
Copy link
Contributor Author

My understanding is that IdentifierName is used so that imported namespaces
support the same property names as ordinary objects. For instance, compare:

var o = { if: 0 };
module.exports = o;

with:

var x;
export { x as if };

In both cases, the exported namespace object defines a property named if,
which consumers can access via o.if.

I agree that production parameters aren't perfect, but I do think it's
preferable to the abstract operation and "plain English" early error that we
have at the moment.

@bterlson
Copy link
Member

bterlson commented Aug 9, 2016

Having reflected on this for a while I like it. I don't like adding grammar parameters willy-nilly but being able to understand the core semantics of this area simply by reading the grammar is a huge win.

Unless my read of the diff is wrong, this seems to be missing static semantics for ExportedNames?

@jugglinmike
Copy link
Contributor Author

@bterlson Good catch. I've extended the definition of ExportedNames accordingly.

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.
@jugglinmike
Copy link
Contributor Author

@bterlson gh-692 introduced a minor conflict for this patch, so I resolved, rebased, and squashed (the original version is available here). Do you think this is ready to land? Or maybe I should find someone to bring it up at next week's meeting?

@bterlson
Copy link
Member

@jugglinmike Sorry, I had to re-review. I don't think this needs consensus.

@bterlson bterlson merged commit 5d5fdab into tc39:master Nov 23, 2016
@jugglinmike
Copy link
Contributor Author

Awesome, thanks Brian!

anba added a commit to anba/ecma262 that referenced this pull request Feb 6, 2017
bterlson pushed a commit that referenced this pull request Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants