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

fix: merge-rule before longhand in default preset #886

Open
wants to merge 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cssnano-preset-default/src/index.js
Expand Up @@ -80,9 +80,9 @@ export default function defaultPreset(opts = {}) {
[postcssNormalizeRepeatStyle, options.normalizeRepeatStyle],
[postcssNormalizePositions, options.normalizePositions],
[postcssNormalizeWhitespace, options.normalizeWhitespace],
[postcssMergeLonghand, options.mergeLonghand],
[postcssDiscardDuplicates, options.discardDuplicates],
[postcssMergeRules, options.mergeRules],
[postcssMergeLonghand, options.mergeLonghand],
[postcssDiscardEmpty, options.discardEmpty],
[postcssUniqueSelectors, options.uniqueSelectors],
[cssDeclarationSorter, options.cssDeclarationSorter],
Expand Down
89 changes: 89 additions & 0 deletions packages/cssnano/src/__tests__/issue701.js
@@ -0,0 +1,89 @@
import postcss from 'postcss';
import cssnano from '..';

test('should merge rules before longhand', () => {
const css = `
.foo {
border-color: #cc1f1a;
}

.bar {
border-bottom-width: 1px;
border-style: solid;
border-color: #cc1f1a;
}
`;

return postcss([cssnano])
.process(css, { from: undefined })
.then((result) => {
expect(result.css).toBe(
'.foo{border-color:#cc1f1a}.bar{border-bottom:1px;border-color:#cc1f1a;border-style:solid}'
);
});
});

test('should merge rules before longhand #2', () => {
const css = `
.has-errors .input {
background-color: #fcebea;
border-color: #cc1f1a;
}

.has-errors .checkbox-label {
background-color: #fcebea;
border-color: #cc1f1a;
}

.has-errors .checkbox-inline {
background-color: #fcebea;
border-color: #cc1f1a;
}

.error-banner .field-errors.filled {
width: 100%;
padding: 1.5rem 1.5rem 1rem;
background-color: #fcebea;
border-bottom-width: 1px;
border-style: solid;
border-color: #cc1f1a;
}

.error-banner .field-errors.filled .field-error {
width: 100%;
font-size: .875rem;
color: #22292f;
line-height: 1.5;
margin-bottom: .5rem;
}
`;

return postcss([cssnano])
.process(css, { from: undefined })
.then((result) => {
expect(result.css).toBe(
'.has-errors .checkbox-inline,.has-errors .checkbox-label,.has-errors .input{background-color:#fcebea;border-color:#cc1f1a}.error-banner .field-errors.filled{background-color:#fcebea;border-bottom:1px;border-color:#cc1f1a;border-style:solid;padding:1.5rem 1.5rem 1rem;width:100%}.error-banner .field-errors.filled .field-error{color:#22292f;font-size:.875rem;line-height:1.5;margin-bottom:.5rem;width:100%}'
);
});
});

test('should merge rules before longhand #3', () => {
const css = `
.foo {
border-color: #cc1f1a;
}

.bar {
border-bottom: 1px;
border-color: #cc1f1a;
}
`;

return postcss([cssnano])
.process(css, { from: undefined })
.then((result) => {
expect(result.css).toBe(
'.bar,.foo{border-color:#cc1f1a}.bar{border-bottom:1px}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output according to the issue #701 (comment) is wrong, not sure why it is wrong in the issue as this is the safe merging in my opinion.

according to the issue, it should be

.foo {
  border-color: #cc1f1a;
}

.bar {
  border-bottom: 1px;
  border-color: #cc1f1a;
}

Though I will check this once again, @evilebottnawi thoughts ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is bug, need to fix

);
});
});