Skip to content

Commit

Permalink
fix: fix setup option return alias
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Sep 14, 2023
1 parent eea0065 commit 6ebe6a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
28 changes: 18 additions & 10 deletions src/analyze/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
)]));
}

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]));
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions test/options-setup/TestComponent.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
3 changes: 2 additions & 1 deletion test/options-setup/TestComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ export default {
add() {
counterStore.add(Number(data.number));
methods.add();
console.log(count)
}
}
return {
...toRefs(data),
count,
a: count,
...methods,
}
}
Expand Down

0 comments on commit 6ebe6a2

Please sign in to comment.