Skip to content

Commit

Permalink
throw always considered to be a side effect
Browse files Browse the repository at this point in the history
  • Loading branch information
kzc committed Jan 6, 2017
1 parent be76a1f commit f2d0851
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ast/nodes/ThrowStatement.js
@@ -1,7 +1,7 @@
import Node from '../Node.js';

export default class ThrowStatement extends Node {
hasEffects ( scope ) {
return scope.findLexicalBoundary().isModuleScope; // TODO should this just be `true`? probably...
hasEffects () {
return true;
}
}
2 changes: 1 addition & 1 deletion test/form/side-effect-h/_config.js
@@ -1,5 +1,5 @@
module.exports = {
description: 'excludes non-top-level throw statements',
description: 'includes throw statements',
options: {
moduleName: 'myBundle'
}
Expand Down
8 changes: 8 additions & 0 deletions test/form/side-effect-h/_expected/amd.js
@@ -1,5 +1,13 @@
define(function () { 'use strict';

function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}

foo();

var main = 42;

return main;
Expand Down
8 changes: 8 additions & 0 deletions test/form/side-effect-h/_expected/cjs.js
@@ -1,5 +1,13 @@
'use strict';

function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}

foo();

var main = 42;

module.exports = main;
8 changes: 8 additions & 0 deletions test/form/side-effect-h/_expected/es.js
@@ -1,3 +1,11 @@
function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}

foo();

var main = 42;

export default main;
8 changes: 8 additions & 0 deletions test/form/side-effect-h/_expected/iife.js
@@ -1,6 +1,14 @@
var myBundle = (function () {
'use strict';

function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}

foo();

var main = 42;

return main;
Expand Down
10 changes: 9 additions & 1 deletion test/form/side-effect-h/_expected/umd.js
Expand Up @@ -4,8 +4,16 @@
(global.myBundle = factory());
}(this, (function () { 'use strict';

function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}

foo();

var main = 42;

return main;

})));
})));
6 changes: 6 additions & 0 deletions test/form/side-effect-t/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'throw statement is a side effect',
options: {
moduleName: 'myBundle'
}
};
9 changes: 9 additions & 0 deletions test/form/side-effect-t/_expected/amd.js
@@ -0,0 +1,9 @@
define(function () { 'use strict';

function foo () {
throw new Error( 'throw side effect' );
}

foo();

});
7 changes: 7 additions & 0 deletions test/form/side-effect-t/_expected/cjs.js
@@ -0,0 +1,7 @@
'use strict';

function foo () {
throw new Error( 'throw side effect' );
}

foo();
5 changes: 5 additions & 0 deletions test/form/side-effect-t/_expected/es.js
@@ -0,0 +1,5 @@
function foo () {
throw new Error( 'throw side effect' );
}

foo();
10 changes: 10 additions & 0 deletions test/form/side-effect-t/_expected/iife.js
@@ -0,0 +1,10 @@
(function () {
'use strict';

function foo () {
throw new Error( 'throw side effect' );
}

foo();

}());
13 changes: 13 additions & 0 deletions test/form/side-effect-t/_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 () {
throw new Error( 'throw side effect' );
}

foo();

})));
5 changes: 5 additions & 0 deletions test/form/side-effect-t/main.js
@@ -0,0 +1,5 @@
function foo () {
throw new Error( 'throw side effect' );
}

foo();

0 comments on commit f2d0851

Please sign in to comment.