@@ -127,6 +127,35 @@ hoist_declarations = function(body)
127127 assigns
128128 })
129129end
130+ local extract_declarations
131+ extract_declarations = function (self , body , start , out )
132+ if body == nil then
133+ body = self .current_stms
134+ end
135+ if start == nil then
136+ start = self .current_stm_i + 1
137+ end
138+ if out == nil then
139+ out = { }
140+ end
141+ for i = start , # body do
142+ local stm = self .transform .statement (body [i ])
143+ body [i ] = stm
144+ local _exp_0 = stm [1 ]
145+ if " assign" == _exp_0 or " declare" == _exp_0 then
146+ local _list_0 = stm [2 ]
147+ for _index_0 = 1 , # _list_0 do
148+ local name = _list_0 [_index_0 ]
149+ if type (name ) == " string" then
150+ insert (out , name )
151+ end
152+ end
153+ elseif " group" == _exp_0 then
154+ extract_declarations (self , stm [2 ], 1 , out )
155+ end
156+ end
157+ return out
158+ end
130159local expand_elseif_assign
131160expand_elseif_assign = function (ifstm )
132161 for i = 4 , # ifstm do
@@ -342,20 +371,40 @@ local Statement = Transformer({
342371 root_stms = function (self , body )
343372 return apply_to_last (body , implicitly_return (self ))
344373 end ,
345- assign = function (self , node )
346- local names , values = unpack (node , 2 )
347- do
348- local globber = self :get_current (" name_glob" )
349- if globber then
374+ declare_glob = function (self , node )
375+ local names = extract_declarations (self )
376+ if node [2 ] == " ^" then
377+ names = (function ()
378+ local _accum_0 = { }
379+ local _len_0 = 1
350380 local _list_0 = names
351381 for _index_0 = 1 , # _list_0 do
352- local name = _list_0 [_index_0 ]
353- if globber (name ) then
354- self :put_name (name )
382+ local _continue_0 = false
383+ repeat
384+ local name = _list_0 [_index_0 ]
385+ if not (name :match (" ^%u" )) then
386+ _continue_0 = true
387+ break
388+ end
389+ local _value_0 = name
390+ _accum_0 [_len_0 ] = _value_0
391+ _len_0 = _len_0 + 1
392+ _continue_0 = true
393+ until true
394+ if not _continue_0 then
395+ break
355396 end
356397 end
357- end
398+ return _accum_0
399+ end )()
358400 end
401+ return {
402+ " declare" ,
403+ names
404+ }
405+ end ,
406+ assign = function (self , node )
407+ local names , values = unpack (node , 2 )
359408 local transformed
360409 if # values == 1 then
361410 local value = values [1 ]
0 commit comments