@@ -3,6 +3,7 @@ import { CodeAnnotation } from "../smooth-code"
3
3
import { wrapChildren } from "./to-estree"
4
4
import { annotationsMap } from "../mdx-client/annotations"
5
5
import { JsxNode as JsxNode , SuperNode } from "./nodes"
6
+ import { getCommentData } from "./comment-data"
6
7
7
8
export function getAnnotationsFromMetastring (
8
9
options : Record < string , string >
@@ -24,8 +25,10 @@ export function extractAnnotationsFromCode(code: Code) {
24
25
const focusList = [ ] as string [ ]
25
26
while ( lineNumber <= lines . length ) {
26
27
const line = lines [ lineNumber - 1 ]
27
- const { key, focusString, data } = getCommentData ( line )
28
- // console.log({ key, focusString, data })
28
+ const { key, focusString, data } = getCommentData (
29
+ line ,
30
+ code . lang
31
+ )
29
32
30
33
const Component = annotationsMap [ key ! ]
31
34
@@ -50,31 +53,6 @@ export function extractAnnotationsFromCode(code: Code) {
50
53
return [ annotations , focusList . join ( "," ) ] as const
51
54
}
52
55
53
- const commentRegex = / \/ \/ \s + ( \w + ) ( \S * ) \s * ( .* ) /
54
- function getCommentData ( line : Code [ "lines" ] [ 0 ] ) {
55
- const comment = line . tokens . find ( t =>
56
- t . content . trim ( ) . startsWith ( "//" )
57
- ) ?. content
58
-
59
- if ( ! comment ) {
60
- return { }
61
- }
62
-
63
- const result = commentRegex . exec ( comment )
64
-
65
- if ( ! result ) {
66
- return { }
67
- }
68
-
69
- const [ , key , focusString , data ] = result
70
-
71
- return {
72
- key,
73
- focusString,
74
- data,
75
- }
76
- }
77
-
78
56
export function extractJSXAnnotations (
79
57
node : SuperNode ,
80
58
index : number ,
@@ -108,7 +86,6 @@ export function extractJSXAnnotations(
108
86
focus,
109
87
data : isEmpty ( data ) ? undefined : data ,
110
88
} )
111
- // console.log(jsxAnnotation)
112
89
parent . children . splice ( nextIndex , 1 )
113
90
}
114
91
return annotations
0 commit comments