File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,3 +171,12 @@ const MyComponent = (props) => {/*?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?*/
171171
172172export default MyComponent"
173173` ;
174+
175+ exports [` should handle componentName with only numbers 1` ] = `
176+ "import React from 'react'
177+
178+ const Svg1BigSvg = (props) => <svg />
179+
180+
181+ export default Svg1BigSvg"
182+ ` ;
Original file line number Diff line number Diff line change @@ -27,9 +27,17 @@ export {
2727 removeStyle ,
2828}
2929
30- function expandState ( state ) {
30+ function getComponentName ( state ) {
3131 const componentName = pascalCase ( path . parse ( state . filePath ) . name )
32- return { ...state , componentName }
32+ if ( Number . isNaN ( parseInt ( componentName [ 0 ] , 10 ) ) ) {
33+ return componentName
34+ }
35+
36+ return `Svg${ componentName } `
37+ }
38+
39+ function expandState ( state ) {
40+ return { componentName : getComponentName ( state ) , ...state }
3341}
3442
3543export async function rawConvert ( code , options , state ) {
Original file line number Diff line number Diff line change @@ -36,13 +36,28 @@ describe('rawConvert', () => {
3636 } ,
3737 template : wrapIntoComponent ( { expandProps : true } ) ,
3838 } ,
39- { filePath : 'MyComponent.js ' } ,
39+ { filePath : 'MyComponent.svg ' } ,
4040 )
4141
4242 expect ( result ) . toMatchSnapshot ( )
4343 } )
4444} )
4545
46+ it ( 'should handle componentName with only numbers' , async ( ) => {
47+ const result = await rawConvert (
48+ `<svg></svg>` ,
49+ {
50+ h2x : {
51+ plugins : [ jsx ] ,
52+ } ,
53+ template : wrapIntoComponent ( { expandProps : true } ) ,
54+ } ,
55+ { filePath : '1_big_svg.svg' } ,
56+ )
57+
58+ expect ( result ) . toMatchSnapshot ( )
59+ } )
60+
4661describe ( 'convert' , ( ) => {
4762 it ( 'should convert using config' , async ( ) => {
4863 const result = await convert (
You can’t perform that action at this time.
0 commit comments