Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dolanmiu committed Jul 11, 2024
1 parent c846517 commit 002ac6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/postcss/state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("persistTailwindClassNames", () => {

persistTailwindClassNames(["[&:not(:first-child)]:border-t"]);
expect(getTailwindClassNames()).toEqual(
new Set(["test", "[&:not(:first-child)]:border-t"]),
new Set(["test", "[&:not(:first-child)]:border-t"])
);

persistTailwindClassNames(["focus\\:outline-none:focus"]);
Expand All @@ -23,7 +23,18 @@ describe("persistTailwindClassNames", () => {
"[&:not(:first-child)]:border-t",
"focus:outline-none",
"focus:outline-none:focus",
]),
])
);

persistTailwindClassNames(["focus\\:ring-0"]);
expect(getTailwindClassNames()).toEqual(
new Set([
"test",
"[&:not(:first-child)]:border-t",
"focus:outline-none",
"focus:outline-none:focus",
"focus:ring-0",
])
);
});
});
4 changes: 2 additions & 2 deletions src/postcss/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const persistTailwindClassNames = (classes: string[]): void => {
globalState.tailwindClassNames.add(item);
} else {
// Case where it is a pseudo class like focus:
const [matches] = [...(unEscaped.matchAll(/^([a-z]+):/g) ?? [])];
const [matches] = [...unEscaped.matchAll(/^([a-z]+):/g)];

if (matches && matches[1]) {
const re = new RegExp(`(${matches[1]}:.+):${matches[1]}`, "gi");
const [newMatches] = [...(unEscaped.matchAll(re) ?? [])];
const [newMatches] = [...unEscaped.matchAll(re)];
if (newMatches && newMatches[1]) {
globalState.tailwindClassNames.add(newMatches[1]);
}
Expand Down

0 comments on commit 002ac6f

Please sign in to comment.