/
utils.ts
101 lines (96 loc) · 2.58 KB
/
utils.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as VAST from './ast'
export type VueObjectType = 'mark' | 'export' | 'definition' | 'instance'
export type VueObjectData = {
node: ObjectExpression
type: VueObjectType
parent: VueObjectData | null
functional: boolean
}
type VueVisitorBase = {
[T in keyof NodeListenerMap]?: (
node: NodeListenerMap[T],
obj: VueObjectData
) => void
}
export interface VueVisitor extends VueVisitorBase {
onVueObjectEnter?(node: ObjectExpression, obj: VueObjectData): void
onVueObjectExit?(node: ObjectExpression, obj: VueObjectData): void
onSetupFunctionEnter?(
node: (FunctionExpression | ArrowFunctionExpression) & { parent: Property },
obj: VueObjectData
): void
onSetupFunctionExit?(
node: (FunctionExpression | ArrowFunctionExpression) & { parent: Property },
obj: VueObjectData
): void
onRenderFunctionEnter?(
node: (FunctionExpression | ArrowFunctionExpression) & { parent: Property },
obj: VueObjectData
): void
[query: string]:
| ((node: VAST.ParamNode, obj: VueObjectData) => void)
| undefined
}
type ScriptSetupVisitorBase = {
[T in keyof NodeListenerMap]?: (node: NodeListenerMap[T]) => void
}
export interface ScriptSetupVisitor extends ScriptSetupVisitorBase {
onDefinePropsEnter?(
node: CallExpression,
props: (ComponentArrayProp | ComponentObjectProp | ComponentTypeProp)[]
): void
onDefinePropsExit?(
node: CallExpression,
props: (ComponentArrayProp | ComponentObjectProp | ComponentTypeProp)[]
): void
[query: string]:
| ((node: VAST.ParamNode) => void)
| ((
node: CallExpression,
props: (ComponentArrayProp | ComponentObjectProp)[]
) => void)
| undefined
}
type ComponentArrayPropDetectName = {
type: 'array'
key: Literal | TemplateLiteral
propName: string
value: null
node: Expression | SpreadElement
}
type ComponentArrayPropUnknownName = {
type: 'array'
key: null
propName: null
value: null
node: Expression | SpreadElement
}
export type ComponentArrayProp =
| ComponentArrayPropDetectName
| ComponentArrayPropUnknownName
type ComponentObjectPropDetectName = {
type: 'object'
key: Expression
propName: string
value: Expression
node: Property
}
type ComponentObjectPropUnknownName = {
type: 'object'
key: null
propName: null
value: Expression
node: Property
}
export type ComponentObjectProp =
| ComponentObjectPropDetectName
| ComponentObjectPropUnknownName
export type ComponentTypeProp = {
type: 'type'
key: Identifier
propName: string
value: null
node: TSPropertySignature | TSMethodSignature
required: boolean
types: string[]
}