Download next.js/packages/next-codemod/lib/parser.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 781 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next-codemod/lib/parser.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next-codemod/lib/parser.ts
-
curl -L -o parser.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next-codemod/lib/parser.ts
781 Bytes
| import j from 'jscodeshift' | |
| import babylonParse from 'jscodeshift/parser/babylon' | |
| import tsOptions from 'jscodeshift/parser/tsOptions' | |
| const dtsOptions = { | |
| ...tsOptions, | |
| plugins: [ | |
| ...tsOptions.plugins.filter((plugin) => plugin !== 'typescript'), | |
| ['typescript', { dts: true }], | |
| ], | |
| } | |
| function createParserFromPath(filePath: string): j.JSCodeshift { | |
| const isDeclarationFile = /\.d\.(m|c)?ts$/.test(filePath) | |
| if (isDeclarationFile) { | |
| return j.withParser(babylonParse(dtsOptions)) | |
| } | |
| // jsx is allowed in .js files, feed them into the tsx parser. | |
| // tsx parser :.js, .jsx, .tsx | |
| // ts parser: .ts, .mts, .cts | |
| const isTsFile = /\.(m|c)?.ts$/.test(filePath) | |
| return isTsFile ? j.withParser('ts') : j.withParser('tsx') | |
| } | |
| export { createParserFromPath } | |