Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(vue-script-setup-converter): move it to the suitable directory #54

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

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
Loading