moving nodes.coffee over to use Tesco's new auto-setter style.

This commit is contained in:
Jeremy Ashkenas 2010-07-28 19:34:02 -04:00
parent a80d8d55c4
commit c67e7fbcea
2 changed files with 106 additions and 128 deletions

View File

@ -255,8 +255,8 @@
return new Expressions(nodes);
};
exports.LiteralNode = (function() {
LiteralNode = function(value) {
this.value = value;
LiteralNode = function(_b) {
this.value = _b;
return this;
};
__extends(LiteralNode, BaseNode);
@ -277,8 +277,8 @@
return LiteralNode;
})();
exports.ReturnNode = (function() {
ReturnNode = function(expression) {
this.expression = expression;
ReturnNode = function(_b) {
this.expression = _b;
return this;
};
__extends(ReturnNode, BaseNode);
@ -310,9 +310,10 @@
return ReturnNode;
})();
exports.ValueNode = (function() {
ValueNode = function(base, properties) {
this.base = base;
this.properties = properties || [];
ValueNode = function(_b, _c) {
this.properties = _c;
this.base = _b;
this.properties = this.properties || [];
return this;
};
__extends(ValueNode, BaseNode);
@ -403,8 +404,8 @@
return ValueNode;
})();
exports.CommentNode = (function() {
CommentNode = function(lines) {
this.lines = lines;
CommentNode = function(_b) {
this.lines = _b;
return this;
};
__extends(CommentNode, BaseNode);
@ -423,11 +424,12 @@
return CommentNode;
})();
exports.CallNode = (function() {
CallNode = function(variable, args) {
CallNode = function(variable, _b) {
this.args = _b;
this.isNew = false;
this.isSuper = variable === 'super';
this.variable = this.isSuper ? null : variable;
this.args = (args || []);
this.args = this.args || [];
this.compileSplatArguments = function(o) {
return SplatNode.compileSplattedArray.call(this, this.args, o);
};
@ -501,9 +503,9 @@
return CallNode;
})();
exports.ExtendsNode = (function() {
ExtendsNode = function(child, parent) {
this.child = child;
this.parent = parent;
ExtendsNode = function(_b, _c) {
this.parent = _c;
this.child = _b;
return this;
};
__extends(ExtendsNode, BaseNode);
@ -517,8 +519,8 @@
return ExtendsNode;
})();
exports.AccessorNode = (function() {
AccessorNode = function(name, tag) {
this.name = name;
AccessorNode = function(_b, tag) {
this.name = _b;
this.prototype = tag === 'prototype' ? '.prototype' : '';
this.soakNode = tag === 'soak';
return this;
@ -536,8 +538,8 @@
return AccessorNode;
})();
exports.IndexNode = (function() {
IndexNode = function(index) {
this.index = index;
IndexNode = function(_b) {
this.index = _b;
return this;
};
__extends(IndexNode, BaseNode);
@ -553,9 +555,9 @@
return IndexNode;
})();
exports.RangeNode = (function() {
RangeNode = function(from, to, exclusive) {
this.from = from;
this.to = to;
RangeNode = function(_b, _c, exclusive) {
this.to = _c;
this.from = _b;
this.exclusive = !!exclusive;
this.equals = this.exclusive ? '' : '=';
return this;
@ -650,8 +652,8 @@
return RangeNode;
})();
exports.SliceNode = (function() {
SliceNode = function(range) {
this.range = range;
SliceNode = function(_b) {
this.range = _b;
return this;
};
__extends(SliceNode, BaseNode);
@ -714,8 +716,9 @@
return ObjectNode;
})();
exports.ArrayNode = (function() {
ArrayNode = function(objects) {
this.objects = objects || [];
ArrayNode = function(_b) {
this.objects = _b;
this.objects = this.objects || [];
this.compileSplatLiteral = function(o) {
return SplatNode.compileSplattedArray.call(this, this.objects, o);
};
@ -748,10 +751,11 @@
return ArrayNode;
})();
exports.ClassNode = (function() {
ClassNode = function(variable, parent, props) {
this.variable = variable;
this.parent = parent;
this.properties = props || [];
ClassNode = function(_b, _c, _d) {
this.properties = _d;
this.parent = _c;
this.variable = _b;
this.properties = this.properties || [];
this.returns = false;
return this;
};
@ -830,10 +834,10 @@
return ClassNode;
})();
exports.AssignNode = (function() {
AssignNode = function(variable, value, context) {
this.variable = variable;
this.value = value;
this.context = context;
AssignNode = function(_b, _c, _d) {
this.context = _d;
this.value = _c;
this.variable = _b;
return this;
};
__extends(AssignNode, BaseNode);
@ -948,9 +952,11 @@
return AssignNode;
})();
exports.CodeNode = (function() {
CodeNode = function(params, body, tag) {
this.params = params || [];
this.body = body || new Expressions();
CodeNode = function(_b, _c, tag) {
this.body = _c;
this.params = _b;
this.params = this.params || [];
this.body = this.body || new Expressions();
this.bound = tag === 'boundfunc';
return this;
};
@ -1185,10 +1191,11 @@
return WhileNode;
})();
exports.OpNode = (function() {
OpNode = function(operator, first, second, flip) {
this.first = first;
this.second = second;
this.operator = this.CONVERSIONS[operator] || operator;
OpNode = function(_b, _c, _d, flip) {
this.second = _d;
this.first = _c;
this.operator = _b;
this.operator = this.CONVERSIONS[this.operator] || this.operator;
this.flip = !!flip;
this.first instanceof ValueNode && this.first.base instanceof ObjectNode ? (this.first = new ParentheticalNode(this.first)) : null;
return this;
@ -1275,9 +1282,9 @@
return OpNode;
})();
exports.InNode = (function() {
InNode = function(object, array) {
this.object = object;
this.array = array;
InNode = function(_b, _c) {
this.array = _c;
this.object = _b;
return this;
};
__extends(InNode, BaseNode);
@ -1323,11 +1330,11 @@
return InNode;
})();
exports.TryNode = (function() {
TryNode = function(attempt, error, recovery, ensure) {
this.attempt = attempt;
this.recovery = recovery;
this.ensure = ensure;
this.error = error;
TryNode = function(_b, _c, _d, _e) {
this.ensure = _e;
this.recovery = _d;
this.error = _c;
this.attempt = _b;
return this;
};
__extends(TryNode, BaseNode);
@ -1358,8 +1365,8 @@
return TryNode;
})();
exports.ThrowNode = (function() {
ThrowNode = function(expression) {
this.expression = expression;
ThrowNode = function(_b) {
this.expression = _b;
return this;
};
__extends(ThrowNode, BaseNode);
@ -1377,8 +1384,8 @@
return ThrowNode;
})();
exports.ExistenceNode = (function() {
ExistenceNode = function(expression) {
this.expression = expression;
ExistenceNode = function(_b) {
this.expression = _b;
return this;
};
__extends(ExistenceNode, BaseNode);
@ -1397,8 +1404,8 @@
return ExistenceNode;
}).call(this);
exports.ParentheticalNode = (function() {
ParentheticalNode = function(expression) {
this.expression = expression;
ParentheticalNode = function(_b) {
this.expression = _b;
return this;
};
__extends(ParentheticalNode, BaseNode);
@ -1429,20 +1436,21 @@
return ParentheticalNode;
})();
exports.ForNode = (function() {
ForNode = function(body, source, name, index) {
var _b;
this.body = body;
this.name = name;
this.index = index || null;
ForNode = function(_b, source, _c, _d) {
var _e;
this.index = _d;
this.name = _c;
this.body = _b;
this.index = this.index || null;
this.source = source.source;
this.guard = source.guard;
this.step = source.step;
this.raw = !!source.raw;
this.object = !!source.object;
if (this.object) {
_b = [this.index, this.name];
this.name = _b[0];
this.index = _b[1];
_e = [this.index, this.name];
this.name = _e[0];
this.index = _e[1];
}
this.pattern = this.name instanceof ValueNode;
if (this.index instanceof ValueNode) {
@ -1564,10 +1572,11 @@
return ForNode;
})();
exports.IfNode = (function() {
IfNode = function(condition, body, tags) {
this.condition = condition;
this.body = body;
this.tags = tags || {};
IfNode = function(_b, _c, _d) {
this.tags = _d;
this.body = _c;
this.condition = _b;
this.tags = this.tags || {};
if (this.tags.invert) {
this.condition = new OpNode('!', new ParentheticalNode(this.condition));
}

View File

@ -236,8 +236,7 @@ exports.LiteralNode = class LiteralNode extends BaseNode
class: 'LiteralNode'
constructor: (value) ->
@value = value
constructor: (@value) ->
# Break and continue must be treated as pure statements -- they lose their
# meaning when wrapped in a closure.
@ -264,8 +263,7 @@ exports.ReturnNode = class ReturnNode extends BaseNode
isPureStatement: -> yes
children: ['expression']
constructor: (expression) ->
@expression = expression
constructor: (@expression) ->
makeReturn: ->
this
@ -291,9 +289,8 @@ exports.ValueNode = class ValueNode extends BaseNode
children: ['base', 'properties']
# A **ValueNode** has a base and a list of property accesses.
constructor: (base, properties) ->
@base = base
@properties = properties or []
constructor: (@base, @properties) ->
@properties = or []
# Add a property access to the list.
push: (prop) ->
@ -378,8 +375,7 @@ exports.CommentNode = class CommentNode extends BaseNode
class: 'CommentNode'
isStatement: -> yes
constructor: (lines) ->
@lines = lines
constructor: (@lines) ->
makeReturn: ->
this
@ -397,11 +393,11 @@ exports.CallNode = class CallNode extends BaseNode
class: 'CallNode'
children: ['variable', 'args']
constructor: (variable, args) ->
constructor: (variable, @args) ->
@isNew = false
@isSuper = variable is 'super'
@variable = if @isSuper then null else variable
@args = (args or [])
@args = or []
@compileSplatArguments = (o) ->
SplatNode.compileSplattedArray.call(this, @args, o)
@ -471,9 +467,7 @@ exports.ExtendsNode = class ExtendsNode extends BaseNode
class: 'ExtendsNode'
children: ['child', 'parent']
constructor: (child, parent) ->
@child = child
@parent = parent
constructor: (@child, @parent) ->
# Hooks one constructor into another's prototype chain.
compileNode: (o) ->
@ -489,8 +483,7 @@ exports.AccessorNode = class AccessorNode extends BaseNode
class: 'AccessorNode'
children: ['name']
constructor: (name, tag) ->
@name = name
constructor: (@name, tag) ->
@prototype = if tag is 'prototype' then '.prototype' else ''
@soakNode = tag is 'soak'
@ -508,8 +501,7 @@ exports.IndexNode = class IndexNode extends BaseNode
class: 'IndexNode'
children: ['index']
constructor: (index) ->
@index = index
constructor: (@index) ->
compileNode: (o) ->
o.chainRoot.wrapped = or @soakNode
@ -527,9 +519,7 @@ exports.RangeNode = class RangeNode extends BaseNode
class: 'RangeNode'
children: ['from', 'to']
constructor: (from, to, exclusive) ->
@from = from
@to = to
constructor: (@from, @to, exclusive) ->
@exclusive = !!exclusive
@equals = if @exclusive then '' else '='
@ -600,8 +590,7 @@ exports.SliceNode = class SliceNode extends BaseNode
class: 'SliceNode'
children: ['range']
constructor: (range) ->
@range = range
constructor: (@range) ->
compileNode: (o) ->
from = @range.from.compile(o)
@ -643,8 +632,8 @@ exports.ArrayNode = class ArrayNode extends BaseNode
class: 'ArrayNode'
children: ['objects']
constructor: (objects) ->
@objects = objects or []
constructor: (@objects) ->
@objects = or []
@compileSplatLiteral = (o) ->
SplatNode.compileSplattedArray.call(this, @objects, o)
@ -678,10 +667,8 @@ exports.ClassNode = class ClassNode extends BaseNode
# Initialize a **ClassNode** with its name, an optional superclass, and a
# list of prototype property assignments.
constructor: (variable, parent, props) ->
@variable = variable
@parent = parent
@properties = props or []
constructor: (@variable, @parent, @properties) ->
@properties = or []
@returns = false
makeReturn: ->
@ -751,10 +738,7 @@ exports.AssignNode = class AssignNode extends BaseNode
class: 'AssignNode'
children: ['variable', 'value']
constructor: (variable, value, context) ->
@variable = variable
@value = value
@context = context
constructor: (@variable, @value, @context) ->
topSensitive: ->
true
@ -853,9 +837,9 @@ exports.CodeNode = class CodeNode extends BaseNode
class: 'CodeNode'
children: ['params', 'body']
constructor: (params, body, tag) ->
@params = params or []
@body = body or new Expressions
constructor: (@params, @body, tag) ->
@params = or []
@body = or new Expressions
@bound = tag is 'boundfunc'
# Compilation creates a new scope unless explicitly asked to share with the
@ -1068,10 +1052,8 @@ exports.OpNode = class OpNode extends BaseNode
class: 'OpNode'
children: ['first', 'second']
constructor: (operator, first, second, flip) ->
@first = first
@second = second
@operator = @CONVERSIONS[operator] or operator
constructor: (@operator, @first, @second, flip) ->
@operator = @CONVERSIONS[@operator] or @operator
@flip = !!flip
if @first instanceof ValueNode and @first.base instanceof ObjectNode
@first = new ParentheticalNode @first
@ -1133,9 +1115,7 @@ exports.InNode = class InNode extends BaseNode
class: 'InNode'
children: ['object', 'array']
constructor: (object, array) ->
@object = object
@array = array
constructor: (@object, @array) ->
isArray: ->
@array instanceof ValueNode and @array.isArray()
@ -1164,11 +1144,7 @@ exports.TryNode = class TryNode extends BaseNode
children: ['attempt', 'recovery', 'ensure']
isStatement: -> yes
constructor: (attempt, error, recovery, ensure) ->
@attempt = attempt
@recovery = recovery
@ensure = ensure
@error = error
constructor: (@attempt, @error, @recovery, @ensure) ->
makeReturn: ->
@attempt = @attempt.makeReturn() if @attempt
@ -1195,8 +1171,7 @@ exports.ThrowNode = class ThrowNode extends BaseNode
children: ['expression']
isStatement: -> yes
constructor: (expression) ->
@expression = expression
constructor: (@expression) ->
# A **ThrowNode** is already a return, of sorts...
makeReturn: ->
@ -1215,8 +1190,7 @@ exports.ExistenceNode = class ExistenceNode extends BaseNode
class: 'ExistenceNode'
children: ['expression']
constructor: (expression) ->
@expression = expression
constructor: (@expression) ->
compileNode: (o) ->
ExistenceNode.compileTest(o, @expression)
@ -1240,8 +1214,7 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode
class: 'ParentheticalNode'
children: ['expression']
constructor: (expression) ->
@expression = expression
constructor: (@expression) ->
isStatement: ->
@expression.isStatement()
@ -1276,10 +1249,8 @@ exports.ForNode = class ForNode extends BaseNode
children: ['body', 'source', 'guard']
isStatement: -> yes
constructor: (body, source, name, index) ->
@body = body
@name = name
@index = index or null
constructor: (@body, source, @name, @index) ->
@index = or null
@source = source.source
@guard = source.guard
@step = source.step
@ -1367,10 +1338,8 @@ exports.IfNode = class IfNode extends BaseNode
class: 'IfNode'
children: ['condition', 'switchSubject', 'body', 'elseBody', 'assigner']
constructor: (condition, body, tags) ->
@condition = condition
@body = body
@tags = tags or {}
constructor: (@condition, @body, @tags) ->
@tags = or {}
@condition = new OpNode('!', new ParentheticalNode(@condition)) if @tags.invert
@elseBody = null
@isChain = false