diff --git a/lib/coffee_script/nodes.js b/lib/coffee_script/nodes.js index f2e9041d..ebba6bb9 100644 --- a/lib/coffee_script/nodes.js +++ b/lib/coffee_script/nodes.js @@ -311,7 +311,7 @@ // JavaScript without translation, eg.: strings, numbers, true, false, null... LiteralNode = (exports.LiteralNode = inherit(Node, { constructor: function constructor(value) { - this.children = [(this.value = value)]; + this.value = value; return this; }, // Break and continue must be treated as statements -- they lose their meaning @@ -563,12 +563,14 @@ return this.from_var + ' = ' + this.from.compile(o) + '; ' + this.to_var + ' = ' + this.to.compile(o) + ";\n" + this.idt(); }, compile_node: function compile_node(o) { - var compare, equals, idx, incr, intro, step; + var compare, equals, idx, incr, intro, step, vars; if (!(o.index)) { return this.compile_array(o); } idx = del(o, 'index'); step = del(o, 'step'); + vars = idx + '=' + this.from_var; + step = step ? step.compile(o) : '1'; equals = this.exclusive ? '' : '='; intro = '(' + this.from_var + ' <= ' + this.to_var + ' ? ' + idx; compare = intro + ' <' + equals + ' ' + this.to_var + ' : ' + idx + ' >' + equals + ' ' + this.to_var + ')'; @@ -583,7 +585,7 @@ body = Expressions.wrap([new LiteralNode('i')]); arr = Expressions.wrap([new ForNode(body, { source: (new ValueNode(this)) - }, 'i') + }, new LiteralNode('i')) ]); return (new ParentheticalNode(new CallNode(new CodeNode([], arr)))).compile(o); } diff --git a/src/nodes.coffee b/src/nodes.coffee index 19f667b6..31672e5d 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -195,7 +195,7 @@ statement Expressions LiteralNode: exports.LiteralNode: inherit Node, { constructor: (value) -> - @children: [@value: value] + @value: value this # Break and continue must be treated as statements -- they lose their meaning @@ -442,6 +442,8 @@ RangeNode: exports.RangeNode: inherit Node, { return @compile_array(o) unless o.index idx: del o, 'index' step: del o, 'step' + vars: idx + '=' + @from_var + step: if step then step.compile(o) else '1' equals: if @exclusive then '' else '=' intro: '(' + @from_var + ' <= ' + @to_var + ' ? ' + idx compare: intro + ' <' + equals + ' ' + @to_var + ' : ' + idx + ' >' + equals + ' ' + @to_var + ')' @@ -453,7 +455,7 @@ RangeNode: exports.RangeNode: inherit Node, { # TODO: This generates pretty ugly code ... shrink it. compile_array: (o) -> body: Expressions.wrap([new LiteralNode('i')]) - arr: Expressions.wrap([new ForNode(body, {source: (new ValueNode(this))}, 'i')]) + arr: Expressions.wrap([new ForNode(body, {source: (new ValueNode(this))}, new LiteralNode('i'))]) (new ParentheticalNode(new CallNode(new CodeNode([], arr)))).compile(o) }