X Tutup
Skip to content

Commit 24cd700

Browse files
lucastetreaultpetebacondarwin
authored andcommitted
refactor(*): use isDefined and isUndefined consistently
Fix any place that compares with `undefined` to use `isUndefined` and `isDefined` instead. Closes angular#4365 Closes angular#12831
1 parent e46ab43 commit 24cd700

File tree

22 files changed

+39
-39
lines changed

22 files changed

+39
-39
lines changed

src/Angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ function equals(o1, o2) {
977977
for (key in o2) {
978978
if (!(key in keySet) &&
979979
key.charAt(0) !== '$' &&
980-
o2[key] !== undefined &&
980+
isDefined(o2[key]) &&
981981
!isFunction(o2[key])) return false;
982982
}
983983
return true;

src/jqLite.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ function jqLiteInheritedData(element, name, value) {
450450

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

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

700700
// we are a write, but the object properties are the key/values
@@ -715,7 +715,7 @@ forEach({
715715
// TODO: do we still need this?
716716
var value = fn.$dv;
717717
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
718-
var jj = (value === undefined) ? Math.min(nodeCount, 1) : nodeCount;
718+
var jj = (isUndefined(value)) ? Math.min(nodeCount, 1) : nodeCount;
719719
for (var j = 0; j < jj; j++) {
720720
var nodeValue = fn(this[j], arg1, arg2);
721721
value = value ? value + nodeValue : nodeValue;

src/ng/cacheFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767
$scope.keys = [];
6868
$scope.cache = $cacheFactory('cacheId');
6969
$scope.put = function(key, value) {
70-
if ($scope.cache.get(key) === undefined) {
70+
if (isUndefined($scope.cache.get(key))) {
7171
$scope.keys.push(key);
7272
}
73-
$scope.cache.put(key, value === undefined ? null : value);
73+
$scope.cache.put(key, isUndefined(value) ? null : value);
7474
};
7575
}]);
7676
</file>

src/ng/compile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11651165
}
11661166

11671167
if (writeAttr !== false) {
1168-
if (value === null || value === undefined) {
1168+
if (value === null || isUndefined(value)) {
11691169
this.$$element.removeAttr(attrName);
11701170
} else {
11711171
this.$$element.attr(attrName, value);
@@ -2131,7 +2131,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
21312131
i = 0, ii = directives.length; i < ii; i++) {
21322132
try {
21332133
directive = directives[i];
2134-
if ((maxPriority === undefined || maxPriority > directive.priority) &&
2134+
if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
21352135
directive.restrict.indexOf(location) != -1) {
21362136
if (startAttrName) {
21372137
directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});

src/ng/cookieReader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function $$CookieReader($document) {
3939
// the first value that is seen for a cookie is the most
4040
// specific one. values for the same cookie name that
4141
// follow are for less specific paths.
42-
if (lastCookies[name] === undefined) {
42+
if (isUndefined(lastCookies[name])) {
4343
lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1));
4444
}
4545
}

src/ng/directive/ngBind.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var ngBindDirective = ['$compile', function($compile) {
6060
$compile.$$addBindingInfo(element, attr.ngBind);
6161
element = element[0];
6262
scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
63-
element.textContent = value === undefined ? '' : value;
63+
element.textContent = isUndefined(value) ? '' : value;
6464
});
6565
};
6666
}
@@ -128,7 +128,7 @@ var ngBindTemplateDirective = ['$interpolate', '$compile', function($interpolate
128128
$compile.$$addBindingInfo(element, interpolateFn.expressions);
129129
element = element[0];
130130
attr.$observe('ngBindTemplate', function(value) {
131-
element.textContent = value === undefined ? '' : value;
131+
element.textContent = isUndefined(value) ? '' : value;
132132
});
133133
};
134134
}

src/ng/directive/ngModel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
556556

557557
function processParseErrors() {
558558
var errorKey = ctrl.$$parserName || 'parse';
559-
if (parserValid === undefined) {
559+
if (isUndefined(parserValid)) {
560560
setValidity(errorKey, null);
561561
} else {
562562
if (!parserValid) {
@@ -1242,7 +1242,7 @@ var ngModelOptionsDirective = function() {
12421242
var that = this;
12431243
this.$options = copy($scope.$eval($attrs.ngModelOptions));
12441244
// Allow adding/overriding bound events
1245-
if (this.$options.updateOn !== undefined) {
1245+
if (isDefined(this.$options.updateOn)) {
12461246
this.$options.updateOnDefault = false;
12471247
// extract "default" pseudo-event from list of events that can trigger a model update
12481248
this.$options.updateOn = trim(this.$options.updateOn.replace(DEFAULT_REGEXP, function() {
@@ -1272,7 +1272,7 @@ function addSetValidityMethod(context) {
12721272
ctrl.$setValidity = setValidity;
12731273

12741274
function setValidity(validationErrorKey, state, controller) {
1275-
if (state === undefined) {
1275+
if (isUndefined(state)) {
12761276
createAndSet('$pending', validationErrorKey, controller);
12771277
} else {
12781278
unsetAndCleanup('$pending', validationErrorKey, controller);

src/ng/httpBackend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
126126

127127
function completeRequest(callback, status, response, headersString, statusText) {
128128
// cancel timeout and subsequent timeout promise resolution
129-
if (timeoutId !== undefined) {
129+
if (isDefined(timeoutId)) {
130130
$browserDefer.cancel(timeoutId);
131131
}
132132
jsonpDone = xhr = null;

src/ng/location.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
141141
var appUrl, prevAppUrl;
142142
var rewrittenUrl;
143143

144-
if ((appUrl = beginsWith(appBase, url)) !== undefined) {
144+
if (isDefined(appUrl = beginsWith(appBase, url))) {
145145
prevAppUrl = appUrl;
146-
if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) {
146+
if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) {
147147
rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
148148
} else {
149149
rewrittenUrl = appBase + prevAppUrl;
150150
}
151-
} else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) {
151+
} else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) {
152152
rewrittenUrl = appBaseNoFile + appUrl;
153153
} else if (appBaseNoFile == url + '/') {
154154
rewrittenUrl = appBaseNoFile;

src/ng/sce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function $SceDelegateProvider() {
294294
'Attempted to trust a value in invalid context. Context: {0}; Value: {1}',
295295
type, trustedValue);
296296
}
297-
if (trustedValue === null || trustedValue === undefined || trustedValue === '') {
297+
if (trustedValue === null || isUndefined(trustedValue) || trustedValue === '') {
298298
return trustedValue;
299299
}
300300
// All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting
@@ -349,7 +349,7 @@ function $SceDelegateProvider() {
349349
* `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception.
350350
*/
351351
function getTrusted(type, maybeTrusted) {
352-
if (maybeTrusted === null || maybeTrusted === undefined || maybeTrusted === '') {
352+
if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
353353
return maybeTrusted;
354354
}
355355
var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);

0 commit comments

Comments
 (0)
X Tutup