diff --git a/moonscript/transform.lua b/moonscript/transform.lua index 4cdf597..6d6eac4 100644 --- a/moonscript/transform.lua +++ b/moonscript/transform.lua @@ -378,8 +378,7 @@ Statement = Transformer({ }) end node = self.transform.statement(first_value, action, node) - local wrapped = a:wrap(node) - return build.assign_one(first_name, wrapped) + return build.assign_one(first_name, a:wrap(node)) end end local transformed @@ -689,7 +688,7 @@ Statement = Transformer({ end)() }) end, - foreach = function(self, node, _, parent_assign) + foreach = function(self, node, _) smart_node(node) local source = unpack(node.iter) local destructures = { } @@ -717,11 +716,7 @@ Statement = Transformer({ if ntype(source) == "unpack" then local list = source[2] local index_name = NameProxy("index") - local assign_name - if parent_assign then - assign_name = parent_assign[2][1] - end - local list_name = assign_name ~= list and self:is_local(list) and list or NameProxy("list") + local list_name = self:is_local(list) and list or NameProxy("list") local slice_var = nil local bounds if is_slice(list) then diff --git a/moonscript/transform.moon b/moonscript/transform.moon index 8a44801..2f87161 100644 --- a/moonscript/transform.moon +++ b/moonscript/transform.moon @@ -194,9 +194,7 @@ Statement = Transformer { a = Accumulator! action = (exp) -> a\mutate_body { exp } node = @transform.statement first_value, action, node - - wrapped = a\wrap node - return build.assign_one first_name, wrapped + return build.assign_one first_name, a\wrap node -- bubble cascading assigns transformed = if num_values == 1 @@ -384,7 +382,7 @@ Statement = Transformer { ret scope_name } - foreach: (node, _, parent_assign) => + foreach: (node, _) => smart_node node source = unpack node.iter @@ -404,8 +402,7 @@ Statement = Transformer { list = source[2] index_name = NameProxy "index" - assign_name = parent_assign[2][1] if parent_assign - list_name = assign_name != list and @is_local(list) and list or NameProxy "list" + list_name = @is_local(list) and list or NameProxy "list" slice_var = nil bounds = if is_slice list diff --git a/moonscript/types.moon b/moonscript/types.moon index e603f60..aee741a 100644 --- a/moonscript/types.moon +++ b/moonscript/types.moon @@ -122,8 +122,10 @@ build = nil build = setmetatable { group: (body={}) -> {"group", body} + do: (body) -> {"do", body} + assign_one: (name, value) -> build.assign { names: {name}