Skip to content

Commit 43fe42b

Browse files
Fix the issue on the Rust side
1 parent cd8a8f6 commit 43fe42b

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

crates/oxide/src/parser.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,17 @@ impl<'a> Extractor<'a> {
861861
ParseAction::SingleCandidate(candidate)
862862
}
863863
Bracketing::Included(sliceable) | Bracketing::Wrapped(sliceable) => {
864-
let parts = vec![candidate, sliceable];
865-
let parts = parts
866-
.into_iter()
867-
.filter(|v| !v.is_empty())
868-
.collect::<Vec<_>>();
864+
if candidate == sliceable {
865+
ParseAction::SingleCandidate(candidate)
866+
} else {
867+
let parts = vec![candidate, sliceable];
868+
let parts = parts
869+
.into_iter()
870+
.filter(|v| !v.is_empty())
871+
.collect::<Vec<_>>();
869872

870-
ParseAction::MultipleCandidates(parts)
873+
ParseAction::MultipleCandidates(parts)
874+
}
871875
}
872876
}
873877
}
@@ -1185,7 +1189,7 @@ mod test {
11851189
fn bad_003() {
11861190
// TODO: This seems… wrong
11871191
let candidates = run(r"[𕤵:]", false);
1188-
assert_eq!(candidates, vec!["𕤵", "𕤵:"]);
1192+
assert_eq!(candidates, vec!["𕤵", "𕤵:",]);
11891193
}
11901194

11911195
#[test]
@@ -1436,4 +1440,15 @@ mod test {
14361440
.unwrap();
14371441
assert_eq!(result, Some("[.foo_&]:px-[0]"));
14381442
}
1443+
1444+
#[test]
1445+
fn does_not_emit_the_same_slice_multiple_times() {
1446+
let candidates: Vec<_> =
1447+
Extractor::with_positions("<div class=\"flex\"></div>".as_bytes(), Default::default())
1448+
.into_iter()
1449+
.map(|(s, p)| unsafe { (std::str::from_utf8_unchecked(s), p) })
1450+
.collect();
1451+
1452+
assert_eq!(candidates, vec![("div", 1), ("class", 5), ("flex", 12),]);
1453+
}
14391454
}

packages/@tailwindcss-upgrade/src/template/candidates.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,15 @@ import type { DesignSystem } from '../../../tailwindcss/src/design-system'
55

66
export async function extractRawCandidates(
77
content: string,
8-
extension: string,
98
): Promise<{ rawCandidate: string; start: number; end: number }[]> {
109
let scanner = new Scanner({})
11-
let result = scanner.getCandidatesWithPositions({ content, extension })
12-
13-
// Create a map to remove duplicates
14-
let candidatesMap = new Map<string, { rawCandidate: string; start: number; end: number }>()
10+
let result = scanner.getCandidatesWithPositions({ content, extension: 'html' })
1511

12+
let candidates: { rawCandidate: string; start: number; end: number }[] = []
1613
for (let { candidate: rawCandidate, position: start } of result) {
17-
let end = start + rawCandidate.length
18-
candidatesMap.set(`${start}:${end}:${rawCandidate}`, {
19-
rawCandidate,
20-
start,
21-
end,
22-
})
14+
candidates.push({ rawCandidate, start, end: start + rawCandidate.length })
2315
}
24-
25-
return [...candidatesMap.values()]
16+
return candidates
2617
}
2718

2819
export function printCandidate(designSystem: DesignSystem, candidate: Candidate) {

0 commit comments

Comments
 (0)