trivikr / vitest-codemod

Codemod scripts to migrate your JavaScript unit tests to vitest
MIT License
23 stars 2 forks source link

[Bug?]: Error on TypeScript inline types #140

Open sschneider-ihre-pvs opened 1 year ago

sschneider-ihre-pvs commented 1 year ago

Self-service

Describe the bug

return mount(SomeComponent as any, { this seems to throw an error at the ,.

Steps to reproduce

have something like jest with vue and mount a component. try to run the codemod

Observed behavior

 ERR <PATH>something.spec.ts Transformation error (Unexpected token, expected "," (37:38))
SyntaxError: Unexpected token, expected "," (37:38)
    at toParseError (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parse-error.ts:81:19)
    at FlowParserMixin.raise (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\tokenizer\index.ts:1487:19)
    at FlowParserMixin.unexpected (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\tokenizer\index.ts:1528:16)
    at FlowParserMixin.expect (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\util.ts:149:28)
    at FlowParserMixin.parseCallExpressionArguments (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:1023:14)
    at FlowParserMixin.parseCoverCallAndAsyncArrowHead (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:886:29)
    at FlowParserMixin.parseSubscript (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:775:19)
    at FlowParserMixin.parseSubscript (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:3249:20)
    at FlowParserMixin.parseSubscripts (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:731:19)
    at FlowParserMixin.parseSubscripts (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:3199:20)
    at FlowParserMixin.parseExprSubscripts (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:716:17)
    at FlowParserMixin.parseUpdate (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:687:21)
    at FlowParserMixin.parseMaybeUnary (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:649:23)
    at FlowParserMixin.parseMaybeUnaryOrPrivate (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:387:14)
    at FlowParserMixin.parseExprOps (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:399:23)
    at FlowParserMixin.parseMaybeConditional (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:354:23)
    at FlowParserMixin.parseMaybeAssign (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:294:21)
    at FlowParserMixin.parseMaybeAssign (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:3053:20)
    at FlowParserMixin.parseExpressionBase (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:217:23)
    at callback (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:208:39)
    at FlowParserMixin.allowInAnd (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:3137:16)
    at FlowParserMixin.parseExpression (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:208:17)
    at FlowParserMixin.parseReturnStatement (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:1067:28)
    at FlowParserMixin.parseStatementContent (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:478:21)
    at FlowParserMixin.parseStatementLike (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:417:17)
    at FlowParserMixin.parseStatementLike (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:1952:26)
    at FlowParserMixin.parseStatementListItem (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:366:17)
    at FlowParserMixin.parseBlockOrModuleBlockBody (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:1395:16)
    at FlowParserMixin.parseBlockBody (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:1368:10)
    at FlowParserMixin.parseBlock (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\statement.ts:1336:10)
    at FlowParserMixin.parseFunctionBody (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:2589:24)
    at parse (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:1905:17)
    at FlowParserMixin.forwardNoArrowParamsConversionAt (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:2189:18)
    at FlowParserMixin.parseFunctionBody (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:1904:14)
    at FlowParserMixin.parseArrowExpression (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:2534:10)
    at FlowParserMixin.parseParenAndDistinguishExpression (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:1831:12)
    at FlowParserMixin.parseParenAndDistinguishExpression (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:3141:20)
    at FlowParserMixin.parseExprAtom (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:1170:21)
    at FlowParserMixin.parseExprAtom (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\jsx\index.ts:574:22)
    at FlowParserMixin.parseExprSubscripts (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:710:23)
    at FlowParserMixin.parseUpdate (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:687:21)
    at FlowParserMixin.parseMaybeUnary (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:649:23)
    at FlowParserMixin.parseMaybeUnaryOrPrivate (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:387:14)
    at FlowParserMixin.parseExprOps (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:399:23)
    at FlowParserMixin.parseMaybeConditional (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:354:23)
    at FlowParserMixin.parseMaybeAssign (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:294:21)
    at FlowParserMixin.parseMaybeAssign (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\plugins\flow\index.ts:3053:20)
    at callback (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:248:12)
    at FlowParserMixin.allowInAnd (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:3137:16)
    at FlowParserMixin.parseMaybeAssignAllowIn (<PATHTONODE>\npm-cache\_npx\0f2dacd58d69eeae\node_modules\@babel\parser\src\parser\expression.ts:247:17)
All done.
Results:
1 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 1.632seconds

Expected behavior

working code mod

Environment

vitest-codemod: 0.1.3
- jscodeshift: 0.14.0
- recast: 0.21.5

Additional context

No response

x8BitRain commented 6 months ago

Add --extensions=ts --parser=ts and it should work.

npx vitest-codemod --dry --print -t jest --extensions=ts --parser=ts tests/integration/helper.spec.ts