@vue/compiler-ssr
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -50,5 +50,5 @@ 'use strict'; | ||
// codegen nodes. | ||
function ssrProcessIf(node, context) { | ||
function ssrProcessIf(node, context, disableNestedFragments = false) { | ||
const [rootBranch] = node.branches; | ||
const ifStatement = compilerDom.createIfStatement(rootBranch.condition, processIfBranch(rootBranch, context)); | ||
const ifStatement = compilerDom.createIfStatement(rootBranch.condition, processIfBranch(rootBranch, context, disableNestedFragments)); | ||
context.pushStatement(ifStatement); | ||
@@ -58,3 +58,3 @@ let currentIf = ifStatement; | ||
const branch = node.branches[i]; | ||
const branchBlockStatement = processIfBranch(branch, context); | ||
const branchBlockStatement = processIfBranch(branch, context, disableNestedFragments); | ||
if (branch.condition) { | ||
@@ -75,5 +75,6 @@ // else-if | ||
} | ||
function processIfBranch(branch, context) { | ||
function processIfBranch(branch, context, disableNestedFragments = false) { | ||
const { children } = branch; | ||
const needFragmentWrapper = (children.length !== 1 || children[0].type !== 1 /* ELEMENT */) && | ||
const needFragmentWrapper = !disableNestedFragments && | ||
(children.length !== 1 || children[0].type !== 1 /* ELEMENT */) && | ||
// optimize away nested fragments when the only child is a ForNode | ||
@@ -88,8 +89,11 @@ !(children.length === 1 && children[0].type === 11 /* FOR */); | ||
// codegen nodes. | ||
function ssrProcessFor(node, context) { | ||
const needFragmentWrapper = node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */; | ||
function ssrProcessFor(node, context, disableNestedFragments = false) { | ||
const needFragmentWrapper = !disableNestedFragments && | ||
(node.children.length !== 1 || node.children[0].type !== 1 /* ELEMENT */); | ||
const renderLoop = compilerDom.createFunctionExpression(compilerDom.createForLoopParams(node.parseResult)); | ||
renderLoop.body = processChildrenAsStatement(node.children, context, needFragmentWrapper); | ||
// v-for always renders a fragment | ||
context.pushStringPart(`<!--[-->`); | ||
// v-for always renders a fragment unless explicitly disabled | ||
if (!disableNestedFragments) { | ||
context.pushStringPart(`<!--[-->`); | ||
} | ||
context.pushStatement(compilerDom.createCallExpression(context.helper(SSR_RENDER_LIST), [ | ||
@@ -99,3 +103,5 @@ node.source, | ||
])); | ||
context.pushStringPart(`<!--]-->`); | ||
if (!disableNestedFragments) { | ||
context.pushStringPart(`<!--]-->`); | ||
} | ||
} | ||
@@ -220,2 +226,35 @@ | ||
function ssrProcessTransitionGroup(node, context) { | ||
const tag = compilerDom.findProp(node, 'tag'); | ||
if (tag) { | ||
if (tag.type === 7 /* DIRECTIVE */) { | ||
// dynamic :tag | ||
context.pushStringPart(`<`); | ||
context.pushStringPart(tag.exp); | ||
context.pushStringPart(`>`); | ||
processChildren(node.children, context, false, | ||
/** | ||
* TransitionGroup has the special runtime behavior of flattening and | ||
* concatenating all children into a single fragment (in order for them to | ||
* be pathced using the same key map) so we need to account for that here | ||
* by disabling nested fragment wrappers from being generated. | ||
*/ | ||
true); | ||
context.pushStringPart(`</`); | ||
context.pushStringPart(tag.exp); | ||
context.pushStringPart(`>`); | ||
} | ||
else { | ||
// static tag | ||
context.pushStringPart(`<${tag.value.content}>`); | ||
processChildren(node.children, context, false, true); | ||
context.pushStringPart(`</${tag.value.content}>`); | ||
} | ||
} | ||
else { | ||
// fragment | ||
processChildren(node.children, context, true, true); | ||
} | ||
} | ||
// We need to construct the slot functions in the 1st pass to ensure proper | ||
@@ -316,5 +355,8 @@ // scope tracking, but the children of each slot cannot be processed until | ||
} | ||
else if (component === compilerDom.TRANSITION_GROUP) { | ||
return ssrProcessTransitionGroup(node, context); | ||
} | ||
else { | ||
// real fall-through (e.g. KeepAlive): just render its children. | ||
processChildren(node.children, context, component === compilerDom.TRANSITION_GROUP); | ||
processChildren(node.children, context); | ||
} | ||
@@ -502,2 +544,6 @@ } | ||
const prop = node.props[i]; | ||
// ignore true-value/false-value on input | ||
if (node.tag === 'input' && isTrueFalseValue(prop)) { | ||
continue; | ||
} | ||
// special cases with children override | ||
@@ -536,2 +582,5 @@ if (prop.type === 7 /* DIRECTIVE */) { | ||
// static key attr | ||
if (attrName === 'key' || attrName === 'ref') { | ||
continue; | ||
} | ||
if (attrName === 'class') { | ||
@@ -588,2 +637,5 @@ openTag.push(` class="`, (dynamicClassBinding = compilerDom.createCallExpression(context.helper(SSR_RENDER_CLASS), [value])), `"`); | ||
else if (!hasDynamicVBind) { | ||
if (prop.name === 'key' || prop.name === 'ref') { | ||
continue; | ||
} | ||
// static prop | ||
@@ -609,2 +661,13 @@ if (prop.name === 'class' && prop.value) { | ||
}; | ||
function isTrueFalseValue(prop) { | ||
if (prop.type === 7 /* DIRECTIVE */) { | ||
return (prop.name === 'bind' && | ||
prop.arg && | ||
compilerDom.isStaticExp(prop.arg) && | ||
(prop.arg.content === 'true-value' || prop.arg.content === 'false-value')); | ||
} | ||
else { | ||
return prop.name === 'true-value' || prop.name === 'false-value'; | ||
} | ||
} | ||
function isTextareaWithValue(node, prop) { | ||
@@ -728,3 +791,3 @@ return !!(node.tag === 'textarea' && | ||
} | ||
function processChildren(children, context, asFragment = false) { | ||
function processChildren(children, context, asFragment = false, disableNestedFragments = false) { | ||
if (asFragment) { | ||
@@ -769,6 +832,6 @@ context.pushStringPart(`<!--[-->`); | ||
case 9 /* IF */: | ||
ssrProcessIf(child, context); | ||
ssrProcessIf(child, context, disableNestedFragments); | ||
break; | ||
case 11 /* FOR */: | ||
ssrProcessFor(child, context); | ||
ssrProcessFor(child, context, disableNestedFragments); | ||
break; | ||
@@ -840,8 +903,22 @@ case 10 /* IF_BRANCH */: | ||
case 'checkbox': | ||
res.props = [ | ||
compilerDom.createObjectProperty(`checked`, compilerDom.createConditionalExpression(compilerDom.createCallExpression(`Array.isArray`, [model]), compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ | ||
model, | ||
value | ||
]), model)) | ||
]; | ||
const trueValueBinding = compilerDom.findProp(node, 'true-value'); | ||
if (trueValueBinding) { | ||
const trueValue = trueValueBinding.type === 6 /* ATTRIBUTE */ | ||
? JSON.stringify(trueValueBinding.value.content) | ||
: trueValueBinding.exp; | ||
res.props = [ | ||
compilerDom.createObjectProperty(`checked`, compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [ | ||
model, | ||
trueValue | ||
])) | ||
]; | ||
} | ||
else { | ||
res.props = [ | ||
compilerDom.createObjectProperty(`checked`, compilerDom.createConditionalExpression(compilerDom.createCallExpression(`Array.isArray`, [model]), compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ | ||
model, | ||
value | ||
]), model)) | ||
]; | ||
} | ||
break; | ||
@@ -848,0 +925,0 @@ case 'file': |
{ | ||
"name": "@vue/compiler-ssr", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "@vue/compiler-ssr", | ||
@@ -31,5 +31,5 @@ "main": "dist/compiler-ssr.cjs.js", | ||
"dependencies": { | ||
"@vue/shared": "3.0.3", | ||
"@vue/compiler-dom": "3.0.3" | ||
"@vue/shared": "3.0.4", | ||
"@vue/compiler-dom": "3.0.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49870
1090
+ Added@vue/compiler-core@3.0.4(transitive)
+ Added@vue/compiler-dom@3.0.4(transitive)
+ Added@vue/shared@3.0.4(transitive)
- Removed@vue/compiler-core@3.0.3(transitive)
- Removed@vue/compiler-dom@3.0.3(transitive)
- Removed@vue/shared@3.0.3(transitive)
Updated@vue/compiler-dom@3.0.4
Updated@vue/shared@3.0.4