11import { logger } from '@rsbuild/core' ;
22import color from 'picocolors' ;
3- import type { ECMASyntaxError , EcmaVersion } from './types.js' ;
4-
5- type Error = {
6- source : string ;
7- output ?: string ;
8- reason : string ;
9- code : string ;
10- } ;
3+ import type {
4+ ECMASyntaxError ,
5+ EcmaVersion ,
6+ SyntaxErrorInfo ,
7+ SyntaxErrorKey ,
8+ } from './types.js' ;
119
1210export function printErrors (
1311 errors : ECMASyntaxError [ ] ,
1412 ecmaVersion : EcmaVersion ,
13+ excludeErrorLogs : SyntaxErrorKey [ ] ,
1514) : void {
1615 if ( errors . length === 0 ) {
1716 logger . success ( '[@rsbuild/plugin-check-syntax] Syntax check passed.' ) ;
1817 return ;
1918 }
2019
21- const errs : Error [ ] = errors . map ( ( error ) => ( {
20+ const errs : SyntaxErrorInfo [ ] = errors . map ( ( error ) => ( {
2221 source : `${ error . source . path } :${ error . source . line } :${ error . source . column } ` ,
2322 output : error . output
2423 ? `${ error . output . path } :${ error . output . line } :${ error . output . column } `
@@ -36,7 +35,7 @@ export function printErrors(
3635
3736 errs . forEach ( ( err , index ) => {
3837 console . log ( color . bold ( color . red ( ` ERROR ${ index + 1 } ` ) ) ) ;
39- printMain ( err , longest ) ;
38+ printMain ( err , longest , excludeErrorLogs ) ;
4039 } ) ;
4140
4241 throw new Error (
@@ -48,7 +47,11 @@ export function printErrors(
4847 ) ;
4948}
5049
51- function printMain ( error : Error , longest : number ) {
50+ function printMain (
51+ error : SyntaxErrorInfo ,
52+ longest : number ,
53+ excludeErrorLogs : SyntaxErrorKey [ ] ,
54+ ) {
5255 const fillWhiteSpace = ( s : string , longest : number ) => {
5356 if ( s . length < longest ) {
5457 const rightPadding = ' ' . repeat ( longest - s . length ) ;
@@ -58,7 +61,7 @@ function printMain(error: Error, longest: number) {
5861 } ;
5962
6063 for ( const [ key , content ] of Object . entries ( error ) ) {
61- if ( ! content ) {
64+ if ( ! content || excludeErrorLogs . includes ( key as SyntaxErrorKey ) ) {
6265 continue ;
6366 }
6467 const title = color . magenta ( `${ fillWhiteSpace ( `${ key } :` , longest + 1 ) } ` ) ;
0 commit comments