Skip to content

Commit

Permalink
Fix uninitialized child nodes for conditional expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
anilanar committed Nov 10, 2017
1 parent 6d0e492 commit 405f43f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/ast/nodes/ConditionalExpression.js
Expand Up @@ -40,20 +40,17 @@ export default class ConditionalExpression extends Node {
}

initialiseChildren ( parentScope ) {
super.initialiseChildren( parentScope );
if ( this.module.bundle.treeshake ) {
this.testValue = this.test.getValue();

if ( this.testValue === UNKNOWN_VALUE ) {
super.initialiseChildren( parentScope );
return;
} else if ( this.testValue ) {
this.consequent.initialise( this.scope );
this.alternate = null;
} else if ( this.alternate ) {
this.alternate.initialise( this.scope );
this.consequent = null;
}
} else {
super.initialiseChildren( parentScope );
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/form/samples/conditional-expression/main.js
Expand Up @@ -20,7 +20,8 @@ var e3 = (true ? () => () => {} : () => () => console.log( 'effect' ))()();
var f1 = false ? foo() : 2;
var f2 = (false ? function () {this.x = 1;} : function () {})();
var f3 = (false ? () => () => console.log( 'effect' ) : () => () => {})()();
var g = true ? 1 : 2;
var g1 = true ? 1 : 2;
var g2 = true || foo() ? 1 : 2;

// known side-effect
var h1 = true ? foo() : 2;
Expand Down

0 comments on commit 405f43f

Please sign in to comment.