@vue/compiler-sfc 3.2.34-beta.1 → 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 +41 -5
- package/dist/compiler-sfc.esm-browser.js +179 -73
- package/package.json +6 -6
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -3264,7 +3264,7 @@ function patchErrors(errors, source, inMap) {
|
|
|
3264
3264
|
}
|
|
3265
3265
|
|
|
3266
3266
|
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
3267
|
-
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s;
|
|
3267
|
+
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
3268
3268
|
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
3269
3269
|
/**
|
|
3270
3270
|
* Utility for rewriting `export default` in a script block into a variable
|
|
@@ -3299,21 +3299,56 @@ function rewriteDefault(input, as, parserPlugins) {
|
|
|
3299
3299
|
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
3300
3300
|
}
|
|
3301
3301
|
if (node.type === 'ExportNamedDeclaration') {
|
|
3302
|
-
node.specifiers
|
|
3302
|
+
for (const specifier of node.specifiers) {
|
|
3303
3303
|
if (specifier.type === 'ExportSpecifier' &&
|
|
3304
3304
|
specifier.exported.type === 'Identifier' &&
|
|
3305
3305
|
specifier.exported.name === 'default') {
|
|
3306
|
-
|
|
3307
|
-
|
|
3306
|
+
if (node.source) {
|
|
3307
|
+
if (specifier.local.name === 'default') {
|
|
3308
|
+
const end = specifierEnd(input, specifier.local.end, node.end);
|
|
3309
|
+
s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
|
|
3310
|
+
s.overwrite(specifier.start, end, ``);
|
|
3311
|
+
s.append(`\nconst ${as} = __VUE_DEFAULT__`);
|
|
3312
|
+
continue;
|
|
3313
|
+
}
|
|
3314
|
+
else {
|
|
3315
|
+
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
3316
|
+
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source?.value}'\n`);
|
|
3317
|
+
s.overwrite(specifier.start, end, ``);
|
|
3318
|
+
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
3319
|
+
continue;
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
const end = specifierEnd(input, specifier.end, node.end);
|
|
3323
|
+
s.overwrite(specifier.start, end, ``);
|
|
3308
3324
|
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
3309
3325
|
}
|
|
3310
|
-
}
|
|
3326
|
+
}
|
|
3311
3327
|
}
|
|
3312
3328
|
});
|
|
3313
3329
|
return s.toString();
|
|
3314
3330
|
}
|
|
3315
3331
|
function hasDefaultExport(input) {
|
|
3316
3332
|
return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
|
|
3333
|
+
}
|
|
3334
|
+
function specifierEnd(input, end, nodeEnd) {
|
|
3335
|
+
// export { default , foo } ...
|
|
3336
|
+
let hasCommas = false;
|
|
3337
|
+
let oldEnd = end;
|
|
3338
|
+
while (end < nodeEnd) {
|
|
3339
|
+
if (/\s/.test(input.charAt(end))) {
|
|
3340
|
+
end++;
|
|
3341
|
+
}
|
|
3342
|
+
else if (input.charAt(end) === ',') {
|
|
3343
|
+
end++;
|
|
3344
|
+
hasCommas = true;
|
|
3345
|
+
break;
|
|
3346
|
+
}
|
|
3347
|
+
else if (input.charAt(end) === '}') {
|
|
3348
|
+
break;
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return hasCommas ? end : oldEnd;
|
|
3317
3352
|
}
|
|
3318
3353
|
|
|
3319
3354
|
// Special compiler macros
|
|
@@ -4616,6 +4651,7 @@ function inferRuntimeType(node, declaredTypes) {
|
|
|
4616
4651
|
case 'WeakSet':
|
|
4617
4652
|
case 'WeakMap':
|
|
4618
4653
|
case 'Date':
|
|
4654
|
+
case 'Promise':
|
|
4619
4655
|
return [node.typeName.name];
|
|
4620
4656
|
case 'Record':
|
|
4621
4657
|
case 'Partial':
|
|
@@ -23271,7 +23271,7 @@ const transformElement = (node, context) => {
|
|
|
23271
23271
|
(tag === 'svg' || tag === 'foreignObject'));
|
|
23272
23272
|
// props
|
|
23273
23273
|
if (props.length > 0) {
|
|
23274
|
-
const propsBuildResult = buildProps(node, context);
|
|
23274
|
+
const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
|
|
23275
23275
|
vnodeProps = propsBuildResult.props;
|
|
23276
23276
|
patchFlag = propsBuildResult.patchFlag;
|
|
23277
23277
|
dynamicPropNames = propsBuildResult.dynamicPropNames;
|
|
@@ -23472,9 +23472,8 @@ function resolveSetupReference(name, context) {
|
|
|
23472
23472
|
: `$setup[${JSON.stringify(fromMaybeRef)}]`;
|
|
23473
23473
|
}
|
|
23474
23474
|
}
|
|
23475
|
-
function buildProps(node, context, props = node.props, ssr = false) {
|
|
23475
|
+
function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
|
|
23476
23476
|
const { tag, loc: elementLoc, children } = node;
|
|
23477
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
23478
23477
|
let properties = [];
|
|
23479
23478
|
const mergeArgs = [];
|
|
23480
23479
|
const runtimeDirectives = [];
|
|
@@ -23493,8 +23492,8 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
23493
23492
|
if (isStaticExp(key)) {
|
|
23494
23493
|
const name = key.content;
|
|
23495
23494
|
const isEventHandler = isOn(name);
|
|
23496
|
-
if (
|
|
23497
|
-
|
|
23495
|
+
if (isEventHandler &&
|
|
23496
|
+
(!isComponent || isDynamicComponent) &&
|
|
23498
23497
|
// omit the flag for click handlers because hydration gives click
|
|
23499
23498
|
// dedicated fast path.
|
|
23500
23499
|
name.toLowerCase() !== 'onclick' &&
|
|
@@ -23918,7 +23917,7 @@ function processSlotOutlet(node, context) {
|
|
|
23918
23917
|
}
|
|
23919
23918
|
}
|
|
23920
23919
|
if (nonNameProps.length > 0) {
|
|
23921
|
-
const { props, directives } = buildProps(node, context, nonNameProps);
|
|
23920
|
+
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
23922
23921
|
slotProps = props;
|
|
23923
23922
|
if (directives.length) {
|
|
23924
23923
|
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
@@ -33424,7 +33423,7 @@ function processIfBranch(branch, context, disableNestedFragments = false) {
|
|
|
33424
33423
|
(children.length !== 1 || children[0].type !== 1 /* ELEMENT */) &&
|
|
33425
33424
|
// optimize away nested fragments when the only child is a ForNode
|
|
33426
33425
|
!(children.length === 1 && children[0].type === 11 /* FOR */);
|
|
33427
|
-
return processChildrenAsStatement(
|
|
33426
|
+
return processChildrenAsStatement(branch, context, needFragmentWrapper);
|
|
33428
33427
|
}
|
|
33429
33428
|
|
|
33430
33429
|
// Plugin for the first transform pass, which simply constructs the AST node
|
|
@@ -33435,7 +33434,7 @@ function ssrProcessFor(node, context, disableNestedFragments = false) {
|
|
|
33435
33434
|
const needFragmentWrapper = !disableNestedFragments &&
|
|
33436
33435
|
(node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */);
|
|
33437
33436
|
const renderLoop = createFunctionExpression(createForLoopParams(node.parseResult));
|
|
33438
|
-
renderLoop.body = processChildrenAsStatement(node
|
|
33437
|
+
renderLoop.body = processChildrenAsStatement(node, context, needFragmentWrapper);
|
|
33439
33438
|
// v-for always renders a fragment unless explicitly disabled
|
|
33440
33439
|
if (!disableNestedFragments) {
|
|
33441
33440
|
context.pushStringPart(`<!--[-->`);
|
|
@@ -33486,7 +33485,7 @@ function ssrProcessSlotOutlet(node, context) {
|
|
|
33486
33485
|
// has fallback content
|
|
33487
33486
|
if (node.children.length) {
|
|
33488
33487
|
const fallbackRenderFn = createFunctionExpression([]);
|
|
33489
|
-
fallbackRenderFn.body = processChildrenAsStatement(node
|
|
33488
|
+
fallbackRenderFn.body = processChildrenAsStatement(node, context);
|
|
33490
33489
|
// _renderSlot(slots, name, props, fallback, ...)
|
|
33491
33490
|
renderCall.arguments[3] = fallbackRenderFn;
|
|
33492
33491
|
}
|
|
@@ -33538,7 +33537,7 @@ function ssrProcessTeleport(node, context) {
|
|
|
33538
33537
|
true, // newline
|
|
33539
33538
|
false, // isSlot
|
|
33540
33539
|
node.loc);
|
|
33541
|
-
contentRenderFn.body = processChildrenAsStatement(node
|
|
33540
|
+
contentRenderFn.body = processChildrenAsStatement(node, context);
|
|
33542
33541
|
context.pushStatement(createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
|
|
33543
33542
|
`_push`,
|
|
33544
33543
|
contentRenderFn,
|
|
@@ -33581,8 +33580,8 @@ function ssrProcessSuspense(node, context) {
|
|
|
33581
33580
|
}
|
|
33582
33581
|
const { slotsExp, wipSlots } = wipEntry;
|
|
33583
33582
|
for (let i = 0; i < wipSlots.length; i++) {
|
|
33584
|
-
const
|
|
33585
|
-
fn.body = processChildrenAsStatement(
|
|
33583
|
+
const slot = wipSlots[i];
|
|
33584
|
+
slot.fn.body = processChildrenAsStatement(slot, context);
|
|
33586
33585
|
}
|
|
33587
33586
|
// _push(ssrRenderSuspense(slots))
|
|
33588
33587
|
context.pushStatement(createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
|
|
@@ -33591,39 +33590,6 @@ function ssrProcessSuspense(node, context) {
|
|
|
33591
33590
|
]));
|
|
33592
33591
|
}
|
|
33593
33592
|
|
|
33594
|
-
function ssrProcessTransitionGroup(node, context) {
|
|
33595
|
-
const tag = findProp(node, 'tag');
|
|
33596
|
-
if (tag) {
|
|
33597
|
-
if (tag.type === 7 /* DIRECTIVE */) {
|
|
33598
|
-
// dynamic :tag
|
|
33599
|
-
context.pushStringPart(`<`);
|
|
33600
|
-
context.pushStringPart(tag.exp);
|
|
33601
|
-
context.pushStringPart(`>`);
|
|
33602
|
-
processChildren(node.children, context, false,
|
|
33603
|
-
/**
|
|
33604
|
-
* TransitionGroup has the special runtime behavior of flattening and
|
|
33605
|
-
* concatenating all children into a single fragment (in order for them to
|
|
33606
|
-
* be patched using the same key map) so we need to account for that here
|
|
33607
|
-
* by disabling nested fragment wrappers from being generated.
|
|
33608
|
-
*/
|
|
33609
|
-
true);
|
|
33610
|
-
context.pushStringPart(`</`);
|
|
33611
|
-
context.pushStringPart(tag.exp);
|
|
33612
|
-
context.pushStringPart(`>`);
|
|
33613
|
-
}
|
|
33614
|
-
else {
|
|
33615
|
-
// static tag
|
|
33616
|
-
context.pushStringPart(`<${tag.value.content}>`);
|
|
33617
|
-
processChildren(node.children, context, false, true);
|
|
33618
|
-
context.pushStringPart(`</${tag.value.content}>`);
|
|
33619
|
-
}
|
|
33620
|
-
}
|
|
33621
|
-
else {
|
|
33622
|
-
// fragment
|
|
33623
|
-
processChildren(node.children, context, true, true);
|
|
33624
|
-
}
|
|
33625
|
-
}
|
|
33626
|
-
|
|
33627
33593
|
// for directives with children overwrite (e.g. v-html & v-text), we need to
|
|
33628
33594
|
// store the raw children so that they can be added in the 2nd pass.
|
|
33629
33595
|
const rawChildrenMap = new WeakMap();
|
|
@@ -33645,7 +33611,7 @@ const ssrTransformElement = (node, context) => {
|
|
|
33645
33611
|
const hasCustomDir = node.props.some(p => p.type === 7 /* DIRECTIVE */ && !isBuiltInDirective(p.name));
|
|
33646
33612
|
const needMergeProps = hasDynamicVBind || hasCustomDir;
|
|
33647
33613
|
if (needMergeProps) {
|
|
33648
|
-
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 */);
|
|
33649
33615
|
if (props || directives.length) {
|
|
33650
33616
|
const mergedProps = buildSSRProps(props, directives, context);
|
|
33651
33617
|
const propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [mergedProps]);
|
|
@@ -33724,7 +33690,7 @@ const ssrTransformElement = (node, context) => {
|
|
|
33724
33690
|
node.children = [createInterpolation(prop.exp, prop.loc)];
|
|
33725
33691
|
}
|
|
33726
33692
|
}
|
|
33727
|
-
else if (!needMergeProps) {
|
|
33693
|
+
else if (!needMergeProps && prop.name !== 'on') {
|
|
33728
33694
|
// Directive transforms.
|
|
33729
33695
|
const directiveTransform = context.directiveTransforms[prop.name];
|
|
33730
33696
|
if (directiveTransform) {
|
|
@@ -33889,7 +33855,7 @@ function ssrProcessElement(node, context) {
|
|
|
33889
33855
|
context.pushStringPart(rawChildren);
|
|
33890
33856
|
}
|
|
33891
33857
|
else if (node.children.length) {
|
|
33892
|
-
processChildren(node
|
|
33858
|
+
processChildren(node, context);
|
|
33893
33859
|
}
|
|
33894
33860
|
if (!isVoidTag(node.tag)) {
|
|
33895
33861
|
// push closing tag
|
|
@@ -33897,11 +33863,75 @@ function ssrProcessElement(node, context) {
|
|
|
33897
33863
|
}
|
|
33898
33864
|
}
|
|
33899
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
|
+
|
|
33900
33929
|
// We need to construct the slot functions in the 1st pass to ensure proper
|
|
33901
33930
|
// scope tracking, but the children of each slot cannot be processed until
|
|
33902
33931
|
// the 2nd pass, so we store the WIP slot functions in a weakMap during the 1st
|
|
33903
33932
|
// pass and complete them in the 2nd pass.
|
|
33904
|
-
const wipMap$
|
|
33933
|
+
const wipMap$2 = new WeakMap();
|
|
33934
|
+
const WIP_SLOT = Symbol();
|
|
33905
33935
|
const componentTypeMap = new WeakMap();
|
|
33906
33936
|
// ssr component transform is done in two phases:
|
|
33907
33937
|
// In phase 1. we use `buildSlot` to analyze the children of the component into
|
|
@@ -33915,12 +33945,16 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33915
33945
|
return;
|
|
33916
33946
|
}
|
|
33917
33947
|
const component = resolveComponentType(node, context, true /* ssr */);
|
|
33948
|
+
const isDynamicComponent = isObject(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
33918
33949
|
componentTypeMap.set(node, component);
|
|
33919
33950
|
if (isSymbol(component)) {
|
|
33920
33951
|
if (component === SUSPENSE) {
|
|
33921
33952
|
return ssrTransformSuspense(node, context);
|
|
33922
33953
|
}
|
|
33923
|
-
|
|
33954
|
+
if (component === TRANSITION_GROUP) {
|
|
33955
|
+
return ssrTransformTransitionGroup(node, context);
|
|
33956
|
+
}
|
|
33957
|
+
return; // other built-in components: fallthrough
|
|
33924
33958
|
}
|
|
33925
33959
|
// Build the fallback vnode-based branch for the component's slots.
|
|
33926
33960
|
// We need to clone the node into a fresh copy and use the buildSlots' logic
|
|
@@ -33944,19 +33978,20 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33944
33978
|
if (node.props.length) {
|
|
33945
33979
|
// note we are not passing ssr: true here because for components, v-on
|
|
33946
33980
|
// handlers should still be passed
|
|
33947
|
-
const { props, directives } = buildProps(node, context);
|
|
33981
|
+
const { props, directives } = buildProps(node, context, undefined, true, isDynamicComponent);
|
|
33948
33982
|
if (props || directives.length) {
|
|
33949
33983
|
propsExp = buildSSRProps(props, directives, context);
|
|
33950
33984
|
}
|
|
33951
33985
|
}
|
|
33952
33986
|
const wipEntries = [];
|
|
33953
|
-
wipMap$
|
|
33987
|
+
wipMap$2.set(node, wipEntries);
|
|
33954
33988
|
const buildSSRSlotFn = (props, children, loc) => {
|
|
33955
33989
|
const fn = createFunctionExpression([props || `_`, `_push`, `_parent`, `_scopeId`], undefined, // no return, assign body later
|
|
33956
33990
|
true, // newline
|
|
33957
33991
|
true, // isSlot
|
|
33958
33992
|
loc);
|
|
33959
33993
|
wipEntries.push({
|
|
33994
|
+
type: WIP_SLOT,
|
|
33960
33995
|
fn,
|
|
33961
33996
|
children,
|
|
33962
33997
|
// also collect the corresponding vnode branch built earlier
|
|
@@ -33986,7 +34021,7 @@ const ssrTransformComponent = (node, context) => {
|
|
|
33986
34021
|
}
|
|
33987
34022
|
};
|
|
33988
34023
|
};
|
|
33989
|
-
function ssrProcessComponent(node, context) {
|
|
34024
|
+
function ssrProcessComponent(node, context, parent) {
|
|
33990
34025
|
const component = componentTypeMap.get(node);
|
|
33991
34026
|
if (!node.ssrCodegenNode) {
|
|
33992
34027
|
// this is a built-in component that fell-through.
|
|
@@ -34002,19 +34037,29 @@ function ssrProcessComponent(node, context) {
|
|
|
34002
34037
|
else {
|
|
34003
34038
|
// real fall-through: Transition / KeepAlive
|
|
34004
34039
|
// just render its children.
|
|
34005
|
-
|
|
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);
|
|
34006
34051
|
}
|
|
34007
34052
|
}
|
|
34008
34053
|
else {
|
|
34009
34054
|
// finish up slot function expressions from the 1st pass.
|
|
34010
|
-
const wipEntries = wipMap$
|
|
34055
|
+
const wipEntries = wipMap$2.get(node) || [];
|
|
34011
34056
|
for (let i = 0; i < wipEntries.length; i++) {
|
|
34012
|
-
const { fn,
|
|
34057
|
+
const { fn, vnodeBranch } = wipEntries[i];
|
|
34013
34058
|
// For each slot, we generate two branches: one SSR-optimized branch and
|
|
34014
34059
|
// one normal vnode-based branch. The branches are taken based on the
|
|
34015
34060
|
// presence of the 2nd `_push` argument (which is only present if the slot
|
|
34016
34061
|
// is called by `_ssrRenderSlot`.
|
|
34017
|
-
fn.body = createIfStatement(createSimpleExpression(`_push`, false), processChildrenAsStatement(
|
|
34062
|
+
fn.body = createIfStatement(createSimpleExpression(`_push`, false), processChildrenAsStatement(wipEntries[i], context, false, true /* withSlotScopeId */), vnodeBranch);
|
|
34018
34063
|
}
|
|
34019
34064
|
// component is inside a slot, inherit slot scope Id
|
|
34020
34065
|
if (context.withSlotScopeId) {
|
|
@@ -34134,7 +34179,7 @@ function ssrCodegenTransform(ast, options) {
|
|
|
34134
34179
|
context.body.push(createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`]));
|
|
34135
34180
|
}
|
|
34136
34181
|
const isFragment = ast.children.length > 1 && ast.children.some(c => !isText(c));
|
|
34137
|
-
processChildren(ast
|
|
34182
|
+
processChildren(ast, context, isFragment);
|
|
34138
34183
|
ast.codegenNode = createBlockStatement(context.body);
|
|
34139
34184
|
// Finalize helpers.
|
|
34140
34185
|
// We need to separate helpers imported from 'vue' vs. '@vue/server-renderer'
|
|
@@ -34185,10 +34230,11 @@ function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
|
|
|
34185
34230
|
// ensure child inherits parent helpers
|
|
34186
34231
|
return createSSRTransformContext(parent.root, parent.options, parent.helpers, withSlotScopeId);
|
|
34187
34232
|
}
|
|
34188
|
-
function processChildren(
|
|
34233
|
+
function processChildren(parent, context, asFragment = false, disableNestedFragments = false) {
|
|
34189
34234
|
if (asFragment) {
|
|
34190
34235
|
context.pushStringPart(`<!--[-->`);
|
|
34191
34236
|
}
|
|
34237
|
+
const { children } = parent;
|
|
34192
34238
|
for (let i = 0; i < children.length; i++) {
|
|
34193
34239
|
const child = children[i];
|
|
34194
34240
|
switch (child.type) {
|
|
@@ -34198,7 +34244,7 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34198
34244
|
ssrProcessElement(child, context);
|
|
34199
34245
|
break;
|
|
34200
34246
|
case 1 /* COMPONENT */:
|
|
34201
|
-
ssrProcessComponent(child, context);
|
|
34247
|
+
ssrProcessComponent(child, context, parent);
|
|
34202
34248
|
break;
|
|
34203
34249
|
case 2 /* SLOT */:
|
|
34204
34250
|
ssrProcessSlotOutlet(child, context);
|
|
@@ -34249,9 +34295,9 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34249
34295
|
context.pushStringPart(`<!--]-->`);
|
|
34250
34296
|
}
|
|
34251
34297
|
}
|
|
34252
|
-
function processChildrenAsStatement(
|
|
34298
|
+
function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
|
|
34253
34299
|
const childContext = createChildContext(parentContext, withSlotScopeId);
|
|
34254
|
-
processChildren(
|
|
34300
|
+
processChildren(parent, childContext, asFragment);
|
|
34255
34301
|
return createBlockStatement(childContext.body);
|
|
34256
34302
|
}
|
|
34257
34303
|
|
|
@@ -34370,7 +34416,8 @@ const ssrTransformShow = (dir, node, context) => {
|
|
|
34370
34416
|
};
|
|
34371
34417
|
};
|
|
34372
34418
|
|
|
34373
|
-
const
|
|
34419
|
+
const filterChild = (node) => node.children.filter(n => n.type !== 3 /* COMMENT */);
|
|
34420
|
+
const hasSingleChild = (node) => filterChild(node).length === 1;
|
|
34374
34421
|
const ssrInjectFallthroughAttrs = (node, context) => {
|
|
34375
34422
|
// _attrs is provided as a function argument.
|
|
34376
34423
|
// mark it as a known identifier so that it doesn't get prefixed by
|
|
@@ -34382,16 +34429,37 @@ const ssrInjectFallthroughAttrs = (node, context) => {
|
|
|
34382
34429
|
node.tagType === 1 /* COMPONENT */ &&
|
|
34383
34430
|
(isBuiltInType(node.tag, 'Transition') ||
|
|
34384
34431
|
isBuiltInType(node.tag, 'KeepAlive'))) {
|
|
34385
|
-
|
|
34386
|
-
|
|
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;
|
|
34387
34438
|
}
|
|
34388
|
-
return;
|
|
34389
34439
|
}
|
|
34390
34440
|
const parent = context.parent;
|
|
34391
34441
|
if (!parent || parent.type !== 0 /* ROOT */) {
|
|
34392
34442
|
return;
|
|
34393
34443
|
}
|
|
34394
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
|
+
}
|
|
34395
34463
|
injectFallthroughAttrs(node.children[0]);
|
|
34396
34464
|
}
|
|
34397
34465
|
else if (hasSingleChild(parent)) {
|
|
@@ -34492,11 +34560,12 @@ function compile$1(template, options = {}) {
|
|
|
34492
34560
|
...(options.nodeTransforms || []) // user transforms
|
|
34493
34561
|
], directiveTransforms: Object.assign({
|
|
34494
34562
|
// reusing core v-bind
|
|
34495
|
-
bind: transformBind,
|
|
34563
|
+
bind: transformBind, on: transformOn,
|
|
34496
34564
|
// model and show has dedicated SSR handling
|
|
34497
34565
|
model: ssrTransformModel, show: ssrTransformShow,
|
|
34498
34566
|
// the following are ignored during SSR
|
|
34499
|
-
on: noopDirectiveTransform,
|
|
34567
|
+
// on: noopDirectiveTransform,
|
|
34568
|
+
cloak: noopDirectiveTransform, once: noopDirectiveTransform, memo: noopDirectiveTransform }, (options.directiveTransforms || {}) // user transforms
|
|
34500
34569
|
) }));
|
|
34501
34570
|
// traverse the template AST and convert into SSR codegen AST
|
|
34502
34571
|
// by replacing ast.codegenNode.
|
|
@@ -34704,7 +34773,7 @@ function patchErrors(errors, source, inMap) {
|
|
|
34704
34773
|
}
|
|
34705
34774
|
|
|
34706
34775
|
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
|
|
34707
|
-
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s;
|
|
34776
|
+
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
|
|
34708
34777
|
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
|
|
34709
34778
|
/**
|
|
34710
34779
|
* Utility for rewriting `export default` in a script block into a variable
|
|
@@ -34735,25 +34804,61 @@ function rewriteDefault(input, as, parserPlugins) {
|
|
|
34735
34804
|
plugins: parserPlugins
|
|
34736
34805
|
}).program.body;
|
|
34737
34806
|
ast.forEach(node => {
|
|
34807
|
+
var _a;
|
|
34738
34808
|
if (node.type === 'ExportDefaultDeclaration') {
|
|
34739
34809
|
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
34740
34810
|
}
|
|
34741
34811
|
if (node.type === 'ExportNamedDeclaration') {
|
|
34742
|
-
node.specifiers
|
|
34812
|
+
for (const specifier of node.specifiers) {
|
|
34743
34813
|
if (specifier.type === 'ExportSpecifier' &&
|
|
34744
34814
|
specifier.exported.type === 'Identifier' &&
|
|
34745
34815
|
specifier.exported.name === 'default') {
|
|
34746
|
-
|
|
34747
|
-
|
|
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, ``);
|
|
34748
34834
|
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
34749
34835
|
}
|
|
34750
|
-
}
|
|
34836
|
+
}
|
|
34751
34837
|
}
|
|
34752
34838
|
});
|
|
34753
34839
|
return s.toString();
|
|
34754
34840
|
}
|
|
34755
34841
|
function hasDefaultExport(input) {
|
|
34756
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;
|
|
34757
34862
|
}
|
|
34758
34863
|
|
|
34759
34864
|
const CONVERT_SYMBOL = '$';
|
|
@@ -36545,6 +36650,7 @@ function inferRuntimeType(node, declaredTypes) {
|
|
|
36545
36650
|
case 'WeakSet':
|
|
36546
36651
|
case 'WeakMap':
|
|
36547
36652
|
case 'Date':
|
|
36653
|
+
case 'Promise':
|
|
36548
36654
|
return [node.typeName.name];
|
|
36549
36655
|
case 'Record':
|
|
36550
36656
|
case 'Partial':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-sfc",
|
|
3
|
-
"version": "3.2.34
|
|
3
|
+
"version": "3.2.34",
|
|
4
4
|
"description": "@vue/compiler-sfc",
|
|
5
5
|
"main": "dist/compiler-sfc.cjs.js",
|
|
6
6
|
"module": "dist/compiler-sfc.esm-browser.js",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "^7.16.4",
|
|
36
|
-
"@vue/compiler-core": "3.2.34
|
|
37
|
-
"@vue/compiler-dom": "3.2.34
|
|
38
|
-
"@vue/compiler-ssr": "3.2.34
|
|
39
|
-
"@vue/reactivity-transform": "3.2.34
|
|
40
|
-
"@vue/shared": "3.2.34
|
|
36
|
+
"@vue/compiler-core": "3.2.34",
|
|
37
|
+
"@vue/compiler-dom": "3.2.34",
|
|
38
|
+
"@vue/compiler-ssr": "3.2.34",
|
|
39
|
+
"@vue/reactivity-transform": "3.2.34",
|
|
40
|
+
"@vue/shared": "3.2.34",
|
|
41
41
|
"estree-walker": "^2.0.2",
|
|
42
42
|
"magic-string": "^0.25.7",
|
|
43
43
|
"source-map": "^0.6.1",
|