lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Allow feature flags to be used in complex `if` conditions

Open nolanlawson opened this issue 2 years ago • 0 comments

Currently we can do this:

import features from '@lwc/features'

if (features.ENABLE_SOMETHING) {
  /* ... */ 
}

... but we can't do this:

import features from '@lwc/features'

if (features.ENABLE_SOMETHING || someOtherCondition) {
  /* ... */ 
}

The reason is that the @lwc/features Babel plugin is pretty specific about what it allows in the if() condition:

https://github.com/salesforce/lwc/blob/1deff061eb2c061327b89f734d1857e17a3ce471/packages/%40lwc/features/src/babel-plugin/index.js#L64-L78

We should fix this so that we can use feature flags everywhere and have them "just work." Or at least work in slightly more complex if conditions.

nolanlawson avatar Aug 16 '22 22:08 nolanlawson