1 | import * as _babel_types from '@babel/types';
|
2 | import { Statement, Expression, TSType, Program, Node, ObjectPattern, TSModuleDeclaration, TSPropertySignature, TSMethodSignature, TSCallSignatureDeclaration, TSFunctionType } from '@babel/types';
|
3 | import { CompilerOptions, CodegenResult, ParserOptions, RootNode, CompilerError, SourceLocation, ElementNode, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core';
|
4 | export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core';
|
5 | import { RawSourceMap } from 'source-map-js';
|
6 | import { ParserPlugin } from '@babel/parser';
|
7 | export { parse as babelParse } from '@babel/parser';
|
8 | import { Result, LazyResult } from 'postcss';
|
9 | import MagicString from 'magic-string';
|
10 | export { default as MagicString } from 'magic-string';
|
11 | export { shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST } from '@vue/reactivity-transform';
|
12 |
|
13 | export interface AssetURLTagConfig {
|
14 | [name: string]: string[];
|
15 | }
|
16 | export interface AssetURLOptions {
|
17 | |
18 |
|
19 |
|
20 |
|
21 | base?: string | null;
|
22 | |
23 |
|
24 |
|
25 | includeAbsolute?: boolean;
|
26 | tags?: AssetURLTagConfig;
|
27 | }
|
28 |
|
29 | export interface TemplateCompiler {
|
30 | compile(template: string, options: CompilerOptions): CodegenResult;
|
31 | parse(template: string, options: ParserOptions): RootNode;
|
32 | }
|
33 | export interface SFCTemplateCompileResults {
|
34 | code: string;
|
35 | ast?: RootNode;
|
36 | preamble?: string;
|
37 | source: string;
|
38 | tips: string[];
|
39 | errors: (string | CompilerError)[];
|
40 | map?: RawSourceMap;
|
41 | }
|
42 | export interface SFCTemplateCompileOptions {
|
43 | source: string;
|
44 | filename: string;
|
45 | id: string;
|
46 | scoped?: boolean;
|
47 | slotted?: boolean;
|
48 | isProd?: boolean;
|
49 | ssr?: boolean;
|
50 | ssrCssVars?: string[];
|
51 | inMap?: RawSourceMap;
|
52 | compiler?: TemplateCompiler;
|
53 | compilerOptions?: CompilerOptions;
|
54 | preprocessLang?: string;
|
55 | preprocessOptions?: any;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | preprocessCustomRequire?: (id: string) => any;
|
62 | |
63 |
|
64 |
|
65 |
|
66 | transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
|
67 | }
|
68 | export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
|
69 |
|
70 | export interface SFCScriptCompileOptions {
|
71 | |
72 |
|
73 |
|
74 |
|
75 | id: string;
|
76 | |
77 |
|
78 |
|
79 | isProd?: boolean;
|
80 | |
81 |
|
82 |
|
83 | sourceMap?: boolean;
|
84 | |
85 |
|
86 |
|
87 | babelParserPlugins?: ParserPlugin[];
|
88 | |
89 |
|
90 |
|
91 |
|
92 | globalTypeFiles?: string[];
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | inlineTemplate?: boolean;
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | genDefaultAs?: string;
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 | templateOptions?: Partial<SFCTemplateCompileOptions>;
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 | hoistStatic?: boolean;
|
119 | |
120 |
|
121 |
|
122 |
|
123 | defineModel?: boolean;
|
124 | |
125 |
|
126 |
|
127 |
|
128 | propsDestructure?: boolean;
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 | fs?: {
|
135 | fileExists(file: string): boolean;
|
136 | readFile(file: string): string | undefined;
|
137 | };
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | reactivityTransform?: boolean;
|
146 | }
|
147 | interface ImportBinding {
|
148 | isType: boolean;
|
149 | imported: string;
|
150 | local: string;
|
151 | source: string;
|
152 | isFromSetup: boolean;
|
153 | isUsedInTemplate: boolean;
|
154 | }
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
|
161 |
|
162 | export interface SFCParseOptions {
|
163 | filename?: string;
|
164 | sourceMap?: boolean;
|
165 | sourceRoot?: string;
|
166 | pad?: boolean | 'line' | 'space';
|
167 | ignoreEmpty?: boolean;
|
168 | compiler?: TemplateCompiler;
|
169 | }
|
170 | export interface SFCBlock {
|
171 | type: string;
|
172 | content: string;
|
173 | attrs: Record<string, string | true>;
|
174 | loc: SourceLocation;
|
175 | map?: RawSourceMap;
|
176 | lang?: string;
|
177 | src?: string;
|
178 | }
|
179 | export interface SFCTemplateBlock extends SFCBlock {
|
180 | type: 'template';
|
181 | ast: ElementNode;
|
182 | }
|
183 | export interface SFCScriptBlock extends SFCBlock {
|
184 | type: 'script';
|
185 | setup?: string | boolean;
|
186 | bindings?: BindingMetadata$1;
|
187 | imports?: Record<string, ImportBinding>;
|
188 | scriptAst?: _babel_types.Statement[];
|
189 | scriptSetupAst?: _babel_types.Statement[];
|
190 | warnings?: string[];
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 | deps?: string[];
|
197 | }
|
198 | export interface SFCStyleBlock extends SFCBlock {
|
199 | type: 'style';
|
200 | scoped?: boolean;
|
201 | module?: string | boolean;
|
202 | }
|
203 | export interface SFCDescriptor {
|
204 | filename: string;
|
205 | source: string;
|
206 | template: SFCTemplateBlock | null;
|
207 | script: SFCScriptBlock | null;
|
208 | scriptSetup: SFCScriptBlock | null;
|
209 | styles: SFCStyleBlock[];
|
210 | customBlocks: SFCBlock[];
|
211 | cssVars: string[];
|
212 | |
213 |
|
214 |
|
215 |
|
216 | slotted: boolean;
|
217 | |
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
|
226 | }
|
227 | export interface SFCParseResult {
|
228 | descriptor: SFCDescriptor;
|
229 | errors: (CompilerError | SyntaxError)[];
|
230 | }
|
231 | export declare const parseCache: Map<string, SFCParseResult> & {
|
232 | max?: number | undefined;
|
233 | };
|
234 | export declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, ignoreEmpty, compiler }?: SFCParseOptions): SFCParseResult;
|
235 |
|
236 | type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
|
237 |
|
238 | export interface SFCStyleCompileOptions {
|
239 | source: string;
|
240 | filename: string;
|
241 | id: string;
|
242 | scoped?: boolean;
|
243 | trim?: boolean;
|
244 | isProd?: boolean;
|
245 | inMap?: RawSourceMap;
|
246 | preprocessLang?: PreprocessLang;
|
247 | preprocessOptions?: any;
|
248 | preprocessCustomRequire?: (id: string) => any;
|
249 | postcssOptions?: any;
|
250 | postcssPlugins?: any[];
|
251 | |
252 |
|
253 |
|
254 | map?: RawSourceMap;
|
255 | }
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | interface CSSModulesOptions {
|
261 | scopeBehaviour?: 'global' | 'local';
|
262 | generateScopedName?: string | ((name: string, filename: string, css: string) => string);
|
263 | hashPrefix?: string;
|
264 | localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
|
265 | exportGlobals?: boolean;
|
266 | globalModulePaths?: RegExp[];
|
267 | }
|
268 | export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
|
269 | isAsync?: boolean;
|
270 | modules?: boolean;
|
271 | modulesOptions?: CSSModulesOptions;
|
272 | }
|
273 | export interface SFCStyleCompileResults {
|
274 | code: string;
|
275 | map: RawSourceMap | undefined;
|
276 | rawResult: Result | LazyResult | undefined;
|
277 | errors: Error[];
|
278 | modules?: Record<string, string>;
|
279 | dependencies: Set<string>;
|
280 | }
|
281 | export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
|
282 | export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
|
283 |
|
284 | export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
|
285 | /**
|
286 | * Utility for rewriting `export default` in a script block into a variable
|
287 | * declaration so that we can inject things into it
|
288 | */
|
289 | export declare function rewriteDefaultAST(ast: Statement[], s: MagicString, as: string): void;
|
290 |
|
291 | type PropsDestructureBindings = Record<string, // public prop key
|
292 | {
|
293 | local: string;
|
294 | default?: Expression;
|
295 | }>;
|
296 |
|
297 | interface ModelDecl {
|
298 | type: TSType | undefined;
|
299 | options: string | undefined;
|
300 | identifier: string | undefined;
|
301 | }
|
302 |
|
303 | declare const enum BindingTypes {
|
304 | /**
|
305 | * returned from data()
|
306 | */
|
307 | DATA = "data",
|
308 | /**
|
309 | * declared as a prop
|
310 | */
|
311 | PROPS = "props",
|
312 | /**
|
313 | * a local alias of a `<script setup>` destructured prop.
|
314 | * the original is stored in __propsAliases of the bindingMetadata object.
|
315 | */
|
316 | PROPS_ALIASED = "props-aliased",
|
317 | /**
|
318 | * a let binding (may or may not be a ref)
|
319 | */
|
320 | SETUP_LET = "setup-let",
|
321 | /**
|
322 | * a const binding that can never be a ref.
|
323 | * these bindings don't need `unref()` calls when processed in inlined
|
324 | * template expressions.
|
325 | */
|
326 | SETUP_CONST = "setup-const",
|
327 | /**
|
328 | * a const binding that does not need `unref()`, but may be mutated.
|
329 | */
|
330 | SETUP_REACTIVE_CONST = "setup-reactive-const",
|
331 | /**
|
332 | * a const binding that may be a ref.
|
333 | */
|
334 | SETUP_MAYBE_REF = "setup-maybe-ref",
|
335 | /**
|
336 | * bindings that are guaranteed to be refs
|
337 | */
|
338 | SETUP_REF = "setup-ref",
|
339 | /**
|
340 | * declared by other options, e.g. computed, inject
|
341 | */
|
342 | OPTIONS = "options",
|
343 | /**
|
344 | * a literal constant, e.g. 'foo', 1, true
|
345 | */
|
346 | LITERAL_CONST = "literal-const"
|
347 | }
|
348 | type BindingMetadata = {
|
349 | [key: string]: BindingTypes | undefined;
|
350 | } & {
|
351 | __isScriptSetup?: boolean;
|
352 | __propsAliases?: Record<string, string>;
|
353 | };
|
354 |
|
355 | export declare class ScriptCompileContext {
|
356 | descriptor: SFCDescriptor;
|
357 | options: Partial<SFCScriptCompileOptions>;
|
358 | isJS: boolean;
|
359 | isTS: boolean;
|
360 | scriptAst: Program | null;
|
361 | scriptSetupAst: Program | null;
|
362 | source: string;
|
363 | filename: string;
|
364 | s: MagicString;
|
365 | startOffset: number | undefined;
|
366 | endOffset: number | undefined;
|
367 | scope?: TypeScope;
|
368 | globalScopes?: TypeScope[];
|
369 | userImports: Record<string, ImportBinding>;
|
370 | hasDefinePropsCall: boolean;
|
371 | hasDefineEmitCall: boolean;
|
372 | hasDefineExposeCall: boolean;
|
373 | hasDefaultExportName: boolean;
|
374 | hasDefaultExportRender: boolean;
|
375 | hasDefineOptionsCall: boolean;
|
376 | hasDefineSlotsCall: boolean;
|
377 | hasDefineModelCall: boolean;
|
378 | propsIdentifier: string | undefined;
|
379 | propsRuntimeDecl: Node | undefined;
|
380 | propsTypeDecl: Node | undefined;
|
381 | propsDestructureDecl: ObjectPattern | undefined;
|
382 | propsDestructuredBindings: PropsDestructureBindings;
|
383 | propsDestructureRestId: string | undefined;
|
384 | propsRuntimeDefaults: Node | undefined;
|
385 | emitsRuntimeDecl: Node | undefined;
|
386 | emitsTypeDecl: Node | undefined;
|
387 | emitIdentifier: string | undefined;
|
388 | modelDecls: Record<string, ModelDecl>;
|
389 | optionsRuntimeDecl: Node | undefined;
|
390 | bindingMetadata: BindingMetadata;
|
391 | helperImports: Set<string>;
|
392 | helper(key: string): string;
|
393 | /**
|
394 | * to be exposed on compiled script block for HMR cache busting
|
395 | */
|
396 | deps?: Set<string>;
|
397 | /**
|
398 | * cache for resolved fs
|
399 | */
|
400 | fs?: NonNullable<SFCScriptCompileOptions['fs']>;
|
401 | constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>);
|
402 | getString(node: Node, scriptSetup?: boolean): string;
|
403 | error(msg: string, node: Node, scope?: TypeScope): never;
|
404 | }
|
405 |
|
406 | /**
|
407 | * TypeResolveContext is compatible with ScriptCompileContext
|
408 | * but also allows a simpler version of it with minimal required properties
|
409 | * when resolveType needs to be used in a non-SFC context, e.g. in a babel
|
410 | * plugin. The simplest context can be just:
|
411 | * ```ts
|
412 | * const ctx: SimpleTypeResolveContext = {
|
413 | * filename: '...',
|
414 | * source: '...',
|
415 | * options: {},
|
416 | * error() {},
|
417 | * ast: []
|
418 | * }
|
419 | * ```
|
420 | */
|
421 | export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'options'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
|
422 | ast: Statement[];
|
423 | };
|
424 | export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext;
|
425 | type Import = Pick<ImportBinding, 'source' | 'imported'>;
|
426 | interface WithScope {
|
427 | _ownerScope: TypeScope;
|
428 | }
|
429 | type ScopeTypeNode = Node & WithScope & {
|
430 | _ns?: TSModuleDeclaration & WithScope;
|
431 | };
|
432 | declare class TypeScope {
|
433 | filename: string;
|
434 | source: string;
|
435 | offset: number;
|
436 | imports: Record<string, Import>;
|
437 | types: Record<string, ScopeTypeNode>;
|
438 | declares: Record<string, ScopeTypeNode>;
|
439 | constructor(filename: string, source: string, offset?: number, imports?: Record<string, Import>, types?: Record<string, ScopeTypeNode>, declares?: Record<string, ScopeTypeNode>);
|
440 | resolvedImportSources: Record<string, string>;
|
441 | exportedTypes: Record<string, ScopeTypeNode>;
|
442 | exportedDeclares: Record<string, ScopeTypeNode>;
|
443 | }
|
444 | interface MaybeWithScope {
|
445 | _ownerScope?: TypeScope;
|
446 | }
|
447 | interface ResolvedElements {
|
448 | props: Record<string, (TSPropertySignature | TSMethodSignature) & {
|
449 | _ownerScope: TypeScope;
|
450 | }>;
|
451 | calls?: (TSCallSignatureDeclaration | TSFunctionType)[];
|
452 | }
|
453 | /**
|
454 | * Resolve arbitrary type node to a list of type elements that can be then
|
455 | * mapped to runtime props or emits.
|
456 | */
|
457 | export declare function resolveTypeElements(ctx: TypeResolveContext, node: Node & MaybeWithScope & {
|
458 | _resolvedElements?: ResolvedElements;
|
459 | }, scope?: TypeScope): ResolvedElements;
|
460 | /**
|
461 | * @private
|
462 | */
|
463 | export declare function registerTS(_ts: any): void;
|
464 | /**
|
465 | * @private
|
466 | */
|
467 | export declare function invalidateTypeCache(filename: string): void;
|
468 | export declare function inferRuntimeType(ctx: TypeResolveContext, node: Node & MaybeWithScope, scope?: TypeScope): string[];
|
469 |
|
470 | export declare const version: string;
|
471 |
|
472 | export declare const walk: any;
|
473 |
|
474 |
|
\ | No newline at end of file |