Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react_refresh: Rewrite main loop (#38)
* 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