Skip to content

Commit

Permalink
refactor(vue-script-setup-converter): move it to the suitable directo…
Browse files Browse the repository at this point in the history
…ry (#54)

* renamed: packages/vue-script-setup-converter/src/lib/helper.ts -> packages/vue-script-setup-converter/src/lib/helpers/node.ts

* test: fix it
  • Loading branch information
inouetakuya authored May 7, 2024
1 parent cbadbf5 commit 0537de9
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/vue-script-setup-converter/src/lib/convertSrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ts,
} from "ts-morph";
import { parse } from "@vue/compiler-sfc";
import { getNodeByKind } from "./helper";
import { getNodeByKind } from "./helpers/node";
import { hasNamedImportIdentifier } from "./helpers/module";
import { convertImportDeclaration } from "./converter/importDeclarationConverter";
import { convertPageMeta } from "./converter/pageMetaConverter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CallExpression, ScriptTarget, SyntaxKind, Project } from "ts-morph";
import { parse } from "@vue/compiler-sfc";
import prettier from "prettier";
import parserTypeScript from "prettier/parser-typescript";
import { getNodeByKind } from "../helper";
import { getNodeByKind } from "../helpers/node";
import { convertEmits } from "./emitsConverter";

const parseScript = (input: string, lang: "js" | "ts" = "js") => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SyntaxKind,
ArrowFunction,
} from "ts-morph";
import { getOptionsNode } from "../helper";
import { getOptionsNode } from "../helpers/node";

// ctx.emit('event') -> emit('event')
export const replaceEmit = (expression: string, contextName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CallExpression, ScriptTarget, SyntaxKind, Project } from "ts-morph";
import { parse } from "@vue/compiler-sfc";
import prettier from "prettier";
import parserTypeScript from "prettier/parser-typescript";
import { getNodeByKind } from "../helper";
import { getNodeByKind } from "../helpers/node";
import { convertPageMeta } from "./pageMetaConverter";

const parseScript = (input: string, lang: "js" | "ts" = "js") => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CallExpression, PropertyAssignment } from "ts-morph";
import { getOptionsNode } from "../helper";
import { getOptionsNode } from "../helpers/node";

export const convertPageMeta = (node: CallExpression, lang: string = "js") => {
const nameNode = getOptionsNode(node, "name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CallExpression, ScriptTarget, SyntaxKind, Project } from "ts-morph";
import { parse } from "@vue/compiler-sfc";
import prettier from "prettier";
import parserTypeScript from "prettier/parser-typescript";
import { getNodeByKind } from "../helper";
import { getNodeByKind } from "../helpers/node";
import { convertProps } from "./propsConverter";

const parseScript = (input: string, lang: "js" | "ts" = "js") => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
AsExpression,
ArrowFunction,
} from "ts-morph";
import { getNodeByKind, getOptionsNode } from "../helper";
import { getNodeByKind, getOptionsNode } from "../helpers/node";

export const convertProps = (node: CallExpression, lang: string = "js") => {
const propsNode = getOptionsNode(node, "props");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parse } from "@vue/compiler-sfc";
import prettier from "prettier";
import parserTypeScript from "prettier/parser-typescript";
import optionsApi from "../../samples/composition-api.txt?raw";
import { getNodeByKind } from "../helper";
import { getNodeByKind } from "../helpers/node";

test("setup statements", () => {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNodeByKind } from "./../helper";
import { getNodeByKind } from "../helpers/node";
import { CallExpression, SyntaxKind, MethodDeclaration } from "ts-morph";
import { replaceEmit } from "./emitsConverter";

Expand Down Expand Up @@ -27,7 +27,7 @@ export const convertSetup = (node: CallExpression) => {
if (!contextName) {
return x.getFullText();
}
return replaceEmit(x.getFullText(), contextName)
return replaceEmit(x.getFullText(), contextName);
})
.join("");
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("helpers/module", () => {
describe("when importDeclaration does not include target namedImport", () => {
const source = `<script>import { ref } from 'vue';</script>`;

it("returns true", () => {
it("returns false", () => {
const sourceFile = getSourceFile(source);
const importDeclaration = sourceFile.getImportDeclaration("vue");
const result = hasNamedImportIdentifier(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: Move to helpers/node.ts
import { SyntaxKind, Node, PropertyAssignment, CallExpression } from "ts-morph";

export const getNodeByKind = (
Expand Down

0 comments on commit 0537de9

Please sign in to comment.