Skip to content

Commit 37339ce

Browse files
committed
accept multiline input again
1 parent 15c741f commit 37339ce

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/lib/merge-classlist.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ConfigUtils } from './config-utils'
22
import { IMPORTANT_MODIFIER, sortModifiers } from './parse-class-name'
33

4+
const SPLIT_CLASSES_REGEX = /\s+/
5+
46
export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
57
const { parseClassName, getClassGroupId, getConflictingClassGroupIds } = configUtils
68

@@ -12,23 +14,12 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
1214
* @example 'md:!pr'
1315
*/
1416
const classGroupsInConflict: string[] = []
17+
const classNames = classList.trim().split(SPLIT_CLASSES_REGEX)
1518

1619
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)
3020

31-
index = nextIndex
21+
for (let index = classNames.length - 1; index >= 0; index -= 1) {
22+
const originalClassName = classNames[index]!
3223

3324
const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } =
3425
parseClassName(originalClassName)
@@ -42,13 +33,15 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
4233

4334
if (!classGroupId) {
4435
if (!hasPostfixModifier) {
36+
// Not a Tailwind class
4537
result = originalClassName + (result.length > 0 ? ' ' + result : result)
4638
continue
4739
}
4840

4941
classGroupId = getClassGroupId(baseClassName)
5042

5143
if (!classGroupId) {
44+
// Not a Tailwind class
5245
result = originalClassName + (result.length > 0 ? ' ' + result : result)
5346
continue
5447
}
@@ -65,6 +58,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
6558
const classId = modifierId + classGroupId
6659

6760
if (classGroupsInConflict.includes(classId)) {
61+
// Tailwind class omitted due to conflict
6862
continue
6963
}
7064

@@ -76,6 +70,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
7670
classGroupsInConflict.push(modifierId + group)
7771
}
7872

73+
// Tailwind class not in conflict
7974
result = originalClassName + (result.length > 0 ? ' ' + result : result)
8075
}
8176

0 commit comments

Comments
 (0)