facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.11k stars 468 forks source link

missing semicolon how to fix this #559

Open wanghaisheng opened 1 year ago

wanghaisheng commented 1 year ago

source code is here https://github.com/fawazahmed0/youtube-uploader/blob/main/src/upload.ts

jscodeshift --run-in-band "upload.ts"

@ElonVolo

> jscodeshift --run-in-band "upload.ts"

Processing 1 files... 
 ERR upload.ts Transformation error (Missing semicolon. (19:11))
SyntaxError: Missing semicolon. (19:11)
    at Object._raise (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\error.js:147:45)
    at Object.raiseWithData (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\error.js:142:17)
    at Object.raise (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\error.js:91:17)
    at Object.semicolon (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\util.js:127:10)
    at Object.parseVarStatement (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\statement.js:808:10)
    at Object.parseStatementContent (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\statement.js:307:21)
    at Object.parseStatement (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\statement.js:247:17)
    at Object.parseBlockOrModuleBlockBody (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\statement.js:983:25)   
    at Object.parseBlockBody (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\parser\statement.js:959:10)
    at Object.parseBlockBody (D:\Download\audio-visual\saas\tiktoka\youtube-uploader-ts\puppeteer-to-playwright\node_modules\@babel\parser\src\plugins\estree.js:137:13)
wanghaisheng commented 1 year ago

https://babeljs.io/docs/babel-plugin-transform-typescript try to use this ,convert source code to this one

in the source code, he use puppeteer and I want to use playwright, so I came to this lib based on jscodeshift.

https://github.com/checkly/puppeteer-to-playwright

when I run npm run convert

it tell me source file is missing semicolon, then I want to pretty the source file ,so go to the ts transform plugin and after pretty code ,it still no luck @ElonVolo

ElonVolo commented 1 year ago

I’m trying to understand the issue you’re having.One immediate thing I’m seeing is that (I believe) is that you’re not passing the path of a transformation file to jscodeshift.To run the codemod you have to use the command like this:jscodeshift -t my_transform_file.js file_to_transform.jsSent from my iPhoneOn May 23, 2023, at 04:30, HeisenBerg? @.***> wrote: https://babeljs.io/docs/babel-plugin-transform-typescript try to use this ,convert source code to this one

edited: removed long code snippet

wanghaisheng commented 1 year ago

just as you suggest, tried this one transform.js is here https://github.com/checkly/puppeteer-to-playwright/blob/main/transform.js

jscodeshift  -t  transform.js upload.ts
Processing 1 files... 
Spawning 1 workers...
Sending 1 files to free worker...
 ERR upload.ts Transformation error (Missing semicolon. (19:11))
SyntaxError: Missing semicolon. (19:11)
    at instantiate (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parse-error/credentials.ts:62:21)
    at toParseError (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parse-error.ts:60:12)
    at JSXParserMixin.raise (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/tokenizer/index.ts:1490:19)
    at JSXParserMixin.semicolon (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/util.ts:138:10)
    at JSXParserMixin.parseVarStatement (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:1167:10)
    at JSXParserMixin.parseStatementContent (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:537:21)
    at JSXParserMixin.parseStatementLike (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:417:17)
    at JSXParserMixin.parseModuleItem (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:354:17)
    at JSXParserMixin.parseBlockOrModuleBlockBody (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:1359:16)
    at JSXParserMixin.parseBlockBody (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:1333:10)
    at JSXParserMixin.parseBlockBody (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/plugins/estree.ts:158:13)
    at JSXParserMixin.parseProgram (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:226:10)
    at JSXParserMixin.parseTopLevel (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/statement.ts:208:25)
    at JSXParserMixin.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/parser/index.ts:45:10)
    at JSXParserMixin.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/plugins/estree.ts:25:43)
    at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/@babel/parser/src/index.ts:67:38)
    at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/parser/babel5Compat.js:47:22)
    at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/recast/lib/parser.js:23:30)
    at fromSource (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:82:25)
    at core (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:44:5)
    at j (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:142:12)
    at _default (/Users/wenke/github/puppeteer-to-playwright-main/transform.js:3:15)
All done. 
Results: 
1 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 1.276seconds 
ElonVolo commented 1 year ago

What platform are you using (mac, linux, windows)? What version node?Sent from my iPhoneOn May 23, 2023, at 11:26, HeisenBerg? @.> wrote: just as you suggest, tried this one transform.js is here https://github.com/checkly/puppeteer-to-playwright/blob/main/transform.js jscodeshift -t transform.js upload.ts Processing 1 files... Spawning 1 workers... Sending 1 files to free worker... ERR upload.ts Transformation error (Missing semicolon. (19:11)) SyntaxError: Missing semicolon. (19:11) at instantiate @./parser/src/parse-error/credentials.ts:62:21) at toParseError @./parser/src/parse-error.ts:60:12) at JSXParserMixin.raise @./parser/src/tokenizer/index.ts:1490:19) at JSXParserMixin.semicolon @./parser/src/parser/util.ts:138:10) at JSXParserMixin.parseVarStatement @./parser/src/parser/statement.ts:1167:10) at JSXParserMixin.parseStatementContent @./parser/src/parser/statement.ts:537:21) at JSXParserMixin.parseStatementLike @./parser/src/parser/statement.ts:417:17) at JSXParserMixin.parseModuleItem @./parser/src/parser/statement.ts:354:17) at JSXParserMixin.parseBlockOrModuleBlockBody @./parser/src/parser/statement.ts:1359:16) at JSXParserMixin.parseBlockBody @./parser/src/parser/statement.ts:1333:10) at JSXParserMixin.parseBlockBody @./parser/src/plugins/estree.ts:158:13) at JSXParserMixin.parseProgram @./parser/src/parser/statement.ts:226:10) at JSXParserMixin.parseTopLevel @./parser/src/parser/statement.ts:208:25) at JSXParserMixin.parse @./parser/src/parser/index.ts:45:10) at JSXParserMixin.parse @./parser/src/plugins/estree.ts:25:43) at Object.parse @.***/parser/src/index.ts:67:38) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/parser/babel5Compat.js:47:22) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/recast/lib/parser.js:23:30) at fromSource (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:82:25) at core (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:44:5) at j (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:142:12) at _default (/Users/wenke/github/puppeteer-to-playwright-main/transform.js:3:15) All done. Results: 1 errors 0 unmodified 0 skipped 0 ok Time elapsed: 1.276seconds

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

Daniel15 commented 1 year ago

Try adding --parser=ts to your jscodeshift command.

Did you try adding a semicolon where it says the semicolon is missing?

ElonVolo commented 1 year ago

You are having this problem with the semicolon because the author of puppeteer-to-playwright isn’t specifying that the Typescript parser is to be used. It looks like they only ever wrote that transform to transform a Javascript file.They’d need to add a —parser=ts argument to their jscodeshift command to avoid getting that error.Sent from my iPhoneOn May 23, 2023, at 12:56, Elon Volow @.> wrote:What platform are you using (mac, linux, windows)? What version node?Sent from my iPhoneOn May 23, 2023, at 11:26, HeisenBerg? @.> wrote: just as you suggest, tried this one transform.js is here https://github.com/checkly/puppeteer-to-playwright/blob/main/transform.js jscodeshift -t transform.js upload.ts Processing 1 files... Spawning 1 workers... Sending 1 files to free worker... ERR upload.ts Transformation error (Missing semicolon. (19:11)) SyntaxError: Missing semicolon. (19:11) at instantiate @./parser/src/parse-error/credentials.ts:62:21) at toParseError @./parser/src/parse-error.ts:60:12) at JSXParserMixin.raise @./parser/src/tokenizer/index.ts:1490:19) at JSXParserMixin.semicolon @./parser/src/parser/util.ts:138:10) at JSXParserMixin.parseVarStatement @./parser/src/parser/statement.ts:1167:10) at JSXParserMixin.parseStatementContent @./parser/src/parser/statement.ts:537:21) at JSXParserMixin.parseStatementLike @./parser/src/parser/statement.ts:417:17) at JSXParserMixin.parseModuleItem @./parser/src/parser/statement.ts:354:17) at JSXParserMixin.parseBlockOrModuleBlockBody @./parser/src/parser/statement.ts:1359:16) at JSXParserMixin.parseBlockBody @./parser/src/parser/statement.ts:1333:10) at JSXParserMixin.parseBlockBody @./parser/src/plugins/estree.ts:158:13) at JSXParserMixin.parseProgram @./parser/src/parser/statement.ts:226:10) at JSXParserMixin.parseTopLevel @./parser/src/parser/statement.ts:208:25) at JSXParserMixin.parse @./parser/src/parser/index.ts:45:10) at JSXParserMixin.parse @./parser/src/plugins/estree.ts:25:43) at Object.parse @./parser/src/index.ts:67:38) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/parser/babel5Compat.js:47:22) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/recast/lib/parser.js:23:30) at fromSource (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:82:25) at core (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:44:5) at j (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:142:12) at _default (/Users/wenke/github/puppeteer-to-playwright-main/transform.js:3:15) All done. Results: 1 errors 0 unmodified 0 skipped 0 ok Time elapsed: 1.276seconds

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

wanghaisheng commented 1 year ago

Try adding --parser=ts to your jscodeshift command.

Did you try adding a semicolon where it says the semicolon is missing?

I have no clue where the semicolon missing , try using pretty extension on vscode to auto insert semicolon and also failed. I will try your advice

wanghaisheng commented 1 year ago

What platform are you using (mac, linux, windows)? What version node?Sent from my iPhoneOn May 23, 2023, at 11:26, HeisenBerg? @.> wrote: just as you suggest, tried this one transform.js is here https://github.com/checkly/puppeteer-to-playwright/blob/main/transform.js jscodeshift -t transform.js upload.ts Processing 1 files... Spawning 1 workers... Sending 1 files to free worker... ERR upload.ts Transformation error (Missing semicolon. (19:11)) SyntaxError: Missing semicolon. (19:11) at instantiate @./parser/src/parse-error/credentials.ts:62:21) at toParseError @./parser/src/parse-error.ts:60:12) at JSXParserMixin.raise @./parser/src/tokenizer/index.ts:1490:19) at JSXParserMixin.semicolon @./parser/src/parser/util.ts:138:10) at JSXParserMixin.parseVarStatement @./parser/src/parser/statement.ts:1167:10) at JSXParserMixin.parseStatementContent @./parser/src/parser/statement.ts:537:21) at JSXParserMixin.parseStatementLike @./parser/src/parser/statement.ts:417:17) at JSXParserMixin.parseModuleItem @./parser/src/parser/statement.ts:354:17) at JSXParserMixin.parseBlockOrModuleBlockBody @./parser/src/parser/statement.ts:1359:16) at JSXParserMixin.parseBlockBody @./parser/src/parser/statement.ts:1333:10) at JSXParserMixin.parseBlockBody @./parser/src/plugins/estree.ts:158:13) at JSXParserMixin.parseProgram @./parser/src/parser/statement.ts:226:10) at JSXParserMixin.parseTopLevel @./parser/src/parser/statement.ts:208:25) at JSXParserMixin.parse @./parser/src/parser/index.ts:45:10) at JSXParserMixin.parse @./parser/src/plugins/estree.ts:25:43) at Object.parse @./parser/src/index.ts:67:38) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/parser/babel5Compat.js:47:22) at Object.parse (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/node_modules/recast/lib/parser.js:23:30) at fromSource (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:82:25) at core (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:44:5) at j (/Users/wenke/.nvm/versions/node/v18.2.0/lib/node_modules/jscodeshift/src/core.js:142:12) at _default (/Users/wenke/github/puppeteer-to-playwright-main/transform.js:3:15) All done. Results: 1 errors 0 unmodified 0 skipped 0 ok Time elapsed: 1.276seconds —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.>

I have tried on my windows and mac computer. version info I will update later

ElonVolo commented 1 year ago

Here is the problem:The migration script isn’t written for typescript, so it’s seeing a typescript type annotation on line 19 and freaking out. The migration package needs to be ported to Typescript by the package author.Sent from my iPhoneOn May 23, 2023, at 21:00, HeisenBerg? @.***> wrote:

Try adding --parser=ts to your jscodeshift command. Did you try adding a semicolon where it says the semicolon is missing?

I have no clue where the semicolon missing , try using pretty extension on vscode to auto insert semicolon and also failed. I will try your advice

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>