yoyo930021 / vc2c

The vc2c project can convert vue class APIs to vue composition APIs in Vue.js components written in Typescript.
https://yoyo930021.github.io/vc2c/
MIT License
87 stars 20 forks source link

Cannot convert files #43

Open Ninja243 opened 1 year ago

Ninja243 commented 1 year ago

Hello, I don't seem to be able to convert any files using this tool. I get the following output:

mweyaruider@MacBook-Pro-4 cct-frontend % npx vc2c single ./src/modules/core/components/cct-tabs/cct-tabs.component.ts  
? You aren't using -o option to set output file path, It will replace original file content. Yes
DeprecationWarning: 'createIdentifier' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createToken' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createArrowFunction' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createCallExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createExpressionStatement' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createStringLiteral' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createPropertyAssignment' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createVariableDeclaration' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createVariableDeclarationList' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createVariableStatement' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createObjectLiteralExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: '' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createShorthandPropertyAssignment' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createReturnStatement' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createParameterDeclaration' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createBlock' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createMethodDeclaration' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
DeprecationWarning: 'createExportAssignment' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:30324
        switch (node.kind) {
                     ^

TypeError: Cannot read properties of undefined (reading 'kind')
    at isOuterExpression (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:30324:22)
    at Object.skipOuterExpressions (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:30344:16)
    at Object.skipPartiallyEmittedExpressions (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:13435:19)
    at Object.parenthesizeExpressionOfExportDefault (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:22002:28)
    at Object.createExportAssignment (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:25853:40)
    at Object.createExportAssignment (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/typescript/lib/typescript.js:3138:29)
    at Object.runPlugins (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/vc2c/dist/lib/plugins/index.js:200:79)
    at Object.convertAST (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/vc2c/dist/lib/convert.js:38:22)
    at convert (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/vc2c/dist/lib/index.js:41:38)
    at Object.convertFile (/Users/mweyaruider/.npm/_npx/451a485627725f3e/node_modules/vc2c/dist/lib/index.js:64:17)
mweyaruider@MacBook-Pro-4 cct-frontend % 

Am I missing some dependencies? This happens for every file I try this with.

Ninja243 commented 1 year ago

Copy pasting the file I'm trying to convert into https://yoyo930021.github.io/vc2c/ also doesn't work, so I think it might not be my environment that's the issue

Ninja243 commented 1 year ago

It looks like the use of "$refs" is what causes the crash above. The following code is not transformed using the service above:

import Vue from 'vue'
import { Prop, Component, Ref, Model, Provide, Inject } from 'vue-property-decorator'
import Component from "vue-class-component";
import { Inject, Prop, Vue, Watch } from "vue-property-decorator";
import { Types } from "@/config/types";
import { ConfirmDialogComponent } from "@/modules/core/components/confirm-dialog/confirm-dialog.component";
import { MessageService } from "@/modules/core/services/message-service";
/**
 * My basic tag
 */
@Component({
  components: {
    "confirm-dialog": ConfirmDialogComponent,
  },
  mounted() {
    this.activeTabName = this.activeTab ? this.activeTab : this.firstTab();
  },
})
export default class CctTabsComponent extends Vue {

  private firstTab(): string {
    const panes = (<any>this.$refs.cctTab).panes;
    return panes?.[0]?.name;
  }
}

This may be related to https://github.com/vuejs/vue-class-component/issues/94

Edit: patching my input file as suggested in the thread above does not fix this

Ninja243 commented 1 year ago

Update: trying this with different versions of typescript (3, 3.5, 3.9.7 (as suggested in package.json), 4, 4.9) doesn't help.

Ninja243 commented 1 year ago

Smaller update: despite forcing the versions of the dependencies of my project to exactly match the versions in this project's package.json, there seems to be an issue with prettier formatting vc2c's output code after it's generated. Here's a small extract of the output when prettier crashes:

SyntaxError: ',' expected. (45:52)
  43 |         const customerService = inject<>(Types.CUSTOMER_SERVICE);
  44 |         const breadCrumbService = inject<>(Types.BREAD_CRUMB_SERVICE);
> 45 |         const tabsErrorValidation = public (nextTab: string, currentTab: string): boolean => {
     |                                                    ^
  46 |             const currTab = (<any>/* TODO: Check this convert result, it can work well in 80% case.*/ context.root.$refs[currentTab])?.$v;
  47 |             const invalid = currTab?.$invalid;
  48 |             if (invalid)
    at A (/Users/mweyaruider/IdeaProjects/cct-frontend/node_modules/prettier/parser-typescript.js:1:15163)
    at cT (/Users/mweyaruider/IdeaProjects/cct-frontend/node_modules/prettier/parser-typescript.js:257:10765)

and here's a gist with the full output: https://gist.github.com/Ninja243/ea7502f705e0ed2d15aa45c66b60d323 Edit: dev dependencies from my package.json can be found here: https://gist.github.com/Ninja243/51ca95866e6660920f150b82f2aebf0b

someguy20336 commented 1 year ago

Hey - I came across this project and was interested in using it, but it didn't work for me either. I am in the process of fixing it in this fork (https://github.com/someguy20336/vc2c) (temp PR with fixes) if you are interested. I will try to submit a PR for this repo once finished, but I am not sure how active this is anymore.

Note:

Ninja243 commented 1 year ago

Oh yeah that's awesome! Thanks for your help, I'll check this out as soon as I get back home!

Have a great Easter weekend!

someguy20336 @.***> schrieb am Sa., 8. Apr. 2023, 15:28:

Hey - I came across this project and was interested in using it, but it didn't work for me either. I am in the process of fixing it in this fork ( https://github.com/someguy20336/vc2c) (temp PR with fixes https://github.com/someguy20336/vc2c/pull/1) if you are interested. I will try to submit a PR for this repo once finished, but I am not sure how active this is anymore.

Note:

  • I have not completed fixing it just yet, but it seems most of it works. Thought I would send it your way in case you wanted to try it and were still looking for a tool
  • I have not fully tested this on our projects yet, just the unit tests
  • We don't use .vue files, so I have not (and will not) be testing with those (couldn't get the tests to work so I removed them for now)

— Reply to this email directly, view it on GitHub https://github.com/yoyo930021/vc2c/issues/43#issuecomment-1500891993, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRWXDC3BY7KHOSP5PAIEQLXAFRWZANCNFSM6AAAAAATNDSPSM . You are receiving this because you authored the thread.Message ID: @.***>

yoyo930021 commented 1 year ago

If you can provide a minimal repro case of code, I can study it.

someguy20336 commented 8 months ago

Hey, so as I mentioned, I fixed it along with several other things in this fork: https://github.com/someguy20336/vc2c/pull/1

I am happy to create a PR into this repo if you would like - otherwise, I plan to archive the fork. I can't guarantee the code is in the best state, but at this point it worked for all our projects for the most part (some manual fixing). I appreciate you making this tool! It helped a lot!