mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
put exported declared names so they can be assigned in deeper scopes
This commit is contained in:
parent
d772547d59
commit
cad4aea610
@ -370,7 +370,12 @@ do
|
||||
elseif "string" == _exp_0 then
|
||||
real_name = name
|
||||
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
|
||||
break
|
||||
end
|
||||
@ -385,16 +390,19 @@ do
|
||||
end
|
||||
return _accum_0
|
||||
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
|
||||
end,
|
||||
whitelist_names = function(self, names)
|
||||
self._name_whitelist = Set(names)
|
||||
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, ...)
|
||||
local value = ...
|
||||
if select("#", ...) == 0 then
|
||||
@ -406,13 +414,8 @@ do
|
||||
self._names[name] = value
|
||||
end,
|
||||
has_name = function(self, name, skip_exports)
|
||||
if not skip_exports then
|
||||
if self.export_all then
|
||||
return true
|
||||
end
|
||||
if self.export_proper and name:match("^%u") then
|
||||
return true
|
||||
end
|
||||
if not skip_exports and self:name_exported(name) then
|
||||
return true
|
||||
end
|
||||
local yes = self._names[name]
|
||||
if yes == nil and self.parent then
|
||||
|
@ -216,15 +216,21 @@ class Block
|
||||
when NameProxy then name\get_name self
|
||||
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
|
||||
|
||||
@put_name name for name in *undeclared
|
||||
undeclared
|
||||
|
||||
whitelist_names: (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, ...) =>
|
||||
value = ...
|
||||
value = true if select("#", ...) == 0
|
||||
@ -233,9 +239,7 @@ class Block
|
||||
@_names[name] = value
|
||||
|
||||
has_name: (name, skip_exports) =>
|
||||
if not skip_exports
|
||||
return true if @export_all
|
||||
return true if @export_proper and name\match"^%u"
|
||||
return true if not skip_exports and @name_exported name
|
||||
|
||||
yes = @_names[name]
|
||||
if yes == nil and @parent
|
||||
|
@ -195,6 +195,7 @@ Statement = Transformer {
|
||||
if destructure.has_destructure names
|
||||
return destructure.split_assign node
|
||||
|
||||
-- print util.dump node
|
||||
node
|
||||
|
||||
continue: (node) =>
|
||||
|
@ -48,3 +48,30 @@ do
|
||||
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
|
||||
|
||||
|
@ -67,9 +67,9 @@ do
|
||||
end
|
||||
do
|
||||
if this then
|
||||
local What = 232
|
||||
What = 232
|
||||
else
|
||||
local What = 4343
|
||||
What = 4343
|
||||
end
|
||||
x, y, z = 1, 2, 3
|
||||
y = function()
|
||||
@ -78,6 +78,30 @@ do
|
||||
do
|
||||
local _with_0 = tmp
|
||||
local j = 2000
|
||||
return _with_0
|
||||
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
|
Loading…
Reference in New Issue
Block a user