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

Resolve issue with first displayName always being used #449

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kylemh
Copy link
Contributor

@kylemh kylemh commented Sep 17, 2022

Fixes: #395
Fixes: #437
Redo of #441

I basically did the fix outlined in #437 by @jesstelford and added some tests.

✅ Tests pass now 🥳

I also made it so that CI runs on each PR push.

Comment on lines +1204 to +1208
const locals = Array.from(
(source as any).locals as [string, ts.Symbol][]
);
const hasOneLocalExport =
locals.filter(local => !!local[1].exports).length === 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't certain about this, but it did seem to resolve the one failing test I was dealing with.

Specifically: 'should be taken from stateless component displayName property (using default export) even if file name doesn't match'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvasek @jesstelford curious on any input here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produced false-negatives in my scenario. I presume because there is only one with displayName, it was ignoring the others.

Copy link
Contributor Author

@kylemh kylemh Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMoo-Miki If you log exports there, what's the output?

@kylemh
Copy link
Contributor Author

kylemh commented Sep 17, 2022

Also, @unicornware since I saw you depending on these changes in flex-development/vite-plugin-react-docgen-typescript#4, I just wanted you to be made aware of this PR.

istarkov added a commit to webstudio-is/webstudio that referenced this pull request Jul 18, 2023
## Description

Allow multiple exports in components. Most radix components will look
like
`export const Tooltip = TooltipPrimitive.Root;`

The others would be a simpe wrappers over radix with just type changes
like like `Omit<TriggerProps, "className">

It's too much to create for each sucj export a standalone file.

After this PR following will work.

```ts
import * as TooltipPrimitive from "@radix-ui/react-tooltip";

export const Tooltip = TooltipPrimitive.Root;
export const TooltipTrigger = TooltipPrimitive.Trigger;
```

Generated exports in case of multiple entries are

```
export propsTooltip: ...
export propsTooltipTrigger ....
```

In case of single export previous behaviour is preserved for now, but
should be changed IMO in the future PRs


Known bugs

Until this merged we should not use displayName (have no idea why we use
it at all) in files with multiple exports
styleguidist/react-docgen-typescript#449

As of now will add comments
```
import * as TooltipPrimitive from "@radix-ui/react-tooltip";

export const Tooltip = TooltipPrimitive.Root;
// We can't use .displayName until this is merged styleguidist/react-docgen-typescript#449
// Tooltip.displayName = "Tooltip";

export const TooltipTrigger = TooltipPrimitive.Trigger;
// We can't use .displayName until this is merged styleguidist/react-docgen-typescript#449
// TooltipTrigger.displayName = "TooltipTrigger";
```


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio-builder/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
@github-actions
Copy link

There was no activity for a long time. The PR will be closed soon.

@github-actions github-actions bot added the stale There is no activity for a long time. label Sep 18, 2023
@kylemh
Copy link
Contributor Author

kylemh commented Sep 18, 2023

Go away, bot.

@github-actions github-actions bot removed the stale There is no activity for a long time. label Sep 19, 2023
@olliethedev
Copy link

would love to see these fixed merged in 🙏

@kylemh
Copy link
Contributor Author

kylemh commented Sep 18, 2024

@pvasek let me know if there's anything more you'd like to have done here!

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 this pull request may close these issues.

Support files with multiple functions and one .displayName Invalid displayName parsing starting with v2.1.0
3 participants