mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
self-compiling ranges and expressions
This commit is contained in:
parent
38d1381c02
commit
950d1199c2
2 changed files with 9 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue