From aa59aa316df2f6f0718a4f080ab3fd74b2043318 Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 16:42:56 +0800 Subject: [PATCH 1/6] refactor(*): replace self compare with `isNumberNaN` --- src/Angular.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index fef4278ff2b2..6f704013b148 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -987,8 +987,7 @@ function copy(source, destination, maxDepth) { } -// eslint-disable-next-line no-self-compare -function simpleCompare(a, b) { return a === b || (a !== a && b !== b); } +function simpleCompare(a, b) { return a === b || (isNumberNaN(a) && isNumberNaN(b)); } /** From 887b7760a2883d37aafc1b8e9a9f0fc5350309bc Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 16:48:12 +0800 Subject: [PATCH 2/6] refactor(*): replace self compare with `isNumberNaN` --- src/Angular.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 6f704013b148..d64bcf445d0d 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1056,8 +1056,7 @@ function simpleCompare(a, b) { return a === b || (isNumberNaN(a) && isNumberNaN( function equals(o1, o2) { if (o1 === o2) return true; if (o1 === null || o2 === null) return false; - // eslint-disable-next-line no-self-compare - if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN + if (isNumberNaN(o1) && isNumberNaN(o2)) return true; // NaN === NaN var t1 = typeof o1, t2 = typeof o2, length, key, keySet; if (t1 === t2 && t1 === 'object') { if (isArray(o1)) { From 85fc6efeb54b863b46f970abce89fe18c48d505a Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 16:52:28 +0800 Subject: [PATCH 3/6] refactor(*): replace self compare with `isNumberNaN` --- src/ng/parse.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 91a1b363e6c4..ebd437484673 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -1843,9 +1843,8 @@ function $ParseProvider() { // fall-through to the primitive equality check } - //Primitive or NaN - // eslint-disable-next-line no-self-compare - return newValue === oldValueOfValue || (newValue !== newValue && oldValueOfValue !== oldValueOfValue); + // Primitive or NaN + return newValue === oldValueOfValue || (isNumberNaN(newValue) && isNumberNaN(oldValueOfValue)); } function inputsWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) { From 6b10ae2d14aca8010a9c8c77fbec35cc7a4a1169 Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 16:57:50 +0800 Subject: [PATCH 4/6] refactor(*): replace self compare with `isNumberNaN` --- src/ng/rootScope.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index e145c5102611..530457cfdc29 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -635,8 +635,7 @@ function $RootScopeProvider() { oldItem = oldValue[i]; newItem = newValue[i]; - // eslint-disable-next-line no-self-compare - bothNaN = (oldItem !== oldItem) && (newItem !== newItem); + bothNaN = isNumberNaN(oldItem) && isNumberNaN(newItem); if (!bothNaN && (oldItem !== newItem)) { changeDetected++; oldValue[i] = newItem; @@ -658,8 +657,7 @@ function $RootScopeProvider() { oldItem = oldValue[key]; if (key in oldValue) { - // eslint-disable-next-line no-self-compare - bothNaN = (oldItem !== oldItem) && (newItem !== newItem); + bothNaN = isNumberNaN(oldItem) && isNumberNaN(newItem); if (!bothNaN && (oldItem !== newItem)) { changeDetected++; oldValue[key] = newItem; From 57aec1491a8b9b724e3114b9a5564dade9e570a6 Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 17:01:27 +0800 Subject: [PATCH 5/6] refactor(*): replace self compare with `isNumberNaN` --- src/ng/directive/ngModel.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 5d73c33ceb28..b97eabb0b59d 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -368,8 +368,7 @@ NgModelController.prototype = { * @returns {boolean} True if `value` is "empty". */ $isEmpty: function(value) { - // eslint-disable-next-line no-self-compare - return isUndefined(value) || value === '' || value === null || value !== value; + return isUndefined(value) || value === '' || value === null || isNumberNaN(value); }, $$updateEmptyClasses: function(value) { From 2d98c6c291abea39ea7e2c8b03db275a892a0f93 Mon Sep 17 00:00:00 2001 From: william-pan Date: Sun, 8 Jul 2018 17:06:08 +0800 Subject: [PATCH 6/6] refactor(*): replace self compare with `isNumberNaN` --- src/ng/directive/ngModel.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index b97eabb0b59d..1450977abe49 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -1087,8 +1087,7 @@ function setupModelWatcher(ctrl) { // case where the model is changed in the ngChange function or the model setter if (modelValue !== ctrl.$modelValue && // checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator - // eslint-disable-next-line no-self-compare - (ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue) + !(isNumberNaN(ctrl.$modelValue) && isNumberNaN(modelValue)) ) { ctrl.$$setModelValue(modelValue); }