1
1
import path from 'path'
2
2
3
3
import type { AST , Linter } from 'eslint'
4
+ import type { VFileMessage } from 'vfile-message'
4
5
5
6
import {
6
7
arrayify ,
@@ -10,9 +11,13 @@ import {
10
11
} from './helpers'
11
12
import { getPhysicalFilename } from './processor'
12
13
import { traverse } from './traverse'
13
- import type { ParserOptions } from './types'
14
+ import type { ParserOptions , WorkerParseResult } from './types'
14
15
15
- export const AST_PROPS = [ 'body' , 'comments' ] as const
16
+ export const AST_PROPS = [
17
+ 'body' ,
18
+ // disable comments temporarily -- #380
19
+ // 'comments'
20
+ ] as const
16
21
17
22
export const DEFAULT_EXTENSIONS : readonly string [ ] = [ '.mdx' ]
18
23
export const MARKDOWN_EXTENSIONS : readonly string [ ] = [ '.md' ]
@@ -59,15 +64,28 @@ export class Parser {
59
64
60
65
const physicalFilename = getPhysicalFilename ( filePath )
61
66
62
- const { root, tokens, comments } = performSyncWork ( {
63
- fileOptions : {
64
- path : physicalFilename ,
65
- value : code ,
66
- } ,
67
- physicalFilename,
68
- isMdx,
69
- ignoreRemarkConfig : ignoreRemarkConfig ,
70
- } )
67
+ let result : WorkerParseResult
68
+
69
+ try {
70
+ result = performSyncWork ( {
71
+ fileOptions : {
72
+ path : physicalFilename ,
73
+ value : code ,
74
+ } ,
75
+ physicalFilename,
76
+ isMdx,
77
+ ignoreRemarkConfig : ignoreRemarkConfig ,
78
+ } )
79
+ } catch ( err : unknown ) {
80
+ const error = err as VFileMessage
81
+ throw Object . assign ( new SyntaxError ( error . message ) , {
82
+ lineNumber : error . line ,
83
+ column : error . column ,
84
+ index : /* istanbul ignore next */ error . position ?. start . offset ,
85
+ } )
86
+ }
87
+
88
+ const { root, tokens, comments } = result
71
89
72
90
this . _ast = {
73
91
...normalizePosition ( root . position ) ,
@@ -85,7 +103,6 @@ export class Parser {
85
103
}
86
104
87
105
for ( const prop of AST_PROPS ) {
88
- // @ts -expect-error
89
106
this . _ast [ prop ] . push ( ...( node . data ?. estree [ prop ] || [ ] ) )
90
107
}
91
108
} )
0 commit comments