emberjs / emberjs/ember-cli-babel

Ember assert is not correctly transformed when using optional chaining

Open
#410 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
152
Forks
115
Avg merge
23h 22m
Merged PRs (30d)
4

Description

If I start with this code
```
import { assert } from '@ember/debug';

const foo = { bar: { baz: 'something' } };
assert('baz', foo.bar?.baz);
```

it gets transformed into

```
const foo = {
bar: {
baz: 'something'
}
};
(true && !(_foo$bar.baz) && Ember.assert('baz', (_foo$bar = foo.bar) === null || _foo$bar === void 0 ? void 0 : _foo$bar.baz));
```

The first check for `!(_foo$bar.baz)` is performed before the `(_foo$bar = foo.bar)` assignment, which means it will always throw an error, regardless of the actual value.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.