Skip to content

Commit 24b3a86

Browse files
committed
correct escape new chain format for lua keywords
1 parent c4ad47c commit 24b3a86

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

moonscript/compile/value.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ return {
7272
local callee = node[2]
7373
local callee_type = ntype(callee)
7474
local item_offset = 3
75-
if callee_type == "dot" or callee_type == "colon" then
75+
if callee_type == "dot" or callee_type == "colon" or callee_type == "index" then
7676
callee = self:get("scope_var")
7777
if not (callee) then
7878
user_error("Short-dot syntax must be called within a with block")

moonscript/compile/value.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ string_chars = {
4646
callee_type = ntype callee
4747
item_offset = 3
4848

49-
if callee_type == "dot" or callee_type == "colon"
49+
if callee_type == "dot" or callee_type == "colon" or callee_type == "index"
5050
callee = @get "scope_var"
5151
unless callee
5252
user_error "Short-dot syntax must be called within a with block"

moonscript/transform.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ Value = Transformer({
14921492
})
14931493
end,
14941494
chain = function(self, node)
1495-
for i = 3, #node do
1495+
for i = 2, #node do
14961496
local part = node[i]
14971497
if ntype(part) == "dot" and data.lua_keywords[part[2]] then
14981498
node[i] = {

moonscript/transform.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ Value = Transformer {
923923
-- pull out colon chain
924924
chain: (node) =>
925925
-- escape lua keywords used in dot accessors
926-
for i=3,#node
926+
for i=2,#node
927927
part = node[i]
928928
if ntype(part) == "dot" and data.lua_keywords[part[2]]
929929
node[i] = { "index", {"string", '"', part[2]} }

spec/inputs/with.moon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@ do
111111
with hi
112112
return .a, .b
113113

114+
115+
do
116+
with dad
117+
.if "yes"
118+
y = .end.of.function

spec/outputs/with.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,19 @@ do
154154
end
155155
end
156156
do
157-
return function()
157+
local _
158+
_ = function()
158159
do
159160
local _with_0 = hi
160161
return _with_0.a, _with_0.b
161162
end
162163
end
164+
end
165+
do
166+
do
167+
local _with_0 = dad
168+
_with_0["if"]("yes")
169+
local y = _with_0["end"].of["function"]
170+
return _with_0
171+
end
163172
end

0 commit comments

Comments
 (0)