const { transformMarkdownTo } = require('simple-mind-map/src/parse/markdownTo.js'); // 模拟 MindmapSidebar.tsx 中的逻辑 async function testAiContinuation() { const text = ` - 子节点1 - 子节点2 `; console.log("解析 markdown..."); let tree = transformMarkdownTo(text); let children = tree?.children || []; if (!children.length) { const lines = text .split(/\r?\n/) .map((l) => l.trim()) .filter(Boolean); const listLines = lines.filter((l) => /^[-*+]\s+/.test(l)).map((l) => l.replace(/^[-*+]\s+/, "")); children = listLines.map((t) => ({ data: { text: t } })); } console.log("解析结果 children:", JSON.stringify(children, null, 2)); // 模拟深拷贝修复 children = JSON.parse(JSON.stringify(children)); console.log("深拷贝后 children:", JSON.stringify(children, null, 2)); // 模拟添加到节点 const mockNode = { data: { uid: 'test-uid', text: 'Root' }, children: [] }; const appendChildren = (node) => { if (node.data.uid === 'test-uid') { // 这里模拟多次添加,检查是否有引用问题 node.children.push(...children); // 如果 children 是同一个引用,再次 push 会导致问题吗? // 在实际 dom/proxy 环境中,直接 push 可能会有问题,但这里主要是测试逻辑正确性 } }; appendChildren(mockNode); console.log("添加后节点:", JSON.stringify(mockNode, null, 2)); } testAiContinuation().catch(console.error);