diff --git a/src/ast/nodes/CallExpression.js b/src/ast/nodes/CallExpression.js index 8fafc91..70d1e13 100644 --- a/src/ast/nodes/CallExpression.js +++ b/src/ast/nodes/CallExpression.js @@ -30,7 +30,9 @@ export default class CallExpression extends Node { } initialise ( scope ) { - this.module.bundle.dependentExpressions.push( this ); + if ( isProgramLevel( this ) ) { + this.module.bundle.dependentExpressions.push( this ); + } super.initialise( scope ); } @@ -38,3 +40,14 @@ export default class CallExpression extends Node { return this.hasEffects( this.findScope() ); } } + +function isProgramLevel ( node ) { + do { + if ( node.type === 'Program' ) { + return true; + } + node = node.parent; + } while ( node && !/Function/.test( node.type ) ); + + return false; +}