File tree Expand file tree Collapse file tree
packages/babel-plugin-transform-svg-component/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,6 +65,15 @@ const MyComponent = (props: React.SVGProps<SVGSVGElement>) => <svg><g /></svg>;
6565export default MyComponent;"
6666`;
6767
68+ exports[`plugin javascript custom templates supports comments in templates 1`] = `
69+ "/**
70+ * Comment
71+ */
72+ const MyComponent = () => <svg ><g /></svg >;
73+
74+ export default MyComponent;"
75+ `;
76+
6877exports[`plugin javascript custom templates supports template that does not return an array 1`] = `"<svg ><g /></svg >;"`;
6978
7079exports[`plugin javascript custom templates supports type annotation on component 1`] = `
@@ -284,6 +293,15 @@ const MyComponent = (props: React.SVGProps<SVGSVGElement>) => <svg><g /></svg>;
284293export default MyComponent;"
285294`;
286295
296+ exports[`plugin typescript custom templates supports comments in templates 1`] = `
297+ "/**
298+ * Comment
299+ */
300+ const MyComponent = () => <svg ><g /></svg >;
301+
302+ export default MyComponent;"
303+ `;
304+
287305exports[`plugin typescript custom templates supports template that does not return an array 1`] = `"<svg ><g /></svg >;"`;
288306
289307exports[`plugin typescript custom templates supports type annotation on component 1`] = `
Original file line number Diff line number Diff line change @@ -248,6 +248,21 @@ describe('plugin', () => {
248248 } )
249249 expect ( code ) . toMatchSnapshot ( )
250250 } )
251+
252+ it ( 'supports comments in templates' , ( ) => {
253+ const { code } = testPlugin ( language ) ( '<svg><g /></svg>' , {
254+ template : ( { jsx } , { tpl } ) => tpl `
255+ /**
256+ * Comment
257+ */
258+ const MyComponent = () => ${ jsx }
259+
260+ export default MyComponent;
261+ ` ,
262+ state : { componentName : 'SvgComponent' } ,
263+ } )
264+ expect ( code ) . toMatchSnapshot ( )
265+ } )
251266 } )
252267
253268 describe ( '#jsxRuntime' , ( ) => {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const plugin = (_: ConfigAPI, opts: Options) => {
1717 const plugins : ParserOptions [ 'plugins' ] = opts . typescript
1818 ? [ 'jsx' , 'typescript' ]
1919 : [ 'jsx' ]
20- const tpl = babelTemplate . smart ( { plugins } ) . ast
20+ const tpl = babelTemplate . smart ( { plugins, preserveComments : true } ) . ast
2121 return {
2222 visitor : {
2323 Program ( path : NodePath < t . Program > ) {
You can’t perform that action at this time.
0 commit comments