( ast: RootNode, options: CompilerOptions, )
| 36 | // passing it to codegen. |
| 37 | |
| 38 | export function ssrCodegenTransform( |
| 39 | ast: RootNode, |
| 40 | options: CompilerOptions, |
| 41 | ): void { |
| 42 | const context = createSSRTransformContext(ast, options) |
| 43 | |
| 44 | // inject SFC <style> CSS variables |
| 45 | // we do this instead of inlining the expression to ensure the vars are |
| 46 | // only resolved once per render |
| 47 | if (options.ssrCssVars) { |
| 48 | const cssContext = createTransformContext(createRoot([]), options) |
| 49 | const varsExp = processExpression( |
| 50 | createSimpleExpression(options.ssrCssVars, false), |
| 51 | cssContext, |
| 52 | ) |
| 53 | context.body.push( |
| 54 | createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`]), |
| 55 | ) |
| 56 | Array.from(cssContext.helpers.keys()).forEach(helper => { |
| 57 | ast.helpers.add(helper) |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | const isFragment = |
| 62 | ast.children.length > 1 && ast.children.some(c => !isText(c)) |
| 63 | processChildren(ast, context, isFragment) |
| 64 | ast.codegenNode = createBlockStatement(context.body) |
| 65 | |
| 66 | // Finalize helpers. |
| 67 | // We need to separate helpers imported from 'vue' vs. '@vue/server-renderer' |
| 68 | ast.ssrHelpers = Array.from( |
| 69 | new Set([ |
| 70 | ...Array.from(ast.helpers).filter(h => h in ssrHelpers), |
| 71 | ...context.helpers, |
| 72 | ]), |
| 73 | ) |
| 74 | |
| 75 | ast.helpers = new Set(Array.from(ast.helpers).filter(h => !(h in ssrHelpers))) |
| 76 | } |
| 77 | |
| 78 | export interface SSRTransformContext { |
| 79 | root: RootNode |
no test coverage detected