fix: result path is not correct

This commit is contained in:
anatawa12 2025-04-07 13:35:13 +09:00
parent 8cb334c91d
commit ebbf6651c9
No known key found for this signature in database
GPG Key ID: 9CA909848B8E4EA6
1 changed files with 3 additions and 2 deletions

View File

@ -100,14 +100,15 @@ type WalkVueNode = RootNode | TemplateChildNode | SimpleExpressionNode;
*/
function walkVueElements<C extends {} | null>(nodes: WalkVueNode[], context: C, callback: (node: ElementNode, context: C) => C | undefined | void | false): void {
for (const node of nodes) {
let currentContext = context;
if (node.type === NodeTypes.COMPOUND_EXPRESSION) throw new Error("Unexpected COMPOUND_EXPRESSION");
if (node.type === NodeTypes.ELEMENT) {
const result = callback(node, context);
if (result === false) return;
if (result !== undefined) context = result;
if (result !== undefined) currentContext = result;
}
if ('children' in node) {
walkVueElements(node.children, context, callback);
walkVueElements(node.children, currentContext, callback);
}
}
}