leafo/moonscript — Issue #32: Assignment as last expression in function doesn't return
Author: ckknight
Created: 2012-02-19 08:31:30+00:00
State: open

Use case:

cache = {}
func = (key) ->
value = cache[key]
if value ~= nil
value
else
cache[key] = value + 1

Expected compilation:

local cache = { }
local func
func = function(key)
local value = cache[key]
if value ~= nil then
return value
else
local _result = value + 1
cache[key] = _result
return _result
end
end

Current compilation:

local cache = { }
local func
func = function(key)
local value = cache[key]
if value ~= nil then
return value
else
cache[key] = value + 1
end
end