Skip to content

Commit 6cdbe4a

Browse files
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.
1 parent 014a28f commit 6cdbe4a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/dgeni-package/services/AttachCommentTreeVisitor.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ module.exports = function AttachCommentTreeVisitor(ParseTreeVisitor, log) {
1616

1717
if (this.currentComment) log.silly('comment: ' +
1818
this.currentComment.range.start.line + ' - ' +
19-
this.currentComment.range.end.line);
19+
this.currentComment.range.end.line + ' : ' +
20+
this.currentComment.range.toString());
2021

2122
ParseTreeVisitor.prototype.visit.call(this, tree);
2223
},
2324

2425
// Really we ought to subclass ParseTreeVisitor but this is fiddly in ES5 so
2526
// it is easier to simply override the prototype's method on the instance
2627
visitAny: function(tree) {
27-
if (tree && tree.location && tree.location.start && this.currentComment) {
28-
if (this.currentComment.range.end.offset < tree.location.start.offset) {
29-
log.silly('tree: ' + tree.constructor.name + ' - ' + tree.location.start.line);
28+
if (tree && tree.location && tree.location.start && this.currentComment &&
29+
this.currentComment.range.end.offset < tree.location.start.offset) {
30+
log.silly('tree: ' + tree.constructor.name + ' - ' + tree.location.start.line);
31+
while (this.currentComment &&
32+
this.currentComment.range.end.offset < tree.location.start.offset) {
33+
log.silly('comment: ' + this.currentComment.range.start.line + ' - ' +
34+
this.currentComment.range.end.line + ' : ' +
35+
this.currentComment.range.toString());
3036
tree.commentBefore = this.currentComment;
3137
this.currentComment.treeAfter = tree;
3238
this.index++;
3339
this.currentComment = this.comments[this.index];
34-
if (this.currentComment) log.silly('comment: ' + this.currentComment.range.start.line + ' - ' + this.currentComment.range.end.line);
3540
}
3641
}
3742
return ParseTreeVisitor.prototype.visitAny.call(this, tree);

0 commit comments

Comments
 (0)