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

Nullish coalescing operator can break redux-saga-babel-plugin #2352

Open
Nantris opened this issue Dec 8, 2022 · 1 comment
Open

Nullish coalescing operator can break redux-saga-babel-plugin #2352

Nantris opened this issue Dec 8, 2022 · 1 comment
Labels

Comments

@Nantris
Copy link

Nantris commented Dec 8, 2022

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:

var extendExpressionWithLocationTemplate = template(`
Object.defineProperty(TARGET, SYMBOL_NAME, {
value: {
fileName: FILENAME,
lineNumber: LINE_NUMBER,
code: SOURCE_CODE,
},
});
`)

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);
}
@Andarist
Copy link
Member

Andarist commented Dec 8, 2022

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

@neurosnap neurosnap added the bug label Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants