-
Notifications
You must be signed in to change notification settings - Fork 516
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
defaultProps: default function type is lost #847
Comments
In function parseJsx, babel output no
|
The positioning problem is probably in the function And Am I right ? |
Correct, we are using I will provide some more details soon on how this can be accomplished |
Steps to handle functions in Update
|
component.defaultProps = { | |
...(component.defaultProps ?? {}), | |
[i.key?.name]: i.value.value, | |
}; |
component.defaultProps = {
...(component.defaultProps ?? {}),
[i.key?.name]: { type: 'property', code: `i.value.value` },
};
3- Now update all uses of defaultProps
in generators to use the code
property. TypeScript will help point out where you need to do that.
Store functions by generating string
1- update the parseDefaultPropsHook
function to process the code
const value = i.value.value;
if (types.isFunctionExpression(value) || types.isArrowFunctionExpression(value)) {
const code = generate(firstArg.body)
.code.trim()
// Remove arbitrary block wrapping if any
// AKA
// { console.log('hi') } -> console.log('hi')
.replace(/^{/, '')
.replace(/}$/, '');
return { type: 'method', code }
} else {
return { type: 'property', code: value }
}
2- I think this should work out of the box for simple cases. It will not yet handle props.
and state.
references inside of it,, but we can leave that as a follow-up as it will require a bunch more work.
I follow up. |
* fix(core): defaultProps function type #847 * fix(core): svelte default props * test(core): update snapshots * test: update snapshots * fix: remove manually adding } * feat: remove useless trim * refactor: use parseStateObjectToMitosisState parseDefaultProps * fix: remove useless import
I am interested in helping provide a fix!
Yes
Which generators are impacted?
Reproduction case
https://mitosis.builder.io/?outputTab=G4VwpkA%3D&code=JYWwDg9gTgLgBAbzgVwM4FMDKNroDQoYAi6AZgIbIA2MAClBGKnAL5ykMhwDkAAgEbJgVACbooAOmAQA9CGA5UwVNwDcAKHXAAdjHEUAxujgAhZDBzb6jZgnVw4SgF7oAXI5hQdAcw0ORyuT8VOgi7vwQECHk2n5wENoAwlTABgDW7gAUbnAxAJ4AlHAAvAB8cABuEMAiGiya6AAekLBwYhTU8KTI2gYw0tqm5paZYAxM7mYWCdZMRXYOaOgkHTSzqAA8U5brpZkLDo7ALu7cIKHAyCDcePaHAahBIWHs5FQYt4fxSSnpWUVlRAsAgyGRwHAiCDsYCNODyRTKOAGCDgYTGbSRMDgqEIeoOFgFDR3KDoGDIKCDTJ3BwbQTTbTUw4JZKpNLFBDZCroXQA8qZACEYxsEgeT1CcAA%2FHAhUwJMzfmlOdyYEV3D12jpQgU8YdSoyHNsEoyNjI6ZY9Q5Cep6kA%3D
Expected Behaviour
onClick
default value should be() => {}
, but vue got{}
, react got lost.vue
react
Actual Behaviour
vue
react
Additional Information
No response
The text was updated successfully, but these errors were encountered: