@@ -1088,6 +1088,48 @@ pub fn collect_member_decorator_spans(class: &Class<'_>, spans: &mut std::vec::V
10881088 }
10891089}
10901090
1091+ /// Collect spans of uninitialized class field declarations for stripping.
1092+ ///
1093+ /// TypeScript class field declarations like `name: string;` without initializers are
1094+ /// type-only annotations that have no runtime effect. They should be stripped from
1095+ /// the output to match TypeScript's emit behavior.
1096+ ///
1097+ /// Only collects:
1098+ /// - Non-static property definitions without an initializer (e.g., `name: string;`)
1099+ ///
1100+ /// Does NOT collect:
1101+ /// - Fields with initializers (e.g., `name = 'value';`) - these have runtime values
1102+ /// - Static fields (e.g., `static version: string;`) - handled separately
1103+ /// - Methods or accessors - they have runtime bodies
1104+ /// - Decorated fields - Angular may need the field structure
1105+ ///
1106+ /// These spans are used by `transform.rs` to remove the declarations from the
1107+ /// source text during transformation.
1108+ pub fn collect_uninitialized_field_spans ( class : & Class < ' _ > , spans : & mut std:: vec:: Vec < Span > ) {
1109+ for element in & class. body . body {
1110+ if let ClassElement :: PropertyDefinition ( prop) = element {
1111+ // Skip static fields - they're handled differently
1112+ if prop. r#static {
1113+ continue ;
1114+ }
1115+
1116+ // Skip fields with initializers - they have runtime values
1117+ if prop. value . is_some ( ) {
1118+ continue ;
1119+ }
1120+
1121+ // Skip decorated fields - Angular may need them
1122+ if !prop. decorators . is_empty ( ) {
1123+ continue ;
1124+ }
1125+
1126+ // This is an uninitialized, non-static, non-decorated field declaration
1127+ // (e.g., `name: string;`) - it should be stripped
1128+ spans. push ( prop. span ) ;
1129+ }
1130+ }
1131+ }
1132+
10911133#[ cfg( test) ]
10921134mod tests {
10931135 use super :: * ;
@@ -1109,7 +1151,7 @@ mod tests {
11091151 let parser_ret = Parser :: new ( & allocator, code, source_type) . parse ( ) ;
11101152
11111153 // Build import map from the program body
1112- let import_map = build_import_map ( & parser_ret. program . body ) ;
1154+ let import_map = build_import_map ( & allocator , & parser_ret. program . body , None ) ;
11131155
11141156 // Find the first class declaration (handles plain, export default, and export named)
11151157 let mut found_metadata = None ;
0 commit comments