()
| 2 | import { transform } from '@babel/standalone'; |
| 3 | |
| 4 | function App() { |
| 5 | |
| 6 | const textareaRef = useRef<HTMLTextAreaElement>(null); |
| 7 | |
| 8 | function onClick() { |
| 9 | if(!textareaRef.current) { |
| 10 | return ; |
| 11 | } |
| 12 | |
| 13 | const res = transform(textareaRef.current.value, { |
| 14 | presets: ['react', 'typescript'], |
| 15 | filename: 'guang.tsx' |
| 16 | }); |
| 17 | console.log(res.code); |
| 18 | } |
| 19 | |
| 20 | const code = `import { useEffect, useState } from "react"; |
| 21 | |
| 22 | function App() { |
| 23 | const [num, setNum] = useState(() => { |
| 24 | const num1 = 1 + 2; |
| 25 | const num2 = 2 + 3; |
| 26 | return num1 + num2 |
| 27 | }); |
| 28 | |
| 29 | return ( |
| 30 | <div onClick={() => setNum((prevNum) => prevNum + 1)}>{num}</div> |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | export default App; |
| 35 | ` |
| 36 | return ( |
| 37 | <div> |
| 38 | <textarea ref={textareaRef} style={{ width: '500px', height: '300px'}} defaultValue={code}></textarea> |
| 39 | <button onClick={onClick}>编译</button> |
| 40 | </div> |
| 41 | ) |
| 42 | } |
| 43 | |
| 44 | export default App |
nothing calls this directly
no outgoing calls
no test coverage detected