You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observed a strange behavior while toying around with my own stringWriter (master branch at 1425618):
If I create an element and call .txt() or .raw() on it once, or provide the text for the element directly in the .ele() call, then there is no callback to writer.text / writer.raw
If I add another method call to .txt(), .raw() or .dummy(), then there is a callback
This only occurs if { pretty: true }
Demo script:
letxml=xmlbuilder.create("root")xml.ele("textDirect",null,"[1]")xml.ele("textSingle").txt("[2]")xml.ele("rawSingle").raw("[3]")xml.ele("textDirectDummy",null,"[4]").dummy()xml.ele("textDummy").txt("[5]").dummy()xml.ele("rawDummy").raw("[6]").dummy()xml.ele("twoTextNodes").txt("[7]").txt("[7]")xml.ele("twoRaw").raw("[8]").raw("[8]")xml.ele("rawAndTextNode").raw("[9]").txt("[9]")xml.end(xmlbuilder.stringWriter({pretty: true,// missing callbacks only if true!writer: {raw: function(node,options,level){console.log(`${options.indent.repeat(level)}RAW ${node.value}`)returnthis._raw(node,options,level)},text: function(node,options,level){console.log(`${options.indent.repeat(level)}TEXT ${node.value}`)returnthis._text(node,options,level)},element: function(node,options,level){console.log(`${options.indent.repeat(level)}ELEMENT ${node.name}`)returnthis._element(node,options,level)}}}))
Output:
ELEMENT root
ELEMENT textDirect
ELEMENT textSingle
ELEMENT rawSingle
ELEMENT textDirectDummy
TEXT [4]
ELEMENT textDummy
TEXT [5]
ELEMENT rawDummy
RAW [6]
ELEMENT twoTextNodes
TEXT [7]
TEXT [7]
ELEMENT twoRaw
RAW [8]
RAW [8]
ELEMENT rawAndTextNode
RAW [9]
TEXT [9]
Expected output / { pretty: false }:
ELEMENT root
ELEMENT textDirect
TEXT [1]
ELEMENT textSingle
TEXT [2]
ELEMENT rawSingle
RAW [3]
ELEMENT textDirectDummy
TEXT [4]
ELEMENT textDummy
TEXT [5]
ELEMENT rawDummy
RAW [6]
ELEMENT twoTextNodes
TEXT [7]
TEXT [7]
ELEMENT twoRaw
RAW [8]
RAW [8]
ELEMENT rawAndTextNode
RAW [9]
TEXT [9]
Is this a bug? Maybe a side-effect of an optimization? Or am I using writer overrides in a completely unanticipated and unsupported way?
The text was updated successfully, but these errors were encountered:
I observed a strange behavior while toying around with my own
stringWriter
(master branch at 1425618):.txt()
or.raw()
on it once, or provide the text for the element directly in the.ele()
call, then there is no callback towriter.text
/writer.raw
.txt()
,.raw()
or.dummy()
, then there is a callback{ pretty: true }
Demo script:
Output:
Expected output /
{ pretty: false }
:Is this a bug? Maybe a side-effect of an optimization? Or am I using writer overrides in a completely unanticipated and unsupported way?
The text was updated successfully, but these errors were encountered: