From a77a93569c77e7cf20948401b07ffc042ea79288 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Wed, 11 Mar 2020 00:51:06 +0100 Subject: [PATCH] fix class comments when there is no toc --- utils/doclint/check_public_api/MDBuilder.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/doclint/check_public_api/MDBuilder.js b/utils/doclint/check_public_api/MDBuilder.js index f57010c0d8e04b..64de28fee31f99 100644 --- a/utils/doclint/check_public_api/MDBuilder.js +++ b/utils/doclint/check_public_api/MDBuilder.js @@ -98,8 +98,10 @@ class MDOutline { */ function parseClass(content) { const members = []; - const commentWalker = document.createTreeWalker(content, NodeFilter.SHOW_COMMENT, { + const commentWalker = document.createTreeWalker(content, NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT, { acceptNode(node) { + if (node instanceof HTMLElement && node.tagName === 'H4') + return NodeFilter.FILTER_ACCEPT; if (!(node instanceof Comment)) return NodeFilter.FILTER_REJECT; if (node.data.trim().startsWith('GEN:toc')) @@ -107,7 +109,7 @@ class MDOutline { return NodeFilter.FILTER_REJECT; } }); - const tocStart = commentWalker.nextNode(); + const commentEnd = commentWalker.nextNode(); const headers = content.querySelectorAll('h4'); const name = content.firstChild.textContent; let extendsName = null; @@ -117,7 +119,7 @@ class MDOutline { commentStart = extendsElement.nextSibling; extendsName = extendsElement.querySelector('a').textContent; } - const comment = parseComment(extractSiblingsIntoFragment(commentStart, tocStart)); + const comment = parseComment(extractSiblingsIntoFragment(commentStart, commentEnd)); for (let i = 0; i < headers.length; i++) { const fragment = extractSiblingsIntoFragment(headers[i], headers[i + 1]); members.push(parseMember(fragment)); @@ -144,7 +146,6 @@ class MDOutline { } /** - * @param {string} name * @param {DocumentFragment} content */ function parseMember(content) {