simplify single name destructures/imports

This commit is contained in:
leaf corcoran 2014-09-02 20:31:08 -07:00
parent 30116b21e1
commit da6c76b7e4
5 changed files with 23 additions and 40 deletions

View File

@ -124,7 +124,7 @@ build_assign = function(scope, destruct_literal, receiver)
values
}
local obj
if scope:is_local(receiver) then
if scope:is_local(receiver) or #extracted_names == 1 then
obj = receiver
else
do
@ -143,7 +143,13 @@ build_assign = function(scope, destruct_literal, receiver)
for _index_0 = 1, #extracted_names do
local tuple = extracted_names[_index_0]
insert(names, tuple[1])
insert(values, NameProxy.chain(obj, unpack(tuple[2])))
local chain
if obj then
chain = NameProxy.chain(obj, unpack(tuple[2]))
else
chain = "nil"
end
insert(values, chain)
end
return build.group({
{

View File

@ -59,7 +59,7 @@ build_assign = (scope, destruct_literal, receiver) ->
inner = {"assign", names, values}
obj = if scope\is_local receiver
obj = if scope\is_local(receiver) or #extracted_names == 1
receiver
else
with obj = NameProxy "obj"
@ -70,7 +70,11 @@ build_assign = (scope, destruct_literal, receiver) ->
for tuple in *extracted_names
insert names, tuple[1]
insert values, NameProxy.chain obj, unpack tuple[2]
chain = if obj
NameProxy.chain obj, unpack tuple[2]
else
"nil"
insert values, chain
build.group {
{"declare", names}

View File

@ -687,10 +687,7 @@ do
_base_0.__class = _class_0
local self = _class_0
val = 23
do
local _obj_0 = table
insert = _obj_0.insert
end
insert = table.insert
Something = _class_0
end
do

View File

@ -26,27 +26,15 @@ do
local _obj_0 = yeah
a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d
end
do
local _obj_0 = one
a = _obj_0[1]
end
a = one[1]
local _ = two
do
local _obj_0 = one
b = _obj_0[1]
end
b = one[1]
c = nil
do
local _obj_0 = one
d = _obj_0[1]
end
d = one[1]
local e = two
local x = one
local y
do
local _obj_0 = two
y = _obj_0[1]
end
y = two[1]
local xx, yy = 1, 2
do
local _obj_0 = {
@ -77,18 +65,12 @@ do
name, street, city = futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2]
end
do
do
local _obj_0 = x
self.world = _obj_0[1]
end
self.world = x[1]
do
local _obj_0 = x
a.b, c.y, func().z = _obj_0[1], _obj_0[2], _obj_0[3]
end
do
local _obj_0 = x
self.world = _obj_0.world
end
self.world = x.world
end
do
local thing = {

View File

@ -1,8 +1,5 @@
local hello
do
local _obj_0 = yeah
hello = _obj_0.hello
end
hello = yeah.hello
local world
do
local _obj_0 = table["cool"]
@ -34,10 +31,7 @@ local yumm
a, yumm = 3434, "hello"
local _table_0 = 232
local something
do
local _obj_0 = a(table)
something = _obj_0.something
end
something = a(table).something
if indent then
local okay, well
do