jscodeshift icon indicating copy to clipboard operation
jscodeshift copied to clipboard

Enable parsing of `accessor` keyword

Open RhodeHummel opened this issue 2 years ago • 6 comments

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

RhodeHummel avatar Jan 05 '24 14:01 RhodeHummel

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?

ElonVolo avatar Jan 05 '24 17:01 ElonVolo

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

Daniel15 avatar Jan 11 '24 01:01 Daniel15

@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?

RhodeHummel avatar Jan 11 '24 01:01 RhodeHummel

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 avatar Jan 11 '24 15:01 ElonVolo

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.

ElonVolo avatar Jan 11 '24 15:01 ElonVolo

@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

RhodeHummel avatar Jan 11 '24 17:01 RhodeHummel