From 9d808239b3120b0120f164834ce3012f779c8939 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sun, 14 Aug 2011 01:26:56 -0700 Subject: style(*): wrap all assignments in if statements we commonly assign stuff in if statments like this: if (variable = someFn()) { //do something with variable } This results in lint and IDE warnings (did you mean ==?). It is better to be explicit about our intention and wrap the assignement into parens: if ((variable = someFn())) { //do something with variable } Doing so suppresses warnings + is easier to understand the intention. I verified that the closure compiler strips the extra parens, so there is no byte overhead for this safety practice. We should use this style going forward... --- src/Compiler.js | 4 ++-- src/Scope.js | 4 ++-- src/directives.js | 2 +- src/filters.js | 2 +- src/parser.js | 14 +++++++------- src/service/route.js | 2 +- src/service/xhr.cache.js | 4 ++-- src/widgets.js | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Compiler.js b/src/Compiler.js index 98e9630c..0001f8af 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -229,14 +229,14 @@ Compiler.prototype = { template = new Template(); eachAttribute(element, function(value, name){ if (!widget) { - if (widget = self.widgets('@' + name)) { + if ((widget = self.widgets('@' + name))) { element.addClass('ng-attr-widget'); widget = bind(selfApi, widget, value, element); } } }); if (!widget) { - if (widget = self.widgets(elementName)) { + if ((widget = self.widgets(elementName))) { if (elementNamespace) element.addClass('ng-widget'); widget = bind(selfApi, widget, element); diff --git a/src/Scope.js b/src/Scope.js index b50d6273..6e90ea66 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -343,7 +343,7 @@ Scope.prototype = { scope.$service('$exceptionHandler')(e); } } - if (watchers = scope.$$watchers) { + if ((watchers = scope.$$watchers)) { // process our watches length = watchers.length; while (length--) { @@ -372,7 +372,7 @@ Scope.prototype = { } } while (scope !== this); } - } while (scope = next); + } while ((scope = next)); if(!(ttl--)) { throw Error('100 $digest() iterations reached. Aborting!'); diff --git a/src/directives.js b/src/directives.js index 937d0cca..54d7feb2 100644 --- a/src/directives.js +++ b/src/directives.js @@ -230,7 +230,7 @@ angularDirective("ng:bind", function(expression, element){ // If we are HTML than save the raw HTML data so that we don't // recompute sanitization since it is expensive. // TODO: turn this into a more generic way to compute this - if (isHtml = (value instanceof HTML)) + if ((isHtml = (value instanceof HTML))) value = (html = value).html; if (lastValue === value && lastError == error) return; isDomElement = isElement(value); diff --git a/src/filters.js b/src/filters.js index f636b242..67e30046 100644 --- a/src/filters.js +++ b/src/filters.js @@ -610,7 +610,7 @@ angularFilter.linky = function(text) { var writer = htmlSanitizeWriter(html); var url; var i; - while (match = raw.match(LINKY_URL_REGEXP)) { + while ((match = raw.match(LINKY_URL_REGEXP))) { // We can not end in these as they are sometimes found at the end of the sentence url = match[0]; // if we did not match ftp/http/mailto then assume mailto diff --git a/src/parser.js b/src/parser.js index dadab1fb..5129f2f7 100644 --- a/src/parser.js +++ b/src/parser.js @@ -421,7 +421,7 @@ function parser(text, json){ var left = logicalOR(); var right; var token; - if (token = expect('=')) { + if ((token = expect('='))) { if (!left.assign) { throwError("implies assignment but [" + text.substring(0, token.index) + "] can not be assigned to", token); @@ -468,7 +468,7 @@ function parser(text, json){ function relational(){ var left = additive(); var token; - if (token = expect('<', '>', '<=', '>=')) { + if ((token = expect('<', '>', '<=', '>='))) { left = binaryFn(left, token.fn, relational()); } return left; @@ -477,7 +477,7 @@ function parser(text, json){ function additive(){ var left = multiplicative(); var token; - while(token = expect('+','-')) { + while ((token = expect('+','-'))) { left = binaryFn(left, token.fn, multiplicative()); } return left; @@ -486,7 +486,7 @@ function parser(text, json){ function multiplicative(){ var left = unary(); var token; - while(token = expect('*','/','%')) { + while ((token = expect('*','/','%'))) { left = binaryFn(left, token.fn, unary()); } return left; @@ -496,9 +496,9 @@ function parser(text, json){ var token; if (expect('+')) { return primary(); - } else if (token = expect('-')) { + } else if ((token = expect('-'))) { return binaryFn(ZERO, token.fn, unary()); - } else if (token = expect('!')) { + } else if ((token = expect('!'))) { return unaryFn(token.fn, unary()); } else { return primary(); @@ -539,7 +539,7 @@ function parser(text, json){ } } var next; - while (next = expect('(', '[', '.')) { + while ((next = expect('(', '[', '.'))) { if (next.text === '(') { primary = functionCall(primary); } else if (next.text === '[') { diff --git a/src/service/route.js b/src/service/route.js index 9b4db0dd..5741c940 100644 --- a/src/service/route.js +++ b/src/service/route.js @@ -216,7 +216,7 @@ angularServiceInject('$route', function($location) { // Match a route forEach(routes, function(rParams, rPath) { if (!pathParams) { - if (pathParams = matcher($location.hashPath, rPath)) { + if ((pathParams = matcher($location.hashPath, rPath))) { selectedRoute = rParams; } } diff --git a/src/service/xhr.cache.js b/src/service/xhr.cache.js index 256b936e..14051c40 100644 --- a/src/service/xhr.cache.js +++ b/src/service/xhr.cache.js @@ -52,7 +52,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) { if (method == 'GET') { var data, dataCached; - if (dataCached = cache.data[url]) { + if ((dataCached = cache.data[url])) { if (sync) { success(200, copy(dataCached.value)); @@ -64,7 +64,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) { return; } - if (data = inflight[url]) { + if ((data = inflight[url])) { data.successes.push(success); data.errors.push(error); } else { diff --git a/src/widgets.js b/src/widgets.js index d9af21c9..30f7256a 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -877,7 +877,7 @@ angularWidget('select', function(element){ lastElement = null; // start at the begining for(index = 0, length = optionGroup.length; index < length; index++) { option = optionGroup[index]; - if (existingOption = existingOptions[index+1]) { + if ((existingOption = existingOptions[index+1])) { // reuse elements lastElement = existingOption.element; if (existingOption.label !== option.label) { @@ -1116,7 +1116,7 @@ angularWidget('ng:switch', function (element) { this.$watch(watchExpr, function(scope, value) { element.html(''); - if (selectedTemplate = casesTemplate[value] || defaultCaseTemplate) { + if ((selectedTemplate = casesTemplate[value] || defaultCaseTemplate)) { changeCounter++; if (childScope) childScope.$destroy(); childScope = scope.$new(); -- cgit v1.2.3