mirror of https://github.com/vuejs/core.git
fix(compiler-vapor): don't mutate ast
This commit is contained in:
parent
7e47ae17f9
commit
d3baff92b1
|
@ -404,14 +404,8 @@ export function createStructuralDirectiveTransform(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const exitFns = []
|
const exitFns = []
|
||||||
for (let i = 0; i < props.length; i++) {
|
for (const prop of props) {
|
||||||
const prop = props[i]
|
|
||||||
if (prop.type === NodeTypes.DIRECTIVE && matches(prop.name)) {
|
if (prop.type === NodeTypes.DIRECTIVE && matches(prop.name)) {
|
||||||
// structural directives are removed to avoid infinite recursion
|
|
||||||
// also we remove them *before* applying so that it can further
|
|
||||||
// traverse itself in case it moves the node around
|
|
||||||
props.splice(i, 1)
|
|
||||||
i--
|
|
||||||
const onExit = fn(node, prop as VaporDirectiveNode, context)
|
const onExit = fn(node, prop as VaporDirectiveNode, context)
|
||||||
if (onExit) exitFns.push(onExit)
|
if (onExit) exitFns.push(onExit)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,16 +65,25 @@ export function createIfBranch(
|
||||||
node.tagType !== ElementTypes.TEMPLATE
|
node.tagType !== ElementTypes.TEMPLATE
|
||||||
) {
|
) {
|
||||||
node = extend({}, node, {
|
node = extend({}, node, {
|
||||||
|
type: NodeTypes.ELEMENT,
|
||||||
|
tag: 'template',
|
||||||
|
props: [],
|
||||||
tagType: ElementTypes.TEMPLATE,
|
tagType: ElementTypes.TEMPLATE,
|
||||||
children: [node],
|
children: [
|
||||||
} as TemplateNode)
|
extend({}, node, {
|
||||||
|
props: node.props.filter(
|
||||||
|
(p) => p.type !== NodeTypes.DIRECTIVE && p.name !== 'if',
|
||||||
|
),
|
||||||
|
} as TemplateChildNode),
|
||||||
|
],
|
||||||
|
} as Partial<TemplateNode>)
|
||||||
context.node = node
|
context.node = node
|
||||||
}
|
}
|
||||||
|
|
||||||
const branch: BlockFunctionIRNode = {
|
const branch: BlockFunctionIRNode = {
|
||||||
type: IRNodeTypes.BLOCK_FUNCTION,
|
type: IRNodeTypes.BLOCK_FUNCTION,
|
||||||
loc: dir.loc,
|
loc: dir.loc,
|
||||||
node: node,
|
node,
|
||||||
templateIndex: -1,
|
templateIndex: -1,
|
||||||
dynamic: {
|
dynamic: {
|
||||||
id: null,
|
id: null,
|
||||||
|
|
Loading…
Reference in New Issue