@vue/compiler-ssr
Advanced tools
Comparing version 3.0.0-beta.20 to 3.0.0-beta.21
@@ -24,2 +24,3 @@ 'use strict'; | ||
const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`); | ||
const SSR_RESOLVE_CSS_VARS = Symbol(`ssrResolveCssVars`); | ||
const ssrHelpers = { | ||
@@ -41,3 +42,4 @@ [SSR_INTERPOLATE]: `ssrInterpolate`, | ||
[SSR_RENDER_TELEPORT]: `ssrRenderTeleport`, | ||
[SSR_RENDER_SUSPENSE]: `ssrRenderSuspense` | ||
[SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`, | ||
[SSR_RESOLVE_CSS_VARS]: `ssrResolveCssVars` | ||
}; | ||
@@ -527,3 +529,3 @@ // Note: these are helpers imported from @vue/server-renderer | ||
const { key, value } = props[j]; | ||
if (key.type === 4 /* SIMPLE_EXPRESSION */ && key.isStatic) { | ||
if (compilerDom.isStaticExp(key)) { | ||
let attrName = key.content; | ||
@@ -657,2 +659,14 @@ // static key attr | ||
const context = createSSRTransformContext(ast, options); | ||
// inject <style vars> resolution | ||
// we do this instead of inlining the expression to ensure the vars are | ||
// only resolved once per render | ||
if (options.ssrCssVars) { | ||
const varsExp = compilerDom.processExpression(compilerDom.createSimpleExpression(options.ssrCssVars, false), compilerDom.createTransformContext(compilerDom.createRoot([]), options)); | ||
context.body.push(compilerDom.createCompoundExpression([ | ||
`const _cssVars = ${ssrHelpers[SSR_RESOLVE_CSS_VARS]}(`, | ||
varsExp, | ||
options.scopeId ? `, ${JSON.stringify(options.scopeId)}` : ``, | ||
`)` | ||
])); | ||
} | ||
const isFragment = ast.children.length > 1 && ast.children.some(c => !compilerDom.isText(c)); | ||
@@ -919,2 +933,42 @@ processChildren(ast.children, context, isFragment); | ||
const ssrInjectCssVars = (node, context) => { | ||
if (!context.ssrCssVars) { | ||
return; | ||
} | ||
// _cssVars is initailized once per render function | ||
// the code is injected in ssrCodegenTrasnform when creating the | ||
// ssr transform context | ||
if (node.type === 0 /* ROOT */) { | ||
context.identifiers._cssVars = 1; | ||
} | ||
const parent = context.parent; | ||
if (!parent || parent.type !== 0 /* ROOT */) { | ||
return; | ||
} | ||
context.helper(SSR_RESOLVE_CSS_VARS); | ||
if (node.type === 10 /* IF_BRANCH */) { | ||
for (const child of node.children) { | ||
injectCssVars(child); | ||
} | ||
} | ||
else { | ||
injectCssVars(node); | ||
} | ||
}; | ||
function injectCssVars(node) { | ||
if (node.type === 1 /* ELEMENT */ && | ||
(node.tagType === 0 /* ELEMENT */ || | ||
node.tagType === 1 /* COMPONENT */) && | ||
!compilerDom.findDir(node, 'for')) { | ||
node.props.push({ | ||
type: 7 /* DIRECTIVE */, | ||
name: 'bind', | ||
arg: undefined, | ||
exp: compilerDom.createSimpleExpression(`_cssVars`, false), | ||
modifiers: [], | ||
loc: compilerDom.locStub | ||
}); | ||
} | ||
} | ||
function compile(template, options = {}) { | ||
@@ -946,2 +1000,3 @@ options = { | ||
ssrInjectFallthroughAttrs, | ||
ssrInjectCssVars, | ||
ssrTransformElement, | ||
@@ -948,0 +1003,0 @@ ssrTransformComponent, |
{ | ||
"name": "@vue/compiler-ssr", | ||
"version": "3.0.0-beta.20", | ||
"version": "3.0.0-beta.21", | ||
"description": "@vue/compiler-ssr", | ||
@@ -30,5 +30,5 @@ "main": "dist/compiler-ssr.cjs.js", | ||
"dependencies": { | ||
"@vue/shared": "3.0.0-beta.20", | ||
"@vue/compiler-dom": "3.0.0-beta.20" | ||
"@vue/shared": "3.0.0-beta.21", | ||
"@vue/compiler-dom": "3.0.0-beta.21" | ||
} | ||
} |
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
46076
1007
+ Added@vue/compiler-core@3.0.0-beta.21(transitive)
+ Added@vue/compiler-dom@3.0.0-beta.21(transitive)
+ Added@vue/shared@3.0.0-beta.21(transitive)
+ Addedestree-walker@2.0.2(transitive)
- Removed@vue/compiler-core@3.0.0-beta.20(transitive)
- Removed@vue/compiler-dom@3.0.0-beta.20(transitive)
- Removed@vue/shared@3.0.0-beta.20(transitive)
- Removedestree-walker@0.8.1(transitive)
Updated@vue/shared@3.0.0-beta.21