|
1 | 1 | use swc_common::{SyntaxContext, DUMMY_SP}; |
2 | 2 | use std::collections::{HashSet, HashMap}; |
3 | 3 | use swc_ecma_ast::*; |
4 | | -use swc_ecma_visit::{VisitMut, VisitMutWith}; |
| 4 | +use swc_ecma_visit::{VisitWith, VisitMut, VisitMutWith}; |
5 | 5 |
|
6 | 6 | use crate::utils::ast_helpers::*; |
7 | 7 | use crate::utils::scope_analyzer::ScopeAnalyzer; |
@@ -2247,11 +2247,11 @@ mod tests { |
2247 | 2247 |
|
2248 | 2248 | #[test] |
2249 | 2249 | fn test_export_aliased_var() { |
2250 | | - // Babel: 'var x = 23; export { x as y };' → '_rec.x = 23; var x = _rec.x; export { x as y };' |
| 2250 | + // 'var x = 23; export { x as y };' → captures x, renames export local to __export_y__ |
2251 | 2251 | let output = transform_code("var x = 23; export { x as y };"); |
2252 | 2252 | assert!(output.contains("__varRecorder__.x = 23;"), "captures local var with value: {}", output); |
2253 | | - assert!(output.contains("var x = __varRecorder__.x;"), "re-declares var from recorder: {}", output); |
2254 | | - assert!(output.contains("export { x as y }"), "keeps aliased export: {}", output); |
| 2253 | + assert!(output.contains("var __export_y__ = __varRecorder__.x;"), "re-declares with __export_ prefix: {}", output); |
| 2254 | + assert!(output.contains("export { __export_y__ as y }"), "keeps aliased export with renamed local: {}", output); |
2255 | 2255 | } |
2256 | 2256 |
|
2257 | 2257 | #[test] |
@@ -2899,11 +2899,11 @@ mod tests { |
2899 | 2899 |
|
2900 | 2900 | #[test] |
2901 | 2901 | fn babel_export_aliased_var_statement() { |
2902 | | - // Babel: 'var x = 23; export { x as y };' |
| 2902 | + // 'var x = 23; export { x as y };' → captures x, renames export local to __export_y__ |
2903 | 2903 | let output = transform_code("var x = 23; export { x as y };"); |
2904 | 2904 | assert!(output.contains("__varRecorder__.x = 23;"), "captures x with value: {}", output); |
2905 | | - assert!(output.contains("var x = __varRecorder__.x;"), "re-declares var from recorder: {}", output); |
2906 | | - assert!(output.contains("export { x as y }"), "keeps aliased export: {}", output); |
| 2905 | + assert!(output.contains("var __export_y__ = __varRecorder__.x;"), "re-declares with __export_ prefix: {}", output); |
| 2906 | + assert!(output.contains("export { __export_y__ as y }"), "keeps aliased export with renamed local: {}", output); |
2907 | 2907 | } |
2908 | 2908 |
|
2909 | 2909 | #[test] |
@@ -3291,7 +3291,7 @@ mod tests { |
3291 | 3291 | // Babel puts __module_exports__ near the top (after recorder init), |
3292 | 3292 | // not at the end of the module body |
3293 | 3293 | let output = transform_code_resurrection("export var x = 23; var y = 42;"); |
3294 | | - let recorder_pos = output.find("recorderFor").expect("has recorder init"); |
| 3294 | + let recorder_pos = output.find("moduleEnv").expect("has recorder init"); |
3295 | 3295 | let module_exports_pos = output.find("__module_exports__").expect("has module_exports"); |
3296 | 3296 | let last_assignment_pos = output.rfind("__varRecorder__").expect("has assignments"); |
3297 | 3297 | assert!(module_exports_pos < last_assignment_pos, |
@@ -3466,7 +3466,7 @@ mod tests { |
3466 | 3466 | // The hoisted let declarations must come AFTER the recorder init and __moduleMeta__, |
3467 | 3467 | // but BEFORE other code |
3468 | 3468 | let output = transform_code_resurrection("var x = 1; function foo() {}"); |
3469 | | - let recorder_pos = output.find("recorderFor").expect("has recorder init"); |
| 3469 | + let recorder_pos = output.find("moduleEnv").expect("has recorder init"); |
3470 | 3470 | let meta_pos = output.find("__moduleMeta__").expect("has module meta"); |
3471 | 3471 | let let_foo_pos = output.find("var foo").expect("has var foo"); |
3472 | 3472 | let var_x_pos = output.find("__varRecorder__.x").expect("has var x"); |
|
0 commit comments