1
1
import postcss from 'postcss'
2
2
import merge from 'lodash.merge'
3
3
import isUrl from 'is-url-superb'
4
- import { walk } from 'posthtml/lib/api.js'
5
- import { parseSrcset , stringifySrcset } from 'srcset'
4
+ import { walk } from 'posthtml/lib/api.js'
5
+ import { parseSrcset , stringifySrcset } from 'srcset'
6
6
import postcssBaseUrl from './plugins/postcss-baseurl.js'
7
7
8
8
const defaultTags = {
@@ -94,30 +94,31 @@ const plugin = (options = {}) => tree => {
94
94
}
95
95
96
96
// Handle style attribute
97
- if ( node . attrs && node . attrs . style && options . inlineCss ) {
97
+ if ( node . attrs ? .style && options . inlineCss ) {
98
98
node . attrs . style = prependUrl ( node . attrs . style , options . url )
99
99
}
100
100
101
101
// Handle defined HTML attributes
102
- Object . entries ( options . attributes ) . forEach ( ( [ attribute , value ] ) => {
103
- if ( node . attrs && node . attrs [ attribute ] ) {
102
+ for ( const [ attribute , value ] of Object . entries ( options . attributes ) ) {
103
+ if ( node . attrs ?. [ attribute ] ) {
104
104
handleSingleValueAttributes ( node , attribute , value )
105
105
}
106
- } )
106
+ }
107
107
108
108
// Handle defined HTML tags
109
109
const tags = Array . isArray ( options . tags ) ?
110
110
Object . entries ( defaultTags ) . filter ( ( [ tag ] ) => options . tags . includes ( tag ) ) :
111
111
Object . entries ( options . tags )
112
112
113
+ // biome-ignore lint: fails with for...of
113
114
tags . forEach ( ( [ tag , attributes ] ) => {
114
115
if ( node . tag !== tag ) {
115
116
return node
116
117
}
117
118
118
119
// Handle tag attributes
119
- Object . entries ( attributes ) . forEach ( ( [ attribute , value ] ) => {
120
- if ( node . attrs && node . attrs [ attribute ] ) {
120
+ for ( const [ attribute , value ] of Object . entries ( attributes ) ) {
121
+ if ( node . attrs ?. [ attribute ] ) {
121
122
// Handle "single-value" attributes
122
123
if ( [ 'href' , 'src' , 'poster' , 'background' ] . includes ( attribute ) ) {
123
124
handleSingleValueAttributes ( node , attribute , value )
@@ -138,7 +139,7 @@ const plugin = (options = {}) => tree => {
138
139
node . attrs [ attribute ] = stringifySrcset ( parsed )
139
140
}
140
141
}
141
- } )
142
+ }
142
143
} )
143
144
144
145
// Return the node
0 commit comments