Skip to content

Commit 8a1c1bd

Browse files
committed
Allow progressive enhancement using repeated CSS properties
1 parent e06e7c6 commit 8a1c1bd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/DoIUse.js

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ export default class DoIUse {
8888
if (!data) {
8989
throw new Error('No feature data?');
9090
}
91+
92+
if (usage.type === 'decl') {
93+
// If there is a previous sibling declaration of the same CSS
94+
// property, don’t treat it as an error, because browser will
95+
// fall back to use last declaration it understood.
96+
97+
const previousSiblings = usage.parent.nodes.slice(0, usage.parent.nodes.indexOf(usage));
98+
const overwritees = previousSiblings.filter(
99+
(node) => node.type === 'decl' && node.prop === usage.prop,
100+
);
101+
if (overwritees.length > 0) {
102+
return;
103+
}
104+
}
105+
91106
const messages = [];
92107
if (data.missing) {
93108
messages.push(`not supported by: ${data.missing}`);
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test } from 'tap';
2+
import postcss from 'postcss';
3+
4+
import DoIUse from '../lib/DoIUse.js';
5+
6+
test('Progressive enhancement using repeated CSS properties', (t) => {
7+
const css = `
8+
p {
9+
background-color: black;
10+
background-color: rgba(0, 0, 0, 0.5);
11+
}
12+
`;
13+
14+
const result = postcss(new DoIUse({
15+
browsers: ['ie >= 6'],
16+
})).process(css);
17+
const warnings = result.warnings();
18+
19+
t.equal(warnings.length, 0, 'No warnings');
20+
21+
t.end();
22+
});

0 commit comments

Comments
 (0)