@@ -2,9 +2,6 @@ import path from 'path'
2
2
3
3
import type { ExpressionStatement } from '@babel/types'
4
4
import type { AST , Linter } from 'eslint'
5
- import remarkMdx from 'remark-mdx'
6
- import remarkParse from 'remark-parse'
7
- import unified from 'unified'
8
5
9
6
import {
10
7
arrayify ,
@@ -16,6 +13,7 @@ import {
16
13
normalizePosition ,
17
14
restoreNodeLocation ,
18
15
} from './helpers'
16
+ import { getPhysicalFilename , getRemarkProcessor } from './processor'
19
17
import {
20
18
COMMENT_CONTENT_REGEX ,
21
19
COMMENT_CONTENT_REGEX_GLOBAL ,
@@ -32,9 +30,6 @@ import type {
32
30
ParserServices ,
33
31
} from './types'
34
32
35
- export const mdProcessor = unified ( ) . use ( remarkParse ) . freeze ( )
36
- export const mdxProcessor = mdProcessor ( ) . use ( remarkMdx ) . freeze ( )
37
-
38
33
export const AST_PROPS = [ 'body' , 'comments' , 'tokens' ] as const
39
34
export const ES_NODE_TYPES : readonly string [ ] = [ 'export' , 'import' , 'jsx' ]
40
35
@@ -43,6 +38,8 @@ export const LOC_ERROR_PROPERTIES = ['column', 'lineNumber'] as const
43
38
export const DEFAULT_EXTENSIONS : readonly string [ ] = [ '.mdx' ]
44
39
export const MARKDOWN_EXTENSIONS : readonly string [ ] = [ '.md' ]
45
40
41
+ export const PLACEHOLDER_FILE_PATH = '__placeholder__.mdx'
42
+
46
43
export const DEFAULT_PARSER_OPTIONS : ParserOptions = {
47
44
comment : true ,
48
45
ecmaFeatures : {
@@ -52,7 +49,7 @@ export const DEFAULT_PARSER_OPTIONS: ParserOptions = {
52
49
new Date ( ) . getUTCFullYear ( ) as Linter . ParserOptions [ 'ecmaVersion' ] ,
53
50
sourceType : 'module' ,
54
51
tokens : true ,
55
- filePath : '__placeholder__.mdx' ,
52
+ filePath : PLACEHOLDER_FILE_PATH ,
56
53
// required for @typescript -eslint/parser
57
54
// reference: https://github.com/typescript-eslint/typescript-eslint/pull/2028
58
55
loc : true ,
@@ -170,7 +167,10 @@ export class Parser {
170
167
return this . _eslintParse ( code , options )
171
168
}
172
169
173
- const root = ( isMdx ? mdxProcessor : mdProcessor ) . parse ( code ) as Parent
170
+ const root = getRemarkProcessor (
171
+ getPhysicalFilename ( options . filePath ) ,
172
+ isMdx ,
173
+ ) . parse ( code ) as Parent
174
174
175
175
this . _ast = {
176
176
...normalizePosition ( root . position ) ,
0 commit comments