1 | import { VNode } from 'vue'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | interface CompilerOptions {
|
7 | modules?: ModuleOptions[]
|
8 | directives?: Record<string, DirectiveFunction>
|
9 | preserveWhitespace?: boolean
|
10 | whitespace?: 'preserve' | 'condense'
|
11 | outputSourceRange?: any
|
12 | }
|
13 |
|
14 | interface CompilerOptionsWithSourceRange extends CompilerOptions {
|
15 | outputSourceRange: true
|
16 | }
|
17 |
|
18 | interface ErrorWithRange {
|
19 | msg: string
|
20 | start: number
|
21 | end: number
|
22 | }
|
23 |
|
24 | interface CompiledResult<ErrorType> {
|
25 | ast: ASTElement | undefined
|
26 | render: string
|
27 | staticRenderFns: string[]
|
28 | errors: ErrorType[]
|
29 | tips: ErrorType[]
|
30 | }
|
31 |
|
32 | interface CompiledResultFunctions {
|
33 | render: () => VNode
|
34 | staticRenderFns: (() => VNode)[]
|
35 | }
|
36 |
|
37 | interface ModuleOptions {
|
38 | preTransformNode: (el: ASTElement) => ASTElement | undefined
|
39 | transformNode: (el: ASTElement) => ASTElement | undefined
|
40 | postTransformNode: (el: ASTElement) => void
|
41 | genData: (el: ASTElement) => string
|
42 | transformCode?: (el: ASTElement, code: string) => string
|
43 | staticKeys?: string[]
|
44 | }
|
45 |
|
46 | type DirectiveFunction = (node: ASTElement, directiveMeta: ASTDirective) => void
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export type SSROptimizability = 0 | 1 | 2 | 3 | 4
|
60 |
|
61 | export interface ASTModifiers {
|
62 | [key: string]: boolean
|
63 | }
|
64 |
|
65 | export interface ASTIfCondition {
|
66 | exp: string | undefined
|
67 | block: ASTElement
|
68 | }
|
69 |
|
70 | export interface ASTElementHandler {
|
71 | value: string
|
72 | params?: any[]
|
73 | modifiers: ASTModifiers | undefined
|
74 | }
|
75 |
|
76 | export interface ASTElementHandlers {
|
77 | [key: string]: ASTElementHandler | ASTElementHandler[]
|
78 | }
|
79 |
|
80 | export interface ASTDirective {
|
81 | name: string
|
82 | rawName: string
|
83 | value: string
|
84 | arg: string | undefined
|
85 | modifiers: ASTModifiers | undefined
|
86 | }
|
87 |
|
88 | export type ASTNode = ASTElement | ASTText | ASTExpression
|
89 |
|
90 | export interface ASTElement {
|
91 | type: 1
|
92 | tag: string
|
93 | attrsList: { name: string; value: any }[]
|
94 | attrsMap: Record<string, any>
|
95 | parent: ASTElement | undefined
|
96 | children: ASTNode[]
|
97 |
|
98 | processed?: true
|
99 |
|
100 | static?: boolean
|
101 | staticRoot?: boolean
|
102 | staticInFor?: boolean
|
103 | staticProcessed?: boolean
|
104 | hasBindings?: boolean
|
105 |
|
106 | text?: string
|
107 | attrs?: { name: string; value: any }[]
|
108 | props?: { name: string; value: string }[]
|
109 | plain?: boolean
|
110 | pre?: true
|
111 | ns?: string
|
112 |
|
113 | component?: string
|
114 | inlineTemplate?: true
|
115 | transitionMode?: string | null
|
116 | slotName?: string
|
117 | slotTarget?: string
|
118 | slotScope?: string
|
119 | scopedSlots?: Record<string, ASTElement>
|
120 |
|
121 | ref?: string
|
122 | refInFor?: boolean
|
123 |
|
124 | if?: string
|
125 | ifProcessed?: boolean
|
126 | elseif?: string
|
127 | else?: true
|
128 | ifConditions?: ASTIfCondition[]
|
129 |
|
130 | for?: string
|
131 | forProcessed?: boolean
|
132 | key?: string
|
133 | alias?: string
|
134 | iterator1?: string
|
135 | iterator2?: string
|
136 |
|
137 | staticClass?: string
|
138 | classBinding?: string
|
139 | staticStyle?: string
|
140 | styleBinding?: string
|
141 | events?: ASTElementHandlers
|
142 | nativeEvents?: ASTElementHandlers
|
143 |
|
144 | transition?: string | true
|
145 | transitionOnAppear?: boolean
|
146 |
|
147 | model?: {
|
148 | value: string
|
149 | callback: string
|
150 | expression: string
|
151 | }
|
152 |
|
153 | directives?: ASTDirective[]
|
154 |
|
155 | forbidden?: true
|
156 | once?: true
|
157 | onceProcessed?: boolean
|
158 | wrapData?: (code: string) => string
|
159 | wrapListeners?: (code: string) => string
|
160 |
|
161 |
|
162 | ssrOptimizability?: SSROptimizability
|
163 | }
|
164 |
|
165 | export interface ASTExpression {
|
166 | type: 2
|
167 | expression: string
|
168 | text: string
|
169 | tokens: (string | Record<string, any>)[]
|
170 | static?: boolean
|
171 |
|
172 | ssrOptimizability?: SSROptimizability
|
173 | }
|
174 |
|
175 | export interface ASTText {
|
176 | type: 3
|
177 | text: string
|
178 | static?: boolean
|
179 | isComment?: boolean
|
180 |
|
181 | ssrOptimizability?: SSROptimizability
|
182 | }
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | interface SFCParserOptions {
|
188 | pad?: true | 'line' | 'space'
|
189 | deindent?: boolean
|
190 | }
|
191 |
|
192 | export interface SFCBlock {
|
193 | type: string
|
194 | content: string
|
195 | attrs: Record<string, string>
|
196 | start?: number
|
197 | end?: number
|
198 | lang?: string
|
199 | src?: string
|
200 | scoped?: boolean
|
201 | module?: string | boolean
|
202 | }
|
203 |
|
204 | export interface SFCDescriptor {
|
205 | template: SFCBlock | undefined
|
206 | script: SFCBlock | undefined
|
207 | styles: SFCBlock[]
|
208 | customBlocks: SFCBlock[]
|
209 | }
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | export function compile(
|
215 | template: string,
|
216 | options: CompilerOptionsWithSourceRange
|
217 | ): CompiledResult<ErrorWithRange>
|
218 |
|
219 | export function compile(
|
220 | template: string,
|
221 | options?: CompilerOptions
|
222 | ): CompiledResult<string>
|
223 |
|
224 | export function compileToFunctions(template: string): CompiledResultFunctions
|
225 |
|
226 | export function ssrCompile(
|
227 | template: string,
|
228 | options: CompilerOptionsWithSourceRange
|
229 | ): CompiledResult<ErrorWithRange>
|
230 |
|
231 | export function ssrCompile(
|
232 | template: string,
|
233 | options?: CompilerOptions
|
234 | ): CompiledResult<string>
|
235 |
|
236 | export function ssrCompileToFunctions(template: string): CompiledResultFunctions
|
237 |
|
238 | export function parseComponent(
|
239 | file: string,
|
240 | options?: SFCParserOptions
|
241 | ): SFCDescriptor
|
242 |
|
243 | export function generateCodeFrame(
|
244 | template: string,
|
245 | start: number,
|
246 | end: number
|
247 | ): string
|
248 |
|
\ | No newline at end of file |