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

Storysource unable to parse Flow type annotations #4955

Open
Nemvts opened this issue Dec 8, 2018 · 4 comments
Open

Storysource unable to parse Flow type annotations #4955

Nemvts opened this issue Dec 8, 2018 · 4 comments

Comments

@Nemvts
Copy link

Nemvts commented Dec 8, 2018

Describe the bug
Storysource is unable to parse Flow type annotations. When the type annotations are removed or by wrapping it around a flow comment the error will go away.

Code snippets
Error message from Console

./src/form/form.stories.js
Module build failed: SyntaxError: Unexpected token (43:5)

Flow example resulting in error

type ContactRawFormProps = {
  handleSubmit: Function,
};
const ContactRawForm = (props: ContactRawFormProps) 

System:

  • OS: Windows10
  • Browser: Chrome
  • Framework: React
  • Addons:
    "@storybook/addon-backgrounds": "3.4.8",
    "@storybook/addon-knobs": "3.4.8",
    "@storybook/addon-notes": "3.4.8",
    "@storybook/addon-storysource": "3.4.8",
  • Version:
    "babel-core": "6.26.3",

Additional context
webpack.config.js

      {
        test: /\.stories\.js?$/,
        exclude: [
          path.resolve(__dirname, '../src/old-components'),
          path.resolve(__dirname, '../src/deprecated'),
        ],
        use: [
          {
            loader: require.resolve('@storybook/addon-storysource/loader'),
            options: {
              prettierConfig: {
                parser: 'babylon',
              },
              uglyCommentsRegex: [/^::/],
            },
          },
        ],
        enforce: 'pre',
      },
@igor-dv
Copy link
Member

igor-dv commented Dec 8, 2018

Storysource is dependant on parsers from Prettier and works now with prettier/parser-babylon and prettier/parser-typescript. For Flow they have a prettier/parser-flow.

It's very easy to add a support for this, would you like to create a PR ?

@Nemvts
Copy link
Author

Nemvts commented Dec 11, 2018

@igor-dv Babel v7 seems to now support Flow syntax so maybe this is not actually needed, but PR #4971 has been created to add support for Flow as an option.

For Reference

@igor-dv
Copy link
Member

igor-dv commented Dec 11, 2018

babel supported Flow before as well (IMO), but the current implementation is not relying on babel directly

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

No branches or pull requests

3 participants
@Nemvts @igor-dv and others