@vue/compiler-sfc 3.2.32 → 3.2.34
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.cjs.js +304 -79
- package/dist/compiler-sfc.esm-browser.js +460 -174
- package/package.json +6 -6
|
@@ -453,7 +453,13 @@ const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + st
|
|
|
453
453
|
/**
|
|
454
454
|
* @private
|
|
455
455
|
*/
|
|
456
|
-
const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
|
|
456
|
+
const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
|
|
457
|
+
const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
|
|
458
|
+
function genPropsAccessExp(name) {
|
|
459
|
+
return identRE.test(name)
|
|
460
|
+
? `__props.${name}`
|
|
461
|
+
: `__props[${JSON.stringify(name)}]`;
|
|
462
|
+
}
|
|
457
463
|
|
|
458
464
|
function defaultOnError(error) {
|
|
459
465
|
throw error;
|
|
@@ -20973,6 +20979,7 @@ var sourceMap = {
|
|
|
20973
20979
|
};
|
|
20974
20980
|
|
|
20975
20981
|
const PURE_ANNOTATION = `/*#__PURE__*/`;
|
|
20982
|
+
const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
|
20976
20983
|
function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, inSSR = false }) {
|
|
20977
20984
|
const context = {
|
|
20978
20985
|
mode,
|
|
@@ -21100,9 +21107,7 @@ function generate(ast, options = {}) {
|
|
|
21100
21107
|
// function mode const declarations should be inside with block
|
|
21101
21108
|
// also they should be renamed to avoid collision with user properties
|
|
21102
21109
|
if (hasHelpers) {
|
|
21103
|
-
push(`const { ${ast.helpers
|
|
21104
|
-
.map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
|
|
21105
|
-
.join(', ')} } = _Vue`);
|
|
21110
|
+
push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
|
|
21106
21111
|
push(`\n`);
|
|
21107
21112
|
newline();
|
|
21108
21113
|
}
|
|
@@ -21159,7 +21164,6 @@ function genFunctionPreamble(ast, context) {
|
|
|
21159
21164
|
const VueBinding = ssr
|
|
21160
21165
|
? `require(${JSON.stringify(runtimeModuleName)})`
|
|
21161
21166
|
: runtimeGlobalName;
|
|
21162
|
-
const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
|
21163
21167
|
// Generate const declaration for helpers
|
|
21164
21168
|
// In prefix mode, we place the const declaration at top so it's done
|
|
21165
21169
|
// only once; But if we not prefixing, we place the declaration inside the
|
|
@@ -22286,7 +22290,9 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
22286
22290
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
22287
22291
|
// ({ x } = y)
|
|
22288
22292
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
22289
|
-
if (type === "setup-const" /* SETUP_CONST */ ||
|
|
22293
|
+
if (type === "setup-const" /* SETUP_CONST */ ||
|
|
22294
|
+
type === "setup-reactive-const" /* SETUP_REACTIVE_CONST */ ||
|
|
22295
|
+
localVars[raw]) {
|
|
22290
22296
|
return raw;
|
|
22291
22297
|
}
|
|
22292
22298
|
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
@@ -22340,11 +22346,11 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
22340
22346
|
else if (type === "props" /* PROPS */) {
|
|
22341
22347
|
// use __props which is generated by compileScript so in ts mode
|
|
22342
22348
|
// it gets correct type
|
|
22343
|
-
return
|
|
22349
|
+
return genPropsAccessExp(raw);
|
|
22344
22350
|
}
|
|
22345
22351
|
else if (type === "props-aliased" /* PROPS_ALIASED */) {
|
|
22346
22352
|
// prop with a different local alias (from defineProps() destructure)
|
|
22347
|
-
return
|
|
22353
|
+
return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
|
|
22348
22354
|
}
|
|
22349
22355
|
}
|
|
22350
22356
|
else {
|
|
@@ -22353,7 +22359,7 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
22353
22359
|
return `$setup.${raw}`;
|
|
22354
22360
|
}
|
|
22355
22361
|
else if (type === "props-aliased" /* PROPS_ALIASED */) {
|
|
22356
|
-
return `$props
|
|
22362
|
+
return `$props['${bindingMetadata.__propsAliases[raw]}']`;
|
|
22357
22363
|
}
|
|
22358
22364
|
else if (type) {
|
|
22359
22365
|
return `$${type}.${raw}`;
|
|
@@ -22614,14 +22620,14 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
22614
22620
|
}
|
|
22615
22621
|
}
|
|
22616
22622
|
function createIfBranch(node, dir) {
|
|
22623
|
+
const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
|
|
22617
22624
|
return {
|
|
22618
22625
|
type: 10 /* IF_BRANCH */,
|
|
22619
22626
|
loc: node.loc,
|
|
22620
22627
|
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
22621
|
-
children:
|
|
22622
|
-
|
|
22623
|
-
|
|
22624
|
-
userKey: findProp(node, `key`)
|
|
22628
|
+
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
|
|
22629
|
+
userKey: findProp(node, `key`),
|
|
22630
|
+
isTemplateIf
|
|
22625
22631
|
};
|
|
22626
22632
|
}
|
|
22627
22633
|
function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
@@ -22656,7 +22662,8 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
22656
22662
|
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
22657
22663
|
// check if the fragment actually contains a single valid child with
|
|
22658
22664
|
// the rest being comments
|
|
22659
|
-
if (
|
|
22665
|
+
if (!branch.isTemplateIf &&
|
|
22666
|
+
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
22660
22667
|
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
22661
22668
|
patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
|
|
22662
22669
|
}
|
|
@@ -23264,7 +23271,7 @@ const transformElement = (node, context) => {
|
|
|
23264
23271
|
(tag === 'svg' || tag === 'foreignObject'));
|
|
23265
23272
|
// props
|
|
23266
23273
|
if (props.length > 0) {
|
|
23267
|
-
const propsBuildResult = buildProps(node, context);
|
|
23274
|
+
const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
|
|
23268
23275
|
vnodeProps = propsBuildResult.props;
|
|
23269
23276
|
patchFlag = propsBuildResult.patchFlag;
|
|
23270
23277
|
dynamicPropNames = propsBuildResult.dynamicPropNames;
|
|
@@ -23447,7 +23454,8 @@ function resolveSetupReference(name, context) {
|
|
|
23447
23454
|
return PascalName;
|
|
23448
23455
|
}
|
|
23449
23456
|
};
|
|
23450
|
-
const fromConst = checkType("setup-const" /* SETUP_CONST */)
|
|
23457
|
+
const fromConst = checkType("setup-const" /* SETUP_CONST */) ||
|
|
23458
|
+
checkType("setup-reactive-const" /* SETUP_REACTIVE_CONST */);
|
|
23451
23459
|
if (fromConst) {
|
|
23452
23460
|
return context.inline
|
|
23453
23461
|
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
|
|
@@ -23464,9 +23472,8 @@ function resolveSetupReference(name, context) {
|
|
|
23464
23472
|
: `$setup[${JSON.stringify(fromMaybeRef)}]`;
|
|
23465
23473
|
}
|
|
23466
23474
|
}
|
|
23467
|
-
function buildProps(node, context, props = node.props, ssr = false) {
|
|
23475
|
+
function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
|
|
23468
23476
|
const { tag, loc: elementLoc, children } = node;
|
|
23469
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
23470
23477
|
let properties = [];
|
|
23471
23478
|
const mergeArgs = [];
|
|
23472
23479
|
const runtimeDirectives = [];
|
|
@@ -23485,8 +23492,8 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
23485
23492
|
if (isStaticExp(key)) {
|
|
23486
23493
|
const name = key.content;
|
|
23487
23494
|
const isEventHandler = isOn(name);
|
|
23488
|
-
if (
|
|
23489
|
-
|
|
23495
|
+
if (isEventHandler &&
|
|
23496
|
+
(!isComponent || isDynamicComponent) &&
|
|
23490
23497
|
// omit the flag for click handlers because hydration gives click
|
|
23491
23498
|
// dedicated fast path.
|
|
23492
23499
|
name.toLowerCase() !== 'onclick' &&
|
|
@@ -23721,10 +23728,11 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
23721
23728
|
classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
|
|
23722
23729
|
}
|
|
23723
23730
|
if (styleProp &&
|
|
23724
|
-
!isStaticExp(styleProp.value) &&
|
|
23725
23731
|
// the static style is compiled into an object,
|
|
23726
23732
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
23727
23733
|
(hasStyleBinding ||
|
|
23734
|
+
(styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
23735
|
+
styleProp.value.content.trim()[0] === `[`) ||
|
|
23728
23736
|
// v-bind:style and style both exist,
|
|
23729
23737
|
// v-bind:style with static literal object
|
|
23730
23738
|
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
@@ -23909,7 +23917,7 @@ function processSlotOutlet(node, context) {
|
|
|
23909
23917
|
}
|
|
23910
23918
|
}
|
|
23911
23919
|
if (nonNameProps.length > 0) {
|
|
23912
|
-
const { props, directives } = buildProps(node, context, nonNameProps);
|
|
23920
|
+
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
23913
23921
|
slotProps = props;
|
|
23914
23922
|
if (directives.length) {
|
|
23915
23923
|
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
@@ -24115,11 +24123,7 @@ const transformText = (node, context) => {
|
|
|
24115
24123
|
const next = children[j];
|
|
24116
24124
|
if (isText(next)) {
|
|
24117
24125
|
if (!currentContainer) {
|
|
24118
|
-
currentContainer = children[i] =
|
|
24119
|
-
type: 8 /* COMPOUND_EXPRESSION */,
|
|
24120
|
-
loc: child.loc,
|
|
24121
|
-
children: [child]
|
|
24122
|
-
};
|
|
24126
|
+
currentContainer = children[i] = createCompoundExpression([child], child.loc);
|
|
24123
24127
|
}
|
|
24124
24128
|
// merge adjacent text node into current
|
|
24125
24129
|
currentContainer.children.push(` + `, next);
|
|
@@ -26903,7 +26907,9 @@ const transformVText = (dir, node, context) => {
|
|
|
26903
26907
|
return {
|
|
26904
26908
|
props: [
|
|
26905
26909
|
createObjectProperty(createSimpleExpression(`textContent`, true), exp
|
|
26906
|
-
?
|
|
26910
|
+
? getConstantType(exp, context) > 0
|
|
26911
|
+
? exp
|
|
26912
|
+
: createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
|
|
26907
26913
|
: createSimpleExpression('', true))
|
|
26908
26914
|
]
|
|
26909
26915
|
};
|
|
@@ -27111,19 +27117,38 @@ const transformShow = (dir, node, context) => {
|
|
|
27111
27117
|
};
|
|
27112
27118
|
};
|
|
27113
27119
|
|
|
27114
|
-
const
|
|
27120
|
+
const transformTransition = (node, context) => {
|
|
27115
27121
|
if (node.type === 1 /* ELEMENT */ &&
|
|
27116
27122
|
node.tagType === 1 /* COMPONENT */) {
|
|
27117
27123
|
const component = context.isBuiltInComponent(node.tag);
|
|
27118
27124
|
if (component === TRANSITION) {
|
|
27119
27125
|
return () => {
|
|
27120
|
-
if (node.children.length
|
|
27126
|
+
if (!node.children.length) {
|
|
27127
|
+
return;
|
|
27128
|
+
}
|
|
27129
|
+
// warn multiple transition children
|
|
27130
|
+
if (hasMultipleChildren(node)) {
|
|
27121
27131
|
context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
|
|
27122
27132
|
start: node.children[0].loc.start,
|
|
27123
27133
|
end: node.children[node.children.length - 1].loc.end,
|
|
27124
27134
|
source: ''
|
|
27125
27135
|
}));
|
|
27126
27136
|
}
|
|
27137
|
+
// check if it's s single child w/ v-show
|
|
27138
|
+
// if yes, inject "persisted: true" to the transition props
|
|
27139
|
+
const child = node.children[0];
|
|
27140
|
+
if (child.type === 1 /* ELEMENT */) {
|
|
27141
|
+
for (const p of child.props) {
|
|
27142
|
+
if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
|
|
27143
|
+
node.props.push({
|
|
27144
|
+
type: 6 /* ATTRIBUTE */,
|
|
27145
|
+
name: 'persisted',
|
|
27146
|
+
value: undefined,
|
|
27147
|
+
loc: node.loc
|
|
27148
|
+
});
|
|
27149
|
+
}
|
|
27150
|
+
}
|
|
27151
|
+
}
|
|
27127
27152
|
};
|
|
27128
27153
|
}
|
|
27129
27154
|
}
|
|
@@ -27339,6 +27364,7 @@ function stringifyNode(node, context) {
|
|
|
27339
27364
|
}
|
|
27340
27365
|
function stringifyElement(node, context) {
|
|
27341
27366
|
let res = `<${node.tag}`;
|
|
27367
|
+
let innerHTML = '';
|
|
27342
27368
|
for (let i = 0; i < node.props.length; i++) {
|
|
27343
27369
|
const p = node.props[i];
|
|
27344
27370
|
if (p.type === 6 /* ATTRIBUTE */) {
|
|
@@ -27347,25 +27373,35 @@ function stringifyElement(node, context) {
|
|
|
27347
27373
|
res += `="${escapeHtml(p.value.content)}"`;
|
|
27348
27374
|
}
|
|
27349
27375
|
}
|
|
27350
|
-
else if (p.type === 7 /* DIRECTIVE */
|
|
27351
|
-
|
|
27352
|
-
|
|
27353
|
-
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
|
|
27358
|
-
// constant v-bind, e.g. :foo="1"
|
|
27359
|
-
let evaluated = evaluateConstant(exp);
|
|
27360
|
-
if (evaluated != null) {
|
|
27361
|
-
const arg = p.arg && p.arg.content;
|
|
27362
|
-
if (arg === 'class') {
|
|
27363
|
-
evaluated = normalizeClass(evaluated);
|
|
27376
|
+
else if (p.type === 7 /* DIRECTIVE */) {
|
|
27377
|
+
if (p.name === 'bind') {
|
|
27378
|
+
const exp = p.exp;
|
|
27379
|
+
if (exp.content[0] === '_') {
|
|
27380
|
+
// internally generated string constant references
|
|
27381
|
+
// e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
|
|
27382
|
+
res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
|
|
27383
|
+
continue;
|
|
27364
27384
|
}
|
|
27365
|
-
|
|
27366
|
-
|
|
27385
|
+
// constant v-bind, e.g. :foo="1"
|
|
27386
|
+
let evaluated = evaluateConstant(exp);
|
|
27387
|
+
if (evaluated != null) {
|
|
27388
|
+
const arg = p.arg && p.arg.content;
|
|
27389
|
+
if (arg === 'class') {
|
|
27390
|
+
evaluated = normalizeClass(evaluated);
|
|
27391
|
+
}
|
|
27392
|
+
else if (arg === 'style') {
|
|
27393
|
+
evaluated = stringifyStyle(normalizeStyle(evaluated));
|
|
27394
|
+
}
|
|
27395
|
+
res += ` ${p.arg.content}="${escapeHtml(evaluated)}"`;
|
|
27367
27396
|
}
|
|
27368
|
-
|
|
27397
|
+
}
|
|
27398
|
+
else if (p.name === 'html') {
|
|
27399
|
+
// #5439 v-html with constant value
|
|
27400
|
+
// not sure why would anyone do this but it can happen
|
|
27401
|
+
innerHTML = evaluateConstant(p.exp);
|
|
27402
|
+
}
|
|
27403
|
+
else if (p.name === 'text') {
|
|
27404
|
+
innerHTML = escapeHtml(toDisplayString(evaluateConstant(p.exp)));
|
|
27369
27405
|
}
|
|
27370
27406
|
}
|
|
27371
27407
|
}
|
|
@@ -27373,8 +27409,13 @@ function stringifyElement(node, context) {
|
|
|
27373
27409
|
res += ` ${context.scopeId}`;
|
|
27374
27410
|
}
|
|
27375
27411
|
res += `>`;
|
|
27376
|
-
|
|
27377
|
-
res +=
|
|
27412
|
+
if (innerHTML) {
|
|
27413
|
+
res += innerHTML;
|
|
27414
|
+
}
|
|
27415
|
+
else {
|
|
27416
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
27417
|
+
res += stringifyNode(node.children[i], context);
|
|
27418
|
+
}
|
|
27378
27419
|
}
|
|
27379
27420
|
if (!isVoidTag(node.tag)) {
|
|
27380
27421
|
res += `</${node.tag}>`;
|
|
@@ -27387,7 +27428,7 @@ function stringifyElement(node, context) {
|
|
|
27387
27428
|
// here, e.g. `{{ 1 }}` or `{{ 'foo' }}`
|
|
27388
27429
|
// in addition, constant exps bail on presence of parens so you can't even
|
|
27389
27430
|
// run JSFuck in here. But we mark it unsafe for security review purposes.
|
|
27390
|
-
// (see compiler-core/src/
|
|
27431
|
+
// (see compiler-core/src/transforms/transformExpression)
|
|
27391
27432
|
function evaluateConstant(exp) {
|
|
27392
27433
|
if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
27393
27434
|
return new Function(`return ${exp.content}`)();
|
|
@@ -27424,7 +27465,7 @@ const ignoreSideEffectTags = (node, context) => {
|
|
|
27424
27465
|
|
|
27425
27466
|
const DOMNodeTransforms = [
|
|
27426
27467
|
transformStyle,
|
|
27427
|
-
...([
|
|
27468
|
+
...([transformTransition] )
|
|
27428
27469
|
];
|
|
27429
27470
|
const DOMDirectiveTransforms = {
|
|
27430
27471
|
cloak: noopDirectiveTransform,
|
|
@@ -27497,6 +27538,7 @@ var CompilerDOM = /*#__PURE__*/Object.freeze({
|
|
|
27497
27538
|
buildProps: buildProps,
|
|
27498
27539
|
buildDirectiveArgs: buildDirectiveArgs,
|
|
27499
27540
|
processSlotOutlet: processSlotOutlet,
|
|
27541
|
+
getConstantType: getConstantType,
|
|
27500
27542
|
generateCodeFrame: generateCodeFrame,
|
|
27501
27543
|
checkCompatEnabled: checkCompatEnabled,
|
|
27502
27544
|
warnDeprecation: warnDeprecation,
|
|
@@ -27668,9 +27710,9 @@ var hashSum = sum;
|
|
|
27668
27710
|
const CSS_VARS_HELPER = `useCssVars`;
|
|
27669
27711
|
// match v-bind() with max 2-levels of nested parens.
|
|
27670
27712
|
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
|
|
27671
|
-
function genCssVarsFromList(vars, id, isProd) {
|
|
27713
|
+
function genCssVarsFromList(vars, id, isProd, isSSR = false) {
|
|
27672
27714
|
return `{\n ${vars
|
|
27673
|
-
.map(key => `"${genVarName(id, key, isProd)}": (${key})`)
|
|
27715
|
+
.map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
|
|
27674
27716
|
.join(',\n ')}\n}`;
|
|
27675
27717
|
}
|
|
27676
27718
|
function genVarName(id, raw, isProd) {
|
|
@@ -27681,7 +27723,7 @@ function genVarName(id, raw, isProd) {
|
|
|
27681
27723
|
return `${id}-${raw.replace(/([^\w-])/g, '_')}`;
|
|
27682
27724
|
}
|
|
27683
27725
|
}
|
|
27684
|
-
function
|
|
27726
|
+
function normalizeExpression(exp) {
|
|
27685
27727
|
exp = exp.trim();
|
|
27686
27728
|
if ((exp[0] === `'` && exp[exp.length - 1] === `'`) ||
|
|
27687
27729
|
(exp[0] === `"` && exp[exp.length - 1] === `"`)) {
|
|
@@ -27696,7 +27738,7 @@ function parseCssVars(sfc) {
|
|
|
27696
27738
|
// ignore v-bind() in comments /* ... */
|
|
27697
27739
|
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
27698
27740
|
while ((match = cssVarRE.exec(content))) {
|
|
27699
|
-
const variable =
|
|
27741
|
+
const variable = normalizeExpression(match[1]);
|
|
27700
27742
|
if (!vars.includes(variable)) {
|
|
27701
27743
|
vars.push(variable);
|
|
27702
27744
|
}
|
|
@@ -27712,7 +27754,7 @@ const cssVarsPlugin = opts => {
|
|
|
27712
27754
|
// rewrite CSS variables
|
|
27713
27755
|
if (cssVarRE.test(decl.value)) {
|
|
27714
27756
|
decl.value = decl.value.replace(cssVarRE, (_, $1) => {
|
|
27715
|
-
return `var(--${genVarName(id,
|
|
27757
|
+
return `var(--${genVarName(id, normalizeExpression($1), isProd)})`;
|
|
27716
27758
|
});
|
|
27717
27759
|
}
|
|
27718
27760
|
}
|
|
@@ -33166,6 +33208,10 @@ function getImportsExpressionExp(path, hash, loc, context) {
|
|
|
33166
33208
|
return exp;
|
|
33167
33209
|
}
|
|
33168
33210
|
const hashExp = `${name} + '${hash}'`;
|
|
33211
|
+
const finalExp = createSimpleExpression(hashExp, false, loc, 3 /* CAN_STRINGIFY */);
|
|
33212
|
+
if (!context.hoistStatic) {
|
|
33213
|
+
return finalExp;
|
|
33214
|
+
}
|
|
33169
33215
|
const existingHoistIndex = context.hoists.findIndex(h => {
|
|
33170
33216
|
return (h &&
|
|
33171
33217
|
h.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
@@ -33175,7 +33221,7 @@ function getImportsExpressionExp(path, hash, loc, context) {
|
|
|
33175
33221
|
if (existingHoistIndex > -1) {
|
|
33176
33222
|
return createSimpleExpression(`_hoisted_${existingHoistIndex + 1}`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
33177
33223
|
}
|
|
33178
|
-
return context.hoist(
|
|
33224
|
+
return context.hoist(finalExp);
|
|
33179
33225
|
}
|
|
33180
33226
|
else {
|
|
33181
33227
|
return createSimpleExpression(`''`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
@@ -33217,35 +33263,41 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
33217
33263
|
imageCandidates.splice(i, 1);
|
|
33218
33264
|
}
|
|
33219
33265
|
}
|
|
33220
|
-
const
|
|
33266
|
+
const shouldProcessUrl = (url) => {
|
|
33221
33267
|
return (!isExternalUrl(url) &&
|
|
33222
33268
|
!isDataUrl(url) &&
|
|
33223
33269
|
(options.includeAbsolute || isRelativeUrl(url)));
|
|
33224
|
-
}
|
|
33270
|
+
};
|
|
33225
33271
|
// When srcset does not contain any qualified URLs, skip transforming
|
|
33226
|
-
if (!
|
|
33272
|
+
if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
|
|
33227
33273
|
return;
|
|
33228
33274
|
}
|
|
33229
33275
|
if (options.base) {
|
|
33230
33276
|
const base = options.base;
|
|
33231
33277
|
const set = [];
|
|
33232
|
-
|
|
33278
|
+
let needImportTransform = false;
|
|
33279
|
+
imageCandidates.forEach(candidate => {
|
|
33280
|
+
let { url, descriptor } = candidate;
|
|
33233
33281
|
descriptor = descriptor ? ` ${descriptor}` : ``;
|
|
33234
|
-
if (
|
|
33235
|
-
|
|
33282
|
+
if (url[0] === '.') {
|
|
33283
|
+
candidate.url = (path.posix || path).join(base, url);
|
|
33284
|
+
set.push(candidate.url + descriptor);
|
|
33285
|
+
}
|
|
33286
|
+
else if (shouldProcessUrl(url)) {
|
|
33287
|
+
needImportTransform = true;
|
|
33236
33288
|
}
|
|
33237
33289
|
else {
|
|
33238
33290
|
set.push(url + descriptor);
|
|
33239
33291
|
}
|
|
33240
33292
|
});
|
|
33241
|
-
|
|
33242
|
-
|
|
33293
|
+
if (!needImportTransform) {
|
|
33294
|
+
attr.value.content = set.join(', ');
|
|
33295
|
+
return;
|
|
33296
|
+
}
|
|
33243
33297
|
}
|
|
33244
33298
|
const compoundExpression = createCompoundExpression([], attr.loc);
|
|
33245
33299
|
imageCandidates.forEach(({ url, descriptor }, index) => {
|
|
33246
|
-
if (
|
|
33247
|
-
!isDataUrl(url) &&
|
|
33248
|
-
(options.includeAbsolute || isRelativeUrl(url))) {
|
|
33300
|
+
if (shouldProcessUrl(url)) {
|
|
33249
33301
|
const { path } = parseUrl(url);
|
|
33250
33302
|
let exp;
|
|
33251
33303
|
if (path) {
|
|
@@ -33275,13 +33327,16 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
33275
33327
|
compoundExpression.children.push(` + ', ' + `);
|
|
33276
33328
|
}
|
|
33277
33329
|
});
|
|
33278
|
-
|
|
33279
|
-
|
|
33330
|
+
let exp = compoundExpression;
|
|
33331
|
+
if (context.hoistStatic) {
|
|
33332
|
+
exp = context.hoist(compoundExpression);
|
|
33333
|
+
exp.constType = 3 /* CAN_STRINGIFY */;
|
|
33334
|
+
}
|
|
33280
33335
|
node.props[index] = {
|
|
33281
33336
|
type: 7 /* DIRECTIVE */,
|
|
33282
33337
|
name: 'bind',
|
|
33283
33338
|
arg: createSimpleExpression('srcset', true, attr.loc),
|
|
33284
|
-
exp
|
|
33339
|
+
exp,
|
|
33285
33340
|
modifiers: [],
|
|
33286
33341
|
loc: attr.loc
|
|
33287
33342
|
};
|
|
@@ -33295,6 +33350,7 @@ const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
|
|
|
33295
33350
|
const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
|
|
33296
33351
|
const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
|
|
33297
33352
|
const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
|
|
33353
|
+
const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
|
|
33298
33354
|
const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
|
|
33299
33355
|
const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
|
|
33300
33356
|
const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
|
|
@@ -33314,6 +33370,7 @@ const ssrHelpers = {
|
|
|
33314
33370
|
[SSR_RENDER_VNODE]: `ssrRenderVNode`,
|
|
33315
33371
|
[SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
|
|
33316
33372
|
[SSR_RENDER_SLOT]: `ssrRenderSlot`,
|
|
33373
|
+
[SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
|
|
33317
33374
|
[SSR_RENDER_CLASS]: `ssrRenderClass`,
|
|
33318
33375
|
[SSR_RENDER_STYLE]: `ssrRenderStyle`,
|
|
33319
33376
|
[SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
|
|
@@ -33366,7 +33423,7 @@ function processIfBranch(branch, context, disableNestedFragments = false) {
|
|
|
33366
33423
|
(children.length !== 1 || children[0].type !== 1 /* ELEMENT */) &&
|
|
33367
33424
|
// optimize away nested fragments when the only child is a ForNode
|
|
33368
33425
|
!(children.length === 1 && children[0].type === 11 /* FOR */);
|
|
33369
|
-
return processChildrenAsStatement(
|
|
33426
|
+
return processChildrenAsStatement(branch, context, needFragmentWrapper);
|
|
33370
33427
|
}
|
|
33371
33428
|
|
|
33372
33429
|
// Plugin for the first transform pass, which simply constructs the AST node
|
|
@@ -33377,7 +33434,7 @@ function ssrProcessFor(node, context, disableNestedFragments = false) {
|
|
|
33377
33434
|
const needFragmentWrapper = !disableNestedFragments &&
|
|
33378
33435
|
(node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */);
|
|
33379
33436
|
const renderLoop = createFunctionExpression(createForLoopParams(node.parseResult));
|
|
33380
|
-
renderLoop.body = processChildrenAsStatement(node
|
|
33437
|
+
renderLoop.body = processChildrenAsStatement(node, context, needFragmentWrapper);
|
|
33381
33438
|
// v-for always renders a fragment unless explicitly disabled
|
|
33382
33439
|
if (!disableNestedFragments) {
|
|
33383
33440
|
context.pushStringPart(`<!--[-->`);
|
|
@@ -33407,7 +33464,20 @@ const ssrTransformSlotOutlet = (node, context) => {
|
|
|
33407
33464
|
if (context.scopeId && context.slotted !== false) {
|
|
33408
33465
|
args.push(`"${context.scopeId}-s"`);
|
|
33409
33466
|
}
|
|
33410
|
-
|
|
33467
|
+
let method = SSR_RENDER_SLOT;
|
|
33468
|
+
// #3989
|
|
33469
|
+
// check if this is a single slot inside a transition wrapper - since
|
|
33470
|
+
// transition will unwrap the slot fragment into a single vnode at runtime,
|
|
33471
|
+
// we need to avoid rendering the slot as a fragment.
|
|
33472
|
+
const parent = context.parent;
|
|
33473
|
+
if (parent &&
|
|
33474
|
+
parent.type === 1 /* ELEMENT */ &&
|
|
33475
|
+
parent.tagType === 1 /* COMPONENT */ &&
|
|
33476
|
+
resolveComponentType(parent, context, true) === TRANSITION &&
|
|
33477
|
+
parent.children.filter(c => c.type === 1 /* ELEMENT */).length === 1) {
|
|
33478
|
+
method = SSR_RENDER_SLOT_INNER;
|
|
33479
|
+
}
|
|
33480
|
+
node.ssrCodegenNode = createCallExpression(context.helper(method), args);
|
|
33411
33481
|
}
|
|
33412
33482
|
};
|
|
33413
33483
|
function ssrProcessSlotOutlet(node, context) {
|
|
@@ -33415,7 +33485,7 @@ function ssrProcessSlotOutlet(node, context) {
|
|
|
33415
33485
|
// has fallback content
|
|
33416
33486
|
if (node.children.length) {
|
|
33417
33487
|
const fallbackRenderFn = createFunctionExpression([]);
|
|
33418
|
-
fallbackRenderFn.body = processChildrenAsStatement(node
|
|
33488
|
+
fallbackRenderFn.body = processChildrenAsStatement(node, context);
|
|
33419
33489
|
// _renderSlot(slots, name, props, fallback, ...)
|
|
33420
33490
|
renderCall.arguments[3] = fallbackRenderFn;
|
|
33421
33491
|
}
|
|
@@ -33467,7 +33537,7 @@ function ssrProcessTeleport(node, context) {
|
|
|
33467
33537
|
true, // newline
|
|
33468
33538
|
false, // isSlot
|
|
33469
33539
|
node.loc);
|
|
33470
|
-
contentRenderFn.body = processChildrenAsStatement(node
|
|
33540
|
+
contentRenderFn.body = processChildrenAsStatement(node, context);
|
|
33471
33541
|
context.pushStatement(createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
|
|
33472
33542
|
`_push`,
|
|
33473
33543
|
contentRenderFn,
|
|
@@ -33510,8 +33580,8 @@ function ssrProcessSuspense(node, context) {
|
|
|
33510
33580
|
}
|
|
33511
33581
|
const { slotsExp, wipSlots } = wipEntry;
|
|
33512
33582
|
for (let i = 0; i < wipSlots.length; i++) {
|
|
33513
|
-
const
|
|
33514
|
-
fn.body = processChildrenAsStatement(
|
|
33583
|
+
const slot = wipSlots[i];
|
|
33584
|
+
slot.fn.body = processChildrenAsStatement(slot, context);
|
|
33515
33585
|
}
|
|
33516
33586
|
// _push(ssrRenderSuspense(slots))
|
|
33517
33587
|
context.pushStatement(createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
|
|
@@ -33520,39 +33590,6 @@ function ssrProcessSuspense(node, context) {
|
|
|
33520
33590
|
]));
|
|
33521
33591
|
}
|
|
33522
33592
|
|
|
33523
|
-
function ssrProcessTransitionGroup(node, context) {
|
|
33524
|
-
const tag = findProp(node, 'tag');
|
|
33525
|
-
if (tag) {
|
|
33526
|
-
if (tag.type === 7 /* DIRECTIVE */) {
|
|
33527
|
-
// dynamic :tag
|
|
33528
|
-
context.pushStringPart(`<`);
|
|
33529
|
-
context.pushStringPart(tag.exp);
|
|
33530
|
-
context.pushStringPart(`>`);
|
|
33531
|
-
processChildren(node.children, context, false,
|
|
33532
|
-
/**
|
|
33533
|
-
* TransitionGroup has the special runtime behavior of flattening and
|
|
33534
|
-
* concatenating all children into a single fragment (in order for them to
|
|
33535
|
-
* be patched using the same key map) so we need to account for that here
|
|
33536
|
-
* by disabling nested fragment wrappers from being generated.
|
|
33537
|
-
*/
|
|
33538
|
-
true);
|
|
33539
|
-
context.pushStringPart(`</`);
|
|
33540
|
-
context.pushStringPart(tag.exp);
|
|
33541
|
-
context.pushStringPart(`>`);
|
|
33542
|
-
}
|
|
33543
|
-
else {
|
|
33544
|
-
// static tag
|
|
33545
|
-
context.pushStringPart(`<${tag.value.content}>`);
|
|
33546
|
-
processChildren(node.children, context, false, true);
|
|
33547
|
-
context.pushStringPart(`</${tag.value.content}>`);
|
|
33548
|
-
}
|
|
33549
|
-
}
|
|
33550
|
-
else {
|
|
33551
|
-
// fragment
|
|
33552
|
-
processChildren(node.children, context, true, true);
|
|
33553
|
-
}
|
|
33554
|
-
}
|
|
33555
|
-
|
|
33556
33593
|
// for directives with children overwrite (e.g. v-html & v-text), we need to
|
|
33557
33594
|
// store the raw children so that they can be added in the 2nd pass.
|
|
33558
33595
|
const rawChildrenMap = new WeakMap();
|
|
@@ -33574,7 +33611,7 @@ const ssrTransformElement = (node, context) => {
|
|
|
33574
33611
|
const hasCustomDir = node.props.some(p => p.type === 7 /* DIRECTIVE */ && !isBuiltInDirective(p.name));
|
|
33575
33612
|
const needMergeProps = hasDynamicVBind || hasCustomDir;
|
|
33576
33613
|
if (needMergeProps) {
|
|
33577
|
-
const { props, directives } = buildProps(node, context, node.props, true /* ssr */);
|
|
33614
|
+
const { props, directives } = buildProps(node, context, node.props, false /* isComponent */, false /* isDynamicComponent */, true /* ssr */);
|
|
33578
33615
|
if (props || directives.length) {
|
|
33579
33616
|
const mergedProps = buildSSRProps(props, directives, context);
|
|
33580
33617
|
const propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [mergedProps]);
|
|
@@ -33653,7 +33690,7 @@ const ssrTransformElement = (node, context) => {
|
|
|
33653
33690
|
node.children = [createInterpolation(prop.exp, prop.loc)];
|
|
33654
33691
|
}
|
|
33655
33692
|
}
|
|
33656
|
-
else if (!needMergeProps) {
|
|
33693
|
+
else if (!needMergeProps && prop.name !== 'on') {
|
|
33657
33694
|
// Directive transforms.
|
|
33658
33695
|
const directiveTransform = context.directiveTransforms[prop.name];
|
|
33659
33696
|
if (directiveTransform) {
|
|
@@ -33818,7 +33855,7 @@ function ssrProcessElement(node, context) {
|
|
|
33818
33855
|
context.pushStringPart(rawChildren);
|
|
33819
33856
|
}
|
|
33820
33857
|
else if (node.children.length) {
|
|
33821
|
-
processChildren(node
|
|
33858
|
+
processChildren(node, context);
|
|
33822
33859
|
}
|
|
33823
33860
|
if (!isVoidTag(node.tag)) {
|
|
33824
33861
|
// push closing tag
|
|
@@ -33826,11 +33863,75 @@ function ssrProcessElement(node, context) {
|
|
|
33826
33863
|
}
|
|
33827
33864
|
}
|
|
33828
33865
|
|
|
33866
|
+
const wipMap$1 = new WeakMap();
|
|
33867
|
+
// phase 1: build props
|
|
33868
|
+
function ssrTransformTransitionGroup(node, context) {
|
|
33869
|
+
return () => {
|
|
33870
|
+
const tag = findProp(node, 'tag');
|
|
33871
|
+
if (tag) {
|
|
33872
|
+
const otherProps = node.props.filter(p => p !== tag);
|
|
33873
|
+
const { props, directives } = buildProps(node, context, otherProps, true, /* isComponent */ false, /* isDynamicComponent */ true /* ssr (skip event listeners) */);
|
|
33874
|
+
let propsExp = null;
|
|
33875
|
+
if (props || directives.length) {
|
|
33876
|
+
propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
|
|
33877
|
+
buildSSRProps(props, directives, context)
|
|
33878
|
+
]);
|
|
33879
|
+
}
|
|
33880
|
+
wipMap$1.set(node, {
|
|
33881
|
+
tag,
|
|
33882
|
+
propsExp
|
|
33883
|
+
});
|
|
33884
|
+
}
|
|
33885
|
+
};
|
|
33886
|
+
}
|
|
33887
|
+
// phase 2: process children
|
|
33888
|
+
function ssrProcessTransitionGroup(node, context) {
|
|
33889
|
+
const entry = wipMap$1.get(node);
|
|
33890
|
+
if (entry) {
|
|
33891
|
+
const { tag, propsExp } = entry;
|
|
33892
|
+
if (tag.type === 7 /* DIRECTIVE */) {
|
|
33893
|
+
// dynamic :tag
|
|
33894
|
+
context.pushStringPart(`<`);
|
|
33895
|
+
context.pushStringPart(tag.exp);
|
|
33896
|
+
if (propsExp) {
|
|
33897
|
+
context.pushStringPart(propsExp);
|
|
33898
|
+
}
|
|
33899
|
+
context.pushStringPart(`>`);
|
|
33900
|
+
processChildren(node, context, false,
|
|
33901
|
+
/**
|
|
33902
|
+
* TransitionGroup has the special runtime behavior of flattening and
|
|
33903
|
+
* concatenating all children into a single fragment (in order for them to
|
|
33904
|
+
* be patched using the same key map) so we need to account for that here
|
|
33905
|
+
* by disabling nested fragment wrappers from being generated.
|
|
33906
|
+
*/
|
|
33907
|
+
true);
|
|
33908
|
+
context.pushStringPart(`</`);
|
|
33909
|
+
context.pushStringPart(tag.exp);
|
|
33910
|
+
context.pushStringPart(`>`);
|
|
33911
|
+
}
|
|
33912
|
+
else {
|
|
33913
|
+
// static tag
|
|
33914
|
+
context.pushStringPart(`<${tag.value.content}`);
|
|
33915
|
+
if (propsExp) {
|
|
33916
|
+
context.pushStringPart(propsExp);
|
|
33917
|
+
}
|
|
33918
|
+
context.pushStringPart(`>`);
|
|
33919
|
+
processChildren(node, context, false, true);
|
|
33920
|
+
context.pushStringPart(`</${tag.value.content}>`);
|
|
33921
|
+
}
|
|
33922
|
+
}
|
|
33923
|
+
else {
|
|
33924
|
+
// fragment
|
|
33925
|
+
processChildren(node, context, true, true);
|
|
33926
|
+
}
|
|
33927
|
+
}
|
|
33928
|
+
|
|
33829
33929
|
// We need to construct the slot functions in the 1st pass to ensure proper
|
|
33830
33930
|
// scope tracking, but the children of each slot cannot be processed until
|
|
33831
33931
|
// the 2nd pass, so we store the WIP slot functions in a weakMap during the 1st
|
|
33832
33932
|
// pass and complete them in the 2nd pass.
|
|
33833
|
-
const wipMap$
|
|
33933
|
+
const wipMap$2 = new WeakMap();
|
|
33934
|
+
const WIP_SLOT = Symbol();
|
|
33834
33935
|
const componentTypeMap = new WeakMap();
|
|
33835
33936
|
// ssr component transform is done in two phases:
|
|
33836
33937
|
// In phase 1. we use `buildSlot` to analyze the children of the component into
|
|
@@ -33844,12 +33945,16 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33844
33945
|
return;
|
|
33845
33946
|
}
|
|
33846
33947
|
const component = resolveComponentType(node, context, true /* ssr */);
|
|
33948
|
+
const isDynamicComponent = isObject(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
33847
33949
|
componentTypeMap.set(node, component);
|
|
33848
33950
|
if (isSymbol(component)) {
|
|
33849
33951
|
if (component === SUSPENSE) {
|
|
33850
33952
|
return ssrTransformSuspense(node, context);
|
|
33851
33953
|
}
|
|
33852
|
-
|
|
33954
|
+
if (component === TRANSITION_GROUP) {
|
|
33955
|
+
return ssrTransformTransitionGroup(node, context);
|
|
33956
|
+
}
|
|
33957
|
+
return; // other built-in components: fallthrough
|
|
33853
33958
|
}
|
|
33854
33959
|
// Build the fallback vnode-based branch for the component's slots.
|
|
33855
33960
|
// We need to clone the node into a fresh copy and use the buildSlots' logic
|
|
@@ -33873,19 +33978,20 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33873
33978
|
if (node.props.length) {
|
|
33874
33979
|
// note we are not passing ssr: true here because for components, v-on
|
|
33875
33980
|
// handlers should still be passed
|
|
33876
|
-
const { props, directives } = buildProps(node, context);
|
|
33981
|
+
const { props, directives } = buildProps(node, context, undefined, true, isDynamicComponent);
|
|
33877
33982
|
if (props || directives.length) {
|
|
33878
33983
|
propsExp = buildSSRProps(props, directives, context);
|
|
33879
33984
|
}
|
|
33880
33985
|
}
|
|
33881
33986
|
const wipEntries = [];
|
|
33882
|
-
wipMap$
|
|
33987
|
+
wipMap$2.set(node, wipEntries);
|
|
33883
33988
|
const buildSSRSlotFn = (props, children, loc) => {
|
|
33884
33989
|
const fn = createFunctionExpression([props || `_`, `_push`, `_parent`, `_scopeId`], undefined, // no return, assign body later
|
|
33885
33990
|
true, // newline
|
|
33886
33991
|
true, // isSlot
|
|
33887
33992
|
loc);
|
|
33888
33993
|
wipEntries.push({
|
|
33994
|
+
type: WIP_SLOT,
|
|
33889
33995
|
fn,
|
|
33890
33996
|
children,
|
|
33891
33997
|
// also collect the corresponding vnode branch built earlier
|
|
@@ -33915,7 +34021,7 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33915
34021
|
}
|
|
33916
34022
|
};
|
|
33917
34023
|
};
|
|
33918
|
-
function ssrProcessComponent(node, context) {
|
|
34024
|
+
function ssrProcessComponent(node, context, parent) {
|
|
33919
34025
|
const component = componentTypeMap.get(node);
|
|
33920
34026
|
if (!node.ssrCodegenNode) {
|
|
33921
34027
|
// this is a built-in component that fell-through.
|
|
@@ -33931,19 +34037,29 @@ function ssrProcessComponent(node, context) {
|
|
|
33931
34037
|
else {
|
|
33932
34038
|
// real fall-through: Transition / KeepAlive
|
|
33933
34039
|
// just render its children.
|
|
33934
|
-
|
|
34040
|
+
// #5352: if is at root level of a slot, push an empty string.
|
|
34041
|
+
// this does not affect the final output, but avoids all-comment slot
|
|
34042
|
+
// content of being treated as empty by ssrRenderSlot().
|
|
34043
|
+
if (parent.type === WIP_SLOT) {
|
|
34044
|
+
context.pushStringPart(``);
|
|
34045
|
+
}
|
|
34046
|
+
// #5351: filter out comment children inside transition
|
|
34047
|
+
if (component === TRANSITION) {
|
|
34048
|
+
node.children = node.children.filter(c => c.type !== 3 /* COMMENT */);
|
|
34049
|
+
}
|
|
34050
|
+
processChildren(node, context);
|
|
33935
34051
|
}
|
|
33936
34052
|
}
|
|
33937
34053
|
else {
|
|
33938
34054
|
// finish up slot function expressions from the 1st pass.
|
|
33939
|
-
const wipEntries = wipMap$
|
|
34055
|
+
const wipEntries = wipMap$2.get(node) || [];
|
|
33940
34056
|
for (let i = 0; i < wipEntries.length; i++) {
|
|
33941
|
-
const { fn,
|
|
34057
|
+
const { fn, vnodeBranch } = wipEntries[i];
|
|
33942
34058
|
// For each slot, we generate two branches: one SSR-optimized branch and
|
|
33943
34059
|
// one normal vnode-based branch. The branches are taken based on the
|
|
33944
34060
|
// presence of the 2nd `_push` argument (which is only present if the slot
|
|
33945
34061
|
// is called by `_ssrRenderSlot`.
|
|
33946
|
-
fn.body = createIfStatement(createSimpleExpression(`_push`, false), processChildrenAsStatement(
|
|
34062
|
+
fn.body = createIfStatement(createSimpleExpression(`_push`, false), processChildrenAsStatement(wipEntries[i], context, false, true /* withSlotScopeId */), vnodeBranch);
|
|
33947
34063
|
}
|
|
33948
34064
|
// component is inside a slot, inherit slot scope Id
|
|
33949
34065
|
if (context.withSlotScopeId) {
|
|
@@ -34063,7 +34179,7 @@ function ssrCodegenTransform(ast, options) {
|
|
|
34063
34179
|
context.body.push(createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`]));
|
|
34064
34180
|
}
|
|
34065
34181
|
const isFragment = ast.children.length > 1 && ast.children.some(c => !isText(c));
|
|
34066
|
-
processChildren(ast
|
|
34182
|
+
processChildren(ast, context, isFragment);
|
|
34067
34183
|
ast.codegenNode = createBlockStatement(context.body);
|
|
34068
34184
|
// Finalize helpers.
|
|
34069
34185
|
// We need to separate helpers imported from 'vue' vs. '@vue/server-renderer'
|
|
@@ -34114,10 +34230,11 @@ function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
|
|
|
34114
34230
|
// ensure child inherits parent helpers
|
|
34115
34231
|
return createSSRTransformContext(parent.root, parent.options, parent.helpers, withSlotScopeId);
|
|
34116
34232
|
}
|
|
34117
|
-
function processChildren(
|
|
34233
|
+
function processChildren(parent, context, asFragment = false, disableNestedFragments = false) {
|
|
34118
34234
|
if (asFragment) {
|
|
34119
34235
|
context.pushStringPart(`<!--[-->`);
|
|
34120
34236
|
}
|
|
34237
|
+
const { children } = parent;
|
|
34121
34238
|
for (let i = 0; i < children.length; i++) {
|
|
34122
34239
|
const child = children[i];
|
|
34123
34240
|
switch (child.type) {
|
|
@@ -34127,7 +34244,7 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34127
34244
|
ssrProcessElement(child, context);
|
|
34128
34245
|
break;
|
|
34129
34246
|
case 1 /* COMPONENT */:
|
|
34130
|
-
ssrProcessComponent(child, context);
|
|
34247
|
+
ssrProcessComponent(child, context, parent);
|
|
34131
34248
|
break;
|
|
34132
34249
|
case 2 /* SLOT */:
|
|
34133
34250
|
ssrProcessSlotOutlet(child, context);
|
|
@@ -34178,9 +34295,9 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34178
34295
|
context.pushStringPart(`<!--]-->`);
|
|
34179
34296
|
}
|
|
34180
34297
|
}
|
|
34181
|
-
function processChildrenAsStatement(
|
|
34298
|
+
function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
|
|
34182
34299
|
const childContext = createChildContext(parentContext, withSlotScopeId);
|
|
34183
|
-
processChildren(
|
|
34300
|
+
processChildren(parent, childContext, asFragment);
|
|
34184
34301
|
return createBlockStatement(childContext.body);
|
|
34185
34302
|
}
|
|
34186
34303
|
|
|
@@ -34299,7 +34416,8 @@ const ssrTransformShow = (dir, node, context) => {
|
|
|
34299
34416
|
};
|
|
34300
34417
|
};
|
|
34301
34418
|
|
|
34302
|
-
const
|
|
34419
|
+
const filterChild = (node) => node.children.filter(n => n.type !== 3 /* COMMENT */);
|
|
34420
|
+
const hasSingleChild = (node) => filterChild(node).length === 1;
|
|
34303
34421
|
const ssrInjectFallthroughAttrs = (node, context) => {
|
|
34304
34422
|
// _attrs is provided as a function argument.
|
|
34305
34423
|
// mark it as a known identifier so that it doesn't get prefixed by
|
|
@@ -34311,16 +34429,37 @@ const ssrInjectFallthroughAttrs = (node, context) => {
|
|
|
34311
34429
|
node.tagType === 1 /* COMPONENT */ &&
|
|
34312
34430
|
(isBuiltInType(node.tag, 'Transition') ||
|
|
34313
34431
|
isBuiltInType(node.tag, 'KeepAlive'))) {
|
|
34314
|
-
|
|
34315
|
-
|
|
34432
|
+
const rootChildren = filterChild(context.root);
|
|
34433
|
+
if (rootChildren.length === 1 && rootChildren[0] === node) {
|
|
34434
|
+
if (hasSingleChild(node)) {
|
|
34435
|
+
injectFallthroughAttrs(node.children[0]);
|
|
34436
|
+
}
|
|
34437
|
+
return;
|
|
34316
34438
|
}
|
|
34317
|
-
return;
|
|
34318
34439
|
}
|
|
34319
34440
|
const parent = context.parent;
|
|
34320
34441
|
if (!parent || parent.type !== 0 /* ROOT */) {
|
|
34321
34442
|
return;
|
|
34322
34443
|
}
|
|
34323
34444
|
if (node.type === 10 /* IF_BRANCH */ && hasSingleChild(node)) {
|
|
34445
|
+
// detect cases where the parent v-if is not the only root level node
|
|
34446
|
+
let hasEncounteredIf = false;
|
|
34447
|
+
for (const c of filterChild(parent)) {
|
|
34448
|
+
if (c.type === 9 /* IF */ ||
|
|
34449
|
+
(c.type === 1 /* ELEMENT */ && findDir(c, 'if'))) {
|
|
34450
|
+
// multiple root v-if
|
|
34451
|
+
if (hasEncounteredIf)
|
|
34452
|
+
return;
|
|
34453
|
+
hasEncounteredIf = true;
|
|
34454
|
+
}
|
|
34455
|
+
else if (
|
|
34456
|
+
// node before v-if
|
|
34457
|
+
!hasEncounteredIf ||
|
|
34458
|
+
// non else nodes
|
|
34459
|
+
!(c.type === 1 /* ELEMENT */ && findDir(c, /else/, true))) {
|
|
34460
|
+
return;
|
|
34461
|
+
}
|
|
34462
|
+
}
|
|
34324
34463
|
injectFallthroughAttrs(node.children[0]);
|
|
34325
34464
|
}
|
|
34326
34465
|
else if (hasSingleChild(parent)) {
|
|
@@ -34421,11 +34560,12 @@ function compile$1(template, options = {}) {
|
|
|
34421
34560
|
...(options.nodeTransforms || []) // user transforms
|
|
34422
34561
|
], directiveTransforms: Object.assign({
|
|
34423
34562
|
// reusing core v-bind
|
|
34424
|
-
bind: transformBind,
|
|
34563
|
+
bind: transformBind, on: transformOn,
|
|
34425
34564
|
// model and show has dedicated SSR handling
|
|
34426
34565
|
model: ssrTransformModel, show: ssrTransformShow,
|
|
34427
34566
|
// the following are ignored during SSR
|
|
34428
|
-
on: noopDirectiveTransform,
|
|
34567
|
+
// on: noopDirectiveTransform,
|
|
34568
|
+
cloak: noopDirectiveTransform, once: noopDirectiveTransform, memo: noopDirectiveTransform }, (options.directiveTransforms || {}) // user transforms
|
|
34429
34569
|
) }));
|
|
34430
34570
|
// traverse the template AST and convert into SSR codegen AST
|
|
34431
34571
|
// by replacing ast.codegenNode.
|
|
@@ -34547,7 +34687,7 @@ function doCompileTemplate({ filename, id, scoped, slotted, inMap, source, ssr =
|
|
|
34547
34687
|
const shortId = id.replace(/^data-v-/, '');
|
|
34548
34688
|
const longId = `data-v-${shortId}`;
|
|
34549
34689
|
let { code, ast, preamble, map } = compiler.compile(source, Object.assign(Object.assign({ mode: 'module', prefixIdentifiers: true, hoistStatic: true, cacheHandlers: true, ssrCssVars: ssr && ssrCssVars && ssrCssVars.length
|
|
34550
|
-
? genCssVarsFromList(ssrCssVars, shortId, isProd)
|
|
34690
|
+
? genCssVarsFromList(ssrCssVars, shortId, isProd, true)
|
|
34551
34691
|
: '', scopeId: scoped ? longId : undefined, slotted, sourceMap: true }, compilerOptions), { nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []), filename, onError: e => errors.push(e), onWarn: w => warnings.push(w) }));
|
|
34552
34692
|
// inMap should be the map produced by ./parse.ts which is a simple line-only
|
|
34553
34693
|
// mapping. If it is present, we need to adjust the final map and errors to
|
|
@@ -34633,7 +34773,7 @@ function patchErrors(errors, source, inMap) {
|
|
|
34633
34773
|
}
|
|
34634
34774
|
|
|
34635
34775
|
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
34636
|
-
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s;
|
|
34776
|
+
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
34637
34777
|
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
34638
34778
|
/**
|
|
34639
34779
|
* Utility for rewriting `export default` in a script block into a variable
|
|
@@ -34664,25 +34804,61 @@ function rewriteDefault(input, as, parserPlugins) {
|
|
|
34664
34804
|
plugins: parserPlugins
|
|
34665
34805
|
}).program.body;
|
|
34666
34806
|
ast.forEach(node => {
|
|
34807
|
+
var _a;
|
|
34667
34808
|
if (node.type === 'ExportDefaultDeclaration') {
|
|
34668
34809
|
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
34669
34810
|
}
|
|
34670
34811
|
if (node.type === 'ExportNamedDeclaration') {
|
|
34671
|
-
node.specifiers
|
|
34812
|
+
for (const specifier of node.specifiers) {
|
|
34672
34813
|
if (specifier.type === 'ExportSpecifier' &&
|
|
34673
34814
|
specifier.exported.type === 'Identifier' &&
|
|
34674
34815
|
specifier.exported.name === 'default') {
|
|
34675
|
-
|
|
34676
|
-
|
|
34816
|
+
if (node.source) {
|
|
34817
|
+
if (specifier.local.name === 'default') {
|
|
34818
|
+
const end = specifierEnd(input, specifier.local.end, node.end);
|
|
34819
|
+
s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
|
|
34820
|
+
s.overwrite(specifier.start, end, ``);
|
|
34821
|
+
s.append(`\nconst ${as} = __VUE_DEFAULT__`);
|
|
34822
|
+
continue;
|
|
34823
|
+
}
|
|
34824
|
+
else {
|
|
34825
|
+
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
34826
|
+
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${(_a = node.source) === null || _a === void 0 ? void 0 : _a.value}'\n`);
|
|
34827
|
+
s.overwrite(specifier.start, end, ``);
|
|
34828
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
34829
|
+
continue;
|
|
34830
|
+
}
|
|
34831
|
+
}
|
|
34832
|
+
const end = specifierEnd(input, specifier.end, node.end);
|
|
34833
|
+
s.overwrite(specifier.start, end, ``);
|
|
34677
34834
|
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
34678
34835
|
}
|
|
34679
|
-
}
|
|
34836
|
+
}
|
|
34680
34837
|
}
|
|
34681
34838
|
});
|
|
34682
34839
|
return s.toString();
|
|
34683
34840
|
}
|
|
34684
34841
|
function hasDefaultExport(input) {
|
|
34685
34842
|
return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
|
|
34843
|
+
}
|
|
34844
|
+
function specifierEnd(input, end, nodeEnd) {
|
|
34845
|
+
// export { default , foo } ...
|
|
34846
|
+
let hasCommas = false;
|
|
34847
|
+
let oldEnd = end;
|
|
34848
|
+
while (end < nodeEnd) {
|
|
34849
|
+
if (/\s/.test(input.charAt(end))) {
|
|
34850
|
+
end++;
|
|
34851
|
+
}
|
|
34852
|
+
else if (input.charAt(end) === ',') {
|
|
34853
|
+
end++;
|
|
34854
|
+
hasCommas = true;
|
|
34855
|
+
break;
|
|
34856
|
+
}
|
|
34857
|
+
else if (input.charAt(end) === '}') {
|
|
34858
|
+
break;
|
|
34859
|
+
}
|
|
34860
|
+
}
|
|
34861
|
+
return hasCommas ? end : oldEnd;
|
|
34686
34862
|
}
|
|
34687
34863
|
|
|
34688
34864
|
const CONVERT_SYMBOL = '$';
|
|
@@ -35045,13 +35221,13 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
35045
35221
|
if (isProp) {
|
|
35046
35222
|
if (escapeScope) {
|
|
35047
35223
|
// prop binding in $$()
|
|
35048
|
-
// { prop } -> { prop:
|
|
35224
|
+
// { prop } -> { prop: __props_prop }
|
|
35049
35225
|
registerEscapedPropBinding(id);
|
|
35050
35226
|
s.appendLeft(id.end + offset, `: __props_${propsLocalToPublicMap[id.name]}`);
|
|
35051
35227
|
}
|
|
35052
35228
|
else {
|
|
35053
|
-
// { prop } -> { prop:
|
|
35054
|
-
s.appendLeft(id.end + offset, `:
|
|
35229
|
+
// { prop } -> { prop: __props.prop }
|
|
35230
|
+
s.appendLeft(id.end + offset, `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`);
|
|
35055
35231
|
}
|
|
35056
35232
|
}
|
|
35057
35233
|
else {
|
|
@@ -35069,7 +35245,7 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
35069
35245
|
}
|
|
35070
35246
|
else {
|
|
35071
35247
|
// x --> __props.x
|
|
35072
|
-
s.overwrite(id.start + offset, id.end + offset,
|
|
35248
|
+
s.overwrite(id.start + offset, id.end + offset, genPropsAccessExp(propsLocalToPublicMap[id.name]));
|
|
35073
35249
|
}
|
|
35074
35250
|
}
|
|
35075
35251
|
else {
|
|
@@ -35104,6 +35280,15 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
35104
35280
|
}
|
|
35105
35281
|
return;
|
|
35106
35282
|
}
|
|
35283
|
+
// catch param
|
|
35284
|
+
if (node.type === 'CatchClause') {
|
|
35285
|
+
scopeStack.push((currentScope = {}));
|
|
35286
|
+
if (node.param && node.param.type === 'Identifier') {
|
|
35287
|
+
registerBinding(node.param);
|
|
35288
|
+
}
|
|
35289
|
+
walkScope(node.body);
|
|
35290
|
+
return;
|
|
35291
|
+
}
|
|
35107
35292
|
// non-function block scopes
|
|
35108
35293
|
if (node.type === 'BlockStatement' && !isFunctionType(parent)) {
|
|
35109
35294
|
scopeStack.push((currentScope = {}));
|
|
@@ -35207,6 +35392,7 @@ const isBuiltInDir = makeMap(`once,memo,if,else,else-if,slot,text,html,on,bind,m
|
|
|
35207
35392
|
* normal `<script>` + `<script setup>` if both are present.
|
|
35208
35393
|
*/
|
|
35209
35394
|
function compileScript(sfc, options) {
|
|
35395
|
+
var _a;
|
|
35210
35396
|
let { script, scriptSetup, source, filename } = sfc;
|
|
35211
35397
|
// feature flags
|
|
35212
35398
|
// TODO remove support for deprecated options when out of experimental
|
|
@@ -35235,6 +35421,11 @@ function compileScript(sfc, options) {
|
|
|
35235
35421
|
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
|
|
35236
35422
|
plugins.push('jsx');
|
|
35237
35423
|
}
|
|
35424
|
+
else {
|
|
35425
|
+
// If don't match the case of adding jsx, should remove the jsx from the babelParserPlugins
|
|
35426
|
+
if (options.babelParserPlugins)
|
|
35427
|
+
options.babelParserPlugins = options.babelParserPlugins.filter(n => n !== 'jsx');
|
|
35428
|
+
}
|
|
35238
35429
|
if (options.babelParserPlugins)
|
|
35239
35430
|
plugins.push(...options.babelParserPlugins);
|
|
35240
35431
|
if (isTS)
|
|
@@ -35310,6 +35501,8 @@ function compileScript(sfc, options) {
|
|
|
35310
35501
|
let hasDefinePropsCall = false;
|
|
35311
35502
|
let hasDefineEmitCall = false;
|
|
35312
35503
|
let hasDefineExposeCall = false;
|
|
35504
|
+
let hasDefaultExportName = false;
|
|
35505
|
+
let hasDefaultExportRender = false;
|
|
35313
35506
|
let propsRuntimeDecl;
|
|
35314
35507
|
let propsRuntimeDefaults;
|
|
35315
35508
|
let propsDestructureDecl;
|
|
@@ -35352,12 +35545,18 @@ function compileScript(sfc, options) {
|
|
|
35352
35545
|
function error(msg, node, end = node.end + startOffset) {
|
|
35353
35546
|
throw new Error(`[@vue/compiler-sfc] ${msg}\n\n${sfc.filename}\n${generateCodeFrame(source, node.start + startOffset, end)}`);
|
|
35354
35547
|
}
|
|
35355
|
-
function registerUserImport(source, local, imported, isType, isFromSetup) {
|
|
35548
|
+
function registerUserImport(source, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
|
|
35356
35549
|
if (source === 'vue' && imported) {
|
|
35357
35550
|
userImportAlias[imported] = local;
|
|
35358
35551
|
}
|
|
35359
|
-
|
|
35360
|
-
|
|
35552
|
+
// template usage check is only needed in non-inline mode, so we can skip
|
|
35553
|
+
// the work if inlineTemplate is true.
|
|
35554
|
+
let isUsedInTemplate = needTemplateUsageCheck;
|
|
35555
|
+
if (needTemplateUsageCheck &&
|
|
35556
|
+
isTS &&
|
|
35557
|
+
sfc.template &&
|
|
35558
|
+
!sfc.template.src &&
|
|
35559
|
+
!sfc.template.lang) {
|
|
35361
35560
|
isUsedInTemplate = isImportUsed(local, sfc);
|
|
35362
35561
|
}
|
|
35363
35562
|
userImports[local] = {
|
|
@@ -35399,7 +35598,9 @@ function compileScript(sfc, options) {
|
|
|
35399
35598
|
if (prop.computed) {
|
|
35400
35599
|
error(`${DEFINE_PROPS}() destructure cannot use computed key.`, prop.key);
|
|
35401
35600
|
}
|
|
35402
|
-
const propKey = prop.key.
|
|
35601
|
+
const propKey = prop.key.type === 'StringLiteral'
|
|
35602
|
+
? prop.key.value
|
|
35603
|
+
: prop.key.name;
|
|
35403
35604
|
if (prop.value.type === 'AssignmentPattern') {
|
|
35404
35605
|
// default value { foo = 123 }
|
|
35405
35606
|
const { left, right } = prop.value;
|
|
@@ -35628,7 +35829,7 @@ function compileScript(sfc, options) {
|
|
|
35628
35829
|
if (destructured && destructured.default) {
|
|
35629
35830
|
const value = scriptSetup.content.slice(destructured.default.start, destructured.default.end);
|
|
35630
35831
|
const isLiteral = destructured.default.type.endsWith('Literal');
|
|
35631
|
-
return isLiteral ? value : `() => ${value}`;
|
|
35832
|
+
return isLiteral ? value : `() => (${value})`;
|
|
35632
35833
|
}
|
|
35633
35834
|
}
|
|
35634
35835
|
function genSetupPropsType(node) {
|
|
@@ -35676,12 +35877,42 @@ function compileScript(sfc, options) {
|
|
|
35676
35877
|
const imported = specifier.type === 'ImportSpecifier' &&
|
|
35677
35878
|
specifier.imported.type === 'Identifier' &&
|
|
35678
35879
|
specifier.imported.name;
|
|
35679
|
-
registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type'
|
|
35880
|
+
registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type' ||
|
|
35881
|
+
(specifier.type === 'ImportSpecifier' &&
|
|
35882
|
+
specifier.importKind === 'type'), false, !options.inlineTemplate);
|
|
35680
35883
|
}
|
|
35681
35884
|
}
|
|
35682
35885
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
35683
35886
|
// export default
|
|
35684
35887
|
defaultExport = node;
|
|
35888
|
+
// check if user has manually specified `name` or 'render` option in
|
|
35889
|
+
// export default
|
|
35890
|
+
// if has name, skip name inference
|
|
35891
|
+
// if has render and no template, generate return object instead of
|
|
35892
|
+
// empty render function (#4980)
|
|
35893
|
+
let optionProperties;
|
|
35894
|
+
if (defaultExport.declaration.type === 'ObjectExpression') {
|
|
35895
|
+
optionProperties = defaultExport.declaration.properties;
|
|
35896
|
+
}
|
|
35897
|
+
else if (defaultExport.declaration.type === 'CallExpression' &&
|
|
35898
|
+
defaultExport.declaration.arguments[0].type === 'ObjectExpression') {
|
|
35899
|
+
optionProperties = defaultExport.declaration.arguments[0].properties;
|
|
35900
|
+
}
|
|
35901
|
+
if (optionProperties) {
|
|
35902
|
+
for (const s of optionProperties) {
|
|
35903
|
+
if (s.type === 'ObjectProperty' &&
|
|
35904
|
+
s.key.type === 'Identifier' &&
|
|
35905
|
+
s.key.name === 'name') {
|
|
35906
|
+
hasDefaultExportName = true;
|
|
35907
|
+
}
|
|
35908
|
+
if ((s.type === 'ObjectMethod' || s.type === 'ObjectProperty') &&
|
|
35909
|
+
s.key.type === 'Identifier' &&
|
|
35910
|
+
s.key.name === 'render') {
|
|
35911
|
+
// TODO warn when we provide a better way to do it?
|
|
35912
|
+
hasDefaultExportRender = true;
|
|
35913
|
+
}
|
|
35914
|
+
}
|
|
35915
|
+
}
|
|
35685
35916
|
// export default { ... } --> const __default__ = { ... }
|
|
35686
35917
|
const start = node.start + scriptStartOffset;
|
|
35687
35918
|
const end = node.declaration.start + scriptStartOffset;
|
|
@@ -35734,6 +35965,10 @@ function compileScript(sfc, options) {
|
|
|
35734
35965
|
// we need to move the block up so that `const __default__` is
|
|
35735
35966
|
// declared before being used in the actual component definition
|
|
35736
35967
|
if (scriptStartOffset > startOffset) {
|
|
35968
|
+
// if content doesn't end with newline, add one
|
|
35969
|
+
if (!/\n$/.test(script.content.trim())) {
|
|
35970
|
+
s.appendLeft(scriptEndOffset, `\n`);
|
|
35971
|
+
}
|
|
35737
35972
|
s.move(scriptStartOffset, scriptEndOffset, 0);
|
|
35738
35973
|
}
|
|
35739
35974
|
}
|
|
@@ -35788,9 +36023,12 @@ function compileScript(sfc, options) {
|
|
|
35788
36023
|
for (let i = 0; i < node.specifiers.length; i++) {
|
|
35789
36024
|
const specifier = node.specifiers[i];
|
|
35790
36025
|
const local = specifier.local.name;
|
|
35791
|
-
|
|
36026
|
+
let imported = specifier.type === 'ImportSpecifier' &&
|
|
35792
36027
|
specifier.imported.type === 'Identifier' &&
|
|
35793
36028
|
specifier.imported.name;
|
|
36029
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
36030
|
+
imported = '*';
|
|
36031
|
+
}
|
|
35794
36032
|
const source = node.source.value;
|
|
35795
36033
|
const existing = userImports[local];
|
|
35796
36034
|
if (source === 'vue' &&
|
|
@@ -35810,7 +36048,9 @@ function compileScript(sfc, options) {
|
|
|
35810
36048
|
}
|
|
35811
36049
|
}
|
|
35812
36050
|
else {
|
|
35813
|
-
registerUserImport(source, local, imported, node.importKind === 'type'
|
|
36051
|
+
registerUserImport(source, local, imported, node.importKind === 'type' ||
|
|
36052
|
+
(specifier.type === 'ImportSpecifier' &&
|
|
36053
|
+
specifier.importKind === 'type'), true, !options.inlineTemplate);
|
|
35814
36054
|
}
|
|
35815
36055
|
}
|
|
35816
36056
|
if (node.specifiers.length && removed === node.specifiers.length) {
|
|
@@ -35873,18 +36113,33 @@ function compileScript(sfc, options) {
|
|
|
35873
36113
|
// await
|
|
35874
36114
|
if ((node.type === 'VariableDeclaration' && !node.declare) ||
|
|
35875
36115
|
node.type.endsWith('Statement')) {
|
|
36116
|
+
const scope = [scriptSetupAst.body];
|
|
35876
36117
|
walk$1(node, {
|
|
35877
36118
|
enter(child, parent) {
|
|
35878
36119
|
if (isFunctionType(child)) {
|
|
35879
36120
|
this.skip();
|
|
35880
36121
|
}
|
|
36122
|
+
if (child.type === 'BlockStatement') {
|
|
36123
|
+
scope.push(child.body);
|
|
36124
|
+
}
|
|
35881
36125
|
if (child.type === 'AwaitExpression') {
|
|
35882
36126
|
hasAwait = true;
|
|
35883
|
-
|
|
35884
|
-
|
|
36127
|
+
// if the await expression is an expression statement and
|
|
36128
|
+
// - is in the root scope
|
|
36129
|
+
// - or is not the first statement in a nested block scope
|
|
36130
|
+
// then it needs a semicolon before the generated code.
|
|
36131
|
+
const currentScope = scope[scope.length - 1];
|
|
36132
|
+
const needsSemi = currentScope.some((n, i) => {
|
|
36133
|
+
return ((scope.length === 1 || i > 0) &&
|
|
36134
|
+
n.type === 'ExpressionStatement' &&
|
|
36135
|
+
n.start === child.start);
|
|
35885
36136
|
});
|
|
35886
36137
|
processAwait(child, needsSemi, parent.type === 'ExpressionStatement');
|
|
35887
36138
|
}
|
|
36139
|
+
},
|
|
36140
|
+
exit(node) {
|
|
36141
|
+
if (node.type === 'BlockStatement')
|
|
36142
|
+
scope.pop();
|
|
35888
36143
|
}
|
|
35889
36144
|
});
|
|
35890
36145
|
}
|
|
@@ -35933,7 +36188,7 @@ function compileScript(sfc, options) {
|
|
|
35933
36188
|
checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
|
|
35934
36189
|
checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
|
|
35935
36190
|
checkInvalidScopeReference(propsDestructureDecl, DEFINE_PROPS);
|
|
35936
|
-
checkInvalidScopeReference(emitsRuntimeDecl,
|
|
36191
|
+
checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_EMITS);
|
|
35937
36192
|
// 6. remove non-script content
|
|
35938
36193
|
if (script) {
|
|
35939
36194
|
if (startOffset < scriptStartOffset) {
|
|
@@ -35969,7 +36224,8 @@ function compileScript(sfc, options) {
|
|
|
35969
36224
|
// props aliases
|
|
35970
36225
|
if (propsDestructureDecl) {
|
|
35971
36226
|
if (propsDestructureRestId) {
|
|
35972
|
-
bindingMetadata[propsDestructureRestId] =
|
|
36227
|
+
bindingMetadata[propsDestructureRestId] =
|
|
36228
|
+
"setup-reactive-const" /* SETUP_REACTIVE_CONST */;
|
|
35973
36229
|
}
|
|
35974
36230
|
for (const key in propsDestructuredBindings) {
|
|
35975
36231
|
const { local } = propsDestructuredBindings[key];
|
|
@@ -35984,7 +36240,9 @@ function compileScript(sfc, options) {
|
|
|
35984
36240
|
if (isType)
|
|
35985
36241
|
continue;
|
|
35986
36242
|
bindingMetadata[key] =
|
|
35987
|
-
|
|
36243
|
+
imported === '*' ||
|
|
36244
|
+
(imported === 'default' && source.endsWith('.vue')) ||
|
|
36245
|
+
source === 'vue'
|
|
35988
36246
|
? "setup-const" /* SETUP_CONST */
|
|
35989
36247
|
: "setup-maybe-ref" /* SETUP_MAYBE_REF */;
|
|
35990
36248
|
}
|
|
@@ -36001,7 +36259,9 @@ function compileScript(sfc, options) {
|
|
|
36001
36259
|
}
|
|
36002
36260
|
}
|
|
36003
36261
|
// 8. inject `useCssVars` calls
|
|
36004
|
-
if (cssVars.length
|
|
36262
|
+
if (cssVars.length &&
|
|
36263
|
+
// no need to do this when targeting SSR
|
|
36264
|
+
!(options.inlineTemplate && ((_a = options.templateOptions) === null || _a === void 0 ? void 0 : _a.ssr))) {
|
|
36005
36265
|
helperImports.add(CSS_VARS_HELPER);
|
|
36006
36266
|
helperImports.add('unref');
|
|
36007
36267
|
s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
|
|
@@ -36040,7 +36300,19 @@ function compileScript(sfc, options) {
|
|
|
36040
36300
|
}
|
|
36041
36301
|
// 10. generate return statement
|
|
36042
36302
|
let returned;
|
|
36043
|
-
if (options.inlineTemplate) {
|
|
36303
|
+
if (!options.inlineTemplate || (!sfc.template && hasDefaultExportRender)) {
|
|
36304
|
+
// non-inline mode, or has manual render in normal <script>
|
|
36305
|
+
// return bindings from script and script setup
|
|
36306
|
+
const allBindings = Object.assign(Object.assign({}, scriptBindings), setupBindings);
|
|
36307
|
+
for (const key in userImports) {
|
|
36308
|
+
if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
|
|
36309
|
+
allBindings[key] = true;
|
|
36310
|
+
}
|
|
36311
|
+
}
|
|
36312
|
+
returned = `{ ${Object.keys(allBindings).join(', ')} }`;
|
|
36313
|
+
}
|
|
36314
|
+
else {
|
|
36315
|
+
// inline mode
|
|
36044
36316
|
if (sfc.template && !sfc.template.src) {
|
|
36045
36317
|
if (options.templateOptions && options.templateOptions.ssr) {
|
|
36046
36318
|
hasInlinedSsrRenderFn = true;
|
|
@@ -36083,16 +36355,6 @@ function compileScript(sfc, options) {
|
|
|
36083
36355
|
returned = `() => {}`;
|
|
36084
36356
|
}
|
|
36085
36357
|
}
|
|
36086
|
-
else {
|
|
36087
|
-
// return bindings from script and script setup
|
|
36088
|
-
const allBindings = Object.assign(Object.assign({}, scriptBindings), setupBindings);
|
|
36089
|
-
for (const key in userImports) {
|
|
36090
|
-
if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
|
|
36091
|
-
allBindings[key] = true;
|
|
36092
|
-
}
|
|
36093
|
-
}
|
|
36094
|
-
returned = `{ ${Object.keys(allBindings).join(', ')} }`;
|
|
36095
|
-
}
|
|
36096
36358
|
if (!options.inlineTemplate && !false) {
|
|
36097
36359
|
// in non-inline mode, the `__isScriptSetup: true` flag is used by
|
|
36098
36360
|
// componentPublicInstance proxy to allow properties that start with $ or _
|
|
@@ -36106,6 +36368,12 @@ function compileScript(sfc, options) {
|
|
|
36106
36368
|
}
|
|
36107
36369
|
// 11. finalize default export
|
|
36108
36370
|
let runtimeOptions = ``;
|
|
36371
|
+
if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
|
|
36372
|
+
const match = filename.match(/([^/\\]+)\.\w+$/);
|
|
36373
|
+
if (match) {
|
|
36374
|
+
runtimeOptions += `\n name: '${match[1]}',`;
|
|
36375
|
+
}
|
|
36376
|
+
}
|
|
36109
36377
|
if (hasInlinedSsrRenderFn) {
|
|
36110
36378
|
runtimeOptions += `\n __ssrInlineRender: true,`;
|
|
36111
36379
|
}
|
|
@@ -36195,14 +36463,18 @@ function walkDeclaration(node, bindings, userImportAlias) {
|
|
|
36195
36463
|
const userReactiveBinding = userImportAlias['reactive'] || 'reactive';
|
|
36196
36464
|
if (isCallOf(init, userReactiveBinding)) {
|
|
36197
36465
|
// treat reactive() calls as let since it's meant to be mutable
|
|
36198
|
-
bindingType =
|
|
36466
|
+
bindingType = isConst
|
|
36467
|
+
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
36468
|
+
: "setup-let" /* SETUP_LET */;
|
|
36199
36469
|
}
|
|
36200
36470
|
else if (
|
|
36201
36471
|
// if a declaration is a const literal, we can mark it so that
|
|
36202
36472
|
// the generated render fn code doesn't need to unref() it
|
|
36203
36473
|
isDefineCall ||
|
|
36204
36474
|
(isConst && canNeverBeRef(init, userReactiveBinding))) {
|
|
36205
|
-
bindingType =
|
|
36475
|
+
bindingType = isCallOf(init, DEFINE_PROPS)
|
|
36476
|
+
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
36477
|
+
: "setup-const" /* SETUP_CONST */;
|
|
36206
36478
|
}
|
|
36207
36479
|
else if (isConst) {
|
|
36208
36480
|
if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
|
|
@@ -36378,6 +36650,7 @@ function inferRuntimeType(node, declaredTypes) {
|
|
|
36378
36650
|
case 'WeakSet':
|
|
36379
36651
|
case 'WeakMap':
|
|
36380
36652
|
case 'Date':
|
|
36653
|
+
case 'Promise':
|
|
36381
36654
|
return [node.typeName.name];
|
|
36382
36655
|
case 'Record':
|
|
36383
36656
|
case 'Partial':
|
|
@@ -36615,13 +36888,13 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
36615
36888
|
code += `,v${capitalize(camelize(prop.name))}`;
|
|
36616
36889
|
}
|
|
36617
36890
|
if (prop.exp) {
|
|
36618
|
-
code += `,${
|
|
36891
|
+
code += `,${processExp(prop.exp.content)}`;
|
|
36619
36892
|
}
|
|
36620
36893
|
}
|
|
36621
36894
|
}
|
|
36622
36895
|
}
|
|
36623
36896
|
else if (node.type === 5 /* INTERPOLATION */) {
|
|
36624
|
-
code += `,${
|
|
36897
|
+
code += `,${processExp(node.content.content)}`;
|
|
36625
36898
|
}
|
|
36626
36899
|
}
|
|
36627
36900
|
]
|
|
@@ -36630,6 +36903,18 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
36630
36903
|
templateUsageCheckCache.set(content, code);
|
|
36631
36904
|
return code;
|
|
36632
36905
|
}
|
|
36906
|
+
function processExp(exp) {
|
|
36907
|
+
if (/ as \w|<.*>/.test(exp)) {
|
|
36908
|
+
let ret = '';
|
|
36909
|
+
// has potential type cast or generic arguments that uses types
|
|
36910
|
+
const ast = parseExpression_1(exp, { plugins: ['typescript'] });
|
|
36911
|
+
walkIdentifiers(ast, node => {
|
|
36912
|
+
ret += `,` + node.name;
|
|
36913
|
+
});
|
|
36914
|
+
return ret;
|
|
36915
|
+
}
|
|
36916
|
+
return stripStrings(exp);
|
|
36917
|
+
}
|
|
36633
36918
|
function stripStrings(exp) {
|
|
36634
36919
|
return exp
|
|
36635
36920
|
.replace(/'[^']*'|"[^"]*"/g, '')
|
|
@@ -36670,8 +36955,9 @@ function hmrShouldReload(prevImports, next) {
|
|
|
36670
36955
|
return false;
|
|
36671
36956
|
}
|
|
36672
36957
|
|
|
36958
|
+
const DEFAULT_FILENAME = 'anonymous.vue';
|
|
36673
36959
|
const sourceToSFC = createCache();
|
|
36674
|
-
function parse$4(source, { sourceMap = true, filename =
|
|
36960
|
+
function parse$4(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM } = {}) {
|
|
36675
36961
|
const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
|
|
36676
36962
|
const cache = sourceToSFC.get(sourceKey);
|
|
36677
36963
|
if (cache) {
|