@@ -184,28 +184,33 @@ for (const [key, data] of yamlEntries('features')) {
184
184
}
185
185
186
186
// Assert that feature references are valid
187
+
188
+ function assertValidReference ( sourceID : string , targetID : string ) : void {
189
+ if ( targetID in features ) {
190
+ if ( isRedirectData ( features [ targetID ] ) ) {
191
+ throw new Error ( `${ sourceID } references a redirect "${ targetID } " instead of an ordinary feature ID` ) ;
192
+ }
193
+ return ;
194
+ }
195
+ throw new Error ( `${ sourceID } 's reference to "${ targetID } " is not a valid feature ID` ) ;
196
+ }
197
+
187
198
for ( const [ id , feature ] of Object . entries ( features ) ) {
188
199
if ( isOrdinaryFeatureData ( feature ) ) {
189
200
for ( const alternative of feature . discouraged ?. alternatives ?? [ ] ) {
190
- if ( ! ( alternative in features ) ) {
191
- throw new Error ( `${ id } 's alternative "${ alternative } " is not a valid feature ID` ) ;
192
- }
201
+ assertValidReference ( id , alternative ) ;
193
202
}
194
203
}
195
204
196
205
if ( isRedirectData ( feature ) ) {
197
206
const { reason } = feature . redirect ;
198
207
switch ( reason ) {
199
208
case 'moved' :
200
- if ( ! ( feature . redirect . target in features ) ) {
201
- throw new Error ( `${ id } 's redirect target "${ feature . redirect . target } is not a valid feature ID` ) ;
202
- }
209
+ assertValidReference ( id , feature . redirect . target ) ;
203
210
break ;
204
211
case 'split' :
205
212
for ( const target of feature . redirect . targets ) {
206
- if ( ! ( target in features ) ) {
207
- throw new Error ( `${ id } 's redirect target "${ target } " is not a valid feature ID` ) ;
208
- }
213
+ assertValidReference ( id , target ) ;
209
214
}
210
215
break ;
211
216
default :
0 commit comments