mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
remove _null and _undefined
they have no significant effect on minified and gziped size. in fact they make things worse. file | before | after removal ---------------------------------------- concat | 325415 | 325297 min | 62070 | 62161 min + gzip | 25187 | 25176 The bottom line is that we are getting 0.05% decrease in size after gzip without all of the hassle of using underscores everywhere.
This commit is contained in:
parent
d95a6925cd
commit
1e59822df7
22 changed files with 52 additions and 54 deletions
|
|
@ -52,9 +52,7 @@ if ('i' !== 'I'.toLowerCase()) {
|
|||
function fromCharCode(code) { return String.fromCharCode(code); }
|
||||
|
||||
|
||||
var _undefined = undefined,
|
||||
_null = null,
|
||||
$$element = '$element',
|
||||
var $$element = '$element',
|
||||
$$update = '$update',
|
||||
$$scope = '$scope',
|
||||
$$validate = '$validate',
|
||||
|
|
@ -315,7 +313,7 @@ function isDefined(value){ return typeof value != $undefined; }
|
|||
* @param {*} value Reference to check.
|
||||
* @returns {boolean} True if `value` is an `Object` but not `null`.
|
||||
*/
|
||||
function isObject(value){ return value!=_null && typeof value == $object;}
|
||||
function isObject(value){ return value!=null && typeof value == $object;}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ function Browser(window, document, body, XHR, $log) {
|
|||
var script = jqLite('<script>')
|
||||
.attr({type: 'text/javascript', src: url.replace('JSON_CALLBACK', callbackId)});
|
||||
window[callbackId] = function(data){
|
||||
window[callbackId] = _undefined;
|
||||
window[callbackId] = undefined;
|
||||
script.remove();
|
||||
completeOutstandingRequest(callback, 200, data);
|
||||
};
|
||||
|
|
@ -290,7 +290,7 @@ function Browser(window, document, body, XHR, $log) {
|
|||
var cookieLength, cookieArray, cookie, i, keyValue, index;
|
||||
|
||||
if (name) {
|
||||
if (value === _undefined) {
|
||||
if (value === undefined) {
|
||||
rawDocument.cookie = escape(name) + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
||||
} else {
|
||||
if (isString(value)) {
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ Compiler.prototype = {
|
|||
template.addChild(i, self.templatize(child, i, priority));
|
||||
});
|
||||
}
|
||||
return template.empty() ? _null : template;
|
||||
return template.empty() ? null : template;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,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('');
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ function toJsonArray(buf, obj, pretty, stack) {
|
|||
}
|
||||
stack.push(obj);
|
||||
}
|
||||
if (obj === _null) {
|
||||
if (obj === null) {
|
||||
buf.push($null);
|
||||
} else if (obj instanceof RegExp) {
|
||||
buf.push(angular['String']['quoteUnicode'](obj.toString()));
|
||||
|
|
@ -128,7 +128,7 @@ function toJsonArray(buf, obj, pretty, stack) {
|
|||
var childPretty = pretty ? pretty + " " : false;
|
||||
var keys = [];
|
||||
for(var k in obj) {
|
||||
if (obj[k] === _undefined)
|
||||
if (obj[k] === undefined)
|
||||
continue;
|
||||
keys.push(k);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ ResourceFactory.prototype = {
|
|||
default:
|
||||
throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments.";
|
||||
}
|
||||
var data = isPostOrPut ? this : _undefined;
|
||||
var data = isPostOrPut ? this : undefined;
|
||||
Resource[name].call(this, params, data, callback);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ angularDirective("ng:bind", function(expression, element){
|
|||
var lastValue = noop, lastError = noop;
|
||||
this.$onEval(function() {
|
||||
var error, value, html, 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 = formatError(e);
|
||||
|
|
@ -229,7 +229,7 @@ angularDirective("ng:bind", function(expression, element){
|
|||
element.html('');
|
||||
element.append(value);
|
||||
} else {
|
||||
element.text(value == _undefined ? '' : value);
|
||||
element.text(value == undefined ? '' : value);
|
||||
}
|
||||
}
|
||||
}, element);
|
||||
|
|
@ -257,7 +257,7 @@ function compileBindTemplate(template){
|
|||
});
|
||||
bindTemplateCache[template] = fn = function(element, prettyPrintJson){
|
||||
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);
|
||||
|
|
@ -767,7 +767,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) {
|
||||
|
|
|
|||
|
|
@ -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*$/;
|
||||
|
|
@ -94,8 +94,8 @@ angularFormatter['boolean'] = formatter(toString, toBoolean);
|
|||
</doc:example>
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ function JQLiteData(element, key, value) {
|
|||
}
|
||||
cache[key] = value;
|
||||
} else {
|
||||
return cache ? cache[key] : _null;
|
||||
return cache ? cache[key] : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
var OPERATORS = {
|
||||
'null':function(self){return _null;},
|
||||
'null':function(self){return null;},
|
||||
'true':function(self){return true;},
|
||||
'false':function(self){return false;},
|
||||
$undefined:noop,
|
||||
|
|
@ -566,7 +566,7 @@ function parser(text, json){
|
|||
function (self){
|
||||
var o = obj(self);
|
||||
var i = indexFn(self);
|
||||
return (o) ? o[i] : _undefined;
|
||||
return (o) ? o[i] : undefined;
|
||||
}, {
|
||||
assign:function(self, value){
|
||||
return obj(self)[indexFn(self)] = value;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ angularServiceInject('$cookies', function($browser) {
|
|||
//delete any cookies deleted in $cookies
|
||||
for (name in lastCookies) {
|
||||
if (isUndefined(cookies[name])) {
|
||||
$browser.cookies(name, _undefined);
|
||||
$browser.cookies(name, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ angularServiceInject("$hover", function(browser, document) {
|
|||
}
|
||||
} else if (tooltip) {
|
||||
tooltip.callout.remove();
|
||||
tooltip = _null;
|
||||
tooltip = null;
|
||||
}
|
||||
});
|
||||
}, ['$browser', '$document'], true);
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ angularServiceInject("$location", function($browser) {
|
|||
*/
|
||||
function composeHref(loc) {
|
||||
var url = toKeyValue(loc.search);
|
||||
var port = (loc.port == DEFAULT_PORTS[loc.protocol] ? _null : loc.port);
|
||||
var port = (loc.port == DEFAULT_PORTS[loc.protocol] ? null : loc.port);
|
||||
|
||||
return loc.protocol + '://' + loc.host +
|
||||
(port ? ':' + port : '') + loc.path +
|
||||
|
|
@ -233,7 +233,7 @@ angularServiceInject("$location", function($browser) {
|
|||
loc.href = href.replace(/#$/, '');
|
||||
loc.protocol = match[1];
|
||||
loc.host = match[3] || '';
|
||||
loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || _null;
|
||||
loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || null;
|
||||
loc.path = match[6] || '';
|
||||
loc.search = parseKeyValue(match[8]);
|
||||
loc.hash = match[10] || '';
|
||||
|
|
|
|||
|
|
@ -196,14 +196,14 @@ angularServiceInject('$route', function(location, $updateView) {
|
|||
});
|
||||
if (dstName) this.$set(dstName, dst);
|
||||
}
|
||||
return match ? dst : _null;
|
||||
return match ? dst : null;
|
||||
}
|
||||
|
||||
|
||||
function updateRoute(){
|
||||
var childScope, routeParams, pathParams, segmentMatch, key, redir;
|
||||
|
||||
$route.current = _null;
|
||||
$route.current = null;
|
||||
forEach(routes, function(rParams, rPath) {
|
||||
if (!pathParams) {
|
||||
if (pathParams = matcher(location.hashPath, rPath)) {
|
||||
|
|
@ -213,7 +213,7 @@ angularServiceInject('$route', function(location, $updateView) {
|
|||
});
|
||||
|
||||
// "otherwise" fallback
|
||||
routeParams = routeParams || routes[_null];
|
||||
routeParams = routeParams || routes[null];
|
||||
|
||||
if(routeParams) {
|
||||
if (routeParams.redirectTo) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ angularServiceInject('$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){
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $log){
|
|||
function cache(method, url, post, callback, verifyCache){
|
||||
if (isFunction(post)) {
|
||||
callback = post;
|
||||
post = _null;
|
||||
post = null;
|
||||
}
|
||||
if (method == 'GET') {
|
||||
var data, dataCached;
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ angularServiceInject('$xhr', function($browser, $error, $log, $updateView){
|
|||
return function(method, url, post, callback){
|
||||
if (isFunction(post)) {
|
||||
callback = post;
|
||||
post = _null;
|
||||
post = null;
|
||||
}
|
||||
if (post && isObject(post)) {
|
||||
post = toJson(post);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
extend(angularValidator, {
|
||||
'noop': function() { return _null; },
|
||||
'noop': function() { return null; },
|
||||
|
||||
/**
|
||||
* @workInProgress
|
||||
|
|
@ -42,7 +42,7 @@ extend(angularValidator, {
|
|||
return msg ||
|
||||
"Value does not match expected format " + regexp + ".";
|
||||
} else {
|
||||
return _null;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ extend(angularValidator, {
|
|||
if (typeof min != $undefined && num > max) {
|
||||
return "Value can not be greater than " + max + ".";
|
||||
}
|
||||
return _null;
|
||||
return null;
|
||||
} else {
|
||||
return "Not a number";
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ extend(angularValidator, {
|
|||
if (!("" + value).match(/^\s*[\d+]*\s*$/) || value != Math.round(value)) {
|
||||
return "Not a whole number";
|
||||
}
|
||||
return _null;
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -182,7 +182,7 @@ extend(angularValidator, {
|
|||
date.getFullYear() == fields[3] &&
|
||||
date.getMonth() == fields[1]-1 &&
|
||||
date.getDate() == fields[2])
|
||||
? _null
|
||||
? null
|
||||
: "Value is not a date. (Expecting format: 12/31/2009).";
|
||||
},
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ extend(angularValidator, {
|
|||
*/
|
||||
'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.";
|
||||
},
|
||||
|
|
@ -249,10 +249,10 @@ extend(angularValidator, {
|
|||
*/
|
||||
'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.";
|
||||
},
|
||||
|
|
@ -286,7 +286,7 @@ extend(angularValidator, {
|
|||
*/
|
||||
'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.";
|
||||
},
|
||||
|
|
@ -322,7 +322,7 @@ extend(angularValidator, {
|
|||
'json': function(value) {
|
||||
try {
|
||||
fromJson(value);
|
||||
return _null;
|
||||
return null;
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ function modelAccessor(scope, element) {
|
|||
return scope.$eval(expr);
|
||||
},
|
||||
set: function(value) {
|
||||
if (value !== _undefined) {
|
||||
if (value !== undefined) {
|
||||
return scope.$tryEval(function(){
|
||||
assign(scope, value);
|
||||
}, element);
|
||||
|
|
@ -310,7 +310,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(scope, element.val());
|
||||
validate();
|
||||
|
|
@ -333,13 +333,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) {
|
||||
|
|
@ -367,7 +367,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;
|
||||
|
|
@ -425,7 +425,7 @@ var textWidget = inputWidget('keydown change', modelAccessor, valueAccessor, ini
|
|||
'image': buttonWidget,
|
||||
'checkbox': inputWidget('click', modelFormattedAccessor, checkedAccessor, initWidgetValue(false)),
|
||||
'radio': inputWidget('click', modelFormattedAccessor, radioAccessor, radioInit),
|
||||
'select-one': inputWidget('change', modelAccessor, valueAccessor, initWidgetValue(_null)),
|
||||
'select-one': inputWidget('change', modelAccessor, valueAccessor, initWidgetValue(null)),
|
||||
'select-multiple': inputWidget('change', modelAccessor, optionsAccessor, initWidgetValue([]))
|
||||
// 'file': fileWidget???
|
||||
};
|
||||
|
|
@ -448,9 +448,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);
|
||||
|
|
|
|||
|
|
@ -682,7 +682,7 @@ describe("widget", function(){
|
|||
} else {
|
||||
|
||||
event = document.createEvent('MouseEvent');
|
||||
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, _null);
|
||||
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
|
||||
event.preventDefaultOrg = event.preventDefault;
|
||||
event.preventDefault = function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue