1
1
import { ConfigUtils } from './config-utils'
2
2
import { IMPORTANT_MODIFIER , sortModifiers } from './parse-class-name'
3
3
4
+ const SPLIT_CLASSES_REGEX = / \s + /
5
+
4
6
export const mergeClassList = ( classList : string , configUtils : ConfigUtils ) => {
5
7
const { parseClassName, getClassGroupId, getConflictingClassGroupIds } = configUtils
6
8
@@ -12,23 +14,12 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
12
14
* @example 'md:!pr'
13
15
*/
14
16
const classGroupsInConflict : string [ ] = [ ]
17
+ const classNames = classList . trim ( ) . split ( SPLIT_CLASSES_REGEX )
15
18
16
19
let result = ''
17
- let index = classList . length - 1
18
-
19
- while ( index >= 0 ) {
20
- while ( classList [ index ] === ' ' ) {
21
- index -= 1
22
- }
23
-
24
- if ( index < 0 ) {
25
- break
26
- }
27
-
28
- const nextIndex = classList . lastIndexOf ( ' ' , index )
29
- const originalClassName = classList . slice ( nextIndex + 1 , index + 1 )
30
20
31
- index = nextIndex
21
+ for ( let index = classNames . length - 1 ; index >= 0 ; index -= 1 ) {
22
+ const originalClassName = classNames [ index ] !
32
23
33
24
const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } =
34
25
parseClassName ( originalClassName )
@@ -42,13 +33,15 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
42
33
43
34
if ( ! classGroupId ) {
44
35
if ( ! hasPostfixModifier ) {
36
+ // Not a Tailwind class
45
37
result = originalClassName + ( result . length > 0 ? ' ' + result : result )
46
38
continue
47
39
}
48
40
49
41
classGroupId = getClassGroupId ( baseClassName )
50
42
51
43
if ( ! classGroupId ) {
44
+ // Not a Tailwind class
52
45
result = originalClassName + ( result . length > 0 ? ' ' + result : result )
53
46
continue
54
47
}
@@ -65,6 +58,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
65
58
const classId = modifierId + classGroupId
66
59
67
60
if ( classGroupsInConflict . includes ( classId ) ) {
61
+ // Tailwind class omitted due to conflict
68
62
continue
69
63
}
70
64
@@ -76,6 +70,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
76
70
classGroupsInConflict . push ( modifierId + group )
77
71
}
78
72
73
+ // Tailwind class not in conflict
79
74
result = originalClassName + ( result . length > 0 ? ' ' + result : result )
80
75
}
81
76
0 commit comments