Browse Source

use correct scope for testing declarations

better-aggressive
Rich-Harris 9 years ago
parent
commit
1ffd5bfae7
  1. 8
      src/Declaration.js
  2. 1
      src/ast/attachScopes.js

8
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 ) {

1
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 );
});

Loading…
Cancel
Save