Follow up after #5673.
It's safer to compare nodes by pointer equality than by equality of `Span`s. Transformer can create multiple nodes of same type with same span.
Once nodes have node IDs, we can use them for comparison instead.
That said, `ptr::eq` is much cheaper, as it doesn't have to follow the pointers to check equality. https://godbolt.org/z/hsqaeKr5M
`get_unique_name` perform string manipulation faster, avoiding bounds checks, and use `itoa` crate for faster conversion of integers to strings for postfixes above 100.
No apparent difference on benchmarks, but I imagine that's only because it's outweighed by cost of hashing strings. If measured alone, I believe it would be a perf improvement.
Close#5488.
`generate_uid` previously iterated through every symbol and unresolved reference in the AST to find a unique var name. If the first var name it tried was already in use, it'd iterate again.
Instead build a hash map recording existing var names in use for every name which could clash with a UID (any var name starting with `_`). Once built, use that hash map to generate UIDs without iterating through all symbols again.
I had hoped to make `generate_uid` cheaper still by just recording the highest digits postfix for each var name, and then incrementing that postfix for each UID. i.e. if AST contains vars `_foo1` and `_foo6`, create UIDs starting at one number higher - `_foo7`, `_foo8` etc. This method would be more efficient, but unfortunately it does not match Babel, and so causes some of Babel's tests to fail.
Revert the changes to `oxc_traverse` made in #5577.
Those changes may well have been good, but...
The soundness of `Traverse` is a finely balanced thing, and the pointer gymnastics are subtle, so I think it's best to be extremely conservative about changes. I last ran Miri on it with the original formulation (`as *mut _` etc) and it passed. Currently it's not possible to usefully run Miri on the transformer because it contains known unsound code (#3483). So until we're able to check soundness with Miri, I think it's best to avoid changes, as it'd be easy to trigger UB unintentionally.
`just ast` panic due to
553262842c,
change the filename to makesure `ast_tool` still working
1. crates/oxc_span/src/source_type/types.rs is removed in
553262842c
This rule was implemented as a `run_once` method which just iterated over symbols. Implement using `run_on_symbol` instead to avoid the additional iteration.
`get_parent_es5_component` and `get_parent_es6_component` were always used together. Combine the two into a single function to only iterate over ancestors once, instead of twice.
`get_parent_es6_component` was finding *any* binding which is inside a class component, rather than parent of current node, leading to false positives.
The added test cases were not behaving correctly previously.