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

Invalid JS generated under a certain TS export. Uses default reserved word #57

Open
rally25rs opened this issue Oct 22, 2021 · 0 comments · Fixed by styleguidist/react-docgen-typescript#411

Comments

@rally25rs
Copy link

Given the file test.tsx

import React from 'react';

export class Column extends React.Component {}

export default function Test() {
  return <span>hi</span>;
}
Test.Column = Column;

I get invalid generated code:

try {
    // @ts-ignore
    default.Column.displayName = "default.Column";
    // @ts-ignore
    default.Column.__docgenInfo = { "description": "", "displayName": "default.Column", "props": {} };
    // @ts-ignore
    if (typeof STORYBOOK_REACT_CLASSES !== "undefined")
        // @ts-ignore
        STORYBOOK_REACT_CLASSES["components/virtualized-table/test.tsx#default.Column"] = { docgenInfo: default.Column.__docgenInfo, name: "default.Column", path: "components/virtualized-table/test.tsx#default.Column" };
}

It is for some reason using default.Column but default is a JS reserved word, so this results in a syntax error Uncaught SyntaxError: expected expression, got keyword 'default'


I can fix this by changing my TS to:

import React from 'react';

export class Column extends React.Component {}

function Test() {
  return <span>hi</span>;
}
Test.Column = Column;

export default Test;

It seems like the order of the export matters in relation to the Test.Column = Column assignment 😕


Versions:

└─ @storybook/[email protected]
└─ @storybook/[email protected]
└─ [email protected]

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

Successfully merging a pull request may close this issue.

1 participant