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

Fix arrow function body parsing #1

Closed

Conversation

DanBurton
Copy link

See: erikd#117

We add three failing tests:
  1. {()=>{};``}
  2. {x=>x;``}
  3. {f:x=>x,y:2}

We also add a fourth test mirroring the third but with a function block
body instead of an expression. The hope is that we get no regressions
when we change the representation of arrow functions.
The issue with the current parsing rules and representation is that
arrow function bodies are not statements, they're either function blocks
or expressions. Looking at the
specification (https://www.ecma-international.org/ecma-262/#prod-ExpressionBody)
we see that the expressions are `AssignmentExpression` in particular.

Making this change appears to fix the additional tests, but it breaks
minification.
The minifier was treating arrow functions with block bodies incorrectly
if they contained a single expression statement with no return
statement. It was transforming them into arrow functions with expression
bodies.

This means for instance that in
```js
let x = (() => { 42 })();
```

`x` would equal `undefined` before minification, but would equal `42`
after minification. The fix is to change the tests to match the correct
behavior.
@DanBurton DanBurton changed the title Add failing tests for arrow functions Fix arrow function body parsing Jan 6, 2021
@DanBurton DanBurton closed this Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants