Nullish coalescing operator can break redux-saga-babel-plugin
Nantris opened this issue · comments
Steps to reproduce
First, of course, enable the Babel plugin. Then run some code like:
function* someFunc({ payload: { bool } }) {
bool = yield bool ?? select(getBool); // << TypeError: Object.defineProperty called on non-object
}
Description of the bug/issue
The code will error with, Object.defineProperty called on non-object
This appears to be caused by these lines of code in the plugin:
redux-saga/packages/babel-plugin-redux-saga/src/index.js
Lines 30 to 38 in 6f07fca
Steps to reproduce the bug/issue
@Andarist does the issue template intentionally have "Steps to reproduce" twice? I guess so since they're different header levels, but it's a little confusing.
Example
I don't think a CodeSandbox can apply the Babel Plugin, but correct me if I'm wrong. I won't have time to make a full repro repo for this.
Actual results
Object.defineProperty called on non-object
The Expected results
Babel plugin does not change result of executed code.
Environment information
- redux-saga version: 1.2.1
- babel: version 7.17.10
- babel-plugin-redux-saga: version 1.1.3
Additional info
This alternative syntax, suggested by @Andarist, worked without provoking the error:
function* someFunc({ payload: { bool } }) {
bool ??= yield select(getBool);
}
Note that the issue is probably not specific to nullish coalescing operator. I'd expect this to either break on yields that don't yield an effect or on yields that mix effect with non-object values