sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 209 forks source link

Fix IdentiferExpression encountered after New/CallExpression #641

Closed gabejohnson closed 7 years ago

gabejohnson commented 7 years ago
{
  foo = bar()
  baz = foo
}
// and
{
  foo = new bar()
  baz = foo
}

both result in:

{
  foo = baz = foo;
}

This is because after enforestation of either a CallExpression or a NewExpression the while loop in enforestLeftHandSideExpression was either entered (in the case of NewExpression) or continued (in the case of CallExpression).

This PR fixes that by breaking or returning respectively.

Fixes #600 and fixes #591

gabejohnson commented 7 years ago

I'd like to add a test for this.

gabejohnson commented 7 years ago

@disnet I just noticed that the test262 tests don't check to see that the parse was correct. Just that it returned a result. How would you suggest I test this? We got rid of all of the parser tests when you added the test262 stuff.

gabejohnson commented 7 years ago

This is not the answer as this:

{
  foo = new bar()['a']
  baz = foo
}

results in:

{
  foo = baz = foo
}

The problem appears to be what's happening when you encounter an identifier in the loop. I think breaking if this.term != null is the way to go.

disnet commented 7 years ago

Nice job tracking this down!

For tests I think what you should do is assert that the AST for the code with a semicolon is the same as the AST without the semicolon.