Skip to content

Function declaration throws in REPL #10950

Description

@mik-jozef
  • Version: v7.4.0
  • Platform: Windows 10 64bit

The following code is executed normally from a file, but throws from REPL.

function f(){} f()
// REPL output:
var f = function f(){} f()
                       ^
SyntaxError: Unexpected identifier

I guess the function declaration is converted to function expression which unlike the declaration requires semicolon. However, everything works fine with 5; function f(){} f().

Also, this code works in REPL: function f(){}, a=9, but it shouldn't.

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    questionIssues asking questions about Node.js.
    on Jan 22, 2017
  2. changed the title [-]Function declatarion throws in REPL[/-] [+]Function declaration throws in REPL[/+] on Jan 22, 2017
  3. Fishrock123 commented on Jan 22, 2017

    @Fishrock123
    Contributor

    So, I get these results on master:

    > function f(){} f()
    var f = function f(){} f()
                           ^
    SyntaxError: Unexpected identifier
    
    > var f = function f(){} f()
    var f = function f(){} f()
                           ^
    SyntaxError: Unexpected identifier
    
    > function f(){}, a=9
    undefined
    > a
    9
    >

    To me, I think all variations of function f(){} f() are incorrect, but function f(){}, a=9 sounds how commas are "supposed" to work.

    Note: I'm no spec expert on what is and isn't valid.

  4. bnoordhuis commented on Jan 22, 2017

    @bnoordhuis
    Member

    It's caused by bb9eabe, which is a fix/workaround for #548 and scheduled to be removed when we upgrade to V8 5.5, see #9618.

    I don't think we'll be able to fix this in in v7.x and older without reintroducing the issue that bb9eabe was supposed to address.

    EDIT: For posterity: bb9eabe is from #7624; the commit log is missing the PR-URL tag.

  5. targos commented on Jan 26, 2017

    @targos
    Member

    This is fixed on master now.

  6. joyeecheung commented on Jan 28, 2017

    @joyeecheung
    Member

    Closing according to #10950 (comment), feel free to reopen if the issue persists

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

    questionIssues asking questions about Node.js.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions