Skip to content

Commit

Permalink
fix: keep the comment (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
wattanx authored May 17, 2024
1 parent 8e347ec commit 323b7f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
exports[`snapshot > defineNuxtComponent 1`] = `
"import { useNuxtApp } from "#imports";
definePageMeta({
name: 'HelloWorld', layout: 'test-layout', middleware: 'test-middleware'
name: 'HelloWorld',
layout: 'test-layout',
middleware: 'test-middleware'
});
const { $client } = useNuxtApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe("convertPageMeta", () => {
export default defineNuxtComponent({
name: 'HelloWorld',
layout: 'test-layout',
// comment
middleware: 'test-middleware',
})
</script>`;
Expand All @@ -42,7 +43,10 @@ describe("convertPageMeta", () => {

expect(output).toMatchInlineSnapshot(`
"definePageMeta({
name: 'HelloWorld',layout: 'test-layout',middleware: 'test-middleware'
name: 'HelloWorld',
layout: 'test-layout',
// comment
middleware: 'test-middleware'
});"
`);
});
Expand All @@ -64,7 +68,9 @@ describe("convertPageMeta", () => {

expect(output).toMatchInlineSnapshot(`
"definePageMeta({
name: 'HelloWorld',layout: 'test-layout',middleware: ['test-middleware-1', 'test-middleware-2']
name: 'HelloWorld',
layout: 'test-layout',
middleware: ['test-middleware-1', 'test-middleware-2']
});"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ const convertToDefinePageMeta = ({
layoutNode: PropertyAssignment | undefined;
middlewareNode: PropertyAssignment | undefined;
}) => {
const nameProperty = nameNode ? nameNode.getText() : "";
const layoutProperty = layoutNode ? layoutNode.getText() : "";
const middlewareProperty = middlewareNode ? middlewareNode.getText() : "";
const nameProperty = nameNode ? nameNode.getFullText() : "";
const layoutProperty = layoutNode ? layoutNode.getFullText() : "";
const middlewareProperty = middlewareNode ? middlewareNode.getFullText() : "";

return `definePageMeta({
${[nameProperty, layoutProperty, middlewareProperty]
.filter(Boolean)
.join(",")}
return `definePageMeta({${[nameProperty, layoutProperty, middlewareProperty]
.filter(Boolean)
.join(",")}
});`;
};

0 comments on commit 323b7f1

Please sign in to comment.