diff --git a/lib/nodes.js b/lib/nodes.js index 922a76e5..2dbc5de3 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -112,7 +112,7 @@ } return _result; }).call(this).join(''); - klass = override || this["class"] + (this.soakNode || this.exist ? '?' : ''); + klass = override || this.constructor.name + (this.soakNode || this.exist ? '?' : ''); return '\n' + idt + klass + children; }; BaseNode.prototype.eachChild = function(func) { @@ -151,7 +151,6 @@ return child instanceof BaseNode && (crossScope || !(child instanceof CodeNode)) ? child.traverseChildren(crossScope, func) : undefined; }); }; - BaseNode.prototype["class"] = 'BaseNode'; BaseNode.prototype.children = []; BaseNode.prototype.unwrap = THIS; BaseNode.prototype.isStatement = NO; @@ -169,7 +168,6 @@ }; })(); __extends(Expressions, BaseNode); - Expressions.prototype["class"] = 'Expressions'; Expressions.prototype.children = ['expressions']; Expressions.prototype.isStatement = YES; Expressions.prototype.push = function(node) { @@ -256,7 +254,6 @@ }; })(); __extends(LiteralNode, BaseNode); - LiteralNode.prototype["class"] = 'LiteralNode'; LiteralNode.prototype.makeReturn = function() { return this.isStatement() ? this : LiteralNode.__super__.makeReturn.call(this); }; @@ -286,7 +283,6 @@ }; })(); __extends(ReturnNode, BaseNode); - ReturnNode.prototype["class"] = 'ReturnNode'; ReturnNode.prototype.isStatement = YES; ReturnNode.prototype.isPureStatement = YES; ReturnNode.prototype.children = ['expression']; @@ -321,7 +317,6 @@ }; })(); __extends(ValueNode, BaseNode); - ValueNode.prototype["class"] = 'ValueNode'; ValueNode.prototype.children = ['base', 'properties']; ValueNode.prototype.push = function(prop) { this.properties.push(prop); @@ -450,7 +445,6 @@ }; })(); __extends(CommentNode, BaseNode); - CommentNode.prototype["class"] = 'CommentNode'; CommentNode.prototype.isStatement = YES; CommentNode.prototype.makeReturn = THIS; CommentNode.prototype.compileNode = function(o) { @@ -472,7 +466,6 @@ }; })(); __extends(CallNode, BaseNode); - CallNode.prototype["class"] = 'CallNode'; CallNode.prototype.children = ['variable', 'args']; CallNode.prototype.compileSplatArguments = function(o) { return SplatNode.compileSplattedArray(this.args, o); @@ -619,7 +612,6 @@ }; })(); __extends(ExtendsNode, BaseNode); - ExtendsNode.prototype["class"] = 'ExtendsNode'; ExtendsNode.prototype.children = ['child', 'parent']; ExtendsNode.prototype.compileNode = function(o) { var ref; @@ -639,7 +631,6 @@ }; })(); __extends(AccessorNode, BaseNode); - AccessorNode.prototype["class"] = 'AccessorNode'; AccessorNode.prototype.children = ['name']; AccessorNode.prototype.compileNode = function(o) { var name, namePart; @@ -659,7 +650,6 @@ }; })(); __extends(IndexNode, BaseNode); - IndexNode.prototype["class"] = 'IndexNode'; IndexNode.prototype.children = ['index']; IndexNode.prototype.compileNode = function(o) { var idx, prefix; @@ -684,7 +674,6 @@ }; })(); __extends(RangeNode, BaseNode); - RangeNode.prototype["class"] = 'RangeNode'; RangeNode.prototype.children = ['from', 'to']; RangeNode.prototype.compileVariables = function(o) { var _ref2, parts; @@ -773,7 +762,6 @@ }; })(); __extends(SliceNode, BaseNode); - SliceNode.prototype["class"] = 'SliceNode'; SliceNode.prototype.children = ['range']; SliceNode.prototype.compileNode = function(o) { var from, to; @@ -796,7 +784,6 @@ }; })(); __extends(ObjectNode, BaseNode); - ObjectNode.prototype["class"] = 'ObjectNode'; ObjectNode.prototype.children = ['properties']; ObjectNode.prototype.topSensitive = YES; ObjectNode.prototype.compileNode = function(o) { @@ -853,7 +840,6 @@ }; })(); __extends(ArrayNode, BaseNode); - ArrayNode.prototype["class"] = 'ArrayNode'; ArrayNode.prototype.children = ['objects']; ArrayNode.prototype.compileSplatLiteral = function(o) { return SplatNode.compileSplattedArray(this.objects, o); @@ -894,7 +880,6 @@ }; })(); __extends(ClassNode, BaseNode); - ClassNode.prototype["class"] = 'ClassNode'; ClassNode.prototype.children = ['variable', 'parent', 'properties']; ClassNode.prototype.isStatement = YES; ClassNode.prototype.makeReturn = function() { @@ -980,7 +965,6 @@ })(); __extends(AssignNode, BaseNode); AssignNode.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/; - AssignNode.prototype["class"] = 'AssignNode'; AssignNode.prototype.children = ['variable', 'value']; AssignNode.prototype.topSensitive = YES; AssignNode.prototype.isValue = function() { @@ -1109,7 +1093,6 @@ }; })(); __extends(CodeNode, BaseNode); - CodeNode.prototype["class"] = 'CodeNode'; CodeNode.prototype.children = ['params', 'body']; CodeNode.prototype.compileNode = function(o) { var _i, _len, _ref2, _ref3, _result, close, code, empty, func, i, open, param, params, sharedScope, splat, top, value; @@ -1194,7 +1177,6 @@ }; })(); __extends(ParamNode, BaseNode); - ParamNode.prototype["class"] = 'ParamNode'; ParamNode.prototype.children = ['name']; ParamNode.prototype.compileNode = function(o) { return this.value.compile(o); @@ -1224,7 +1206,6 @@ }; })(); __extends(SplatNode, BaseNode); - SplatNode.prototype["class"] = 'SplatNode'; SplatNode.prototype.children = ['name']; SplatNode.prototype.compileNode = function(o) { return (this.index != null) ? this.compileParam(o) : this.name.compile(o); @@ -1300,7 +1281,6 @@ }; })(); __extends(WhileNode, BaseNode); - WhileNode.prototype["class"] = 'WhileNode'; WhileNode.prototype.children = ['condition', 'guard', 'body']; WhileNode.prototype.isStatement = YES; WhileNode.prototype.addBody = function(body) { @@ -1375,7 +1355,6 @@ OpNode.prototype.CHAINABLE = ['<', '>', '>=', '<=', '===', '!==']; OpNode.prototype.ASSIGNMENT = ['||=', '&&=', '?=']; OpNode.prototype.PREFIX_OPERATORS = ['new', 'typeof', 'delete']; - OpNode.prototype["class"] = 'OpNode'; OpNode.prototype.children = ['first', 'second']; OpNode.prototype.isUnary = function() { return !this.second; @@ -1398,7 +1377,7 @@ return (this.operator = this.INVERSIONS[this.operator]); }; OpNode.prototype.toString = function(idt) { - return OpNode.__super__.toString.call(this, idt, this["class"] + ' ' + this.operator); + return OpNode.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator); }; OpNode.prototype.compileNode = function(o) { var node; @@ -1470,7 +1449,6 @@ }; })(); __extends(InNode, BaseNode); - InNode.prototype["class"] = 'InNode'; InNode.prototype.children = ['object', 'array']; InNode.prototype.isArray = function() { return this.array instanceof ValueNode && this.array.isArray(); @@ -1517,7 +1495,6 @@ }; })(); __extends(TryNode, BaseNode); - TryNode.prototype["class"] = 'TryNode'; TryNode.prototype.children = ['attempt', 'recovery', 'ensure']; TryNode.prototype.isStatement = YES; TryNode.prototype.makeReturn = function() { @@ -1550,7 +1527,6 @@ }; })(); __extends(ThrowNode, BaseNode); - ThrowNode.prototype["class"] = 'ThrowNode'; ThrowNode.prototype.children = ['expression']; ThrowNode.prototype.isStatement = YES; ThrowNode.prototype.makeReturn = THIS; @@ -1568,7 +1544,6 @@ }; })(); __extends(ExistenceNode, BaseNode); - ExistenceNode.prototype["class"] = 'ExistenceNode'; ExistenceNode.prototype.children = ['expression']; ExistenceNode.prototype.compileNode = function(o) { var code; @@ -1587,7 +1562,6 @@ }; })(); __extends(ParentheticalNode, BaseNode); - ParentheticalNode.prototype["class"] = 'ParentheticalNode'; ParentheticalNode.prototype.children = ['expression']; ParentheticalNode.prototype.isStatement = function(o) { return this.expression.isStatement(o); @@ -1640,7 +1614,6 @@ }; })(); __extends(ForNode, BaseNode); - ForNode.prototype["class"] = 'ForNode'; ForNode.prototype.children = ['body', 'source', 'guard']; ForNode.prototype.isStatement = YES; ForNode.prototype.topSensitive = YES; @@ -1768,7 +1741,6 @@ }; })(); __extends(SwitchNode, BaseNode); - SwitchNode.prototype["class"] = 'SwitchNode'; SwitchNode.prototype.children = ['subject', 'cases', 'otherwise']; SwitchNode.prototype.isStatement = YES; SwitchNode.prototype.makeReturn = function() { @@ -1834,7 +1806,6 @@ }; })(); __extends(IfNode, BaseNode); - IfNode.prototype["class"] = 'IfNode'; IfNode.prototype.children = ['condition', 'body', 'elseBody', 'assigner']; IfNode.prototype.topSensitive = YES; IfNode.prototype.bodyNode = function() { diff --git a/src/nodes.coffee b/src/nodes.coffee index 6ab8b9f1..a5a3090e 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -113,7 +113,7 @@ exports.BaseNode = class BaseNode toString: (idt, override) -> idt or= '' children = (child.toString idt + TAB for child in @collectChildren()).join('') - klass = override or @class + if @soakNode or @exist then '?' else '' + klass = override or @constructor.name + if @soakNode or @exist then '?' else '' '\n' + idt + klass + children eachChild: (func) -> @@ -136,7 +136,6 @@ exports.BaseNode = class BaseNode # Default implementations of the common node properties and methods. Nodes # will override these with custom logic, if needed. - class: 'BaseNode' children: [] unwrap : THIS @@ -152,7 +151,6 @@ exports.BaseNode = class BaseNode # `if`, `switch`, or `try`, and so on... exports.Expressions = class Expressions extends BaseNode - class: 'Expressions' children: ['expressions'] isStatement: YES @@ -236,8 +234,6 @@ Expressions.wrap = (nodes) -> # `true`, `false`, `null`... exports.LiteralNode = class LiteralNode extends BaseNode - class: 'LiteralNode' - constructor: (@value) -> super() @@ -265,7 +261,6 @@ exports.LiteralNode = class LiteralNode extends BaseNode # make sense. exports.ReturnNode = class ReturnNode extends BaseNode - class: 'ReturnNode' isStatement: YES isPureStatement: YES children: ['expression'] @@ -290,7 +285,6 @@ exports.ReturnNode = class ReturnNode extends BaseNode # or vanilla. exports.ValueNode = class ValueNode extends BaseNode - class: 'ValueNode' children: ['base', 'properties'] # A **ValueNode** has a base and a list of property accesses. @@ -411,7 +405,6 @@ exports.ValueNode = class ValueNode extends BaseNode # at the same position. exports.CommentNode = class CommentNode extends BaseNode - class: 'CommentNode' isStatement: YES constructor: (@comment) -> @@ -428,7 +421,6 @@ exports.CommentNode = class CommentNode extends BaseNode # calls against the prototype's function of the same name. exports.CallNode = class CallNode extends BaseNode - class: 'CallNode' children: ['variable', 'args'] constructor: (variable, @args, @exist) -> @@ -548,7 +540,6 @@ exports.CallNode = class CallNode extends BaseNode # [Closure Library](http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.html). exports.ExtendsNode = class ExtendsNode extends BaseNode - class: 'ExtendsNode' children: ['child', 'parent'] constructor: (@child, @parent) -> @@ -565,7 +556,6 @@ exports.ExtendsNode = class ExtendsNode extends BaseNode # an accessor into the object's prototype. exports.AccessorNode = class AccessorNode extends BaseNode - class: 'AccessorNode' children: ['name'] constructor: (@name, tag) -> @@ -585,7 +575,6 @@ exports.AccessorNode = class AccessorNode extends BaseNode # A `[ ... ]` indexed accessor into an array or object. exports.IndexNode = class IndexNode extends BaseNode - class: 'IndexNode' children: ['index'] constructor: (@index) -> @@ -605,7 +594,6 @@ exports.IndexNode = class IndexNode extends BaseNode # corresponding array of integers at runtime. exports.RangeNode = class RangeNode extends BaseNode - class: 'RangeNode' children: ['from', 'to'] constructor: (@from, @to, tag) -> @@ -677,7 +665,6 @@ exports.RangeNode = class RangeNode extends BaseNode # is the index of the beginning. exports.SliceNode = class SliceNode extends BaseNode - class: 'SliceNode' children: ['range'] constructor: (@range) -> @@ -695,7 +682,6 @@ exports.SliceNode = class SliceNode extends BaseNode # An object literal, nothing fancy. exports.ObjectNode = class ObjectNode extends BaseNode - class: 'ObjectNode' children: ['properties'] topSensitive: YES @@ -728,7 +714,6 @@ exports.ObjectNode = class ObjectNode extends BaseNode # An array literal. exports.ArrayNode = class ArrayNode extends BaseNode - class: 'ArrayNode' children: ['objects'] constructor: (@objects) -> @@ -762,7 +747,6 @@ exports.ArrayNode = class ArrayNode extends BaseNode # The CoffeeScript class definition. exports.ClassNode = class ClassNode extends BaseNode - class: 'ClassNode' children: ['variable', 'parent', 'properties'] isStatement: YES @@ -840,7 +824,6 @@ exports.AssignNode = class AssignNode extends BaseNode # Matchers for detecting class/method names METHOD_DEF: /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/ - class: 'AssignNode' children: ['variable', 'value'] constructor: (@variable, @value, @context) -> @@ -942,7 +925,6 @@ exports.AssignNode = class AssignNode extends BaseNode # has no *children* -- they're within the inner scope. exports.CodeNode = class CodeNode extends BaseNode - class: 'CodeNode' children: ['params', 'body'] constructor: (@params, @body, tag) -> @@ -1011,7 +993,6 @@ exports.CodeNode = class CodeNode extends BaseNode # as well as be a splat, gathering up a group of parameters into an array. exports.ParamNode = class ParamNode extends BaseNode - class: 'ParamNode' children: ['name'] constructor: (@name, @attach, @splat) -> @@ -1033,7 +1014,6 @@ exports.ParamNode = class ParamNode extends BaseNode # or as part of a destructuring assignment. exports.SplatNode = class SplatNode extends BaseNode - class: 'SplatNode' children: ['name'] constructor: (name) -> @@ -1097,7 +1077,6 @@ exports.SplatNode = class SplatNode extends BaseNode # flexibility or more speed than a comprehension can provide. exports.WhileNode = class WhileNode extends BaseNode - class: 'WhileNode' children: ['condition', 'guard', 'body'] isStatement: YES @@ -1167,7 +1146,6 @@ exports.OpNode = class OpNode extends BaseNode # Operators must come before their operands with a space. PREFIX_OPERATORS: ['new', 'typeof', 'delete'] - class: 'OpNode' children: ['first', 'second'] constructor: (@operator, @first, @second, flip) -> @@ -1200,7 +1178,7 @@ exports.OpNode = class OpNode extends BaseNode @operator = @INVERSIONS[@operator] toString: (idt) -> - super(idt, @class + ' ' + @operator) + super(idt, @constructor.name + ' ' + @operator) compileNode: (o) -> return node.compile o if node = ValueNode.unfoldSoak o, this, 'first' @@ -1250,7 +1228,6 @@ exports.OpNode = class OpNode extends BaseNode #### InNode exports.InNode = class InNode extends BaseNode - class: 'InNode' children: ['object', 'array'] constructor: (@object, @array) -> @@ -1279,7 +1256,6 @@ exports.InNode = class InNode extends BaseNode # A classic *try/catch/finally* block. exports.TryNode = class TryNode extends BaseNode - class: 'TryNode' children: ['attempt', 'recovery', 'ensure'] isStatement: YES @@ -1309,7 +1285,6 @@ exports.TryNode = class TryNode extends BaseNode # Simple node to throw an exception. exports.ThrowNode = class ThrowNode extends BaseNode - class: 'ThrowNode' children: ['expression'] isStatement: YES @@ -1329,7 +1304,6 @@ exports.ThrowNode = class ThrowNode extends BaseNode # table. exports.ExistenceNode = class ExistenceNode extends BaseNode - class: 'ExistenceNode' children: ['expression'] constructor: (@expression) -> @@ -1352,7 +1326,6 @@ exports.ExistenceNode = class ExistenceNode extends BaseNode # Parentheses are a good way to force any statement to become an expression. exports.ParentheticalNode = class ParentheticalNode extends BaseNode - class: 'ParentheticalNode' children: ['expression'] constructor: (@expression) -> @@ -1388,7 +1361,6 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode # you can map and filter in a single pass. exports.ForNode = class ForNode extends BaseNode - class: 'ForNode' children: ['body', 'source', 'guard'] isStatement: YES @@ -1485,7 +1457,6 @@ exports.ForNode = class ForNode extends BaseNode # A JavaScript *switch* statement. Converts into a returnable expression on-demand. exports.SwitchNode = class SwitchNode extends BaseNode - class: 'SwitchNode' children: ['subject', 'cases', 'otherwise'] isStatement: YES @@ -1526,7 +1497,6 @@ exports.SwitchNode = class SwitchNode extends BaseNode # because ternaries are already proper expressions, and don't need conversion. exports.IfNode = class IfNode extends BaseNode - class: 'IfNode' children: ['condition', 'body', 'elseBody', 'assigner'] topSensitive: YES