diff --git a/yaml/dom.nim b/yaml/dom.nim index 3b88e9b..454f508 100644 --- a/yaml/dom.nim +++ b/yaml/dom.nim @@ -235,11 +235,12 @@ proc serializeNode(n: YamlNode, c: SerializationContext, a: AnchorStyle, tagId: TagId anchor: AnchorId if a == asAlways: + val = c.nextAnchorId when defined(JS): - {.emit: [c, ".refs.set(", n, ", ", c.nextAnchorId, ");"].} + {.emit: [c, ".refs.set(", n, ", ", val, ");"].} else: c.refs[p] = c.nextAnchorId - c.nextAnchorId = AnchorId(int(c.nextAnchorId) + 1) + c.nextAnchorId = AnchorId(int(val) + 1) else: when defined(JS): {.emit: [c, ".refs.set(", n, ", ", yAnchorNone, ");"].} diff --git a/yaml/serialization.nim b/yaml/serialization.nim index 27c8c98..bb3c0ea 100644 --- a/yaml/serialization.nim +++ b/yaml/serialization.nim @@ -1244,10 +1244,13 @@ proc representChild*[O](value: ref O, ts: TagStyle, c: SerializationContext) = c.nextAnchorId = AnchorId(int(c.nextAnchorId) + 1) c.put(aliasEvent(val)) return - if c.style == asAlways: - c.refs[p] = c.nextAnchorId - c.nextAnchorId = AnchorId(int(c.nextAnchorId) + 1) - else: c.refs[p] = yAnchorNone + if c.style == asAlways: + val = c.nextAnchorId + when defined(JS): + {.emit: [c, ".refs.set(", p, ", ", val, ");"].} + else: c.refs[p] = val + c.nextAnchorId = AnchorId(int(val) + 1) + else: c.refs[p] = yAnchorNone let a = if c.style == asAlways: val else: cast[AnchorId](p) childTagStyle = if ts == tsAll: tsAll else: tsRootOnly