Browse Source

skip throw statements inside functions when checking for side-effects

better-aggressive
Rich-Harris 9 years ago
parent
commit
0ffe08b1ff
  1. 4
      src/utils/testForSideEffects.js
  2. 6
      test/form/side-effect-h/_config.js
  3. 7
      test/form/side-effect-h/_expected/amd.js
  4. 5
      test/form/side-effect-h/_expected/cjs.js
  5. 3
      test/form/side-effect-h/_expected/es6.js
  6. 7
      test/form/side-effect-h/_expected/iife.js
  7. 11
      test/form/side-effect-h/_expected/umd.js
  8. 9
      test/form/side-effect-h/main.js

4
src/utils/testForSideEffects.js

@ -34,7 +34,9 @@ export default function testForSideEffects ( node, scope, statement, strongDepen
} }
else if ( node.type === 'ThrowStatement' ) { else if ( node.type === 'ThrowStatement' ) {
hasSideEffect = true; // we only care about errors thrown at the top level, otherwise
// any function with error checking gets included if called
hasSideEffect = !scope.parent;
} }
else if ( node.type === 'CallExpression' || node.type === 'NewExpression' ) { else if ( node.type === 'CallExpression' || node.type === 'NewExpression' ) {

6
test/form/side-effect-h/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'excludes non-top-level throw statements',
options: {
moduleName: 'myBundle'
}
};

7
test/form/side-effect-h/_expected/amd.js

@ -0,0 +1,7 @@
define(function () { 'use strict';
var main = 42;
return main;
});

5
test/form/side-effect-h/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
var main = 42;
module.exports = main;

3
test/form/side-effect-h/_expected/es6.js

@ -0,0 +1,3 @@
var main = 42;
export default main;

7
test/form/side-effect-h/_expected/iife.js

@ -0,0 +1,7 @@
var myBundle = (function () { 'use strict';
var main = 42;
return main;
})();

11
test/form/side-effect-h/_expected/umd.js

@ -0,0 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
}(this, function () { 'use strict';
var main = 42;
return main;
}));

9
test/form/side-effect-h/main.js

@ -0,0 +1,9 @@
function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}
foo();
export default 42;
Loading…
Cancel
Save