Skip to content

Commit

Permalink
feat: ignore withDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed May 31, 2024
1 parent da8f70c commit 2381d07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/analyze/setupScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const traverse: typeof _traverse
// @ts-expect-error unwarp default
= _traverse.default?.default || _traverse.default || _traverse;

const ignoreFunctionsName = ['defineProps', 'defineEmits', 'withDefaults'];

export function processSetup(
ast: t.Node,
parentScope?: Scope,
Expand Down Expand Up @@ -41,7 +43,7 @@ export function processSetup(
)
&& !(declaration.init?.type === 'CallExpression'
&& declaration.init?.callee.type === 'Identifier'
&& ['defineProps', 'defineEmits'].includes(declaration.init?.callee.name)
&& ignoreFunctionsName.includes(declaration.init?.callee.name)
)
) {
graph.nodes.add(name);
Expand All @@ -64,7 +66,7 @@ export function processSetup(
)
&& !(declaration.init?.type === 'CallExpression'
&& declaration.init?.callee.type === 'Identifier'
&& ['defineProps', 'defineEmits'].includes(declaration.init?.callee.name)
&& ignoreFunctionsName.includes(declaration.init?.callee.name)
)
) {
graph.nodes.add(name);
Expand All @@ -90,7 +92,7 @@ export function processSetup(
)
&& !(declaration.init?.type === 'CallExpression'
&& declaration.init?.callee.type === 'Identifier'
&& ['defineProps', 'defineEmits'].includes(declaration.init?.callee.name)
&& ignoreFunctionsName.includes(declaration.init?.callee.name)
)
) {
graph.nodes.add(name);
Expand All @@ -113,7 +115,7 @@ export function processSetup(
)
&& !(declaration.init?.type === 'CallExpression'
&& declaration.init?.callee.type === 'Identifier'
&& ['defineProps', 'defineEmits'].includes(declaration.init?.callee.name)
&& ignoreFunctionsName.includes(declaration.init?.callee.name)
)
) {
graph.nodes.add(name);
Expand All @@ -137,7 +139,7 @@ export function processSetup(
)
&& !(declaration.init?.type === 'CallExpression'
&& declaration.init?.callee.type === 'Identifier'
&& ['defineProps', 'defineEmits'].includes(declaration.init?.callee.name)
&& ignoreFunctionsName.includes(declaration.init?.callee.name)
)
) {
graph.nodes.add(name);
Expand Down
4 changes: 4 additions & 0 deletions test/setup-block/TestComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ onMounted(() => {
funC()
})
const props1 = withDefaults(defineProps<{test: number}>(), {
test: 1,
})
</script>

<template>
Expand Down

0 comments on commit 2381d07

Please sign in to comment.