MCPcopy
hub / github.com/vuejs/core / ssrCodegenTransform

Function ssrCodegenTransform

packages/compiler-ssr/src/ssrCodegenTransform.ts:38–76  ·  view source on GitHub ↗
(
  ast: RootNode,
  options: CompilerOptions,
)

Source from the content-addressed store, hash-verified

36// passing it to codegen.
37
38export 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
78export interface SSRTransformContext {
79 root: RootNode

Callers 1

compileFunction · 0.90

Calls 13

createTransformContextFunction · 0.85
processExpressionFunction · 0.85
createSimpleExpressionFunction · 0.85
createCompoundExpressionFunction · 0.85
processChildrenFunction · 0.85
createBlockStatementFunction · 0.85
forEachMethod · 0.80
someMethod · 0.80
pushMethod · 0.65
filterMethod · 0.65
createRootFunction · 0.50

Tested by

no test coverage detected