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

Fix visibleName with dots #1675

Merged
merged 3 commits into from Sep 3, 2020

Conversation

Lazyuki
Copy link
Contributor

@Lazyuki Lazyuki commented Sep 2, 2020

Fixes: styleguidist/react-docgen-typescript#292

With react-docgen-typescript's version 1.20.4, components with @visibleName JSDoc tags are working. However, it changes the react component's displayName to the one specified in @visibleName, and when it contains a ., the code examples were not working. This was because Styleguidist was trying to import the component with the dot in its name in the code example which resulted in the syntax error.

Example:

// ===== DialogTitle.tsx ======
/**
 * @visibleName Dialog.Title
 */
export const DialogTitle = props => (<h2 {...props} />);

// ===== Dialog.tsx ======
import DialogTitle from './DialogTitle.tsx';
const Dialog = ({ children }) => <div>{children}</div>;
Dialog.Title = DialogTitle;
export default Dialog;

This caused Styleguidist to try

const Dialog.Title$0 = require('./DialogTitle.tsx');

in the example code renderer, which resulted in SyntaxError: Missing initializer in const declaration.

@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #1675 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
src/loaders/utils/resolveESModule.ts 100.00% <100.00%> (ø)

@311chaos
Copy link

311chaos commented Sep 2, 2020

I had this issue come up, but with different characters. I had visible names with hyphens or commas that also stopped working.

@Lazyuki
Copy link
Contributor Author

Lazyuki commented Sep 2, 2020

Oh I didn't expect those characters to be in @visibleName, but I guess that's possible. I can modify this to exclude all non-alphabetical characters.

@sapegin sapegin merged commit e637f53 into styleguidist:master Sep 3, 2020
@sapegin
Copy link
Member

sapegin commented Sep 3, 2020

Thanks!

@styleguidist-bot
Copy link
Collaborator

🎉 This PR is included in version 11.0.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Missing initializer in const declaration error when using @visibleName
4 participants