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

Wrong transpilation when optional chaining is used in assert() #89

Open
simonihmig opened this issue Oct 14, 2021 · 1 comment
Open

Comments

@simonihmig
Copy link

I have this code:

assert('Need profile data', this.args.window.profile?.data);

When optional chaining is not transpiled, things work fine. The line above is transformed to:

(true && !(this.args.window.profile?.data) && (0, _debug.assert)('Need profile data', this.args.window.profile?.data));

However some automated dependency updates including most Babel stuff changed behavior, in that optional chaining is now transpiled, I believe due to some bug in Chrome, see babel/babel#13145.

But now the transform yields this broken code:

var _this$args$window$pro;

(true && !(_this$args$window$pro.data) && (0, _debug.assert)('Need profile data', (_this$args$window$pro = this.args.window.profile) === null || _this$args$window$pro === void 0 ? void 0 : _this$args$window$pro.data));

Which throws with Cannot read properties of undefined (reading 'data') as at the time the !(_this$args$window$pro.data) expression is evaluated _this$args$window$pro is still undefined!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants