Browse Source

unify APIs

better-aggressive
Rich-Harris 9 years ago
parent
commit
2ded15a0d8
  1. 6
      src/Declaration.js
  2. 4
      src/utils/run.js

6
src/Declaration.js

@ -43,7 +43,7 @@ export default class Declaration {
if ( this.tested ) return this.hasSideEffects; if ( this.tested ) return this.hasSideEffects;
this.tested = true; 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 this.hasSideEffects = true; // err on the side of caution. TODO handle unambiguous `var x; x = y => z` cases
} else { } else {
this.hasSideEffects = run( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies, false, safe ); 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}`; return es6 ? this.name : `${this.module.name}.${this.name}`;
} }
run ( strongDependencies, safe ) {
return safe;
}
use () { use () {
// noop? // noop?
} }

4
src/utils/run.js

@ -83,7 +83,7 @@ export default function run ( node, scope, statement, strongDependencies, force,
statement.module.trace( node.callee.name ); statement.module.trace( node.callee.name );
if ( declaration ) { if ( declaration ) {
if ( declaration.isExternal || declaration.run( strongDependencies, safe ) ) { if ( declaration.run( strongDependencies, safe ) ) {
hasSideEffect = true; hasSideEffect = true;
} }
} else if ( safe && !pureFunctions[ node.callee.name ] ) { } else if ( safe && !pureFunctions[ node.callee.name ] ) {
@ -104,7 +104,7 @@ export default function run ( node, scope, statement, strongDependencies, force,
} }
} else { } else {
// is not a keypath like `foo.bar.baz` – could be e.g. // 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; hasSideEffect = true;
} }
} }

Loading…
Cancel
Save