@@ -3,6 +3,7 @@ import { CodeAnnotation } from "../smooth-code"
33import { wrapChildren } from "./to-estree"
44import { annotationsMap } from "../mdx-client/annotations"
55import { JsxNode as JsxNode , SuperNode } from "./nodes"
6+ import { getCommentData } from "./comment-data"
67
78export function getAnnotationsFromMetastring (
89 options : Record < string , string >
@@ -24,8 +25,10 @@ export function extractAnnotationsFromCode(code: Code) {
2425 const focusList = [ ] as string [ ]
2526 while ( lineNumber <= lines . length ) {
2627 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+ )
2932
3033 const Component = annotationsMap [ key ! ]
3134
@@ -50,31 +53,6 @@ export function extractAnnotationsFromCode(code: Code) {
5053 return [ annotations , focusList . join ( "," ) ] as const
5154}
5255
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-
7856export function extractJSXAnnotations (
7957 node : SuperNode ,
8058 index : number ,
@@ -108,7 +86,6 @@ export function extractJSXAnnotations(
10886 focus,
10987 data : isEmpty ( data ) ? undefined : data ,
11088 } )
111- // console.log(jsxAnnotation)
11289 parent . children . splice ( nextIndex , 1 )
11390 }
11491 return annotations
0 commit comments