@@ -40,9 +40,9 @@ namespace sourcemeta::codegen {
4040TypeScript::TypeScript (std::ostream &stream, const std::string_view type_prefix)
4141 : output{stream}, prefix{type_prefix} {}
4242
43- auto TypeScript::operator ()(const IRScalar &entry) const -> void {
43+ auto TypeScript::operator ()(const IRScalar &entry) -> void {
4444 this ->output << " export type "
45- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
45+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
4646 << " = " ;
4747
4848 switch (entry.value ) {
@@ -64,9 +64,9 @@ auto TypeScript::operator()(const IRScalar &entry) const -> void {
6464 this ->output << " ;\n " ;
6565}
6666
67- auto TypeScript::operator ()(const IREnumeration &entry) const -> void {
67+ auto TypeScript::operator ()(const IREnumeration &entry) -> void {
6868 this ->output << " export type "
69- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
69+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
7070 << " = " ;
7171
7272 const char *separator{" " };
@@ -79,19 +79,20 @@ auto TypeScript::operator()(const IREnumeration &entry) const -> void {
7979 this ->output << " ;\n " ;
8080}
8181
82- auto TypeScript::operator ()(const IRObject &entry) const -> void {
83- const auto type_name{sourcemeta::core::mangle (entry.pointer , this ->prefix )};
82+ auto TypeScript::operator ()(const IRObject &entry) -> void {
83+ const auto type_name{
84+ mangle (this ->prefix , entry.pointer , entry.symbol , this ->cache )};
8485 const auto has_typed_additional{
8586 std::holds_alternative<IRType>(entry.additional )};
8687 const auto allows_any_additional{
8788 std::holds_alternative<bool >(entry.additional ) &&
8889 std::get<bool >(entry.additional )};
8990
9091 if (has_typed_additional && entry.members .empty ()) {
92+ const auto &additional_type{std::get<IRType>(entry.additional )};
9193 this ->output << " export type " << type_name << " = Record<string, "
92- << sourcemeta::core::mangle (
93- std::get<IRType>(entry.additional ).pointer ,
94- this ->prefix )
94+ << mangle (this ->prefix , additional_type.pointer ,
95+ additional_type.symbol , this ->cache )
9596 << " >;\n " ;
9697 return ;
9798 }
@@ -117,7 +118,8 @@ auto TypeScript::operator()(const IRObject &entry) const -> void {
117118 this ->output << " " << readonly_marker << " \" "
118119 << escape_string (member_name) << " \" " << optional_marker
119120 << " : "
120- << sourcemeta::core::mangle (member_value.pointer , this ->prefix )
121+ << mangle (this ->prefix , member_value.pointer ,
122+ member_value.symbol , this ->cache )
121123 << " ;\n " ;
122124 }
123125
@@ -135,35 +137,36 @@ auto TypeScript::operator()(const IRObject &entry) const -> void {
135137 this ->output << " // match a superset of what JSON Schema allows\n " ;
136138 for (const auto &[member_name, member_value] : entry.members ) {
137139 this ->output << " "
138- << sourcemeta::core:: mangle (member_value.pointer ,
139- this ->prefix )
140+ << mangle (this -> prefix , member_value.pointer ,
141+ member_value. symbol , this ->cache )
140142 << " |\n " ;
141143 }
142144
145+ const auto &additional_type{std::get<IRType>(entry.additional )};
143146 this ->output << " "
144- << sourcemeta::core::mangle (
145- std::get<IRType>(entry.additional ).pointer ,
146- this ->prefix )
147+ << mangle (this ->prefix , additional_type.pointer ,
148+ additional_type.symbol , this ->cache )
147149 << " |\n " ;
148150 this ->output << " undefined;\n " ;
149151 }
150152
151153 this ->output << " }\n " ;
152154}
153155
154- auto TypeScript::operator ()(const IRImpossible &entry) const -> void {
156+ auto TypeScript::operator ()(const IRImpossible &entry) -> void {
155157 this ->output << " export type "
156- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
158+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
157159 << " = never;\n " ;
158160}
159161
160- auto TypeScript::operator ()(const IRArray &entry) const -> void {
162+ auto TypeScript::operator ()(const IRArray &entry) -> void {
161163 this ->output << " export type "
162- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
164+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
163165 << " = " ;
164166
165167 if (entry.items .has_value ()) {
166- this ->output << sourcemeta::core::mangle (entry.items ->pointer , this ->prefix )
168+ this ->output << mangle (this ->prefix , entry.items ->pointer ,
169+ entry.items ->symbol , this ->cache )
167170 << " []" ;
168171 } else {
169172 this ->output << " unknown[]" ;
@@ -172,44 +175,48 @@ auto TypeScript::operator()(const IRArray &entry) const -> void {
172175 this ->output << " ;\n " ;
173176}
174177
175- auto TypeScript::operator ()(const IRReference &entry) const -> void {
178+ auto TypeScript::operator ()(const IRReference &entry) -> void {
176179 this ->output << " export type "
177- << sourcemeta::core::mangle (entry.pointer , this ->prefix ) << " = "
178- << sourcemeta::core::mangle (entry.target .pointer , this ->prefix )
180+ << mangle (this ->prefix , entry.pointer , entry.symbol , this ->cache )
181+ << " = "
182+ << mangle (this ->prefix , entry.target .pointer ,
183+ entry.target .symbol , this ->cache )
179184 << " ;\n " ;
180185}
181186
182- auto TypeScript::operator ()(const IRTuple &entry) const -> void {
187+ auto TypeScript::operator ()(const IRTuple &entry) -> void {
183188 this ->output << " export type "
184- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
189+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
185190 << " = [" ;
186191
187192 const char *separator{" " };
188193 for (const auto &item : entry.items ) {
189194 this ->output << separator
190- << sourcemeta::core::mangle (item.pointer , this ->prefix );
195+ << mangle (this ->prefix , item.pointer , item.symbol ,
196+ this ->cache );
191197 separator = " , " ;
192198 }
193199
194200 if (entry.additional .has_value ()) {
195201 this ->output << separator << " ..."
196- << sourcemeta::core:: mangle (entry.additional ->pointer ,
197- this ->prefix )
202+ << mangle (this -> prefix , entry.additional ->pointer ,
203+ entry. additional -> symbol , this ->cache )
198204 << " []" ;
199205 }
200206
201207 this ->output << " ];\n " ;
202208}
203209
204- auto TypeScript::operator ()(const IRUnion &entry) const -> void {
210+ auto TypeScript::operator ()(const IRUnion &entry) -> void {
205211 this ->output << " export type "
206- << sourcemeta::core:: mangle (entry.pointer , this ->prefix )
212+ << mangle (this -> prefix , entry.pointer , entry. symbol , this ->cache )
207213 << " =\n " ;
208214
209215 const char *separator{" " };
210216 for (const auto &value : entry.values ) {
211217 this ->output << separator << " "
212- << sourcemeta::core::mangle (value.pointer , this ->prefix );
218+ << mangle (this ->prefix , value.pointer , value.symbol ,
219+ this ->cache );
213220 separator = " |\n " ;
214221 }
215222
0 commit comments