Skip to content

Commit d1142d2

Browse files
committed
Fix math method bugs and make more robust, be sure append() clears stash
1 parent ef26c1e commit d1142d2

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

fluent/resource.lua

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ local FluentNode = class({
4949

5050
attach = function (self, node)
5151
if node and
52-
type(node.__mul) == "function"
52+
type(node.__mul) == "function"
5353
then
54-
return self * node
54+
return node * self
5555
else
5656
return false
5757
end
@@ -162,10 +162,16 @@ node_types.Comment = class({
162162
end,
163163
__add = function (self, node)
164164
self.content = (self.content or "") .. "\n" .. (node.content or "")
165+
return self
165166
end,
166167
__mul = function (self, node)
167-
self.comment = node
168-
return self
168+
if self:is_a(node_types.Message) then
169+
self.comment = node
170+
return self
171+
elseif node:is_a(node_types.Message) then
172+
node.comment = self
173+
return node
174+
end
169175
end
170176
})
171177

@@ -235,8 +241,8 @@ local FluentResource = class({
235241
local flush = function ()
236242
if _stash then
237243
self:insert(_stash)
244+
_stash = nil
238245
end
239-
_stash = nil
240246
return #self.body
241247
end
242248
local stash = function (node)
@@ -249,17 +255,15 @@ local FluentResource = class({
249255
end
250256
for _, ast in ipairs(ast) do
251257
local node = node_to_class(ast)
252-
if node.appendable then
253-
stash(node)
254-
elseif node:is_a(node_types.blank_block) then
258+
if node:is_a(node_types.blank_block) then
255259
if not node.discardable then
256260
flush()
257261
end
258-
elseif node:attach(_stash) and flush() then
259-
self:insert(node)
262+
elseif node:attach(_stash) then
263+
_stash = nil
264+
stash(node)
260265
else
261-
flush()
262-
self:insert(node)
266+
stash(node)
263267
end
264268
end
265269
flush()

0 commit comments

Comments
 (0)