Skip to content

Commit 2350a29

Browse files
authored
case insensitive matching (#517)
1 parent 900f867 commit 2350a29

16 files changed

+53
-24
lines changed

plugins/css-blank-pseudo/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
more efficient and also does less work at the MutationObserver handler.
77
- Breaking: removed old CDN urls
88
- Breaking: removed old CLI
9+
- Fix case insensitive matching.
910

1011
#### How to migrate:
1112

plugins/css-blank-pseudo/src/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
3131
return {
3232
postcssPlugin: 'css-blank-pseudo',
3333
Rule: (rule, { result }) => {
34-
if (rule.selector.indexOf(':blank') === -1) {
34+
if (rule.selector.toLowerCase().indexOf(':blank') === -1) {
3535
return;
3636
}
3737

3838
let modifiedSelector;
3939
try {
4040
const modifiedSelectorAST = parser((selectors) => {
4141
selectors.walkPseudos((selector) => {
42-
if (selector.value !== ':blank') {
42+
if (selector.value.toLowerCase() !== ':blank') {
4343
return;
4444
}
4545

@@ -66,12 +66,10 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
6666
return;
6767
}
6868

69-
const clone = rule.clone({ selector: modifiedSelector });
69+
rule.cloneBefore({ selector: modifiedSelector });
7070

71-
if (options.preserve) {
72-
rule.before(clone);
73-
} else {
74-
rule.replaceWith(clone);
71+
if (!options.preserve) {
72+
rule.remove();
7573
}
7674
},
7775
};

plugins/css-blank-pseudo/test/basic.css

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ test :matches(test :blank :blank test) test {
3333
test:not(:blank) {
3434
order: 5;
3535
}
36+
37+
uppercase :BLaNK {
38+
order: 6;
39+
}

plugins/css-blank-pseudo/test/basic.expect.css

+8
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ test:not([blank]) {
5757
test:not(:blank) {
5858
order: 5;
5959
}
60+
61+
uppercase [blank] {
62+
order: 6;
63+
}
64+
65+
uppercase :BLaNK {
66+
order: 6;
67+
}

plugins/css-blank-pseudo/test/basic.preserve.expect.css

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ test :matches(test [blank] [blank] test) test {
3232
test:not([blank]) {
3333
order: 5;
3434
}
35+
36+
uppercase [blank] {
37+
order: 6;
38+
}

plugins/css-blank-pseudo/test/basic.replacewith.expect.css

+8
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ test:not(.css-blank) {
5757
test:not(:blank) {
5858
order: 5;
5959
}
60+
61+
uppercase .css-blank {
62+
order: 6;
63+
}
64+
65+
uppercase :BLaNK {
66+
order: 6;
67+
}

plugins/css-blank-pseudo/test/basic.wrong-replacewith.expect.css

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ test :matches(test :blank :blank test) test {
3333
test:not(:blank) {
3434
order: 5;
3535
}
36+
37+
uppercase :BLaNK {
38+
order: 6;
39+
}

plugins/css-has-pseudo/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Added: 'forcePolyfill' options for browser polyfill
1111
- Added: Rules within `@supports selector(:has(something))` won't be transformed.
1212
- Fix: Use base36 encoding to support all possible selectors.
13+
- Fix: case insensitive matching.
1314

1415
#### How to migrate :
1516

plugins/css-has-pseudo/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
1818
return {
1919
postcssPlugin: 'css-has-pseudo-experimental',
2020
RuleExit: (rule, { result }) => {
21-
if (!rule.selector.includes(':has(') || isWithinSupportCheck(rule)) {
21+
if (!rule.selector.toLowerCase().includes(':has(') || isWithinSupportCheck(rule)) {
2222
return;
2323
}
2424

2525
const selectors = rule.selectors.map((selector) => {
26-
if (!selector.includes(':has(')) {
26+
if (!selector.toLowerCase().includes(':has(')) {
2727
return selector;
2828
}
2929

@@ -41,7 +41,7 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
4141

4242
let containsHasPseudo = false;
4343
selectorAST.walkPseudos((node) => {
44-
containsHasPseudo = containsHasPseudo || (node.value === ':has' && node.nodes);
44+
containsHasPseudo = containsHasPseudo || (node.value.toLowerCase() === ':has' && node.nodes);
4545

4646
// see : https://bugs.chromium.org/p/chromium/issues/detail?id=669058#c34
4747
// When we have ':has(:visited) {...}', the subject elements of the rule
@@ -51,15 +51,15 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
5151
// selector does not match if it is inside the ':has()' argument selector.
5252
// So if a ':has()' argument selector requires a matching ':visited', the
5353
// style rule are not applied.
54-
if (node.value === ':visited') {
54+
if (node.value.toLowerCase() === ':visited') {
5555
// We can't leave `:has` untouched as that might cause broken selector lists.
5656
// Replacing with the specificity matching name as this should never match anything without `:not()`.
5757
node.replaceWith(parser.className({
5858
value: options.specificityMatchingName,
5959
}));
6060
}
6161

62-
if (node.value === ':any-link') {
62+
if (node.value.toLowerCase() === ':any-link') {
6363
// we can transform `:any-link` to `:link` as this is allowed
6464
node.value = ':link';
6565
}

plugins/css-has-pseudo/src/is-guarded-by-at-supports.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import valueParser from 'postcss-value-parser';
22
import selectorParser from 'postcss-selector-parser';
33

44
export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string): boolean {
5-
if (!atSupportsParams.includes(':has(')) {
5+
if (!atSupportsParams.toLowerCase().includes(':has(')) {
66
return false;
77
}
88

@@ -13,7 +13,7 @@ export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string):
1313

1414
const ast = valueParser(atSupportsParams);
1515
ast.walk((node) => {
16-
if (node.type === 'function' && node.value === 'selector') {
16+
if (node.type === 'function' && node.value.toLowerCase() === 'selector') {
1717
selectors.add(valueParser.stringify(node.nodes));
1818
return false;
1919
}
@@ -33,7 +33,7 @@ export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string):
3333
}
3434

3535
export function selectorContainsHasPseudo(selector: string): boolean {
36-
if (!selector.includes(':has(')) {
36+
if (!selector.toLowerCase().includes(':has(')) {
3737
return false;
3838
}
3939

@@ -42,7 +42,7 @@ export function selectorContainsHasPseudo(selector: string): boolean {
4242
try {
4343
const ast = selectorParser().astSync(selector);
4444
ast.walk((node) => {
45-
if (node.type === 'pseudo' && node.value === ':has' && node.nodes && node.nodes.length > 0) {
45+
if (node.type === 'pseudo' && node.value.toLowerCase() === ':has' && node.nodes && node.nodes.length > 0) {
4646
containsHasPseudo = true;
4747
return false;
4848
}

plugins/css-has-pseudo/test/browser.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
color: grey
44
}
55

6-
#d_main:has(#d_checkbox:checked)>#d_subject {
6+
#d_main:HAS(#d_checkbox:checked)>#d_subject {
77
color: red
88
}
99

1010
#d_main:has(#d_option:checked)>#d_subject {
1111
color: red
1212
}
1313

14-
#d_main:has(#d_checkbox:disabled)>#d_subject {
14+
#d_main:hAs(#d_checkbox:disabled)>#d_subject {
1515
color: green
1616
}
1717

plugins/css-has-pseudo/test/browser.expect.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
color: grey
44
}
55

6-
[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
6+
[csstools-has-z-2s-2n-31-2p-2x-32-1m-20-1t-2b-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
77
color: red
88
}
99

1010
[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-33-34-38-2x-33-32-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
1111
color: red
1212
}
1313

14-
[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2s-2x-37-2p-2q-30-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
14+
[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-1t-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2s-2x-37-2p-2q-30-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
1515
color: green
1616
}
1717

plugins/css-prefers-color-scheme/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Breaking: remove `color-depth` queries fallback
99
- Breaking: remove 'no-preference' support as this was dropped from the spec
1010
- Breaking: remove old global object
11+
- Fix: case insensitive matching.
1112

1213
#### How to migrate :
1314

plugins/css-prefers-color-scheme/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
2020
return {
2121
postcssPlugin: 'postcss-prefers-color-scheme',
2222
AtRule: (atRule) => {
23-
if (atRule.name !== 'media') {
23+
if (atRule.name.toLowerCase() !== 'media') {
2424
return;
2525
}
2626

plugins/css-prefers-color-scheme/test/browser.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
}
1212

13-
@media (prefers-color-scheme: light) {
13+
@MEDIA (PREFERS-COLOR-SCHEME: LIGHT) {
1414
#fixture {
1515
color: rgb(255, 192, 203);
1616
}

plugins/css-prefers-color-scheme/test/browser.expect.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
}
1717
}
1818

19-
@media (color: 70318723) {
19+
@MEDIA (color: 70318723) {
2020
#fixture {
2121
color: rgb(255, 192, 203);
2222
}
2323
}
2424

25-
@media (prefers-color-scheme: light) {
25+
@MEDIA (PREFERS-COLOR-SCHEME: LIGHT) {
2626
#fixture {
2727
color: rgb(255, 192, 203);
2828
}

0 commit comments

Comments
 (0)