vize_relief 0.0.1-alpha.76

Relief - The sculptured AST surface for Vize Vue templates
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
//! Vue template AST node types.
//!
//! This module defines the AST (Abstract Syntax Tree) for Vue templates.
//! All AST nodes are allocated in a bumpalo arena for efficient memory management
//! and zero-copy transfer to JavaScript.

use serde::{Deserialize, Serialize};
use vize_carton::PatchFlags;
use vize_carton::{Box, Bump, String, Vec};

/// Node type discriminant
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u8)]
pub enum NodeType {
    Root = 0,
    Element = 1,
    Text = 2,
    Comment = 3,
    SimpleExpression = 4,
    Interpolation = 5,
    Attribute = 6,
    Directive = 7,
    CompoundExpression = 8,
    If = 9,
    IfBranch = 10,
    For = 11,
    TextCall = 12,
    // Codegen nodes
    VNodeCall = 13,
    JsCallExpression = 14,
    JsObjectExpression = 15,
    JsProperty = 16,
    JsArrayExpression = 17,
    JsFunctionExpression = 18,
    JsConditionalExpression = 19,
    JsCacheExpression = 20,
    // SSR codegen nodes
    JsBlockStatement = 21,
    JsTemplateLiteral = 22,
    JsIfStatement = 23,
    JsAssignmentExpression = 24,
    JsSequenceExpression = 25,
    JsReturnStatement = 26,
}

/// Element type discriminant
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[repr(u8)]
pub enum ElementType {
    #[default]
    Element = 0,
    Component = 1,
    Slot = 2,
    Template = 3,
}

/// Namespace for elements
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[repr(u8)]
pub enum Namespace {
    #[default]
    Html = 0,
    Svg = 1,
    MathMl = 2,
}

/// Constant type levels for static analysis
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
)]
#[repr(u8)]
pub enum ConstantType {
    #[default]
    NotConstant = 0,
    CanSkipPatch = 1,
    CanCache = 2,
    CanStringify = 3,
}

/// Source position in the template
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
pub struct Position {
    /// Byte offset from start of file
    pub offset: u32,
    /// 1-indexed line number
    pub line: u32,
    /// 1-indexed column number
    pub column: u32,
}

impl Position {
    pub const fn new(offset: u32, line: u32, column: u32) -> Self {
        Self {
            offset,
            line,
            column,
        }
    }
}

/// Source location span [start, end)
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct SourceLocation {
    pub start: Position,
    pub end: Position,
    pub source: String,
}

impl Default for SourceLocation {
    fn default() -> Self {
        Self::STUB
    }
}

/// Static stub location for returning references
static STUB_LOCATION: SourceLocation = SourceLocation {
    start: Position {
        offset: 0,
        line: 1,
        column: 1,
    },
    end: Position {
        offset: 0,
        line: 1,
        column: 1,
    },
    source: String::const_new(""),
};

impl SourceLocation {
    /// Stub location for generated nodes
    pub const STUB: Self = Self {
        start: Position {
            offset: 0,
            line: 1,
            column: 1,
        },
        end: Position {
            offset: 0,
            line: 1,
            column: 1,
        },
        source: String::const_new(""),
    };

    pub fn new(start: Position, end: Position, source: impl Into<String>) -> Self {
        Self {
            start,
            end,
            source: source.into(),
        }
    }
}

/// Root AST node
#[derive(Debug)]
pub struct RootNode<'a> {
    pub children: Vec<'a, TemplateChildNode<'a>>,
    pub helpers: Vec<'a, RuntimeHelper>,
    pub components: Vec<'a, String>,
    pub directives: Vec<'a, String>,
    pub hoists: Vec<'a, Option<JsChildNode<'a>>>,
    pub imports: Vec<'a, ImportItem<'a>>,
    pub cached: Vec<'a, Option<Box<'a, CacheExpression<'a>>>>,
    pub temps: u32,
    pub source: String,
    pub loc: SourceLocation,
    pub codegen_node: Option<CodegenNode<'a>>,
    pub transformed: bool,
}

impl<'a> RootNode<'a> {
    pub fn new(allocator: &'a Bump, source: impl Into<String>) -> Self {
        Self {
            children: Vec::new_in(allocator),
            helpers: Vec::new_in(allocator),
            components: Vec::new_in(allocator),
            directives: Vec::new_in(allocator),
            hoists: Vec::new_in(allocator),
            imports: Vec::new_in(allocator),
            cached: Vec::new_in(allocator),
            temps: 0,
            source: source.into(),
            loc: SourceLocation::STUB,
            codegen_node: None,
            transformed: false,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Root
    }
}

/// Import item for code generation
#[derive(Debug)]
pub struct ImportItem<'a> {
    pub exp: Box<'a, SimpleExpressionNode<'a>>,
    pub path: String,
}

/// Runtime helper symbols
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[repr(u8)]
pub enum RuntimeHelper {
    // Core helpers
    Fragment,
    Teleport,
    Suspense,
    KeepAlive,
    BaseTransition,
    Transition,
    TransitionGroup,
    OpenBlock,
    CreateBlock,
    CreateElementBlock,
    CreateVNode,
    CreateElementVNode,
    CreateComment,
    CreateText,
    CreateStatic,
    ResolveComponent,
    ResolveDynamicComponent,
    ResolveDirective,
    ResolveFilter,
    WithDirectives,
    RenderList,
    RenderSlot,
    CreateSlots,
    ToDisplayString,
    MergeProps,
    NormalizeClass,
    NormalizeStyle,
    NormalizeProps,
    GuardReactiveProps,
    ToHandlers,
    Camelize,
    Capitalize,
    ToHandlerKey,
    SetBlockTracking,
    PushScopeId,
    PopScopeId,
    WithCtx,
    Unref,
    IsRef,
    WithMemo,
    IsMemoSame,
    VShow,
    VModelText,
    VModelCheckbox,
    VModelRadio,
    VModelSelect,
    VModelDynamic,
    WithModifiers,
    WithKeys,

    // SSR helpers
    /// SSR text interpolation with escaping
    SsrInterpolate,
    /// SSR VNode rendering
    SsrRenderVNode,
    /// SSR component rendering
    SsrRenderComponent,
    /// SSR slot rendering (with fragment markers)
    SsrRenderSlot,
    /// SSR slot rendering (without fragment markers)
    SsrRenderSlotInner,
    /// SSR render all attributes
    SsrRenderAttrs,
    /// SSR render single attribute
    SsrRenderAttr,
    /// SSR render dynamic key attribute
    SsrRenderDynamicAttr,
    /// SSR boolean attribute inclusion check
    SsrIncludeBooleanAttr,
    /// SSR class stringification
    SsrRenderClass,
    /// SSR style stringification
    SsrRenderStyle,
    /// SSR dynamic input type model rendering
    SsrRenderDynamicModel,
    /// SSR get dynamic v-model props
    SsrGetDynamicModelProps,
    /// SSR v-for list rendering
    SsrRenderList,
    /// SSR loose equality check (for v-model)
    SsrLooseEqual,
    /// SSR array membership check (for v-model)
    SsrLooseContain,
    /// SSR get directive props
    SsrGetDirectiveProps,
    /// SSR teleport rendering
    SsrRenderTeleport,
    /// SSR suspense rendering
    SsrRenderSuspense,
}

impl RuntimeHelper {
    pub fn name(&self) -> &'static str {
        match self {
            // Core helpers
            Self::Fragment => "Fragment",
            Self::Teleport => "Teleport",
            Self::Suspense => "Suspense",
            Self::KeepAlive => "KeepAlive",
            Self::BaseTransition => "BaseTransition",
            Self::Transition => "Transition",
            Self::TransitionGroup => "TransitionGroup",
            Self::OpenBlock => "openBlock",
            Self::CreateBlock => "createBlock",
            Self::CreateElementBlock => "createElementBlock",
            Self::CreateVNode => "createVNode",
            Self::CreateElementVNode => "createElementVNode",
            Self::CreateComment => "createCommentVNode",
            Self::CreateText => "createTextVNode",
            Self::CreateStatic => "createStaticVNode",
            Self::ResolveComponent => "resolveComponent",
            Self::ResolveDynamicComponent => "resolveDynamicComponent",
            Self::ResolveDirective => "resolveDirective",
            Self::ResolveFilter => "resolveFilter",
            Self::WithDirectives => "withDirectives",
            Self::RenderList => "renderList",
            Self::RenderSlot => "renderSlot",
            Self::CreateSlots => "createSlots",
            Self::ToDisplayString => "toDisplayString",
            Self::MergeProps => "mergeProps",
            Self::NormalizeClass => "normalizeClass",
            Self::NormalizeStyle => "normalizeStyle",
            Self::NormalizeProps => "normalizeProps",
            Self::GuardReactiveProps => "guardReactiveProps",
            Self::ToHandlers => "toHandlers",
            Self::Camelize => "camelize",
            Self::Capitalize => "capitalize",
            Self::ToHandlerKey => "toHandlerKey",
            Self::SetBlockTracking => "setBlockTracking",
            Self::PushScopeId => "pushScopeId",
            Self::PopScopeId => "popScopeId",
            Self::WithCtx => "withCtx",
            Self::Unref => "unref",
            Self::IsRef => "isRef",
            Self::WithMemo => "withMemo",
            Self::IsMemoSame => "isMemoSame",
            Self::VShow => "vShow",
            Self::VModelText => "vModelText",
            Self::VModelCheckbox => "vModelCheckbox",
            Self::VModelRadio => "vModelRadio",
            Self::VModelSelect => "vModelSelect",
            Self::VModelDynamic => "vModelDynamic",
            Self::WithModifiers => "withModifiers",
            Self::WithKeys => "withKeys",

            // SSR helpers
            Self::SsrInterpolate => "ssrInterpolate",
            Self::SsrRenderVNode => "ssrRenderVNode",
            Self::SsrRenderComponent => "ssrRenderComponent",
            Self::SsrRenderSlot => "ssrRenderSlot",
            Self::SsrRenderSlotInner => "ssrRenderSlotInner",
            Self::SsrRenderAttrs => "ssrRenderAttrs",
            Self::SsrRenderAttr => "ssrRenderAttr",
            Self::SsrRenderDynamicAttr => "ssrRenderDynamicAttr",
            Self::SsrIncludeBooleanAttr => "ssrIncludeBooleanAttr",
            Self::SsrRenderClass => "ssrRenderClass",
            Self::SsrRenderStyle => "ssrRenderStyle",
            Self::SsrRenderDynamicModel => "ssrRenderDynamicModel",
            Self::SsrGetDynamicModelProps => "ssrGetDynamicModelProps",
            Self::SsrRenderList => "ssrRenderList",
            Self::SsrLooseEqual => "ssrLooseEqual",
            Self::SsrLooseContain => "ssrLooseContain",
            Self::SsrGetDirectiveProps => "ssrGetDirectiveProps",
            Self::SsrRenderTeleport => "ssrRenderTeleport",
            Self::SsrRenderSuspense => "ssrRenderSuspense",
        }
    }

    /// Check if this is an SSR-specific helper
    pub fn is_ssr(&self) -> bool {
        matches!(
            self,
            Self::SsrInterpolate
                | Self::SsrRenderVNode
                | Self::SsrRenderComponent
                | Self::SsrRenderSlot
                | Self::SsrRenderSlotInner
                | Self::SsrRenderAttrs
                | Self::SsrRenderAttr
                | Self::SsrRenderDynamicAttr
                | Self::SsrIncludeBooleanAttr
                | Self::SsrRenderClass
                | Self::SsrRenderStyle
                | Self::SsrRenderDynamicModel
                | Self::SsrGetDynamicModelProps
                | Self::SsrRenderList
                | Self::SsrLooseEqual
                | Self::SsrLooseContain
                | Self::SsrGetDirectiveProps
                | Self::SsrRenderTeleport
                | Self::SsrRenderSuspense
        )
    }
}

// ============================================================================
// Template Nodes
// ============================================================================

/// All template child node types
#[derive(Debug)]
pub enum TemplateChildNode<'a> {
    Element(Box<'a, ElementNode<'a>>),
    Text(Box<'a, TextNode>),
    Comment(Box<'a, CommentNode>),
    Interpolation(Box<'a, InterpolationNode<'a>>),
    If(Box<'a, IfNode<'a>>),
    IfBranch(Box<'a, IfBranchNode<'a>>),
    For(Box<'a, ForNode<'a>>),
    TextCall(Box<'a, TextCallNode<'a>>),
    CompoundExpression(Box<'a, CompoundExpressionNode<'a>>),
    /// Reference to a hoisted node (index into root.hoists array)
    Hoisted(usize),
}

impl<'a> TemplateChildNode<'a> {
    pub fn node_type(&self) -> NodeType {
        match self {
            Self::Element(_) => NodeType::Element,
            Self::Text(_) => NodeType::Text,
            Self::Comment(_) => NodeType::Comment,
            Self::Interpolation(_) => NodeType::Interpolation,
            Self::If(_) => NodeType::If,
            Self::IfBranch(_) => NodeType::IfBranch,
            Self::For(_) => NodeType::For,
            Self::TextCall(_) => NodeType::TextCall,
            Self::CompoundExpression(_) => NodeType::CompoundExpression,
            Self::Hoisted(_) => NodeType::SimpleExpression, // Hoisted refs are like expressions
        }
    }

    pub fn loc(&self) -> &SourceLocation {
        match self {
            Self::Element(n) => &n.loc,
            Self::Text(n) => &n.loc,
            Self::Comment(n) => &n.loc,
            Self::Interpolation(n) => &n.loc,
            Self::If(n) => &n.loc,
            Self::IfBranch(n) => &n.loc,
            Self::For(n) => &n.loc,
            Self::TextCall(n) => &n.loc,
            Self::CompoundExpression(n) => &n.loc,
            Self::Hoisted(_) => &STUB_LOCATION, // Hoisted refs don't have a real location
        }
    }
}

/// Element node
#[derive(Debug)]
pub struct ElementNode<'a> {
    pub ns: Namespace,
    pub tag: String,
    pub tag_type: ElementType,
    pub props: Vec<'a, PropNode<'a>>,
    pub children: Vec<'a, TemplateChildNode<'a>>,
    pub is_self_closing: bool,
    pub loc: SourceLocation,
    pub inner_loc: Option<SourceLocation>,
    pub codegen_node: Option<ElementCodegenNode<'a>>,
    /// If props are hoisted, this is the index into the hoists array (1-based for _hoisted_N)
    pub hoisted_props_index: Option<usize>,
}

impl<'a> ElementNode<'a> {
    pub fn new(allocator: &'a Bump, tag: impl Into<String>, loc: SourceLocation) -> Self {
        Self {
            ns: Namespace::Html,
            tag: tag.into(),
            tag_type: ElementType::Element,
            props: Vec::new_in(allocator),
            children: Vec::new_in(allocator),
            is_self_closing: false,
            loc,
            inner_loc: None,
            codegen_node: None,
            hoisted_props_index: None,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Element
    }
}

/// Element codegen node (VNodeCall, SimpleExpression, CacheExpression, etc.)
#[derive(Debug)]
pub enum ElementCodegenNode<'a> {
    VNodeCall(Box<'a, VNodeCall<'a>>),
    SimpleExpression(Box<'a, SimpleExpressionNode<'a>>),
    CacheExpression(Box<'a, CacheExpression<'a>>),
}

/// Prop node (attribute or directive)
#[derive(Debug)]
pub enum PropNode<'a> {
    Attribute(Box<'a, AttributeNode>),
    Directive(Box<'a, DirectiveNode<'a>>),
}

impl<'a> PropNode<'a> {
    pub fn loc(&self) -> &SourceLocation {
        match self {
            Self::Attribute(n) => &n.loc,
            Self::Directive(n) => &n.loc,
        }
    }
}

/// Attribute node
#[derive(Debug)]
pub struct AttributeNode {
    pub name: String,
    pub name_loc: SourceLocation,
    pub value: Option<TextNode>,
    pub loc: SourceLocation,
}

impl AttributeNode {
    pub fn new(name: impl Into<String>, loc: SourceLocation) -> Self {
        Self {
            name: name.into(),
            name_loc: loc.clone(),
            value: None,
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Attribute
    }
}

/// Directive node (v-if, v-for, v-bind, etc.)
#[derive(Debug)]
pub struct DirectiveNode<'a> {
    /// Normalized directive name without prefix (e.g., "if", "for", "bind")
    pub name: String,
    /// Raw attribute name including shorthand (e.g., "@click", ":class")
    pub raw_name: Option<String>,
    /// Directive expression
    pub exp: Option<ExpressionNode<'a>>,
    /// Directive argument (e.g., "click" in @click)
    pub arg: Option<ExpressionNode<'a>>,
    /// Directive modifiers (e.g., ["stop", "prevent"] in @click.stop.prevent)
    pub modifiers: Vec<'a, SimpleExpressionNode<'a>>,
    /// Parsed result for v-for
    pub for_parse_result: Option<ForParseResult<'a>>,
    pub loc: SourceLocation,
}

impl<'a> DirectiveNode<'a> {
    pub fn new(allocator: &'a Bump, name: impl Into<String>, loc: SourceLocation) -> Self {
        Self {
            name: name.into(),
            raw_name: None,
            exp: None,
            arg: None,
            modifiers: Vec::new_in(allocator),
            for_parse_result: None,
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Directive
    }
}

/// Text node
#[derive(Debug)]
pub struct TextNode {
    pub content: String,
    pub loc: SourceLocation,
}

impl TextNode {
    pub fn new(content: impl Into<String>, loc: SourceLocation) -> Self {
        Self {
            content: content.into(),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Text
    }
}

/// Comment node
#[derive(Debug)]
pub struct CommentNode {
    pub content: String,
    pub loc: SourceLocation,
}

impl CommentNode {
    pub fn new(content: impl Into<String>, loc: SourceLocation) -> Self {
        Self {
            content: content.into(),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::Comment
    }
}

/// Interpolation node ({{ expr }})
#[derive(Debug)]
pub struct InterpolationNode<'a> {
    pub content: ExpressionNode<'a>,
    pub loc: SourceLocation,
}

impl<'a> InterpolationNode<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::Interpolation
    }
}

// ============================================================================
// Expression Nodes
// ============================================================================

/// Expression node types
#[derive(Debug)]
pub enum ExpressionNode<'a> {
    Simple(Box<'a, SimpleExpressionNode<'a>>),
    Compound(Box<'a, CompoundExpressionNode<'a>>),
}

impl<'a> ExpressionNode<'a> {
    pub fn loc(&self) -> &SourceLocation {
        match self {
            Self::Simple(n) => &n.loc,
            Self::Compound(n) => &n.loc,
        }
    }
}

/// Simple expression node
#[derive(Debug)]
pub struct SimpleExpressionNode<'a> {
    pub content: String,
    pub is_static: bool,
    pub const_type: ConstantType,
    pub loc: SourceLocation,
    /// Parsed JavaScript AST (None = simple identifier, Some = parsed expression)
    pub js_ast: Option<JsExpression<'a>>,
    /// Hoisted node reference
    pub hoisted: Option<Box<'a, JsChildNode<'a>>>,
    /// Identifiers declared in this expression
    pub identifiers: Option<Vec<'a, String>>,
    /// Whether this is a handler key
    pub is_handler_key: bool,
    /// Whether this expression has been processed for ref .value transformation
    pub is_ref_transformed: bool,
}

impl<'a> SimpleExpressionNode<'a> {
    pub fn new(content: impl Into<String>, is_static: bool, loc: SourceLocation) -> Self {
        Self {
            content: content.into(),
            is_static,
            const_type: if is_static {
                ConstantType::CanStringify
            } else {
                ConstantType::NotConstant
            },
            loc,
            js_ast: None,
            hoisted: None,
            identifiers: None,
            is_handler_key: false,
            is_ref_transformed: false,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::SimpleExpression
    }
}

/// Placeholder for JavaScript expression AST from OXC
#[derive(Debug)]
pub struct JsExpression<'a> {
    /// Raw expression content (will be replaced with OXC AST)
    pub raw: String,
    _marker: std::marker::PhantomData<&'a ()>,
}

/// Compound expression node (mixed content)
#[derive(Debug)]
pub struct CompoundExpressionNode<'a> {
    pub children: Vec<'a, CompoundExpressionChild<'a>>,
    pub loc: SourceLocation,
    pub identifiers: Option<Vec<'a, String>>,
    pub is_handler_key: bool,
}

impl<'a> CompoundExpressionNode<'a> {
    pub fn new(allocator: &'a Bump, loc: SourceLocation) -> Self {
        Self {
            children: Vec::new_in(allocator),
            loc,
            identifiers: None,
            is_handler_key: false,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::CompoundExpression
    }
}

/// Child of a compound expression
#[derive(Debug)]
pub enum CompoundExpressionChild<'a> {
    Simple(Box<'a, SimpleExpressionNode<'a>>),
    Compound(Box<'a, CompoundExpressionNode<'a>>),
    Interpolation(Box<'a, InterpolationNode<'a>>),
    Text(Box<'a, TextNode>),
    String(String),
    Symbol(RuntimeHelper),
}

// ============================================================================
// Control Flow Nodes
// ============================================================================

/// If node (v-if)
#[derive(Debug)]
pub struct IfNode<'a> {
    pub branches: Vec<'a, IfBranchNode<'a>>,
    pub loc: SourceLocation,
    pub codegen_node: Option<IfCodegenNode<'a>>,
}

impl<'a> IfNode<'a> {
    pub fn new(allocator: &'a Bump, loc: SourceLocation) -> Self {
        Self {
            branches: Vec::new_in(allocator),
            loc,
            codegen_node: None,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::If
    }
}

/// If codegen node type
#[derive(Debug)]
pub enum IfCodegenNode<'a> {
    Conditional(Box<'a, ConditionalExpression<'a>>),
    Cache(Box<'a, CacheExpression<'a>>),
}

/// If branch node (v-if, v-else-if, v-else)
#[derive(Debug)]
pub struct IfBranchNode<'a> {
    pub condition: Option<ExpressionNode<'a>>,
    pub children: Vec<'a, TemplateChildNode<'a>>,
    pub user_key: Option<PropNode<'a>>,
    pub is_template_if: bool,
    pub loc: SourceLocation,
}

impl<'a> IfBranchNode<'a> {
    pub fn new(
        allocator: &'a Bump,
        condition: Option<ExpressionNode<'a>>,
        loc: SourceLocation,
    ) -> Self {
        Self {
            condition,
            children: Vec::new_in(allocator),
            user_key: None,
            is_template_if: false,
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::IfBranch
    }
}

/// For node (v-for)
#[derive(Debug)]
pub struct ForNode<'a> {
    pub source: ExpressionNode<'a>,
    pub value_alias: Option<ExpressionNode<'a>>,
    pub key_alias: Option<ExpressionNode<'a>>,
    pub object_index_alias: Option<ExpressionNode<'a>>,
    pub parse_result: ForParseResult<'a>,
    pub children: Vec<'a, TemplateChildNode<'a>>,
    pub loc: SourceLocation,
    pub codegen_node: Option<Box<'a, VNodeCall<'a>>>,
}

impl<'a> ForNode<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::For
    }
}

/// Parsed result for v-for expression
#[derive(Debug)]
pub struct ForParseResult<'a> {
    pub source: ExpressionNode<'a>,
    pub value: Option<ExpressionNode<'a>>,
    pub key: Option<ExpressionNode<'a>>,
    pub index: Option<ExpressionNode<'a>>,
    pub finalized: bool,
}

/// Text call node
#[derive(Debug)]
pub struct TextCallNode<'a> {
    pub content: TextCallContent<'a>,
    pub loc: SourceLocation,
    pub codegen_node: Option<TextCallCodegenNode<'a>>,
}

impl<'a> TextCallNode<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::TextCall
    }
}

/// Text call content
#[derive(Debug)]
pub enum TextCallContent<'a> {
    Text(Box<'a, TextNode>),
    Interpolation(Box<'a, InterpolationNode<'a>>),
    Compound(Box<'a, CompoundExpressionNode<'a>>),
}

/// Text call codegen node
#[derive(Debug)]
pub enum TextCallCodegenNode<'a> {
    Call(Box<'a, CallExpression<'a>>),
    Simple(Box<'a, SimpleExpressionNode<'a>>),
}

// ============================================================================
// Codegen Nodes
// ============================================================================

/// VNode call expression
#[derive(Debug)]
pub struct VNodeCall<'a> {
    pub tag: VNodeTag<'a>,
    pub props: Option<PropsExpression<'a>>,
    pub children: Option<VNodeChildren<'a>>,
    pub patch_flag: Option<PatchFlags>,
    pub dynamic_props: Option<DynamicProps<'a>>,
    pub directives: Option<DirectiveArguments<'a>>,
    pub is_block: bool,
    pub disable_tracking: bool,
    pub is_component: bool,
    pub loc: SourceLocation,
}

impl<'a> VNodeCall<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::VNodeCall
    }
}

/// VNode tag type
#[derive(Debug)]
pub enum VNodeTag<'a> {
    String(String),
    Symbol(RuntimeHelper),
    Call(Box<'a, CallExpression<'a>>),
}

/// VNode children type
#[derive(Debug)]
pub enum VNodeChildren<'a> {
    Multiple(Vec<'a, TemplateChildNode<'a>>),
    Single(TemplateTextChildNode<'a>),
    Slots(Box<'a, SlotsExpression<'a>>),
    ForRenderList(Box<'a, CallExpression<'a>>),
    Simple(Box<'a, SimpleExpressionNode<'a>>),
    Cache(Box<'a, CacheExpression<'a>>),
}

/// Template text child node
#[derive(Debug)]
pub enum TemplateTextChildNode<'a> {
    Text(Box<'a, TextNode>),
    Interpolation(Box<'a, InterpolationNode<'a>>),
    Compound(Box<'a, CompoundExpressionNode<'a>>),
}

/// Props expression type
#[derive(Debug)]
pub enum PropsExpression<'a> {
    Object(Box<'a, ObjectExpression<'a>>),
    Call(Box<'a, CallExpression<'a>>),
    Simple(Box<'a, SimpleExpressionNode<'a>>),
}

/// Dynamic props type
#[derive(Debug)]
pub enum DynamicProps<'a> {
    String(String),
    Simple(Box<'a, SimpleExpressionNode<'a>>),
}

/// Directive arguments
#[derive(Debug)]
pub struct DirectiveArguments<'a> {
    pub elements: Vec<'a, DirectiveArgumentNode<'a>>,
    pub loc: SourceLocation,
}

/// Single directive argument
#[derive(Debug)]
pub struct DirectiveArgumentNode<'a> {
    pub directive: String,
    pub exp: Option<ExpressionNode<'a>>,
    pub arg: Option<ExpressionNode<'a>>,
    pub modifiers: Option<Box<'a, ObjectExpression<'a>>>,
}

/// Slots expression
#[derive(Debug)]
pub enum SlotsExpression<'a> {
    Object(Box<'a, ObjectExpression<'a>>),
    Dynamic(Box<'a, CallExpression<'a>>),
}

// ============================================================================
// JavaScript AST Nodes
// ============================================================================

/// All JavaScript child node types for codegen
#[derive(Debug)]
pub enum JsChildNode<'a> {
    VNodeCall(Box<'a, VNodeCall<'a>>),
    Call(Box<'a, CallExpression<'a>>),
    Object(Box<'a, ObjectExpression<'a>>),
    Array(Box<'a, ArrayExpression<'a>>),
    Function(Box<'a, FunctionExpression<'a>>),
    Conditional(Box<'a, ConditionalExpression<'a>>),
    Cache(Box<'a, CacheExpression<'a>>),
    Assignment(Box<'a, AssignmentExpression<'a>>),
    Sequence(Box<'a, SequenceExpression<'a>>),
    SimpleExpression(Box<'a, SimpleExpressionNode<'a>>),
    CompoundExpression(Box<'a, CompoundExpressionNode<'a>>),
}

/// Codegen node union type
#[derive(Debug)]
pub enum CodegenNode<'a> {
    TemplateChild(TemplateChildNode<'a>),
    JsChild(JsChildNode<'a>),
    BlockStatement(Box<'a, BlockStatement<'a>>),
}

/// Call expression
#[derive(Debug)]
pub struct CallExpression<'a> {
    pub callee: Callee,
    pub arguments: Vec<'a, CallArgument<'a>>,
    pub loc: SourceLocation,
}

impl<'a> CallExpression<'a> {
    pub fn new(allocator: &'a Bump, callee: Callee, loc: SourceLocation) -> Self {
        Self {
            callee,
            arguments: Vec::new_in(allocator),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::JsCallExpression
    }
}

/// Callee type
#[derive(Debug)]
pub enum Callee {
    String(String),
    Symbol(RuntimeHelper),
}

/// Call argument type
#[derive(Debug)]
pub enum CallArgument<'a> {
    String(String),
    Symbol(RuntimeHelper),
    JsChild(JsChildNode<'a>),
    TemplateChild(TemplateChildNode<'a>),
    TemplateChildren(Vec<'a, TemplateChildNode<'a>>),
}

/// Object expression
#[derive(Debug)]
pub struct ObjectExpression<'a> {
    pub properties: Vec<'a, Property<'a>>,
    pub loc: SourceLocation,
}

impl<'a> ObjectExpression<'a> {
    pub fn new(allocator: &'a Bump, loc: SourceLocation) -> Self {
        Self {
            properties: Vec::new_in(allocator),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::JsObjectExpression
    }
}

/// Object property
#[derive(Debug)]
pub struct Property<'a> {
    pub key: ExpressionNode<'a>,
    pub value: JsChildNode<'a>,
    pub loc: SourceLocation,
}

impl<'a> Property<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsProperty
    }
}

/// Array expression
#[derive(Debug)]
pub struct ArrayExpression<'a> {
    pub elements: Vec<'a, ArrayElement<'a>>,
    pub loc: SourceLocation,
}

impl<'a> ArrayExpression<'a> {
    pub fn new(allocator: &'a Bump, loc: SourceLocation) -> Self {
        Self {
            elements: Vec::new_in(allocator),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::JsArrayExpression
    }
}

/// Array element type
#[derive(Debug)]
pub enum ArrayElement<'a> {
    String(String),
    Node(JsChildNode<'a>),
}

/// Function expression
#[derive(Debug)]
pub struct FunctionExpression<'a> {
    pub params: Option<FunctionParams<'a>>,
    pub returns: Option<FunctionReturns<'a>>,
    pub body: Option<FunctionBody<'a>>,
    pub newline: bool,
    pub is_slot: bool,
    pub is_non_scoped_slot: bool,
    pub loc: SourceLocation,
}

impl<'a> FunctionExpression<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsFunctionExpression
    }
}

/// Function parameters
#[derive(Debug)]
pub enum FunctionParams<'a> {
    Single(ExpressionNode<'a>),
    String(String),
    Multiple(Vec<'a, FunctionParam<'a>>),
}

/// Single function parameter
#[derive(Debug)]
pub enum FunctionParam<'a> {
    Expression(ExpressionNode<'a>),
    String(String),
}

/// Function returns
#[derive(Debug)]
pub enum FunctionReturns<'a> {
    Single(TemplateChildNode<'a>),
    Multiple(Vec<'a, TemplateChildNode<'a>>),
    JsChild(JsChildNode<'a>),
}

/// Function body
#[derive(Debug)]
pub enum FunctionBody<'a> {
    Block(Box<'a, BlockStatement<'a>>),
    If(Box<'a, IfStatement<'a>>),
}

/// Conditional expression (ternary)
#[derive(Debug)]
pub struct ConditionalExpression<'a> {
    pub test: JsChildNode<'a>,
    pub consequent: JsChildNode<'a>,
    pub alternate: JsChildNode<'a>,
    pub newline: bool,
    pub loc: SourceLocation,
}

impl<'a> ConditionalExpression<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsConditionalExpression
    }
}

/// Cache expression
#[derive(Debug)]
pub struct CacheExpression<'a> {
    pub index: u32,
    pub value: JsChildNode<'a>,
    pub need_pause_tracking: bool,
    pub in_v_once: bool,
    pub need_array_spread: bool,
    pub loc: SourceLocation,
}

impl<'a> CacheExpression<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsCacheExpression
    }
}

// ============================================================================
// SSR Codegen Nodes
// ============================================================================

/// Block statement
#[derive(Debug)]
pub struct BlockStatement<'a> {
    pub body: Vec<'a, BlockStatementBody<'a>>,
    pub loc: SourceLocation,
}

impl<'a> BlockStatement<'a> {
    pub fn new(allocator: &'a Bump, loc: SourceLocation) -> Self {
        Self {
            body: Vec::new_in(allocator),
            loc,
        }
    }

    pub fn node_type(&self) -> NodeType {
        NodeType::JsBlockStatement
    }
}

/// Block statement body item
#[derive(Debug)]
pub enum BlockStatementBody<'a> {
    JsChild(JsChildNode<'a>),
    If(Box<'a, IfStatement<'a>>),
}

/// Template literal
#[derive(Debug)]
pub struct TemplateLiteral<'a> {
    pub elements: Vec<'a, TemplateLiteralElement<'a>>,
    pub loc: SourceLocation,
}

impl<'a> TemplateLiteral<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsTemplateLiteral
    }
}

/// Template literal element
#[derive(Debug)]
pub enum TemplateLiteralElement<'a> {
    String(String),
    JsChild(JsChildNode<'a>),
}

/// If statement (SSR)
#[derive(Debug)]
pub struct IfStatement<'a> {
    pub test: ExpressionNode<'a>,
    pub consequent: Box<'a, BlockStatement<'a>>,
    pub alternate: Option<IfStatementAlternate<'a>>,
    pub loc: SourceLocation,
}

impl<'a> IfStatement<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsIfStatement
    }
}

/// If statement alternate
#[derive(Debug)]
pub enum IfStatementAlternate<'a> {
    If(Box<'a, IfStatement<'a>>),
    Block(Box<'a, BlockStatement<'a>>),
    Return(Box<'a, ReturnStatement<'a>>),
}

/// Assignment expression
#[derive(Debug)]
pub struct AssignmentExpression<'a> {
    pub left: Box<'a, SimpleExpressionNode<'a>>,
    pub right: JsChildNode<'a>,
    pub loc: SourceLocation,
}

impl<'a> AssignmentExpression<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsAssignmentExpression
    }
}

/// Sequence expression
#[derive(Debug)]
pub struct SequenceExpression<'a> {
    pub expressions: Vec<'a, JsChildNode<'a>>,
    pub loc: SourceLocation,
}

impl<'a> SequenceExpression<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsSequenceExpression
    }
}

/// Return statement
#[derive(Debug)]
pub struct ReturnStatement<'a> {
    pub returns: ReturnValue<'a>,
    pub loc: SourceLocation,
}

impl<'a> ReturnStatement<'a> {
    pub fn node_type(&self) -> NodeType {
        NodeType::JsReturnStatement
    }
}

/// Return value type
#[derive(Debug)]
pub enum ReturnValue<'a> {
    Single(TemplateChildNode<'a>),
    Multiple(Vec<'a, TemplateChildNode<'a>>),
    JsChild(JsChildNode<'a>),
}