Skip to content

Commit

Permalink
fix: node comment display error
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed May 15, 2024
1 parent 7111d84 commit 52324f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/analyze/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ export function getComment(node: t.Node) {
let comment = '';

node.leadingComments?.forEach((_comment) => {
if (_comment.loc!.end.line > node.loc!.start.line) {
return;
}
if (_comment.value.trim().startsWith('*')) {
comment += `${_comment.value.trim().replace(/^[\s]*\*+[\s]*\**/gm, '').trim()}\n`;
}
});

node.trailingComments?.forEach((_comment) => {
if (_comment.loc!.end.line > node.loc!.start.line) {
return;
}
if (_comment.value.trim().startsWith('*')) {
comment += `${_comment.value.trim().replace(/^[\s]*\*+[\s]*\**/gm, '').trim()}\n`;
}
Expand Down
4 changes: 2 additions & 2 deletions test/setup-block/TestComponent.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { NodeType } from '@/analyze/utils';

const edges = new Map<TypedNode, Set<TypedNode>>();

const route: TypedNode = { label: 'route', type: NodeType.var, info: { line: 7, column: 6 } };
const path: TypedNode = { label: 'path', type: NodeType.var, info: { line: 9, column: 6, used: new Set(['watch']) } };
const route: TypedNode = { label: 'route', type: NodeType.var, info: { line: 7, column: 6, comment: 'route' } };
const path: TypedNode = { label: 'path', type: NodeType.var, info: { line: 9, column: 6, used: new Set(['watch']), comment: 'path' } };
const lmsg: TypedNode = { label: 'lmsg', type: NodeType.var, info: { line: 11, column: 6, used: new Set(['watch']) } };
const data: TypedNode = { label: 'data', type: NodeType.var, info: { line: 19, column: 6, comment: '这是注释11' } };
const age: TypedNode = { label: 'age', type: NodeType.var, info: { line: 23, column: 6 } };
Expand Down
4 changes: 2 additions & 2 deletions test/setup-block/TestComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const props = defineProps({
})
const emits = defineEmits(['update:msg'])
/** route */
const route = useRoute();
/** path */
const path = computed(() => route.path?.age)
const lmsg = ref(props.msg)
Expand Down

0 comments on commit 52324f0

Please sign in to comment.