@@ -2,9 +2,6 @@ import path from 'path'
22
33import type { ExpressionStatement } from '@babel/types'
44import type { AST , Linter } from 'eslint'
5- import remarkMdx from 'remark-mdx'
6- import remarkParse from 'remark-parse'
7- import unified from 'unified'
85
96import {
107 arrayify ,
@@ -16,6 +13,7 @@ import {
1613 normalizePosition ,
1714 restoreNodeLocation ,
1815} from './helpers'
16+ import { getPhysicalFilename , getRemarkProcessor } from './processor'
1917import {
2018 COMMENT_CONTENT_REGEX ,
2119 COMMENT_CONTENT_REGEX_GLOBAL ,
@@ -32,9 +30,6 @@ import type {
3230 ParserServices ,
3331} from './types'
3432
35- export const mdProcessor = unified ( ) . use ( remarkParse ) . freeze ( )
36- export const mdxProcessor = mdProcessor ( ) . use ( remarkMdx ) . freeze ( )
37-
3833export const AST_PROPS = [ 'body' , 'comments' , 'tokens' ] as const
3934export const ES_NODE_TYPES : readonly string [ ] = [ 'export' , 'import' , 'jsx' ]
4035
@@ -43,6 +38,8 @@ export const LOC_ERROR_PROPERTIES = ['column', 'lineNumber'] as const
4338export const DEFAULT_EXTENSIONS : readonly string [ ] = [ '.mdx' ]
4439export const MARKDOWN_EXTENSIONS : readonly string [ ] = [ '.md' ]
4540
41+ export const PLACEHOLDER_FILE_PATH = '__placeholder__.mdx'
42+
4643export const DEFAULT_PARSER_OPTIONS : ParserOptions = {
4744 comment : true ,
4845 ecmaFeatures : {
@@ -52,7 +49,7 @@ export const DEFAULT_PARSER_OPTIONS: ParserOptions = {
5249 new Date ( ) . getUTCFullYear ( ) as Linter . ParserOptions [ 'ecmaVersion' ] ,
5350 sourceType : 'module' ,
5451 tokens : true ,
55- filePath : '__placeholder__.mdx' ,
52+ filePath : PLACEHOLDER_FILE_PATH ,
5653 // required for @typescript -eslint/parser
5754 // reference: https://github.com/typescript-eslint/typescript-eslint/pull/2028
5855 loc : true ,
@@ -170,7 +167,10 @@ export class Parser {
170167 return this . _eslintParse ( code , options )
171168 }
172169
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
174174
175175 this . _ast = {
176176 ...normalizePosition ( root . position ) ,
0 commit comments