@@ -1203,27 +1203,31 @@ export async function applyHtmlTransforms(
1203
1203
tags = res . tags
1204
1204
}
1205
1205
1206
- const headTags : HtmlTagDescriptor [ ] = [ ]
1207
- const headPrependTags : HtmlTagDescriptor [ ] = [ ]
1208
- const bodyTags : HtmlTagDescriptor [ ] = [ ]
1209
- const bodyPrependTags : HtmlTagDescriptor [ ] = [ ]
1206
+ let headTags : HtmlTagDescriptor [ ] | undefined
1207
+ let headPrependTags : HtmlTagDescriptor [ ] | undefined
1208
+ let bodyTags : HtmlTagDescriptor [ ] | undefined
1209
+ let bodyPrependTags : HtmlTagDescriptor [ ] | undefined
1210
1210
1211
1211
for ( const tag of tags ) {
1212
- if ( tag . injectTo === 'body' ) {
1213
- bodyTags . push ( tag )
1214
- } else if ( tag . injectTo === 'body-prepend' ) {
1215
- bodyPrependTags . push ( tag )
1216
- } else if ( tag . injectTo === 'head' ) {
1217
- headTags . push ( tag )
1218
- } else {
1219
- headPrependTags . push ( tag )
1212
+ switch ( tag . injectTo ) {
1213
+ case 'body' :
1214
+ ; ( bodyTags ??= [ ] ) . push ( tag )
1215
+ break
1216
+ case 'body-prepend' :
1217
+ ; ( bodyPrependTags ??= [ ] ) . push ( tag )
1218
+ break
1219
+ case 'head' :
1220
+ ; ( headTags ??= [ ] ) . push ( tag )
1221
+ break
1222
+ default :
1223
+ ; ( headPrependTags ??= [ ] ) . push ( tag )
1220
1224
}
1221
1225
}
1222
1226
1223
- html = injectToHead ( html , headPrependTags , true )
1224
- html = injectToHead ( html , headTags )
1225
- html = injectToBody ( html , bodyPrependTags , true )
1226
- html = injectToBody ( html , bodyTags )
1227
+ if ( headPrependTags ) html = injectToHead ( html , headPrependTags , true )
1228
+ if ( headTags ) html = injectToHead ( html , headTags )
1229
+ if ( bodyPrependTags ) html = injectToBody ( html , bodyPrependTags , true )
1230
+ if ( bodyTags ) html = injectToBody ( html , bodyTags )
1227
1231
}
1228
1232
}
1229
1233
0 commit comments