ember-cli / ember-cli/babel-plugin-debug-macros

Wrong transpilation when optional chaining is used in `assert()`

Đang mở
#89 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
13
Fork
13
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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 https://github.com/babel/babel/issues/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!

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.