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

Function declaration throws in REPL #10950

Closed
mik-jozef opened this issue Jan 22, 2017 · 4 comments
Closed

Function declaration throws in REPL #10950

mik-jozef opened this issue Jan 22, 2017 · 4 comments
Labels
question Issues that look for answers. repl Issues and PRs related to the REPL subsystem.

Comments

@mik-jozef
Copy link

mik-jozef commented Jan 22, 2017

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

@mscdex mscdex added repl Issues and PRs related to the REPL subsystem. question Issues that look for answers. labels Jan 22, 2017
@mscdex mscdex changed the title Function declatarion throws in REPL Function declaration throws in REPL Jan 22, 2017
@Fishrock123
Copy link
Contributor

Fishrock123 commented Jan 22, 2017

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.

@bnoordhuis
Copy link
Member

bnoordhuis commented Jan 22, 2017

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.

@targos
Copy link
Member

targos commented Jan 26, 2017

This is fixed on master now.

@joyeecheung
Copy link
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
Labels
question Issues that look for answers. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants