diff --git a/lib/extractors/exported.js b/lib/extractors/exported.js index 7ede439cb..b6b297caa 100644 --- a/lib/extractors/exported.js +++ b/lib/extractors/exported.js @@ -28,7 +28,8 @@ function walkExported(ast, data, addComment) { function getComments(data, path) { if (!hasJSDocComment(path)) { - return [addBlankComment(data, path, path.node)]; + var added = addBlankComment(data, path, path.node); + return added ? [added] : []; } return path.node.leadingComments.filter(isJSDocComment).map(function (comment) { return addComment(data, comment.value, comment.loc, path, path.node.loc, true); @@ -136,7 +137,12 @@ function traverseExportedSubtree(path, data, addComments, overrideName) { } } -function getCachedData(dataCache, path) { +function getCachedData(dataCache, filePath) { + var path = filePath; + if (!nodePath.extname(path)) { + path = require.resolve(path); + } + var value = dataCache[path]; if (!value) { var input = fs.readFileSync(path, 'utf-8'); diff --git a/lib/parsers/javascript.js b/lib/parsers/javascript.js index 73a44316b..9fada0ed1 100644 --- a/lib/parsers/javascript.js +++ b/lib/parsers/javascript.js @@ -70,8 +70,8 @@ function _addComment(visited, data, commentValue, commentLoc, path, nodeLoc, inc }); if (path.parentPath && path.parentPath.node) { - context.code = data.source.substring - .apply(data.source, path.parentPath.node.range); + var parentNode = path.parentPath.node; + context.code = data.source.substring(parentNode.start, parentNode.end); } } return parse(commentValue, commentLoc, context); diff --git a/test/fixture/document-exported.input.js b/test/fixture/document-exported.input.js index 5e97a6d86..5af071f09 100644 --- a/test/fixture/document-exported.input.js +++ b/test/fixture/document-exported.input.js @@ -47,7 +47,7 @@ var notExportedObject = { func: function() {}, }; -export {x, y3 as y4} from './document-exported/x.js'; +export {x, y3 as y4} from './document-exported/x'; export z from './document-exported/z.js'; export y2Default from './document-exported/y.js';