Browse Source

handle NaN

better-aggressive
Rich-Harris 9 years ago
parent
commit
4580b4bf54
  1. 6
      src/ast/conditions.js
  2. 2
      test/function/skips-dead-branches-d/_config.js
  3. 2
      test/function/skips-dead-branches-e/_config.js
  4. 9
      test/function/skips-dead-branches-f/_config.js
  5. 11
      test/function/skips-dead-branches-f/main.js

6
src/ast/conditions.js

@ -8,8 +8,8 @@ function isNotEqualTest ( node ) {
function nodesAreEqual ( a, b ) { function nodesAreEqual ( a, b ) {
if ( a.type !== b.type ) return false; if ( a.type !== b.type ) return false;
if ( a.type === 'Literal' ) return a.value === b.value; if ( a.type === 'Literal' ) return a.value === b.value
if ( a.type === 'Identifier' ) return a.name === b.name; if ( a.type === 'Identifier' ) return a.name === b.name && a.name !== 'NaN';
return false; return false;
} }
@ -17,7 +17,7 @@ function nodesAreEqual ( a, b ) {
function nodesAreNotEqual ( a, b ) { function nodesAreNotEqual ( a, b ) {
if ( a.type !== b.type ) return false; if ( a.type !== b.type ) return false;
if ( a.type === 'Literal' ) return a.value != b.value; if ( a.type === 'Literal' ) return a.value != b.value;
if ( a.type === 'Identifier' ) return a.name != b.name; if ( a.type === 'Identifier' ) return a.name != b.name || a.name === 'NaN';
return false; return false;
} }

2
test/function/skips-dead-branches-d/_config.js

@ -1,7 +1,7 @@
var assert = require( 'assert' ); var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'skips a dead branch (c)', description: 'skips a dead branch (d)',
code: function ( code ) { code: function ( code ) {
assert.equal( code.indexOf( 'obj.foo = function' ), -1, code ); assert.equal( code.indexOf( 'obj.foo = function' ), -1, code );
} }

2
test/function/skips-dead-branches-e/_config.js

@ -1,7 +1,7 @@
var assert = require( 'assert' ); var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'skips a dead branch (c)', description: 'skips a dead branch (e)',
code: function ( code ) { code: function ( code ) {
assert.equal( code.indexOf( 'obj.foo = function' ), -1, code ); assert.equal( code.indexOf( 'obj.foo = function' ), -1, code );
} }

9
test/function/skips-dead-branches-f/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
module.exports = {
solo: true,
description: 'skips a dead branch (f)',
code: function ( code ) {
assert.equal( code.indexOf( 'obj.foo = function' ), -1, code );
}
}

11
test/function/skips-dead-branches-f/main.js

@ -0,0 +1,11 @@
var obj = {};
obj.foo = function () {
console.log( 'this should be excluded' );
}
function bar () {
console.log( 'this should be included' );
}
if ( NaN === NaN ) obj.foo();
bar();
Loading…
Cancel
Save