Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor: use isDefined and isUndefined consistently #12831

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ function equals(o1, o2) {
for (key in o2) {
if (!(key in keySet) &&
key.charAt(0) !== '$' &&
o2[key] !== undefined &&
isDefined(o2[key]) &&
!isFunction(o2[key])) return false;
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function jqLiteInheritedData(element, name, value) {

while (element) {
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = jqLite.data(element, names[i])) !== undefined) return value;
if (isDefined(value = jqLite.data(element, names[i]))) return value;
}

// If dealing with a document fragment node with a host element, and no parent, use the host
Expand Down Expand Up @@ -694,7 +694,7 @@ forEach({
// in a way that survives minification.
// jqLiteEmpty takes no arguments but is a setter.
if (fn !== jqLiteEmpty &&
(((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2) === undefined)) {
(isUndefined((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2))) {
if (isObject(arg1)) {

// we are a write, but the object properties are the key/values
Expand All @@ -715,7 +715,7 @@ forEach({
// TODO: do we still need this?
var value = fn.$dv;
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
var jj = (value === undefined) ? Math.min(nodeCount, 1) : nodeCount;
var jj = (isUndefined(value)) ? Math.min(nodeCount, 1) : nodeCount;
for (var j = 0; j < jj; j++) {
var nodeValue = fn(this[j], arg1, arg2);
value = value ? value + nodeValue : nodeValue;
Expand Down
4 changes: 2 additions & 2 deletions src/ng/cacheFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
$scope.keys = [];
$scope.cache = $cacheFactory('cacheId');
$scope.put = function(key, value) {
if ($scope.cache.get(key) === undefined) {
if (isUndefined($scope.cache.get(key))) {
$scope.keys.push(key);
}
$scope.cache.put(key, value === undefined ? null : value);
$scope.cache.put(key, isUndefined(value) ? null : value);
};
}]);
</file>
Expand Down
4 changes: 2 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}

if (writeAttr !== false) {
if (value === null || value === undefined) {
if (value === null || isUndefined(value)) {
this.$$element.removeAttr(attrName);
} else {
this.$$element.attr(attrName, value);
Expand Down Expand Up @@ -2131,7 +2131,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
i = 0, ii = directives.length; i < ii; i++) {
try {
directive = directives[i];
if ((maxPriority === undefined || maxPriority > directive.priority) &&
if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
directive.restrict.indexOf(location) != -1) {
if (startAttrName) {
directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
Expand Down
2 changes: 1 addition & 1 deletion src/ng/cookieReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function $$CookieReader($document) {
// the first value that is seen for a cookie is the most
// specific one. values for the same cookie name that
// follow are for less specific paths.
if (lastCookies[name] === undefined) {
if (isUndefined(lastCookies[name])) {
lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var ngBindDirective = ['$compile', function($compile) {
$compile.$$addBindingInfo(element, attr.ngBind);
element = element[0];
scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
element.textContent = value === undefined ? '' : value;
element.textContent = isUndefined(value) ? '' : value;
});
};
}
Expand Down Expand Up @@ -128,7 +128,7 @@ var ngBindTemplateDirective = ['$interpolate', '$compile', function($interpolate
$compile.$$addBindingInfo(element, interpolateFn.expressions);
element = element[0];
attr.$observe('ngBindTemplate', function(value) {
element.textContent = value === undefined ? '' : value;
element.textContent = isUndefined(value) ? '' : value;
});
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$

function processParseErrors() {
var errorKey = ctrl.$$parserName || 'parse';
if (parserValid === undefined) {
if (isUndefined(parserValid)) {
setValidity(errorKey, null);
} else {
if (!parserValid) {
Expand Down Expand Up @@ -1242,7 +1242,7 @@ var ngModelOptionsDirective = function() {
var that = this;
this.$options = copy($scope.$eval($attrs.ngModelOptions));
// Allow adding/overriding bound events
if (this.$options.updateOn !== undefined) {
if (isDefined(this.$options.updateOn)) {
this.$options.updateOnDefault = false;
// extract "default" pseudo-event from list of events that can trigger a model update
this.$options.updateOn = trim(this.$options.updateOn.replace(DEFAULT_REGEXP, function() {
Expand Down Expand Up @@ -1272,7 +1272,7 @@ function addSetValidityMethod(context) {
ctrl.$setValidity = setValidity;

function setValidity(validationErrorKey, state, controller) {
if (state === undefined) {
if (isUndefined(state)) {
createAndSet('$pending', validationErrorKey, controller);
} else {
unsetAndCleanup('$pending', validationErrorKey, controller);
Expand Down
2 changes: 1 addition & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc

function completeRequest(callback, status, response, headersString, statusText) {
// cancel timeout and subsequent timeout promise resolution
if (timeoutId !== undefined) {
if (isDefined(timeoutId)) {
$browserDefer.cancel(timeoutId);
}
jsonpDone = xhr = null;
Expand Down
6 changes: 3 additions & 3 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
var appUrl, prevAppUrl;
var rewrittenUrl;

if ((appUrl = beginsWith(appBase, url)) !== undefined) {
if (isDefined(appUrl = beginsWith(appBase, url))) {
prevAppUrl = appUrl;
if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) {
if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) {
rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
} else {
rewrittenUrl = appBase + prevAppUrl;
}
} else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) {
} else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) {
rewrittenUrl = appBaseNoFile + appUrl;
} else if (appBaseNoFile == url + '/') {
rewrittenUrl = appBaseNoFile;
Expand Down
4 changes: 2 additions & 2 deletions src/ng/sce.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function $SceDelegateProvider() {
'Attempted to trust a value in invalid context. Context: {0}; Value: {1}',
type, trustedValue);
}
if (trustedValue === null || trustedValue === undefined || trustedValue === '') {
if (trustedValue === null || isUndefined(trustedValue) || trustedValue === '') {
return trustedValue;
}
// All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting
Expand Down Expand Up @@ -349,7 +349,7 @@ function $SceDelegateProvider() {
* `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception.
*/
function getTrusted(type, maybeTrusted) {
if (maybeTrusted === null || maybeTrusted === undefined || maybeTrusted === '') {
if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
return maybeTrusted;
}
var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
Expand Down
4 changes: 2 additions & 2 deletions src/ngAnimate/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMA
// Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
// therefore there is no reason to test anymore for other vendor prefixes:
// http://caniuse.com/#search=transition
if (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {
if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionend)) {
CSS_PREFIX = '-webkit-';
TRANSITION_PROP = 'WebkitTransition';
TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
Expand All @@ -45,7 +45,7 @@ if (window.ontransitionend === undefined && window.onwebkittransitionend !== und
TRANSITIONEND_EVENT = 'transitionend';
}

if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {
if (isUndefined(window.onanimationend) && isDefined(window.onwebkitanimationend)) {
CSS_PREFIX = '-webkit-';
ANIMATION_PROP = 'WebkitAnimation';
ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
Expand Down
2 changes: 1 addition & 1 deletion src/ngCookies/cookieWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function $$CookieWriter($document, $log, $browser) {
options = options || {};
expires = options.expires;
path = angular.isDefined(options.path) ? options.path : cookiePath;
if (value === undefined) {
if (angular.isUndefined(value)) {
expires = 'Thu, 01 Jan 1970 00:00:00 GMT';
value = '';
}
Expand Down
6 changes: 3 additions & 3 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ angular.mock.$Browser = function() {
if (fn.id === deferId) fnIndex = index;
});

if (fnIndex !== undefined) {
if (angular.isDefined(fnIndex)) {
self.deferredFns.splice(fnIndex, 1);
return true;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ angular.mock.$IntervalProvider = function() {
if (fn.id === promise.$$intervalId) fnIndex = index;
});

if (fnIndex !== undefined) {
if (angular.isDefined(fnIndex)) {
repeatFns.splice(fnIndex, 1);
}
}
Expand Down Expand Up @@ -504,7 +504,7 @@ angular.mock.$IntervalProvider = function() {
if (fn.id === promise.$$intervalId) fnIndex = index;
});

if (fnIndex !== undefined) {
if (angular.isDefined(fnIndex)) {
repeatFns[fnIndex].deferred.reject('canceled');
repeatFns.splice(fnIndex, 1);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function lookupDottedPath(obj, path) {
throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path);
}
var keys = path.split('.');
for (var i = 0, ii = keys.length; i < ii && obj !== undefined; i++) {
for (var i = 0, ii = keys.length; i < ii && angular.isDefined(obj); i++) {
var key = keys[i];
obj = (obj !== null) ? obj[key] : undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ngScenario/Scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ _jQuery.fn.bindings = function(windowJquery, bindExp) {
}

function push(value) {
if (value === undefined) {
if (angular.isUndefined(value)) {
value = '';
} else if (typeof value !== 'string') {
value = angular.toJson(value);
Expand Down
6 changes: 3 additions & 3 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ describe('$http', function() {
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
return headers['accept'] == 'Rewritten' &&
headers['content-type'] == 'Content-Type Rewritten' &&
headers['Accept'] === undefined &&
headers['Content-Type'] === undefined;
isUndefined(headers['Accept']) &&
isUndefined(headers['Content-Type']);
}).respond('');

$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
Expand All @@ -779,7 +779,7 @@ describe('$http', function() {
mockedCookies['XSRF-TOKEN'] = 'secret';
$browser.url('http://host.com/base');
$httpBackend.expect('GET', 'http://www.test.com/url', undefined, function(headers) {
return headers['X-XSRF-TOKEN'] === undefined;
return isUndefined(headers['X-XSRF-TOKEN']);
}).respond('');

$http({url: 'http://www.test.com/url', method: 'GET', headers: {}});
Expand Down
2 changes: 1 addition & 1 deletion test/ng/intervalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('$interval', function() {
if (fn.id === id) fnIndex = index;
});

if (fnIndex !== undefined) {
if (isDefined(fnIndex)) {
repeatFns.splice(fnIndex, 1);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/ng/qSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('q', function() {
log.push(logPrefix + '->throw(' + _argToString(returnVal) + ')');
throw returnVal;
} else {
if (returnVal === undefined) {
if (isUndefined(returnVal)) {
log.push(logPrefix);
} else {
log.push(logPrefix + '->' + _argToString(returnVal));
Expand Down
4 changes: 2 additions & 2 deletions test/ng/sceSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ describe('SCE', function() {
function runTest(cfg, testFn) {
return function() {
module(function($sceDelegateProvider) {
if (cfg.whiteList !== undefined) {
if (isDefined(cfg.whiteList)) {
$sceDelegateProvider.resourceUrlWhitelist(cfg.whiteList);
}
if (cfg.blackList !== undefined) {
if (isDefined(cfg.blackList)) {
$sceDelegateProvider.resourceUrlBlacklist(cfg.blackList);
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/ngCookies/cookieWriterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ describe('cookie options', function() {
.reduce(function(prev, value) {
var pair = value.split('=', 2);
if (pair[0] === key) {
if (prev === undefined) {
return pair[1] === undefined ? true : pair[1];
if (isUndefined(prev)) {
return isUndefined(pair[1]) ? true : pair[1];
} else {
throw 'duplicate key in cookie string';
}
Expand Down
2 changes: 1 addition & 1 deletion test/ngScenario/matchersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('angular.scenario.matchers', function() {
function expectMatcher(value, test) {
delete matchers.error;
delete matchers.future.value;
if (value !== undefined) {
if (isDefined(value)) {
matchers.future.value = value;
}
test();
Expand Down