mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
parent
9e48a3b6b8
commit
d85973411f
@ -101,7 +101,18 @@ do
|
|||||||
_base_0.__class = _class_0
|
_base_0.__class = _class_0
|
||||||
NameProxy = _class_0
|
NameProxy = _class_0
|
||||||
end
|
end
|
||||||
|
local is_name_proxy
|
||||||
|
is_name_proxy = function(v)
|
||||||
|
if not (type(v) == "table") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local _exp_0 = v.__class
|
||||||
|
if LocalName == _exp_0 or NameProxy == _exp_0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
return {
|
return {
|
||||||
NameProxy = NameProxy,
|
NameProxy = NameProxy,
|
||||||
LocalName = LocalName
|
LocalName = LocalName,
|
||||||
|
is_name_proxy = is_name_proxy
|
||||||
}
|
}
|
||||||
|
@ -41,5 +41,11 @@ class NameProxy
|
|||||||
else
|
else
|
||||||
("name<prefix(%s)>")\format @prefix
|
("name<prefix(%s)>")\format @prefix
|
||||||
|
|
||||||
|
is_name_proxy = (v) ->
|
||||||
|
return false unless type(v) == "table"
|
||||||
|
|
||||||
{ :NameProxy, :LocalName }
|
switch v.__class
|
||||||
|
when LocalName, NameProxy
|
||||||
|
true
|
||||||
|
|
||||||
|
{ :NameProxy, :LocalName, :is_name_proxy }
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
local Transformer
|
local Transformer
|
||||||
Transformer = require("moonscript.transform.transformer").Transformer
|
Transformer = require("moonscript.transform.transformer").Transformer
|
||||||
local NameProxy
|
local NameProxy, LocalName, is_name_proxy
|
||||||
NameProxy = require("moonscript.transform.names").NameProxy
|
do
|
||||||
|
local _obj_0 = require("moonscript.transform.names")
|
||||||
|
NameProxy, LocalName, is_name_proxy = _obj_0.NameProxy, _obj_0.LocalName, _obj_0.is_name_proxy
|
||||||
|
end
|
||||||
local Run, transform_last_stm, implicitly_return, last_stm
|
local Run, transform_last_stm, implicitly_return, last_stm
|
||||||
do
|
do
|
||||||
local _obj_0 = require("moonscript.transform.statements")
|
local _obj_0 = require("moonscript.transform.statements")
|
||||||
@ -649,6 +652,18 @@ return Transformer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
local names
|
||||||
|
do
|
||||||
|
local _accum_0 = { }
|
||||||
|
local _len_0 = 1
|
||||||
|
local _list_0 = node.names
|
||||||
|
for _index_0 = 1, #_list_0 do
|
||||||
|
local n = _list_0[_index_0]
|
||||||
|
_accum_0[_len_0] = is_name_proxy(n) and n or LocalName(n) or n
|
||||||
|
_len_0 = _len_0 + 1
|
||||||
|
end
|
||||||
|
names = _accum_0
|
||||||
|
end
|
||||||
return build.group({
|
return build.group({
|
||||||
list_name ~= list and build.assign_one(list_name, list) or NOOP,
|
list_name ~= list and build.assign_one(list_name, list) or NOOP,
|
||||||
slice_var or NOOP,
|
slice_var or NOOP,
|
||||||
@ -658,7 +673,7 @@ return Transformer({
|
|||||||
body = {
|
body = {
|
||||||
{
|
{
|
||||||
"assign",
|
"assign",
|
||||||
node.names,
|
names,
|
||||||
{
|
{
|
||||||
NameProxy.index(list_name, index_name)
|
NameProxy.index(list_name, index_name)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Transformer from require "moonscript.transform.transformer"
|
import Transformer from require "moonscript.transform.transformer"
|
||||||
|
|
||||||
import NameProxy from require "moonscript.transform.names"
|
import NameProxy, LocalName, is_name_proxy from require "moonscript.transform.names"
|
||||||
|
|
||||||
import Run, transform_last_stm, implicitly_return, last_stm
|
import Run, transform_last_stm, implicitly_return, last_stm
|
||||||
from require "moonscript.transform.statements"
|
from require "moonscript.transform.statements"
|
||||||
@ -400,6 +400,8 @@ Transformer {
|
|||||||
else
|
else
|
||||||
{1, {"length", list_name}}
|
{1, {"length", list_name}}
|
||||||
|
|
||||||
|
names = [is_name_proxy(n) and n or LocalName(n) or n for n in *node.names]
|
||||||
|
|
||||||
return build.group {
|
return build.group {
|
||||||
list_name != list and build.assign_one(list_name, list) or NOOP
|
list_name != list and build.assign_one(list_name, list) or NOOP
|
||||||
slice_var or NOOP
|
slice_var or NOOP
|
||||||
@ -407,7 +409,7 @@ Transformer {
|
|||||||
name: index_name
|
name: index_name
|
||||||
bounds: bounds
|
bounds: bounds
|
||||||
body: {
|
body: {
|
||||||
{"assign", node.names, { NameProxy.index list_name, index_name }}
|
{"assign", names, { NameProxy.index list_name, index_name }}
|
||||||
build.group node.body
|
build.group node.body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user