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

original parserOptions not getting passed to traversed files. Intentional? #521

Open
krosenberg opened this issue Sep 15, 2021 · 0 comments

Comments

@krosenberg
Copy link

krosenberg commented Sep 15, 2021

I'm using react-docgen@next on a project that uses Flow, and I'm utilizing the new makeFsImporter importer to be able to parse imported types. Here's my setup:

value = docgen.parse(source, null, null, {
  importer: docgen.importers.makeFsImporter(),
  filename: path,
  parserOptions: {
    plugins: [
      'jsx',
      'flow',
      'nullishCoalescingOperator',
      'objectRestSpread',
      'optionalCatchBinding',
      'optionalChaining',
      'classProperties',
      'classPrivateProperties',
      'classPrivateMethods',
    ],
  },
});

I am passing parserOptions because the .babelrc that react-docgen finds is not the one I want it to use (it doesn't contain the flow plugin). I noticed that the parserOptions get applied correctly to the original file, but for other files that are traversed, parserOptions are ignored:

https://github.com/reactjs/react-docgen/blob/master/src/importer/makeFsImporter.js#L70

This causes a SyntaxError when traversed files with imported types are parsed because it reverts to the .babelrc that I was avoiding by specifying parserOptions.plugins.

Is the line in makeFsImporter that sets parserOptions: {} intentional? Or can it be removed so that parserOptions specified in the original parse call are applied to other files? I'm happy to open a PR if so.

EDIT: I found a similar question asked when this code was introduced: https://github.com/reactjs/react-docgen/pull/352/files/8c0a15fcae4053b1d2115bd7dbd24252cf70b228#r287538448.

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

No branches or pull requests

1 participant