@@ -6,7 +6,8 @@ import type { MangleUserConfig } from '@tailwindcss-mangle/config'
6
6
import { sort } from 'fast-sort'
7
7
import defu from 'defu'
8
8
import AhoCorasick from 'modern-ahocorasick'
9
- import { createGlobMatcher , defaultMangleClassFilter } from '@/utils'
9
+ import { createGlobMatcher , defaultMangleClassFilter , escapeStringRegexp } from '@/utils'
10
+
10
11
export class Context {
11
12
options : MangleUserConfig
12
13
includeMatcher : ( file : string ) => boolean
@@ -18,6 +19,7 @@ export class Context {
18
19
useAC : boolean
19
20
preserveFunctionSet : Set < string >
20
21
preserveClassNamesSet : Set < string >
22
+ preserveFunctionRegexs : RegExp [ ]
21
23
constructor ( opts : MangleUserConfig = { } ) {
22
24
this . options = opts // defu(opts, getDefaultMangleUserConfig())
23
25
this . classSet = new Set ( )
@@ -28,6 +30,9 @@ export class Context {
28
30
this . useAC = false
29
31
this . preserveFunctionSet = new Set ( opts . preserveFunction )
30
32
this . preserveClassNamesSet = new Set ( )
33
+ this . preserveFunctionRegexs = [ ...this . preserveFunctionSet . values ( ) ] . map ( ( x ) => {
34
+ return new RegExp ( escapeStringRegexp ( x ) + '\\(([^)]*)\\)' , 'g' )
35
+ } )
31
36
}
32
37
33
38
isPreserveClass ( className : string ) {
@@ -139,4 +144,6 @@ export class Context {
139
144
}
140
145
return config
141
146
}
147
+
148
+ // ["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
142
149
}
0 commit comments