From 5b192adbb40e66745a68224df2ccad9effcb589f Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Tue, 7 Nov 2023 22:39:34 +0000 Subject: [PATCH] chore: move docs and use optional chaining --- lib/svgo/plugins.js | 2 +- plugins/plugins-types.ts | 28 +++++++++++++++++++++++----- plugins/removeUnknownsAndDefaults.js | 8 ++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/svgo/plugins.js b/lib/svgo/plugins.js index 5719d1633..efeb01b14 100644 --- a/lib/svgo/plugins.js +++ b/lib/svgo/plugins.js @@ -14,7 +14,7 @@ const { visit } = require('../xast.js'); */ const invokePlugins = (ast, info, plugins, overrides, globalOverrides) => { for (const plugin of plugins) { - const override = overrides == null ? null : overrides[plugin.name]; + const override = overrides?.[plugin.name]; if (override === false) { continue; } diff --git a/plugins/plugins-types.ts b/plugins/plugins-types.ts index daf5ff0ad..a3f8852f0 100644 --- a/plugins/plugins-types.ts +++ b/plugins/plugins-types.ts @@ -73,10 +73,28 @@ type DefaultPlugins = { }; mergeStyles: void; inlineStyles: { + /** + * Inlines selectors that match once only. + * + * @default true + */ onlyMatchedOnce?: boolean; + /** + * Clean up matched selectors. Unused selects are left as-is. + * + * @default true + */ removeMatchedSelectors?: boolean; - useMqs?: Array; - usePseudos?: Array; + /** + * Media queries to use. An empty string indicates all selectors outside of + * media queries. + */ + useMqs?: string[]; + /** + * Pseudo-classes and elements to use. An empty string indicates all + * all non-pseudo-classes and elements. + */ + usePseudos?: string[]; }; mergePaths: { force?: boolean; @@ -89,13 +107,13 @@ type DefaultPlugins = { * Disable or enable a structure optimisations. * @default true */ - restructure?: boolean | undefined; + restructure?: boolean; /** * Enables merging of @media rules with the same media query by splitted by other rules. * The optimisation is unsafe in general, but should work fine in most cases. Use it on your own risk. * @default false */ - forceMediaMerge?: boolean | undefined; + forceMediaMerge?: boolean; /** * Specify what comments to leave: * - 'exclamation' or true – leave all exclamation comments @@ -103,7 +121,7 @@ type DefaultPlugins = { * - false – remove all comments * @default true */ - comments?: string | boolean | undefined; + comments?: string | boolean; /** * Advanced optimizations */ diff --git a/plugins/removeUnknownsAndDefaults.js b/plugins/removeUnknownsAndDefaults.js index c67845cd5..410b36554 100644 --- a/plugins/removeUnknownsAndDefaults.js +++ b/plugins/removeUnknownsAndDefaults.js @@ -182,16 +182,12 @@ exports.fn = (root, params) => { attributesDefaults.get(name) === value ) { // keep defaults if parent has own or inherited style - if ( - computedParentStyle == null || - computedParentStyle[name] == null - ) { + if (computedParentStyle?.[name] == null) { delete node.attributes[name]; } } if (uselessOverrides && node.attributes.id == null) { - const style = - computedParentStyle == null ? null : computedParentStyle[name]; + const style = computedParentStyle?.[name]; if ( presentationNonInheritableGroupAttrs.includes(name) === false && style != null &&