Skip to content

Commit

Permalink
refactor: Optimization code
Browse files Browse the repository at this point in the history
  • Loading branch information
HcySunYang committed Jan 15, 2019
1 parent 0c3d854 commit c19d188
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/parser/lib/jscomments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getComments(cnode: bt.Node, trailing?: boolean): CommentResult {
: cnode.leadingComments || []
if (!commentNodes || !commentNodes.length) return res

let comments: string = '',
let comments: string | string[] = '',
matchs: RegExpMatchArray | null
;(commentNodes as []).forEach((node: bt.Comment) => {
if (isCommentLine(node)) {
Expand All @@ -35,11 +35,10 @@ export function getComments(cnode: bt.Node, trailing?: boolean): CommentResult {
.replace(commentRE, '\n')
.replace(/^\*/, '')
.split('\n')
.map(t => t.trim())
.filter(t => t)
.join('\n')
.trim()
let currentKey = 'default'
comments.split('\n').forEach(c => {
;(comments as string[]).forEach(c => {
if ((matchs = c.match(leadRE))) {
currentKey = matchs[1]
res[currentKey] = res[currentKey] || []
Expand Down

0 comments on commit c19d188

Please sign in to comment.