Skip to content

Commit

Permalink
react_refresh: Rewrite main loop (#38)
Browse files Browse the repository at this point in the history
* react_refresh: Don't visit arrow function nodes

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 #36

* react_refresh: Rewrite main loop

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. #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 #36).  This also solves other open issues, like #26, #34, and #35.

Fixes #26
Fixes #34
Fixes #35

* Add test case for #35

* Improve docs for ReactRefreshTransformVisitor fields

* Replace "wat" placeholder
  • Loading branch information
martinhath authored Sep 3, 2024
1 parent 2bde4e9 commit b608508
Showing 1 changed file with 259 additions and 188 deletions.
Loading

0 comments on commit b608508

Please sign in to comment.