Browse Source

`throw` always considered to be a side effect

gh-1187
kzc 8 years ago
parent
commit
f2d0851f12
  1. 4
      src/ast/nodes/ThrowStatement.js
  2. 2
      test/form/side-effect-h/_config.js
  3. 8
      test/form/side-effect-h/_expected/amd.js
  4. 8
      test/form/side-effect-h/_expected/cjs.js
  5. 8
      test/form/side-effect-h/_expected/es.js
  6. 8
      test/form/side-effect-h/_expected/iife.js
  7. 10
      test/form/side-effect-h/_expected/umd.js
  8. 6
      test/form/side-effect-t/_config.js
  9. 9
      test/form/side-effect-t/_expected/amd.js
  10. 7
      test/form/side-effect-t/_expected/cjs.js
  11. 5
      test/form/side-effect-t/_expected/es.js
  12. 10
      test/form/side-effect-t/_expected/iife.js
  13. 13
      test/form/side-effect-t/_expected/umd.js
  14. 5
      test/form/side-effect-t/main.js

4
src/ast/nodes/ThrowStatement.js

@ -1,7 +1,7 @@
import Node from '../Node.js'; import Node from '../Node.js';
export default class ThrowStatement extends Node { export default class ThrowStatement extends Node {
hasEffects ( scope ) { hasEffects () {
return scope.findLexicalBoundary().isModuleScope; // TODO should this just be `true`? probably... return true;
} }
} }

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

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

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

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

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

@ -1,5 +1,13 @@
'use strict'; 'use strict';
function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}
foo();
var main = 42; var main = 42;
module.exports = main; module.exports = main;

8
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; var main = 42;
export default main; export default main;

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

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

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

@ -4,8 +4,16 @@
(global.myBundle = factory()); (global.myBundle = factory());
}(this, (function () { 'use strict'; }(this, (function () { 'use strict';
function foo ( ok ) {
if ( !ok ) {
throw new Error( 'this will be ignored' );
}
}
foo();
var main = 42; var main = 42;
return main; return main;
}))); })));

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

@ -0,0 +1,6 @@
module.exports = {
description: 'throw statement is a side effect',
options: {
moduleName: 'myBundle'
}
};

9
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
test/form/side-effect-t/_expected/cjs.js

@ -0,0 +1,7 @@
'use strict';
function foo () {
throw new Error( 'throw side effect' );
}
foo();

5
test/form/side-effect-t/_expected/es.js

@ -0,0 +1,5 @@
function foo () {
throw new Error( 'throw side effect' );
}
foo();

10
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
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
test/form/side-effect-t/main.js

@ -0,0 +1,5 @@
function foo () {
throw new Error( 'throw side effect' );
}
foo();
Loading…
Cancel
Save