fix(transform): transform should still apply even when node is removed
This commit is contained in:
parent
3a177a18d2
commit
9c01e0bf0d
@ -287,16 +287,20 @@ function genIfBranch(
|
|||||||
context: CodegenContext
|
context: CodegenContext
|
||||||
) {
|
) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
|
const { push, indent, deindent, newline } = context
|
||||||
// v-if or v-else-if
|
// v-if or v-else-if
|
||||||
context.push(`(${condition.content})`, condition)
|
push(`(${condition.content})`, condition)
|
||||||
context.push(`?`)
|
indent()
|
||||||
|
push(`? `)
|
||||||
genChildren(children, context)
|
genChildren(children, context)
|
||||||
context.push(`:`)
|
newline()
|
||||||
|
push(`: `)
|
||||||
if (nextIndex < branches.length) {
|
if (nextIndex < branches.length) {
|
||||||
genIfBranch(branches[nextIndex], branches, nextIndex + 1, context)
|
genIfBranch(branches[nextIndex], branches, nextIndex + 1, context)
|
||||||
} else {
|
} else {
|
||||||
context.push(`null`)
|
context.push(`null`)
|
||||||
}
|
}
|
||||||
|
deindent()
|
||||||
} else {
|
} else {
|
||||||
// v-else
|
// v-else
|
||||||
__DEV__ && assert(nextIndex === branches.length)
|
__DEV__ && assert(nextIndex === branches.length)
|
||||||
|
@ -132,12 +132,13 @@ function traverseNode(
|
|||||||
for (let i = 0; i < nodeTransforms.length; i++) {
|
for (let i = 0; i < nodeTransforms.length; i++) {
|
||||||
const plugin = nodeTransforms[i]
|
const plugin = nodeTransforms[i]
|
||||||
plugin(node, context)
|
plugin(node, context)
|
||||||
if (!context.currentNode) {
|
// node may have been replaced
|
||||||
return
|
node = context.currentNode || node
|
||||||
} else {
|
}
|
||||||
// node may have been replaced
|
|
||||||
node = context.currentNode
|
if (!context.currentNode) {
|
||||||
}
|
// node was removed
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// further traverse downwards
|
// further traverse downwards
|
||||||
|
Loading…
x
Reference in New Issue
Block a user