@vue/compiler-sfc 3.2.47 → 3.3.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,317 +1,459 @@
1
- import { parse as babelParse } from '@babel/parser';
2
- import { BindingMetadata } from '@vue/compiler-core';
3
- import { CodegenResult } from '@vue/compiler-core';
4
- import { CompilerError } from '@vue/compiler-core';
5
- import { CompilerOptions } from '@vue/compiler-core';
6
- import { ElementNode } from '@vue/compiler-core';
7
- import { extractIdentifiers } from '@vue/compiler-core';
8
- import { generateCodeFrame } from '@vue/compiler-core';
9
- import { isInDestructureAssignment } from '@vue/compiler-core';
10
- import { isStaticProperty } from '@vue/compiler-core';
11
- import { LazyResult } from 'postcss';
12
- import MagicString from 'magic-string';
13
- import { ParserOptions } from '@vue/compiler-core';
14
- import { ParserPlugin } from '@babel/parser';
15
- import { RawSourceMap } from 'source-map';
16
- import { Result } from 'postcss';
17
- import { RootNode } from '@vue/compiler-core';
18
- import { shouldTransform as shouldTransformRef } from '@vue/reactivity-transform';
19
- import { SourceLocation } from '@vue/compiler-core';
20
- import { Statement } from '@babel/types';
21
- import { transform as transformRef } from '@vue/reactivity-transform';
22
- import { transformAST as transformRefAST } from '@vue/reactivity-transform';
23
- import { walkIdentifiers } from '@vue/compiler-core';
24
-
25
- export declare interface AssetURLOptions {
26
- /**
27
- * If base is provided, instead of transforming relative asset urls into
28
- * imports, they will be directly rewritten to absolute urls.
29
- */
30
- base?: string | null;
31
- /**
32
- * If true, also processes absolute urls.
33
- */
34
- includeAbsolute?: boolean;
35
- tags?: AssetURLTagConfig;
36
- }
37
-
38
- export declare interface AssetURLTagConfig {
39
- [name: string]: string[];
40
- }
41
-
42
- export { babelParse }
43
-
44
- export { BindingMetadata }
45
-
46
- export { CompilerError }
47
-
48
- export { CompilerOptions }
49
-
50
- /**
51
- * Compile `<script setup>`
52
- * It requires the whole SFC descriptor because we need to handle and merge
53
- * normal `<script>` + `<script setup>` if both are present.
54
- */
55
- export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
56
-
57
- export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
58
-
59
- export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
60
-
61
- export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
62
-
63
- /**
64
- * Aligns with postcss-modules
65
- * https://github.com/css-modules/postcss-modules
66
- */
67
- declare interface CSSModulesOptions {
68
- scopeBehaviour?: 'global' | 'local';
69
- generateScopedName?: string | ((name: string, filename: string, css: string) => string);
70
- hashPrefix?: string;
71
- localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
72
- exportGlobals?: boolean;
73
- globalModulePaths?: RegExp[];
74
- }
75
-
76
- export { extractIdentifiers }
77
-
78
- export { generateCodeFrame }
79
-
80
- declare interface ImportBinding {
81
- isType: boolean;
82
- imported: string;
83
- local: string;
84
- source: string;
85
- isFromSetup: boolean;
86
- isUsedInTemplate: boolean;
87
- }
88
-
89
- export { isInDestructureAssignment }
90
-
91
- export { isStaticProperty }
92
-
93
- export { MagicString }
94
-
95
- export declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, ignoreEmpty, compiler }?: SFCParseOptions): SFCParseResult;
96
-
97
- declare type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
98
-
99
- /**
100
- * Utility for rewriting `export default` in a script block into a variable
101
- * declaration so that we can inject things into it
102
- */
103
- export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
104
-
105
- export declare interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
106
- isAsync?: boolean;
107
- modules?: boolean;
108
- modulesOptions?: CSSModulesOptions;
109
- }
110
-
111
- export declare interface SFCBlock {
112
- type: string;
113
- content: string;
114
- attrs: Record<string, string | true>;
115
- loc: SourceLocation;
116
- map?: RawSourceMap;
117
- lang?: string;
118
- src?: string;
119
- }
120
-
121
- export declare interface SFCDescriptor {
122
- filename: string;
123
- source: string;
124
- template: SFCTemplateBlock | null;
125
- script: SFCScriptBlock | null;
126
- scriptSetup: SFCScriptBlock | null;
127
- styles: SFCStyleBlock[];
128
- customBlocks: SFCBlock[];
129
- cssVars: string[];
130
- /**
131
- * whether the SFC uses :slotted() modifier.
132
- * this is used as a compiler optimization hint.
133
- */
134
- slotted: boolean;
135
- /**
136
- * compare with an existing descriptor to determine whether HMR should perform
137
- * a reload vs. re-render.
138
- *
139
- * Note: this comparison assumes the prev/next script are already identical,
140
- * and only checks the special case where <script setup lang="ts"> unused import
141
- * pruning result changes due to template changes.
142
- */
143
- shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
144
- }
145
-
146
- export declare interface SFCParseOptions {
147
- filename?: string;
148
- sourceMap?: boolean;
149
- sourceRoot?: string;
150
- pad?: boolean | 'line' | 'space';
151
- ignoreEmpty?: boolean;
152
- compiler?: TemplateCompiler;
153
- }
154
-
155
- export declare interface SFCParseResult {
156
- descriptor: SFCDescriptor;
157
- errors: (CompilerError | SyntaxError)[];
158
- }
159
-
160
- export declare interface SFCScriptBlock extends SFCBlock {
161
- type: 'script';
162
- setup?: string | boolean;
163
- bindings?: BindingMetadata;
164
- imports?: Record<string, ImportBinding>;
165
- scriptAst?: Statement[];
166
- scriptSetupAst?: Statement[];
167
- }
168
-
169
- export declare interface SFCScriptCompileOptions {
170
- /**
171
- * Scope ID for prefixing injected CSS variables.
172
- * This must be consistent with the `id` passed to `compileStyle`.
173
- */
174
- id: string;
175
- /**
176
- * Production mode. Used to determine whether to generate hashed CSS variables
177
- */
178
- isProd?: boolean;
179
- /**
180
- * Enable/disable source map. Defaults to true.
181
- */
182
- sourceMap?: boolean;
183
- /**
184
- * https://babeljs.io/docs/en/babel-parser#plugins
185
- */
186
- babelParserPlugins?: ParserPlugin[];
187
- /**
188
- * (Experimental) Enable syntax transform for using refs without `.value` and
189
- * using destructured props with reactivity
190
- */
191
- reactivityTransform?: boolean;
192
- /**
193
- * (Experimental) Enable syntax transform for using refs without `.value`
194
- * https://github.com/vuejs/rfcs/discussions/369
195
- * @deprecated now part of `reactivityTransform`
196
- * @default false
197
- */
198
- refTransform?: boolean;
199
- /**
200
- * (Experimental) Enable syntax transform for destructuring from defineProps()
201
- * https://github.com/vuejs/rfcs/discussions/394
202
- * @deprecated now part of `reactivityTransform`
203
- * @default false
204
- */
205
- propsDestructureTransform?: boolean;
206
- /**
207
- * @deprecated use `reactivityTransform` instead.
208
- */
209
- refSugar?: boolean;
210
- /**
211
- * Compile the template and inline the resulting render function
212
- * directly inside setup().
213
- * - Only affects `<script setup>`
214
- * - This should only be used in production because it prevents the template
215
- * from being hot-reloaded separately from component state.
216
- */
217
- inlineTemplate?: boolean;
218
- /**
219
- * Options for template compilation when inlining. Note these are options that
220
- * would normally be passed to `compiler-sfc`'s own `compileTemplate()`, not
221
- * options passed to `compiler-dom`.
222
- */
223
- templateOptions?: Partial<SFCTemplateCompileOptions>;
224
- }
225
-
226
- export declare interface SFCStyleBlock extends SFCBlock {
227
- type: 'style';
228
- scoped?: boolean;
229
- module?: string | boolean;
230
- }
231
-
232
- export declare interface SFCStyleCompileOptions {
233
- source: string;
234
- filename: string;
235
- id: string;
236
- scoped?: boolean;
237
- trim?: boolean;
238
- isProd?: boolean;
239
- inMap?: RawSourceMap;
240
- preprocessLang?: PreprocessLang;
241
- preprocessOptions?: any;
242
- preprocessCustomRequire?: (id: string) => any;
243
- postcssOptions?: any;
244
- postcssPlugins?: any[];
245
- /**
246
- * @deprecated use `inMap` instead.
247
- */
248
- map?: RawSourceMap;
249
- }
250
-
251
- export declare interface SFCStyleCompileResults {
252
- code: string;
253
- map: RawSourceMap | undefined;
254
- rawResult: Result | LazyResult | undefined;
255
- errors: Error[];
256
- modules?: Record<string, string>;
257
- dependencies: Set<string>;
258
- }
259
-
260
- export declare interface SFCTemplateBlock extends SFCBlock {
261
- type: 'template';
262
- ast: ElementNode;
263
- }
264
-
265
- export declare interface SFCTemplateCompileOptions {
266
- source: string;
267
- filename: string;
268
- id: string;
269
- scoped?: boolean;
270
- slotted?: boolean;
271
- isProd?: boolean;
272
- ssr?: boolean;
273
- ssrCssVars?: string[];
274
- inMap?: RawSourceMap;
275
- compiler?: TemplateCompiler;
276
- compilerOptions?: CompilerOptions;
277
- preprocessLang?: string;
278
- preprocessOptions?: any;
279
- /**
280
- * In some cases, compiler-sfc may not be inside the project root (e.g. when
281
- * linked or globally installed). In such cases a custom `require` can be
282
- * passed to correctly resolve the preprocessors.
283
- */
284
- preprocessCustomRequire?: (id: string) => any;
285
- /**
286
- * Configure what tags/attributes to transform into asset url imports,
287
- * or disable the transform altogether with `false`.
288
- */
289
- transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
290
- }
291
-
292
- export declare interface SFCTemplateCompileResults {
293
- code: string;
294
- ast?: RootNode;
295
- preamble?: string;
296
- source: string;
297
- tips: string[];
298
- errors: (string | CompilerError)[];
299
- map?: RawSourceMap;
300
- }
301
-
302
- export { shouldTransformRef }
303
-
304
- export declare interface TemplateCompiler {
305
- compile(template: string, options: CompilerOptions): CodegenResult;
306
- parse(template: string, options: ParserOptions): RootNode;
307
- }
308
-
309
- export { transformRef }
310
-
311
- export { transformRefAST }
312
-
313
- export declare const walk: any;
314
-
315
- export { walkIdentifiers }
316
-
317
- export { }
1
+ import * as _babel_types from '@babel/types';
2
+ import { Statement, Expression, TSType, Program, Node, ObjectPattern, 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
+ * If base is provided, instead of transforming relative asset urls into
19
+ * imports, they will be directly rewritten to absolute urls.
20
+ */
21
+ base?: string | null;
22
+ /**
23
+ * If true, also processes absolute urls.
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
+ * In some cases, compiler-sfc may not be inside the project root (e.g. when
58
+ * linked or globally installed). In such cases a custom `require` can be
59
+ * passed to correctly resolve the preprocessors.
60
+ */
61
+ preprocessCustomRequire?: (id: string) => any;
62
+ /**
63
+ * Configure what tags/attributes to transform into asset url imports,
64
+ * or disable the transform altogether with `false`.
65
+ */
66
+ transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
67
+ }
68
+ export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
69
+
70
+ export interface SFCScriptCompileOptions {
71
+ /**
72
+ * Scope ID for prefixing injected CSS variables.
73
+ * This must be consistent with the `id` passed to `compileStyle`.
74
+ */
75
+ id: string;
76
+ /**
77
+ * Production mode. Used to determine whether to generate hashed CSS variables
78
+ */
79
+ isProd?: boolean;
80
+ /**
81
+ * Enable/disable source map. Defaults to true.
82
+ */
83
+ sourceMap?: boolean;
84
+ /**
85
+ * https://babeljs.io/docs/en/babel-parser#plugins
86
+ */
87
+ babelParserPlugins?: ParserPlugin[];
88
+ /**
89
+ * A list of files to parse for global types to be made available for type
90
+ * resolving in SFC macros. The list must be fully resolved file system paths.
91
+ */
92
+ globalTypeFiles?: string[];
93
+ /**
94
+ * Compile the template and inline the resulting render function
95
+ * directly inside setup().
96
+ * - Only affects `<script setup>`
97
+ * - This should only be used in production because it prevents the template
98
+ * from being hot-reloaded separately from component state.
99
+ */
100
+ inlineTemplate?: boolean;
101
+ /**
102
+ * Generate the final component as a variable instead of default export.
103
+ * This is useful in e.g. @vitejs/plugin-vue where the script needs to be
104
+ * placed inside the main module.
105
+ */
106
+ genDefaultAs?: string;
107
+ /**
108
+ * Options for template compilation when inlining. Note these are options that
109
+ * would normally be passed to `compiler-sfc`'s own `compileTemplate()`, not
110
+ * options passed to `compiler-dom`.
111
+ */
112
+ templateOptions?: Partial<SFCTemplateCompileOptions>;
113
+ /**
114
+ * Hoist <script setup> static constants.
115
+ * - Only enables when one `<script setup>` exists.
116
+ * @default true
117
+ */
118
+ hoistStatic?: boolean;
119
+ /**
120
+ * (**Experimental**) Enable macro `defineModel`
121
+ * @default false
122
+ */
123
+ defineModel?: boolean;
124
+ /**
125
+ * (**Experimental**) Enable reactive destructure for `defineProps`
126
+ * @default false
127
+ */
128
+ propsDestructure?: boolean;
129
+ /**
130
+ * File system access methods to be used when resolving types
131
+ * imported in SFC macros. Defaults to ts.sys in Node.js, can be overwritten
132
+ * to use a virtual file system for use in browsers (e.g. in REPLs)
133
+ */
134
+ fs?: {
135
+ fileExists(file: string): boolean;
136
+ readFile(file: string): string | undefined;
137
+ };
138
+ /**
139
+ * (Experimental) Enable syntax transform for using refs without `.value` and
140
+ * using destructured props with reactivity
141
+ * @deprecated the Reactivity Transform proposal has been dropped. This
142
+ * feature will be removed from Vue core in 3.4. If you intend to continue
143
+ * using it, disable this and switch to the [Vue Macros implementation](https://vue-macros.sxzz.moe/features/reactivity-transform.html).
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
+ * Compile `<script setup>`
157
+ * It requires the whole SFC descriptor because we need to handle and merge
158
+ * normal `<script>` + `<script setup>` if both are present.
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
+ * Fully resolved dependency file paths (unix slashes) with imported types
193
+ * used in macros, used for HMR cache busting in @vitejs/plugin-vue and
194
+ * vue-loader.
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
+ * whether the SFC uses :slotted() modifier.
214
+ * this is used as a compiler optimization hint.
215
+ */
216
+ slotted: boolean;
217
+ /**
218
+ * compare with an existing descriptor to determine whether HMR should perform
219
+ * a reload vs. re-render.
220
+ *
221
+ * Note: this comparison assumes the prev/next script are already identical,
222
+ * and only checks the special case where <script setup lang="ts"> unused import
223
+ * pruning result changes due to template changes.
224
+ */
225
+ shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
226
+ }
227
+ export interface SFCParseResult {
228
+ descriptor: SFCDescriptor;
229
+ errors: (CompilerError | SyntaxError)[];
230
+ }
231
+ export declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, ignoreEmpty, compiler }?: SFCParseOptions): SFCParseResult;
232
+
233
+ type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
234
+
235
+ export interface SFCStyleCompileOptions {
236
+ source: string;
237
+ filename: string;
238
+ id: string;
239
+ scoped?: boolean;
240
+ trim?: boolean;
241
+ isProd?: boolean;
242
+ inMap?: RawSourceMap;
243
+ preprocessLang?: PreprocessLang;
244
+ preprocessOptions?: any;
245
+ preprocessCustomRequire?: (id: string) => any;
246
+ postcssOptions?: any;
247
+ postcssPlugins?: any[];
248
+ /**
249
+ * @deprecated use `inMap` instead.
250
+ */
251
+ map?: RawSourceMap;
252
+ }
253
+ /**
254
+ * Aligns with postcss-modules
255
+ * https://github.com/css-modules/postcss-modules
256
+ */
257
+ interface CSSModulesOptions {
258
+ scopeBehaviour?: 'global' | 'local';
259
+ generateScopedName?: string | ((name: string, filename: string, css: string) => string);
260
+ hashPrefix?: string;
261
+ localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
262
+ exportGlobals?: boolean;
263
+ globalModulePaths?: RegExp[];
264
+ }
265
+ export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
266
+ isAsync?: boolean;
267
+ modules?: boolean;
268
+ modulesOptions?: CSSModulesOptions;
269
+ }
270
+ export interface SFCStyleCompileResults {
271
+ code: string;
272
+ map: RawSourceMap | undefined;
273
+ rawResult: Result | LazyResult | undefined;
274
+ errors: Error[];
275
+ modules?: Record<string, string>;
276
+ dependencies: Set<string>;
277
+ }
278
+ export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
279
+ export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
280
+
281
+ export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
282
+ /**
283
+ * Utility for rewriting `export default` in a script block into a variable
284
+ * declaration so that we can inject things into it
285
+ */
286
+ export declare function rewriteDefaultAST(ast: Statement[], s: MagicString, as: string): void;
287
+
288
+ type PropsDestructureBindings = Record<string, // public prop key
289
+ {
290
+ local: string;
291
+ default?: Expression;
292
+ }>;
293
+
294
+ interface ModelDecl {
295
+ type: TSType | undefined;
296
+ options: string | undefined;
297
+ identifier: string | undefined;
298
+ }
299
+
300
+ declare const enum BindingTypes {
301
+ /**
302
+ * returned from data()
303
+ */
304
+ DATA = "data",
305
+ /**
306
+ * declared as a prop
307
+ */
308
+ PROPS = "props",
309
+ /**
310
+ * a local alias of a `<script setup>` destructured prop.
311
+ * the original is stored in __propsAliases of the bindingMetadata object.
312
+ */
313
+ PROPS_ALIASED = "props-aliased",
314
+ /**
315
+ * a let binding (may or may not be a ref)
316
+ */
317
+ SETUP_LET = "setup-let",
318
+ /**
319
+ * a const binding that can never be a ref.
320
+ * these bindings don't need `unref()` calls when processed in inlined
321
+ * template expressions.
322
+ */
323
+ SETUP_CONST = "setup-const",
324
+ /**
325
+ * a const binding that does not need `unref()`, but may be mutated.
326
+ */
327
+ SETUP_REACTIVE_CONST = "setup-reactive-const",
328
+ /**
329
+ * a const binding that may be a ref.
330
+ */
331
+ SETUP_MAYBE_REF = "setup-maybe-ref",
332
+ /**
333
+ * bindings that are guaranteed to be refs
334
+ */
335
+ SETUP_REF = "setup-ref",
336
+ /**
337
+ * declared by other options, e.g. computed, inject
338
+ */
339
+ OPTIONS = "options",
340
+ /**
341
+ * a literal constant, e.g. 'foo', 1, true
342
+ */
343
+ LITERAL_CONST = "literal-const"
344
+ }
345
+ type BindingMetadata = {
346
+ [key: string]: BindingTypes | undefined;
347
+ } & {
348
+ __isScriptSetup?: boolean;
349
+ __propsAliases?: Record<string, string>;
350
+ };
351
+
352
+ export declare class ScriptCompileContext {
353
+ descriptor: SFCDescriptor;
354
+ options: Partial<SFCScriptCompileOptions>;
355
+ isJS: boolean;
356
+ isTS: boolean;
357
+ scriptAst: Program | null;
358
+ scriptSetupAst: Program | null;
359
+ source: string;
360
+ filename: string;
361
+ s: MagicString;
362
+ startOffset: number | undefined;
363
+ endOffset: number | undefined;
364
+ scope?: TypeScope;
365
+ globalScopes?: TypeScope[];
366
+ userImports: Record<string, ImportBinding>;
367
+ hasDefinePropsCall: boolean;
368
+ hasDefineEmitCall: boolean;
369
+ hasDefineExposeCall: boolean;
370
+ hasDefaultExportName: boolean;
371
+ hasDefaultExportRender: boolean;
372
+ hasDefineOptionsCall: boolean;
373
+ hasDefineSlotsCall: boolean;
374
+ hasDefineModelCall: boolean;
375
+ propsIdentifier: string | undefined;
376
+ propsRuntimeDecl: Node | undefined;
377
+ propsTypeDecl: Node | undefined;
378
+ propsDestructureDecl: ObjectPattern | undefined;
379
+ propsDestructuredBindings: PropsDestructureBindings;
380
+ propsDestructureRestId: string | undefined;
381
+ propsRuntimeDefaults: Node | undefined;
382
+ emitsRuntimeDecl: Node | undefined;
383
+ emitsTypeDecl: Node | undefined;
384
+ emitIdentifier: string | undefined;
385
+ modelDecls: Record<string, ModelDecl>;
386
+ optionsRuntimeDecl: Node | undefined;
387
+ bindingMetadata: BindingMetadata;
388
+ helperImports: Set<string>;
389
+ helper(key: string): string;
390
+ /**
391
+ * to be exposed on compiled script block for HMR cache busting
392
+ */
393
+ deps?: Set<string>;
394
+ constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>);
395
+ getString(node: Node, scriptSetup?: boolean): string;
396
+ error(msg: string, node: Node, scope?: TypeScope): never;
397
+ }
398
+
399
+ /**
400
+ * TypeResolveContext is compatible with ScriptCompileContext
401
+ * but also allows a simpler version of it with minimal required properties
402
+ * when resolveType needs to be used in a non-SFC context, e.g. in a babel
403
+ * plugin. The simplest context can be just:
404
+ * ```ts
405
+ * const ctx: SimpleTypeResolveContext = {
406
+ * filename: '...',
407
+ * source: '...',
408
+ * options: {},
409
+ * error() {},
410
+ * ast: []
411
+ * }
412
+ * ```
413
+ */
414
+ export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'options'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps'>> & {
415
+ ast: Statement[];
416
+ };
417
+ export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext;
418
+ type Import = Pick<ImportBinding, 'source' | 'imported'>;
419
+ type ScopeTypeNode = Node & {
420
+ _ownerScope: TypeScope;
421
+ };
422
+ interface TypeScope {
423
+ filename: string;
424
+ source: string;
425
+ offset: number;
426
+ imports: Record<string, Import>;
427
+ types: Record<string, ScopeTypeNode>;
428
+ exportedTypes: Record<string, ScopeTypeNode>;
429
+ }
430
+ interface WithScope {
431
+ _ownerScope?: TypeScope;
432
+ }
433
+ interface ResolvedElements {
434
+ props: Record<string, (TSPropertySignature | TSMethodSignature) & {
435
+ _ownerScope: TypeScope;
436
+ }>;
437
+ calls?: (TSCallSignatureDeclaration | TSFunctionType)[];
438
+ }
439
+ /**
440
+ * Resolve arbitrary type node to a list of type elements that can be then
441
+ * mapped to runtime props or emits.
442
+ */
443
+ export declare function resolveTypeElements(ctx: TypeResolveContext, node: Node & WithScope & {
444
+ _resolvedElements?: ResolvedElements;
445
+ }, scope?: TypeScope): ResolvedElements;
446
+ /**
447
+ * @private
448
+ */
449
+ export declare function registerTS(_ts: any): void;
450
+ /**
451
+ * @private
452
+ */
453
+ export declare function invalidateTypeCache(filename: string): void;
454
+ export declare function inferRuntimeType(ctx: TypeResolveContext, node: Node & WithScope, scope?: TypeScope): string[];
455
+
456
+ export declare const version: string;
457
+
458
+ export declare const walk: any;
459
+