Skip to content

Commit

Permalink
chore: move docs and use optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Nov 7, 2023
1 parent 0f3b671 commit 5b192ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/svgo/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 23 additions & 5 deletions plugins/plugins-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
usePseudos?: Array<string>;
/**
* 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;
Expand All @@ -89,21 +107,21 @@ 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
* - 'first-exclamation' – remove every comment except first one
* - false – remove all comments
* @default true
*/
comments?: string | boolean | undefined;
comments?: string | boolean;
/**
* Advanced optimizations
*/
Expand Down
8 changes: 2 additions & 6 deletions plugins/removeUnknownsAndDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 5b192ad

Please sign in to comment.