diff --git a/src/Declaration.js b/src/Declaration.js index f7195b4..0abc9af 100644 --- a/src/Declaration.js +++ b/src/Declaration.js @@ -6,10 +6,10 @@ export default class Declaration { if ( node ) { if ( node.type === 'FunctionDeclaration' ) { this.isFunctionDeclaration = true; - this.functionBody = node.body; + this.functionNode = node; } else if ( node.type === 'VariableDeclarator' && node.init && /FunctionExpression/.test( node.init.type ) ) { this.isFunctionDeclaration = true; - this.functionBody = node.init.body; + this.functionNode = node.init; } } @@ -32,8 +32,8 @@ export default class Declaration { } testForSideEffects ( strongDependencies ) { - if ( !this.statement ) return; - return testForSideEffects( this.functionBody, this.statement.scope, this.statement, strongDependencies ); + if ( !this.statement || !this.functionNode ) return; + return testForSideEffects( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies ); } render ( es6 ) { diff --git a/src/ast/attachScopes.js b/src/ast/attachScopes.js index ab166ad..9c12df0 100644 --- a/src/ast/attachScopes.js +++ b/src/ast/attachScopes.js @@ -20,6 +20,7 @@ export default function attachScopes ( statement ) { // var foo = 1 if ( node.type === 'VariableDeclaration' ) { const isBlockDeclaration = blockDeclarations[ node.kind ]; + node.declarations.forEach( declarator => { scope.addDeclaration( declarator, isBlockDeclaration, true ); });