@@ -59,14 +59,14 @@ export class Parser {
5959 }
6060
6161 // @internal
62- private _options = DEFAULT_PARSER_OPTIONS
62+ private readonly _options = DEFAULT_PARSER_OPTIONS
6363
6464 constructor ( ) {
6565 this . parse = this . parse . bind ( this )
6666 this . parseForESLint = this . parseForESLint . bind ( this )
6767 }
6868
69- normalizeJsxNode ( node : Node , parent ?: Parent ) {
69+ normalizeJsxNode ( node : Node , parent ?: Parent , options = this . _options ) {
7070 const value = node . value as string
7171
7272 if ( node . type !== 'jsx' || isComment ( value ) ) {
@@ -135,7 +135,7 @@ export class Parser {
135135 } )
136136 }
137137
138- return this . _normalizeJsxNodes ( node )
138+ return this . _normalizeJsxNodes ( node , options )
139139 }
140140
141141 parse ( code : string , options : ParserOptions ) {
@@ -176,7 +176,7 @@ export class Parser {
176176 return
177177 }
178178
179- let normalized = this . normalizeJsxNode ( node , parent )
179+ let normalized = this . normalizeJsxNode ( node , parent , options )
180180 normalized = Array . isArray ( normalized ) ? normalized : [ normalized ]
181181 normalized . forEach ( _node => this . _nodeToAst ( _node , options ) )
182182 } ,
@@ -190,15 +190,15 @@ export class Parser {
190190 }
191191
192192 // @internal
193- private _eslintParse ( code : string , options = this . _options ) {
193+ private _eslintParse ( code : string , options : ParserOptions ) {
194194 if ( ! this . _parser || options . parser !== this . _options . parser ) {
195195 this . _parser = normalizeParser ( options . parser )
196196 }
197197 /* istanbul ignore else */
198- if ( options . filePath ) {
199- this . _options = options
198+ if ( options . filePath && this . _options !== options ) {
199+ Object . assign ( this . _options , options )
200200 }
201- const program = this . _parser ( code , options )
201+ const program = this . _parser ( code , this . _options )
202202 /* istanbul ignore next */
203203 return ( 'ast' in program && program . ast
204204 ? program
@@ -207,7 +207,10 @@ export class Parser {
207207
208208 // fix adjacent JSX nodes
209209 // @internal
210- private _normalizeJsxNodes ( node : Node ) : Node | Node [ ] {
210+ private _normalizeJsxNodes (
211+ node : Node ,
212+ options : ParserOptions ,
213+ ) : Node | Node [ ] {
211214 const value = node . value as string
212215
213216 let program : AST . Program
@@ -216,6 +219,7 @@ export class Parser {
216219 // wrap into single element which is valid jsx but not valid jsx in mdx, so that it won't break on adjacent JSX nodes
217220 program = this . _eslintParse (
218221 `${ JSX_WRAPPER_START } ${ value } ${ JSX_WRAPPER_END } ` ,
222+ options ,
219223 ) . ast
220224 } catch ( e ) {
221225 if ( hasProperties < LocationError > ( e , LOC_ERROR_PROPERTIES ) ) {
@@ -225,6 +229,7 @@ export class Parser {
225229
226230 e . index += start . offset - OFFSET
227231 e . column =
232+ /* istanbul ignore next */
228233 e . lineNumber > 1 ? e . column : e . column + start . column - OFFSET
229234 e . lineNumber += start . line - 1
230235
0 commit comments