Closed kuizuo closed 11 months ago
Yeah that would be a nice improvement
And the above code should run before split-variable-declarations
The order mostly doesn't matter, babel requeues nodes after replacing/moving and all unminify visitors are merged into a single one. But applying it on exit instead of enter is required in many cases because the checks/matchers involve child nodes which other visitors could have modified.
I couldn't guarantee whether it was safe or not. This can cause variable names to be duplicated
I'd only handle var
to be safe, let
/const
have a lot of edge cases with scoping, for loops and closures.
For readability it should ignore normal for loops like for (var u = 0, v = o.length; u < v; u++) {
that have either node.test
or node.update
Wanna create a PR with these changes and a few simple test cases?
I noticed there is a test segment in the split-variable-declarations.test.ts file. I think we can implement this feature for a for loop in the split-variable-declarations.ts file.
Putting it in that file is fine
The purpose of this feature is as follows.
before
after
I've come across a piece of obfuscated code in which the
qt
identifier is the decoder. I think with this transform, the control-flow-switch can be handled better.At last, I tried to write a piece of visitor code, but I couldn't guarantee whether it was safe or not. This can cause variable names to be duplicated. And the above code should run before split-variable-declarations