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

Ember assert is not correctly transformed when using optional chaining #410

Open
mongoose700 opened this issue Jun 10, 2021 · 3 comments
Open

Comments

@mongoose700
Copy link

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.

@Techn1x
Copy link

Techn1x commented Feb 13, 2024

We found this occurred specifically in our CI environment, when CI=true

@Techn1x
Copy link

Techn1x commented Feb 13, 2024

Some starting points for investigation

CI flags look to be used here

flags: { DEBUG: isDebug, CI: !!process.env.CI },

flags: { DEBUG: isDebug, CI: !!process.env.CI },

From https://github.com/ember-cli/babel-plugin-debug-macros/tree/master

The assert macro can expand in a more intelligent way with the correct configuration. When babel-plugin-debug-macros is provided with the assertPredicateIndex the predicate is injected in front of the assertion in order to avoid costly assertion message generation when not needed.

And then;
https://github.com/ember-cli/babel-plugin-debug-macros/blob/f40c21bdd5d6332ae1862826ed9127317a1778a6/src/utils/builder.js#L14-L41

And;
https://github.com/ember-cli/babel-plugin-debug-macros/blob/f40c21bdd5d6332ae1862826ed9127317a1778a6/src/utils/builder.js#L110-L114

@Techn1x
Copy link

Techn1x commented Feb 13, 2024

Looks like it has been reported over there as an issue
ember-cli/babel-plugin-debug-macros#89

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