Skip to content

Commit 199679a

Browse files
author
Robert Jackson
committed
Replace all feature flag bindings (not just specific scenarios).
1 parent 11b5d05 commit 199679a

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

fixtures/inline-feature-flags/expectation.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@ if (false) {
55
a = () => console.log('hello');
66
} else if (true) {
77
a = () => console.log('bye');
8+
}
9+
10+
if (!false) {
11+
console.log('stuff');
12+
}
13+
14+
a = false ? 'hello' : 'bye';
15+
16+
if (false && window.foo && window.bar) {
17+
console.log('wheeee');
818
}

fixtures/inline-feature-flags/sample.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ if (FEATURE_A) {
66
} else if (FEATURE_B) {
77
a = () => console.log('bye');
88
}
9+
10+
if (!FEATURE_A) {
11+
console.log('stuff');
12+
}
13+
14+
a = FEATURE_A ? 'hello' : 'bye';
15+
16+
if (FEATURE_A && window.foo && window.bar) {
17+
console.log('wheeee');
18+
}

src/lib/utils/macros.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ export default class Macros {
5252
if (this.envFlags.DEBUG) { return; }
5353
Object.keys(featuresMap).forEach((source) => {
5454
Object.keys(featuresMap[source]).forEach((flag) => {
55+
let flagValue = featuresMap[source][flag];
5556
let binding = path.scope.getBinding(flag);
56-
if (binding && featuresMap[source][flag] !== null) {
57-
binding.referencePaths.forEach(p => {
58-
if (p.parentPath.isIfStatement() ||
59-
(p.parentPath.isLogicalExpression() &&
60-
p.parentPath.parentPath &&
61-
p.parentPath.parentPath.isIfStatement())) {
62-
p.replaceWith(builder.t.booleanLiteral(featuresMap[source][flag]))
63-
}
57+
58+
if (binding && flagValue !== null) {
59+
binding.referencePaths.forEach(referencePath => {
60+
referencePath.replaceWith(builder.t.booleanLiteral(flagValue));
6461
});
6562

6663
if (binding.path.parentPath.isImportDeclaration()) {

0 commit comments

Comments
 (0)