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) { var manualLowercase = function (s) {
return isString(s) ? s.replace(/[A-Z]/g, return isString(s)
function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); }) : s; ? s.replace(/[A-Z]/g, function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); })
: s;
}; };
var manualUppercase = function (s) { var manualUppercase = function (s) {
return isString(s) ? s.replace(/[a-z]/g, return isString(s)
function (ch) {return fromCharCode(ch.charCodeAt(0) & ~32); }) : 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 jQuery, // delay binding
slice = Array.prototype.slice, slice = Array.prototype.slice,
push = Array.prototype.push, 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 */ /** @name angular */
angular = window[$angular] || (window[$angular] = {}), angular = window[$angular] || (window[$angular] = {}),
@ -417,13 +421,13 @@ function isElement(node) {
*/ */
function HTML(html, option) { function HTML(html, option) {
this.html = html; this.html = html;
this.get = lowercase(option) == 'unsafe' ? this.get = lowercase(option) == 'unsafe'
valueFn(html) : ? valueFn(html)
function htmlSanitize() { : function htmlSanitize() {
var buf = []; var buf = [];
htmlParser(html, htmlSanitizeWriter(buf)); htmlParser(html, htmlSanitizeWriter(buf));
return buf.join(''); return buf.join('');
}; };
} }
if (msie) { if (msie) {

View file

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

View file

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

View file

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

View file

@ -107,9 +107,9 @@ function lex(text, parseStringsForObjects){
function throwError(error, start, end) { function throwError(error, start, end) {
end = end || index; end = end || index;
throw Error("Lexer Error: " + error + " at column" + throw Error("Lexer Error: " + error + " at column" +
(isDefined(start) ? (isDefined(start)
"s " + start + "-" + index + " [" + text.substring(start, end) + "]" : ? "s " + start + "-" + index + " [" + text.substring(start, end) + "]"
" " + end) + : " " + end) +
" in expression [" + text + "]."); " in expression [" + text + "].");
} }
@ -199,8 +199,9 @@ function lex(text, parseStringsForObjects){
index++; index++;
tokens.push({index:start, text:rawString, string:string, json:true, tokens.push({index:start, text:rawString, string:string, json:true,
fn:function(){ fn:function(){
return (string.length == dateParseLength) ? return (string.length == dateParseLength)
angular['String']['toDate'](string) : string; ? angular['String']['toDate'](string)
: string;
}}); }});
return; return;
} else { } else {
@ -588,9 +589,9 @@ function parser(text, json){
} }
var fnPtr = fn(self) || noop; var fnPtr = fn(self) || noop;
// IE stupidity! // IE stupidity!
return fnPtr.apply ? return fnPtr.apply
fnPtr.apply(self, args) : ? fnPtr.apply(self, args)
fnPtr(args[0], args[1], args[2], args[3], args[4]); : 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) { _jQuery.fn.bindings = function(name) {
function contains(text, value) { function contains(text, value) {
return value instanceof RegExp ? return value instanceof RegExp
value.test(text) : ? value.test(text)
text && text.indexOf(value) >= 0; : text && text.indexOf(value) >= 0;
} }
var result = []; var result = [];
this.find('.ng-binding:visible').each(function() { this.find('.ng-binding:visible').each(function() {

View file

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

View file

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