code.find(codeshift.Decorator) ignores decorators on class properties
code.find(codeshift.Decorator) ignores decorators on nodes of type ClassProperty
Example input code:
class Foo {
@service aProp;
@service() bProp;
@service
get cProp() {}
@service
dProp() {}
}
Example transform
export const parser = "ts";
export default function transformer(file, api) {
const j = api.jscodeshift;
const code = j(file.source);
code.find(j.Decorator).forEach(path => {
if (
path.value.expression.type === "Identifier" &&
path.value.expression.name === "service"
) {
path.value.expression.name = "inject";
}
});
return code.toSource();
}
Output (unexpected)
class Foo {
@service aProp;
@service() bProp;
@inject
get cProp() {}
@inject
dProp() {}
}
I just ran in to this same thing.
Here is my example: https://astexplorer.net/#/gist/a8ffcb056b86f73e6b23bd8a8b08e69e/fa79daed27bfbb99fad3274b28e717b716c45a5f
I'm using the flow parser here
decorators exist on methods, but not properties?

Looks like I have to switch to the ts parser:

but that doesn't make sense either :thinking: the find(j.Decorator) still only finds 3 decorators, when I expect there to be 8
Any update on this issue ? i can't create Class function decorators like @property https://astexplorer.net/#/gist/a8ffcb056b86f73e6b23bd8a8b08e69e/b0cb9478fd38744aa1fbe0f1c78607ab4953ceca