fix(compiler-ssr): handle comments codegen + refactor ssr codegen transform

This commit is contained in:
Evan You
2020-05-01 17:04:36 -04:00
parent 0e730c06e4
commit 6c60ce13e0
5 changed files with 85 additions and 27 deletions

View File

@@ -27,7 +27,8 @@ import {
isVoidTag,
escapeHtml,
NO,
generateCodeFrame
generateCodeFrame,
escapeHtmlComment
} from '@vue/shared'
import { compile } from '@vue/compiler-ssr'
import { ssrRenderAttrs } from './helpers/ssrRenderAttrs'
@@ -230,9 +231,6 @@ function ssrCompile(
return (compileCache[template] = Function('require', code)(require))
}
// https://www.w3.org/TR/html52/syntax.html#comments
const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g
function renderVNode(
push: PushFn,
vnode: VNode,
@@ -245,9 +243,7 @@ function renderVNode(
break
case Comment:
push(
children
? `<!--${(children as string).replace(commentStripRE, '')}-->`
: `<!---->`
children ? `<!--${escapeHtmlComment(children as string)}-->` : `<!---->`
)
break
case Static: