-
Notifications
You must be signed in to change notification settings - Fork 486
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
Conversation
Avoid exception when no comment was attached.
@@ -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] : []; |
There was a problem hiding this comment.
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.
context.code = data.source.substring | ||
.apply(data.source, path.parentPath.node.range); | ||
var parentNode = path.parentPath.node; | ||
if (parentNode.range) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to test this?
function getCachedData(dataCache, filePath) { | ||
var path = filePath; | ||
if (!nodePath.extname(path)) { | ||
path = require.resolve(path); |
There was a problem hiding this comment.
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.
context.code = data.source.substring | ||
.apply(data.source, path.parentPath.node.range); | ||
var parentNode = path.parentPath.node; | ||
if (parentNode.range) { |
There was a problem hiding this comment.
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.
@arv I've added test coverage and removed the fallback for the old Babel API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great.
I'll merge this.
In my use case, I have a project where imports are written without a file extension, i.e.
This PR uses
require.resolve
to figure out the actual file name if no extension was specified.Most probably, a more advanced resolution would be better but this should be good enough and avoids some confusion.
Additionally, I have fixed a few problems I ran into.