facebook / jscodeshift

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

Enable parsing of `accessor` keyword #580

Closed RhodeHummel closed 2 months ago

RhodeHummel commented 9 months ago

It looks like jscodeshift does not currently support the accessor keyword that was added typescript in 3.9. Can we please add support for this. Thank you.

https://github.com/microsoft/TypeScript/pull/49705 https://github.com/tc39/proposal-decorators

ElonVolo commented 9 months ago

Would you be able to add the content you were trying to transform, the transformation script you wrote, the command you ran to transform it, and the expected output, to the issue?

Daniel15 commented 8 months ago

I think this will need upstream changes (recast and/or ast-types)

RhodeHummel commented 8 months ago

@ElonVolo Here is a simple case. Basically, I just want it to run without any errors. Hope this is enough information for you.

// test-file.ts
export class Test {
    public accessor myValue = 10;
}
// test-transform.ts
import { FileInfo, API, Options } from 'jscodeshift';

module.exports = function (file: FileInfo, { j }: API, _options: Options) {
    const root = j(file.source);

    // Do nothing just output the file again
    return root.toSource();
};

BTW: I noticed that this is already supported by babel but the plugin for it does need to be configured. Could that be the problem in this case?

ElonVolo commented 8 months ago

I'm running the transform and file code you submitted and I'm not getting any errors. Nothing's being transformed, which is expected as no modifications have been made.

Are you getting some different result on your end?

ElonVolo commented 8 months ago

I think this will need upstream changes (recast and/or ast-types)

I looked at the recast code and there does seem to be some support for Typescript's accessor keyword.

RhodeHummel commented 8 months ago

@ElonVolo I definitely get an error. There is no error message, it just prints out results 1 error instead of 1 unmodified. I have created an isolated test case and included it here.

To see the error, run npx ts-node test.ts

jscodeshift-error.zip