Node: Function declaration throws in REPL

Created on 22 Jan 2017  路  4Comments  路  Source: nodejs/node

  • 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.

question repl

Most helpful comment

It's caused by bb9eabec4, 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 bb9eabec4 was supposed to address.

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

All 4 comments

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.

It's caused by bb9eabec4, 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 bb9eabec4 was supposed to address.

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

This is fixed on master now.

Closing according to https://github.com/nodejs/node/issues/10950#issuecomment-275525097, feel free to reopen if the issue persists

Was this page helpful?
0 / 5 - 0 ratings