Skip to content

Commit

Permalink
feat: Convert page meta in convertSrt
Browse files Browse the repository at this point in the history
  • Loading branch information
inouetakuya committed May 5, 2024
1 parent e3ff62d commit f4959f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`snapshot > defineNuxtComponent 1`] = `
"import { defineNuxtComponent, useNuxtApp } from '#imports';
definePageMeta({
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 @@ -79,6 +79,8 @@ import { defineNuxtComponent, useNuxtApp } from '#imports';
export default defineNuxtComponent({
name: 'HelloWorld',
layout: 'test-layout',
middleware: 'test-middleware',
setup(props, ctx) {
const { $client } = useNuxtApp();
Expand Down
13 changes: 13 additions & 0 deletions packages/vue-script-setup-converter/src/lib/convertSrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "ts-morph";
import { parse } from "@vue/compiler-sfc";
import { getNodeByKind } from "./helper";
import { convertPageMeta } from "./converter/pageMetaConverter";
import { convertProps } from "./converter/propsConverter";
import { convertSetup } from "./converter/setupConverter";
import { convertEmits } from "./converter/emitsConverter";
Expand Down Expand Up @@ -40,6 +41,7 @@ export const convertSrc = (input: string) => {
throw new Error("defineComponent is not found.");
}

const pageMeta = convertPageMeta(callexpression, lang) ?? "";
const props = convertProps(callexpression, lang) ?? "";
const emits = convertEmits(callexpression, lang) ?? "";
const statement = convertSetup(callexpression) ?? "";
Expand All @@ -53,6 +55,10 @@ export const convertSrc = (input: string) => {
.map((x) => x.getText())
);

if (isDefineNuxtComponent(callexpression)) {
statements.addStatements(pageMeta);
}

statements.addStatements(props);
statements.addStatements(emits);
statements.addStatements(statement);
Expand All @@ -75,3 +81,10 @@ const isDefineComponent = (node: CallExpression) => {
node.getExpression().getText() === "defineNuxtComponent"
);
};

const isDefineNuxtComponent = (node: CallExpression) => {
if (!Node.isIdentifier(node.getExpression())) {
return false;
}
return node.getExpression().getText() === "defineNuxtComponent";
};

0 comments on commit f4959f8

Please sign in to comment.