aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2011-03-26 16:06:38 -0700
committerIgor Minar2011-03-26 23:19:04 -0700
commit1e59822df7366094dbf38b0c4ce0cc979258ad19 (patch)
treef171a959e390bda54988369eb634dfd5dc73e30a
parentd95a6925cdb5e8009b11fe3ce6dcc8d579bb4234 (diff)
downloadangular.js-1e59822df7366094dbf38b0c4ce0cc979258ad19.tar.bz2
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.
-rw-r--r--src/Angular.js6
-rw-r--r--src/Browser.js4
-rw-r--r--src/Compiler.js2
-rw-r--r--src/JSON.js6
-rw-r--r--src/Resource.js2
-rw-r--r--src/Scope.js2
-rw-r--r--src/apis.js2
-rw-r--r--src/directives.js8
-rw-r--r--src/formatters.js6
-rw-r--r--src/jqLite.js2
-rw-r--r--src/markups.js4
-rw-r--r--src/parser.js4
-rw-r--r--src/service/cookies.js2
-rw-r--r--src/service/hover.js2
-rw-r--r--src/service/location.js4
-rw-r--r--src/service/route.js6
-rw-r--r--src/service/xhr.bulk.js2
-rw-r--r--src/service/xhr.cache.js2
-rw-r--r--src/service/xhr.js2
-rw-r--r--src/validators.js20
-rw-r--r--src/widgets.js16
-rw-r--r--test/widgetsSpec.js2
22 files changed, 52 insertions, 54 deletions
diff --git a/src/Angular.js b/src/Angular.js
index a91bf04c..b2949646 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -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;}
/**
diff --git a/src/Browser.js b/src/Browser.js
index e51df16c..55439762 100644
--- a/src/Browser.js
+++ b/src/Browser.js
@@ -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)) {
diff --git a/src/Compiler.js b/src/Compiler.js
index 09857ea4..a03d24c4 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -330,7 +330,7 @@ Compiler.prototype = {
template.addChild(i, self.templatize(child, i, priority));
});
}
- return template.empty() ? _null : template;
+ return template.empty() ? null : template;
}
};
diff --git a/src/JSON.js b/src/JSON.js
index 52d5a763..5e13dc45 100644
--- a/src/JSON.js
+++ b/src/JSON.js
@@ -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);
}
diff --git a/src/Resource.js b/src/Resource.js
index f748fb5a..341193fa 100644
--- a/src/Resource.js
+++ b/src/Resource.js
@@ -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);
};
});
diff --git a/src/Scope.js b/src/Scope.js
index 7d802a51..c5612c9f 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -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;
diff --git a/src/apis.js b/src/apis.js
index 1ca33208..9311c620 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -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;
diff --git a/src/directives.js b/src/directives.js
index 5e611571..32860a1e 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -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) {
diff --git a/src/formatters.js b/src/formatters.js
index a7a5cc4f..02773be1 100644
--- a/src/formatters.js
+++ b/src/formatters.js
@@ -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";
}
diff --git a/src/jqLite.js b/src/jqLite.js
index cda8ec70..9c96df4a 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -105,7 +105,7 @@ function JQLiteData(element, key, value) {
}
cache[key] = value;
} else {
- return cache ? cache[key] : _null;
+ return cache ? cache[key] : null;
}
}
diff --git a/src/markups.js b/src/markups.js
index 99e1cca7..24de5c37 100644
--- a/src/markups.js
+++ b/src/markups.js
@@ -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) {
diff --git a/src/parser.js b/src/parser.js
index a8bd21e4..0a19dad9 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -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;
diff --git a/src/service/cookies.js b/src/service/cookies.js
index b8de81c2..86e55fc1 100644
--- a/src/service/cookies.js
+++ b/src/service/cookies.js
@@ -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);
}
}
diff --git a/src/service/hover.js b/src/service/hover.js
index a7cef71a..fca18130 100644
--- a/src/service/hover.js
+++ b/src/service/hover.js
@@ -50,7 +50,7 @@ angularServiceInject("$hover", function(browser, document) {
}
} else if (tooltip) {
tooltip.callout.remove();
- tooltip = _null;
+ tooltip = null;
}
});
}, ['$browser', '$document'], true);
diff --git a/src/service/location.js b/src/service/location.js
index 31323284..a5875b72 100644
--- a/src/service/location.js
+++ b/src/service/location.js
@@ -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] || '';
diff --git a/src/service/route.js b/src/service/route.js
index 2de484f6..19fc81bf 100644
--- a/src/service/route.js
+++ b/src/service/route.js
@@ -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) {
diff --git a/src/service/xhr.bulk.js b/src/service/xhr.bulk.js
index 9933aa7e..c6cf608c 100644
--- a/src/service/xhr.bulk.js
+++ b/src/service/xhr.bulk.js
@@ -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){
diff --git a/src/service/xhr.cache.js b/src/service/xhr.cache.js
index e87b127b..284321d7 100644
--- a/src/service/xhr.cache.js
+++ b/src/service/xhr.cache.js
@@ -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;
diff --git a/src/service/xhr.js b/src/service/xhr.js
index 1de72b22..18f695e6 100644
--- a/src/service/xhr.js
+++ b/src/service/xhr.js
@@ -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);
diff --git a/src/validators.js b/src/validators.js
index ad76646b..c2902849 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -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();
}
diff --git a/src/widgets.js b/src/widgets.js
index 91b0fcf2..ac8a88e0 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -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);
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index dc7ffa77..eab5cce7 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -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() {