Skip to content

function.sent as an expression statement. #2

Open

Description

@nicolo-ribaudo

Hi, while implementing function.sent support in Babel I got a doubt: is this code valid?

function* foo() {
  function.sent;
}

The current specification disallows it (an ExpressionStatement can't start with function):
https://tc39.github.io/ecma262/#prod-ExpressionStatement

ExpressionStatement[Yield, Await]:
  [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] Expression[+In, ?Yield, ?Await] ;

I couldn't find in this proposal a relaxation of that grammar, but I don't see why it should be disallowed.

Activity

  1. allenwb commented on Jul 7, 2017

    @allenwb
    Member

    Good catch.

    Yes, it seems reasonable that an expression statement could start with function . sent. For example, that would be useful for making recursive function calls. So, you should consider that to be part of the proposal.

    But, actually specify that via the current ES grammar notation looks like it may be tricky and might even require extending the notation. FunctionDeclaration probably will need a [lookahead ∉ { function . }] guard, but that's not enough. We also need to find a way for ExpressionStatement to express a conditional multi-token lookahead that will allow function .. Maybe something like:

    ExpressionStatement[Yield, Await]:
      [lookahead ∉ { {, function [lookahead ∉ { . }], async [no LineTerminator here] function, class, let [ }] Expression[+In, ?Yield, ?Await] ;
    
  2. nicolo-ribaudo commented on Jul 7, 2017

    @nicolo-ribaudo
    MemberAuthor

    What about using positive lookahead?

    ExpressionStatement[Yield, Await]:
      [lookahead ∈ { function . }] Expression[+In, ?Yield, ?Await] ;
      [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] Expression[+In, ?Yield, ?Await] ;
    
  3. allenwb commented on Jul 7, 2017

    @allenwb
    Member

    yes, adding positive lookahead to the notation is probably the better way to go

  4. transferred this issue fromallenwb/ESideason Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions