From 6cdbe4a2644b72c73b3a380b1c3bc7141739de31 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 18 Mar 2015 17:54:15 +0000 Subject: [PATCH] chore(doc-gen): fix AttachCommentTreeVisitor In the case that there were more than one comment blocks preceding a block of code, the visitor was only attaching the first comment. Really what we should do is to attach the last comment before the code block. --- .../services/AttachCommentTreeVisitor.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/dgeni-package/services/AttachCommentTreeVisitor.js b/docs/dgeni-package/services/AttachCommentTreeVisitor.js index 9325f0b4f0..d63b6a1144 100644 --- a/docs/dgeni-package/services/AttachCommentTreeVisitor.js +++ b/docs/dgeni-package/services/AttachCommentTreeVisitor.js @@ -16,7 +16,8 @@ module.exports = function AttachCommentTreeVisitor(ParseTreeVisitor, log) { if (this.currentComment) log.silly('comment: ' + this.currentComment.range.start.line + ' - ' + - this.currentComment.range.end.line); + this.currentComment.range.end.line + ' : ' + + this.currentComment.range.toString()); ParseTreeVisitor.prototype.visit.call(this, tree); }, @@ -24,14 +25,18 @@ module.exports = function AttachCommentTreeVisitor(ParseTreeVisitor, log) { // Really we ought to subclass ParseTreeVisitor but this is fiddly in ES5 so // it is easier to simply override the prototype's method on the instance visitAny: function(tree) { - if (tree && tree.location && tree.location.start && this.currentComment) { - if (this.currentComment.range.end.offset < tree.location.start.offset) { - log.silly('tree: ' + tree.constructor.name + ' - ' + tree.location.start.line); + if (tree && tree.location && tree.location.start && this.currentComment && + this.currentComment.range.end.offset < tree.location.start.offset) { + log.silly('tree: ' + tree.constructor.name + ' - ' + tree.location.start.line); + while (this.currentComment && + this.currentComment.range.end.offset < tree.location.start.offset) { + log.silly('comment: ' + this.currentComment.range.start.line + ' - ' + + this.currentComment.range.end.line + ' : ' + + this.currentComment.range.toString()); tree.commentBefore = this.currentComment; this.currentComment.treeAfter = tree; this.index++; this.currentComment = this.comments[this.index]; - if (this.currentComment) log.silly('comment: ' + this.currentComment.range.start.line + ' - ' + this.currentComment.range.end.line); } } return ParseTreeVisitor.prototype.visitAny.call(this, tree);