mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
escape dot chains that are lua keywords
This commit is contained in:
parent
b7bf9b73d0
commit
867989b4f7
@ -1271,6 +1271,19 @@ Value = Transformer({
|
|||||||
end,
|
end,
|
||||||
chain = function(self, node)
|
chain = function(self, node)
|
||||||
local stub = node[#node]
|
local stub = node[#node]
|
||||||
|
for i = 3, #node do
|
||||||
|
local part = node[i]
|
||||||
|
if ntype(part) == "dot" and data.lua_keywords[part[2]] then
|
||||||
|
node[i] = {
|
||||||
|
"index",
|
||||||
|
{
|
||||||
|
"string",
|
||||||
|
'"',
|
||||||
|
part[2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
if ntype(node[2]) == "string" then
|
if ntype(node[2]) == "string" then
|
||||||
node[2] = {
|
node[2] = {
|
||||||
"parens",
|
"parens",
|
||||||
|
@ -680,6 +680,12 @@ Value = Transformer {
|
|||||||
chain: (node) =>
|
chain: (node) =>
|
||||||
stub = node[#node]
|
stub = node[#node]
|
||||||
|
|
||||||
|
-- escape lua keywords used in dot accessors
|
||||||
|
for i=3,#node
|
||||||
|
part = node[i]
|
||||||
|
if ntype(part) == "dot" and data.lua_keywords[part[2]]
|
||||||
|
node[i] = { "index", {"string", '"', part[2]} }
|
||||||
|
|
||||||
if ntype(node[2]) == "string"
|
if ntype(node[2]) == "string"
|
||||||
-- add parens if callee is raw string
|
-- add parens if callee is raw string
|
||||||
node[2] = {"parens", node[2] }
|
node[2] = {"parens", node[2] }
|
||||||
|
@ -227,4 +227,9 @@ a *= 3 + 5
|
|||||||
a *= 3
|
a *= 3
|
||||||
a /= func "cool"
|
a /= func "cool"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
x.then = "hello"
|
||||||
|
x.while.true = "hello"
|
||||||
|
|
||||||
-- cooool
|
-- cooool
|
||||||
|
@ -227,3 +227,5 @@ a = a + (3 - 5)
|
|||||||
a = a * (3 + 5)
|
a = a * (3 + 5)
|
||||||
a = a * 3
|
a = a * 3
|
||||||
a = a / func("cool")
|
a = a / func("cool")
|
||||||
|
x["then"] = "hello"
|
||||||
|
x["while"]["true"] = "hello"
|
Loading…
Reference in New Issue
Block a user