From 2ded15a0d8fa38639c1f6ac171e5bf7c64b1a223 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 14 Nov 2015 17:27:12 -0500 Subject: [PATCH] unify APIs --- src/Declaration.js | 6 +++++- src/utils/run.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Declaration.js b/src/Declaration.js index f4d2e0d..31f9345 100644 --- a/src/Declaration.js +++ b/src/Declaration.js @@ -43,7 +43,7 @@ export default class Declaration { if ( this.tested ) return this.hasSideEffects; this.tested = true; - if ( !this.statement || !this.functionNode ) { + if ( !this.functionNode ) { this.hasSideEffects = true; // err on the side of caution. TODO handle unambiguous `var x; x = y => z` cases } else { this.hasSideEffects = run( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies, false, safe ); @@ -224,6 +224,10 @@ export class ExternalDeclaration { return es6 ? this.name : `${this.module.name}.${this.name}`; } + run ( strongDependencies, safe ) { + return safe; + } + use () { // noop? } diff --git a/src/utils/run.js b/src/utils/run.js index 8139a40..2d9ca6e 100644 --- a/src/utils/run.js +++ b/src/utils/run.js @@ -83,7 +83,7 @@ export default function run ( node, scope, statement, strongDependencies, force, statement.module.trace( node.callee.name ); if ( declaration ) { - if ( declaration.isExternal || declaration.run( strongDependencies, safe ) ) { + if ( declaration.run( strongDependencies, safe ) ) { hasSideEffect = true; } } else if ( safe && !pureFunctions[ node.callee.name ] ) { @@ -104,7 +104,7 @@ export default function run ( node, scope, statement, strongDependencies, force, } } else { // is not a keypath like `foo.bar.baz` – could be e.g. - // `(a || b).foo()`. Err on the side of caution + // `foo[bar].baz()`. Err on the side of caution hasSideEffect = true; } }