@vue/compiler-sfc 3.2.46 → 3.3.0-alpha.1

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,259 @@
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 { CompilerOptions, CodegenResult, ParserOptions, RootNode, CompilerError, SourceLocation, ElementNode, BindingMetadata } from '@vue/compiler-core';
3
+ export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core';
4
+ import { RawSourceMap } from 'source-map';
5
+ import { ParserPlugin } from '@babel/parser';
6
+ export { parse as babelParse } from '@babel/parser';
7
+ import { Result, LazyResult } from 'postcss';
8
+ export { shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST } from '@vue/reactivity-transform';
9
+ export { default as MagicString } from 'magic-string';
10
+
11
+ export interface AssetURLTagConfig {
12
+ [name: string]: string[];
13
+ }
14
+ export interface AssetURLOptions {
15
+ /**
16
+ * If base is provided, instead of transforming relative asset urls into
17
+ * imports, they will be directly rewritten to absolute urls.
18
+ */
19
+ base?: string | null;
20
+ /**
21
+ * If true, also processes absolute urls.
22
+ */
23
+ includeAbsolute?: boolean;
24
+ tags?: AssetURLTagConfig;
25
+ }
26
+
27
+ export interface TemplateCompiler {
28
+ compile(template: string, options: CompilerOptions): CodegenResult;
29
+ parse(template: string, options: ParserOptions): RootNode;
30
+ }
31
+ export interface SFCTemplateCompileResults {
32
+ code: string;
33
+ ast?: RootNode;
34
+ preamble?: string;
35
+ source: string;
36
+ tips: string[];
37
+ errors: (string | CompilerError)[];
38
+ map?: RawSourceMap;
39
+ }
40
+ export interface SFCTemplateCompileOptions {
41
+ source: string;
42
+ filename: string;
43
+ id: string;
44
+ scoped?: boolean;
45
+ slotted?: boolean;
46
+ isProd?: boolean;
47
+ ssr?: boolean;
48
+ ssrCssVars?: string[];
49
+ inMap?: RawSourceMap;
50
+ compiler?: TemplateCompiler;
51
+ compilerOptions?: CompilerOptions;
52
+ preprocessLang?: string;
53
+ preprocessOptions?: any;
54
+ /**
55
+ * In some cases, compiler-sfc may not be inside the project root (e.g. when
56
+ * linked or globally installed). In such cases a custom `require` can be
57
+ * passed to correctly resolve the preprocessors.
58
+ */
59
+ preprocessCustomRequire?: (id: string) => any;
60
+ /**
61
+ * Configure what tags/attributes to transform into asset url imports,
62
+ * or disable the transform altogether with `false`.
63
+ */
64
+ transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean;
65
+ }
66
+ declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
67
+
68
+ export interface SFCScriptCompileOptions {
69
+ /**
70
+ * Scope ID for prefixing injected CSS variables.
71
+ * This must be consistent with the `id` passed to `compileStyle`.
72
+ */
73
+ id: string;
74
+ /**
75
+ * Production mode. Used to determine whether to generate hashed CSS variables
76
+ */
77
+ isProd?: boolean;
78
+ /**
79
+ * Enable/disable source map. Defaults to true.
80
+ */
81
+ sourceMap?: boolean;
82
+ /**
83
+ * https://babeljs.io/docs/en/babel-parser#plugins
84
+ */
85
+ babelParserPlugins?: ParserPlugin[];
86
+ /**
87
+ * (Experimental) Enable syntax transform for using refs without `.value` and
88
+ * using destructured props with reactivity
89
+ */
90
+ reactivityTransform?: boolean;
91
+ /**
92
+ * (Experimental) Enable syntax transform for using refs without `.value`
93
+ * https://github.com/vuejs/rfcs/discussions/369
94
+ * @deprecated now part of `reactivityTransform`
95
+ * @default false
96
+ */
97
+ refTransform?: boolean;
98
+ /**
99
+ * (Experimental) Enable syntax transform for destructuring from defineProps()
100
+ * https://github.com/vuejs/rfcs/discussions/394
101
+ * @deprecated now part of `reactivityTransform`
102
+ * @default false
103
+ */
104
+ propsDestructureTransform?: boolean;
105
+ /**
106
+ * @deprecated use `reactivityTransform` instead.
107
+ */
108
+ refSugar?: boolean;
109
+ /**
110
+ * Compile the template and inline the resulting render function
111
+ * directly inside setup().
112
+ * - Only affects `<script setup>`
113
+ * - This should only be used in production because it prevents the template
114
+ * from being hot-reloaded separately from component state.
115
+ */
116
+ inlineTemplate?: boolean;
117
+ /**
118
+ * Options for template compilation when inlining. Note these are options that
119
+ * would normally be passed to `compiler-sfc`'s own `compileTemplate()`, not
120
+ * options passed to `compiler-dom`.
121
+ */
122
+ templateOptions?: Partial<SFCTemplateCompileOptions>;
123
+ }
124
+ export interface ImportBinding {
125
+ isType: boolean;
126
+ imported: string;
127
+ local: string;
128
+ source: string;
129
+ isFromSetup: boolean;
130
+ isUsedInTemplate: boolean;
131
+ }
132
+ /**
133
+ * Compile `<script setup>`
134
+ * It requires the whole SFC descriptor because we need to handle and merge
135
+ * normal `<script>` + `<script setup>` if both are present.
136
+ */
137
+ declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock;
138
+
139
+ export interface SFCParseOptions {
140
+ filename?: string;
141
+ sourceMap?: boolean;
142
+ sourceRoot?: string;
143
+ pad?: boolean | 'line' | 'space';
144
+ ignoreEmpty?: boolean;
145
+ compiler?: TemplateCompiler;
146
+ }
147
+ export interface SFCBlock {
148
+ type: string;
149
+ content: string;
150
+ attrs: Record<string, string | true>;
151
+ loc: SourceLocation;
152
+ map?: RawSourceMap;
153
+ lang?: string;
154
+ src?: string;
155
+ }
156
+ export interface SFCTemplateBlock extends SFCBlock {
157
+ type: 'template';
158
+ ast: ElementNode;
159
+ }
160
+ export interface SFCScriptBlock extends SFCBlock {
161
+ type: 'script';
162
+ setup?: string | boolean;
163
+ bindings?: BindingMetadata;
164
+ imports?: Record<string, ImportBinding>;
165
+ scriptAst?: _babel_types.Statement[];
166
+ scriptSetupAst?: _babel_types.Statement[];
167
+ }
168
+ export interface SFCStyleBlock extends SFCBlock {
169
+ type: 'style';
170
+ scoped?: boolean;
171
+ module?: string | boolean;
172
+ }
173
+ export interface SFCDescriptor {
174
+ filename: string;
175
+ source: string;
176
+ template: SFCTemplateBlock | null;
177
+ script: SFCScriptBlock | null;
178
+ scriptSetup: SFCScriptBlock | null;
179
+ styles: SFCStyleBlock[];
180
+ customBlocks: SFCBlock[];
181
+ cssVars: string[];
182
+ /**
183
+ * whether the SFC uses :slotted() modifier.
184
+ * this is used as a compiler optimization hint.
185
+ */
186
+ slotted: boolean;
187
+ /**
188
+ * compare with an existing descriptor to determine whether HMR should perform
189
+ * a reload vs. re-render.
190
+ *
191
+ * Note: this comparison assumes the prev/next script are already identical,
192
+ * and only checks the special case where <script setup lang="ts"> unused import
193
+ * pruning result changes due to template changes.
194
+ */
195
+ shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
196
+ }
197
+ export interface SFCParseResult {
198
+ descriptor: SFCDescriptor;
199
+ errors: (CompilerError | SyntaxError)[];
200
+ }
201
+ declare function parse(source: string, { sourceMap, filename, sourceRoot, pad, ignoreEmpty, compiler }?: SFCParseOptions): SFCParseResult;
202
+
203
+ export type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus';
204
+
205
+ export interface SFCStyleCompileOptions {
206
+ source: string;
207
+ filename: string;
208
+ id: string;
209
+ scoped?: boolean;
210
+ trim?: boolean;
211
+ isProd?: boolean;
212
+ inMap?: RawSourceMap;
213
+ preprocessLang?: PreprocessLang;
214
+ preprocessOptions?: any;
215
+ preprocessCustomRequire?: (id: string) => any;
216
+ postcssOptions?: any;
217
+ postcssPlugins?: any[];
218
+ /**
219
+ * @deprecated use `inMap` instead.
220
+ */
221
+ map?: RawSourceMap;
222
+ }
223
+ /**
224
+ * Aligns with postcss-modules
225
+ * https://github.com/css-modules/postcss-modules
226
+ */
227
+ export interface CSSModulesOptions {
228
+ scopeBehaviour?: 'global' | 'local';
229
+ generateScopedName?: string | ((name: string, filename: string, css: string) => string);
230
+ hashPrefix?: string;
231
+ localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
232
+ exportGlobals?: boolean;
233
+ globalModulePaths?: RegExp[];
234
+ }
235
+ export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
236
+ isAsync?: boolean;
237
+ modules?: boolean;
238
+ modulesOptions?: CSSModulesOptions;
239
+ }
240
+ export interface SFCStyleCompileResults {
241
+ code: string;
242
+ map: RawSourceMap | undefined;
243
+ rawResult: Result | LazyResult | undefined;
244
+ errors: Error[];
245
+ modules?: Record<string, string>;
246
+ dependencies: Set<string>;
247
+ }
248
+ declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
249
+ declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>;
250
+
251
+ /**
252
+ * Utility for rewriting `export default` in a script block into a variable
253
+ * declaration so that we can inject things into it
254
+ */
255
+ declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
256
+
257
+ declare const walk: any;
258
+
259
+ export { compileScript, compileStyle, compileStyleAsync, compileTemplate, parse, rewriteDefault, walk };