https://github.com/codemodsquad/jscodeshift-choose-parser
pick a jscodeshift parser intelligently based upon local project config
https://github.com/codemodsquad/jscodeshift-choose-parser
jscodeshift
Last synced: 3 months ago
JSON representation
pick a jscodeshift parser intelligently based upon local project config
- Host: GitHub
- URL: https://github.com/codemodsquad/jscodeshift-choose-parser
- Owner: codemodsquad
- License: mit
- Created: 2020-01-28T21:18:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T16:21:59.000Z (almost 3 years ago)
- Last Synced: 2024-04-14T09:40:41.381Z (over 1 year ago)
- Topics: jscodeshift
- Language: JavaScript
- Size: 2.97 MB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# jscodeshift-choose-parser
[](https://circleci.com/gh/codemodsquad/jscodeshift-choose-parser)
[](https://codecov.io/gh/codemodsquad/jscodeshift-choose-parser)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://badge.fury.io/js/jscodeshift-choose-parser)### `chooseJSCodeshiftParser(file: string): string | Parser`
```js
const chooseJSCodeshiftParser = require('jscodeshift-choose-parser')
```Intelligently chooses a parser for a given file. Basically:
- If extension is `.ts` or `.tsx` return `'ts'`/`'tsx'` depending on extension
- Else if `@babel/core` is installed, return parser that uses with `@babel/core` using local babel config
- Else return `undefined`The default `babylon` parser in `jscodeshift` **does not use your local babel config** AFAIK. This package
returns a parser that **does use your local babel config**.### Example in a transform
```js
const chooseJSCodeshiftParser = require('jscodeshift-choose-parser')module.exports = function(fileInfo, api) {
const parser = chooseJSCodeshiftParser(fileInfo.path)
return api.jscodeshift
.withParser(parser)(fileInfo.source)
.findVariableDeclarators('foo')
.renameTo('bar')
.toSource()
}
```