stringify names for better compression, remove dead functions, removed underscore.js compatibility

This commit is contained in:
Misko Hevery 2010-08-18 16:23:12 -07:00
parent 1087270c95
commit 5ddd8d9586
23 changed files with 155 additions and 257 deletions

View file

@ -1,25 +1,42 @@
////////////////////////////////////
if (typeof document.getAttribute == 'undefined')
if (typeof document.getAttribute == $undefined)
document.getAttribute = function() {};
var consoleNode,
NULL = null,
UNDEFIEND = undefined,
var _undefined = undefined,
_null = null,
$$element = '$element',
$angular = 'angular',
$array = 'array',
$boolean = 'boolean',
$console = 'console',
$date = 'date',
$display = 'display',
$element = 'element',
$function = 'function',
$length = 'length',
$name = 'name',
$none = 'none',
$noop = 'noop',
$null = 'null',
$number = 'number',
$object = 'object',
$string = 'string',
$undefined = 'undefined',
NG_EXCEPTION = 'ng-exception',
NG_VALIDATION_ERROR = 'ng-validation-error',
NOOP = 'noop',
PRIORITY_FIRST = -99999,
PRIORITY_WATCH = -1000,
PRIORITY_LAST = 99999,
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
NOOP = 'noop',
NG_EXCEPTION = 'ng-exception',
NG_VALIDATION_ERROR = 'ng-validation-error',
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
_ = window['_'],
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
jqLite = jQuery || jqLiteWrap,
slice = Array.prototype.slice,
error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop,
angular = window['angular'] || (window['angular'] = {}),
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
angular = window[$angular] || (window[$angular] = {}),
angularTextMarkup = extensionMap(angular, 'markup'),
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
angularDirective = extensionMap(angular, 'directive'),
@ -36,7 +53,7 @@ function foreach(obj, iterator, context) {
if (obj) {
if (isFunction(obj)){
for (key in obj) {
if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) {
if (key != 'prototype' && key != $length && key != $name && obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key);
}
}
@ -93,7 +110,7 @@ function extensionMap(angular, name, transform) {
}
function jqLiteWrap(element) {
// for some reasons the parentNode of an orphan looks like null but its typeof is object.
// for some reasons the parentNode of an orphan looks like _null but its typeof is object.
if (element) {
if (isString(element)) {
var div = document.createElement('div');
@ -105,13 +122,13 @@ function jqLiteWrap(element) {
}
return element;
}
function isUndefined(value){ return typeof value == 'undefined'; }
function isDefined(value){ return typeof value != 'undefined'; }
function isObject(value){ return value!=null && typeof value == 'object';}
function isUndefined(value){ return typeof value == $undefined; }
function isDefined(value){ return typeof value != $undefined; }
function isObject(value){ return value!=_null && typeof value == 'object';}
function isString(value){ return typeof value == 'string';}
function isNumber(value){ return typeof value == 'number';}
function isArray(value) { return value instanceof Array; }
function isFunction(value){ return typeof value == 'function';}
function isFunction(value){ return typeof value == $function;}
function isTextNode(node) { return nodeName(node) == '#text'; }
function lowercase(value){ return isString(value) ? value.toLowerCase() : value; }
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
@ -295,7 +312,7 @@ function escapeAttr(html) {
function bind(self, fn) {
var curryArgs = arguments.length > 2 ? slice.call(arguments, 2, arguments.length) : [];
if (typeof fn == 'function') {
if (typeof fn == $function) {
return curryArgs.length ? function() {
return arguments.length ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length))) : fn.apply(self, curryArgs);
}: function() {
@ -321,7 +338,7 @@ function merge(src, dst) {
for ( var key in src) {
var value = dst[key];
var type = typeof value;
if (type == 'undefined') {
if (type == $undefined) {
dst[key] = fromJson(toJson(src[key]));
} else if (type == 'object' && value.constructor != array &&
key.substring(0, 1) != "$") {
@ -361,7 +378,7 @@ function toKeyValue(obj) {
function angularInit(config){
if (config.autobind) {
// TODO default to the source of angular.js
var scope = compile(window.document, null, {'$config':config});
var scope = compile(window.document, _null, {'$config':config});
if (config.css)
scope.$browser.addCss(config.base_url + config.css);
scope.$init();

View file

@ -57,7 +57,7 @@ Browser.prototype = {
xhr: function(method, url, post, callback){
if (isFunction(post)) {
callback = post;
post = null;
post = _null;
}
if (lowercase(method) == 'json') {
var callbackId = "angular_" + Math.random() + '_' + (this.idCounter++);
@ -67,7 +67,7 @@ Browser.prototype = {
script.src = url.replace('JSON_CALLBACK', callbackId);
this.head.append(script);
window[callbackId] = function(data){
window[callbackId] = undefined;
window[callbackId] = _undefined;
callback(200, data);
};
} else {

View file

@ -181,7 +181,7 @@ Compiler.prototype = {
template.addChild(i, self.templatize(child, i, priority));
});
}
return template.empty() ? null : template;
return template.empty() ? _null : template;
}
};

View file

@ -2,7 +2,7 @@ var array = [].constructor;
function toJson(obj, pretty){
var buf = [];
toJsonArray(buf, obj, pretty ? "\n " : null, []);
toJsonArray(buf, obj, pretty ? "\n " : _null, []);
return buf.join('');
}
@ -31,21 +31,21 @@ function toJsonArray(buf, obj, pretty, stack){
stack.push(obj);
}
var type = typeof obj;
if (obj === null) {
buf.push("null");
} else if (type === 'function') {
if (obj === _null) {
buf.push($null);
} else if (type === $function) {
return;
} else if (type === 'boolean') {
} else if (type === $boolean) {
buf.push('' + obj);
} else if (type === 'number') {
} else if (type === $number) {
if (isNaN(obj)) {
buf.push('null');
buf.push($null);
} else {
buf.push('' + obj);
}
} else if (type === 'string') {
} else if (type === $string) {
return buf.push(angular['String']['quoteUnicode'](obj));
} else if (type === 'object') {
} else if (type === $object) {
if (obj instanceof Array) {
buf.push("[");
var len = obj.length;
@ -53,8 +53,8 @@ function toJsonArray(buf, obj, pretty, stack){
for(var i=0; i<len; i++) {
var item = obj[i];
if (sep) buf.push(",");
if (typeof item == 'function' || typeof item == 'undefined') {
buf.push("null");
if (typeof item == $function || typeof item == $undefined) {
buf.push($null);
} else {
toJsonArray(buf, item, pretty, stack);
}
@ -70,7 +70,7 @@ function toJsonArray(buf, obj, pretty, stack){
var childPretty = pretty ? pretty + " " : false;
var keys = [];
for(var k in obj) {
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === undefined)
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === _undefined)
continue;
keys.push(k);
}
@ -79,7 +79,7 @@ function toJsonArray(buf, obj, pretty, stack){
var key = keys[keyIndex];
try {
var value = obj[key];
if (typeof value != 'function') {
if (typeof value != $function) {
if (comma) {
buf.push(",");
if (pretty) buf.push(pretty);
@ -95,7 +95,7 @@ function toJsonArray(buf, obj, pretty, stack){
buf.push("}");
}
}
if (typeof obj == "object") {
if (typeof obj == $object) {
stack.pop();
}
}

View file

@ -7,10 +7,10 @@ function Lexer(text, parsStrings){
}
Lexer.OPERATORS = {
'null':function(self){return null;},
'null':function(self){return _null;},
'true':function(self){return true;},
'false':function(self){return false;},
'undefined':noop,
$undefined:noop,
'+':function(self, a,b){return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
'-':function(self, a,b){return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
'*':function(self, a,b){return a*b;},
@ -490,7 +490,7 @@ Parser.prototype = {
if (instance)
instance = instance[key];
}
if (typeof instance != 'function') {
if (typeof instance != $function) {
throw "Function '" + token.text + "' at column '" +
(token.index+1) + "' in '" + this.text + "' is not defined.";
}
@ -507,10 +507,6 @@ Parser.prototype = {
primary = this.arrayDeclaration();
} else if (this.expect('{')) {
primary = this.object();
} else if (this.expect('{:')) {
primary = this.closure(false);
} else if (this.expect('{(')) {
primary = this.closure(true);
} else {
var token = this.expect();
primary = token.fn;
@ -533,32 +529,6 @@ Parser.prototype = {
return primary;
},
closure: function(hasArgs) {
var args = [];
if (hasArgs) {
if (!this.expect(')')) {
args.push(this.expect().text);
while(this.expect(',')) {
args.push(this.expect().text);
}
this.consume(')');
}
this.consume(":");
}
var statements = this.statements();
this.consume("}");
return function(self) {
return function($){
var scope = createScope(self);
scope['$'] = $;
for ( var i = 0; i < args.length; i++) {
setter(scope, args[i], arguments[i]);
}
return statements(scope);
};
};
},
fieldAccess: function(object) {
var field = this.expect().text;
var getter = getterFn(field);
@ -581,7 +551,7 @@ Parser.prototype = {
return function (self){
var o = obj(self);
var i = indexFn(self);
return (o) ? o[i] : undefined;
return (o) ? o[i] : _undefined;
};
}
},
@ -601,8 +571,8 @@ Parser.prototype = {
}
var fnPtr = fn(self) || noop;
// IE stupidity!
return fnPtr.apply ?
fnPtr.apply(self, args) :
return fnPtr.apply ?
fnPtr.apply(self, args) :
fnPtr(args[0], args[1], args[2], args[3], args[4]);
};
},
@ -648,51 +618,6 @@ Parser.prototype = {
};
},
entityDeclaration: function () {
var decl = [];
while(this.hasTokens()) {
decl.push(this.entityDecl());
if (!this.expect(';')) {
this.assertAllConsumed();
}
}
return function (self){
var code = "";
for ( var i = 0; i < decl.length; i++) {
code += decl[i](self);
}
return code;
};
},
entityDecl: function () {
var entity = this.expect().text;
var instance;
var defaults;
if (this.expect('=')) {
instance = entity;
entity = this.expect().text;
}
if (this.expect(':')) {
defaults = this.primary()(null);
}
return function(self) {
var Entity = self.datastore.entity(entity, defaults);
setter(self, entity, Entity);
if (instance) {
var document = Entity();
document['$$anchor'] = instance;
setter(self, instance, document);
return "$anchor." + instance + ":{" +
instance + "=" + entity + ".load($anchor." + instance + ");" +
instance + ".$$anchor=" + angular['String']['quote'](instance) + ";" +
"};";
} else {
return "";
}
};
},
watch: function () {
var decl = [];
while(this.hasTokens()) {

View file

@ -124,7 +124,7 @@ ResourceFactory.prototype = {
var callback = noop;
switch(arguments.length) {
case 2: params = a1; callback = a2;
case 1: if (typeof a1 == 'function') callback = a1; else params = a1;
case 1: if (typeof a1 == $function) callback = a1; else params = a1;
case 0: break;
default:
throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments.";

View file

@ -15,7 +15,7 @@ function getter(instance, path, unboundFn) {
if (isUndefined(instance) && key.charAt(0) == '$') {
var type = angular['Global']['typeOf'](lastInstance);
type = angular[type.charAt(0).toUpperCase()+type.substring(1)];
var fn = type ? type[[key.substring(1)]] : undefined;
var fn = type ? type[[key.substring(1)]] : _undefined;
if (fn) {
instance = bind(lastInstance, fn, lastInstance);
return instance;
@ -50,37 +50,37 @@ var scopeId = 0;
JS_KEYWORDS = {};
foreach(
["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default",
"delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto",
"if", "implements", "import", "ininstanceof", "intinterface", "long", "native", "new", "null", "package", "private",
"delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", $function, "goto",
"if", "implements", "import", "ininstanceof", "intinterface", "long", "native", "new", $null, "package", "private",
"protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws",
"transient", "true", "try", "typeof", "var", "volatile", "void", "while", "with"],
"transient", "true", "try", "typeof", "var", "volatile", "void", $undefined, "while", "with"],
function(key){ JS_KEYWORDS[key] = true;}
);
function getterFn(path){
var fn = getterFnCache[path];
if (fn) return fn;
var code = 'function (self){\n';
code += ' var last, fn, type;\n';
var code = 'function (s){\n';
code += ' var l, fn, t;\n';
foreach(path.split('.'), function(key) {
key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key;
code += ' if(!self) return self;\n';
code += ' last = self;\n';
code += ' self = self' + key + ';\n';
code += ' if(typeof self == "function") \n';
code += ' self = function(){ return last'+key+'.apply(last, arguments); };\n';
code += ' if(!s) return s;\n';
code += ' l = s;\n';
code += ' s = s' + key + ';\n';
code += ' if(typeof s == "'+$function+'") \n';
code += ' s = function(){ return l'+key+'.apply(l, arguments); };\n';
if (key.charAt(1) == '$') {
// special code for super-imposed functions
var name = key.substr(2);
code += ' if(!self) {\n';
code += ' type = angular.Global.typeOf(last);\n';
code += ' fn = (angular[type.charAt(0).toUpperCase() + type.substring(1)]||{})["' + name + '"];\n';
code += ' if(!s) {\n';
code += ' t = angular.Global.typeOf(l);\n';
code += ' fn = (angular[t.charAt(0).toUpperCase() + t.substring(1)]||{})["' + name + '"];\n';
code += ' if (fn)\n';
code += ' self = function(){ return fn.apply(last, [last].concat(Array.prototype.slice.call(arguments, 0, arguments.length))); };\n';
code += ' s = function(){ return fn.apply(l, [l].concat(Array.prototype.slice.call(arguments, 0, arguments.length))); };\n';
code += ' }\n';
}
});
code += ' return self;\n}';
code += ' return s;\n}';
fn = eval('fn = ' + code);
fn["toString"] = function(){ return code; };
@ -90,7 +90,7 @@ function getterFn(path){
///////////////////////////////////
function expressionCompile(exp){
if (typeof exp === 'function') return exp;
if (typeof exp === $function) return exp;
var fn = compileCache[exp];
if (!fn) {
var parser = new Parser(exp);
@ -130,7 +130,7 @@ function createScope(parent, services, existing) {
$eval: function $eval(exp) {
var type = typeof exp;
if (type == 'undefined') {
if (type == $undefined) {
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
for ( var queue = evalLists.sorted[i],
jSize = queue.length,
@ -138,7 +138,7 @@ function createScope(parent, services, existing) {
instance.$tryEval(queue[j].fn, queue[j].handler);
}
}
} else if (type === 'function') {
} else if (type === $function) {
return exp.call(instance);
} else if (type === 'string') {
return expressionCompile(exp).call(instance);
@ -148,7 +148,7 @@ function createScope(parent, services, existing) {
$tryEval: function (expression, exceptionHandler) {
var type = typeof expression;
try {
if (type == 'function') {
if (type == $function) {
return expression.call(instance);
} else if (type == 'string'){
return expressionCompile(expression).call(instance);

View file

@ -1,11 +1,11 @@
var angularGlobal = {
'typeOf':function(obj){
if (obj === null) return "null";
if (obj === _null) return $null;
var type = typeof obj;
if (type == "object") {
if (obj instanceof Array) return "array";
if (obj instanceof Date) return "date";
if (obj.nodeType == 1) return "element";
if (type == $object) {
if (obj instanceof Array) return $array;
if (obj instanceof Date) return $date;
if (obj.nodeType == 1) return $element;
}
return type;
}
@ -102,7 +102,7 @@ var angularArray = {
}
}
break;
case "function":
case $function:
predicates.push(expression);
break;
default:
@ -236,34 +236,18 @@ var angularFunction = {
}
};
function defineApi(dst, chain, underscoreNames){
if (_) {
var lastChain = _.last(chain);
foreach(underscoreNames, function(name){
lastChain[name] = _[name];
});
}
function defineApi(dst, chain){
angular[dst] = angular[dst] || {};
foreach(chain, function(parent){
extend(angular[dst], parent);
});
}
defineApi('Global', [angularGlobal],
['extend', 'clone','isEqual',
'isElement', 'isArray', 'isFunction', 'isUndefined']);
defineApi('Collection', [angularGlobal, angularCollection],
['each', 'map', 'reduce', 'reduceRight', 'detect',
'select', 'reject', 'all', 'any', 'include',
'invoke', 'pluck', 'max', 'min', 'sortBy',
'sortedIndex', 'toArray', 'size']);
defineApi('Array', [angularGlobal, angularCollection, angularArray],
['first', 'last', 'compact', 'flatten', 'without',
'uniq', 'intersect', 'zip', 'indexOf', 'lastIndexOf']);
defineApi('Object', [angularGlobal, angularCollection, angularObject],
['keys', 'values']);
defineApi('String', [angularGlobal, angularString], []);
defineApi('Date', [angularGlobal, angularDate], []);
defineApi('Global', [angularGlobal]);
defineApi('Collection', [angularGlobal, angularCollection]);
defineApi('Array', [angularGlobal, angularCollection, angularArray]);
defineApi('Object', [angularGlobal, angularCollection, angularObject]);
defineApi('String', [angularGlobal, angularString]);
defineApi('Date', [angularGlobal, angularDate]);
//IE bug
angular['Date']['toString'] = angularDate['toString'];
defineApi('Function', [angularGlobal, angularCollection, angularFunction],
['bind', 'bindAll', 'delay', 'defer', 'wrap', 'compose']);
defineApi('Function', [angularGlobal, angularCollection, angularFunction]);

View file

@ -27,7 +27,7 @@ angularDirective("ng:bind", function(expression){
var lastValue = noop, lastError = noop;
this.$onEval(function() {
var error, value, isHtml, isDomElement,
oldElement = this.hasOwnProperty('$element') ? this.$element : undefined;
oldElement = this.hasOwnProperty($$element) ? this.$element : _undefined;
this.$element = element;
value = this.$tryEval(expression, function(e){
error = toJson(e);
@ -76,7 +76,7 @@ function compileBindTemplate(template){
});
bindTemplateCache[template] = fn = function(element){
var parts = [], self = this,
oldElement = this.hasOwnProperty('$element') ? self.$element : undefined;
oldElement = this.hasOwnProperty($$element) ? self.$element : _undefined;
self.$element = element;
for ( var i = 0; i < bindings.length; i++) {
var value = bindings[i].call(self, element);
@ -242,7 +242,7 @@ angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;}));
angularDirective("ng:show", function(expression, element){
return function(element){
this.$onEval(function(){
element.css('display', toBoolean(this.$eval(expression)) ? '' : 'none');
element.css($display, toBoolean(this.$eval(expression)) ? '' : $none);
}, element);
};
});
@ -250,7 +250,7 @@ angularDirective("ng:show", function(expression, element){
angularDirective("ng:hide", function(expression, element){
return function(element){
this.$onEval(function(){
element.css('display', toBoolean(this.$eval(expression)) ? 'none' : '');
element.css($display, toBoolean(this.$eval(expression)) ? $none : '');
}, element);
};
});
@ -261,7 +261,7 @@ angularDirective("ng:style", function(expression, element){
this.$onEval(function(){
var style = this.$eval(expression) || {}, key, mergedStyle = {};
for(key in style) {
if (resetStyle[key] === undefined) resetStyle[key] = '';
if (resetStyle[key] === _undefined) resetStyle[key] = '';
mergedStyle[key] = style[key];
}
for(key in resetStyle) {

View file

@ -7,7 +7,7 @@ angularFilter.number = function(amount, fractionSize){
if (isNaN(amount) || !isFinite(amount)) {
return '';
}
fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize;
fractionSize = typeof fractionSize == $undefined ? 2 : fractionSize;
var isNegative = amount < 0;
amount = Math.abs(amount);
var pow = Math.pow(10, fractionSize);

View file

@ -1,6 +1,6 @@
function formatter(format, parse) {return {'format':format, 'parse':parse || format};}
function toString(obj) {
return (isDefined(obj) && obj !== null) ? "" + obj : obj;
return (isDefined(obj) && obj !== _null) ? "" + obj : obj;
}
var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
@ -9,8 +9,8 @@ angularFormatter.noop = formatter(identity, identity);
angularFormatter.json = formatter(toJson, fromJson);
angularFormatter['boolean'] = formatter(toString, toBoolean);
angularFormatter.number = formatter(toString, function(obj){
if (obj == null || NUMBER.exec(obj)) {
return obj===null || obj === '' ? null : 1*obj;
if (obj == _null || NUMBER.exec(obj)) {
return obj===_null || obj === '' ? _null : 1*obj;
} else {
throw "Not a number";
}

View file

@ -70,7 +70,7 @@ JQLite.prototype = {
}
cache[key] = value;
} else {
return cache ? cache[key] : null;
return cache ? cache[key] : _null;
}
},
@ -115,7 +115,7 @@ JQLite.prototype = {
trigger: function(type) {
var evnt = document.createEvent('MouseEvent');
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, _null);
this[0].dispatchEvent(evnt);
},
@ -195,8 +195,8 @@ JQLite.prototype = {
e.setAttribute(name, value);
} else {
var attributes = e.attributes,
item = attributes ? attributes.getNamedItem(name) : undefined;
return item && item.specified ? item.value : undefined;
item = attributes ? attributes.getNamedItem(name) : _undefined;
return item && item.specified ? item.value : _undefined;
}
},

View file

@ -20,11 +20,11 @@ function parseBindings(string) {
function binding(string) {
var binding = string.replace(/\n/gm, ' ').match(/^\{\{(.*)\}\}$/);
return binding ? binding[1] : null;
return binding ? binding[1] : _null;
}
function hasBindings(bindings) {
return bindings.length > 1 || binding(bindings[0]) !== null;
return bindings.length > 1 || binding(bindings[0]) !== _null;
}
angularTextMarkup('{{}}', function(text, textNode, parentElement) {
@ -61,7 +61,7 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) {
angularTextMarkup('OPTION', function(text, textNode, parentElement){
if (nodeName(parentElement) == "OPTION") {
var select = document.createElement('select');
select.insertBefore(parentElement[0].cloneNode(true), null);
select.insertBefore(parentElement[0].cloneNode(true), _null);
if (!select.innerHTML.match(/<option(\s.*\s|\s)value\s*=\s*.*>.*<\/\s*option\s*>/gi)) {
parentElement.attr('value', text);
}

View file

@ -2,7 +2,7 @@ function Future(name, behavior) {
this.name = name;
this.behavior = behavior;
this.fulfilled = false;
this.value = undefined;
this.value = _undefined;
}
Future.prototype = {

View file

@ -42,7 +42,7 @@ angular.scenario.Runner = function(scope, jQuery){
} finally {
afterEach();
}
self.currentSpec = null;
self.currentSpec = _null;
};
this.logger = function returnNoop(){
return extend(returnNoop, {close:noop, fail:noop});
@ -144,7 +144,7 @@ angular.scenario.Runner.prototype = {
function done() {
result.finished = true;
futureLogger.close();
self.self = null;
self.self = _null;
(callback||noop).call(specThis);
}
function next(value){
@ -153,7 +153,7 @@ angular.scenario.Runner.prototype = {
}
var future = spec.futures[spec.nextFutureIndex];
(result.log || {close:noop}).close();
result.log = null;
result.log = _null;
if (future) {
spec.nextFutureIndex ++;
result.log = futureLogger('future', future.name);

View file

@ -40,7 +40,7 @@ angularService("$location", function(browser){
}
function check(param) {
return lastLocation[param] == location[param] ? undefined : location[param];
return lastLocation[param] == location[param] ? _undefined : location[param];
}
function checkProtocol(){
@ -49,9 +49,9 @@ angularService("$location", function(browser){
lastLocation.port === location.port &&
lastLocation.path === location.path &&
equals(lastLocation.search, location.search))
return undefined;
return _undefined;
var url = toKeyValue(location.search);
var port = (location.port == DEFAULT_PORTS[location.protocol] ? null : location.port);
var port = (location.port == DEFAULT_PORTS[location.protocol] ? _null : location.port);
return location.protocol + '://' + location.host +
(port ? ':' + port : '') + location.path +
(url ? '?' + url : '');
@ -60,7 +60,7 @@ angularService("$location", function(browser){
function checkHashPathSearch(){
if (lastLocation.hashPath === location.hashPath &&
equals(lastLocation.hashSearch, location.hashSearch) )
return undefined;
return _undefined;
var url = toKeyValue(location.hashSearch);
return escape(location.hashPath) + (url ? '?' + url : '');
}
@ -72,7 +72,7 @@ angularService("$location", function(browser){
location.href = url.replace('#$', '');
location.protocol = match[1];
location.host = match[3] || '';
location.port = match[5] || DEFAULT_PORTS[location.protocol] || null;
location.port = match[5] || DEFAULT_PORTS[location.protocol] || _null;
location.path = match[6];
location.search = parseKeyValue(match[8]);
location.hash = match[10] || '';
@ -149,7 +149,7 @@ angularService("$hover", function(browser, document) {
}
} else if (tooltip) {
tooltip.callout.remove();
tooltip = null;
tooltip = _null;
}
});
}, {inject:['$browser', '$document']});
@ -211,7 +211,7 @@ function switchRouteMatcher(on, when, dstName) {
});
if (dstName) this.$set(dstName, dst);
}
return match ? dst : null;
return match ? dst : _null;
}
angularService('$route', function(location){
@ -234,7 +234,7 @@ angularService('$route', function(location){
};
function updateRoute(){
var childScope;
$route.current = null;
$route.current = _null;
angular.foreach(routes, function(routeParams, route) {
if (!childScope) {
var pathParams = matcher(location.hashPath, route);
@ -262,7 +262,7 @@ angularService('$xhr', function($browser, $error, $log){
return function(method, url, post, callback){
if (isFunction(post)) {
callback = post;
post = null;
post = _null;
}
if (post && isObject(post)) {
post = toJson(post);
@ -300,7 +300,7 @@ angularService('$xhr.bulk', function($xhr, $error, $log){
function bulkXHR(method, url, post, callback) {
if (isFunction(post)) {
callback = post;
post = null;
post = _null;
}
var currentQueue;
foreach(bulkXHR.urls, function(queue){
@ -349,7 +349,7 @@ angularService('$xhr.cache', function($xhr){
function cache(method, url, post, callback, verifyCache){
if (isFunction(post)) {
callback = post;
post = null;
post = _null;
}
if (method == 'GET') {
var data;

View file

@ -1,25 +1,25 @@
foreach({
'noop': function() { return null; },
'noop': function() { return _null; },
'regexp': function(value, regexp, msg) {
if (!value.match(regexp)) {
return msg ||
"Value does not match expected format " + regexp + ".";
} else {
return null;
return _null;
}
},
'number': function(value, min, max) {
var num = 1 * value;
if (num == value) {
if (typeof min != 'undefined' && num < min) {
if (typeof min != $undefined && num < min) {
return "Value can not be less than " + min + ".";
}
if (typeof min != 'undefined' && num > max) {
if (typeof min != $undefined && num > max) {
return "Value can not be greater than " + max + ".";
}
return null;
return _null;
} else {
return "Not a number";
}
@ -31,43 +31,43 @@ foreach({
if (!("" + value).match(/^\s*[\d+]*\s*$/) || value != Math.round(value)) {
return "Not a whole number";
}
return null;
return _null;
},
'date': function(value, min, max) {
if (value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/)) {
return null;
return _null;
}
return "Value is not a date. (Expecting format: 12/31/2009).";
},
'ssn': function(value) {
if (value.match(/^\d\d\d-\d\d-\d\d\d\d$/)) {
return null;
return _null;
}
return "SSN needs to be in 999-99-9999 format.";
},
'email': function(value) {
if (value.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)) {
return null;
return _null;
}
return "Email needs to be in username@host.com format.";
},
'phone': function(value) {
if (value.match(/^1\(\d\d\d\)\d\d\d-\d\d\d\d$/)) {
return null;
return _null;
}
if (value.match(/^\+\d{2,3} (\(\d{1,5}\))?[\d ]+\d$/)) {
return null;
return _null;
}
return "Phone number needs to be in 1(987)654-3210 format in North America or +999 (123) 45678 906 internationaly.";
},
'url': function(value) {
if (value.match(/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/)) {
return null;
return _null;
}
return "URL needs to be in http://server[:port]/path format.";
},
@ -75,7 +75,7 @@ foreach({
'json': function(value) {
try {
fromJson(value);
return null;
return _null;
} catch (e) {
return e.toString();
}

View file

@ -6,7 +6,7 @@ function modelAccessor(scope, element) {
return scope.$eval(expr);
},
set: function(value) {
if (value !== undefined) {
if (value !== _undefined) {
return scope.$tryEval(expr + '=' + toJson(value), element);
}
}
@ -57,7 +57,7 @@ function valueAccessor(scope, element) {
return {
get: function(){
if (lastError)
elementError(element, NG_VALIDATION_ERROR, null);
elementError(element, NG_VALIDATION_ERROR, _null);
try {
var value = parse(element.val());
validate();
@ -80,13 +80,13 @@ function valueAccessor(scope, element) {
function validate() {
var value = trim(element.val());
if (element[0].disabled || element[0].readOnly) {
elementError(element, NG_VALIDATION_ERROR, null);
elementError(element, NG_VALIDATION_ERROR, _null);
invalidWidgets.markValid(element);
} else {
var error, validateScope = inherit(scope, {$element:element});
error = required && !value ?
'Required' :
(value ? validator(validateScope, value) : null);
(value ? validator(validateScope, value) : _null);
elementError(element, NG_VALIDATION_ERROR, error);
lastError = error;
if (error) {
@ -114,7 +114,7 @@ function radioAccessor(scope, element) {
var domElement = element[0];
return {
get: function(){
return domElement.checked ? domElement.value : null;
return domElement.checked ? domElement.value : _null;
},
set: function(value){
domElement.checked = value == domElement.value;
@ -157,7 +157,7 @@ var textWidget = inputWidget('keyup change', modelAccessor, valueAccessor, initW
'image': buttonWidget,
'checkbox': inputWidget('click', modelFormattedAccessor, checkedAccessor, initWidgetValue(false)),
'radio': inputWidget('click', modelFormattedAccessor, radioAccessor, radioInit),
'select-one': inputWidget('change', modelFormattedAccessor, valueAccessor, initWidgetValue(null)),
'select-one': inputWidget('change', modelFormattedAccessor, valueAccessor, initWidgetValue(_null)),
'select-multiple': inputWidget('change', modelFormattedAccessor, optionsAccessor, initWidgetValue([]))
// 'file': fileWidget???
};
@ -179,9 +179,9 @@ function radioInit(model, view, element) {
input.checked = false;
input.name = this.$id + '@' + input.name;
if (isUndefined(modelValue)) {
model.set(modelValue = null);
model.set(modelValue = _null);
}
if (modelValue == null && viewValue !== null) {
if (modelValue == _null && viewValue !== _null) {
model.set(viewValue);
}
view.set(modelValue);

View file

@ -8,7 +8,7 @@ ApiTest.prototype.testItShouldReturnTypeOf = function (){
assertEquals("string", angular.Object.typeOf(""));
assertEquals("date", angular.Object.typeOf(new Date()));
assertEquals("element", angular.Object.typeOf(document.body));
assertEquals("function", angular.Object.typeOf(function(){}));
assertEquals($function, angular.Object.typeOf(function(){}));
};
ApiTest.prototype.testItShouldReturnSize = function(){

View file

@ -59,7 +59,7 @@ describe('browser', function(){
expect(head.scripts.length).toEqual(1);
var url = head.scripts[0].src.split('?cb=');
expect(url[0]).toEqual('http://example.org/path');
expect(typeof window[url[1]]).toEqual('function');
expect(typeof window[url[1]]).toEqual($function);
window[url[1]]('data');
expect(log).toEqual('200:data;');
expect(typeof window[url[1]]).toEqual('undefined');

View file

@ -409,34 +409,6 @@ ParserTest.prototype.testMissingThrowsError = function() {
}
};
ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () {
var scope = createScope();
var fn = scope.$eval("{:value}");
scope.$set("value", 1);
assertEquals(1, fn());
scope.$set("value", 2);
assertEquals(2, fn());
fn = scope.$eval("{():value}");
assertEquals(2, fn());
};
ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function () {
var scope = createScope();
scope.$set("value", 1);
var fn = scope.$eval("{(a):value+a}");
assertEquals(11, fn(10));
scope.$set("value", 2);
assertEquals(12, fn(10));
fn = scope.$eval("{(a,b):value+a+b}");
assertEquals(112, fn(10, 100));
};
ParserTest.prototype.testItShouldHaveDefaultArugument = function(){
var scope = createScope();
var fn = scope.$eval("{:$*2}");
assertEquals(4, fn(2));
};
ParserTest.prototype.testDoubleNegationBug = function (){
var scope = createScope();
assertEquals(true, scope.$eval('true'));

View file

@ -15,12 +15,12 @@ describe("resource", function() {
});
it("should build resource", function(){
expect(typeof CreditCard).toBe('function');
expect(typeof CreditCard.get).toBe('function');
expect(typeof CreditCard.save).toBe('function');
expect(typeof CreditCard.remove).toBe('function');
expect(typeof CreditCard['delete']).toBe('function');
expect(typeof CreditCard.query).toBe('function');
expect(typeof CreditCard).toBe($function);
expect(typeof CreditCard.get).toBe($function);
expect(typeof CreditCard.save).toBe($function);
expect(typeof CreditCard.remove).toBe($function);
expect(typeof CreditCard['delete']).toBe($function);
expect(typeof CreditCard.query).toBe($function);
});
it('should default to empty parameters', function(){

View file

@ -247,7 +247,7 @@ describe("service", function(){
scope.$xhr('POST', '/req', 'MyData', callback);
xhr.flush();
var cb = $xhrError.mostRecentCall.args[0].callback;
expect(typeof cb).toEqual('function');
expect(typeof cb).toEqual($function);
expect($xhrError).wasCalledWith(
{url:'/req', method:'POST', data:'MyData', callback:cb},
{status:500, body:'MyError'});
@ -297,7 +297,7 @@ describe("service", function(){
expect($xhrError).wasCalled();
var cb = $xhrError.mostRecentCall.args[0].callback;
expect(typeof cb).toEqual('function');
expect(typeof cb).toEqual($function);
expect($xhrError).wasCalledWith(
{url:'/req1', method:'GET', data:null, callback:cb},
{status:404, response:'NotFound'});