diff --git a/src/__snapshots__/index.test.js.snap b/src/__snapshots__/index.test.js.snap index f788c01e..bb8819fe 100644 --- a/src/__snapshots__/index.test.js.snap +++ b/src/__snapshots__/index.test.js.snap @@ -171,3 +171,12 @@ const MyComponent = (props) => {/*?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?*/ export default MyComponent" `; + +exports[`should handle componentName with only numbers 1`] = ` +"import React from 'react' + +const Svg1BigSvg = (props) => + + +export default Svg1BigSvg" +`; diff --git a/src/index.js b/src/index.js index f529d968..b7ec41a1 100644 --- a/src/index.js +++ b/src/index.js @@ -27,9 +27,17 @@ export { removeStyle, } -function expandState(state) { +function getComponentName(state) { const componentName = pascalCase(path.parse(state.filePath).name) - return { ...state, componentName } + if (Number.isNaN(parseInt(componentName[0], 10))) { + return componentName + } + + return `Svg${componentName}` +} + +function expandState(state) { + return { componentName: getComponentName(state), ...state } } export async function rawConvert(code, options, state) { diff --git a/src/index.test.js b/src/index.test.js index 14fce0e9..2baff5d2 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -36,13 +36,28 @@ describe('rawConvert', () => { }, template: wrapIntoComponent({ expandProps: true }), }, - { filePath: 'MyComponent.js' }, + { filePath: 'MyComponent.svg' }, ) expect(result).toMatchSnapshot() }) }) +it('should handle componentName with only numbers', async () => { + const result = await rawConvert( + ``, + { + h2x: { + plugins: [jsx], + }, + template: wrapIntoComponent({ expandProps: true }), + }, + { filePath: '1_big_svg.svg' }, + ) + + expect(result).toMatchSnapshot() +}) + describe('convert', () => { it('should convert using config', async () => { const result = await convert(