Browse Source

include top-level throw statement inside block

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

1
src/ast/Scope.js

@ -40,6 +40,7 @@ export default class Scope {
this.parent = options.parent;
this.isBlockScope = !!options.block;
this.isTopLevel = !this.parent || ( this.parent.isTopLevel && this.isBlockScope );
this.declarations = blank();

2
src/utils/testForSideEffects.js

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

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

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

11
test/form/side-effect-i/_expected/amd.js

@ -0,0 +1,11 @@
define(function () { 'use strict';
if ( !ok ) {
throw new Error( 'this will be included' );
}
var main = 42;
return main;
});

9
test/form/side-effect-i/_expected/cjs.js

@ -0,0 +1,9 @@
'use strict';
if ( !ok ) {
throw new Error( 'this will be included' );
}
var main = 42;
module.exports = main;

7
test/form/side-effect-i/_expected/es6.js

@ -0,0 +1,7 @@
if ( !ok ) {
throw new Error( 'this will be included' );
}
var main = 42;
export default main;

11
test/form/side-effect-i/_expected/iife.js

@ -0,0 +1,11 @@
var myBundle = (function () { 'use strict';
if ( !ok ) {
throw new Error( 'this will be included' );
}
var main = 42;
return main;
})();

15
test/form/side-effect-i/_expected/umd.js

@ -0,0 +1,15 @@
(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';
if ( !ok ) {
throw new Error( 'this will be included' );
}
var main = 42;
return main;
}));

5
test/form/side-effect-i/main.js

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