Skip to content

Commit

Permalink
Remove a few scope parameters previously missed
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 7, 2017
1 parent 453ff86 commit 6c80cbb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ast/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default class Node {
if ( value ) {
if ( 'length' in value ) {
for ( const child of value ) {
if ( child && child.hasEffects( this.scope ) ) {
if ( child && child.hasEffects() ) {
return true;
}
}
} else if ( value.hasEffects( this.scope ) ) {
} else if ( value.hasEffects() ) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/AssignmentExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class AssignmentExpression extends Node {
}

hasEffects () {
const hasEffects = this.isUsedByBundle() || this.right.hasEffects( this.scope );
const hasEffects = this.isUsedByBundle() || this.right.hasEffects();
return hasEffects;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ClassDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ClassDeclaration extends Class {
parentScope.addDeclaration( this.name, this, false, false );
this.id.initialise( parentScope );
}
super.initialiseChildren(parentScope);
super.initialiseChildren( parentScope );
}

render ( code, es ) {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ExportDefaultDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class ExportDefaultDeclaration extends Node {
if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
code.remove( this.leadingCommentStart || this.start, this.next || this.end );
} else {
const hasEffects = this.declaration.hasEffects( this.module.scope );
const hasEffects = this.declaration.hasEffects();
code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
}
} else if ( name === this.declaration.name ) {
Expand Down
13 changes: 6 additions & 7 deletions src/ast/nodes/shared/callHasEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ function isES5Function ( node ) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}

function hasEffectsNew ( node, scope ) {
function hasEffectsNew ( node ) {
let inner = node;

if ( inner.type === 'ExpressionStatement' ) {
inner = inner.expression;

if ( inner.type === 'AssignmentExpression' ) {
if ( inner.right.hasEffects( scope ) ) {
if ( inner.right.hasEffects() ) {
return true;

} else {
inner = inner.left;

if ( inner.type === 'MemberExpression' ) {
if ( inner.computed && inner.property.hasEffects( scope ) ) {
if ( inner.computed && inner.property.hasEffects() ) {
return true;

} else {
Expand All @@ -38,19 +38,18 @@ function hasEffectsNew ( node, scope ) {
}
}

return node.hasEffects( scope );
return node.hasEffects();
}

function fnHasEffects ( fn, isNew ) {
if ( currentlyCalling.has( fn ) ) return false; // prevent infinite loops... TODO there must be a better way
currentlyCalling.add( fn );

// handle body-less arrow functions
const scope = fn.body.scope || fn.scope;
const body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];

for ( const node of body ) {
if ( isNew ? hasEffectsNew( node, scope ) : node.hasEffects( scope ) ) {
if ( isNew ? hasEffectsNew( node ) : node.hasEffects() ) {
currentlyCalling.delete( fn );
return true;
}
Expand All @@ -61,7 +60,7 @@ function fnHasEffects ( fn, isNew ) {
}

export default function callHasEffects ( scope, callee, isNew ) {
const values = new Set([ callee ]);
const values = new Set( [ callee ] );

for ( const node of values ) {
if ( node === UNKNOWN ) return true; // err on side of caution
Expand Down

0 comments on commit 6c80cbb

Please sign in to comment.