MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / App

Function App

playground-test/src/App2.tsx:4–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import type { PluginObj } from '@babel/core';
3
4function App() {
5
6 const code1 =`
7 function add(a, b) {
8 return a + b;
9 }
10 export { add };
11 `;
12
13 const url = URL.createObjectURL(new Blob([code1], { type: 'application/javascript' }));
14
15 const transformImportSourcePlugin: PluginObj = {
16 visitor: {
17 ImportDeclaration(path) {
18 path.node.source.value = url;
19 }
20 },
21 }
22
23
24 const code = `import { add } from './add.ts';
25
26 console.log(add(2, 3));
27 `
28
29 function onClick() {
30 const res = transform(code, {
31 presets: ['react', 'typescript'],
32 filename: 'guang.ts',
33 plugins: [transformImportSourcePlugin]
34 });
35 console.log(res.code);
36 }
37
38 return (
39 <div>
40 <button onClick={onClick}>编译</button>
41 </div>
42 )
43}
44
45export default App

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected