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

Unexected 'Invalid left-hand side in for-in' #1920

Open
pelchats opened this Issue Mar 16, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@pelchats

pelchats commented Mar 16, 2018

Esprima throws an error when parsing seemingly correct code with a for-in loop. The error seems to be sensitive to the code surrounding it.

Steps to reproduce

esprima.parse(`
  if (a) {
    for(f(); false;) {}
  } else
    for(x in y) {
      g()
    }
`)

Note that this is a ~minimal reproduction. The actual code that I was trying to parse is http://pagead2.googlesyndication.com/pagead/js/r20180312/r20170110/reactive_library.js

Expected output

I think the AST should be parsed successfully. I don't see anything wrong with the above code. In particular, changing the f() call in the first for loop somehow makes the error disappear. Likewise adding curly braces after else also makes the error disappear.

Chrome executes the following code just fine:

  var a = false;
  function f() {
    console.log('f called');
  }
  function g() {
    console.log('g called');
  }
  var c = 0;
  var e = 1;
  var y = [1];
  if (a) {
    for(f(); false;) {}
  } else
    for(x in y) {
      g()
  }
> g called

Actual output

Error: Line 5: Invalid left-hand side in for-in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment