Open cadamsdev opened 1 year ago
Ah. I think that's because we haven't improved our state.
prefix replacement logic to be better than just a regex.
Workaround is to call it something other than state
. Fixing it will require replacing this:
with a babel transform. Will try to write up how soon
Workaround is to call it something other than
state
. Fixing it will require replacing this:
In my scenario I don't have control over that because this object is provided by a 3rd party library see here
Gotcha. Then we'll definitely need to fix this.
What we want is replaceIdentifiers
: https://github.com/BuilderIO/mitosis/blob/ebee81104cea791a08896a578800b339a8397201/packages/core/src/helpers/replace-identifiers.ts#L24-L35
But the problem is that replaceIdentifiers
does not allow you to complete remove state.
without replacing it with something. We have to provide a replacement. So we need to update that function so that it doesn't need to do that:
Identifier
nodes, it needs to check for the parent, which is a MemberExpression
nodeMemberExpression
node (otherwise we will replace cases like obj.state.foo
)object
property of the MemberExpression
has a value that matches our from
, then:
to
exists, we do what we currently do (replace the object
property with a new babel.identifier
with the new value)to
is undefined
, then we replace the whole parent MemberExpression
with its property
this AST explorer is very helpful to visualize this better: https://astexplorer.net/#/gist/4528525361ba7f6a4c7ecf12b6a70878/189cadebfe99437196acc5d8339709489cc6496f
I am interested in helping provide a fix!
Yes
Which generators are impacted?
Reproduction case
https://mitosis.builder.io/?outputTab=E4UwhgxgLkA%3D&code=KYDwDg9gTgLgBAE2AMwIYFcA29noHYDGMAlhHnALICeAwhALaR7B4wAUYUEYAzgJRwA3gChhcOLkIkyE%2FEQCMbHg2AB5AEYArASPHiA9PrgR0MMKbjEecelZ7E8AczgA6HjFQxgYvQTLu4MExUAmB6FngAXjhlcI1NNw8vFyCQsIiAbh8AX1FxSSJScgKYACYlFXidHwMjAHdoAGtULnwEGrg%2FPADY4ABlJOA4aN74xM9gLL1O%2F3hU0PDWYZiVAYmU4IXMnLy4KGAYdChyNg6AHgRiADc4fQA%2BHz4s7KA%3D%3D%3D
Expected Behaviour
When there's a javascript object structured like this e.g
mitosis code
should keep "state" in the output
e.g react
Actual Behaviour
mitosis
outputs (react)
Additional Information
There is a workaround which is to do this
mitosis
react
This seems to be an issue with all outputs (I see this same issue with angular as well)