-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest2.js
More file actions
67 lines (51 loc) · 1.24 KB
/
test2.js
File metadata and controls
67 lines (51 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const ts = require('typescript')
// console.log(typescipt.parsr)
console.log(Object.keys(ts).length)
const str = `
type N = number
interface B {
fn: void
}
export interface Props extends B{
/**
* xxxx
* @zh-cn 中文
* @en 英语
*/
a: N,
b?: string,
c: boolean,
d: any,
e: (a: number) => void
}
export function B () {
return (
<div>B组件</div>
)
}
export default function Test (props: Props) {
return (
<div>hello world</div>
)
}
`
const str2 = `
export * from './a'
export default b
export {
c
}
`
const tsconfig = require('./packages/otaku-ui/tsconfig.json')
const program = ts.createProgram(['./packages/otaku-ui/src/index.ts'], tsconfig)
const root = ts.createSourceFile('1.tsx', str, ts.ScriptTarget.ESNext, true)
console.log(program.getTypeChecker())
// ts.forEachChild(root, (node) => {
// console.log(ts.SyntaxKind[node.kind], node.kind)
// console.log(ts.isExportDeclaration(node))
// })
// const printAllChildren = (node, depth = 0) => {
// console.log(new Array(depth + 1).join('----'), ts.SyntaxKind[node.kind], node.pos, node.end);
// node.getChildren().forEach((c) => printAllChildren(c, depth + 1));
// };
// printAllChildren(root)