|
|
@ -8,6 +8,11 @@ const blockDeclarations = { |
|
|
|
'let': true |
|
|
|
}; |
|
|
|
|
|
|
|
const modifierNodes = { |
|
|
|
AssignmentExpression: 'left', |
|
|
|
UpdateExpression: 'argument' |
|
|
|
}; |
|
|
|
|
|
|
|
function isIife ( node, parent ) { |
|
|
|
return parent && parent.type === 'CallExpression' && node === parent.callee; |
|
|
|
} |
|
|
@ -47,6 +52,7 @@ export default class Statement { |
|
|
|
this.dependantIds = []; |
|
|
|
this.namespaceReplacements = []; |
|
|
|
|
|
|
|
this.hasSideEffects = false; |
|
|
|
this.isIncluded = false; |
|
|
|
|
|
|
|
this.isImportDeclaration = node.type === 'ImportDeclaration'; |
|
|
@ -167,6 +173,19 @@ export default class Statement { |
|
|
|
if ( isFunctionDeclaration( node, parent ) ) writeDepth += 1; |
|
|
|
if ( /Function/.test( node.type ) && !isIife( node, parent ) ) readDepth += 1; |
|
|
|
|
|
|
|
// If this is a top-level call expression, or an assignment to a global,
|
|
|
|
// this statement will need to be marked
|
|
|
|
if ( !readDepth ) { |
|
|
|
if ( node.type === 'CallExpression' ) { |
|
|
|
this.hasSideEffects = true; |
|
|
|
} else if ( node.type in modifierNodes ) { |
|
|
|
let subject = node[ modifierNodes[ node.type ] ]; |
|
|
|
while ( subject.type === 'MemberExpression' ) subject = subject.object; |
|
|
|
|
|
|
|
if ( !this.module.locals.defines( subject.name ) ) this.hasSideEffects = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ( node._scope ) scope = node._scope; |
|
|
|
|
|
|
|
this.checkForReads( scope, node, parent, !readDepth ); |
|
|
|