Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: How do I get hold of Decorator nodes? #535

Open
klippx opened this issue Dec 8, 2022 · 1 comment
Open

Help: How do I get hold of Decorator nodes? #535

klippx opened this issue Dec 8, 2022 · 1 comment
Labels

Comments

@klippx
Copy link

klippx commented Dec 8, 2022

How do I get a hold of the collection for @Directive() and @ObjectType() and Field() decorator calls in this example?

https://astexplorer.net/#/gist/96fa2a58a3c859d61278839d7b897f8f/acf963ec5bd8c96799d87bf4f8ccf6504c24c6d6

I have tried

module.exports = function transformer(file, api) {
  const j = api.jscodeshift;
  const root = j(file.source);

  // Nothing! But isn't this exactly what the selector is supposed to find?
  const decorators = root.find(j.Decorator); 
  
  // A lot, but none of the decorators
  const identifiers = root.find(j.Identifier); 

  // Finds the `@Field()` decorator, but also includes the `visualizations` property which is too much.
  const classProperties = root.find(j.ClassProperty);   

  return root.toSource();
};

I want to find them and only them so I can remove those lines of code with j.remove(path).

My config looks like this:

const options = {
  dry: true,
  print: true,
  verbose: 1,
  parser: 'babylon',
  parserConfig: {
    sourceType: 'module',
    allowImportExportEverywhere: true,
    allowReturnOutsideFunction: true,
    startLine: 1,
    tokens: true,
    plugins: [
      'typescript',
      ['decorators', { decoratorsBeforeExport: true }],
    ],
  },
};
@ludgerey
Copy link

ludgerey commented Jan 22, 2024

I have the same issue.

Basically this makes mods impossible for Class Decorators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants