1717import { debug } from '../../../shared/src/helpers/logging.js' ;
1818import { JsTsAnalysisInput } from '../analysis/analysis.js' ;
1919import { buildParserOptions } from '../parsers/options.js' ;
20- import { parseForESLint } from '../parsers/parse.js' ;
21- import { parsers } from '../parsers/eslint.js' ;
20+ import { parse } from '../parsers/parse.js' ;
21+ import { Parser , parsersMap } from '../parsers/eslint.js' ;
2222import { getProgramById } from '../program/program.js' ;
2323import { Linter } from 'eslint' ;
2424import { JsTsLanguage } from '../../../shared/src/helpers/language.js' ;
@@ -34,59 +34,59 @@ import { getContext } from '../../../shared/src/helpers/context.js';
3434 * @param language the language of the input
3535 * @returns the parsed source code
3636 */
37- export function buildSourceCode ( input : JsTsAnalysisInput , language : JsTsLanguage ) {
37+ export function build ( input : JsTsAnalysisInput , language : JsTsLanguage ) {
3838 const vueFile = isVueFile ( input . filePath ) ;
3939
40+ let parser : Parser = vueFile ? parsersMap . vuejs : parsersMap . typescript ;
4041 if ( shouldUseTypescriptParser ( language ) ) {
4142 const options : Linter . ParserOptions = {
4243 // enable logs for @typescript -eslint
4344 // debugLevel: true,
4445 filePath : input . filePath ,
45- parser : vueFile ? parsers . typescript : undefined ,
46+ parser : vueFile ? parsersMap . typescript : undefined ,
4647 } ;
47- const parser = vueFile ? parsers . vuejs : parsers . typescript ;
4848 if ( ! vueFile ) {
4949 options . programs = input . programId && [ getProgramById ( input . programId ) ] ;
5050 options . project = input . tsConfigs ;
5151 }
5252 try {
53- debug ( `Parsing ${ input . filePath } with ${ parser . parser } ` ) ;
54- return parseForESLint ( input . fileContent , parser . parse , buildParserOptions ( options , false ) ) ;
53+ debug ( `Parsing ${ input . filePath } with ${ parser . meta . name } ` ) ;
54+ return parse ( input . fileContent , parser , buildParserOptions ( options , false ) ) ;
5555 } catch ( error ) {
56- debug ( `Failed to parse ${ input . filePath } with TypeScript parser: ${ error . message } ` ) ;
56+ debug ( `Failed to parse ${ input . filePath } with ${ parser . meta . name } : ${ error . message } ` ) ;
5757 if ( language === 'ts' ) {
5858 throw error ;
5959 }
6060 }
6161 }
6262
6363 let moduleError ;
64+ parser = vueFile ? parsersMap . vuejs : parsersMap . javascript ;
6465 try {
65- const parser = vueFile ? parsers . vuejs : parsers . javascript ;
66- debug ( `Parsing ${ input . filePath } with ${ parser . parser } ` ) ;
67- return parseForESLint (
66+ debug ( `Parsing ${ input . filePath } with ${ parser . meta ?. name } ` ) ;
67+ return parse (
6868 input . fileContent ,
69- parser . parse ,
70- buildParserOptions ( { parser : vueFile ? parsers . javascript : undefined } , true ) ,
69+ parser ,
70+ buildParserOptions ( { parser : vueFile ? parsersMap . javascript : undefined } , true ) ,
7171 ) ;
7272 } catch ( error ) {
73- debug ( `Failed to parse ${ input . filePath } with Javascript parser: ${ error . message } ` ) ;
73+ debug ( `Failed to parse ${ input . filePath } with ${ parser . meta ?. name } : ${ error . message } ` ) ;
7474 if ( vueFile ) {
7575 throw error ;
7676 }
7777 moduleError = error ;
7878 }
7979
8080 try {
81- debug ( `Parsing ${ input . filePath } with Javascript parser in 'script' mode` ) ;
82- return parseForESLint (
81+ debug ( `Parsing ${ input . filePath } with ${ parsersMap . javascript . meta ?. name } in 'script' mode` ) ;
82+ return parse (
8383 input . fileContent ,
84- parsers . javascript . parse ,
84+ parsersMap . javascript ,
8585 buildParserOptions ( { sourceType : 'script' } , true ) ,
8686 ) ;
8787 } catch ( error ) {
8888 debug (
89- `Failed to parse ${ input . filePath } with Javascript parser in 'script' mode: ${ error . message } ` ,
89+ `Failed to parse ${ input . filePath } with ${ parsersMap . javascript . meta ?. name } in 'script' mode: ${ error . message } ` ,
9090 ) ;
9191 /**
9292 * We prefer displaying parsing error as module if parsing as script also failed,
0 commit comments