@@ -18,8 +18,9 @@ use rustc_hash::FxHashMap;
1818#[ cfg( feature = "cross_file_elision" ) ]
1919use super :: cross_file_elision:: CrossFileAnalyzer ;
2020use super :: decorator:: {
21- collect_constructor_decorator_spans, collect_member_decorator_spans,
22- extract_component_metadata, find_component_decorator, find_component_decorator_span,
21+ collect_all_class_decorator_spans, collect_constructor_decorator_spans,
22+ collect_member_decorator_spans, extract_component_metadata, find_component_decorator,
23+ find_component_decorator_span,
2324} ;
2425use super :: definition:: { const_value_to_expression, generate_component_definitions} ;
2526use super :: import_elision:: { ImportElisionAnalyzer , filter_imports} ;
@@ -790,10 +791,13 @@ pub fn transform_angular_file(
790791 ) ;
791792 }
792793
793- // Track the decorator span to remove
794- if let Some ( span) = find_component_decorator_span ( class) {
795- decorator_spans_to_remove. push ( span) ;
796- }
794+ // Track ALL class decorator spans for removal (Angular + non-Angular).
795+ // Non-Angular decorators (e.g. @UntilDestroy()) must also be removed,
796+ // otherwise they end up decorating the compiled output which is invalid JS.
797+ collect_all_class_decorator_spans (
798+ class,
799+ & mut decorator_spans_to_remove,
800+ ) ;
797801 // Collect constructor parameter decorators (@Optional, @Inject, etc.)
798802 collect_constructor_decorator_spans (
799803 class,
@@ -927,10 +931,8 @@ pub fn transform_angular_file(
927931 if let Some ( mut directive_metadata) =
928932 extract_directive_metadata ( allocator, class, implicit_standalone)
929933 {
930- // Track decorator span for removal
931- if let Some ( span) = find_directive_decorator_span ( class) {
932- decorator_spans_to_remove. push ( span) ;
933- }
934+ // Track ALL class decorator spans for removal (Angular + non-Angular)
935+ collect_all_class_decorator_spans ( class, & mut decorator_spans_to_remove) ;
934936 // Collect constructor parameter decorators (@Optional, @Inject, etc.)
935937 collect_constructor_decorator_spans ( class, & mut decorator_spans_to_remove) ;
936938 // Collect member decorators (@Input, @Output, @HostBinding, etc.)
@@ -981,10 +983,8 @@ pub fn transform_angular_file(
981983 // - ɵprov: Provider metadata for Angular's DI system
982984 // - ɵfac: Factory function to instantiate the class
983985
984- // Track decorator span for removal
985- if let Some ( span) = find_injectable_decorator_span ( class) {
986- decorator_spans_to_remove. push ( span) ;
987- }
986+ // Track ALL class decorator spans for removal (Angular + non-Angular)
987+ collect_all_class_decorator_spans ( class, & mut decorator_spans_to_remove) ;
988988 // Collect constructor parameter decorators (@Optional, @Inject, etc.)
989989 collect_constructor_decorator_spans ( class, & mut decorator_spans_to_remove) ;
990990
@@ -1035,10 +1035,8 @@ pub fn transform_angular_file(
10351035 // - ɵpipe: Pipe definition for Angular's pipe system
10361036 // - ɵfac: Factory function for dependency injection (when pipe has constructor deps)
10371037
1038- // Track decorator span for removal
1039- if let Some ( span) = find_pipe_decorator_span ( class) {
1040- decorator_spans_to_remove. push ( span) ;
1041- }
1038+ // Track ALL class decorator spans for removal (Angular + non-Angular)
1039+ collect_all_class_decorator_spans ( class, & mut decorator_spans_to_remove) ;
10421040 // Collect constructor parameter decorators (@Optional, @Inject, etc.)
10431041 collect_constructor_decorator_spans ( class, & mut decorator_spans_to_remove) ;
10441042
@@ -1083,10 +1081,8 @@ pub fn transform_angular_file(
10831081 // - ɵfac: Factory function for instantiation (with constructor dependencies)
10841082 // - ɵinj: Injector definition with providers and imports
10851083
1086- // Track decorator span for removal
1087- if let Some ( span) = find_ng_module_decorator_span ( class) {
1088- decorator_spans_to_remove. push ( span) ;
1089- }
1084+ // Track ALL class decorator spans for removal (Angular + non-Angular)
1085+ collect_all_class_decorator_spans ( class, & mut decorator_spans_to_remove) ;
10901086 // Collect constructor parameter decorators (@Optional, @Inject, etc.)
10911087 collect_constructor_decorator_spans ( class, & mut decorator_spans_to_remove) ;
10921088
@@ -1169,25 +1165,22 @@ pub fn transform_angular_file(
11691165 _ => None ,
11701166 } ;
11711167 if let Some ( class) = class {
1172- // Check for component, directive, injectable, pipe, or ngmodule decorators
1173- // and collect associated parameter/member decorator spans
1174- if let Some ( span) = find_component_decorator_span ( class) {
1175- new_decorator_spans. push ( span) ;
1176- collect_constructor_decorator_spans ( class, & mut new_decorator_spans) ;
1177- collect_member_decorator_spans ( class, & mut new_decorator_spans) ;
1178- } else if let Some ( span) = find_directive_decorator_span ( class) {
1179- new_decorator_spans. push ( span) ;
1180- collect_constructor_decorator_spans ( class, & mut new_decorator_spans) ;
1181- collect_member_decorator_spans ( class, & mut new_decorator_spans) ;
1182- } else if let Some ( span) = find_injectable_decorator_span ( class) {
1183- new_decorator_spans. push ( span) ;
1184- collect_constructor_decorator_spans ( class, & mut new_decorator_spans) ;
1185- } else if let Some ( span) = find_pipe_decorator_span ( class) {
1186- new_decorator_spans. push ( span) ;
1187- collect_constructor_decorator_spans ( class, & mut new_decorator_spans) ;
1188- } else if let Some ( span) = find_ng_module_decorator_span ( class) {
1189- new_decorator_spans. push ( span) ;
1168+ // Check if this is an Angular-decorated class (component, directive, etc.)
1169+ // and collect ALL decorator spans for removal (Angular + non-Angular)
1170+ let is_component = find_component_decorator_span ( class) . is_some ( ) ;
1171+ let is_directive = !is_component && find_directive_decorator_span ( class) . is_some ( ) ;
1172+ let is_angular_class = is_component
1173+ || is_directive
1174+ || find_injectable_decorator_span ( class) . is_some ( )
1175+ || find_pipe_decorator_span ( class) . is_some ( )
1176+ || find_ng_module_decorator_span ( class) . is_some ( ) ;
1177+
1178+ if is_angular_class {
1179+ collect_all_class_decorator_spans ( class, & mut new_decorator_spans) ;
11901180 collect_constructor_decorator_spans ( class, & mut new_decorator_spans) ;
1181+ if is_component || is_directive {
1182+ collect_member_decorator_spans ( class, & mut new_decorator_spans) ;
1183+ }
11911184 }
11921185 }
11931186 }
0 commit comments