@@ -19,11 +19,11 @@ export const ES_NODE_TYPES = ['export', 'import', 'jsx'] as const
1919
2020export type EsNodeType = ( typeof ES_NODE_TYPES ) [ number ]
2121
22- export const parseMdx = unified ( )
22+ export const mdxProcessor = unified ( )
2323 . use < any > ( remarkParse )
2424 . use < any > ( remarkStringify )
2525 . use ( remarkMdx )
26- . freeze ( ) . parse
26+ . freeze ( )
2727
2828export const parseForESLint = (
2929 code : string ,
@@ -53,7 +53,7 @@ export const parseForESLint = (
5353 }
5454 }
5555
56- const root = parseMdx ( code ) as Parent
56+ const root = mdxProcessor . parse ( code ) as Parent
5757
5858 const ast : AST . Program = {
5959 ...normalizePosition ( root . position ) ,
@@ -65,36 +65,36 @@ export const parseForESLint = (
6565 }
6666
6767 traverse ( root , {
68- enter ( { position , type } ) {
69- if ( ! ES_NODE_TYPES . includes ( type as EsNodeType ) ) {
68+ enter ( node ) {
69+ if ( ! ES_NODE_TYPES . includes ( node . type as EsNodeType ) ) {
7070 return
7171 }
7272
73- const rawText = code . slice ( position . start . offset , position . end . offset )
73+ const rawText = node . value as string
7474
7575 // fix #4
7676 if ( isComment ( rawText ) ) {
7777 return
7878 }
7979
80- const node = normalizePosition ( position )
81- const startLine = node . loc . start . line - 1 //! line is 1-indexed, change to 0-indexed to simplify usage
80+ const { loc , start } = normalizePosition ( node . position )
81+ const startLine = loc . start . line - 1 //! line is 1-indexed, change to 0-indexed to simplify usage
8282
8383 let program : AST . Program
8484
8585 try {
8686 program = parser ( rawText , options )
8787 } catch ( e ) {
8888 if ( e instanceof SyntaxError ) {
89- e . index += node . start
90- e . column += node . loc . start . column
89+ e . index += start
90+ e . column += loc . start . column
9191 e . lineNumber += startLine
9292 }
9393
9494 throw e
9595 }
9696
97- const offset = node . start - program . range [ 0 ]
97+ const offset = start - program . range [ 0 ]
9898
9999 AST_PROPS . forEach ( prop =>
100100 ast [ prop ] . push (
0 commit comments