Open jackbsteinberg opened 5 years ago
Solutions discussed:
First, refactor all codemods so that you never replace the parent node. This might magically solve the problem, depending on the implementation details of ts-morph's forEachDescendant().
If that does not solve the problem, then implement our own depth-first postorder traversal to replace forEachDescendant(). This depends on the previous step; a depth-first postorder traversal will fail badly if we're replacing the parents of nodes that are in the process of being traversed.
This may be more complicated than just applying the transforms recursively, because the first transform could cause a loss of type information. See https://github.com/jackbsteinberg/get-originals-rewriter/issues/35#issuecomment-522652550 for a similar issue and a proposed solution.
Currently when the rewriter encounters nested accessors and methods it will only convert the outermost to its original:
This is possibly because parents of observed nodes are being rewritten, which prevents the algorithm from continuing to inspect and properly rewrite all the children.