@@ -5,8 +5,8 @@ import { generateError } from './generateError.js';
55import { generateHtmlScripts } from './generateHtmlScripts.js' ;
66import type {
77 AcornParseError ,
8+ CheckSyntaxOptions as BaseCheckSyntaxOptions ,
89 CheckSyntaxExclude ,
9- CheckSyntaxOptions ,
1010 ECMASyntaxError ,
1111 EcmaVersion ,
1212 SyntaxErrorKey ,
@@ -16,12 +16,19 @@ import { checkIsExclude } from './utils.js';
1616const HTML_REGEX = / \. h t m l $ / ;
1717export const JS_REGEX : RegExp = / \. (?: j s | m j s | c j s | j s x ) $ / ;
1818
19+ type CheckSyntaxOptions = BaseCheckSyntaxOptions & {
20+ rootPath ?: string ;
21+ } & (
22+ | Required < Pick < BaseCheckSyntaxOptions , 'targets' > >
23+ | Required < Pick < BaseCheckSyntaxOptions , 'ecmaVersion' > >
24+ ) ;
25+
1926export class CheckSyntax {
2027 errors : ECMASyntaxError [ ] = [ ] ;
2128
2229 ecmaVersion : EcmaVersion ;
2330
24- targets : string [ ] ;
31+ targets ? : string [ ] ;
2532
2633 rootPath : string ;
2734
@@ -31,27 +38,24 @@ export class CheckSyntax {
3138
3239 excludeErrorLogs : SyntaxErrorKey [ ] ;
3340
34- constructor (
35- options : CheckSyntaxOptions &
36- Required < Pick < CheckSyntaxOptions , 'targets' > > & {
37- rootPath : string ;
38- } ,
39- ) {
41+ constructor ( options : CheckSyntaxOptions ) {
4042 if ( ! options ) {
4143 throw new Error ( '[CheckSyntaxRspackPlugin] `options` is required.' ) ;
4244 }
43- if ( ! options . targets && ! options . ecmaVersion ) {
45+
46+ const { targets, ecmaVersion } = options ;
47+ if ( ! targets && ! ecmaVersion ) {
4448 throw new Error (
4549 '[CheckSyntaxRspackPlugin] `targets` or `ecmaVersion` option is required' ,
4650 ) ;
4751 }
4852
49- this . targets = options . targets ;
53+ this . targets = targets ;
54+ this . ecmaVersion = ecmaVersion || browserslistToESVersion ( targets ) ;
55+
5056 this . exclude = options . exclude ;
5157 this . excludeOutput = options . excludeOutput ;
52- this . rootPath = options . rootPath ;
53- this . ecmaVersion =
54- options . ecmaVersion || browserslistToESVersion ( this . targets ) ;
58+ this . rootPath = options . rootPath || '' ;
5559 this . excludeErrorLogs = options . excludeErrorLogs || [ ] ;
5660 }
5761
0 commit comments