diff --git a/lib/svgo.test.js b/lib/svgo.test.js index de849ea9f..9513d5a1f 100644 --- a/lib/svgo.test.js +++ b/lib/svgo.test.js @@ -368,7 +368,6 @@ test('multipass option should trigger plugins multiple times', () => { * @type {Plugin} */ const testPlugin = { - type: 'visitor', name: 'testPlugin', fn: (_root, _params, info) => { list.push(info.multipassCount); diff --git a/lib/svgo/plugins.js b/lib/svgo/plugins.js index 54cd2580f..4eec940fe 100644 --- a/lib/svgo/plugins.js +++ b/lib/svgo/plugins.js @@ -20,23 +20,10 @@ const invokePlugins = (ast, info, plugins, overrides, globalOverrides) => { } const params = { ...plugin.params, ...globalOverrides, ...override }; - if (plugin.type === 'perItem') { - ast = perItem(ast, info, plugin, params); - } - if (plugin.type === 'perItemReverse') { - ast = perItem(ast, info, plugin, params, true); - } - if (plugin.type === 'full') { - if (plugin.active) { - ast = plugin.fn(ast, params, info); - } - } - if (plugin.type === 'visitor') { - if (plugin.active) { - const visitor = plugin.fn(ast, params, info); - if (visitor != null) { - visit(ast, visitor); - } + if (plugin.active) { + const visitor = plugin.fn(ast, params, info); + if (visitor != null) { + visit(ast, visitor); } } } @@ -44,38 +31,6 @@ const invokePlugins = (ast, info, plugins, overrides, globalOverrides) => { }; exports.invokePlugins = invokePlugins; -/** - * Direct or reverse per-item loop. - * - * @param {Object} data input data - * @param {Object} info extra information - * @param {Array} plugins plugins list to process - * @param {boolean} [reverse] reverse pass? - * @return {Object} output data - */ -function perItem(data, info, plugin, params, reverse) { - function monkeys(items) { - items.children = items.children.filter(function (item) { - // reverse pass - if (reverse && item.children) { - monkeys(item); - } - // main filter - let kept = true; - if (plugin.active) { - kept = plugin.fn(item, params, info) !== false; - } - // direct pass - if (!reverse && item.children) { - monkeys(item); - } - return kept; - }); - return items; - } - return monkeys(data); -} - const createPreset = ({ name, plugins }) => { return { name, diff --git a/plugins-api.md b/plugins-api.md index 4a55eea06..e4cc79b19 100644 --- a/plugins-api.md +++ b/plugins-api.md @@ -9,7 +9,6 @@ Basic plugin looks like this ```js export const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { // do nothing @@ -33,7 +32,6 @@ Visitor pattern allows to access all nodes in direct order from the root to the ```js const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { return { @@ -74,7 +72,6 @@ All nodes except root also have an access to parentNode ```js const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { return { @@ -97,7 +94,6 @@ To remove node from parent create new array with children ```js const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { return { @@ -115,7 +111,6 @@ Find all circles with specific attribute ```js const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { return { @@ -135,7 +130,6 @@ Collect all elements and analyze later ```js const myPlugin = { - type: 'visitor', name: 'pluginName', fn: () => { const elements = []