Open trivikr opened 2 years ago
The @babel/parser-7.16.12
on https://astexplorer.net/ does not throw any error.
If you don't supply jscodeshift a parser parameter the default that jscodeshift uses something called babel5compat, which is has a significantly reduced feature set from ts, babylon, etc. So you could think of it as behaving like a much older version of babel.
Babylon should probably be made the default parser at some point, but at the moment having babylon become the default parser breaks a ton of unit tests.
Describe the bug
jscodeshift throws
SyntaxError: Unexpected token, expected ","
for typescript file with just typesSteps to reproduce
Stackblitz: https://stackblitz.com/edit/node-u3ttzg Run
npx jscodeshift example.ts
in console.To reproduce in your workspace, add the following files:
transform.js
```js // transform.js module.exports = function (fileInfo, api, options) { const j = api.jscodeshift; const source = j(fileInfo.source); return source.toSource(); }; ```example.ts
```ts // example.ts import AWS from 'aws-sdk'; export const listTables = (client: AWS.DynamoDB) => client.listTables().promise(); ```Observed behavior
Throws error:
Expected behavior
The jscodeshift run is complete with no transformation
Screenshots
Screenshot
![unexpected-token-error](https://user-images.githubusercontent.com/16024985/157371026-f9e47b67-814c-4fb4-8d76-a0e8f365b986.png)Additional context
We noticed this issue in
aws-sdk-js-codemod
and we tried to fix it by passingparser=ts
in the tests in https://github.com/trivikr/aws-sdk-js-codemod/pull/83But explicitly setting the parser breaks other tests. We can pass parser for the specific test, but it will affect our consumers which may run transformation on or multiple files.