fix(compiler-core): fix prod whitespace/comment removal

fix #1256
This commit is contained in:
Evan You 2020-06-11 11:44:39 -04:00
parent b942a310a8
commit f3623e4d1e

View File

@ -216,13 +216,17 @@ function parseChildren(
removedWhitespace = true removedWhitespace = true
nodes[i] = null as any nodes[i] = null as any
} else { } else {
// Otherwise, condensed consecutive whitespace inside the text down to // Otherwise, condensed consecutive whitespace inside the text
// a single space // down to a single space
node.content = ' ' node.content = ' '
} }
} else { } else {
node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ') node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ')
} }
} else if (!__DEV__ && node.type === NodeTypes.COMMENT) {
// remove comment nodes in prod
removedWhitespace = true
nodes[i] = null as any
} }
} }
} else if (parent && context.options.isPreTag(parent.tag)) { } else if (parent && context.options.isPreTag(parent.tag)) {
@ -239,12 +243,6 @@ function parseChildren(
} }
function pushNode(nodes: TemplateChildNode[], node: TemplateChildNode): void { function pushNode(nodes: TemplateChildNode[], node: TemplateChildNode): void {
// ignore comments in production
/* istanbul ignore next */
if (!__DEV__ && node.type === NodeTypes.COMMENT) {
return
}
if (node.type === NodeTypes.TEXT) { if (node.type === NodeTypes.TEXT) {
const prev = last(nodes) const prev = last(nodes)
// Merge if both this and the previous node are text and those are // Merge if both this and the previous node are text and those are