Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow progressive enhancement using repeated CSS properties #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/DoIUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ export default class DoIUse {
if (!data) {
throw new Error('No feature data?');
}

if (usage.type === 'decl') {
// If there is a previous sibling declaration of the same CSS
// property, don’t treat it as an error, because browser will
// fall back to use last declaration it understood.

const previousSiblings = usage.parent.nodes.slice(0, usage.parent.nodes.indexOf(usage));
const overwritees = previousSiblings.filter(
(node) => node.type === 'decl' && node.prop === usage.prop,
);
if (overwritees.length > 0) {
return;
}
}

const messages = [];
if (data.missing) {
messages.push(`not supported by: ${data.missing}`);
Expand Down
22 changes: 22 additions & 0 deletions test/postcss-progressive-enhancement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test } from 'tap';
import postcss from 'postcss';

import DoIUse from '../lib/DoIUse.js';

test('Progressive enhancement using repeated CSS properties', (t) => {
const css = `
p {
background-color: black;
background-color: rgba(0, 0, 0, 0.5);
}
`;

const result = postcss(new DoIUse({
browsers: ['ie >= 6'],
})).process(css);
const warnings = result.warnings();

t.equal(warnings.length, 0, 'No warnings');

t.end();
});
Loading