 
   # When used as a value, expand the range into the equivalent array.
   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 'i'
+    idt    = @idt 1
+    i      = o.scope.freeVariable 'i'
     result = o.scope.freeVariable 'result'
-    pre    = "\n#{idt}#{result} = []; #{vars}"
+    pre    = "\n#{idt}#{result} = [];"
     if @fromNum and @toNum
       o.index = i
       body = @compileSimple o
     else
+      vars = "#{i} = #{@from}" + if @to isnt @toVar then ", #{@to}" else ''
       clause = "#{@fromVar} <= #{@toVar} ?"
-      body   = "var #{i} = #{@fromVar}; #{clause} #{i} <#{@equals} #{@toVar} : #{i} >#{@equals} #{@toVar}; #{clause} #{i} += 1 : #{i} -= 1"
+      body   = "var #{vars}; #{clause} #{i} <#{@equals} #{@toVar} : #{i} >#{@equals} #{@toVar}; #{clause} #{i} += 1 : #{i} -= 1"
     post   = "{ #{result}.push(#{i}); }\n#{idt}return #{result};\n#{o.indent}"
     "(function() {#{pre}\n#{idt}for (#{body})#{post}}).call(this)"
 

      unless @object
        lvar      = scope.freeVariable 'len'
        stepPart  = if @step then "#{ivar} += #{ @step.compile(o) }" else "#{ivar}++"
        forPart   = "#{ivar} = 0, #{lvar} = #{svar}.length; #{ivar} < #{lvar}; #{stepPart}"
    sourcePart    = (if rvar then "#{rvar} = []; " else '') + sourcePart
    sourcePart    = if sourcePart then "#{@tab}#{sourcePart}\n#{@tab}" else @tab
    returnResult  = @compileReturnValue(rvar, o)
    body          = Push.wrap(rvar, body) unless topLevel
    if @guard

    else
      varPart     = "#{idt1}#{namePart};\n" if namePart
    if @object
      forPart     = "#{ivar} in #{sourcePart}"
      guardPart   = "\n#{idt1}if (!#{utility('hasProp')}.call(#{svar}, #{ivar})) continue;" unless @raw
    body          = body.compile merge o, indent: idt1, top: true
    vars          = if range then name else "#{name}, #{ivar}"
    """
    #{resultPart}#{@tab}for (#{forPart}) {#{guardPart}
    #{varPart}#{body}
    #{@tab}}#{returnResult}
    """
