diff --git a/moonscript/compile.lua b/moonscript/compile.lua index ccb2e93..aaa42c2 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -415,8 +415,14 @@ do }) return name end, - add = function(self, item) - self._lines:add(item) + add = function(self, item, pos) + do + local _with_0 = self._lines + _with_0:add(item) + if pos then + _with_0:mark_pos(pos) + end + end return item end, render = function(self, buffer) diff --git a/moonscript/compile.moon b/moonscript/compile.moon index ac6c463..af700e1 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -288,9 +288,11 @@ class Block @stm {"assign", {name}, {value}} name - -- add a line object - add: (item) => - @_lines\add item + -- add something to the line buffer + add: (item, pos) => + with @_lines + \add item + \mark_pos pos if pos item -- todo: pass in buffer as argument diff --git a/moonscript/compile/statement.lua b/moonscript/compile/statement.lua index 7b6ccb0..2d2a80c 100644 --- a/moonscript/compile/statement.lua +++ b/moonscript/compile/statement.lua @@ -78,7 +78,7 @@ return { _with_0:append(declare) else if #undeclared > 0 then - self:add(declare) + self:add(declare, node[-1]) end _with_0:append_list((function() local _accum_0 = { } diff --git a/moonscript/compile/statement.moon b/moonscript/compile/statement.moon index 9d0f43a..e5c5740 100644 --- a/moonscript/compile/statement.moon +++ b/moonscript/compile/statement.moon @@ -43,7 +43,7 @@ import concat, insert from table if #undeclared == #names and not has_fndef \append declare else - @add declare if #undeclared > 0 + @add declare, node[-1] if #undeclared > 0 \append_list [@value name for name in *names], ", " \append " = "