Magic in the emitter callback?
- Dominant language
- JavaScript
- Stars
- 6.8k
- Forks
- 573
- PR merge metrics
- No merged PRs in 30d
Description
### Expected behavior
`choo` should accept valid JS code in the emitter callback.
### Actual behavior
`choo` throws
> "Unexpected token: punc ()) while parsing file: /app/index.js"
when an ES6 arrow function is used the emitter callback.
### Steps to reproduce behavior
This is working code (adapted from the intro tutorial, running on glitch)
```
const choo = require('choo');
const html = require('choo/html');
const main = require('./templates/main.js');
const app = choo();
app.use(function (state, emitter) {
state.animals = [
{ type: 'lion', x: 200, y: 100 },
{ type: 'crocodile', x: 50, y: 300 }
];
emitter.on('addAnimal', function () {
const obj = { type: 'lion', x: 100, y: 200 };
state.animals.push(obj);
emitter.emit('render');
});
});
app.route('/', main);
app.mount('div');
```
When I replace ` function () `with `() =>`
```
emitter.on('addAnimal', () => {
const obj = { type: 'lion', x: 100, y: 200 };
state.animals.push(obj);
emitter.emit('render');
});
```
`choo` throws the above error. Some kind of magic going on?
Contributor guide
Assessment
This issue has not been assessed yet.