[Plugins] Allow custom getCommentChildNodes (#3639)
* [Plugins] Allow plugins to specify their own getChildNodes for comment printing * Rename getChildNodes -> getCommentChildNodesmaster
parent
dbe0758b48
commit
6260629f18
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue