test: improve coverage

This commit is contained in:
Evan You
2019-09-24 16:35:01 -04:00
parent e67084e5a1
commit cae03f616d
8 changed files with 318 additions and 52 deletions

View File

@@ -277,6 +277,7 @@ function genNode(node: CodegenNode, context: CodegenContext) {
genArrayExpression(node, context)
break
default:
/* istanbul ignore next */
__DEV__ &&
assert(false, `unhandled codegen node type: ${(node as any).type}`)
}
@@ -399,7 +400,7 @@ function genFor(node: ForNode, context: CodegenContext) {
}
if (keyAlias) {
if (!valueAlias) {
push(`_`)
push(`__value`)
}
push(`, `)
genExpression(keyAlias, context)
@@ -407,9 +408,9 @@ function genFor(node: ForNode, context: CodegenContext) {
if (objectIndexAlias) {
if (!keyAlias) {
if (!valueAlias) {
push(`_, __`)
push(`__value, __key`)
} else {
push(`__`)
push(`, __key`)
}
}
push(`, `)
@@ -447,12 +448,9 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
// value
genExpression(value, context)
if (i < properties.length - 1) {
if (multilines) {
push(`,`)
newline()
} else {
push(`, `)
}
// will only reach this if it's multilines
push(`,`)
newline()
}
}
multilines && deindent()

View File

@@ -199,6 +199,7 @@ function pushNode(
node: ChildNode
): void {
// ignore comments in production
/* istanbul ignore next */
if (!__DEV__ && node.type === NodeTypes.COMMENT) {
return
}

View File

@@ -85,6 +85,7 @@ function createTransformContext(
childIndex: 0,
currentNode: null,
replaceNode(node) {
/* istanbul ignore if */
if (__DEV__ && !context.currentNode) {
throw new Error(`node being replaced is already removed.`)
}
@@ -97,6 +98,7 @@ function createTransformContext(
: context.currentNode
? context.childIndex
: -1
/* istanbul ignore if */
if (__DEV__ && removalIndex < 0) {
throw new Error(`node being removed is not a child of current parent`)
}

View File

@@ -60,6 +60,7 @@ export function advancePositionWithMutation(
}
export function assert(condition: boolean, msg?: string) {
/* istanbul ignore if */
if (!condition) {
throw new Error(msg || `unexpected compiler condition`)
}