1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

adding body-less while expressions

This commit is contained in:
Jeremy Ashkenas 2010-01-09 11:51:32 -05:00
parent 4c3f00cf77
commit ae58e2ec6c
3 changed files with 5 additions and 3 deletions

View file

@ -14,9 +14,9 @@
# end # end
LotteryTicket: { LotteryTicket: {
get_picks: => this.picks get_picks: => this.picks
set_picks: nums => this.picks: nums set_picks: nums => this.picks: nums
get_purchase: => this.purchase get_purchase: => this.purchase
set_purchase: amount => this.purchase: amount set_purchase: amount => this.purchase: amount
} }

View file

@ -340,6 +340,7 @@ rule
# The while loop. (there is no do..while). # The while loop. (there is no do..while).
While: While:
WHILE Expression Block { result = WhileNode.new(val[1], val[2]) } WHILE Expression Block { result = WhileNode.new(val[1], val[2]) }
| WHILE Expression { result = WhileNode.new(val[1], nil) }
; ;
# Array comprehensions, including guard and current index. # Array comprehensions, including guard and current index.

View file

@ -609,6 +609,7 @@ module CoffeeScript
o[:top] = true o[:top] = true
cond = @condition.compile(o) cond = @condition.compile(o)
post = returns ? "\n#{idt}return null;" : '' post = returns ? "\n#{idt}return null;" : ''
return write("#{idt}while (#{cond});#{post}") if @body.nil?
write("#{idt}while (#{cond}) {\n#{@body.compile(o)}\n#{idt}}#{post}") write("#{idt}while (#{cond}) {\n#{@body.compile(o)}\n#{idt}}#{post}")
end end
end end