mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
cleaning up super assignment.
This commit is contained in:
@@ -187,9 +187,9 @@
|
||||
|
||||
})();
|
||||
|
||||
exports.Block = Block = (function() {
|
||||
exports.Block = Block = (function(_super) {
|
||||
|
||||
__extends(Block, Base);
|
||||
__extends(Block, _super);
|
||||
|
||||
function Block(nodes) {
|
||||
this.expressions = compact(flatten(nodes || []));
|
||||
@@ -384,11 +384,11 @@
|
||||
|
||||
return Block;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Literal = Literal = (function() {
|
||||
exports.Literal = Literal = (function(_super) {
|
||||
|
||||
__extends(Literal, Base);
|
||||
__extends(Literal, _super);
|
||||
|
||||
function Literal(value) {
|
||||
this.value = value;
|
||||
@@ -440,11 +440,11 @@
|
||||
|
||||
return Literal;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Return = Return = (function() {
|
||||
exports.Return = Return = (function(_super) {
|
||||
|
||||
__extends(Return, Base);
|
||||
__extends(Return, _super);
|
||||
|
||||
function Return(expr) {
|
||||
if (expr && !expr.unwrap().isUndefined) this.expression = expr;
|
||||
@@ -474,11 +474,11 @@
|
||||
|
||||
return Return;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Value = Value = (function() {
|
||||
exports.Value = Value = (function(_super) {
|
||||
|
||||
__extends(Value, Base);
|
||||
__extends(Value, _super);
|
||||
|
||||
function Value(base, props, tag) {
|
||||
if (!props && base instanceof Value) return base;
|
||||
@@ -622,11 +622,11 @@
|
||||
|
||||
return Value;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Comment = Comment = (function() {
|
||||
exports.Comment = Comment = (function(_super) {
|
||||
|
||||
__extends(Comment, Base);
|
||||
__extends(Comment, _super);
|
||||
|
||||
function Comment(comment) {
|
||||
this.comment = comment;
|
||||
@@ -645,11 +645,11 @@
|
||||
|
||||
return Comment;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Call = Call = (function() {
|
||||
exports.Call = Call = (function(_super) {
|
||||
|
||||
__extends(Call, Base);
|
||||
__extends(Call, _super);
|
||||
|
||||
function Call(variable, args, soak) {
|
||||
this.args = args != null ? args : [];
|
||||
@@ -814,11 +814,11 @@
|
||||
|
||||
return Call;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Extends = Extends = (function() {
|
||||
exports.Extends = Extends = (function(_super) {
|
||||
|
||||
__extends(Extends, Base);
|
||||
__extends(Extends, _super);
|
||||
|
||||
function Extends(child, parent) {
|
||||
this.child = child;
|
||||
@@ -833,11 +833,11 @@
|
||||
|
||||
return Extends;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Access = Access = (function() {
|
||||
exports.Access = Access = (function(_super) {
|
||||
|
||||
__extends(Access, Base);
|
||||
__extends(Access, _super);
|
||||
|
||||
function Access(name, tag) {
|
||||
this.name = name;
|
||||
@@ -861,11 +861,11 @@
|
||||
|
||||
return Access;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Index = Index = (function() {
|
||||
exports.Index = Index = (function(_super) {
|
||||
|
||||
__extends(Index, Base);
|
||||
__extends(Index, _super);
|
||||
|
||||
function Index(index) {
|
||||
this.index = index;
|
||||
@@ -883,11 +883,11 @@
|
||||
|
||||
return Index;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Range = Range = (function() {
|
||||
exports.Range = Range = (function(_super) {
|
||||
|
||||
__extends(Range, Base);
|
||||
__extends(Range, _super);
|
||||
|
||||
Range.prototype.children = ['from', 'to'];
|
||||
|
||||
@@ -962,11 +962,11 @@
|
||||
|
||||
return Range;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Slice = Slice = (function() {
|
||||
exports.Slice = Slice = (function(_super) {
|
||||
|
||||
__extends(Slice, Base);
|
||||
__extends(Slice, _super);
|
||||
|
||||
Slice.prototype.children = ['range'];
|
||||
|
||||
@@ -988,11 +988,11 @@
|
||||
|
||||
return Slice;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Obj = Obj = (function() {
|
||||
exports.Obj = Obj = (function(_super) {
|
||||
|
||||
__extends(Obj, Base);
|
||||
__extends(Obj, _super);
|
||||
|
||||
function Obj(props, generated) {
|
||||
this.generated = generated != null ? generated : false;
|
||||
@@ -1054,11 +1054,11 @@
|
||||
|
||||
return Obj;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Arr = Arr = (function() {
|
||||
exports.Arr = Arr = (function(_super) {
|
||||
|
||||
__extends(Arr, Base);
|
||||
__extends(Arr, _super);
|
||||
|
||||
function Arr(objs) {
|
||||
this.objects = objs || [];
|
||||
@@ -1102,11 +1102,11 @@
|
||||
|
||||
return Arr;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Class = Class = (function() {
|
||||
exports.Class = Class = (function(_super) {
|
||||
|
||||
__extends(Class, Base);
|
||||
__extends(Class, _super);
|
||||
|
||||
function Class(variable, parent, body) {
|
||||
this.variable = variable;
|
||||
@@ -1239,15 +1239,13 @@
|
||||
this.walkBody(name, o);
|
||||
this.ensureConstructor(name);
|
||||
this.body.spaced = true;
|
||||
if (this.parent) {
|
||||
this.superClass = new Literal(o.scope.freeVariable('super'));
|
||||
this.body.expressions.unshift(new Extends(lname, this.superClass));
|
||||
}
|
||||
if (!(this.ctor instanceof Code)) this.body.expressions.unshift(this.ctor);
|
||||
this.body.expressions.push(lname);
|
||||
this.addBoundFunctions(o);
|
||||
call = Closure.wrap(this.body);
|
||||
if (this.parent) {
|
||||
this.superClass = new Literal(o.scope.freeVariable('super', false));
|
||||
this.body.expressions.unshift(new Extends(lname, this.superClass));
|
||||
call.args.push(this.parent);
|
||||
call.variable.params.push(new Param(this.superClass));
|
||||
}
|
||||
@@ -1258,11 +1256,11 @@
|
||||
|
||||
return Class;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Assign = Assign = (function() {
|
||||
exports.Assign = Assign = (function(_super) {
|
||||
|
||||
__extends(Assign, Base);
|
||||
__extends(Assign, _super);
|
||||
|
||||
function Assign(variable, value, context, options) {
|
||||
this.variable = variable;
|
||||
@@ -1456,11 +1454,11 @@
|
||||
|
||||
return Assign;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Code = Code = (function() {
|
||||
exports.Code = Code = (function(_super) {
|
||||
|
||||
__extends(Code, Base);
|
||||
__extends(Code, _super);
|
||||
|
||||
function Code(params, body, tag) {
|
||||
this.params = params || [];
|
||||
@@ -1568,11 +1566,11 @@
|
||||
|
||||
return Code;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Param = Param = (function() {
|
||||
exports.Param = Param = (function(_super) {
|
||||
|
||||
__extends(Param, Base);
|
||||
__extends(Param, _super);
|
||||
|
||||
function Param(name, value, splat) {
|
||||
this.name = name;
|
||||
@@ -1607,11 +1605,11 @@
|
||||
|
||||
return Param;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Splat = Splat = (function() {
|
||||
exports.Splat = Splat = (function(_super) {
|
||||
|
||||
__extends(Splat, Base);
|
||||
__extends(Splat, _super);
|
||||
|
||||
Splat.prototype.children = ['name'];
|
||||
|
||||
@@ -1673,11 +1671,11 @@
|
||||
|
||||
return Splat;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.While = While = (function() {
|
||||
exports.While = While = (function(_super) {
|
||||
|
||||
__extends(While, Base);
|
||||
__extends(While, _super);
|
||||
|
||||
function While(condition, options) {
|
||||
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
|
||||
@@ -1745,12 +1743,12 @@
|
||||
|
||||
return While;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Op = Op = (function() {
|
||||
exports.Op = Op = (function(_super) {
|
||||
var CONVERSIONS, INVERSIONS;
|
||||
|
||||
__extends(Op, Base);
|
||||
__extends(Op, _super);
|
||||
|
||||
function Op(op, first, second, flip) {
|
||||
var call;
|
||||
@@ -1897,11 +1895,11 @@
|
||||
|
||||
return Op;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.In = In = (function() {
|
||||
exports.In = In = (function(_super) {
|
||||
|
||||
__extends(In, Base);
|
||||
__extends(In, _super);
|
||||
|
||||
function In(object, array) {
|
||||
this.object = object;
|
||||
@@ -1969,11 +1967,11 @@
|
||||
|
||||
return In;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Try = Try = (function() {
|
||||
exports.Try = Try = (function(_super) {
|
||||
|
||||
__extends(Try, Base);
|
||||
__extends(Try, _super);
|
||||
|
||||
function Try(attempt, error, recovery, ensure) {
|
||||
this.attempt = attempt;
|
||||
@@ -2009,11 +2007,11 @@
|
||||
|
||||
return Try;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Throw = Throw = (function() {
|
||||
exports.Throw = Throw = (function(_super) {
|
||||
|
||||
__extends(Throw, Base);
|
||||
__extends(Throw, _super);
|
||||
|
||||
function Throw(expression) {
|
||||
this.expression = expression;
|
||||
@@ -2033,11 +2031,11 @@
|
||||
|
||||
return Throw;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Existence = Existence = (function() {
|
||||
exports.Existence = Existence = (function(_super) {
|
||||
|
||||
__extends(Existence, Base);
|
||||
__extends(Existence, _super);
|
||||
|
||||
function Existence(expression) {
|
||||
this.expression = expression;
|
||||
@@ -2066,11 +2064,11 @@
|
||||
|
||||
return Existence;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.Parens = Parens = (function() {
|
||||
exports.Parens = Parens = (function(_super) {
|
||||
|
||||
__extends(Parens, Base);
|
||||
__extends(Parens, _super);
|
||||
|
||||
function Parens(body) {
|
||||
this.body = body;
|
||||
@@ -2104,11 +2102,11 @@
|
||||
|
||||
return Parens;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.For = For = (function() {
|
||||
exports.For = For = (function(_super) {
|
||||
|
||||
__extends(For, While);
|
||||
__extends(For, _super);
|
||||
|
||||
function For(body, source) {
|
||||
var _ref2;
|
||||
@@ -2237,11 +2235,11 @@
|
||||
|
||||
return For;
|
||||
|
||||
})();
|
||||
})(While);
|
||||
|
||||
exports.Switch = Switch = (function() {
|
||||
exports.Switch = Switch = (function(_super) {
|
||||
|
||||
__extends(Switch, Base);
|
||||
__extends(Switch, _super);
|
||||
|
||||
function Switch(subject, cases, otherwise) {
|
||||
this.subject = subject;
|
||||
@@ -2312,11 +2310,11 @@
|
||||
|
||||
return Switch;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
exports.If = If = (function() {
|
||||
exports.If = If = (function(_super) {
|
||||
|
||||
__extends(If, Base);
|
||||
__extends(If, _super);
|
||||
|
||||
function If(condition, body, options) {
|
||||
this.body = body;
|
||||
@@ -2426,7 +2424,7 @@
|
||||
|
||||
return If;
|
||||
|
||||
})();
|
||||
})(Base);
|
||||
|
||||
Closure = {
|
||||
wrap: function(expressions, statement, noReturn) {
|
||||
|
||||
@@ -69,13 +69,14 @@
|
||||
return null;
|
||||
};
|
||||
|
||||
Scope.prototype.freeVariable = function(type) {
|
||||
Scope.prototype.freeVariable = function(name, reserve) {
|
||||
var index, temp;
|
||||
if (reserve == null) reserve = true;
|
||||
index = 0;
|
||||
while (this.check((temp = this.temporary(type, index)))) {
|
||||
while (this.check((temp = this.temporary(name, index)))) {
|
||||
index++;
|
||||
}
|
||||
this.add(temp, 'var', true);
|
||||
if (reserve) this.add(temp, 'var', true);
|
||||
return temp;
|
||||
};
|
||||
|
||||
|
||||
@@ -937,9 +937,6 @@ exports.Class = class Class extends Base
|
||||
@walkBody name, o
|
||||
@ensureConstructor name
|
||||
@body.spaced = yes
|
||||
if @parent
|
||||
@superClass = new Literal o.scope.freeVariable 'super'
|
||||
@body.expressions.unshift new Extends lname, @superClass
|
||||
@body.expressions.unshift @ctor unless @ctor instanceof Code
|
||||
@body.expressions.push lname
|
||||
@addBoundFunctions o
|
||||
@@ -947,10 +944,12 @@ exports.Class = class Class extends Base
|
||||
call = Closure.wrap @body
|
||||
|
||||
if @parent
|
||||
@superClass = new Literal o.scope.freeVariable 'super', no
|
||||
@body.expressions.unshift new Extends lname, @superClass
|
||||
call.args.push @parent
|
||||
call.variable.params.push new Param @superClass
|
||||
|
||||
klass = new Parens call, true
|
||||
klass = new Parens call, yes
|
||||
klass = new Assign @variable, klass if @variable
|
||||
klass.compile o
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ exports.Scope = class Scope
|
||||
|
||||
# If we need to store an intermediate result, find an available name for a
|
||||
# compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
freeVariable: (type) ->
|
||||
freeVariable: (name, reserve=true) ->
|
||||
index = 0
|
||||
index++ while @check((temp = @temporary type, index))
|
||||
@add temp, 'var', yes
|
||||
index++ while @check((temp = @temporary name, index))
|
||||
@add temp, 'var', yes if reserve
|
||||
temp
|
||||
|
||||
# Ensure that an assignment is made at the top of this scope
|
||||
|
||||
Reference in New Issue
Block a user