Skip to content

Commit f04e9ce

Browse files
kdy1claude
andcommitted
Port ES2022 modules to compat and implement VisitMut for CompatCompiler
This commit ports oxc's ES2022 transformer architecture to SWC's AST and Visitor API, implementing the VisitMut trait for CompatCompiler to enable composable transformations. ## Changes ### CompatCompiler - Implemented VisitMut trait with visitor methods for all relevant AST nodes - Added support for composable transformations by calling VisitMutHook instances - Transformations execute in order: TypeScript → Plugins → ES2026 → ES2021 → ES2020 → ES2019 → ES2018 → ES2017 → ES2016 → ES2015 → RegExp ### ES2022 Module - Ported class_static_block.rs from oxc to SWC - Transforms static blocks to private fields with IIFE - Implements VisitMutHook for composability - Includes comprehensive unit tests - Created stub implementation for class_properties - Full implementation requires ~7000 lines across 13 files - Documented implementation plan for incremental porting - Created ES2022 struct that combines class_static_block and class_properties ### TypeScript Support - Added `enabled()` method to TypeScriptOptions ### Code Quality - All changes pass `cargo clippy --all --all-targets -- -D warnings` - Formatted with `cargo fmt --all` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d77c19b commit f04e9ce

File tree

8 files changed

+893
-455
lines changed

8 files changed

+893
-455
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//! ES2022: Class Properties
2+
//!
3+
//! This module transforms class properties and private fields.
4+
//!
5+
//! ## Status
6+
//!
7+
//! This is currently a stub implementation. The full implementation requires
8+
//! porting approximately 7000 lines of code from oxc, including:
9+
//! - class.rs - Core class transformation logic (903 lines)
10+
//! - private_field.rs - Private field expression transformation (>1000 lines)
11+
//! - constructor.rs - Constructor injection logic (797 lines)
12+
//! - super_converter.rs - Super expression transformation (630 lines)
13+
//! - static_block_and_prop_init.rs - Static block and property transformation
14+
//! (550 lines)
15+
//! - prop_decl.rs - Property declaration transformation (391 lines)
16+
//! - class_details.rs - Class metadata and private property tracking (283
17+
//! lines)
18+
//! - instance_prop_init.rs - Instance property initializer transformation (231
19+
//! lines)
20+
//! - private_method.rs - Private method transformation (173 lines)
21+
//! - computed_key.rs - Computed property key handling (164 lines)
22+
//! - class_bindings.rs - Class name and temp var binding management (146 lines)
23+
//! - utils.rs - Utility functions (61 lines)
24+
//!
25+
//! ## Implementation Plan
26+
//!
27+
//! The porting work should be done incrementally:
28+
//! 1. Port utility modules first (utils.rs, class_bindings.rs,
29+
//! class_details.rs)
30+
//! 2. Then port transformation logic (prop_decl.rs, computed_key.rs, etc.)
31+
//! 3. Finally port complex transformations (private_field.rs, constructor.rs,
32+
//! class.rs)
33+
//! 4. Integration (mod.rs)
34+
35+
use swc_ecma_hooks::VisitMutHook;
36+
37+
use super::ClassPropertiesOptions;
38+
use crate::compat::context::TransformCtx;
39+
40+
/// Class properties transformer
41+
///
42+
/// This is currently a stub implementation that does nothing.
43+
/// The full implementation will handle:
44+
/// - Public class fields
45+
/// - Private class fields
46+
/// - Private methods
47+
/// - Static initialization blocks
48+
/// - Computed property keys
49+
pub struct ClassProperties<'ctx> {
50+
#[allow(dead_code)]
51+
options: ClassPropertiesOptions,
52+
#[allow(dead_code)]
53+
class_static_block: bool,
54+
#[allow(dead_code)]
55+
remove_class_fields_without_initializer: bool,
56+
#[allow(dead_code)]
57+
ctx: &'ctx TransformCtx,
58+
}
59+
60+
impl<'ctx> ClassProperties<'ctx> {
61+
#[allow(dead_code)]
62+
pub fn new(
63+
options: ClassPropertiesOptions,
64+
class_static_block: bool,
65+
remove_class_fields_without_initializer: bool,
66+
ctx: &'ctx TransformCtx,
67+
) -> Self {
68+
Self {
69+
options,
70+
class_static_block,
71+
remove_class_fields_without_initializer,
72+
ctx,
73+
}
74+
}
75+
}
76+
77+
impl VisitMutHook for ClassProperties<'_> {
78+
// This is a stub implementation.
79+
// The full implementation would include methods for:
80+
// - enter_program / exit_program
81+
// - enter_class / exit_class
82+
// - enter_class_members
83+
// - enter_property_definition / exit_property_definition
84+
// - enter_private_property / exit_private_property
85+
// - enter_private_method / exit_private_method
86+
// - enter_static_block / exit_static_block
87+
// - enter_expression / exit_expression
88+
// - enter_assign_expr
89+
// And many more...
90+
}

0 commit comments

Comments
 (0)