diff --git a/src/Bundle.js b/src/Bundle.js index 0a670d2..9f66026 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -82,14 +82,12 @@ export default class Bundle { }); // mark statements that should appear in the bundle - const safe = !this.aggressive; - let settled = false; while ( !settled ) { settled = true; this.modules.forEach( module => { - if ( module.run( safe || module === entryModule ) ) settled = false; + if ( module.run() ) settled = false; }); } diff --git a/src/Declaration.js b/src/Declaration.js index 31f9345..76c7fa1 100644 --- a/src/Declaration.js +++ b/src/Declaration.js @@ -39,14 +39,14 @@ export default class Declaration { return `exports.${this.name}`; } - run ( strongDependencies, safe ) { + run ( strongDependencies ) { if ( this.tested ) return this.hasSideEffects; this.tested = true; 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 ); + this.hasSideEffects = run( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies, false ); } return this.hasSideEffects; @@ -93,13 +93,13 @@ export class SyntheticDefaultDeclaration { this.original.render(); } - run ( strongDependencies, safe ) { + run ( strongDependencies ) { if ( this.original ) { - return this.original.run( strongDependencies, safe ); + return this.original.run( strongDependencies ); } if ( /FunctionExpression/.test( this.node.declaration.type ) ) { - return run( this.node.declaration.body, this.statement.scope, this.statement, strongDependencies, false, safe ); + return run( this.node.declaration.body, this.statement.scope, this.statement, strongDependencies, false ); } } @@ -224,8 +224,8 @@ export class ExternalDeclaration { return es6 ? this.name : `${this.module.name}.${this.name}`; } - run ( strongDependencies, safe ) { - return safe; + run ( strongDependencies ) { + return true; } use () { diff --git a/src/utils/run.js b/src/utils/run.js index 2d9ca6e..ac303f1 100644 --- a/src/utils/run.js +++ b/src/utils/run.js @@ -46,7 +46,7 @@ simdTypes.forEach( t => { -export default function run ( node, scope, statement, strongDependencies, force, safe ) { +export default function run ( node, scope, statement, strongDependencies, force ) { let hasSideEffect = false; walk( node, { @@ -83,10 +83,10 @@ export default function run ( node, scope, statement, strongDependencies, force, statement.module.trace( node.callee.name ); if ( declaration ) { - if ( declaration.run( strongDependencies, safe ) ) { + if ( declaration.run( strongDependencies ) ) { hasSideEffect = true; } - } else if ( safe && !pureFunctions[ node.callee.name ] ) { + } else if ( !pureFunctions[ node.callee.name ] ) { hasSideEffect = true; } } @@ -99,7 +99,7 @@ export default function run ( node, scope, statement, strongDependencies, force, // TODO make pureFunctions configurable const declaration = scope.findDeclaration( flattened.name ) || statement.module.trace( flattened.name ); - if ( safe && ( !!declaration || !pureFunctions[ flattened.keypath ] ) ) { + if ( !!declaration || !pureFunctions[ flattened.keypath ] ) { hasSideEffect = true; } } else { @@ -110,7 +110,7 @@ export default function run ( node, scope, statement, strongDependencies, force, } // otherwise we're probably dealing with a function expression - else if ( run( node.callee, scope, statement, strongDependencies, true, safe ) ) { + else if ( run( node.callee, scope, statement, strongDependencies, true ) ) { hasSideEffect = true; } } @@ -126,7 +126,7 @@ export default function run ( node, scope, statement, strongDependencies, force, } else { declaration = statement.module.trace( subject.name ); - if ( ( safe && ( !declaration || declaration.isExternal ) ) || declaration && declaration.isUsed ) { + if ( !declaration || declaration.isExternal || declaration.isUsed ) { hasSideEffect = true; } } diff --git a/test/form/aggressive/_config.js b/test/form/aggressive/_config.js deleted file mode 100644 index bafb1e0..0000000 --- a/test/form/aggressive/_config.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - description: 'ignores side-effects outside entry module in aggressive mode', - options: { - aggressive: true - } -} diff --git a/test/form/aggressive/_expected/amd.js b/test/form/aggressive/_expected/amd.js deleted file mode 100644 index eac4f98..0000000 --- a/test/form/aggressive/_expected/amd.js +++ /dev/null @@ -1,9 +0,0 @@ -define(function () { 'use strict'; - - function foo () { - return 42; - } - - assert.equal( foo(), 42 ); - -}); \ No newline at end of file diff --git a/test/form/aggressive/_expected/cjs.js b/test/form/aggressive/_expected/cjs.js deleted file mode 100644 index a547fb6..0000000 --- a/test/form/aggressive/_expected/cjs.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -function foo () { - return 42; -} - -assert.equal( foo(), 42 ); \ No newline at end of file diff --git a/test/form/aggressive/_expected/es6.js b/test/form/aggressive/_expected/es6.js deleted file mode 100644 index f32ad00..0000000 --- a/test/form/aggressive/_expected/es6.js +++ /dev/null @@ -1,5 +0,0 @@ -function foo () { - return 42; -} - -assert.equal( foo(), 42 ); \ No newline at end of file diff --git a/test/form/aggressive/_expected/iife.js b/test/form/aggressive/_expected/iife.js deleted file mode 100644 index 3ba1058..0000000 --- a/test/form/aggressive/_expected/iife.js +++ /dev/null @@ -1,9 +0,0 @@ -(function () { 'use strict'; - - function foo () { - return 42; - } - - assert.equal( foo(), 42 ); - -})(); \ No newline at end of file diff --git a/test/form/aggressive/_expected/umd.js b/test/form/aggressive/_expected/umd.js deleted file mode 100644 index 1eb1ef2..0000000 --- a/test/form/aggressive/_expected/umd.js +++ /dev/null @@ -1,13 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory() : - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(this, function () { 'use strict'; - - function foo () { - return 42; - } - - assert.equal( foo(), 42 ); - -})); \ No newline at end of file diff --git a/test/form/aggressive/foo.js b/test/form/aggressive/foo.js deleted file mode 100644 index 16f57e9..0000000 --- a/test/form/aggressive/foo.js +++ /dev/null @@ -1,9 +0,0 @@ -function x () { - console.log( 'side-effect' ); -} - -x(); - -export function foo () { - return 42; -} diff --git a/test/form/aggressive/main.js b/test/form/aggressive/main.js deleted file mode 100644 index 66c6979..0000000 --- a/test/form/aggressive/main.js +++ /dev/null @@ -1,3 +0,0 @@ -import { foo } from './foo'; - -assert.equal( foo(), 42 ); diff --git a/test/function/aggressive-mode/_config.js b/test/function/aggressive-mode/_config.js deleted file mode 100644 index 7317b3f..0000000 --- a/test/function/aggressive-mode/_config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - // solo: true, - // show: true, - description: 'aggressive mode distinguishes between necessary and probably-not-necessary side-effects', - options: { - aggressive: true - } -}; diff --git a/test/function/aggressive-mode/foo.js b/test/function/aggressive-mode/foo.js deleted file mode 100644 index 15ed18e..0000000 --- a/test/function/aggressive-mode/foo.js +++ /dev/null @@ -1,11 +0,0 @@ -function Foo () {} - -Foo.prototype = { - answer: function () { - return 42; - } -}; - -export default function foo () { - return new Foo(); -} diff --git a/test/function/aggressive-mode/main.js b/test/function/aggressive-mode/main.js deleted file mode 100644 index 707c46a..0000000 --- a/test/function/aggressive-mode/main.js +++ /dev/null @@ -1,3 +0,0 @@ -import foo from './foo'; - -assert.equal( foo().answer(), 42 );