diff --git a/packages/babel-preset/src/index.js b/packages/babel-preset/src/index.js index ef28b66d..8fde43de 100644 --- a/packages/babel-preset/src/index.js +++ b/packages/babel-preset/src/index.js @@ -63,6 +63,7 @@ const plugin = (api, opts) => { const plugins = [ [transformSvgComponent, opts], + ...(opts.icon && opts.dimensions ? [svgEmDimensions] : []), [ removeJSXAttribute, { elements: ['svg', 'Svg'], attributes: toRemoveAttributes }, @@ -81,10 +82,6 @@ const plugin = (api, opts) => { ]) } - if (opts.icon && opts.dimensions) { - plugins.push(svgEmDimensions) - } - if (opts.titleProp) { plugins.push(svgDynamicTitle) } diff --git a/packages/babel-preset/src/index.test.js b/packages/babel-preset/src/index.test.js index a6e839c1..de53db23 100644 --- a/packages/babel-preset/src/index.test.js +++ b/packages/babel-preset/src/index.test.js @@ -24,12 +24,12 @@ describe('preset', () => { }, }), ).toMatchInlineSnapshot(` -"import React from \\"react\\"; - -const SvgComponent = () => ; - -export default SvgComponent;" -`) + "import React from \\"react\\"; + + const SvgComponent = () => ; + + export default SvgComponent;" + `) }) it('should handle native expo option', () => { @@ -41,13 +41,13 @@ export default SvgComponent;" }, }), ).toMatchInlineSnapshot(` -"import React from \\"react\\"; -import { Svg } from \\"expo\\"; - -const SvgComponent = () => ; - -export default SvgComponent;" -`) + "import React from \\"react\\"; + import { Svg } from \\"expo\\"; + + const SvgComponent = () => ; + + export default SvgComponent;" + `) }) it('should handle titleProp', () => { @@ -59,14 +59,14 @@ export default SvgComponent;" }, }), ).toMatchInlineSnapshot(` -"import React from \\"react\\"; - -const SvgComponent = ({ - title -}) => {title}; - -export default SvgComponent;" -`) + "import React from \\"react\\"; + + const SvgComponent = ({ + title + }) => {title}; + + export default SvgComponent;" + `) }) it('should handle replaceAttrValues', () => { @@ -81,11 +81,30 @@ export default SvgComponent;" }, }), ).toMatchInlineSnapshot(` -"import React from \\"react\\"; - -const SvgComponent = () => ; + "import React from \\"react\\"; + + const SvgComponent = () => ; + + export default SvgComponent;" + `) + }) -export default SvgComponent;" -`) + it('should handle expandProps & icon & dimensions', () => { + expect( + testPreset('', { + expandProps: 'end', + icon: true, + dimensions: true, + state: { + componentName: 'SvgComponent', + }, + }), + ).toMatchInlineSnapshot(` + "import React from \\"react\\"; + + const SvgComponent = props => ; + + export default SvgComponent;" + `) }) })