diff --git a/src/ast/nodes/ConditionalExpression.js b/src/ast/nodes/ConditionalExpression.js index 178f4bc655e..25092c3df1a 100644 --- a/src/ast/nodes/ConditionalExpression.js +++ b/src/ast/nodes/ConditionalExpression.js @@ -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 ); } } diff --git a/test/form/samples/conditional-expression/main.js b/test/form/samples/conditional-expression/main.js index 59a7f88e96b..c2490d994d7 100644 --- a/test/form/samples/conditional-expression/main.js +++ b/test/form/samples/conditional-expression/main.js @@ -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;