File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed
fixtures/inline-feature-flags Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,14 @@ if (false) {
5
5
a = ( ) => console . log ( 'hello' ) ;
6
6
} else if ( true ) {
7
7
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' ) ;
8
18
}
Original file line number Diff line number Diff line change @@ -6,3 +6,13 @@ if (FEATURE_A) {
6
6
} else if ( FEATURE_B ) {
7
7
a = ( ) => console . log ( 'bye' ) ;
8
8
}
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
+ }
Original file line number Diff line number Diff line change @@ -52,15 +52,12 @@ export default class Macros {
52
52
if ( this . envFlags . DEBUG ) { return ; }
53
53
Object . keys ( featuresMap ) . forEach ( ( source ) => {
54
54
Object . keys ( featuresMap [ source ] ) . forEach ( ( flag ) => {
55
+ let flagValue = featuresMap [ source ] [ flag ] ;
55
56
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 ) ) ;
64
61
} ) ;
65
62
66
63
if ( binding . path . parentPath . isImportDeclaration ( ) ) {
You can’t perform that action at this time.
0 commit comments