@vue/compiler-sfc 2.7.0-alpha.8 → 2.7.0-beta.2
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.
- package/dist/compiler-sfc.d.ts +234 -55
- package/dist/compiler-sfc.js +159 -69
- package/package.json +1 -1
package/dist/compiler-sfc.d.ts
CHANGED
|
@@ -5,6 +5,144 @@ declare interface AssetURLOptions {
|
|
|
5
5
|
[name: string]: string | string[];
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
declare type ASTAttr = {
|
|
9
|
+
name: string;
|
|
10
|
+
value: any;
|
|
11
|
+
dynamic?: boolean;
|
|
12
|
+
start?: number;
|
|
13
|
+
end?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare type ASTDirective = {
|
|
17
|
+
name: string;
|
|
18
|
+
rawName: string;
|
|
19
|
+
value: string;
|
|
20
|
+
arg: string | null;
|
|
21
|
+
isDynamicArg: boolean;
|
|
22
|
+
modifiers: ASTModifiers | null;
|
|
23
|
+
start?: number;
|
|
24
|
+
end?: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare type ASTElement = {
|
|
28
|
+
type: 1;
|
|
29
|
+
tag: string;
|
|
30
|
+
attrsList: Array<ASTAttr>;
|
|
31
|
+
attrsMap: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
};
|
|
34
|
+
rawAttrsMap: {
|
|
35
|
+
[key: string]: ASTAttr;
|
|
36
|
+
};
|
|
37
|
+
parent: ASTElement | void;
|
|
38
|
+
children: Array<ASTNode>;
|
|
39
|
+
start?: number;
|
|
40
|
+
end?: number;
|
|
41
|
+
processed?: true;
|
|
42
|
+
static?: boolean;
|
|
43
|
+
staticRoot?: boolean;
|
|
44
|
+
staticInFor?: boolean;
|
|
45
|
+
staticProcessed?: boolean;
|
|
46
|
+
hasBindings?: boolean;
|
|
47
|
+
text?: string;
|
|
48
|
+
attrs?: Array<ASTAttr>;
|
|
49
|
+
dynamicAttrs?: Array<ASTAttr>;
|
|
50
|
+
props?: Array<ASTAttr>;
|
|
51
|
+
plain?: boolean;
|
|
52
|
+
pre?: true;
|
|
53
|
+
ns?: string;
|
|
54
|
+
component?: string;
|
|
55
|
+
inlineTemplate?: true;
|
|
56
|
+
transitionMode?: string | null;
|
|
57
|
+
slotName?: string | null;
|
|
58
|
+
slotTarget?: string | null;
|
|
59
|
+
slotTargetDynamic?: boolean;
|
|
60
|
+
slotScope?: string | null;
|
|
61
|
+
scopedSlots?: {
|
|
62
|
+
[name: string]: ASTElement;
|
|
63
|
+
};
|
|
64
|
+
ref?: string;
|
|
65
|
+
refInFor?: boolean;
|
|
66
|
+
if?: string;
|
|
67
|
+
ifProcessed?: boolean;
|
|
68
|
+
elseif?: string;
|
|
69
|
+
else?: true;
|
|
70
|
+
ifConditions?: ASTIfConditions;
|
|
71
|
+
for?: string;
|
|
72
|
+
forProcessed?: boolean;
|
|
73
|
+
key?: string;
|
|
74
|
+
alias?: string;
|
|
75
|
+
iterator1?: string;
|
|
76
|
+
iterator2?: string;
|
|
77
|
+
staticClass?: string;
|
|
78
|
+
classBinding?: string;
|
|
79
|
+
staticStyle?: string;
|
|
80
|
+
styleBinding?: string;
|
|
81
|
+
events?: ASTElementHandlers;
|
|
82
|
+
nativeEvents?: ASTElementHandlers;
|
|
83
|
+
transition?: string | true;
|
|
84
|
+
transitionOnAppear?: boolean;
|
|
85
|
+
model?: {
|
|
86
|
+
value: string;
|
|
87
|
+
callback: string;
|
|
88
|
+
expression: string;
|
|
89
|
+
};
|
|
90
|
+
directives?: Array<ASTDirective>;
|
|
91
|
+
forbidden?: true;
|
|
92
|
+
once?: true;
|
|
93
|
+
onceProcessed?: boolean;
|
|
94
|
+
wrapData?: (code: string) => string;
|
|
95
|
+
wrapListeners?: (code: string) => string;
|
|
96
|
+
ssrOptimizability?: number;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
declare type ASTElementHandler = {
|
|
100
|
+
value: string;
|
|
101
|
+
params?: Array<any>;
|
|
102
|
+
modifiers: ASTModifiers | null;
|
|
103
|
+
dynamic?: boolean;
|
|
104
|
+
start?: number;
|
|
105
|
+
end?: number;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
declare type ASTElementHandlers = {
|
|
109
|
+
[key: string]: ASTElementHandler | Array<ASTElementHandler>;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
declare type ASTExpression = {
|
|
113
|
+
type: 2;
|
|
114
|
+
expression: string;
|
|
115
|
+
text: string;
|
|
116
|
+
tokens: Array<string | Object>;
|
|
117
|
+
static?: boolean;
|
|
118
|
+
ssrOptimizability?: number;
|
|
119
|
+
start?: number;
|
|
120
|
+
end?: number;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
declare type ASTIfCondition = {
|
|
124
|
+
exp: string | null;
|
|
125
|
+
block: ASTElement;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
declare type ASTIfConditions = Array<ASTIfCondition>;
|
|
129
|
+
|
|
130
|
+
declare type ASTModifiers = {
|
|
131
|
+
[key: string]: boolean;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
declare type ASTNode = ASTElement | ASTText | ASTExpression;
|
|
135
|
+
|
|
136
|
+
declare type ASTText = {
|
|
137
|
+
type: 3;
|
|
138
|
+
text: string;
|
|
139
|
+
static?: boolean;
|
|
140
|
+
isComment?: boolean;
|
|
141
|
+
ssrOptimizability?: number;
|
|
142
|
+
start?: number;
|
|
143
|
+
end?: number;
|
|
144
|
+
};
|
|
145
|
+
|
|
8
146
|
declare type BindingMetadata = {
|
|
9
147
|
[key: string]: BindingTypes | undefined;
|
|
10
148
|
} & {
|
|
@@ -53,18 +191,56 @@ declare const enum BindingTypes {
|
|
|
53
191
|
OPTIONS = "options"
|
|
54
192
|
}
|
|
55
193
|
|
|
194
|
+
declare type CompiledResult = {
|
|
195
|
+
ast: ASTElement | null;
|
|
196
|
+
render: string;
|
|
197
|
+
staticRenderFns: Array<string>;
|
|
198
|
+
stringRenderFns?: Array<string>;
|
|
199
|
+
errors?: Array<string | WarningMessage>;
|
|
200
|
+
tips?: Array<string | WarningMessage>;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export declare type CompilerOptions = {
|
|
204
|
+
warn?: Function;
|
|
205
|
+
modules?: Array<ModuleOptions>;
|
|
206
|
+
directives?: {
|
|
207
|
+
[key: string]: Function;
|
|
208
|
+
};
|
|
209
|
+
staticKeys?: string;
|
|
210
|
+
isUnaryTag?: (tag: string) => boolean | undefined;
|
|
211
|
+
canBeLeftOpenTag?: (tag: string) => boolean | undefined;
|
|
212
|
+
isReservedTag?: (tag: string) => boolean | undefined;
|
|
213
|
+
preserveWhitespace?: boolean;
|
|
214
|
+
whitespace?: 'preserve' | 'condense';
|
|
215
|
+
optimize?: boolean;
|
|
216
|
+
mustUseProp?: (tag: string, type: string | null, name: string) => boolean;
|
|
217
|
+
isPreTag?: (attr: string) => boolean | null;
|
|
218
|
+
getTagNamespace?: (tag: string) => string | undefined;
|
|
219
|
+
expectHTML?: boolean;
|
|
220
|
+
isFromDOM?: boolean;
|
|
221
|
+
shouldDecodeTags?: boolean;
|
|
222
|
+
shouldDecodeNewlines?: boolean;
|
|
223
|
+
shouldDecodeNewlinesForHref?: boolean;
|
|
224
|
+
outputSourceRange?: boolean;
|
|
225
|
+
shouldKeepComment?: boolean;
|
|
226
|
+
delimiters?: [string, string];
|
|
227
|
+
comments?: boolean;
|
|
228
|
+
scopeId?: string;
|
|
229
|
+
bindings?: BindingMetadata;
|
|
230
|
+
};
|
|
231
|
+
|
|
56
232
|
/**
|
|
57
233
|
* Compile `<script setup>`
|
|
58
234
|
* It requires the whole SFC descriptor because we need to handle and merge
|
|
59
235
|
* normal `<script>` + `<script setup>` if both are present.
|
|
60
236
|
*/
|
|
61
|
-
export declare function compileScript(sfc: SFCDescriptor, options?:
|
|
237
|
+
export declare function compileScript(sfc: SFCDescriptor, options?: SFCScriptCompileOptions): SFCScriptBlock;
|
|
62
238
|
|
|
63
|
-
export declare function compileStyle(options:
|
|
239
|
+
export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults;
|
|
64
240
|
|
|
65
|
-
export declare function compileStyleAsync(options:
|
|
241
|
+
export declare function compileStyleAsync(options: SFCStyleCompileOptions): Promise<SFCStyleCompileResults>;
|
|
66
242
|
|
|
67
|
-
export declare function compileTemplate(options:
|
|
243
|
+
export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults;
|
|
68
244
|
|
|
69
245
|
export declare function generateCodeFrame(source: string, start?: number, end?: number): string;
|
|
70
246
|
|
|
@@ -76,15 +252,24 @@ declare interface ImportBinding {
|
|
|
76
252
|
isUsedInTemplate: boolean;
|
|
77
253
|
}
|
|
78
254
|
|
|
255
|
+
declare type ModuleOptions = {
|
|
256
|
+
preTransformNode?: (el: ASTElement) => ASTElement | null | void;
|
|
257
|
+
transformNode?: (el: ASTElement) => ASTElement | null | void;
|
|
258
|
+
postTransformNode?: (el: ASTElement) => void;
|
|
259
|
+
genData?: (el: ASTElement) => string;
|
|
260
|
+
transformCode?: (el: ASTElement, code: string) => string;
|
|
261
|
+
staticKeys?: Array<string>;
|
|
262
|
+
};
|
|
263
|
+
|
|
79
264
|
export declare function parse(options: ParseOptions): SFCDescriptor;
|
|
80
265
|
|
|
81
266
|
declare interface ParseOptions {
|
|
82
267
|
source: string;
|
|
83
268
|
filename?: string;
|
|
84
|
-
compiler?:
|
|
269
|
+
compiler?: TemplateCompiler;
|
|
85
270
|
compilerParseOptions?: VueTemplateCompilerParseOptions;
|
|
86
271
|
sourceRoot?: string;
|
|
87
|
-
|
|
272
|
+
sourceMap?: boolean;
|
|
88
273
|
}
|
|
89
274
|
|
|
90
275
|
declare interface RawSourceMap extends StartOfSourceMap {
|
|
@@ -95,24 +280,14 @@ declare interface RawSourceMap extends StartOfSourceMap {
|
|
|
95
280
|
mappings: string;
|
|
96
281
|
}
|
|
97
282
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Enable/disable source map. Defaults to true.
|
|
105
|
-
*/
|
|
106
|
-
sourceMap?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* https://babeljs.io/docs/en/babel-parser#plugins
|
|
109
|
-
*/
|
|
110
|
-
babelParserPlugins?: ParserPlugin[];
|
|
111
|
-
}
|
|
283
|
+
/**
|
|
284
|
+
* Utility for rewriting `export default` in a script block into a variable
|
|
285
|
+
* declaration so that we can inject things into it
|
|
286
|
+
*/
|
|
287
|
+
export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string;
|
|
112
288
|
|
|
113
289
|
export declare interface SFCBlock extends SFCCustomBlock {
|
|
114
290
|
lang?: string;
|
|
115
|
-
src?: string;
|
|
116
291
|
scoped?: boolean;
|
|
117
292
|
module?: string | boolean;
|
|
118
293
|
}
|
|
@@ -125,6 +300,7 @@ export declare interface SFCCustomBlock {
|
|
|
125
300
|
};
|
|
126
301
|
start: number;
|
|
127
302
|
end: number;
|
|
303
|
+
src?: string;
|
|
128
304
|
map?: RawSourceMap;
|
|
129
305
|
}
|
|
130
306
|
|
|
@@ -148,7 +324,7 @@ export declare interface SFCDescriptor {
|
|
|
148
324
|
shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean;
|
|
149
325
|
}
|
|
150
326
|
|
|
151
|
-
declare interface SFCScriptBlock extends SFCBlock {
|
|
327
|
+
export declare interface SFCScriptBlock extends SFCBlock {
|
|
152
328
|
type: 'script';
|
|
153
329
|
setup?: string | boolean;
|
|
154
330
|
bindings?: BindingMetadata;
|
|
@@ -163,12 +339,22 @@ declare interface SFCScriptBlock extends SFCBlock {
|
|
|
163
339
|
scriptSetupAst?: any[];
|
|
164
340
|
}
|
|
165
341
|
|
|
166
|
-
declare interface
|
|
167
|
-
|
|
168
|
-
|
|
342
|
+
export declare interface SFCScriptCompileOptions {
|
|
343
|
+
/**
|
|
344
|
+
* Production mode. Used to determine whether to generate hashed CSS variables
|
|
345
|
+
*/
|
|
346
|
+
isProd?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Enable/disable source map. Defaults to true.
|
|
349
|
+
*/
|
|
350
|
+
sourceMap?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* https://babeljs.io/docs/en/babel-parser#plugins
|
|
353
|
+
*/
|
|
354
|
+
babelParserPlugins?: ParserPlugin[];
|
|
169
355
|
}
|
|
170
356
|
|
|
171
|
-
export declare interface
|
|
357
|
+
export declare interface SFCStyleCompileOptions {
|
|
172
358
|
source: string;
|
|
173
359
|
filename: string;
|
|
174
360
|
id: string;
|
|
@@ -181,18 +367,18 @@ export declare interface StyleCompileOptions {
|
|
|
181
367
|
postcssPlugins?: any[];
|
|
182
368
|
}
|
|
183
369
|
|
|
184
|
-
export declare interface
|
|
370
|
+
export declare interface SFCStyleCompileResults {
|
|
185
371
|
code: string;
|
|
186
372
|
map: any | void;
|
|
187
373
|
rawResult: LazyResult | void;
|
|
188
374
|
errors: string[];
|
|
189
375
|
}
|
|
190
376
|
|
|
191
|
-
export declare interface
|
|
377
|
+
export declare interface SFCTemplateCompileOptions {
|
|
192
378
|
source: string;
|
|
193
379
|
filename: string;
|
|
194
|
-
compiler?:
|
|
195
|
-
compilerOptions?:
|
|
380
|
+
compiler?: TemplateCompiler;
|
|
381
|
+
compilerOptions?: CompilerOptions;
|
|
196
382
|
transformAssetUrls?: AssetURLOptions | boolean;
|
|
197
383
|
transformAssetUrlsOptions?: TransformAssetUrlsOptions;
|
|
198
384
|
preprocessLang?: string;
|
|
@@ -203,9 +389,10 @@ export declare interface TemplateCompileOptions {
|
|
|
203
389
|
optimizeSSR?: boolean;
|
|
204
390
|
prettify?: boolean;
|
|
205
391
|
isTS?: boolean;
|
|
392
|
+
bindings?: BindingMetadata;
|
|
206
393
|
}
|
|
207
394
|
|
|
208
|
-
export declare interface
|
|
395
|
+
export declare interface SFCTemplateCompileResults {
|
|
209
396
|
ast: Object | undefined;
|
|
210
397
|
code: string;
|
|
211
398
|
source: string;
|
|
@@ -213,27 +400,27 @@ export declare interface TemplateCompileResult {
|
|
|
213
400
|
errors: (string | WarningMessage)[];
|
|
214
401
|
}
|
|
215
402
|
|
|
403
|
+
declare interface StartOfSourceMap {
|
|
404
|
+
file?: string;
|
|
405
|
+
sourceRoot?: string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export declare interface TemplateCompiler {
|
|
409
|
+
parseComponent(source: string, options?: any): SFCDescriptor;
|
|
410
|
+
compile(template: string, options: CompilerOptions): CompiledResult;
|
|
411
|
+
ssrCompile(template: string, options: CompilerOptions): CompiledResult;
|
|
412
|
+
}
|
|
413
|
+
|
|
216
414
|
declare interface TransformAssetUrlsOptions {
|
|
217
415
|
/**
|
|
218
416
|
* If base is provided, instead of transforming relative asset urls into
|
|
219
417
|
* imports, they will be directly rewritten to absolute urls.
|
|
220
418
|
*/
|
|
221
419
|
base?: string;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
compile(template: string, options: VueTemplateCompilerOptions): VueTemplateCompilerResults;
|
|
227
|
-
ssrCompile(template: string, options: VueTemplateCompilerOptions): VueTemplateCompilerResults;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
declare interface VueTemplateCompilerOptions {
|
|
231
|
-
modules?: Object[];
|
|
232
|
-
outputSourceRange?: boolean;
|
|
233
|
-
whitespace?: 'preserve' | 'condense';
|
|
234
|
-
directives?: {
|
|
235
|
-
[key: string]: Function;
|
|
236
|
-
};
|
|
420
|
+
/**
|
|
421
|
+
* If true, also processes absolute urls.
|
|
422
|
+
*/
|
|
423
|
+
includeAbsolute?: boolean;
|
|
237
424
|
}
|
|
238
425
|
|
|
239
426
|
declare interface VueTemplateCompilerParseOptions {
|
|
@@ -242,15 +429,7 @@ declare interface VueTemplateCompilerParseOptions {
|
|
|
242
429
|
outputSourceRange?: boolean;
|
|
243
430
|
}
|
|
244
431
|
|
|
245
|
-
declare
|
|
246
|
-
ast: Object | undefined;
|
|
247
|
-
render: string;
|
|
248
|
-
staticRenderFns: string[];
|
|
249
|
-
errors: (string | WarningMessage)[];
|
|
250
|
-
tips: (string | WarningMessage)[];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
declare type WarningMessage = {
|
|
432
|
+
export declare type WarningMessage = {
|
|
254
433
|
msg: string;
|
|
255
434
|
start?: number;
|
|
256
435
|
end?: number;
|
package/dist/compiler-sfc.js
CHANGED
|
@@ -690,6 +690,9 @@ function parseComponent(source, options = {}) {
|
|
|
690
690
|
return cumulated;
|
|
691
691
|
}, {})
|
|
692
692
|
};
|
|
693
|
+
if (typeof currentBlock.attrs.src === 'string') {
|
|
694
|
+
currentBlock.src = currentBlock.attrs.src;
|
|
695
|
+
}
|
|
693
696
|
if (isSpecialTag(tag)) {
|
|
694
697
|
checkAttrs(currentBlock, attrs);
|
|
695
698
|
if (tag === 'script') {
|
|
@@ -730,9 +733,6 @@ function parseComponent(source, options = {}) {
|
|
|
730
733
|
if (attr.name === 'module') {
|
|
731
734
|
block.module = attr.value || true;
|
|
732
735
|
}
|
|
733
|
-
if (attr.name === 'src') {
|
|
734
|
-
block.src = attr.value;
|
|
735
|
-
}
|
|
736
736
|
}
|
|
737
737
|
}
|
|
738
738
|
function end(tag, start) {
|
|
@@ -5789,7 +5789,7 @@ function resolveAsset(options, type, id, warnMissing) {
|
|
|
5789
5789
|
// fallback to prototype chain
|
|
5790
5790
|
const res = assets[id] || assets[camelizedId] || assets[PascalCaseId];
|
|
5791
5791
|
if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
|
|
5792
|
-
warn$3('Failed to resolve ' + type.slice(0, -1) + ': ' + id
|
|
5792
|
+
warn$3('Failed to resolve ' + type.slice(0, -1) + ': ' + id);
|
|
5793
5793
|
}
|
|
5794
5794
|
return res;
|
|
5795
5795
|
}
|
|
@@ -8053,7 +8053,6 @@ function compileScript(sfc, options = {}) {
|
|
|
8053
8053
|
let emitsTypeDecl;
|
|
8054
8054
|
let emitsTypeDeclRaw;
|
|
8055
8055
|
let emitIdentifier;
|
|
8056
|
-
let hasAwait = false;
|
|
8057
8056
|
// props/emits declared via types
|
|
8058
8057
|
const typeDeclaredProps = {};
|
|
8059
8058
|
const typeDeclaredEmits = new Set();
|
|
@@ -8233,33 +8232,6 @@ function compileScript(sfc, options = {}) {
|
|
|
8233
8232
|
}
|
|
8234
8233
|
});
|
|
8235
8234
|
}
|
|
8236
|
-
/**
|
|
8237
|
-
* await foo()
|
|
8238
|
-
* -->
|
|
8239
|
-
* ;(
|
|
8240
|
-
* ([__temp,__restore] = withAsyncContext(() => foo())),
|
|
8241
|
-
* await __temp,
|
|
8242
|
-
* __restore()
|
|
8243
|
-
* )
|
|
8244
|
-
*
|
|
8245
|
-
* const a = await foo()
|
|
8246
|
-
* -->
|
|
8247
|
-
* const a = (
|
|
8248
|
-
* ([__temp, __restore] = withAsyncContext(() => foo())),
|
|
8249
|
-
* __temp = await __temp,
|
|
8250
|
-
* __restore(),
|
|
8251
|
-
* __temp
|
|
8252
|
-
* )
|
|
8253
|
-
*/
|
|
8254
|
-
function processAwait(node, needSemi, isStatement) {
|
|
8255
|
-
const argumentStart = node.argument.extra && node.argument.extra.parenthesized
|
|
8256
|
-
? node.argument.extra.parenStart
|
|
8257
|
-
: node.argument.start;
|
|
8258
|
-
const argumentStr = source.slice(argumentStart + startOffset, node.argument.end + startOffset);
|
|
8259
|
-
const containsNestedAwait = /\bawait\b/.test(argumentStr);
|
|
8260
|
-
s.overwrite(node.start + startOffset, argumentStart + startOffset, `${needSemi ? `;` : ``}(\n ([__temp,__restore] = ${helper(`withAsyncContext`)}(${containsNestedAwait ? `async ` : ``}() => `);
|
|
8261
|
-
s.appendLeft(node.end + startOffset, `)),\n ${isStatement ? `` : `__temp = `}await __temp,\n __restore()${isStatement ? `` : `,\n __temp`}\n)`);
|
|
8262
|
-
}
|
|
8263
8235
|
/**
|
|
8264
8236
|
* check defaults. If the default object is an object literal with only
|
|
8265
8237
|
* static properties, we can directly generate more optimized default
|
|
@@ -8614,18 +8586,7 @@ function compileScript(sfc, options = {}) {
|
|
|
8614
8586
|
scope.push(child.body);
|
|
8615
8587
|
}
|
|
8616
8588
|
if (child.type === 'AwaitExpression') {
|
|
8617
|
-
|
|
8618
|
-
// if the await expression is an expression statement and
|
|
8619
|
-
// - is in the root scope
|
|
8620
|
-
// - or is not the first statement in a nested block scope
|
|
8621
|
-
// then it needs a semicolon before the generated code.
|
|
8622
|
-
const currentScope = scope[scope.length - 1];
|
|
8623
|
-
const needsSemi = currentScope.some((n, i) => {
|
|
8624
|
-
return ((scope.length === 1 || i > 0) &&
|
|
8625
|
-
n.type === 'ExpressionStatement' &&
|
|
8626
|
-
n.start === child.start);
|
|
8627
|
-
});
|
|
8628
|
-
processAwait(child, needsSemi, parent.type === 'ExpressionStatement');
|
|
8589
|
+
error(`Vue 2 does not support top level await in <script setup>.`, child);
|
|
8629
8590
|
}
|
|
8630
8591
|
},
|
|
8631
8592
|
exit(node) {
|
|
@@ -8767,12 +8728,7 @@ function compileScript(sfc, options = {}) {
|
|
|
8767
8728
|
if (propsIdentifier) {
|
|
8768
8729
|
s.prependLeft(startOffset, `\nconst ${propsIdentifier} = __props${propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``}\n`);
|
|
8769
8730
|
}
|
|
8770
|
-
|
|
8771
|
-
if (hasAwait) {
|
|
8772
|
-
const any = isTS ? `: any` : ``;
|
|
8773
|
-
s.prependLeft(startOffset, `\nlet __temp${any}, __restore${any}\n`);
|
|
8774
|
-
}
|
|
8775
|
-
const destructureElements = [`expose`];
|
|
8731
|
+
const destructureElements = hasDefineExposeCall ? [`expose`] : [];
|
|
8776
8732
|
if (emitIdentifier) {
|
|
8777
8733
|
destructureElements.push(emitIdentifier === `emit` ? `emit` : `emit: ${emitIdentifier}`);
|
|
8778
8734
|
}
|
|
@@ -8789,7 +8745,9 @@ function compileScript(sfc, options = {}) {
|
|
|
8789
8745
|
allBindings[key] = true;
|
|
8790
8746
|
}
|
|
8791
8747
|
}
|
|
8792
|
-
|
|
8748
|
+
// __sfc marker indicates these bindings are compiled from <script setup>
|
|
8749
|
+
// and should not be proxied on `this`
|
|
8750
|
+
const returned = `{ ${`__sfc: true,`}${Object.keys(allBindings).join(', ')} }`;
|
|
8793
8751
|
s.appendRight(endOffset, `\nreturn ${returned}\n}\n\n`);
|
|
8794
8752
|
// 11. finalize default export
|
|
8795
8753
|
let runtimeOptions = ``;
|
|
@@ -8816,9 +8774,6 @@ function compileScript(sfc, options = {}) {
|
|
|
8816
8774
|
else if (emitsTypeDecl) {
|
|
8817
8775
|
runtimeOptions += genRuntimeEmits(typeDeclaredEmits);
|
|
8818
8776
|
}
|
|
8819
|
-
// <script setup> components are closed by default. If the user did not
|
|
8820
|
-
// explicitly call `defineExpose`, call expose() with no args.
|
|
8821
|
-
const exposeCall = hasDefineExposeCall ? `` : ` expose();\n`;
|
|
8822
8777
|
// wrap setup code with function.
|
|
8823
8778
|
if (isTS) {
|
|
8824
8779
|
// for TS, make sure the exported type is still valid type with
|
|
@@ -8827,7 +8782,7 @@ function compileScript(sfc, options = {}) {
|
|
|
8827
8782
|
// user's TS setting should compile it down to proper targets
|
|
8828
8783
|
// export default defineComponent({ ...__default__, ... })
|
|
8829
8784
|
const def = defaultExport ? `\n ...${DEFAULT_VAR},` : ``;
|
|
8830
|
-
s.prependLeft(startOffset, `\nexport default /*#__PURE__*/${helper(`defineComponent`)}({${def}${runtimeOptions}\n
|
|
8785
|
+
s.prependLeft(startOffset, `\nexport default /*#__PURE__*/${helper(`defineComponent`)}({${def}${runtimeOptions}\n setup(${args}) {\n`);
|
|
8831
8786
|
s.appendRight(endOffset, `})`);
|
|
8832
8787
|
}
|
|
8833
8788
|
else {
|
|
@@ -8835,12 +8790,11 @@ function compileScript(sfc, options = {}) {
|
|
|
8835
8790
|
// without TS, can't rely on rest spread, so we use Object.assign
|
|
8836
8791
|
// export default Object.assign(__default__, { ... })
|
|
8837
8792
|
s.prependLeft(startOffset, `\nexport default /*#__PURE__*/Object.assign(${DEFAULT_VAR}, {${runtimeOptions}\n ` +
|
|
8838
|
-
|
|
8793
|
+
`setup(${args}) {\n`);
|
|
8839
8794
|
s.appendRight(endOffset, `})`);
|
|
8840
8795
|
}
|
|
8841
8796
|
else {
|
|
8842
|
-
s.prependLeft(startOffset, `\nexport default {${runtimeOptions}\n `
|
|
8843
|
-
`${hasAwait ? `async ` : ``}setup(${args}) {\n${exposeCall}`);
|
|
8797
|
+
s.prependLeft(startOffset, `\nexport default {${runtimeOptions}\n setup(${args}) {\n`);
|
|
8844
8798
|
s.appendRight(endOffset, `}`);
|
|
8845
8799
|
}
|
|
8846
8800
|
}
|
|
@@ -9378,7 +9332,7 @@ const cache = new lruCache(100);
|
|
|
9378
9332
|
const splitRE = /\r?\n/g;
|
|
9379
9333
|
const emptyRE = /^(?:\/\/)?\s*$/;
|
|
9380
9334
|
function parse(options) {
|
|
9381
|
-
const { source, filename = DEFAULT_FILENAME, compiler, compilerParseOptions = { pad: false }, sourceRoot = '',
|
|
9335
|
+
const { source, filename = DEFAULT_FILENAME, compiler, compilerParseOptions = { pad: false }, sourceRoot = '', sourceMap = true } = options;
|
|
9382
9336
|
const cacheKey = hashSum(filename + source + JSON.stringify(compilerParseOptions));
|
|
9383
9337
|
let output = cache.get(cacheKey);
|
|
9384
9338
|
if (output) {
|
|
@@ -9394,7 +9348,7 @@ function parse(options) {
|
|
|
9394
9348
|
}
|
|
9395
9349
|
output.filename = filename;
|
|
9396
9350
|
output.shouldForceReload = prevImports => hmrShouldReload(prevImports, output);
|
|
9397
|
-
if (
|
|
9351
|
+
if (sourceMap) {
|
|
9398
9352
|
if (output.script && !output.script.src) {
|
|
9399
9353
|
output.script.map = generateSourceMap(filename, source, output.script.content, sourceRoot, compilerParseOptions.pad);
|
|
9400
9354
|
}
|
|
@@ -9445,6 +9399,9 @@ function urlToRequire(url, transformAssetUrlsOption = {}) {
|
|
|
9445
9399
|
const secondChar = url.charAt(1);
|
|
9446
9400
|
url = url.slice(secondChar === '/' ? 2 : 1);
|
|
9447
9401
|
}
|
|
9402
|
+
if (isExternalUrl(url) || isDataUrl(url) || firstChar === '#') {
|
|
9403
|
+
return returnValue;
|
|
9404
|
+
}
|
|
9448
9405
|
const uriParts = parseUriParts(url);
|
|
9449
9406
|
if (transformAssetUrlsOption.base) {
|
|
9450
9407
|
// explicit base - directly rewrite the url into absolute url
|
|
@@ -9457,7 +9414,10 @@ function urlToRequire(url, transformAssetUrlsOption = {}) {
|
|
|
9457
9414
|
}
|
|
9458
9415
|
return returnValue;
|
|
9459
9416
|
}
|
|
9460
|
-
if (
|
|
9417
|
+
if (transformAssetUrlsOption.includeAbsolute ||
|
|
9418
|
+
firstChar === '.' ||
|
|
9419
|
+
firstChar === '~' ||
|
|
9420
|
+
firstChar === '@') {
|
|
9461
9421
|
if (!uriParts.hash) {
|
|
9462
9422
|
return `require("${url}")`;
|
|
9463
9423
|
}
|
|
@@ -9487,6 +9447,14 @@ function parseUriParts(urlString) {
|
|
|
9487
9447
|
}
|
|
9488
9448
|
}
|
|
9489
9449
|
return returnValue;
|
|
9450
|
+
}
|
|
9451
|
+
const externalRE = /^(https?:)?\/\//;
|
|
9452
|
+
function isExternalUrl(url) {
|
|
9453
|
+
return externalRE.test(url);
|
|
9454
|
+
}
|
|
9455
|
+
const dataUrlRE = /^\s*data:/i;
|
|
9456
|
+
function isDataUrl(url) {
|
|
9457
|
+
return dataUrlRE.test(url);
|
|
9490
9458
|
}
|
|
9491
9459
|
|
|
9492
9460
|
// vue compiler module for transforming `<tag>:<attribute>` to `require`
|
|
@@ -11741,8 +11709,19 @@ function genElement(el, state) {
|
|
|
11741
11709
|
if (!el.plain || (el.pre && state.maybeComponent(el))) {
|
|
11742
11710
|
data = genData(el, state);
|
|
11743
11711
|
}
|
|
11712
|
+
let tag;
|
|
11713
|
+
// check if this is a component in <script setup>
|
|
11714
|
+
const bindings = state.options.bindings;
|
|
11715
|
+
if (bindings && bindings.__isScriptSetup !== false) {
|
|
11716
|
+
tag =
|
|
11717
|
+
checkBindingType(bindings, el.tag) ||
|
|
11718
|
+
checkBindingType(bindings, camelize(el.tag)) ||
|
|
11719
|
+
checkBindingType(bindings, capitalize(camelize(el.tag)));
|
|
11720
|
+
}
|
|
11721
|
+
if (!tag)
|
|
11722
|
+
tag = `'${el.tag}'`;
|
|
11744
11723
|
const children = el.inlineTemplate ? null : genChildren(el, state, true);
|
|
11745
|
-
code = `_c(
|
|
11724
|
+
code = `_c(${tag}${data ? `,${data}` : '' // data
|
|
11746
11725
|
}${children ? `,${children}` : '' // children
|
|
11747
11726
|
})`;
|
|
11748
11727
|
}
|
|
@@ -11753,6 +11732,12 @@ function genElement(el, state) {
|
|
|
11753
11732
|
return code;
|
|
11754
11733
|
}
|
|
11755
11734
|
}
|
|
11735
|
+
function checkBindingType(bindings, key) {
|
|
11736
|
+
const type = bindings[key];
|
|
11737
|
+
if (type && type.startsWith('setup')) {
|
|
11738
|
+
return key;
|
|
11739
|
+
}
|
|
11740
|
+
}
|
|
11756
11741
|
// hoist static sub-trees out
|
|
11757
11742
|
function genStatic(el, state) {
|
|
11758
11743
|
el.staticProcessed = true;
|
|
@@ -12907,7 +12892,7 @@ const doNotPrefix = makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
|
|
|
12907
12892
|
* The input is expected to be the render function code directly returned from
|
|
12908
12893
|
* `compile()` calls, e.g. `with(this){return ...}`
|
|
12909
12894
|
*/
|
|
12910
|
-
function
|
|
12895
|
+
function prefixIdentifiers(source, fnName = '', isFunctional = false, isTS = false, babelOptions = {}, bindings) {
|
|
12911
12896
|
source = `function ${fnName}(${isFunctional ? `_c,_vm` : ``}){${source}\n}`;
|
|
12912
12897
|
const s = new MagicString(source);
|
|
12913
12898
|
const plugins = [
|
|
@@ -12915,21 +12900,36 @@ function stripWith(source, fnName = '', isFunctional = false, isTS = false, babe
|
|
|
12915
12900
|
...((babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [])
|
|
12916
12901
|
];
|
|
12917
12902
|
const ast = parser$1.parseExpression(source, Object.assign(Object.assign({}, babelOptions), { plugins }));
|
|
12903
|
+
const isScriptSetup = bindings && bindings.__isScriptSetup !== false;
|
|
12918
12904
|
walkIdentifiers(ast, ident => {
|
|
12919
|
-
|
|
12905
|
+
const { name } = ident;
|
|
12906
|
+
if (doNotPrefix(name)) {
|
|
12907
|
+
return;
|
|
12908
|
+
}
|
|
12909
|
+
if (!isScriptSetup) {
|
|
12910
|
+
s.prependRight(ident.start, '_vm.');
|
|
12920
12911
|
return;
|
|
12921
12912
|
}
|
|
12922
|
-
s.
|
|
12913
|
+
s.overwrite(ident.start, ident.end, rewriteIdentifier(name, bindings));
|
|
12923
12914
|
}, node => {
|
|
12924
12915
|
if (node.type === 'WithStatement') {
|
|
12925
12916
|
s.remove(node.start, node.body.start + 1);
|
|
12926
12917
|
s.remove(node.end - 1, node.end);
|
|
12927
12918
|
if (!isFunctional) {
|
|
12928
|
-
s.prependRight(node.start, `var _vm=this
|
|
12919
|
+
s.prependRight(node.start, `var _vm=this,_c=_vm._self._c${isScriptSetup ? `,_setup=_vm._self._setupProxy;` : `;`}`);
|
|
12929
12920
|
}
|
|
12930
12921
|
}
|
|
12931
12922
|
});
|
|
12932
12923
|
return s.toString();
|
|
12924
|
+
}
|
|
12925
|
+
function rewriteIdentifier(name, bindings) {
|
|
12926
|
+
const type = bindings[name];
|
|
12927
|
+
if (type && type.startsWith('setup')) {
|
|
12928
|
+
return `_setup.${name}`;
|
|
12929
|
+
}
|
|
12930
|
+
else {
|
|
12931
|
+
return `_vm.${name}`;
|
|
12932
|
+
}
|
|
12933
12933
|
}
|
|
12934
12934
|
|
|
12935
12935
|
function compileTemplate(options) {
|
|
@@ -12977,7 +12977,7 @@ function preprocess$1(options, preprocessor) {
|
|
|
12977
12977
|
return res;
|
|
12978
12978
|
}
|
|
12979
12979
|
function actuallyCompile(options) {
|
|
12980
|
-
const { source, compiler = _compiler, compilerOptions = {}, transpileOptions = {}, transformAssetUrls, transformAssetUrlsOptions, isProduction = process.env.NODE_ENV === 'production', isFunctional = false, optimizeSSR = false, prettify = true, isTS = false } = options;
|
|
12980
|
+
const { source, compiler = _compiler, compilerOptions = {}, transpileOptions = {}, transformAssetUrls, transformAssetUrlsOptions, isProduction = process.env.NODE_ENV === 'production', isFunctional = false, optimizeSSR = false, prettify = true, isTS = false, bindings } = options;
|
|
12981
12981
|
const compile = optimizeSSR && compiler.ssrCompile ? compiler.ssrCompile : compiler.compile;
|
|
12982
12982
|
let finalCompilerOptions = compilerOptions;
|
|
12983
12983
|
if (transformAssetUrls) {
|
|
@@ -12992,6 +12992,7 @@ function actuallyCompile(options) {
|
|
|
12992
12992
|
filename: options.filename
|
|
12993
12993
|
});
|
|
12994
12994
|
}
|
|
12995
|
+
finalCompilerOptions.bindings = bindings;
|
|
12995
12996
|
const { ast, render, staticRenderFns, tips, errors } = compile(source, finalCompilerOptions);
|
|
12996
12997
|
if (errors && errors.length) {
|
|
12997
12998
|
return {
|
|
@@ -13005,8 +13006,8 @@ function actuallyCompile(options) {
|
|
|
13005
13006
|
else {
|
|
13006
13007
|
// transpile code with vue-template-es2015-compiler, which is a forked
|
|
13007
13008
|
// version of Buble that applies ES2015 transforms + stripping `with` usage
|
|
13008
|
-
let code = `var __render__ = ${
|
|
13009
|
-
`var __staticRenderFns__ = [${staticRenderFns.map(code =>
|
|
13009
|
+
let code = `var __render__ = ${prefixIdentifiers(render, `render`, isFunctional, isTS, transpileOptions, bindings)}\n` +
|
|
13010
|
+
`var __staticRenderFns__ = [${staticRenderFns.map(code => prefixIdentifiers(code, ``, isFunctional, isTS, transpileOptions, bindings))}]` +
|
|
13010
13011
|
`\n`;
|
|
13011
13012
|
// #23 we use __render__ to avoid `render` not being prefixed by the
|
|
13012
13013
|
// transpiler when stripping with, but revert it back to `render` to
|
|
@@ -17608,9 +17609,98 @@ function preprocess(options, preprocessor) {
|
|
|
17608
17609
|
}, options.preprocessOptions));
|
|
17609
17610
|
}
|
|
17610
17611
|
|
|
17612
|
+
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
17613
|
+
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
17614
|
+
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
17615
|
+
/**
|
|
17616
|
+
* Utility for rewriting `export default` in a script block into a variable
|
|
17617
|
+
* declaration so that we can inject things into it
|
|
17618
|
+
*/
|
|
17619
|
+
function rewriteDefault(input, as, parserPlugins) {
|
|
17620
|
+
if (!hasDefaultExport(input)) {
|
|
17621
|
+
return input + `\nconst ${as} = {}`;
|
|
17622
|
+
}
|
|
17623
|
+
let replaced;
|
|
17624
|
+
const classMatch = input.match(exportDefaultClassRE);
|
|
17625
|
+
if (classMatch) {
|
|
17626
|
+
replaced =
|
|
17627
|
+
input.replace(exportDefaultClassRE, '$1class $2') +
|
|
17628
|
+
`\nconst ${as} = ${classMatch[2]}`;
|
|
17629
|
+
}
|
|
17630
|
+
else {
|
|
17631
|
+
replaced = input.replace(defaultExportRE, `$1const ${as} =`);
|
|
17632
|
+
}
|
|
17633
|
+
if (!hasDefaultExport(replaced)) {
|
|
17634
|
+
return replaced;
|
|
17635
|
+
}
|
|
17636
|
+
// if the script somehow still contains `default export`, it probably has
|
|
17637
|
+
// multi-line comments or template strings. fallback to a full parse.
|
|
17638
|
+
const s = new MagicString(input);
|
|
17639
|
+
const ast = parser$1.parse(input, {
|
|
17640
|
+
sourceType: 'module',
|
|
17641
|
+
plugins: parserPlugins
|
|
17642
|
+
}).program.body;
|
|
17643
|
+
ast.forEach(node => {
|
|
17644
|
+
if (node.type === 'ExportDefaultDeclaration') {
|
|
17645
|
+
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
17646
|
+
}
|
|
17647
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
17648
|
+
for (const specifier of node.specifiers) {
|
|
17649
|
+
if (specifier.type === 'ExportSpecifier' &&
|
|
17650
|
+
specifier.exported.type === 'Identifier' &&
|
|
17651
|
+
specifier.exported.name === 'default') {
|
|
17652
|
+
if (node.source) {
|
|
17653
|
+
if (specifier.local.name === 'default') {
|
|
17654
|
+
const end = specifierEnd(input, specifier.local.end, node.end);
|
|
17655
|
+
s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
|
|
17656
|
+
s.overwrite(specifier.start, end, ``);
|
|
17657
|
+
s.append(`\nconst ${as} = __VUE_DEFAULT__`);
|
|
17658
|
+
continue;
|
|
17659
|
+
}
|
|
17660
|
+
else {
|
|
17661
|
+
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
17662
|
+
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
|
|
17663
|
+
s.overwrite(specifier.start, end, ``);
|
|
17664
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
17665
|
+
continue;
|
|
17666
|
+
}
|
|
17667
|
+
}
|
|
17668
|
+
const end = specifierEnd(input, specifier.end, node.end);
|
|
17669
|
+
s.overwrite(specifier.start, end, ``);
|
|
17670
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
17671
|
+
}
|
|
17672
|
+
}
|
|
17673
|
+
}
|
|
17674
|
+
});
|
|
17675
|
+
return s.toString();
|
|
17676
|
+
}
|
|
17677
|
+
function hasDefaultExport(input) {
|
|
17678
|
+
return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
|
|
17679
|
+
}
|
|
17680
|
+
function specifierEnd(input, end, nodeEnd) {
|
|
17681
|
+
// export { default , foo } ...
|
|
17682
|
+
let hasCommas = false;
|
|
17683
|
+
let oldEnd = end;
|
|
17684
|
+
while (end < nodeEnd) {
|
|
17685
|
+
if (/\s/.test(input.charAt(end))) {
|
|
17686
|
+
end++;
|
|
17687
|
+
}
|
|
17688
|
+
else if (input.charAt(end) === ',') {
|
|
17689
|
+
end++;
|
|
17690
|
+
hasCommas = true;
|
|
17691
|
+
break;
|
|
17692
|
+
}
|
|
17693
|
+
else if (input.charAt(end) === '}') {
|
|
17694
|
+
break;
|
|
17695
|
+
}
|
|
17696
|
+
}
|
|
17697
|
+
return hasCommas ? end : oldEnd;
|
|
17698
|
+
}
|
|
17699
|
+
|
|
17611
17700
|
exports.compileScript = compileScript;
|
|
17612
17701
|
exports.compileStyle = compileStyle;
|
|
17613
17702
|
exports.compileStyleAsync = compileStyleAsync;
|
|
17614
17703
|
exports.compileTemplate = compileTemplate;
|
|
17615
17704
|
exports.generateCodeFrame = generateCodeFrame;
|
|
17616
17705
|
exports.parse = parse;
|
|
17706
|
+
exports.rewriteDefault = rewriteDefault;
|