Commit e07cc5c
authored
[turbopack] Refactor the analyzer to fix a few issues and prepare to split it up (#86265)
# Refactor Analyzer State Management in Turbopack
This PR refactors the state management in the Turbopack ECMAScript analyzer to improve code organization and maintainability. The changes include:
- Introduced a `LexicalContext` enum to track the current execution context (function, module, control flow) and remove most dependencies on AstPath
- Moved early return stack and variable declaration kind into the `AnalyzerState` struct
- Added helper methods for entering and exiting different block types
- Improved handling of nested blocks and control flow
- Fixed unreachable code detection in anonymous blocks which allows us to drop some redundant unreachable effects from loops
- Handle more cases for nested `var` declarations
These refactorings are all either fixing minor issues or regularizing state management. This is preparation for splitting this AST traversal into two pieces.1 parent 5b62dd8 commit e07cc5c
File tree
26 files changed
+1138
-864
lines changed- turbopack/crates
- turbopack-ecmascript
- src
- analyzer
- tests/analyzer/graph
- react-dom-production
- this-binding
- unreachable-break
- unreachable
- webpack-target-node
- turbopack-tests/tests/snapshot/comptime/early-return
- input
- output
26 files changed
+1138
-864
lines changedLines changed: 422 additions & 297 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
Lines changed: 19 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2843 | 2843 | | |
2844 | 2844 | | |
2845 | 2845 | | |
2846 | | - | |
| 2846 | + | |
2847 | 2847 | | |
2848 | 2848 | | |
2849 | 2849 | | |
| |||
3230 | 3230 | | |
3231 | 3231 | | |
3232 | 3232 | | |
3233 | | - | |
| 3233 | + | |
3234 | 3234 | | |
3235 | 3235 | | |
3236 | 3236 | | |
| |||
3454 | 3454 | | |
3455 | 3455 | | |
3456 | 3456 | | |
| 3457 | + | |
3457 | 3458 | | |
3458 | 3459 | | |
3459 | 3460 | | |
| |||
3687 | 3688 | | |
3688 | 3689 | | |
3689 | 3690 | | |
3690 | | - | |
| 3691 | + | |
3691 | 3692 | | |
3692 | 3693 | | |
3693 | 3694 | | |
| |||
4228 | 4229 | | |
4229 | 4230 | | |
4230 | 4231 | | |
4231 | | - | |
| 4232 | + | |
4232 | 4233 | | |
4233 | 4234 | | |
4234 | 4235 | | |
| |||
4241 | 4242 | | |
4242 | 4243 | | |
4243 | 4244 | | |
4244 | | - | |
| 4245 | + | |
4245 | 4246 | | |
4246 | 4247 | | |
4247 | 4248 | | |
| |||
4287 | 4288 | | |
4288 | 4289 | | |
4289 | 4290 | | |
4290 | | - | |
| 4291 | + | |
4291 | 4292 | | |
4292 | 4293 | | |
4293 | 4294 | | |
4294 | 4295 | | |
4295 | 4296 | | |
4296 | | - | |
| 4297 | + | |
4297 | 4298 | | |
4298 | 4299 | | |
4299 | 4300 | | |
| |||
4357 | 4358 | | |
4358 | 4359 | | |
4359 | 4360 | | |
4360 | | - | |
| 4361 | + | |
4361 | 4362 | | |
4362 | 4363 | | |
4363 | 4364 | | |
| 4365 | + | |
4364 | 4366 | | |
4365 | 4367 | | |
4366 | 4368 | | |
| |||
4491 | 4493 | | |
4492 | 4494 | | |
4493 | 4495 | | |
4494 | | - | |
| 4496 | + | |
4495 | 4497 | | |
4496 | 4498 | | |
4497 | 4499 | | |
| |||
4619 | 4621 | | |
4620 | 4622 | | |
4621 | 4623 | | |
4622 | | - | |
| 4624 | + | |
4623 | 4625 | | |
4624 | 4626 | | |
4625 | 4627 | | |
4626 | | - | |
| 4628 | + | |
4627 | 4629 | | |
4628 | 4630 | | |
4629 | 4631 | | |
| 4632 | + | |
4630 | 4633 | | |
4631 | 4634 | | |
4632 | 4635 | | |
| |||
4644 | 4647 | | |
4645 | 4648 | | |
4646 | 4649 | | |
4647 | | - | |
| 4650 | + | |
4648 | 4651 | | |
4649 | 4652 | | |
4650 | 4653 | | |
| |||
4687 | 4690 | | |
4688 | 4691 | | |
4689 | 4692 | | |
4690 | | - | |
| 4693 | + | |
4691 | 4694 | | |
4692 | 4695 | | |
4693 | 4696 | | |
| 4697 | + | |
4694 | 4698 | | |
4695 | 4699 | | |
4696 | 4700 | | |
| |||
4776 | 4780 | | |
4777 | 4781 | | |
4778 | 4782 | | |
4779 | | - | |
| 4783 | + | |
4780 | 4784 | | |
4781 | 4785 | | |
4782 | 4786 | | |
| |||
4959 | 4963 | | |
4960 | 4964 | | |
4961 | 4965 | | |
| 4966 | + | |
4962 | 4967 | | |
4963 | 4968 | | |
4964 | 4969 | | |
| |||
0 commit comments