diff --git a/lib/nodes.js b/lib/nodes.js index 1831a994..6ba67ffe 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -623,24 +623,23 @@ vars = this.compileVariables(merge(o, { indent: idt })); - result = o.scope.freeVariable(); + if (this.fromNum && this.toNum && Math.abs(+this.fromNum - +this.toNum) <= 20) { + range = (function() { + _c = []; + for (var _b = +this.fromNum; +this.fromNum <= +this.toNum ? _b <= +this.toNum : _b >= +this.toNum; +this.fromNum <= +this.toNum ? _b += 1 : _b -= 1){ _c.push(_b) }; + return _c; + }).call(this); + if (this.exclusive) { + range.pop(); + } + return ("[" + (range.join(', ')) + "]"); + } i = o.scope.freeVariable(); + result = o.scope.freeVariable(); pre = ("\n" + (idt) + (result) + " = []; " + (vars)); if (this.fromNum && this.toNum) { - if (Math.abs(+this.fromNum - +this.toNum) <= 20) { - range = (function() { - _b = []; - for (var _c = +this.fromNum; +this.fromNum <= +this.toNum ? _c <= +this.toNum : _c >= +this.toNum; +this.fromNum <= +this.toNum ? _c += 1 : _c -= 1){ _b.push(_c) }; - return _b; - }).call(this); - if (this.exclusive) { - range.pop(); - } - return ("[" + (range.join(', ')) + "]"); - } else { - o.index = i; - body = this.compileSimple(o); - } + o.index = i; + body = this.compileSimple(o); } else { clause = ("" + this.fromVar + " <= " + this.toVar + " ?"); body = ("var " + i + " = " + this.fromVar + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1"); diff --git a/src/nodes.coffee b/src/nodes.coffee index f83e62b0..597665a1 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -574,21 +574,20 @@ exports.RangeNode = class RangeNode extends BaseNode compileArray: (o) -> idt = @idt 1 vars = @compileVariables merge o, indent: idt + if @fromNum and @toNum and Math.abs(+@fromNum - +@toNum) <= 20 + range = [+@fromNum..+@toNum] + range.pop() if @exclusive + return "[#{ range.join(', ') }]" + i = o.scope.freeVariable() result = o.scope.freeVariable() - i = o.scope.freeVariable() pre = "\n#{idt}#{result} = []; #{vars}" if @fromNum and @toNum - if Math.abs(+@fromNum - +@toNum) <= 20 - range = [+@fromNum..+@toNum] - range.pop() if @exclusive - return "[#{ range.join(', ') }]" - else - o.index = i - body = @compileSimple o + o.index = i + body = @compileSimple o else clause = "#@fromVar <= #@toVar ?" body = "var #i = #@fromVar; #clause #i <#@equals #@toVar : #i >#@equals #@toVar; #clause #i += 1 : #i -= 1" - post = "{ #{result}.push(#i) };\n#{idt}return #result;\n#o.indent" + post = "{ #{result}.push(#i) };\n#{idt}return #result;\n#o.indent" "(function() {#{pre}\n#{idt}for (#body)#post}).call(this)" #### SliceNode