Closed trusktr closed 10 months ago
Yeah seems like this
is pushed in the wrong scope.
This is the culprit. The workaround could be to find the nearest function or block parent, and then move the declaration there.
Why do we need a declaration? Why not leave this
as-is considering that the output's wrapper is also an arrow function?
@trusktr It's to protect reactive properties from accessing the props object.
For example:
<Div title={this.title} />
// if preserved
createComponent(Div, {
get title() {
return this.title; // recursive
},
});
Reproduction:
https://playground.solidjs.com/anonymous/ab9e79a2-8bb0-4e1d-96cd-f55b12d0242e
A workaround is to avoid arrow functions, here with a regular method:
https://playground.solidjs.com/anonymous/e80be486-0bc4-4512-b4d0-c1dad21ee863
The transform is replacing
this
with a variable that grabsthis
from somewhere unrelated to the code, f.e. like so:At the top level of a module,
this
isundefined
.