File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ exports[`cli --icon 1`] = `
44"import React from \\ "react\\ ";
55
66const One = props => (
7- <svg width =\\"1em \\" height =\\"1em\\" viewBox =\\"0 0 48 1 \\" { ... props } >
7+ <svg viewBox =\\"0 0 48 1 \\" width =\\"1em\\" height =\\"1em \\" { ... props } >
88 <path d =\\"M0 0h48v1H0z\\" fill =\\"#063855\\" fillRule =\\"evenodd\\" />
99 </svg >
1010);
Original file line number Diff line number Diff line change 1+ import { JSXAttribute } from 'h2x-plugin-jsx'
2+
3+ const makeSizeAttr = name => {
4+ const attr = new JSXAttribute ( )
5+ attr . name = name
6+ attr . value = '1em'
7+ attr . litteral = false
8+ return attr
9+ }
10+
111const emSize = ( ) => ( {
212 visitor : {
3- JSXAttribute : {
13+ JSXElement : {
414 enter ( path ) {
5- if (
6- path . parent . name === 'svg ' &&
7- ( path . node . name === 'width' || path . node . name === 'height' )
8- ) {
9- path . node . value = '1em'
10- path . node . litteral = false
15+ if ( path . node . name === 'svg' && ! path . node . attributes . some ( attr => attr && attr . name === 'width' && attr . value === '1em' ) && ! path . node . attributes . some ( attr => attr && attr . name === 'height' && attr . value === '1em' ) ) {
16+ const nextAttrs = path . node . attributes . filter ( attr => attr . name !== 'width ' && attr . name !== 'height' ) ;
17+ nextAttrs . push ( makeSizeAttr ( 'width' ) ) ;
18+ nextAttrs . push ( makeSizeAttr ( 'height' ) ) ;
19+ path . node . attributes = nextAttrs ;
20+ path . replace ( path . node ) ;
1121 }
1222 } ,
1323 } ,
You can’t perform that action at this time.
0 commit comments