refactor(compiler): use shorter helpers for text and comment nodes

This commit is contained in:
Evan You
2019-10-24 17:55:00 -04:00
parent eb20730a67
commit 1c0a2c6d41
19 changed files with 126 additions and 108 deletions

View File

@@ -218,15 +218,16 @@ function parseChildren(
const next = nodes[i + 1]
// If:
// - the whitespace is the first or last node, or:
// - the whitespace contains newline AND is between two element or comments
// - the whitespace is adjacent to a comment, or:
// - the whitespace is between two elements AND contains newline
// Then the whitespace is ignored.
if (
!prev ||
!next ||
((prev.type === NodeTypes.ELEMENT ||
prev.type === NodeTypes.COMMENT) &&
(next.type === NodeTypes.ELEMENT ||
next.type === NodeTypes.COMMENT) &&
prev.type === NodeTypes.COMMENT ||
next.type === NodeTypes.COMMENT ||
(prev.type === NodeTypes.ELEMENT &&
next.type === NodeTypes.ELEMENT &&
/[\r\n]/.test(node.content))
) {
removedWhitespace = true