From 5ddd8d958686c5075b6c58b700f19b4bdea90e1d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 18 Aug 2010 16:23:12 -0700 Subject: stringify names for better compression, remove dead functions, removed underscore.js compatibility --- src/Angular.js | 53 +++++++++++++++++++----------- src/Browser.js | 4 +-- src/Compiler.js | 2 +- src/JSON.js | 28 ++++++++-------- src/Parser.js | 87 ++++---------------------------------------------- src/Resource.js | 2 +- src/Scope.js | 40 +++++++++++------------ src/apis.js | 44 ++++++++----------------- src/directives.js | 10 +++--- src/filters.js | 2 +- src/formatters.js | 6 ++-- src/jqLite.js | 8 ++--- src/markups.js | 6 ++-- src/scenario/Future.js | 2 +- src/scenario/Runner.js | 6 ++-- src/services.js | 22 ++++++------- src/validators.js | 26 +++++++-------- src/widgets.js | 16 +++++----- 18 files changed, 145 insertions(+), 219 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 4c2e3716..3f248849 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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(); diff --git a/src/Browser.js b/src/Browser.js index b4314e2c..46ac2bb0 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -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 { diff --git a/src/Compiler.js b/src/Compiler.js index e09f1876..c45dd46e 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -181,7 +181,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 0311c317..6fb43f0f 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -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 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(/.*<\/\s*option\s*>/gi)) { parentElement.attr('value', text); } diff --git a/src/scenario/Future.js b/src/scenario/Future.js index d70e8e6e..cc40eff0 100644 --- a/src/scenario/Future.js +++ b/src/scenario/Future.js @@ -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 = { diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js index ac32559c..d1a9271b 100644 --- a/src/scenario/Runner.js +++ b/src/scenario/Runner.js @@ -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); diff --git a/src/services.js b/src/services.js index a5158149..19375f39 100644 --- a/src/services.js +++ b/src/services.js @@ -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; diff --git a/src/validators.js b/src/validators.js index 5c7fc952..b99c8aa9 100644 --- a/src/validators.js +++ b/src/validators.js @@ -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(); } diff --git a/src/widgets.js b/src/widgets.js index 87a302fa..336813aa 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -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); -- cgit v1.2.3