put exported declared names so they can be assigned in deeper scopes

This commit is contained in:
leaf corcoran 2013-01-13 12:11:47 -08:00
parent d772547d59
commit cad4aea610
5 changed files with 80 additions and 21 deletions

View File

@ -370,7 +370,12 @@ do
elseif "string" == _exp_0 then elseif "string" == _exp_0 then
real_name = name real_name = name
end end
if not (is_local or real_name and not self:has_name(real_name)) then if not (is_local or real_name and not self:has_name(real_name, true)) then
_continue_0 = true
break
end
self:put_name(real_name)
if self:name_exported(real_name) then
_continue_0 = true _continue_0 = true
break break
end end
@ -385,16 +390,19 @@ do
end end
return _accum_0 return _accum_0
end)() end)()
local _list_0 = undeclared
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
self:put_name(name)
end
return undeclared return undeclared
end, end,
whitelist_names = function(self, names) whitelist_names = function(self, names)
self._name_whitelist = Set(names) self._name_whitelist = Set(names)
end, end,
name_exported = function(self, name)
if self.export_all then
return true
end
if self.export_proper and name:match("^%u") then
return true
end
end,
put_name = function(self, name, ...) put_name = function(self, name, ...)
local value = ... local value = ...
if select("#", ...) == 0 then if select("#", ...) == 0 then
@ -406,13 +414,8 @@ do
self._names[name] = value self._names[name] = value
end, end,
has_name = function(self, name, skip_exports) has_name = function(self, name, skip_exports)
if not skip_exports then if not skip_exports and self:name_exported(name) then
if self.export_all then return true
return true
end
if self.export_proper and name:match("^%u") then
return true
end
end end
local yes = self._names[name] local yes = self._names[name]
if yes == nil and self.parent then if yes == nil and self.parent then

View File

@ -216,15 +216,21 @@ class Block
when NameProxy then name\get_name self when NameProxy then name\get_name self
when "string" then name when "string" then name
continue unless is_local or real_name and not @has_name real_name continue unless is_local or real_name and not @has_name real_name, true
-- put exported names so they can be assigned to in deeper scope
@put_name real_name
continue if @name_exported real_name
real_name real_name
@put_name name for name in *undeclared
undeclared undeclared
whitelist_names: (names) => whitelist_names: (names) =>
@_name_whitelist = Set names @_name_whitelist = Set names
name_exported: (name) =>
return true if @export_all
return true if @export_proper and name\match"^%u"
put_name: (name, ...) => put_name: (name, ...) =>
value = ... value = ...
value = true if select("#", ...) == 0 value = true if select("#", ...) == 0
@ -233,9 +239,7 @@ class Block
@_names[name] = value @_names[name] = value
has_name: (name, skip_exports) => has_name: (name, skip_exports) =>
if not skip_exports return true if not skip_exports and @name_exported name
return true if @export_all
return true if @export_proper and name\match"^%u"
yes = @_names[name] yes = @_names[name]
if yes == nil and @parent if yes == nil and @parent

View File

@ -195,6 +195,7 @@ Statement = Transformer {
if destructure.has_destructure names if destructure.has_destructure names
return destructure.split_assign node return destructure.split_assign node
-- print util.dump node
node node
continue: (node) => continue: (node) =>

View File

@ -48,3 +48,30 @@ do
j = 2000 j = 2000
do
export *
x = 3434
if y then
x = 10
do
export *
if y then
x = 10
x = 3434
do
do
export *
k = 1212
do
h = 100
y = ->
h = 100
k = 100
h = 100

View File

@ -67,9 +67,9 @@ do
end end
do do
if this then if this then
local What = 232 What = 232
else else
local What = 4343 What = 4343
end end
x, y, z = 1, 2, 3 x, y, z = 1, 2, 3
y = function() y = function()
@ -78,6 +78,30 @@ do
do do
local _with_0 = tmp local _with_0 = tmp
local j = 2000 local j = 2000
return _with_0
end end
end
do
x = 3434
if y then
x = 10
end
end
do
if y then
local x = 10
end
x = 3434
end
do
do
k = 1212
do
local h = 100
end
y = function()
local h = 100
k = 100
end
end
local h = 100
end end