From 7cf1e654a6bf903b17fba12025bbf298ce0d2a6b Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 17 May 2017 16:41:22 +0800 Subject: [PATCH] fix root node optimizability --- src/server/optimizing-compiler/codegen.js | 2 +- src/server/optimizing-compiler/optimizer.js | 22 ++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/server/optimizing-compiler/codegen.js b/src/server/optimizing-compiler/codegen.js index c78ee650..03c5a550 100644 --- a/src/server/optimizing-compiler/codegen.js +++ b/src/server/optimizing-compiler/codegen.js @@ -99,7 +99,7 @@ function genStringElement (el, state, stringifyChildren) { const children = genSSRChildren(el, state, true) return `_ssrNode(${ flattenSegments(elementToOpenTagSegments(el, state)) - }","${el.tag}"${ + },"${el.tag}"${ children ? `,${children}` : '' })` } diff --git a/src/server/optimizing-compiler/optimizer.js b/src/server/optimizing-compiler/optimizer.js index bcbe3dea..4fba08a4 100644 --- a/src/server/optimizing-compiler/optimizer.js +++ b/src/server/optimizing-compiler/optimizer.js @@ -35,28 +35,28 @@ function walk (node: ASTNode, isRoot?: boolean) { return } // root node or nodes with custom directives should always be a VNode - if (isRoot || hasCustomDirective(node)) { + const selfUnoptimizable = isRoot || hasCustomDirective(node) + const check = child => { + if (child.ssrOptimizability !== optimizability.FULL) { + node.ssrOptimizability = selfUnoptimizable + ? optimizability.PARTIAL + : optimizability.SELF + } + } + if (selfUnoptimizable) { node.ssrOptimizability = optimizability.CHILDREN } if (node.type === 1) { for (let i = 0, l = node.children.length; i < l; i++) { const child = node.children[i] walk(child) - if (child.ssrOptimizability !== optimizability.FULL) { - node.ssrOptimizability = node.ssrOptimizability === optimizability.CHILDREN - ? optimizability.PARTIAL - : optimizability.SELF - } + check(child) } if (node.ifConditions) { for (let i = 1, l = node.ifConditions.length; i < l; i++) { const block = node.ifConditions[i].block walk(block) - if (block.ssrOptimizability !== optimizability.FULL) { - node.ssrOptimizability = node.ssrOptimizability === optimizability.CHILDREN - ? optimizability.PARTIAL - : optimizability.SELF - } + check(block) } } if (node.ssrOptimizability == null) {