1
+ /**
2
+ * This declaration is copied from https://github.com/vuejs/vue/pull/7918
3
+ * which may included vue-template-compiler v2.6.0.
4
+ */
5
+ declare module 'vue-template-compiler' {
6
+ import Vue , { VNode } from "vue"
7
+
8
+ /*
9
+ * Template compilation options / results
10
+ */
11
+ interface CompilerOptions {
12
+ modules ?: ModuleOptions [ ] ;
13
+ directives ?: Record < string , DirectiveFunction > ;
14
+ preserveWhitespace ?: boolean ;
15
+ }
16
+
17
+ interface CompiledResult {
18
+ ast : ASTElement | undefined ;
19
+ render : string ;
20
+ staticRenderFns : string [ ] ;
21
+ errors : string [ ] ;
22
+ tips : string [ ] ;
23
+ }
24
+
25
+ interface CompiledResultFunctions {
26
+ render : ( ) => VNode ;
27
+ staticRenderFns : ( ( ) => VNode ) [ ] ;
28
+ }
29
+
30
+ interface ModuleOptions {
31
+ preTransformNode : ( el : ASTElement ) => ASTElement | undefined ;
32
+ transformNode : ( el : ASTElement ) => ASTElement | undefined ;
33
+ postTransformNode : ( el : ASTElement ) => void ;
34
+ genData : ( el : ASTElement ) => string ;
35
+ transformCode ?: ( el : ASTElement , code : string ) => string ;
36
+ staticKeys ?: string [ ] ;
37
+ }
38
+
39
+ type DirectiveFunction = ( node : ASTElement , directiveMeta : ASTDirective ) => void ;
40
+
41
+ /*
42
+ * AST Types
43
+ */
44
+
45
+ /**
46
+ * - 0: FALSE - whole sub tree un-optimizable
47
+ * - 1: FULL - whole sub tree optimizable
48
+ * - 2: SELF - self optimizable but has some un-optimizable children
49
+ * - 3: CHILDREN - self un-optimizable but have fully optimizable children
50
+ * - 4: PARTIAL - self un-optimizable with some un-optimizable children
51
+ */
52
+ export type SSROptimizability = 0 | 1 | 2 | 3 | 4
53
+
54
+ export interface ASTModifiers {
55
+ [ key : string ] : boolean ;
56
+ }
57
+
58
+ export interface ASTIfCondition {
59
+ exp : string | undefined ;
60
+ block : ASTElement ;
61
+ }
62
+
63
+ export interface ASTElementHandler {
64
+ value : string ;
65
+ params ?: any [ ] ;
66
+ modifiers : ASTModifiers | undefined ;
67
+ }
68
+
69
+ export interface ASTElementHandlers {
70
+ [ key : string ] : ASTElementHandler | ASTElementHandler [ ] ;
71
+ }
72
+
73
+ export interface ASTDirective {
74
+ name : string ;
75
+ rawName : string ;
76
+ value : string ;
77
+ arg : string | undefined ;
78
+ modifiers : ASTModifiers | undefined ;
79
+ }
80
+
81
+ export type ASTNode = ASTElement | ASTText | ASTExpression ;
82
+
83
+ export interface ASTElement {
84
+ type : 1 ;
85
+ tag : string ;
86
+ attrsList : { name : string ; value : any } [ ] ;
87
+ attrsMap : Record < string , any > ;
88
+ parent : ASTElement | undefined ;
89
+ children : ASTNode [ ] ;
90
+
91
+ processed ?: true ;
92
+
93
+ static ?: boolean ;
94
+ staticRoot ?: boolean ;
95
+ staticInFor ?: boolean ;
96
+ staticProcessed ?: boolean ;
97
+ hasBindings ?: boolean ;
98
+
99
+ text ?: string ;
100
+ attrs ?: { name : string ; value : any } [ ] ;
101
+ props ?: { name : string ; value : string } [ ] ;
102
+ plain ?: boolean ;
103
+ pre ?: true ;
104
+ ns ?: string ;
105
+
106
+ component ?: string ;
107
+ inlineTemplate ?: true ;
108
+ transitionMode ?: string | null ;
109
+ slotName ?: string ;
110
+ slotTarget ?: string ;
111
+ slotScope ?: string ;
112
+ scopedSlots ?: Record < string , ASTElement > ;
113
+
114
+ ref ?: string ;
115
+ refInFor ?: boolean ;
116
+
117
+ if ?: string ;
118
+ ifProcessed ?: boolean ;
119
+ elseif ?: string ;
120
+ else ?: true ;
121
+ ifConditions ?: ASTIfCondition [ ] ;
122
+
123
+ for ?: string ;
124
+ forProcessed ?: boolean ;
125
+ key ?: string ;
126
+ alias ?: string ;
127
+ iterator1 ?: string ;
128
+ iterator2 ?: string ;
129
+
130
+ staticClass ?: string ;
131
+ classBinding ?: string ;
132
+ staticStyle ?: string ;
133
+ styleBinding ?: string ;
134
+ events ?: ASTElementHandlers ;
135
+ nativeEvents ?: ASTElementHandlers ;
136
+
137
+ transition ?: string | true ;
138
+ transitionOnAppear ?: boolean ;
139
+
140
+ model ?: {
141
+ value : string ;
142
+ callback : string ;
143
+ expression : string ;
144
+ } ;
145
+
146
+ directives ?: ASTDirective [ ] ;
147
+
148
+ forbidden ?: true ;
149
+ once ?: true ;
150
+ onceProcessed ?: boolean ;
151
+ wrapData ?: ( code : string ) => string ;
152
+ wrapListeners ?: ( code : string ) => string ;
153
+
154
+ // 2.4 ssr optimization
155
+ ssrOptimizability ?: SSROptimizability ;
156
+
157
+ // weex specific
158
+ appendAsTree ?: boolean ;
159
+ }
160
+
161
+ export interface ASTExpression {
162
+ type : 2 ;
163
+ expression : string ;
164
+ text : string ;
165
+ tokens : ( string | Record < string , any > ) [ ] ;
166
+ static ?: boolean ;
167
+ // 2.4 ssr optimization
168
+ ssrOptimizability ?: SSROptimizability ;
169
+ }
170
+
171
+ export interface ASTText {
172
+ type : 3 ;
173
+ text : string ;
174
+ static ?: boolean ;
175
+ isComment ?: boolean ;
176
+ // 2.4 ssr optimization
177
+ ssrOptimizability ?: SSROptimizability ;
178
+ }
179
+
180
+ /*
181
+ * SFC parser related types
182
+ */
183
+ interface SFCParserOptions {
184
+ pad ?: true | 'line' | 'space' ;
185
+ }
186
+
187
+ export interface SFCBlock {
188
+ type : string ;
189
+ content : string ;
190
+ attrs : Record < string , string > ;
191
+ start ?: number ;
192
+ end ?: number ;
193
+ lang ?: string ;
194
+ src ?: string ;
195
+ scoped ?: boolean ;
196
+ module ?: string | boolean ;
197
+ }
198
+
199
+ export interface SFCDescriptor {
200
+ template : SFCBlock | undefined ;
201
+ script : SFCBlock | undefined ;
202
+ styles : SFCBlock [ ] ;
203
+ customBlocks : SFCBlock [ ] ;
204
+ }
205
+
206
+ /*
207
+ * Exposed functions
208
+ */
209
+ export function compile (
210
+ template : string ,
211
+ options ?: CompilerOptions
212
+ ) : CompiledResult ;
213
+
214
+ export function compileToFunctions ( template : string ) : CompiledResultFunctions ;
215
+
216
+ export function ssrCompile (
217
+ template : string ,
218
+ options ?: CompilerOptions
219
+ ) : CompiledResult ;
220
+
221
+ export function ssrCompileToFunctions ( template : string ) : CompiledResultFunctions ;
222
+
223
+ export function parseComponent (
224
+ file : string ,
225
+ options ?: SFCParserOptions
226
+ ) : SFCDescriptor ;
227
+ }
0 commit comments