[Plugins] Allow custom getCommentChildNodes (#3639)

* [Plugins] Allow plugins to specify their own getChildNodes for comment printing

* Rename getChildNodes -> getCommentChildNodes
master
Marcel Jackwerth 2018-01-03 13:58:53 +01:00 committed by Lucas Azzola
parent dbe0758b48
commit 6260629f18
1 changed files with 19 additions and 10 deletions

View File

@ -45,13 +45,22 @@ function getSortedChildNodes(node, text, options, resultArray) {
return node[childNodesCacheKey];
}
let names;
if (node && typeof node === "object") {
names = Object.keys(node).filter(
n =>
n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode"
);
} else {
let childNodes;
if (printer.getCommentChildNodes) {
childNodes = printer.getCommentChildNodes(node);
} else if (node && typeof node === "object") {
childNodes = Object.keys(node)
.filter(
n =>
n !== "enclosingNode" &&
n !== "precedingNode" &&
n !== "followingNode"
)
.map(n => node[n]);
}
if (!childNodes) {
return;
}
@ -62,9 +71,9 @@ function getSortedChildNodes(node, text, options, resultArray) {
});
}
for (let i = 0, nameCount = names.length; i < nameCount; ++i) {
getSortedChildNodes(node[names[i]], text, options, resultArray);
}
childNodes.forEach(childNode => {
getSortedChildNodes(childNode, text, options, resultArray);
});
return resultArray;
}