Skip to content

Commit 5487955

Browse files
authored
Delete unused data attributes (#19)
1 parent 06342a1 commit 5487955

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ function extractStyles(styles, ast) {
128128
return false;
129129
}
130130

131+
if (selector.includes('[data-') && !selector.includes('[data-color-mode')) {
132+
return false;
133+
}
134+
131135
const tag = selector.match(/^\w[-\w]+/);
132136
if (tag && !ALLOW_TAGS.has(tag[0])) {
133137
return false;
@@ -154,6 +158,10 @@ function extractStyles(styles, ast) {
154158
return selector.slice(5);
155159
}
156160

161+
if (selector.startsWith(':root ')) {
162+
return selector.slice(6);
163+
}
164+
157165
return selector;
158166
}
159167

@@ -174,7 +182,7 @@ function extractStyles(styles, ast) {
174182
function classifyRules(rules) {
175183
function extractTheme(rule) {
176184
for (const selector of rule.selectors) {
177-
const match = /-theme\*=(\w+)/.exec(selector);
185+
const match = /(?:-theme\*|data-color-mode)=(\w+)/.exec(selector);
178186
if (match) {
179187
return match[1];
180188
}

0 commit comments

Comments
 (0)