reformated multiline trinary expressions to have a leading ?/:.

This commit is contained in:
Misko Hevery 2011-02-12 08:58:11 -08:00
parent 00cc9eb32a
commit cdc093a463
8 changed files with 57 additions and 48 deletions

View file

@ -30,12 +30,14 @@ var uppercase = function (string){ return isString(string) ? string.toUpperCase(
var manualLowercase = function (s) {
return isString(s) ? s.replace(/[A-Z]/g,
function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); }) : s;
return isString(s)
? s.replace(/[A-Z]/g, function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); })
: s;
};
var manualUppercase = function (s) {
return isString(s) ? s.replace(/[a-z]/g,
function (ch) {return fromCharCode(ch.charCodeAt(0) & ~32); }) : s;
return isString(s)
? s.replace(/[a-z]/g, function (ch) {return fromCharCode(ch.charCodeAt(0) & ~32); })
: s;
};
@ -89,7 +91,9 @@ var _undefined = undefined,
jQuery, // delay binding
slice = Array.prototype.slice,
push = Array.prototype.push,
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
error = window[$console]
? bind(window[$console], window[$console]['error'] || noop)
: noop,
/** @name angular */
angular = window[$angular] || (window[$angular] = {}),
@ -417,13 +421,13 @@ function isElement(node) {
*/
function HTML(html, option) {
this.html = html;
this.get = lowercase(option) == 'unsafe' ?
valueFn(html) :
function htmlSanitize() {
var buf = [];
htmlParser(html, htmlSanitizeWriter(buf));
return buf.join('');
};
this.get = lowercase(option) == 'unsafe'
? valueFn(html)
: function htmlSanitize() {
var buf = [];
htmlParser(html, htmlSanitizeWriter(buf));
return buf.join('');
};
}
if (msie) {

View file

@ -637,8 +637,9 @@ var angularArray = {
return 0;
}
function reverse(comp, descending) {
return toBoolean(descending) ?
function(a,b){return comp(b,a);} : comp;
return toBoolean(descending)
? function(a,b){return comp(b,a);}
: comp;
}
function compare(v1, v2){
var t1 = typeof v1;

View file

@ -243,15 +243,17 @@ function compileBindTemplate(template){
var bindings = [];
forEach(parseBindings(template), function(text){
var exp = binding(text);
bindings.push(exp ? function(element){
var error, value = this.$tryEval(exp, function(e){
error = toJson(e);
});
elementError(element, NG_EXCEPTION, error);
return error ? error : value;
} : function() {
return text;
});
bindings.push(exp
? function(element){
var error, value = this.$tryEval(exp, function(e){
error = toJson(e);
});
elementError(element, NG_EXCEPTION, error);
return error ? error : value;
}
: function() {
return text;
});
});
bindTemplateCache[template] = fn = function(element, prettyPrintJson){
var parts = [], self = this,

View file

@ -5,12 +5,12 @@
var jqCache = {},
jqName = 'ng-' + new Date().getTime(),
jqId = 1,
addEventListenerFn = (window.document.addEventListener ?
function(element, type, fn) {element.addEventListener(type, fn, false);} :
function(element, type, fn) {element.attachEvent('on' + type, fn);}),
removeEventListenerFn = (window.document.removeEventListener ?
function(element, type, fn) {element.removeEventListener(type, fn, false); } :
function(element, type, fn) {element.detachEvent('on' + type, fn); });
addEventListenerFn = (window.document.addEventListener
? function(element, type, fn) {element.addEventListener(type, fn, false);}
: function(element, type, fn) {element.attachEvent('on' + type, fn);}),
removeEventListenerFn = (window.document.removeEventListener
? function(element, type, fn) {element.removeEventListener(type, fn, false); }
: function(element, type, fn) {element.detachEvent('on' + type, fn); });
function jqNextId() { return (jqId++); }

View file

@ -107,9 +107,9 @@ function lex(text, parseStringsForObjects){
function throwError(error, start, end) {
end = end || index;
throw Error("Lexer Error: " + error + " at column" +
(isDefined(start) ?
"s " + start + "-" + index + " [" + text.substring(start, end) + "]" :
" " + end) +
(isDefined(start)
? "s " + start + "-" + index + " [" + text.substring(start, end) + "]"
: " " + end) +
" in expression [" + text + "].");
}
@ -199,8 +199,9 @@ function lex(text, parseStringsForObjects){
index++;
tokens.push({index:start, text:rawString, string:string, json:true,
fn:function(){
return (string.length == dateParseLength) ?
angular['String']['toDate'](string) : string;
return (string.length == dateParseLength)
? angular['String']['toDate'](string)
: string;
}});
return;
} else {
@ -588,9 +589,9 @@ function parser(text, json){
}
var fnPtr = fn(self) || noop;
// IE stupidity!
return fnPtr.apply ?
fnPtr.apply(self, args) :
fnPtr(args[0], args[1], args[2], args[3], args[4]);
return fnPtr.apply
? fnPtr.apply(self, args)
: fnPtr(args[0], args[1], args[2], args[3], args[4]);
};
}

View file

@ -309,9 +309,9 @@ function browserTrigger(element, type) {
*/
_jQuery.fn.bindings = function(name) {
function contains(text, value) {
return value instanceof RegExp ?
value.test(text) :
text && text.indexOf(value) >= 0;
return value instanceof RegExp
? value.test(text)
: text && text.indexOf(value) >= 0;
}
var result = [];
this.find('.ng-binding:visible').each(function() {

View file

@ -181,8 +181,9 @@ extend(angularValidator, {
return (date &&
date.getFullYear() == fields[3] &&
date.getMonth() == fields[1]-1 &&
date.getDate() == fields[2]) ?
_null : "Value is not a date. (Expecting format: 12/31/2009).";
date.getDate() == fields[2])
? _null
: "Value is not a date. (Expecting format: 12/31/2009).";
},
/**

View file

@ -337,9 +337,9 @@ function valueAccessor(scope, element) {
invalidWidgets.markValid(element);
} else {
var error, validateScope = inherit(scope, {$element:element});
error = required && !value ?
'Required' :
(value ? validator(validateScope, value) : _null);
error = required && !value
? 'Required'
: (value ? validator(validateScope, value) : _null);
elementError(element, NG_VALIDATION_ERROR, error);
lastError = error;
if (error) {
@ -940,9 +940,9 @@ angularWidget("@ng:repeat", function(expression, element){
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
childScope.$index = index;
childScope.$position = index == 0 ?
'first' :
(index == collectionLength - 1 ? 'last' : 'middle');
childScope.$position = index == 0
? 'first'
: (index == collectionLength - 1 ? 'last' : 'middle');
lastElement.after(cloneElement = element.cloneNode());
cloneElement.attr('ng:repeat-index', index);
linker(childScope, cloneElement);