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(postcss-reduce-initial): ensure options are always read #1482

Merged
merged 1 commit into from
Mar 23, 2023
Merged
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
14 changes: 14 additions & 0 deletions packages/cssnano/test/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ test('should be able to exclude plugins (exclude syntax)', () => {
});
});

test('should be able to exclude pointer-events plugin', () => {
return cssnano({
preset: [
'default',
{
reduceInitial: { ignore: ['pointer-events'] },
},
],
})
.process('.selector { pointer-events: initial; }', { from: undefined })
.then((result) => {
assert.is(result.css, '.selector{pointer-events:initial}');
});
});
test('should error on a bad preset', async () => {
try {
await postcss([cssnano({ preset: 'avanced' })])
Expand Down
8 changes: 5 additions & 3 deletions packages/postcss-reduce-initial/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const initial = 'initial';

// In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
const defaultIgnoreProps = ['writing-mode', 'transform-box'];
/** @typedef {{ignore?: string[]}} Options */

/**
* @type {import('postcss').PluginCreator<void>}
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} options
* @return {import('postcss').Plugin}
*/
function pluginCreator() {
function pluginCreator(options = {}) {
return {
postcssPlugin: 'postcss-reduce-initial',
/** @param {import('postcss').Result & {opts: browserslist.Options & {ignore?: string[]}}} result */
Expand All @@ -31,7 +33,7 @@ function pluginCreator() {
css.walkDecls((decl) => {
const lowerCasedProp = decl.prop.toLowerCase();
const ignoreProp = new Set(
defaultIgnoreProps.concat(resultOpts.ignore || [])
defaultIgnoreProps.concat(options.ignore || [])
);

if (ignoreProp.has(lowerCasedProp)) {
Expand Down
12 changes: 9 additions & 3 deletions packages/postcss-reduce-initial/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export = pluginCreator;
/** @typedef {{ignore?: string[]}} Options */
/**
* @type {import('postcss').PluginCreator<void>}
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} options
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(): import('postcss').Plugin;
declare function pluginCreator(options?: Options): import('postcss').Plugin;
declare namespace pluginCreator {
const postcss: true;
export { postcss, Options };
}
type Options = {
ignore?: string[];
};
declare var postcss: true;