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

react_refresh: Rewrite main loop #38

Merged
merged 6 commits into from
Sep 3, 2024
Merged

Conversation

martinhath
Copy link
Contributor

@martinhath martinhath commented Aug 6, 2024

This turned into an all-in-one commit:

The largest change is the fact that we perform most of the work directly
in the visitor functions. For applicable calls to atom (and friends)
we replace the CallExpr right then and there. This makes it so that
we don't need to deal with export handling, or accidentally replace
entire expressions with erroneous cached atoms (See e.g. the failing
test in #36). This also solves other open issues, like #26 , #34 , and #35 .

Fixes #26
Fixes #34
Fixes #35


I built this on top of #37, but I suppose technically speaking that's not necessary. This is a pretty large change, so if you think this is a direction to pursue it might make sense to rethink that change in the context of this anyways.

There's still some cleanup I can do, and probably a bunch of edge cases I've missed. I intend to look at these next.

Since atoms created in a function context are new atoms, there's
nothing in the arrow function sub-tree that we should transform. The
default behavior seems to be to visit everything, whereas an empty impl
stops the walk.

Another driveby fix: store previous `top_level` in `visit_mut_stmts`
instead of always resetting it to `true`.  I don't have a failing test
for this (so it might be fine), but it's a pattern that's explicitly
called out in the docs [0].

[0]: https://swc.rs/docs/plugin/ecmascript/cheatsheet#make-your-handlers-stateless

Fixes pmndrs#36
This turned into an all-in-one commit:

 * Move the logic to the `visit_mut_*` functions from VisitMut.
 * Make atom key names more flexible to support e.g. pmndrs#26

The largest change is the fact that we perform most of the work directly
in the visitor functions.  For applicable calls to `atom` (and friends)
we replace the `CallExpr` right then and there.  This makes it so that
we don't need to deal with `export` handling, or accidentally replace
entire expressions with erroneous cached atoms (See e.g. the failing
test in pmndrs#36).  This also solves other open issues, like pmndrs#26, pmndrs#34, and pmndrs#35.

Fixes pmndrs#26
Fixes pmndrs#34
Fixes pmndrs#35
@Thisen
Copy link
Collaborator

Thisen commented Aug 29, 2024

This is cool @martinhath.

I have merged the previous PR. Could you rebase this PR and cleanup the comments, etc.?

I'll take a look then. Thanks.

@Thisen Thisen merged commit b608508 into pmndrs:main Sep 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants