From 09ef9865cfa4feed073a50892bd6e3eeffcd402d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 13 Mar 2015 14:55:38 -0700 Subject: [PATCH] Parse top-level floating comments --- index.js | 6 +++++- test/fixture/comment-only.output.json | 29 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6bc1c7b..efc5547 100644 --- a/index.js +++ b/index.js @@ -146,13 +146,17 @@ module.exports = function (indexes) { file: data.file }; - if (path.parent.node) { + if (path.parent && path.parent.node) { comment.context.code = code.substring .apply(code, path.parent.node.range); } } types.visit(ast, { + visitProgram: makeVisitor(function (comment, node, path) { + addContext(comment, path); + }), + visitMemberExpression: makeVisitor(function (comment, node, path) { inferName(comment, node.property.name); addContext(comment, path); diff --git a/test/fixture/comment-only.output.json b/test/fixture/comment-only.output.json index 0637a08..c5d9bbb 100644 --- a/test/fixture/comment-only.output.json +++ b/test/fixture/comment-only.output.json @@ -1 +1,28 @@ -[] \ No newline at end of file +[ + { + "description": "This function returns the number one.", + "tags": [ + { + "title": "return", + "description": "numberone", + "type": { + "type": "NameExpression", + "name": "Number" + } + } + ], + "context": { + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "file": "fixture/comment-only.input.js" + } + } +] \ No newline at end of file