Christoph
Christoph

Reputation: 2073

Babel does not transpile with ES2015 but Stage0 preset

I'm running into a problem transpiling the following code (redux reducer) with babel and the ES2015 preset. I'm (wrongly) assuming this is code that can be transpiled.

const todos = (state = [], action) => {
    switch (action.type) {
        case 'TOGGLE_TODO':
        return state.map(todo =>
            (todo.id === action.id)
                ? {
                ...todo,
                completed: !todo.completed
                }
                : todo
            )

        default:
        return state
    }
}

export default todos

The error message

repl: Unexpected token (7:16)
   5 |             (todo.id === action.id)
   6 |                 ? {
>  7 |                 ...todo,

Transpiling with the Stage0 preset works fine. I did verify this behaivor with the Babel online.

Upvotes: 0

Views: 72

Answers (2)

Quoc-Anh Nguyen
Quoc-Anh Nguyen

Reputation: 5056

Because preset-2016 doesn't support object rest spread. It's stage 3 now

Upvotes: 1

lipp
lipp

Reputation: 5926

You are using the object spread operator which is part of stage 3.

Upvotes: 0

Related Questions