From 5d76a8d741ee8ac7c7bd47704a43e79257fce186 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sat, 1 Oct 2011 22:33:28 -0700 Subject: [PATCH] fixed bug with class value declaring --- moonscript/compile/line.lua | 32 +++++++++++++------------------- moonscript/compile/line.moon | 7 ++----- moonscript/transform.lua | 6 +++++- moonscript/transform.moon | 2 +- moonscript/types.lua | 6 ++++++ moonscript/types.moon | 3 +++ tests/outputs/class.lua | 1 - 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/moonscript/compile/line.lua b/moonscript/compile/line.lua index 7e2a2b0..2d71558 100644 --- a/moonscript/compile/line.lua +++ b/moonscript/compile/line.lua @@ -70,12 +70,8 @@ line_compile = { end do local _with_0 = self:line() - local skip_values = false if #undeclared == #names and not has_fndef then _with_0:append(declare) - if #values == 0 then - skip_values = true - end else if #undeclared > 0 then self:add(declare) @@ -94,22 +90,20 @@ line_compile = { return _accum_0 end)(), ", ") end - if not skip_values then - _with_0:append(" = ") - _with_0:append_list((function() - local _accum_0 = { } - local _len_0 = 0 - do - local _item_0 = values - for _index_0 = 1, #_item_0 do - local v = _item_0[_index_0] - _len_0 = _len_0 + 1 - _accum_0[_len_0] = self:value(v) - end + _with_0:append(" = ") + _with_0:append_list((function() + local _accum_0 = { } + local _len_0 = 0 + do + local _item_0 = values + for _index_0 = 1, #_item_0 do + local v = _item_0[_index_0] + _len_0 = _len_0 + 1 + _accum_0[_len_0] = self:value(v) end - return _accum_0 - end)(), ", ") - end + end + return _accum_0 + end)(), ", ") return _with_0 end end diff --git a/moonscript/compile/line.moon b/moonscript/compile/line.moon index bf04553..b04e71b 100644 --- a/moonscript/compile/line.moon +++ b/moonscript/compile/line.moon @@ -48,17 +48,14 @@ line_compile = i = i +1 with @line! - skip_values = false if #undeclared == #names and not has_fndef \append declare - skip_values = true if #values == 0 else @add declare if #undeclared > 0 \append_list [@value name for name in *names], ", " - if not skip_values - \append " = " - \append_list [@value v for v in *values], ", " + \append " = " + \append_list [@value v for v in *values], ", " update: (node) => _, name, op, exp = unpack node diff --git a/moonscript/transform.lua b/moonscript/transform.lua index 86b23d2..e5d53ea 100644 --- a/moonscript/transform.lua +++ b/moonscript/transform.lua @@ -298,7 +298,11 @@ local transformers = { cls_name }) value = _with_0.group({ - _with_0.assign_one(name), + _with_0.declare({ + names = { + name + } + }), _with_0.assign({ names = { name diff --git a/moonscript/transform.moon b/moonscript/transform.moon index 9c2cbe1..c210285 100644 --- a/moonscript/transform.moon +++ b/moonscript/transform.moon @@ -148,7 +148,7 @@ transformers = { } value = .group { - .assign_one name + .declare names: {name} .assign { names: {name} values: {value} diff --git a/moonscript/types.lua b/moonscript/types.lua index dad191c..1f96b46 100644 --- a/moonscript/types.lua +++ b/moonscript/types.lua @@ -39,6 +39,12 @@ local node_types = { t } }, + declare = { + { + "names", + t + } + }, ["if"] = { { "cond", diff --git a/moonscript/types.moon b/moonscript/types.moon index 495d7e9..4e546f1 100644 --- a/moonscript/types.moon +++ b/moonscript/types.moon @@ -26,6 +26,9 @@ node_types = { {"names", t} {"values", t} } + declare: { + {"names", t} + } if: { {"cond", t} {"then", t} diff --git a/tests/outputs/class.lua b/tests/outputs/class.lua index 0d7eeae..eb536f7 100644 --- a/tests/outputs/class.lua +++ b/tests/outputs/class.lua @@ -113,7 +113,6 @@ Hi = (function() _base_0.__class = _class_0 return _class_0 end)() -Simple = Simple = (function() local _parent_0 = Hi local _base_0 = {