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

feat(vue-script-setup-converter): Remove defineComponent from import declaration #53

Conversation

inouetakuya
Copy link
Contributor

Remove defineComponent from import declaration because the converted code does not need to import defineComponent.

Copy link

vercel bot commented May 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wattanx-converter ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 1:38pm

@@ -1,3 +1,4 @@
// TODO: Move to helpers/node.ts
Copy link
Contributor Author

@inouetakuya inouetakuya May 6, 2024

Choose a reason for hiding this comment

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

I will handle this in another Pull Request 🙏

.map((x) => {
if (x.isKind(SyntaxKind.ImportDeclaration)) {
if (hasNamedImportIdentifier(x, "defineComponent")) {
removeNamedImportIdentifier(x, "defineComponent");
Copy link
Owner

Choose a reason for hiding this comment

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

It may be better to extract only the ImportDeclaration and insert it later.
(I don't want to rewrite the original sorce.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I don't want to rewrite the original sorce.)

Pros.

I thought so too, but chose to rewrite the original once, because no real harm would come from rewriting the original at this time, and because duplicating the importDeclaration would have been somewhat tedious.

However, on second thought, I decided that it could be a breeding ground for bugs in the future, so I will fix it.

😺

import type { ImportDeclaration, SourceFile } from "ts-morph";
import { hasNamedImportIdentifier } from "../helpers/module";

export const convertDefineComponentImport = (sourceFile: SourceFile) => {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it is a convert to defineComponent.

Suggested change
export const convertDefineComponentImport = (sourceFile: SourceFile) => {
export const convertImportDeclaration = (sourceFile: SourceFile) => {

@@ -41,6 +43,7 @@ export const convertSrc = (input: string) => {
throw new Error("defineComponent is not found.");
}

const defineComponentImport = convertDefineComponentImport(sourceFile) ?? "";
Copy link
Owner

Choose a reason for hiding this comment

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

Looking here, convertDefineComponentImport looks good. I prefer converterImportDeclaration to defineComponentImport.

…ComponentImportConverter.ts -> packages/vue-script-setup-converter/src/lib/converter/importDeclarationConverter.ts
Copy link
Owner

@wattanx wattanx left a comment

Choose a reason for hiding this comment

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

👍

@wattanx wattanx merged commit cbadbf5 into wattanx:main May 6, 2024
3 checks passed
@inouetakuya inouetakuya deleted the feat-vue-script-setup-converter-remove-define-component branch May 6, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants