Blame view

node_modules/vue/packages/compiler-sfc/dist/compiler-sfc.d.ts 11.7 KB
4cd4fd28   郭伟龙   feat: 初始化项目
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
import { LazyResult } from 'postcss';
import { ParserPlugin } from '@babel/parser';

declare interface AssetURLOptions {
    [name: string]: string | string[];
}

declare type ASTAttr = {
    name: string;
    value: any;
    dynamic?: boolean;
    start?: number;
    end?: number;
};

declare type ASTDirective = {
    name: string;
    rawName: string;
    value: string;
    arg: string | null;
    isDynamicArg: boolean;
    modifiers: ASTModifiers | null;
    start?: number;
    end?: number;
};

declare type ASTElement = {
    type: 1;
    tag: string;
    attrsList: Array<ASTAttr>;
    attrsMap: {
        [key: string]: any;
    };
    rawAttrsMap: {
        [key: string]: ASTAttr;
    };
    parent: ASTElement | void;
    children: Array<ASTNode>;
    start?: number;
    end?: number;
    processed?: true;
    static?: boolean;
    staticRoot?: boolean;
    staticInFor?: boolean;
    staticProcessed?: boolean;
    hasBindings?: boolean;
    text?: string;
    attrs?: Array<ASTAttr>;
    dynamicAttrs?: Array<ASTAttr>;
    props?: Array<ASTAttr>;
    plain?: boolean;
    pre?: true;
    ns?: string;
    component?: string;
    inlineTemplate?: true;
    transitionMode?: string | null;
    slotName?: string | null;
    slotTarget?: string | null;
    slotTargetDynamic?: boolean;
    slotScope?: string | null;
    scopedSlots?: {
        [name: string]: ASTElement;
    };
    ref?: string;
    refInFor?: boolean;
    if?: string;
    ifProcessed?: boolean;
    elseif?: string;
    else?: true;
    ifConditions?: ASTIfConditions;
    for?: string;
    forProcessed?: boolean;
    key?: string;
    alias?: string;
    iterator1?: string;
    iterator2?: string;
    staticClass?: string;
    classBinding?: string;
    staticStyle?: string;
    styleBinding?: string;
    events?: ASTElementHandlers;
    nativeEvents?: ASTElementHandlers;
    transition?: string | true;
    transitionOnAppear?: boolean;
    model?: {
        value: string;
        callback: string;
        expression: string;
    };
    directives?: Array<ASTDirective>;
    forbidden?: true;
    once?: true;
    onceProcessed?: boolean;
    wrapData?: (code: string) => string;
    wrapListeners?: (code: string) => string;
    ssrOptimizability?: number;
};

declare type ASTElementHandler = {
    value: string;
    params?: Array<any>;
    modifiers: ASTModifiers | null;
    dynamic?: boolean;
    start?: number;
    end?: number;
};

declare type ASTElementHandlers = {
    [key: string]: ASTElementHandler | Array<ASTElementHandler>;
};

declare type ASTExpression = {
    type: 2;
    expression: string;
    text: string;
    tokens: Array<string | Object>;
    static?: boolean;
    ssrOptimizability?: number;
    start?: number;
    end?: number;
};

declare type ASTIfCondition = {
    exp: string | null;
    block: ASTElement;
};

declare type ASTIfConditions = Array<ASTIfCondition>;

declare type ASTModifiers = {
    [key: string]: boolean;
};

declare type ASTNode = ASTElement | ASTText | ASTExpression;

declare type ASTText = {
    type: 3;
    text: string;
    static?: boolean;
    isComment?: boolean;
    ssrOptimizability?: number;
    start?: number;
    end?: number;
};

declare type BindingMetadata = {
    [key: string]: BindingTypes | undefined;
} & {
    __isScriptSetup?: boolean;
};

declare const enum BindingTypes {
    /**
     * returned from data()
     */
    DATA = "data",
    /**
     * declared as a prop
     */
    PROPS = "props",
    /**
     * a local alias of a `<script setup>` destructured prop.
     * the original is stored in __propsAliases of the bindingMetadata object.
     */
    PROPS_ALIASED = "props-aliased",
    /**
     * a let binding (may or may not be a ref)
     */
    SETUP_LET = "setup-let",
    /**
     * a const binding that can never be a ref.
     * these bindings don't need `unref()` calls when processed in inlined
     * template expressions.
     */
    SETUP_CONST = "setup-const",
    /**
     * a const binding that does not need `unref()`, but may be mutated.
     */
    SETUP_REACTIVE_CONST = "setup-reactive-const",
    /**
     * a const binding that may be a ref.
     */
    SETUP_MAYBE_REF = "setup-maybe-ref",
    /**
     * bindings that are guaranteed to be refs
     */
    SETUP_REF = "setup-ref",
    /**
     * declared by other options, e.g. computed, inject
     */
    OPTIONS = "options"
}

declare type CompiledResult = {
    ast: ASTElement | null;
    render: string;
    staticRenderFns: Array<string>;
    stringRenderFns?: Array<string>;
    errors?: Array<string | WarningMessage>;
    tips?: Array<string | WarningMessage>;
};

export declare type CompilerOptions = {
    warn?: Function;
    modules?: Array<ModuleOptions>;
    directives?: {
        [key: string]: Function;
    };
    staticKeys?: string;
    isUnaryTag?: (tag: string) => boolean | undefined;
    canBeLeftOpenTag?: (tag: string) => boolean | undefined;
    isReservedTag?: (tag: string) => boolean | undefined;
    preserveWhitespace?: boolean;
    whitespace?: 'preserve' | 'condense';
    optimize?: boolean;
    mustUseProp?: (tag: string, type: string | null, name: string) => boolean;
    isPreTag?: (attr: string) => boolean | null;
    getTagNamespace?: (tag: string) => string | undefined;
    expectHTML?: boolean;
    isFromDOM?: boolean;
    shouldDecodeTags?: boolean;
    shouldDecodeNewlines?: boolean;
    shouldDecodeNewlinesForHref?: boolean;
    outputSourceRange?: boolean;
    shouldKeepComment?: boolean;
    delimiters?: [string, string];
    comments?: boolean;
    scopeId?: string;
    bindings?: BindingMetadata;
};

/**
 * Compile `<script setup>`
 * It requires the whole SFC descriptor because we need to handle and merge
 * normal `<script>` + `<script setup>` if both are present.
 */
export declare function compileScript(sfc: SFCDescriptor, options?: SFCScriptCompileOptions): SFCScriptBlock;

export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;

export declare function compileStyleAsync(options: SFCStyleCompileOptions): Promise<SFCStyleCompileResults>;

export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;

export declare function generateCodeFrame(source: string, start?: number, end?: number): string;

declare interface ImportBinding {
    isType: boolean;
    imported: string;
    source: string;
    isFromSetup: boolean;
    isUsedInTemplate: boolean;
}

declare type ModuleOptions = {
    preTransformNode?: (el: ASTElement) => ASTElement | null | void;
    transformNode?: (el: ASTElement) => ASTElement | null | void;
    postTransformNode?: (el: ASTElement) => void;
    genData?: (el: ASTElement) => string;
    transformCode?: (el: ASTElement, code: string) => string;
    staticKeys?: Array<string>;
};

export declare function parse(options: SFCParseOptions): SFCDescriptor;

/**
 * Parse a single-file component (*.vue) file into an SFC Descriptor Object.
 */
export declare function parseComponent(source: string, options?: VueTemplateCompilerParseOptions): SFCDescriptor;

declare interface RawSourceMap extends StartOfSourceMap {
    version: string;
    sources: string[];
    names: string[];
    sourcesContent?: string[];
    mappings: string;
}

/**
 * Utility for rewriting `export default` in a script block into a variable
 * declaration so that we can inject things into it
 */
export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;

export declare interface SFCBlock extends SFCCustomBlock {
    lang?: string;
    scoped?: boolean;
    module?: string | boolean;
}

export declare interface SFCCustomBlock {
    type: string;
    content: string;
    attrs: {
        [key: string]: string | true;
    };
    start: number;
    end: number;
    src?: string;
    map?: RawSourceMap;
}

export declare interface SFCDescriptor {
    source: string;
    filename: string;
    template: SFCBlock | null;
    script: SFCScriptBlock | null;
    scriptSetup: SFCScriptBlock | null;
    styles: SFCBlock[];
    customBlocks: SFCCustomBlock[];
    cssVars: string[];
    errors: (string | WarningMessage)[];
    /**
     * compare with an existing descriptor to determine whether HMR should perform
     * a reload vs. re-render.
     *
     * Note: this comparison assumes the prev/next script are already identical,
     * and only checks the special case where `<script setup lang="ts">` unused
     * import pruning result changes due to template changes.
     */
    shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
}

export declare interface SFCParseOptions {
    source: string;
    filename?: string;
    compiler?: TemplateCompiler;
    compilerParseOptions?: VueTemplateCompilerParseOptions;
    sourceRoot?: string;
    sourceMap?: boolean;
    /**
     * @deprecated use `sourceMap` instead.
     */
    needMap?: boolean;
}

export declare interface SFCScriptBlock extends SFCBlock {
    type: 'script';
    setup?: string | boolean;
    bindings?: BindingMetadata;
    imports?: Record<string, ImportBinding>;
    /**
     * import('\@babel/types').Statement
     */
    scriptAst?: any[];
    /**
     * import('\@babel/types').Statement
     */
    scriptSetupAst?: any[];
}

export declare interface SFCScriptCompileOptions {
    /**
     * Scope ID for prefixing injected CSS variables.
     * This must be consistent with the `id` passed to `compileStyle`.
     */
    id: string;
    /**
     * Production mode. Used to determine whether to generate hashed CSS variables
     */
    isProd?: boolean;
    /**
     * Enable/disable source map. Defaults to true.
     */
    sourceMap?: boolean;
    /**
     * https://babeljs.io/docs/en/babel-parser#plugins
     */
    babelParserPlugins?: ParserPlugin[];
}

export declare interface SFCStyleCompileOptions {
    source: string;
    filename: string;
    id: string;
    map?: any;
    scoped?: boolean;
    trim?: boolean;
    preprocessLang?: string;
    preprocessOptions?: any;
    postcssOptions?: any;
    postcssPlugins?: any[];
    isProd?: boolean;
}

export declare interface SFCStyleCompileResults {
    code: string;
    map: any | void;
    rawResult: LazyResult | void;
    errors: string[];
}

export declare interface SFCTemplateCompileOptions {
    source: string;
    filename: string;
    compiler?: TemplateCompiler;
    compilerOptions?: CompilerOptions;
    transformAssetUrls?: AssetURLOptions | boolean;
    transformAssetUrlsOptions?: TransformAssetUrlsOptions;
    preprocessLang?: string;
    preprocessOptions?: any;
    transpileOptions?: any;
    isProduction?: boolean;
    isFunctional?: boolean;
    optimizeSSR?: boolean;
    prettify?: boolean;
    isTS?: boolean;
    bindings?: BindingMetadata;
}

export declare interface SFCTemplateCompileResults {
    ast: Object | undefined;
    code: string;
    source: string;
    tips: (string | WarningMessage)[];
    errors: (string | WarningMessage)[];
}

declare interface StartOfSourceMap {
    file?: string;
    sourceRoot?: string;
}

export declare interface TemplateCompiler {
    parseComponent(source: string, options?: any): SFCDescriptor;
    compile(template: string, options: CompilerOptions): CompiledResult;
    ssrCompile(template: string, options: CompilerOptions): CompiledResult;
}

declare interface TransformAssetUrlsOptions {
    /**
     * If base is provided, instead of transforming relative asset urls into
     * imports, they will be directly rewritten to absolute urls.
     */
    base?: string;
    /**
     * If true, also processes absolute urls.
     */
    includeAbsolute?: boolean;
}

declare interface VueTemplateCompilerParseOptions {
    pad?: 'line' | 'space' | boolean;
    deindent?: boolean;
    outputSourceRange?: boolean;
}

export declare type WarningMessage = {
    msg: string;
    start?: number;
    end?: number;
};

export { }