55//!
66//! Ported from Angular's `render3/r3_ast.ts`.
77
8- use oxc_allocator:: { Box , Vec } ;
8+ use oxc_allocator:: { Box , HashMap , Vec } ;
99use oxc_span:: { Atom , Span } ;
10- use rustc_hash:: FxHashMap ;
1110
1211use crate :: ast:: expression:: { ASTWithSource , AngularExpression , BindingType , ParsedEventType } ;
12+ use crate :: i18n:: ast:: IcuType ;
13+
14+ // ============================================================================
15+ // i18n Metadata
16+ // ============================================================================
17+
18+ /// i18n metadata attached to R3 nodes.
19+ #[ derive( Debug ) ]
20+ pub enum I18nMeta < ' a > {
21+ /// Root of an i18n message.
22+ Message ( I18nMessage < ' a > ) ,
23+ /// Part of a containing message.
24+ Node ( I18nNode < ' a > ) ,
25+ }
26+
27+ /// An i18n message containing translatable content.
28+ #[ derive( Debug ) ]
29+ pub struct I18nMessage < ' a > {
30+ /// Message AST nodes.
31+ pub nodes : Vec < ' a , I18nNode < ' a > > ,
32+ /// The meaning of the message (for disambiguation).
33+ pub meaning : Atom < ' a > ,
34+ /// Description of the message for translators.
35+ pub description : Atom < ' a > ,
36+ /// Custom ID specified by the developer.
37+ pub custom_id : Atom < ' a > ,
38+ /// The computed message ID.
39+ pub id : Atom < ' a > ,
40+ /// Legacy IDs for backwards compatibility.
41+ pub legacy_ids : Vec < ' a , Atom < ' a > > ,
42+ }
43+
44+ /// i18n AST node.
45+ #[ derive( Debug ) ]
46+ pub enum I18nNode < ' a > {
47+ /// Plain text content.
48+ Text ( I18nText < ' a > ) ,
49+ /// Container for child nodes.
50+ Container ( I18nContainer < ' a > ) ,
51+ /// ICU expression (plural, select, selectordinal).
52+ Icu ( I18nIcu < ' a > ) ,
53+ /// HTML tag placeholder.
54+ TagPlaceholder ( I18nTagPlaceholder < ' a > ) ,
55+ /// Expression placeholder.
56+ Placeholder ( I18nPlaceholder < ' a > ) ,
57+ /// ICU placeholder (nested ICU reference).
58+ IcuPlaceholder ( I18nIcuPlaceholder < ' a > ) ,
59+ /// Control flow block placeholder.
60+ BlockPlaceholder ( I18nBlockPlaceholder < ' a > ) ,
61+ }
62+
63+ /// Plain text content.
64+ #[ derive( Debug ) ]
65+ pub struct I18nText < ' a > {
66+ /// The text value.
67+ pub value : Atom < ' a > ,
68+ /// Source span.
69+ pub source_span : Span ,
70+ }
71+
72+ /// Container for child nodes.
73+ #[ derive( Debug ) ]
74+ pub struct I18nContainer < ' a > {
75+ /// Child nodes.
76+ pub children : Vec < ' a , I18nNode < ' a > > ,
77+ /// Source span.
78+ pub source_span : Span ,
79+ }
80+
81+ /// ICU expression (plural, select, selectordinal).
82+ #[ derive( Debug ) ]
83+ pub struct I18nIcu < ' a > {
84+ /// The expression being evaluated.
85+ pub expression : Atom < ' a > ,
86+ /// ICU type (plural, select, selectordinal).
87+ pub icu_type : IcuType ,
88+ /// Case branches.
89+ pub cases : HashMap < ' a , Atom < ' a > , I18nNode < ' a > > ,
90+ /// Source span.
91+ pub source_span : Span ,
92+ /// Expression placeholder name (for message serialization).
93+ pub expression_placeholder : Option < Atom < ' a > > ,
94+ }
95+
96+ /// HTML tag placeholder.
97+ #[ derive( Debug ) ]
98+ pub struct I18nTagPlaceholder < ' a > {
99+ /// Tag name.
100+ pub tag : Atom < ' a > ,
101+ /// Tag attributes.
102+ pub attrs : HashMap < ' a , Atom < ' a > , Atom < ' a > > ,
103+ /// Start tag placeholder name.
104+ pub start_name : Atom < ' a > ,
105+ /// Close tag placeholder name.
106+ pub close_name : Atom < ' a > ,
107+ /// Child nodes.
108+ pub children : Vec < ' a , I18nNode < ' a > > ,
109+ /// Whether this is a void element.
110+ pub is_void : bool ,
111+ /// Source span (overall).
112+ pub source_span : Span ,
113+ /// Start tag source span.
114+ pub start_source_span : Option < Span > ,
115+ /// End tag source span.
116+ pub end_source_span : Option < Span > ,
117+ }
118+
119+ /// Expression placeholder.
120+ #[ derive( Debug ) ]
121+ pub struct I18nPlaceholder < ' a > {
122+ /// The expression value.
123+ pub value : Atom < ' a > ,
124+ /// Placeholder name.
125+ pub name : Atom < ' a > ,
126+ /// Source span.
127+ pub source_span : Span ,
128+ }
129+
130+ /// ICU placeholder (reference to a nested ICU).
131+ #[ derive( Debug ) ]
132+ pub struct I18nIcuPlaceholder < ' a > {
133+ /// The ICU expression.
134+ pub value : Box < ' a , I18nIcu < ' a > > ,
135+ /// Placeholder name.
136+ pub name : Atom < ' a > ,
137+ /// Source span.
138+ pub source_span : Span ,
139+ }
140+
141+ /// Control flow block placeholder.
142+ #[ derive( Debug ) ]
143+ pub struct I18nBlockPlaceholder < ' a > {
144+ /// Block name.
145+ pub name : Atom < ' a > ,
146+ /// Block parameters.
147+ pub parameters : Vec < ' a , Atom < ' a > > ,
148+ /// Start block placeholder name.
149+ pub start_name : Atom < ' a > ,
150+ /// End block placeholder name.
151+ pub close_name : Atom < ' a > ,
152+ /// Child nodes.
153+ pub children : Vec < ' a , I18nNode < ' a > > ,
154+ /// Source span (overall).
155+ pub source_span : Span ,
156+ /// Start block source span.
157+ pub start_source_span : Option < Span > ,
158+ /// End block source span.
159+ pub end_source_span : Option < Span > ,
160+ }
13161
14162// ============================================================================
15163// Core Node Enum
@@ -873,9 +1021,9 @@ pub struct R3Directive<'a> {
8731021#[ derive( Debug ) ]
8741022pub struct R3Icu < ' a > {
8751023 /// Variable expressions.
876- pub vars : FxHashMap < Atom < ' a > , R3BoundText < ' a > > ,
1024+ pub vars : HashMap < ' a , Atom < ' a > , R3BoundText < ' a > > ,
8771025 /// Placeholder expressions.
878- pub placeholders : FxHashMap < Atom < ' a > , R3IcuPlaceholder < ' a > > ,
1026+ pub placeholders : HashMap < ' a , Atom < ' a > , R3IcuPlaceholder < ' a > > ,
8791027 /// Source span.
8801028 pub source_span : Span ,
8811029 /// i18n metadata.
@@ -891,25 +1039,6 @@ pub enum R3IcuPlaceholder<'a> {
8911039 BoundText ( R3BoundText < ' a > ) ,
8921040}
8931041
894- // ============================================================================
895- // i18n
896- // ============================================================================
897-
898- /// i18n metadata for internationalization.
899- #[ derive( Debug ) ]
900- pub struct I18nMeta < ' a > {
901- /// Message ID.
902- pub id : Option < Atom < ' a > > ,
903- /// Custom ID.
904- pub custom_id : Option < Atom < ' a > > ,
905- /// Legacy ID list.
906- pub legacy_ids : Vec < ' a , Atom < ' a > > ,
907- /// Description.
908- pub description : Option < Atom < ' a > > ,
909- /// Meaning.
910- pub meaning : Option < Atom < ' a > > ,
911- }
912-
9131042// ============================================================================
9141043// Visitor
9151044// ============================================================================
0 commit comments