Skip to content

Commit

Permalink
fix: Fix including line break
Browse files Browse the repository at this point in the history
  • Loading branch information
sya-ri committed Sep 2, 2024
1 parent b055483 commit aa1472b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rotten-hotels-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"css-var-extract": patch
---

Fix including line break
2 changes: 1 addition & 1 deletion packages/css-var-extract/src/extractCssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const extractCssVars = (css: string): CssVars => {
while (true) {
const root = rootRegex.exec(css);
if (!root) break;
const condition = root[1]?.trim() ?? "";
const condition = root[1]?.trim()?.replace("\n", " ") ?? "";
if (!root[2]) break;
const cssVarRegex = /\s*(--[^;]*):([^;]*);?\n*/g;
while (true) {
Expand Down
12 changes: 12 additions & 0 deletions packages/css-var-extract/tests/extractCssVars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,16 @@ describe("ExtractCssVars", () => {
},
});
});

it.each([
[[":root,", ".light { --primary: #fff }"]],
[[":root, .light", "{ --primary: #fff }"]],
[[":root, .light {", " --primary: #fff }"]],
])("should be extracted including line break", (input) => {
expect(extractCssVars(input.join("\n"))).toEqual({
"--primary": {
":root, .light": "#fff",
},
});
});
});

0 comments on commit aa1472b

Please sign in to comment.