Skip to content

Commit e092265

Browse files
committed
save
1 parent 6b98f64 commit e092265

16 files changed

Lines changed: 957 additions & 246 deletions

crates/oxc_angular_compiler/src/component/import_elision.rs

Lines changed: 585 additions & 143 deletions
Large diffs are not rendered by default.

crates/oxc_angular_compiler/src/ir/expression.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,10 +1824,7 @@ pub fn transform_expressions_in_update_op<'a, F>(
18241824
transform_expressions_in_output_statement(&mut op.statement, transform, flags);
18251825
}
18261826
// Operations without expressions
1827-
UpdateOp::ListEnd(_)
1828-
| UpdateOp::Advance(_)
1829-
| UpdateOp::I18nApply(_)
1830-
| UpdateOp::Animation(_) => {}
1827+
UpdateOp::ListEnd(_) | UpdateOp::Advance(_) | UpdateOp::I18nApply(_) => {}
18311828
}
18321829
}
18331830

@@ -2020,6 +2017,13 @@ pub fn transform_expressions_in_create_op<'a, F>(
20202017
transform_expressions_in_update_op(handler_op, transform, child_flags);
20212018
}
20222019
}
2020+
CreateOp::Animation(op) => {
2021+
// Process handler ops in the animation op
2022+
let child_flags = flags.union(VisitorContextFlag::IN_CHILD_OPERATION);
2023+
for handler_op in op.handler_ops.iter_mut() {
2024+
transform_expressions_in_update_op(handler_op, transform, child_flags);
2025+
}
2026+
}
20232027
CreateOp::AnimationString(op) => {
20242028
transform_expressions_in_expression(&mut op.expression, transform, flags);
20252029
}
@@ -2152,7 +2156,6 @@ pub fn visit_expressions_in_update_op<'a, F>(
21522156
UpdateOp::ListEnd(_)
21532157
| UpdateOp::Advance(_)
21542158
| UpdateOp::I18nApply(_)
2155-
| UpdateOp::Animation(_)
21562159
| UpdateOp::Statement(_) => {}
21572160
}
21582161
}
@@ -2190,6 +2193,12 @@ pub fn visit_expressions_in_create_op<'a, F>(
21902193
visit_expressions_in_update_op(handler_op, visitor, child_flags);
21912194
}
21922195
}
2196+
CreateOp::Animation(op) => {
2197+
let child_flags = flags.union(VisitorContextFlag::IN_CHILD_OPERATION);
2198+
for handler_op in op.handler_ops.iter() {
2199+
visit_expressions_in_update_op(handler_op, visitor, child_flags);
2200+
}
2201+
}
21932202
CreateOp::AnimationString(op) => {
21942203
visit_expressions_in_expression(&op.expression, visitor, flags);
21952204
}

crates/oxc_angular_compiler/src/ir/ops.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub enum CreateOp<'a> {
157157
TwoWayListener(TwoWayListenerOp<'a>),
158158
/// Animation string binding.
159159
AnimationString(AnimationStringOp<'a>),
160+
/// Animation binding (converted from AnimationBinding, emits syntheticHostProperty).
161+
Animation(AnimationOp<'a>),
160162
/// Animation listener.
161163
AnimationListener(AnimationListenerOp<'a>),
162164
/// Create a pipe instance.
@@ -223,6 +225,7 @@ impl<'a> Op for CreateOp<'a> {
223225
CreateOp::Listener(_) => OpKind::Listener,
224226
CreateOp::TwoWayListener(_) => OpKind::TwoWayListener,
225227
CreateOp::AnimationString(_) => OpKind::AnimationString,
228+
CreateOp::Animation(_) => OpKind::Animation,
226229
CreateOp::AnimationListener(_) => OpKind::AnimationListener,
227230
CreateOp::Pipe(_) => OpKind::Pipe,
228231
CreateOp::Defer(_) => OpKind::Defer,
@@ -267,6 +270,7 @@ impl<'a> Op for CreateOp<'a> {
267270
CreateOp::Listener(op) => op.base.prev,
268271
CreateOp::TwoWayListener(op) => op.base.prev,
269272
CreateOp::AnimationString(op) => op.base.prev,
273+
CreateOp::Animation(op) => op.base.prev,
270274
CreateOp::AnimationListener(op) => op.base.prev,
271275
CreateOp::Pipe(op) => op.base.prev,
272276
CreateOp::Defer(op) => op.base.prev,
@@ -311,6 +315,7 @@ impl<'a> Op for CreateOp<'a> {
311315
CreateOp::Listener(op) => op.base.next,
312316
CreateOp::TwoWayListener(op) => op.base.next,
313317
CreateOp::AnimationString(op) => op.base.next,
318+
CreateOp::Animation(op) => op.base.next,
314319
CreateOp::AnimationListener(op) => op.base.next,
315320
CreateOp::Pipe(op) => op.base.next,
316321
CreateOp::Defer(op) => op.base.next,
@@ -355,6 +360,7 @@ impl<'a> Op for CreateOp<'a> {
355360
CreateOp::Listener(op) => op.base.prev = prev,
356361
CreateOp::TwoWayListener(op) => op.base.prev = prev,
357362
CreateOp::AnimationString(op) => op.base.prev = prev,
363+
CreateOp::Animation(op) => op.base.prev = prev,
358364
CreateOp::AnimationListener(op) => op.base.prev = prev,
359365
CreateOp::Pipe(op) => op.base.prev = prev,
360366
CreateOp::Defer(op) => op.base.prev = prev,
@@ -399,6 +405,7 @@ impl<'a> Op for CreateOp<'a> {
399405
CreateOp::Listener(op) => op.base.next = next,
400406
CreateOp::TwoWayListener(op) => op.base.next = next,
401407
CreateOp::AnimationString(op) => op.base.next = next,
408+
CreateOp::Animation(op) => op.base.next = next,
402409
CreateOp::AnimationListener(op) => op.base.next = next,
403410
CreateOp::Pipe(op) => op.base.next = next,
404411
CreateOp::Defer(op) => op.base.next = next,
@@ -484,8 +491,6 @@ pub enum UpdateOp<'a> {
484491
/// Intermediate binding.
485492
Binding(BindingOp<'a>),
486493
/// Animation binding.
487-
Animation(AnimationOp<'a>),
488-
/// Animation binding.
489494
AnimationBinding(AnimationBindingOp<'a>),
490495
/// Semantic variable declaration.
491496
Variable(UpdateVariableOp<'a>),
@@ -517,7 +522,6 @@ impl<'a> Op for UpdateOp<'a> {
517522
UpdateOp::I18nExpression(_) => OpKind::I18nExpression,
518523
UpdateOp::I18nApply(_) => OpKind::I18nApply,
519524
UpdateOp::Binding(_) => OpKind::Binding,
520-
UpdateOp::Animation(_) => OpKind::Animation,
521525
UpdateOp::AnimationBinding(_) => OpKind::AnimationBinding,
522526
UpdateOp::Variable(_) => OpKind::Variable,
523527
UpdateOp::Control(_) => OpKind::Control,
@@ -545,7 +549,6 @@ impl<'a> Op for UpdateOp<'a> {
545549
UpdateOp::I18nExpression(op) => op.base.prev,
546550
UpdateOp::I18nApply(op) => op.base.prev,
547551
UpdateOp::Binding(op) => op.base.prev,
548-
UpdateOp::Animation(op) => op.base.prev,
549552
UpdateOp::AnimationBinding(op) => op.base.prev,
550553
UpdateOp::Variable(op) => op.base.prev,
551554
UpdateOp::Control(op) => op.base.prev,
@@ -573,7 +576,6 @@ impl<'a> Op for UpdateOp<'a> {
573576
UpdateOp::I18nExpression(op) => op.base.next,
574577
UpdateOp::I18nApply(op) => op.base.next,
575578
UpdateOp::Binding(op) => op.base.next,
576-
UpdateOp::Animation(op) => op.base.next,
577579
UpdateOp::AnimationBinding(op) => op.base.next,
578580
UpdateOp::Variable(op) => op.base.next,
579581
UpdateOp::Control(op) => op.base.next,
@@ -601,7 +603,6 @@ impl<'a> Op for UpdateOp<'a> {
601603
UpdateOp::I18nExpression(op) => op.base.prev = prev,
602604
UpdateOp::I18nApply(op) => op.base.prev = prev,
603605
UpdateOp::Binding(op) => op.base.prev = prev,
604-
UpdateOp::Animation(op) => op.base.prev = prev,
605606
UpdateOp::AnimationBinding(op) => op.base.prev = prev,
606607
UpdateOp::Variable(op) => op.base.prev = prev,
607608
UpdateOp::Control(op) => op.base.prev = prev,
@@ -629,7 +630,6 @@ impl<'a> Op for UpdateOp<'a> {
629630
UpdateOp::I18nExpression(op) => op.base.next = next,
630631
UpdateOp::I18nApply(op) => op.base.next = next,
631632
UpdateOp::Binding(op) => op.base.next = next,
632-
UpdateOp::Animation(op) => op.base.next = next,
633633
UpdateOp::AnimationBinding(op) => op.base.next = next,
634634
UpdateOp::Variable(op) => op.base.next = next,
635635
UpdateOp::Control(op) => op.base.next = next,
@@ -1817,17 +1817,35 @@ pub struct BindingOp<'a> {
18171817
pub is_text_attribute: bool,
18181818
}
18191819

1820-
/// Animation binding.
1820+
/// Animation binding (CREATE op).
1821+
///
1822+
/// This operation is converted from AnimationBinding during the convert_animations phase.
1823+
/// It emits a syntheticHostProperty instruction that binds an animation trigger to an element.
1824+
///
1825+
/// In Angular's TypeScript, AnimationOp has handlerOps for callback bodies, but in our
1826+
/// simplified implementation we keep the expression directly and emit a return statement.
1827+
///
1828+
/// Ported from Angular's `AnimationOp` in `ir/src/ops/create.ts`.
18211829
#[derive(Debug)]
18221830
pub struct AnimationOp<'a> {
18231831
/// Common operation metadata.
1824-
pub base: UpdateOpBase<'a>,
1832+
pub base: CreateOpBase<'a>,
18251833
/// Target element.
18261834
pub target: XrefId,
18271835
/// Animation name.
18281836
pub name: Atom<'a>,
1829-
/// Expression.
1830-
pub expression: Box<'a, IrExpression<'a>>,
1837+
/// Animation kind (enter or leave).
1838+
pub animation_kind: AnimationKind,
1839+
/// Handler operations (contains the expression as a return statement).
1840+
pub handler_ops: Vec<'a, UpdateOp<'a>>,
1841+
/// Function name for the handler.
1842+
pub handler_fn_name: Option<Atom<'a>>,
1843+
/// I18n message.
1844+
pub i18n_message: Option<XrefId>,
1845+
/// Security context.
1846+
pub security_context: SecurityContext,
1847+
/// Sanitizer function.
1848+
pub sanitizer: Option<Atom<'a>>,
18311849
}
18321850

18331851
/// Animation string binding (CREATE op).

crates/oxc_angular_compiler/src/pipeline/phases/allocate_slots.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,6 @@ fn propagate_slots_to_expressions(
601601
apply.handle = I18nSlotHandle::Single(slot);
602602
}
603603
}
604-
UpdateOp::Animation(anim) => {
605-
update_expression_slots(&mut anim.expression, slot_map);
606-
}
607604
UpdateOp::AnimationBinding(anim) => {
608605
update_expression_slots(&mut anim.expression, slot_map);
609606
}

crates/oxc_angular_compiler/src/pipeline/phases/assign_i18n_slot_dependencies.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ fn get_update_op_target(op: &UpdateOp<'_>) -> Option<XrefId> {
223223
| UpdateOp::Advance(_)
224224
| UpdateOp::I18nApply(_)
225225
| UpdateOp::Binding(_)
226-
| UpdateOp::Animation(_)
227226
| UpdateOp::AnimationBinding(_)
228227
| UpdateOp::Variable(_)
229228
| UpdateOp::Control(_)

0 commit comments

Comments
 (0)