-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
5c0357b
to
05e4e69
Compare
05e4e69
to
e096071
Compare
Netlify deploy previewhttps://deploy-preview-38517--material-ui.netlify.app/ Bundle size report |
1b17451
to
50e64e6
Compare
50e64e6
to
b7d18f5
Compare
7581015
to
7191668
Compare
*/ | ||
onOpen: PropTypes.func.isRequired, | ||
/** | ||
* If `true`, the component is shown. | ||
* @default false | ||
*/ | ||
open: PropTypes.bool.isRequired, |
There was a problem hiding this comment.
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 | |||
|
There was a problem hiding this comment.
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...
typescript-to-proptypes
to share the AST parsing with parseStyles
7191668
to
a3c51c6
Compare
c00cf3a
to
8274555
Compare
@@ -3,15 +3,21 @@ | |||
"onClose": { | |||
"type": { "name": "func" }, | |||
"required": true, | |||
"signature": { "type": "function(event: object) => void", "describedArgs": ["event"] } | |||
"signature": { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Do you have some specific project in mind? (I assume you do not go into those AST just for pleasure 😁) |
I plan to rebuild |
@@ -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": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} | ||
// x = React.memo((props:type) { return <div/> }) | ||
// x = React.forwardRef((props:type) { return <div/> }) | ||
if (ts.isCallExpression(node.initializer) && node.initializer.arguments.length > 0) { |
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it does 👌
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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<...>
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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... |
💯 agree. I think @oliviertassinari is the only offender here ;) |
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
andtypescript-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.