Skip to content

Commit 96c3ec7

Browse files
authored
Update babylon to latest beta and fix detection of comments (#222)
1 parent d9befb5 commit 96c3ec7

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"dependencies": {
3636
"async": "^2.1.4",
3737
"babel-runtime": "^6.9.2",
38-
"babylon": "v7.0.0-beta.20",
38+
"babylon": "7.0.0-beta.29",
3939
"commander": "^2.9.0",
4040
"doctrine": "^2.0.0",
4141
"node-dir": "^0.1.10",

src/handlers/componentDocblockHandler.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,27 @@ export default function componentDocblockHandler(
3131
path: NodePath
3232
) {
3333
var description = null;
34-
// Find parent statement (e.g. var Component = React.createClass(<path>);)
35-
var searchPath = path;
36-
while (searchPath && !types.Statement.check(searchPath.node)) {
37-
searchPath = searchPath.parent;
38-
}
39-
if (searchPath) {
40-
// If the parent is an export statement, we have to traverse one more up
41-
if (types.ExportNamedDeclaration.check(searchPath.parentPath.node) ||
42-
types.ExportDefaultDeclaration.check(searchPath.parentPath.node)) {
43-
searchPath = searchPath.parentPath;
44-
}
45-
description = getDocblock(searchPath);
46-
}
47-
if (description == null && isClassDefinition(path)) {
34+
35+
if (isClassDefinition(path)) {
4836
// If we have a class declaration or expression, then the comment might be
49-
// attached to the first decorator instead.
37+
// attached to the last decorator instead as trailing comment.
5038
if (path.node.decorators && path.node.decorators.length > 0) {
51-
description = getDocblock(path.get('decorators', 0));
39+
description = getDocblock(path.get('decorators', path.node.decorators.length - 1), true);
5240
}
5341
}
5442
if (description == null) {
55-
// If this is the first statement in the module body, the comment is attached
56-
// to the program node
57-
var programPath = searchPath;
58-
while (programPath && !types.Program.check(programPath.node)) {
59-
programPath = programPath.parent;
43+
// Find parent statement (e.g. var Component = React.createClass(<path>);)
44+
var searchPath = path;
45+
while (searchPath && !types.Statement.check(searchPath.node)) {
46+
searchPath = searchPath.parent;
6047
}
61-
if (programPath.get('body', 0) === searchPath) {
62-
description = getDocblock(programPath);
48+
if (searchPath) {
49+
// If the parent is an export statement, we have to traverse one more up
50+
if (types.ExportNamedDeclaration.check(searchPath.parentPath.node) ||
51+
types.ExportDefaultDeclaration.check(searchPath.parentPath.node)) {
52+
searchPath = searchPath.parentPath;
53+
}
54+
description = getDocblock(searchPath);
6355
}
6456
}
6557
documentation.set('description', description || '');

src/utils/docblock.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ let DOCBLOCK_HEADER = /^\*\s/;
2929
* Given a path, this function returns the closest preceding docblock if it
3030
* exists.
3131
*/
32-
export function getDocblock(path: NodePath): ?string {
32+
export function getDocblock(path: NodePath, trailing: boolean = false): ?string {
3333
var comments = [];
34-
if (path.node.leadingComments) {
34+
if (trailing && path.node.trailingComments) {
35+
comments = path.node.trailingComments.filter(
36+
comment => comment.type === 'CommentBlock' &&
37+
DOCBLOCK_HEADER.test(comment.value)
38+
);
39+
} else if (path.node.leadingComments) {
3540
comments = path.node.leadingComments.filter(
3641
comment => comment.type === 'CommentBlock' &&
3742
DOCBLOCK_HEADER.test(comment.value)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,14 @@ babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24
748748
lodash "^4.2.0"
749749
to-fast-properties "^1.0.1"
750750

751+
752+
version "7.0.0-beta.29"
753+
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.29.tgz#6a3e0e6287390385a36f5511e7f94db8618574ae"
754+
751755
babylon@^6.17.0, babylon@^6.17.2, babylon@^6.17.4:
752756
version "6.17.4"
753757
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.4.tgz#3e8b7402b88d22c3423e137a1577883b15ff869a"
754758

755-
756-
version "7.0.0-beta.20"
757-
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.20.tgz#7dbc70cc88de13334066fe5200e0efaa30c0490e"
758-
759759
balanced-match@^1.0.0:
760760
version "1.0.0"
761761
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

0 commit comments

Comments
 (0)