mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
class inner expressions run in class scope
This commit is contained in:
parent
255a92f8ee
commit
e55fa25e6e
@ -5,7 +5,7 @@ require("moonscript.compile.format")
|
||||
require("moonscript.compile.statement")
|
||||
require("moonscript.compile.value")
|
||||
local transform = require("moonscript.transform")
|
||||
local NameProxy = transform.NameProxy
|
||||
local NameProxy, LocalName = transform.NameProxy, transform.LocalName
|
||||
local Set
|
||||
do
|
||||
local _table_0 = require("moonscript.data")
|
||||
@ -122,15 +122,19 @@ Block = (function()
|
||||
local _list_0 = names
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local name = _list_0[_index_0]
|
||||
local t = util.moon.type(name)
|
||||
local is_local = false
|
||||
local real_name
|
||||
if t == NameProxy then
|
||||
local _exp_0 = util.moon.type(name)
|
||||
if LocalName == _exp_0 then
|
||||
is_local = true
|
||||
real_name = name:get_name(self)
|
||||
elseif t == "string" then
|
||||
elseif NameProxy == _exp_0 then
|
||||
real_name = name:get_name(self)
|
||||
elseif "string" == _exp_0 then
|
||||
real_name = name
|
||||
end
|
||||
local _value_0
|
||||
if real_name and not self:has_name(real_name) then
|
||||
if is_local or real_name and not self:has_name(real_name) then
|
||||
_value_0 = real_name
|
||||
end
|
||||
if _value_0 ~= nil then
|
||||
|
@ -9,7 +9,7 @@ require "moonscript.compile.value"
|
||||
|
||||
transform = require "moonscript.transform"
|
||||
|
||||
import NameProxy from transform
|
||||
import NameProxy, LocalName from transform
|
||||
import Set from require "moonscript.data"
|
||||
import ntype from require "moonscript.types"
|
||||
|
||||
@ -88,12 +88,15 @@ class Block
|
||||
|
||||
declare: (names) =>
|
||||
undeclared = for name in *names
|
||||
t = util.moon.type(name)
|
||||
real_name = if t == NameProxy
|
||||
name\get_name self
|
||||
elseif t == "string"
|
||||
name
|
||||
real_name if real_name and not @has_name real_name
|
||||
is_local = false
|
||||
real_name = switch util.moon.type name
|
||||
when LocalName
|
||||
is_local = true
|
||||
name\get_name self
|
||||
when NameProxy then name\get_name self
|
||||
when "string" then name
|
||||
|
||||
real_name if is_local or real_name and not @has_name real_name
|
||||
|
||||
@put_name name for name in *undeclared
|
||||
undeclared
|
||||
|
@ -5,6 +5,33 @@ local data = require("moonscript.data")
|
||||
local reversed = util.reversed
|
||||
local ntype, build, smart_node, is_slice = types.ntype, types.build, types.smart_node, types.is_slice
|
||||
local insert = table.insert
|
||||
LocalName = (function()
|
||||
local _parent_0 = nil
|
||||
local _base_0 = {
|
||||
get_name = function(self)
|
||||
return self.name
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
if _parent_0 then
|
||||
setmetatable(_base_0, getmetatable(_parent_0).__index)
|
||||
end
|
||||
local _class_0 = setmetatable({
|
||||
__init = function(self, name)
|
||||
self.name = name
|
||||
self[1] = "temp_name"
|
||||
end
|
||||
}, {
|
||||
__index = _base_0,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
end)()
|
||||
NameProxy = (function()
|
||||
local _parent_0 = nil
|
||||
local _base_0 = {
|
||||
@ -771,6 +798,16 @@ Statement = Transformer({
|
||||
}),
|
||||
_with_0.assign_one(cls_name, cls),
|
||||
_with_0.assign_one(base_name:chain("__class"), cls_name),
|
||||
_with_0.group((function()
|
||||
if #statements > 0 then
|
||||
return {
|
||||
_with_0.assign_one(LocalName("self"), cls_name),
|
||||
_with_0.group(statements)
|
||||
}
|
||||
else
|
||||
return { }
|
||||
end
|
||||
end)()),
|
||||
cls_name
|
||||
})
|
||||
value = _with_0.group({
|
||||
|
@ -9,7 +9,12 @@ import reversed from util
|
||||
import ntype, build, smart_node, is_slice from types
|
||||
import insert from table
|
||||
|
||||
export Statement, Value, NameProxy, Run
|
||||
export Statement, Value, NameProxy, LocalName, Run
|
||||
|
||||
-- always declares as local
|
||||
class LocalName
|
||||
new: (@name) => self[1] = "temp_name"
|
||||
get_name: => @name
|
||||
|
||||
class NameProxy
|
||||
new: (@prefix) =>
|
||||
@ -428,6 +433,11 @@ Statement = Transformer {
|
||||
.assign_one cls_name, cls
|
||||
.assign_one base_name\chain"__class", cls_name
|
||||
|
||||
.group if #statements > 0 {
|
||||
.assign_one LocalName"self", cls_name
|
||||
.group statements
|
||||
} else {}
|
||||
|
||||
cls_name
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user