@@ -65,29 +65,28 @@ export class BaseConfigFactory {
6565 private createJavascriptPlusLwcConfigArray ( ) : Linter . Config [ ] {
6666 let configs : Linter . Config [ ] = validateAndGetRawLwcConfigArray ( ) ;
6767
68- // Deep clone the languageOptions to avoid mutating the original shared config from the LWC package
68+ // Reconstruct languageOptions to avoid mutating the original shared config from the LWC package
69+ // TODO: Remove configFile and sourceType overrides when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
6970 const originalParserOptions = configs [ 0 ] . languageOptions ! . parserOptions as Linter . ParserOptions ;
70- const clonedBabelOptions = JSON . parse ( JSON . stringify ( originalParserOptions . babelOptions ) ) ;
71+ const originalBabelOptions = originalParserOptions . babelOptions || { } ;
7172 configs [ 0 ] . languageOptions = {
7273 ...configs [ 0 ] . languageOptions ,
7374 parserOptions : {
7475 ...originalParserOptions ,
75- babelOptions : clonedBabelOptions
76+ // For some reason babel doesn't like .cjs files unless we explicitly set this to undefined
77+ // because ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist
78+ // in the parserOptions (and for babel "commonjs" isn't a valid option)
79+ sourceType : undefined ,
80+ babelOptions : {
81+ ...originalBabelOptions ,
82+ // Turn off the babel parser's configFile option from the lwc base plugin
83+ configFile : false ,
84+ // Add @babel /preset-react to enable JSX parsing for React/JSX files
85+ presets : [ ...( originalBabelOptions . presets || [ ] ) , '@babel/preset-react' ]
86+ }
7687 }
7788 } ;
7889
79- // TODO: Remove the For the following 2 updates when https://github.com/salesforce/eslint-config-lwc/issues/158 is fixed
80- // 1) Turn off the babel parser's configFile option from the lwc base plugin
81- clonedBabelOptions . configFile = false ;
82- // 2) For some reason babel doesn't like .cjs files unless we explicitly set this to undefined because I think
83- // ESLint 9 is setting it to "commonjs" automatically when the field doesn't exist in the parserOptions (and for
84- // babel "commonjs" isn't a valid option)
85- ( configs [ 0 ] . languageOptions ! . parserOptions as Linter . ParserOptions ) . sourceType = undefined ;
86-
87- // 3) Add @babel/preset-react to enable JSX parsing for React/JSX files
88- const existingPresets = clonedBabelOptions . presets || [ ] ;
89- clonedBabelOptions . presets = [ ...existingPresets , '@babel/preset-react' ] ;
90-
9190 // Swap out eslintJs.configs.recommended with eslintJs.configs.all
9291 configs [ 1 ] = eslintJs . configs . all ;
9392
0 commit comments