Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5ddd8d9

Browse files
committed
stringify names for better compression, remove dead functions, removed underscore.js compatibility
1 parent 1087270 commit 5ddd8d9

23 files changed

+155
-257
lines changed

src/Angular.js

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
////////////////////////////////////
22

3-
if (typeof document.getAttribute == 'undefined')
3+
if (typeof document.getAttribute == $undefined)
44
document.getAttribute = function() {};
55

6-
var consoleNode,
7-
NULL = null,
8-
UNDEFIEND = undefined,
6+
var _undefined = undefined,
7+
_null = null,
8+
$$element = '$element',
9+
$angular = 'angular',
10+
$array = 'array',
11+
$boolean = 'boolean',
12+
$console = 'console',
13+
$date = 'date',
14+
$display = 'display',
15+
$element = 'element',
16+
$function = 'function',
17+
$length = 'length',
18+
$name = 'name',
19+
$none = 'none',
20+
$noop = 'noop',
21+
$null = 'null',
22+
$number = 'number',
23+
$object = 'object',
24+
$string = 'string',
25+
$undefined = 'undefined',
26+
NG_EXCEPTION = 'ng-exception',
27+
NG_VALIDATION_ERROR = 'ng-validation-error',
28+
NOOP = 'noop',
929
PRIORITY_FIRST = -99999,
1030
PRIORITY_WATCH = -1000,
1131
PRIORITY_LAST = 99999,
1232
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
13-
NOOP = 'noop',
14-
NG_EXCEPTION = 'ng-exception',
15-
NG_VALIDATION_ERROR = 'ng-validation-error',
1633
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
1734
_ = window['_'],
1835
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
1936
jqLite = jQuery || jqLiteWrap,
2037
slice = Array.prototype.slice,
21-
error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop,
22-
angular = window['angular'] || (window['angular'] = {}),
38+
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
39+
angular = window[$angular] || (window[$angular] = {}),
2340
angularTextMarkup = extensionMap(angular, 'markup'),
2441
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
2542
angularDirective = extensionMap(angular, 'directive'),
@@ -36,7 +53,7 @@ function foreach(obj, iterator, context) {
3653
if (obj) {
3754
if (isFunction(obj)){
3855
for (key in obj) {
39-
if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) {
56+
if (key != 'prototype' && key != $length && key != $name && obj.hasOwnProperty(key)) {
4057
iterator.call(context, obj[key], key);
4158
}
4259
}
@@ -93,7 +110,7 @@ function extensionMap(angular, name, transform) {
93110
}
94111

95112
function jqLiteWrap(element) {
96-
// for some reasons the parentNode of an orphan looks like null but its typeof is object.
113+
// for some reasons the parentNode of an orphan looks like _null but its typeof is object.
97114
if (element) {
98115
if (isString(element)) {
99116
var div = document.createElement('div');
@@ -105,13 +122,13 @@ function jqLiteWrap(element) {
105122
}
106123
return element;
107124
}
108-
function isUndefined(value){ return typeof value == 'undefined'; }
109-
function isDefined(value){ return typeof value != 'undefined'; }
110-
function isObject(value){ return value!=null && typeof value == 'object';}
125+
function isUndefined(value){ return typeof value == $undefined; }
126+
function isDefined(value){ return typeof value != $undefined; }
127+
function isObject(value){ return value!=_null && typeof value == 'object';}
111128
function isString(value){ return typeof value == 'string';}
112129
function isNumber(value){ return typeof value == 'number';}
113130
function isArray(value) { return value instanceof Array; }
114-
function isFunction(value){ return typeof value == 'function';}
131+
function isFunction(value){ return typeof value == $function;}
115132
function isTextNode(node) { return nodeName(node) == '#text'; }
116133
function lowercase(value){ return isString(value) ? value.toLowerCase() : value; }
117134
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
@@ -295,7 +312,7 @@ function escapeAttr(html) {
295312

296313
function bind(self, fn) {
297314
var curryArgs = arguments.length > 2 ? slice.call(arguments, 2, arguments.length) : [];
298-
if (typeof fn == 'function') {
315+
if (typeof fn == $function) {
299316
return curryArgs.length ? function() {
300317
return arguments.length ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length))) : fn.apply(self, curryArgs);
301318
}: function() {
@@ -321,7 +338,7 @@ function merge(src, dst) {
321338
for ( var key in src) {
322339
var value = dst[key];
323340
var type = typeof value;
324-
if (type == 'undefined') {
341+
if (type == $undefined) {
325342
dst[key] = fromJson(toJson(src[key]));
326343
} else if (type == 'object' && value.constructor != array &&
327344
key.substring(0, 1) != "$") {
@@ -361,7 +378,7 @@ function toKeyValue(obj) {
361378
function angularInit(config){
362379
if (config.autobind) {
363380
// TODO default to the source of angular.js
364-
var scope = compile(window.document, null, {'$config':config});
381+
var scope = compile(window.document, _null, {'$config':config});
365382
if (config.css)
366383
scope.$browser.addCss(config.base_url + config.css);
367384
scope.$init();

src/Browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Browser.prototype = {
5757
xhr: function(method, url, post, callback){
5858
if (isFunction(post)) {
5959
callback = post;
60-
post = null;
60+
post = _null;
6161
}
6262
if (lowercase(method) == 'json') {
6363
var callbackId = "angular_" + Math.random() + '_' + (this.idCounter++);
@@ -67,7 +67,7 @@ Browser.prototype = {
6767
script.src = url.replace('JSON_CALLBACK', callbackId);
6868
this.head.append(script);
6969
window[callbackId] = function(data){
70-
window[callbackId] = undefined;
70+
window[callbackId] = _undefined;
7171
callback(200, data);
7272
};
7373
} else {

src/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Compiler.prototype = {
181181
template.addChild(i, self.templatize(child, i, priority));
182182
});
183183
}
184-
return template.empty() ? null : template;
184+
return template.empty() ? _null : template;
185185
}
186186
};
187187

src/JSON.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var array = [].constructor;
22

33
function toJson(obj, pretty){
44
var buf = [];
5-
toJsonArray(buf, obj, pretty ? "\n " : null, []);
5+
toJsonArray(buf, obj, pretty ? "\n " : _null, []);
66
return buf.join('');
77
}
88

@@ -31,30 +31,30 @@ function toJsonArray(buf, obj, pretty, stack){
3131
stack.push(obj);
3232
}
3333
var type = typeof obj;
34-
if (obj === null) {
35-
buf.push("null");
36-
} else if (type === 'function') {
34+
if (obj === _null) {
35+
buf.push($null);
36+
} else if (type === $function) {
3737
return;
38-
} else if (type === 'boolean') {
38+
} else if (type === $boolean) {
3939
buf.push('' + obj);
40-
} else if (type === 'number') {
40+
} else if (type === $number) {
4141
if (isNaN(obj)) {
42-
buf.push('null');
42+
buf.push($null);
4343
} else {
4444
buf.push('' + obj);
4545
}
46-
} else if (type === 'string') {
46+
} else if (type === $string) {
4747
return buf.push(angular['String']['quoteUnicode'](obj));
48-
} else if (type === 'object') {
48+
} else if (type === $object) {
4949
if (obj instanceof Array) {
5050
buf.push("[");
5151
var len = obj.length;
5252
var sep = false;
5353
for(var i=0; i<len; i++) {
5454
var item = obj[i];
5555
if (sep) buf.push(",");
56-
if (typeof item == 'function' || typeof item == 'undefined') {
57-
buf.push("null");
56+
if (typeof item == $function || typeof item == $undefined) {
57+
buf.push($null);
5858
} else {
5959
toJsonArray(buf, item, pretty, stack);
6060
}
@@ -70,7 +70,7 @@ function toJsonArray(buf, obj, pretty, stack){
7070
var childPretty = pretty ? pretty + " " : false;
7171
var keys = [];
7272
for(var k in obj) {
73-
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === undefined)
73+
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === _undefined)
7474
continue;
7575
keys.push(k);
7676
}
@@ -79,7 +79,7 @@ function toJsonArray(buf, obj, pretty, stack){
7979
var key = keys[keyIndex];
8080
try {
8181
var value = obj[key];
82-
if (typeof value != 'function') {
82+
if (typeof value != $function) {
8383
if (comma) {
8484
buf.push(",");
8585
if (pretty) buf.push(pretty);
@@ -95,7 +95,7 @@ function toJsonArray(buf, obj, pretty, stack){
9595
buf.push("}");
9696
}
9797
}
98-
if (typeof obj == "object") {
98+
if (typeof obj == $object) {
9999
stack.pop();
100100
}
101101
}

src/Parser.js

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function Lexer(text, parsStrings){
77
}
88

99
Lexer.OPERATORS = {
10-
'null':function(self){return null;},
10+
'null':function(self){return _null;},
1111
'true':function(self){return true;},
1212
'false':function(self){return false;},
13-
'undefined':noop,
13+
$undefined:noop,
1414
'+':function(self, a,b){return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
1515
'-':function(self, a,b){return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
1616
'*':function(self, a,b){return a*b;},
@@ -490,7 +490,7 @@ Parser.prototype = {
490490
if (instance)
491491
instance = instance[key];
492492
}
493-
if (typeof instance != 'function') {
493+
if (typeof instance != $function) {
494494
throw "Function '" + token.text + "' at column '" +
495495
(token.index+1) + "' in '" + this.text + "' is not defined.";
496496
}
@@ -507,10 +507,6 @@ Parser.prototype = {
507507
primary = this.arrayDeclaration();
508508
} else if (this.expect('{')) {
509509
primary = this.object();
510-
} else if (this.expect('{:')) {
511-
primary = this.closure(false);
512-
} else if (this.expect('{(')) {
513-
primary = this.closure(true);
514510
} else {
515511
var token = this.expect();
516512
primary = token.fn;
@@ -533,32 +529,6 @@ Parser.prototype = {
533529
return primary;
534530
},
535531

536-
closure: function(hasArgs) {
537-
var args = [];
538-
if (hasArgs) {
539-
if (!this.expect(')')) {
540-
args.push(this.expect().text);
541-
while(this.expect(',')) {
542-
args.push(this.expect().text);
543-
}
544-
this.consume(')');
545-
}
546-
this.consume(":");
547-
}
548-
var statements = this.statements();
549-
this.consume("}");
550-
return function(self) {
551-
return function($){
552-
var scope = createScope(self);
553-
scope['$'] = $;
554-
for ( var i = 0; i < args.length; i++) {
555-
setter(scope, args[i], arguments[i]);
556-
}
557-
return statements(scope);
558-
};
559-
};
560-
},
561-
562532
fieldAccess: function(object) {
563533
var field = this.expect().text;
564534
var getter = getterFn(field);
@@ -581,7 +551,7 @@ Parser.prototype = {
581551
return function (self){
582552
var o = obj(self);
583553
var i = indexFn(self);
584-
return (o) ? o[i] : undefined;
554+
return (o) ? o[i] : _undefined;
585555
};
586556
}
587557
},
@@ -601,8 +571,8 @@ Parser.prototype = {
601571
}
602572
var fnPtr = fn(self) || noop;
603573
// IE stupidity!
604-
return fnPtr.apply ?
605-
fnPtr.apply(self, args) :
574+
return fnPtr.apply ?
575+
fnPtr.apply(self, args) :
606576
fnPtr(args[0], args[1], args[2], args[3], args[4]);
607577
};
608578
},
@@ -648,51 +618,6 @@ Parser.prototype = {
648618
};
649619
},
650620

651-
entityDeclaration: function () {
652-
var decl = [];
653-
while(this.hasTokens()) {
654-
decl.push(this.entityDecl());
655-
if (!this.expect(';')) {
656-
this.assertAllConsumed();
657-
}
658-
}
659-
return function (self){
660-
var code = "";
661-
for ( var i = 0; i < decl.length; i++) {
662-
code += decl[i](self);
663-
}
664-
return code;
665-
};
666-
},
667-
668-
entityDecl: function () {
669-
var entity = this.expect().text;
670-
var instance;
671-
var defaults;
672-
if (this.expect('=')) {
673-
instance = entity;
674-
entity = this.expect().text;
675-
}
676-
if (this.expect(':')) {
677-
defaults = this.primary()(null);
678-
}
679-
return function(self) {
680-
var Entity = self.datastore.entity(entity, defaults);
681-
setter(self, entity, Entity);
682-
if (instance) {
683-
var document = Entity();
684-
document['$$anchor'] = instance;
685-
setter(self, instance, document);
686-
return "$anchor." + instance + ":{" +
687-
instance + "=" + entity + ".load($anchor." + instance + ");" +
688-
instance + ".$$anchor=" + angular['String']['quote'](instance) + ";" +
689-
"};";
690-
} else {
691-
return "";
692-
}
693-
};
694-
},
695-
696621
watch: function () {
697622
var decl = [];
698623
while(this.hasTokens()) {

src/Resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ ResourceFactory.prototype = {
124124
var callback = noop;
125125
switch(arguments.length) {
126126
case 2: params = a1; callback = a2;
127-
case 1: if (typeof a1 == 'function') callback = a1; else params = a1;
127+
case 1: if (typeof a1 == $function) callback = a1; else params = a1;
128128
case 0: break;
129129
default:
130130
throw "Expected between 1-2 arguments [params, callback], got " + arguments.length + " arguments.";

0 commit comments

Comments
 (0)