summaryrefslogtreecommitdiff
path: root/node_modules/svgo/plugins/removeComments.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-12-21 22:46:53 +0800
commitf06956efd2dc4bf77244a9fcce2b883a00b925af (patch)
tree0123cb73ce67f1f4b17e1d6cbabff076ee44e31b /node_modules/svgo/plugins/removeComments.js
parent8d980c13970c15b6d2312b6fc4ac51698dd0d220 (diff)
updated node modules
Diffstat (limited to 'node_modules/svgo/plugins/removeComments.js')
-rw-r--r--node_modules/svgo/plugins/removeComments.js28
1 files changed, 25 insertions, 3 deletions
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
@@ -6,6 +6,12 @@ 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.
*
* @example
@@ -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);
},
},
};