Refactoring scope to use an array instead of an object, to make the IE bugfix significantly tidier.

This commit is contained in:
Timothy Jones
2010-10-20 12:36:50 +13:00
parent 7342058e64
commit 8fff6e9baf
5 changed files with 275 additions and 79 deletions

View File

@@ -6,6 +6,168 @@
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
Scope = require('./scope').Scope;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, include = _ref.include, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
@@ -250,6 +412,7 @@
exports.Literal = (function() {
Literal = (function() {
function Literal(_arg) {
var _arg;
this.value = _arg;
Literal.__super__.constructor.call(this);
return this;
@@ -287,6 +450,7 @@
exports.Return = (function() {
Return = (function() {
function Return(_arg) {
var _arg;
this.expression = _arg;
Return.__super__.constructor.call(this);
return this;
@@ -322,6 +486,7 @@
exports.Value = (function() {
Value = (function() {
function Value(_arg, _arg2, tag) {
var _arg, _arg2;
this.properties = _arg2;
this.base = _arg;
Value.__super__.constructor.call(this);
@@ -443,6 +608,7 @@
exports.Comment = (function() {
Comment = (function() {
function Comment(_arg) {
var _arg;
this.comment = _arg;
Comment.__super__.constructor.call(this);
return this;
@@ -460,6 +626,7 @@
exports.Call = (function() {
Call = (function() {
function Call(variable, _arg, _arg2) {
var _arg, _arg2;
this.soakNode = _arg2;
this.args = _arg;
Call.__super__.constructor.call(this);
@@ -598,6 +765,7 @@
exports.Extends = (function() {
Extends = (function() {
function Extends(_arg, _arg2) {
var _arg, _arg2;
this.parent = _arg2;
this.child = _arg;
Extends.__super__.constructor.call(this);
@@ -617,6 +785,7 @@
exports.Accessor = (function() {
Accessor = (function() {
function Accessor(_arg, tag) {
var _arg;
this.name = _arg;
Accessor.__super__.constructor.call(this);
this.prototype = tag === 'prototype' ? '.prototype' : '';
@@ -639,6 +808,7 @@
exports.Index = (function() {
Index = (function() {
function Index(_arg) {
var _arg;
this.index = _arg;
Index.__super__.constructor.call(this);
return this;
@@ -661,6 +831,7 @@
exports.Range = (function() {
Range = (function() {
function Range(_arg, _arg2, tag) {
var _arg, _arg2;
this.to = _arg2;
this.from = _arg;
Range.__super__.constructor.call(this);
@@ -749,6 +920,7 @@
exports.Slice = (function() {
Slice = (function() {
function Slice(_arg) {
var _arg;
this.range = _arg;
Slice.__super__.constructor.call(this);
return this;
@@ -781,7 +953,7 @@
__extends(ObjectLiteral, Base);
ObjectLiteral.prototype.children = ['properties'];
ObjectLiteral.prototype.compileNode = function(o) {
var _i, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
var _i, _len, _len2, _ref2, _ref3, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
top = del(o, 'top');
o.indent = this.idt(1);
nonComments = (function() {
@@ -796,10 +968,10 @@
}).call(this);
lastNoncom = last(nonComments);
props = (function() {
_result = [];
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
prop = _ref2[i];
_result.push((function() {
_result2 = [];
for (i = 0, _len2 = (_ref3 = this.properties).length; i < _len2; i++) {
prop = _ref3[i];
_result2.push((function() {
join = i === this.properties.length - 1 ? '' : (prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n');
indent = prop instanceof Comment ? '' : this.idt(1);
if (prop instanceof Value && prop.tags["this"]) {
@@ -810,7 +982,7 @@
return indent + prop.compile(o) + join;
}).call(this));
}
return _result;
return _result2;
}).call(this);
props = props.join('');
obj = ("{" + (props ? '\n' + props + '\n' + this.idt() : '') + "}");
@@ -831,6 +1003,7 @@
exports.ArrayLiteral = (function() {
ArrayLiteral = (function() {
function ArrayLiteral(_arg) {
var _arg;
this.objects = _arg;
ArrayLiteral.__super__.constructor.call(this);
this.objects || (this.objects = []);
@@ -876,6 +1049,7 @@
exports.Class = (function() {
Class = (function() {
function Class(variable, _arg, _arg2) {
var _arg, _arg2;
this.properties = _arg2;
this.parent = _arg;
Class.__super__.constructor.call(this);
@@ -974,6 +1148,7 @@
exports.Assign = (function() {
Assign = (function() {
function Assign(_arg, _arg2, _arg3) {
var _arg, _arg2, _arg3;
this.context = _arg3;
this.value = _arg2;
this.variable = _arg;
@@ -1107,6 +1282,7 @@
exports.Code = (function() {
Code = (function() {
function Code(_arg, _arg2, tag) {
var _arg, _arg2;
this.body = _arg2;
this.params = _arg;
Code.__super__.constructor.call(this);
@@ -1123,7 +1299,7 @@
__extends(Code, Base);
Code.prototype.children = ['params', 'body'];
Code.prototype.compileNode = function(o) {
var _i, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
var _i, _j, _len, _len2, _len3, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
sharedScope = del(o, 'sharedScope');
top = del(o, 'top');
o.scope = sharedScope || new Scope(o.scope, this.body, this);
@@ -1171,8 +1347,8 @@
if (!(empty || this.noReturn)) {
this.body.makeReturn();
}
for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
param = params[_i];
for (_j = 0, _len3 = params.length; _j < _len3; _j++) {
param = params[_j];
(o.scope.parameter(param));
}
comm = this.comment ? this.comment.compile(o) + '\n' : '';
@@ -1197,6 +1373,7 @@
exports.Param = (function() {
Param = (function() {
function Param(_arg, _arg2, _arg3) {
var _arg, _arg2, _arg3;
this.splat = _arg3;
this.attach = _arg2;
this.name = _arg;
@@ -1465,6 +1642,7 @@
exports.In = (function() {
In = (function() {
function In(_arg, _arg2) {
var _arg, _arg2;
this.array = _arg2;
this.object = _arg;
In.__super__.constructor.call(this);
@@ -1503,6 +1681,7 @@
exports.Try = (function() {
Try = (function() {
function Try(_arg, _arg2, _arg3, _arg4) {
var _arg, _arg2, _arg3, _arg4;
this.ensure = _arg4;
this.recovery = _arg3;
this.error = _arg2;
@@ -1539,6 +1718,7 @@
exports.Throw = (function() {
Throw = (function() {
function Throw(_arg) {
var _arg;
this.expression = _arg;
Throw.__super__.constructor.call(this);
return this;
@@ -1557,6 +1737,7 @@
exports.Existence = (function() {
Existence = (function() {
function Existence(_arg) {
var _arg;
this.expression = _arg;
Existence.__super__.constructor.call(this);
return this;
@@ -1576,6 +1757,7 @@
exports.Parens = (function() {
Parens = (function() {
function Parens(_arg) {
var _arg;
this.expression = _arg;
Parens.__super__.constructor.call(this);
return this;
@@ -1612,7 +1794,7 @@
exports.For = (function() {
For = (function() {
function For(_arg, source, _arg2, _arg3) {
var _ref2;
var _arg, _arg2, _arg3, _ref2;
this.index = _arg3;
this.name = _arg2;
this.body = _arg;
@@ -1771,6 +1953,7 @@
exports.Switch = (function() {
Switch = (function() {
function Switch(_arg, _arg2, _arg3) {
var _arg, _arg2, _arg3;
this.otherwise = _arg3;
this.cases = _arg2;
this.subject = _arg;
@@ -1827,6 +2010,7 @@
exports.If = (function() {
If = (function() {
function If(condition, _arg, tags) {
var _arg;
this.body = _arg;
this.tags = tags || (tags = {});
this.condition = tags.invert ? condition.invert() : condition;
@@ -1962,7 +2146,7 @@
UTILITIES = {
"extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',
bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}',
inArray: '(function() {\n var indexOf = Array.prototype.indexOf || function(item) {\n var i = this.length; while (i--) if (this[i] === item) return i;\n return -1;\n };\n return function(item, array) { return indexOf.call(array, item) > -1; };\n})();',
inArray: '(function() {\n var indexOf = Array.prototype.indexOf || function(item) {\n var i = this.length; while (i--) if (this[i] === item) return i;\n return -1;\n };\n return function(item, array) { return indexOf.call(array, item) > -1; };\n})()',
hasProp: 'Object.prototype.hasOwnProperty',
slice: 'Array.prototype.slice'
};