diff --git a/README.md b/README.md index a8090ea3..4ed5aaea 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,6 @@ Options: --ref forward ref to SVG root element --no-dimensions remove width and height from root SVG tag --no-expand-props disable props expanding - --svg-attributes add attributes to the svg element (deprecated) --svg-props add props to the svg element --replace-attr-values replace an attribute value --template specify a custom template to use diff --git a/packages/cli/README.md b/packages/cli/README.md index ca3ea2d6..c17460f2 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -28,7 +28,6 @@ Options: --ref forward ref to SVG root element --no-dimensions remove width and height from root SVG tag --no-expand-props disable props expanding - --svg-attributes add attributes to the svg element (deprecated) --svg-props add props to the svg element --replace-attr-values replace an attribute value --template specify a custom template to use diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap index e6f928bd..71e3d4b7 100644 --- a/packages/cli/src/__snapshots__/index.test.js.snap +++ b/packages/cli/src/__snapshots__/index.test.js.snap @@ -313,20 +313,6 @@ export default SvgFile " `; -exports[`cli should support various args: --svg-attributes "focusable=false" 1`] = ` -"import React from 'react' - -const SvgFile = props => ( - - - -) - -export default SvgFile - -" -`; - exports[`cli should support various args: --svg-props "hidden={true}" 1`] = ` "import React from 'react' diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js index 44d6b2f0..030f2622 100644 --- a/packages/cli/src/index.js +++ b/packages/cli/src/index.js @@ -54,11 +54,6 @@ program .option('--ref', 'forward ref to SVG root element') .option('--no-dimensions', 'remove width and height from root SVG tag') .option('--no-expand-props', 'disable props expanding') - .option( - '--svg-attributes ', - 'add attributes to the svg element (deprecated)', - parseObject, - ) .option( '--svg-props ', 'add props to the svg element', @@ -146,15 +141,6 @@ async function run() { } } - // TODO remove in v3 - if (program.outDir && program.svgAttributes) { - console.log( - chalk.yellow( - '--svg-attributes option is deprecated an will be removed in v3, please use --svg-props instead', - ), - ) - } - const command = program.outDir ? dirCommand : fileCommand await command(program, filenames, config) } diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js index 1f90a5cc..a588ea7b 100644 --- a/packages/cli/src/index.test.js +++ b/packages/cli/src/index.test.js @@ -126,7 +126,6 @@ describe('cli', () => { ['--native --ref'], ['--ref'], ['--replace-attr-values "#063855=currentColor"'], - ['--svg-attributes "focusable=false"'], [`--svg-props "hidden={true}"`], ['--no-svgo'], ['--no-prettier'], diff --git a/packages/core/src/__snapshots__/convert.test.js.snap b/packages/core/src/__snapshots__/convert.test.js.snap index 2d3de85e..e7a9675f 100644 --- a/packages/core/src/__snapshots__/convert.test.js.snap +++ b/packages/core/src/__snapshots__/convert.test.js.snap @@ -227,27 +227,6 @@ export default SvgComponent " `; -exports[`convert config should support options { svgAttributes: { focusable: false } } 1`] = ` -"import React from 'react' - -const SvgComponent = props => ( - - - - - -) - -export default SvgComponent -" -`; - exports[`convert config should support options { svgo: false } 1`] = ` "import React from 'react' @@ -310,19 +289,6 @@ export default SvgComponent " `; -exports[`convert config svgAttribute 1`] = ` -"import React from 'react' - -const SvgComponent = props => ( - - - -) - -export default SvgComponent -" -`; - exports[`convert config titleProp 1`] = ` "import React from 'react' diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 855cce27..3ea736df 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -10,7 +10,6 @@ export const DEFAULT_CONFIG = { prettierConfig: null, ref: false, replaceAttrValues: null, - svgAttributes: null, svgProps: null, svgo: true, svgoConfig: null, diff --git a/packages/core/src/config.test.js b/packages/core/src/config.test.js index 1779a674..90f92038 100644 --- a/packages/core/src/config.test.js +++ b/packages/core/src/config.test.js @@ -49,7 +49,6 @@ Object { "ref": false, "replaceAttrValues": null, "runtimeConfig": true, - "svgAttributes": null, "svgProps": null, "svgo": true, "svgoConfig": null, @@ -82,7 +81,6 @@ Object { ], ], "runtimeConfig": true, - "svgAttributes": null, "svgProps": null, "svgo": true, "svgoConfig": null, @@ -115,7 +113,6 @@ Object { ], ], "runtimeConfig": true, - "svgAttributes": null, "svgProps": null, "svgo": true, "svgoConfig": null, @@ -149,7 +146,6 @@ Object { ], ], "runtimeConfig": true, - "svgAttributes": null, "svgProps": null, "svgo": true, "svgoConfig": null, diff --git a/packages/core/src/convert.test.js b/packages/core/src/convert.test.js index c95c4925..8cc732c4 100644 --- a/packages/core/src/convert.test.js +++ b/packages/core/src/convert.test.js @@ -220,7 +220,6 @@ describe('convert', () => { [{ native: true, ref: true }], [{ ref: true }], [{ replaceAttrValues: { none: 'black' } }], - [{ svgAttributes: { focusable: false } }], [{ svgo: false }], [{ prettier: false }], [{ template: () => 'nothing' }], @@ -232,14 +231,6 @@ describe('convert', () => { expect(result).toMatchSnapshot() }) - it('svgAttribute', async () => { - const svg = `` - - expect( - await convert(svg, { svgAttribute: { focusable: false } }), - ).toMatchSnapshot() - }) - it('titleProp', async () => { const svg = ` diff --git a/packages/core/src/h2x/__snapshots__/svgAttributes.test.js.snap b/packages/core/src/h2x/__snapshots__/svgAttributes.test.js.snap deleted file mode 100644 index 7e79b49f..00000000 --- a/packages/core/src/h2x/__snapshots__/svgAttributes.test.js.snap +++ /dev/null @@ -1,37 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`svgAttributes should add a new attribute 1`] = ` -" -" -`; - -exports[`svgAttributes should add multiple attributes to svg 1`] = ` -" -" -`; - -exports[`svgAttributes should add one attribute to svg 1`] = ` -" - - - - -" -`; - -exports[`svgAttributes should update old attribute to the new attribute 1`] = ` -" - - - - -" -`; diff --git a/packages/core/src/h2x/svgAttributes.js b/packages/core/src/h2x/svgAttributes.js deleted file mode 100644 index 11d6d24f..00000000 --- a/packages/core/src/h2x/svgAttributes.js +++ /dev/null @@ -1,53 +0,0 @@ -import { JSXAttribute } from 'h2x-plugin-jsx' - -const compareAttrsName = attr => otherAttr => attr.name === otherAttr.name -const compareAttrsValue = attr => otherAttr => attr.value === otherAttr.value - -const compareAttrs = attr => otherAttr => - compareAttrsName(attr)(otherAttr) && compareAttrsValue(attr)(otherAttr) - -const areAttrsAlreadyInjected = (node, attributes = {}) => { - const nodeAttrs = node.attributes - - return Object.keys(attributes).reduce((accumulation, key) => { - if (nodeAttrs.some(compareAttrs({ name: key, value: attributes[key] }))) - return accumulation - return false - }, true) -} - -const svgAttributes = (attributes = {}) => () => { - const keys = Object.keys(attributes) - - return { - visitor: { - JSXElement: { - enter(path) { - if (path.node.name !== 'svg') return - if (areAttrsAlreadyInjected(path.node, attributes)) return - - const parseAttributes = keys.reduce((accumulation, key) => { - const prop = new JSXAttribute() - prop.name = key - prop.value = attributes[key] - return [...accumulation, prop] - }, []) - - const mergeAttributes = path.node.attributes.reduce( - (accumulation, value) => { - if (accumulation.some(compareAttrsName(value))) - return accumulation - return [...accumulation, value] - }, - parseAttributes, - ) - - path.node.attributes = mergeAttributes - path.replace(path.node) - }, - }, - }, - } -} - -export default svgAttributes diff --git a/packages/core/src/h2x/svgAttributes.test.js b/packages/core/src/h2x/svgAttributes.test.js deleted file mode 100644 index aef3c025..00000000 --- a/packages/core/src/h2x/svgAttributes.test.js +++ /dev/null @@ -1,72 +0,0 @@ -import jsx from 'h2x-plugin-jsx' -import { transform } from 'h2x-core' -import svgAttributes from './svgAttributes' - -describe('svgAttributes', () => { - it('should add one attribute to svg', () => { - const attrs = { focusable: false } - const result = transform( - ` - - - - - - `, - { plugins: [jsx, svgAttributes(attrs)] }, - ) - - expect(result).toMatchSnapshot() - }) - - it('should add multiple attributes to svg', () => { - const attrs = { - focusable: false, - hidden: 'hidden', - } - const result = transform( - ` - - - - - `, - { plugins: [jsx, svgAttributes(attrs)] }, - ) - - expect(result).toMatchSnapshot() - }) - - it('should update old attribute to the new attribute', () => { - const attrs = { focusable: true } - const result = transform( - ` - - - - - `, - { plugins: [jsx, svgAttributes(attrs)] }, - ) - - expect(result).toMatchSnapshot() - }) - - it('should add a new attribute', () => { - const attrs = { - focusable: true, - hidden: true, - } - const result = transform( - ` - - - - - `, - { plugins: [jsx, svgAttributes(attrs)] }, - ) - - expect(result).toMatchSnapshot() - }) -}) diff --git a/packages/core/src/index.js b/packages/core/src/index.js index a87289ed..044d61c2 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -10,7 +10,6 @@ export { default as removeComments } from './h2x/removeComments' export { default as removeDimensions } from './h2x/removeDimensions' export { default as replaceAttrValues } from './h2x/replaceAttrValues' export { default as stripAttribute } from './h2x/stripAttribute' -export { default as svgAttributes } from './h2x/svgAttributes' export { default as svgProps } from './h2x/svgProps' export { default as svgRef } from './h2x/svgRef' export { default as titleProp } from './h2x/titleProp' diff --git a/packages/core/src/plugins/h2x.js b/packages/core/src/plugins/h2x.js index d163876e..2cec58fa 100644 --- a/packages/core/src/plugins/h2x.js +++ b/packages/core/src/plugins/h2x.js @@ -7,7 +7,6 @@ import { removeDimensions, replaceAttrValues, stripAttribute, - svgAttributes, svgProps, svgRef, titleProp, @@ -21,7 +20,6 @@ function configToPlugins(config) { if (!config.dimensions) plugins.push(removeDimensions()) if (config.icon) plugins.push(emSize()) if (config.ref) plugins.push(svgRef()) - if (config.svgAttributes) plugins.push(svgAttributes(config.svgAttributes)) if (config.svgProps) plugins.push(svgProps(config.svgProps)) // TODO remove boolean value in the next major release if (config.expandProps)