@@ -134,9 +134,54 @@ describe('transformFileAsync', () => {
134134 expect ( formattedCode . match ( / \{ ` / g) ) . toHaveLength ( 8 )
135135 expect ( formattedCode . match ( / ` \} / g) ) . toHaveLength ( 8 )
136136 } )
137+
138+ it ( 'should format TypeScript syntax with the babel-ts parser' , async ( ) => {
139+ const targetFileWithTypes = nodePath . resolve (
140+ __dirname ,
141+ '../__mocks__/ExamplesTypeAnnotations.tsx'
142+ )
143+ const pluginOptionsWithTypes = {
144+ componentName : 'ComponentBox' ,
145+ filesToMatch : [ 'ExamplesTypeAnnotations.tsx' ] ,
146+ prettierPath,
147+ }
148+
149+ const babelFileResult = await transformFileAsync ( targetFileWithTypes , {
150+ code : true ,
151+ presets : [
152+ [
153+ '@babel/preset-env' ,
154+ {
155+ modules : false ,
156+ targets : { firefox : '100' } ,
157+ } ,
158+ ] ,
159+ ] ,
160+ plugins : [ [ babelPluginReactLive , pluginOptionsWithTypes ] ] ,
161+ } )
162+
163+ const code = removeConsoleNinja ( String ( babelFileResult ?. code ) )
164+
165+ const formattedCode = prettier . format ( code , {
166+ filepath : 'file.tsx' ,
167+ semi : false ,
168+ } )
169+
170+ expect ( formattedCode ) . toMatchInlineSnapshot ( `
171+ "const ComponentBox = ({ children }) => children
172+ export const MockTypeAnnotations = () => {
173+ const value = "hello"
174+ return (
175+ <ComponentBox data-test="id">{\`<span>{value as string}</span>
176+ \`}</ComponentBox>
177+ )
178+ }
179+ "
180+ ` )
181+ } )
137182} )
138183
139- function removeConsoleNinja ( code ) {
184+ function removeConsoleNinja ( code : string ) : string {
140185 if ( code . includes ( 'oo_cm' ) ) {
141186 const index = code . indexOf ( 'function oo_cm()' )
142187 code = code . slice ( 0 , index )
0 commit comments