Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some comments came up in Zapu's work, and a few additional tests
  • Loading branch information
maxtaco committed Oct 9, 2015
1 parent bf16ec1 commit 0b7345f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
67 changes: 53 additions & 14 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/nodes.coffee
Expand Up @@ -3023,10 +3023,10 @@ exports.For = class For extends While
# - Issue #99 as fixed by @davidbond

# Create variables
begin = new Value new Literal "_begin"
end = new Value new Literal "_end"
positive = new Value new Literal "_positive"
stepVal = new Value new Literal "_step"
begin = new Value new Literal o.scope.freeVariable "begin"
end = new Value new Literal o.scope.freeVariable "end"
positive = new Value new Literal o.scope.freeVariable "positive"
stepVal = new Value new Literal o.scope.freeVariable "step"

# Calculate stepping
if @step
Expand Down
19 changes: 16 additions & 3 deletions test/iced.coffee
Expand Up @@ -731,7 +731,7 @@ atest 'loops with defers (Issue #89 via @davidbau)', (cb) ->
await delay defer()
arr.push x
arrayEq arr, ['c', 'b', 'a']

arr = []
step = -2
for x in ['a', 'b', 'c'] by step
Expand All @@ -741,6 +741,19 @@ atest 'loops with defers (Issue #89 via @davidbau)', (cb) ->

cb true, {}

atest "nested loops with negative steps", (cb) ->
v1 = []
for i in [10...0] by -1
for j in [10...i] by -1
await delay defer()
v1.push (i*1000)+j
v2 = []
for i in [10...0] by -1
for j in [10...i] by -1
v2.push (i*1000)+j
arrayEq v1, v2
cb true, {}

atest 'loop with function as step', (cb) ->
makeFunc = ->
calld = false
Expand All @@ -757,7 +770,7 @@ atest 'loop with function as step', (cb) ->
func = makeFunc()
arr = []
for x in [1,2,3] by func()
arr.push x
arr.push x

arrayEq [1,2,3], arr

Expand All @@ -783,7 +796,7 @@ atest 'loop with function as step', (cb) ->
arr.push x

arrayEq [1,2,3], arr

cb true, {}

# helper to assert that a string should fail compilation
Expand Down

0 comments on commit 0b7345f

Please sign in to comment.