Browse Source

add aggressive mode

better-aggressive
Rich-Harris 9 years ago
parent
commit
2dea1ef0e5
  1. 7
      src/Bundle.js
  2. 6
      test/form/aggressive/_config.js
  3. 9
      test/form/aggressive/_expected/amd.js
  4. 7
      test/form/aggressive/_expected/cjs.js
  5. 5
      test/form/aggressive/_expected/es6.js
  6. 9
      test/form/aggressive/_expected/iife.js
  7. 13
      test/form/aggressive/_expected/umd.js
  8. 9
      test/form/aggressive/foo.js
  9. 3
      test/form/aggressive/main.js

7
src/Bundle.js

@ -50,6 +50,7 @@ export default class Bundle {
this.external = options.external || [];
this.onwarn = options.onwarn || onwarn;
this.aggressive = options.aggressive;
// TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
[ 'module', 'exports' ].forEach( global => this.assumedGlobals[ global ] = true );
@ -74,7 +75,11 @@ export default class Bundle {
});
// mark statements that should appear in the bundle
this.modules.forEach( module => module.markStatements() );
if ( this.aggressive ) {
entryModule.markStatements();
} else {
this.modules.forEach( module => module.markStatements() );
}
this.orderedModules = this.sort();
this.deconflict();

6
test/form/aggressive/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'ignores side-effects outside entry module in aggressive mode',
options: {
aggressive: true
}
}

9
test/form/aggressive/_expected/amd.js

@ -0,0 +1,9 @@
define(function () { 'use strict';
function foo () {
return 42;
}
assert.equal( foo(), 42 );
});

7
test/form/aggressive/_expected/cjs.js

@ -0,0 +1,7 @@
'use strict';
function foo () {
return 42;
}
assert.equal( foo(), 42 );

5
test/form/aggressive/_expected/es6.js

@ -0,0 +1,5 @@
function foo () {
return 42;
}
assert.equal( foo(), 42 );

9
test/form/aggressive/_expected/iife.js

@ -0,0 +1,9 @@
(function () { 'use strict';
function foo () {
return 42;
}
assert.equal( foo(), 42 );
})();

13
test/form/aggressive/_expected/umd.js

@ -0,0 +1,13 @@
(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 );
}));

9
test/form/aggressive/foo.js

@ -0,0 +1,9 @@
function x () {
console.log( 'side-effect' );
}
x();
export function foo () {
return 42;
}

3
test/form/aggressive/main.js

@ -0,0 +1,3 @@
import { foo } from './foo';
assert.equal( foo(), 42 );
Loading…
Cancel
Save