From 6ebe6a2d935243449904d5d5715d7184f04730e7 Mon Sep 17 00:00:00 2001 From: zcf0508 Date: Thu, 14 Sep 2023 13:05:39 +0800 Subject: [PATCH] fix: fix setup option return alias --- src/analyze/options.ts | 28 +++++++++++++++-------- test/options-setup/TestComponent.graph.ts | 6 +++-- test/options-setup/TestComponent.vue | 3 ++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/analyze/options.ts b/src/analyze/options.ts index 802751b..28da780 100644 --- a/src/analyze/options.ts +++ b/src/analyze/options.ts @@ -171,18 +171,26 @@ export function analyze( traverse(returnNode, { ObjectProperty(path3) { if(path3.parent === returnNode) { - if(path3.node.key.type === 'Identifier') { + if(path3.node.key.type === 'Identifier' && path3.node.value.type === 'Identifier') { + const valName = path3.node.value.name; + if(!graph.nodes.has(valName)) { + graph.nodes.add(valName); + nodeCollection.addTypedNode( + valName, + tempNodeCollection.nodes.get(valName)! + ); + } + if(!graph.edges.has(valName)) { + graph.edges.set(valName, new Set([...Array.from( + tempEdges.get(valName) || new Set() + )])); + } + const name = path3.node.key.name; - const valName = path3.node.value.type === 'Identifier' ? path3.node.value.name : ''; - if(valName && tempNodes.has(valName)) { + if(name !== valName) { graph.nodes.add(name); - nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(valName)!); - if(!graph.edges.get(name)) { - graph.edges.set(name, new Set()); - tempEdges.get(valName)?.forEach((edge) => { - graph.edges.get(name)?.add(edge); - }); - } + nodeCollection.addNode(name, path3.node.key); + graph.edges.set(name, new Set([valName])); } } } diff --git a/test/options-setup/TestComponent.graph.ts b/test/options-setup/TestComponent.graph.ts index dbf7858..1fa888b 100644 --- a/test/options-setup/TestComponent.graph.ts +++ b/test/options-setup/TestComponent.graph.ts @@ -6,13 +6,15 @@ const number: TypedNode = {label: 'number', type: NodeType.var, info: {line: 65, const count: TypedNode = {label: 'count', type: NodeType.var, info: {line: 67, column: 10}}; const plus: TypedNode = {label: 'plus', type: NodeType.fun, info: {line: 70, column: 6}}; const add: TypedNode = {label: 'add', type: NodeType.fun, info: {line: 74, column: 6}}; +const a: TypedNode = {label: 'a', type: NodeType.var, info: {line: 83, column: 6}}; edges.set(number, new Set([])); edges.set(count, new Set([])); edges.set(plus, new Set([plus])); -edges.set(add, new Set([number, add])); +edges.set(add, new Set([number, add, count])); +edges.set(a, new Set([count])); export const graph = { - nodes: new Set([number, count, plus, add]), + nodes: new Set([number, count, plus, add, a]), edges, }; diff --git a/test/options-setup/TestComponent.vue b/test/options-setup/TestComponent.vue index ee8a580..3987215 100644 --- a/test/options-setup/TestComponent.vue +++ b/test/options-setup/TestComponent.vue @@ -75,12 +75,13 @@ export default { add() { counterStore.add(Number(data.number)); methods.add(); + console.log(count) } } return { ...toRefs(data), - count, + a: count, ...methods, } }