mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fiddling with For#compileNode.
This commit is contained in:
parent
460272291f
commit
ad9b7d700a
2 changed files with 16 additions and 9 deletions
14
lib/nodes.js
14
lib/nodes.js
|
@ -1796,6 +1796,9 @@
|
|||
rvar = scope.freeVariable('results');
|
||||
}
|
||||
ivar = (this.range ? name : index) || scope.freeVariable('i');
|
||||
if (this.pattern) {
|
||||
name = ivar;
|
||||
}
|
||||
varPart = '';
|
||||
guardPart = '';
|
||||
defPart = '';
|
||||
|
@ -1814,7 +1817,9 @@
|
|||
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
||||
svar = ref;
|
||||
}
|
||||
namePart = this.pattern ? new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")).compile(o, LEVEL_TOP) : name ? "" + name + " = " + svar + "[" + ivar + "]" : void 0;
|
||||
if (name && !this.pattern) {
|
||||
namePart = "" + name + " = " + svar + "[" + ivar + "]";
|
||||
}
|
||||
if (!this.object) {
|
||||
lvar = scope.freeVariable('len');
|
||||
stepPart = this.step ? "" + ivar + " += " + (this.step.compile(o, LEVEL_OP)) : "" + ivar + "++";
|
||||
|
@ -1824,9 +1829,7 @@
|
|||
if (this.scoped) {
|
||||
body = Closure.wrap(body, true, !this.returns);
|
||||
}
|
||||
if (!this.pattern) {
|
||||
defPart += this.pluckDirectCall(o, body, name, index);
|
||||
}
|
||||
defPart += this.pluckDirectCall(o, body, name, index);
|
||||
if (this.returns && !hasPureLast) {
|
||||
resultPart = "" + this.tab + rvar + " = [];\n";
|
||||
returnResult = '\n' + (new Return(new Literal(rvar)).compile(o, LEVEL_PAREN));
|
||||
|
@ -1835,6 +1838,9 @@
|
|||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
if (this.pattern) {
|
||||
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")));
|
||||
}
|
||||
if (namePart) {
|
||||
varPart = "\n" + idt1 + namePart + ";";
|
||||
}
|
||||
|
|
|
@ -1451,6 +1451,7 @@ exports.For = class For extends Base
|
|||
scope.find(index, immediate: yes) if index
|
||||
rvar = scope.freeVariable 'results' if @returns and not hasPureLast
|
||||
ivar = (if @range then name else index) or scope.freeVariable 'i'
|
||||
name = ivar if @pattern
|
||||
varPart = ''
|
||||
guardPart = ''
|
||||
defPart = ''
|
||||
|
@ -1464,23 +1465,23 @@ exports.For = class For extends Base
|
|||
if (name or @own) and not IDENTIFIER.test svar
|
||||
defPart = "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
|
||||
svar = ref
|
||||
namePart = if @pattern
|
||||
new Assign(@name, new Literal "#{svar}[#{ivar}]").compile o, LEVEL_TOP
|
||||
else if name
|
||||
"#{name} = #{svar}[#{ivar}]"
|
||||
if name and not @pattern
|
||||
namePart = "#{name} = #{svar}[#{ivar}]"
|
||||
unless @object
|
||||
lvar = scope.freeVariable 'len'
|
||||
stepPart = if @step then "#{ivar} += #{ @step.compile(o, LEVEL_OP) }" else "#{ivar}++"
|
||||
forPart = "#{ivar} = 0, #{lvar} = #{svar}.length; #{ivar} < #{lvar}; #{stepPart}"
|
||||
if @scoped
|
||||
body = Closure.wrap body, true, not @returns
|
||||
defPart += @pluckDirectCall o, body, name, index unless @pattern
|
||||
defPart += @pluckDirectCall o, body, name, index
|
||||
if @returns and not hasPureLast
|
||||
resultPart = "#{@tab}#{rvar} = [];\n"
|
||||
returnResult = '\n' + (new Return(new Literal(rvar)).compile o, LEVEL_PAREN)
|
||||
body = Push.wrap rvar, body
|
||||
if @guard
|
||||
body = Expressions.wrap [new If @guard, body]
|
||||
if @pattern
|
||||
body.expressions.unshift new Assign @name, new Literal "#{svar}[#{ivar}]"
|
||||
varPart = "\n#{idt1}#{namePart};" if namePart
|
||||
if @object
|
||||
forPart = "#{ivar} in #{svar}"
|
||||
|
|
Loading…
Reference in a new issue