From f06956efd2dc4bf77244a9fcce2b883a00b925af Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 21 Dec 2023 22:46:53 +0800 Subject: updated node modules --- node_modules/svgo/plugins/removeComments.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'node_modules/svgo/plugins/removeComments.js') diff --git a/node_modules/svgo/plugins/removeComments.js b/node_modules/svgo/plugins/removeComments.js index 70e46271..67f8efd1 100644 --- a/node_modules/svgo/plugins/removeComments.js +++ b/node_modules/svgo/plugins/removeComments.js @@ -5,6 +5,12 @@ const { detachNodeFromParent } = require('../lib/xast.js'); exports.name = 'removeComments'; exports.description = 'removes comments'; +/** + * If a comment matches one of the following patterns, it will be + * preserved by default. Particularly for copyright/license information. + */ +const DEFAULT_PRESERVE_PATTERNS = [/^!/]; + /** * Remove comments. * @@ -16,13 +22,29 @@ exports.description = 'removes comments'; * * @type {import('./plugins-types').Plugin<'removeComments'>} */ -exports.fn = () => { +exports.fn = (_root, params) => { + const { preservePatterns = DEFAULT_PRESERVE_PATTERNS } = params; + return { comment: { enter: (node, parentNode) => { - if (node.value.charAt(0) !== '!') { - detachNodeFromParent(node, parentNode); + if (preservePatterns) { + if (!Array.isArray(preservePatterns)) { + throw Error( + `Expected array in removeComments preservePatterns parameter but received ${preservePatterns}` + ); + } + + const matches = preservePatterns.some((pattern) => { + return new RegExp(pattern).test(node.value); + }); + + if (matches) { + return; + } } + + detachNodeFromParent(node, parentNode); }, }, }; -- cgit v1.2.3