|
17 | 17 | * along with this program; if not, write to the Free Software Foundation, |
18 | 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 | */ |
20 | | -import * as babel from '@babel/eslint-parser'; |
| 20 | +import * as babel from 'babel-eslint'; |
21 | 21 | import { Linter, SourceCode } from 'eslint'; |
22 | 22 | import { ParsingError } from './analyzer'; |
23 | 23 | import * as VueJS from 'vue-eslint-parser'; |
@@ -68,7 +68,7 @@ export function parseJavaScriptSourceFile( |
68 | 68 |
|
69 | 69 | let exceptionToReport: ParseException | null = null; |
70 | 70 | for (const config of [PARSER_CONFIG_MODULE, PARSER_CONFIG_SCRIPT]) { |
71 | | - const result = parse(babel.parseForESLint, babelConfig(config), fileContent); |
| 71 | + const result = parse(babel.parseForESLint, config, fileContent); |
72 | 72 | if (result instanceof SourceCode) { |
73 | 73 | return result; |
74 | 74 | } else if (!exceptionToReport) { |
@@ -119,19 +119,16 @@ export function parseVueSourceFile( |
119 | 119 | tsConfigs?: string[], |
120 | 120 | ): SourceCode | ParsingError { |
121 | 121 | let exception: ParseException | null = null; |
122 | | - const parserOptions = { |
123 | | - filePath, |
124 | | - project: tsConfigs, |
125 | | - extraFileExtensions: ['.vue'], |
126 | | - ...PARSER_CONFIG_MODULE, |
127 | | - }; |
128 | | - const parsers = [ |
129 | | - { parser: '@typescript-eslint/parser', parserOptions }, |
130 | | - { parser: '@babel/eslint-parser', parserOptions: babelConfig(parserOptions) }, |
131 | | - ]; |
132 | | - for (const { parser, parserOptions } of parsers) { |
| 122 | + const parsers = ['@typescript-eslint/parser', 'babel-eslint']; |
| 123 | + for (const parser of parsers) { |
133 | 124 | try { |
134 | | - const result = VueJS.parseForESLint(fileContent, { parser, ...parserOptions }); |
| 125 | + const result = VueJS.parseForESLint(fileContent, { |
| 126 | + filePath, |
| 127 | + parser, |
| 128 | + project: tsConfigs, |
| 129 | + extraFileExtensions: ['.vue'], |
| 130 | + ...PARSER_CONFIG_MODULE, |
| 131 | + }); |
135 | 132 | return new SourceCode(({ |
136 | 133 | ...result, |
137 | 134 | parserServices: result.services, |
@@ -191,11 +188,3 @@ export function parseExceptionCodeOf(exceptionMsg: string): ParseExceptionCode { |
191 | 188 | return ParseExceptionCode.Parsing; |
192 | 189 | } |
193 | 190 | } |
194 | | - |
195 | | -export function babelConfig(config: Linter.ParserOptions) { |
196 | | - const pluginPath = `${__dirname}/../node_modules`; |
197 | | - const babelOptions = { |
198 | | - presets: [`${pluginPath}/@babel/preset-react`, `${pluginPath}/@babel/preset-flow`], |
199 | | - }; |
200 | | - return { ...config, requireConfigFile: false, babelOptions }; |
201 | | -} |
0 commit comments