|
1 | 1 | const babylon = require('@babel/parser'); |
2 | | -const babelTraverse = require('@babel/traverse'); |
3 | 2 |
|
4 | 3 | const { config: astParseConfig, getNodeLines } = require('../../../shared/astParse'); |
5 | 4 | const NO_TRAIL_FLOW = require('../../../shared/constants').NO_TRAIL_FLOW; |
@@ -53,41 +52,24 @@ const getCrumbs = (fileCode, path) => { |
53 | 52 |
|
54 | 53 | try { |
55 | 54 | ast = babylon.parse(fileCode, astParseConfig); |
56 | | - |
57 | | - // TODO: ast has comments array, maybe use it |
58 | | - babelTraverse.default(ast, { |
59 | | - enter(path) { |
60 | | - const node = path.node; |
61 | | - if (!node || !(node.leadingComments || node.trailingComments)) return; |
62 | | - |
63 | | - const leadingComment = node.leadingComments |
64 | | - ? node.leadingComments[node.leadingComments.length - 1] |
65 | | - : null; |
66 | | - |
67 | | - let trailingComment = node.trailingComments ? node.trailingComments[0] : null; |
68 | | - |
69 | | - if (trailingComment && trailingComment.loc.start.line !== node.loc.start.line) { |
70 | | - trailingComment = null; |
| 55 | + if (ast.comments) { |
| 56 | + ast.comments.forEach(comment => { |
| 57 | + if (comment && isCodecrumb(comment)) { |
| 58 | + const params = parseCodecrumbComment(comment); |
| 59 | + |
| 60 | + const loc = comment.loc.start; |
| 61 | + const crumbNodeLines = getNodeLines(comment); |
| 62 | + crumbsList.push({ |
| 63 | + name: params.name || '', //TODO: check, can be bug with layout calc |
| 64 | + displayLoc: `#${loc.line}`, |
| 65 | + crumbNodeLines: params.linesRange |
| 66 | + ? [crumbNodeLines[0], crumbNodeLines[1] + params.linesRange] |
| 67 | + : crumbNodeLines, |
| 68 | + params |
| 69 | + }); |
71 | 70 | } |
72 | | - |
73 | | - [leadingComment, trailingComment].forEach(comment => { |
74 | | - if (comment && isCodecrumb(comment)) { |
75 | | - const params = parseCodecrumbComment(comment); |
76 | | - |
77 | | - const loc = comment.loc.start; |
78 | | - const crumbNodeLines = getNodeLines(comment); |
79 | | - crumbsList.push({ |
80 | | - name: params.name || '', //TODO: check, can be bug with layout calc |
81 | | - displayLoc: `#${loc.line}`, |
82 | | - crumbNodeLines: params.linesRange |
83 | | - ? [crumbNodeLines[0], crumbNodeLines[1] + params.linesRange] |
84 | | - : crumbNodeLines, |
85 | | - params |
86 | | - }); |
87 | | - } |
88 | | - }); |
89 | | - } |
90 | | - }); |
| 71 | + }); |
| 72 | + } |
91 | 73 |
|
92 | 74 | return crumbsList; |
93 | 75 | } catch (e) { |
|
0 commit comments