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

[core] Rework typescript-to-proptypes to share the AST parsing with parseStyles #38517

Merged
merged 9 commits into from
Sep 4, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Aug 17, 2023

I'm diverging from the API exposed by the original typescript-to-proptypes API.
Why ? Because we now have quite a lot of tooling that rely on the typescript AST, and the typescript-to-proptypes has a lot of interesting we could not use because it was totally independent of the rest.

@michaldudak @alexfauquette , I am not sure where the code used both by parseStyle and typescript-to-proptypes (and other codes in the future) should live.
For example, createTypeScriptProject will be used by X.

I'll propose some evolution on the API of those methods to share more logic with X later.

@flaviendelangle flaviendelangle self-assigned this Aug 17, 2023
@flaviendelangle flaviendelangle added the core Infrastructure work going on behind the scenes label Aug 17, 2023
@mui-bot
Copy link

mui-bot commented Aug 17, 2023

Netlify deploy preview

https://deploy-preview-38517--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 5920e67

@flaviendelangle flaviendelangle force-pushed the rework-ttp branch 2 times, most recently from 1b17451 to 50e64e6 Compare August 17, 2023 13:07
@flaviendelangle flaviendelangle force-pushed the rework-ttp branch 6 times, most recently from 7581015 to 7191668 Compare August 18, 2023 12:29
*/
onOpen: PropTypes.func.isRequired,
/**
* If `true`, the component is shown.
* @default false
*/
open: PropTypes.bool.isRequired,
Copy link
Member Author

Choose a reason for hiding this comment

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

This fix is correct

@@ -56,6 +56,7 @@ const OuterElementType = React.forwardRef((props, ref) => {
});

// Adapter for react-window

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea where this white line is coming from...

@flaviendelangle flaviendelangle changed the title [core] Rework typescript-to-proptypes [core] Rework typescript-to-proptypes to share the AST parsing with parseStyles Aug 18, 2023
@@ -3,15 +3,21 @@
"onClose": {
"type": { "name": "func" },
"required": true,
"signature": { "type": "function(event: object) => void", "describedArgs": ["event"] }
"signature": {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why the parsing is better now 😆

@@ -86,22 +86,22 @@ Hidden.propTypes /* remove-proptypes */ = {
*/
initialWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
/**
* If `true`, component is hidden on screens below (but not including) this size.
Copy link
Member Author

Choose a reason for hiding this comment

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

Those new descriptions are the right one from the type definition 🤔

@@ -319,7 +325,7 @@ function plugin(
if (!node.id) {
return;
}
const props = propTypes.body.find((prop) => prop.name === node.id!.name);
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know why the return format of the parser was this ast.body format, but I find the new one a lot easier to read.

@alexfauquette
Copy link
Member

For example, createTypeScriptProject will be used by X.

Do you have some specific project in mind? (I assume you do not go into those AST just for pleasure 😁)

@flaviendelangle flaviendelangle marked this pull request as ready for review August 21, 2023 09:44
@flaviendelangle
Copy link
Member Author

Do you have some specific project in mind?

I plan to rebuild getTypeScriptProjects to be a superset of this method, so that I can pass the X typescript projects to any shared method and have it work.

docs/translations/api-docs/hidden/hidden.json Outdated Show resolved Hide resolved
@@ -39,5 +39,57 @@
"description": "The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object."
}
},
"classDescriptions": {}
"classDescriptions": {
Copy link
Member

Choose a reason for hiding this comment

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

👍

packages/api-docs-builder/utils/createTypeScriptProject.ts Outdated Show resolved Hide resolved
packages/api-docs-builder/utils/createTypeScriptProject.ts Outdated Show resolved Hide resolved
}
// x = React.memo((props:type) { return <div/> })
// x = React.forwardRef((props:type) { return <div/> })
if (ts.isCallExpression(node.initializer) && node.initializer.arguments.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

We also have React.memo(React.forwardRef(...)) (Base UI's Option), but since there are no changes in generated files, I assume it works fine 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess it does 👌

Copy link
Member

Choose a reason for hiding this comment

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

@flaviendelangle, it looks like it doesn't after all. While working on #36287, I changed the wording of the PropTypes warning message and noticed that it was not updated on some components.
The affected components are:

  • base/Option
  • base/Portal
  • base/TextareaAutosize
  • joy/Box
  • lab/Timeline
  • material-next/SliderRoot
  • material-next/SliderRail
  • material-next/SliderTrack
  • material-next/SliderThumb
  • material-next/SliderValueLabel
  • material-next/SliderMark
  • material-next/SliderMarkLabel
  • material/Popper
  • material/SliderRoot
  • material/SliderRail
  • material/SliderTrack
  • material/SliderThumb
  • material/SliderValueLabel
  • material/SliderMark
  • material/SliderMarkLabel

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we agree that the previous version did not handle this scenario as well ?
If so, I can have a look on how to improve the new one 👍

Copy link
Member

Choose a reason for hiding this comment

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

Partially. For example, base/Option did not work correctly before, but joy/Box was fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

For base/Option, the injector did not handler nested wrapper function list memo(forwardRef(...)), I have a working fix.

For joy/Box, I'm investigating

Copy link
Member Author

Choose a reason for hiding this comment

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

For joy/Box, I was returning too soon so all the createX were probably broken at the parsing phase

Copy link
Member Author

@flaviendelangle flaviendelangle Sep 6, 2023

Choose a reason for hiding this comment

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

For base/Portal (and probably others) we don't support correctly the as React.ForwardRefExoticComponent<...>

Copy link
Member Author

@flaviendelangle flaviendelangle Sep 6, 2023

Choose a reason for hiding this comment

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

For SliderRoot and equivalent, I suspect that the proptypes have been written manually, because I see nothing in the code to generate the proptypes of styled(...)

While working to fix anotherbug, I enabled the proptypes of the styled by mistake so if we want we can do it, but right now they are never generated.

package.json Outdated Show resolved Hide resolved
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

Looks good to me (and most importantly, it works ;)). Please handle the failing CI check and it'll be good to go.

@flaviendelangle
Copy link
Member Author

I think this CI failure is caused by a71e6a0 which is not related at all to my PR.

By the way, I would find it great not to push commits without PRs as it often leads to this kind of problem...

@michaldudak
Copy link
Member

💯 agree. I think @oliviertassinari is the only offender here ;)

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 2, 2023
@oliviertassinari
Copy link
Member

I think this CI failure is caused by a71e6a0 which is not related at all to my PR.

Oops, #38758 will help.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 4, 2023
@flaviendelangle flaviendelangle merged commit f0af89f into mui:master Sep 4, 2023
@flaviendelangle flaviendelangle deleted the rework-ttp branch September 4, 2023 10:19
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Sep 8, 2023
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Sep 8, 2023
xcode-it pushed a commit to xcode-it/material-ui that referenced this pull request Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants