File tree 2 files changed +25
-10
lines changed
2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,14 @@ export default defineConfig({
12
12
'electron' ,
13
13
] ,
14
14
plugins : [
15
- alias ( [ {
16
- find : '@common' ,
17
- replacement : path . join ( __dirname , 'common' ) ,
18
- } ] ) ,
15
+ alias (
16
+ [
17
+ { find : '@common' , replacement : path . join ( __dirname , 'common' ) } ,
18
+ ] ,
19
+ {
20
+ acornOptions : { ecmaVersion : 2022 } ,
21
+ } ,
22
+ ) ,
19
23
] ,
20
24
} ) ] ,
21
25
} )
Original file line number Diff line number Diff line change @@ -18,10 +18,15 @@ export interface AliasNode {
18
18
}
19
19
}
20
20
21
- export function alias ( options : {
22
- find : string | RegExp
23
- replacement : string
24
- } [ ] ) : Plugin {
21
+ export function alias (
22
+ aliases : {
23
+ find : string | RegExp
24
+ replacement : string
25
+ } [ ] ,
26
+ options ?: {
27
+ acornOptions ?: Partial < import ( 'acorn' ) . Options >
28
+ } ,
29
+ ) : Plugin {
25
30
let acorn : typeof import ( 'acorn' )
26
31
return {
27
32
name : 'plugin-alias' ,
@@ -34,7 +39,13 @@ export function alias(options: {
34
39
throw new Error ( '[plugin/alias] dependency "acorn". Did you install it?' )
35
40
}
36
41
37
- const ast = acorn . parse ( code , { ecmaVersion : 2020 } ) // acorn7.x Last supported 2020
42
+ const ast = acorn . parse (
43
+ code ,
44
+ Object . assign ( {
45
+ // acorn7.x Last supported 2020
46
+ ecmaVersion : 2020
47
+ } , options ?. acornOptions ) ,
48
+ )
38
49
const ms = new MagicString ( code )
39
50
const nodes : AliasNode [ ] = [ ]
40
51
@@ -82,7 +93,7 @@ export function alias(options: {
82
93
} = node
83
94
84
95
const source = importee . raw . slice ( 1 , - 1 )
85
- const option = options . find ( opt => opt . find instanceof RegExp
96
+ const option = aliases . find ( opt => opt . find instanceof RegExp
86
97
? opt . find . test ( source )
87
98
: source . startsWith ( opt . find + '/' ) )
88
99
if ( ! option ) continue
You can’t perform that action at this time.
0 commit comments