michaelboyles / redcr

Compile-time alternative to Immer
MIT License
6 stars 0 forks source link

[BUG] Return statement at end of a reducer returns in undefined state #14

Closed michaelboyles closed 2 years ago

michaelboyles commented 2 years ago

Describe the bug

When return; is added to the end of a block, intuitively you should expect it to make no difference to behaviour. However, in a redcr reducer, it results in the reducer returning undefined.

I can't think of a reason anyone would sensibly do this (in fact, maybe eslint would remove it?) but it low-hanging fruit so worth fixing anyway.

Sample input

interface State {
    str: string;
}
const reducer = redcr((state: State) => {
    state.str = 'abc';
    return;
});

Current output

Specify which ES version you're targeting: ES2020

const reducer = (state) => {
    state = { ...state, str: 'abc' };
    return;
    return state;
};

There are 2 returns, and the first should just be removed entirely.