This reverts the previous changes to handling labels so that all tests can pass.
This passes all false postivies found in `monitor-oxc` (node_modules/flow-parser/flow_parser.js)
As it turns out this requires less code and produces better diagnostics.
Part of #5008. Make scopes for `ForStatement`, `ForInStatement` and `ForOfStatement` unconditional. i.e. always create a scope, even if there is no lexical binding (e.g. `for (i of a) {}`).
Transform checker check root unresolved references.
The transform checker is now checking pretty much everything it can.
Only fields of `ScopeTree` and `SymbolTable` that it's *not* checking are those which contain `AstNodeId`s, because transformer does not create node IDs at present:
* `ScopeTree::node_ids`
* `SymbolTable::declarations`
* `Reference::node_id`
Checking also only proceeds in "from AST" direction.
i.e. for each `SymbolId` which appears in the AST, we check everything about that symbol. But we *don't* go through all the "rows" in `SymbolTable` and check if there are any extra symbols in the table which aren't in the AST.
Presumably transformer will leave a lot of old symbols lying around in `SymbolTable` (ditto scopes and references). We'd need to add `ScopeFlags::Deleted`, `SymbolFlags::Deleted` and `ReferenceFlags::Deleted` for the transformer to be able to "delete" existing symbols.
Previously was checking that references point to symbols with same name, but not necessarily the same symbol (there could be 2 different symbols with same name).
Pure refactor of transform checker. Store all scope data in `PostTransformChecker` so it doesn't need to be passed around. `SemanticData` contains a full set of all semantic data for semantic pass, so we have 2 instances of it for 1. after transform and 2. rebuilt semantic.
Transformer checker use `SemanticIds` to store collected IDs. `SemanticIds` only contains the IDs, without the `Vec` of errors which is only used temporarily.
closes https://github.com/oxc-project/oxc/issues/4790
@overlookmotel enjoy ... take a look at the snapshots and probably nothing else.
The snapshots are minimal right now, but it's already showing symbols from import specifiers are not being removed. We can iterate on the snapshot representation to aid debugging later.
I'll extend this to `transformer_conformance` and `oxc-monitor` in an up coming PR.
close: #4870
I added the `move_identifier_reference` and `move_member_expression` methods used to take ownership in `ast_builder_impl`. This way can let us get rid of `ast.copy`.
Another possible approach is to add `get_expression_owner` to `SimpleAssignmentTarget` and a `get_inner_expression_owner` method to `Expression`. And add an `into_xxxxx` method for `inherit_variants` macro
The implementation looks like this
```rs
let Some(expression) = self.get_expression_owner() else { return; }
match expr.get_inner_expression_owner() {
Expression::Identifier(ident) => {
*target = self.ctx.ast.simple_assignment_target_from_identifier_reference(ident);
}
inner_expr @ match_member_expression!(Expression) => {
*target = SimpleAssignmentTarget::from(
inner_expr.into_member_expression()
);
}
_ => (),
}
```
After studying google closure compiler, I'm leaning towards a multi-ast-pass infrastructure for the minifier.
This is one of the few places where we are going to trade maintainability over performance, given the goal of the minifier is compression size not performance.
All of the terminologies and separation of concerns are aligned with google closure compiler.
Infrastructure of `terser` and `esbuild` are not suitable for us to study nor pursuit. Their code are so tightly coupled - I failed to comprehend any of them every time I try to walk through a piece of optmization. Google closure compiler despite being written in Java, it's actually the most readable minifier out there.
To improve performance between ast passes, I envision a change detection system over a portion of the code.
The benchmark will demonstrate the performance regression of running 5 ast passes instead of 2.
To complete this PR, I need to figure out "fix-point" and order of these ast passes.