Skip to content

Commit 9d80823

Browse files
committed
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...
1 parent ef01362 commit 9d80823

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

src/Compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ Compiler.prototype = {
229229
template = new Template();
230230
eachAttribute(element, function(value, name){
231231
if (!widget) {
232-
if (widget = self.widgets('@' + name)) {
232+
if ((widget = self.widgets('@' + name))) {
233233
element.addClass('ng-attr-widget');
234234
widget = bind(selfApi, widget, value, element);
235235
}
236236
}
237237
});
238238
if (!widget) {
239-
if (widget = self.widgets(elementName)) {
239+
if ((widget = self.widgets(elementName))) {
240240
if (elementNamespace)
241241
element.addClass('ng-widget');
242242
widget = bind(selfApi, widget, element);

src/Scope.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Scope.prototype = {
343343
scope.$service('$exceptionHandler')(e);
344344
}
345345
}
346-
if (watchers = scope.$$watchers) {
346+
if ((watchers = scope.$$watchers)) {
347347
// process our watches
348348
length = watchers.length;
349349
while (length--) {
@@ -372,7 +372,7 @@ Scope.prototype = {
372372
}
373373
} while (scope !== this);
374374
}
375-
} while (scope = next);
375+
} while ((scope = next));
376376

377377
if(!(ttl--)) {
378378
throw Error('100 $digest() iterations reached. Aborting!');

src/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ angularDirective("ng:bind", function(expression, element){
230230
// If we are HTML than save the raw HTML data so that we don't
231231
// recompute sanitization since it is expensive.
232232
// TODO: turn this into a more generic way to compute this
233-
if (isHtml = (value instanceof HTML))
233+
if ((isHtml = (value instanceof HTML)))
234234
value = (html = value).html;
235235
if (lastValue === value && lastError == error) return;
236236
isDomElement = isElement(value);

src/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ angularFilter.linky = function(text) {
610610
var writer = htmlSanitizeWriter(html);
611611
var url;
612612
var i;
613-
while (match = raw.match(LINKY_URL_REGEXP)) {
613+
while ((match = raw.match(LINKY_URL_REGEXP))) {
614614
// We can not end in these as they are sometimes found at the end of the sentence
615615
url = match[0];
616616
// if we did not match ftp/http/mailto then assume mailto

src/parser.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ function parser(text, json){
421421
var left = logicalOR();
422422
var right;
423423
var token;
424-
if (token = expect('=')) {
424+
if ((token = expect('='))) {
425425
if (!left.assign) {
426426
throwError("implies assignment but [" +
427427
text.substring(0, token.index) + "] can not be assigned to", token);
@@ -468,7 +468,7 @@ function parser(text, json){
468468
function relational(){
469469
var left = additive();
470470
var token;
471-
if (token = expect('<', '>', '<=', '>=')) {
471+
if ((token = expect('<', '>', '<=', '>='))) {
472472
left = binaryFn(left, token.fn, relational());
473473
}
474474
return left;
@@ -477,7 +477,7 @@ function parser(text, json){
477477
function additive(){
478478
var left = multiplicative();
479479
var token;
480-
while(token = expect('+','-')) {
480+
while ((token = expect('+','-'))) {
481481
left = binaryFn(left, token.fn, multiplicative());
482482
}
483483
return left;
@@ -486,7 +486,7 @@ function parser(text, json){
486486
function multiplicative(){
487487
var left = unary();
488488
var token;
489-
while(token = expect('*','/','%')) {
489+
while ((token = expect('*','/','%'))) {
490490
left = binaryFn(left, token.fn, unary());
491491
}
492492
return left;
@@ -496,9 +496,9 @@ function parser(text, json){
496496
var token;
497497
if (expect('+')) {
498498
return primary();
499-
} else if (token = expect('-')) {
499+
} else if ((token = expect('-'))) {
500500
return binaryFn(ZERO, token.fn, unary());
501-
} else if (token = expect('!')) {
501+
} else if ((token = expect('!'))) {
502502
return unaryFn(token.fn, unary());
503503
} else {
504504
return primary();
@@ -539,7 +539,7 @@ function parser(text, json){
539539
}
540540
}
541541
var next;
542-
while (next = expect('(', '[', '.')) {
542+
while ((next = expect('(', '[', '.'))) {
543543
if (next.text === '(') {
544544
primary = functionCall(primary);
545545
} else if (next.text === '[') {

src/service/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ angularServiceInject('$route', function($location) {
216216
// Match a route
217217
forEach(routes, function(rParams, rPath) {
218218
if (!pathParams) {
219-
if (pathParams = matcher($location.hashPath, rPath)) {
219+
if ((pathParams = matcher($location.hashPath, rPath))) {
220220
selectedRoute = rParams;
221221
}
222222
}

src/service/xhr.cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
5252

5353
if (method == 'GET') {
5454
var data, dataCached;
55-
if (dataCached = cache.data[url]) {
55+
if ((dataCached = cache.data[url])) {
5656

5757
if (sync) {
5858
success(200, copy(dataCached.value));
@@ -64,7 +64,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
6464
return;
6565
}
6666

67-
if (data = inflight[url]) {
67+
if ((data = inflight[url])) {
6868
data.successes.push(success);
6969
data.errors.push(error);
7070
} else {

src/widgets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ angularWidget('select', function(element){
877877
lastElement = null; // start at the begining
878878
for(index = 0, length = optionGroup.length; index < length; index++) {
879879
option = optionGroup[index];
880-
if (existingOption = existingOptions[index+1]) {
880+
if ((existingOption = existingOptions[index+1])) {
881881
// reuse elements
882882
lastElement = existingOption.element;
883883
if (existingOption.label !== option.label) {
@@ -1116,7 +1116,7 @@ angularWidget('ng:switch', function (element) {
11161116

11171117
this.$watch(watchExpr, function(scope, value) {
11181118
element.html('');
1119-
if (selectedTemplate = casesTemplate[value] || defaultCaseTemplate) {
1119+
if ((selectedTemplate = casesTemplate[value] || defaultCaseTemplate)) {
11201120
changeCounter++;
11211121
if (childScope) childScope.$destroy();
11221122
childScope = scope.$new();

0 commit comments

Comments
 (0)