Skip to content

Resolve imports without extension #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/extractors/exported.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] : [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids running into a NPE later on when addBlankComment does not return a value.

}
return path.node.leadingComments.filter(isJSDocComment).map(function (comment) {
return addComment(data, comment.value, comment.loc, path, path.node.loc, true);
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense. A lot of people use node's resolve mechanism today.

}

var value = dataCache[path];
if (!value) {
var input = fs.readFileSync(path, 'utf-8');
Expand Down
9 changes: 7 additions & 2 deletions lib/parsers/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ 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;
if (parentNode.range) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure when Babel dropped range but it might be possible to remove this branch entirely and just use start and end directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We updated our babel deps pretty recently. I think we should be able to remove this.

context.code = data.source.substring
.apply(data.source, parentNode.range);
} else {
context.code = data.source.substring(parentNode.start, parentNode.end);
}
}
}
return parse(commentValue, commentLoc, context);
Expand Down