@@ -89,15 +89,16 @@ export function to_class(value, hash, directives) {
8989 * @param {boolean } important
9090 */
9191function append_styles ( styles , important = false ) {
92- let separator = important ? ' !important;' : ';' ;
93- let css = '' ;
92+ var separator = important ? ' !important;' : ';' ;
93+ var css = '' ;
9494
95- for ( const key in styles ) {
96- const value = styles [ key ] ;
95+ for ( var key in styles ) {
96+ var value = styles [ key ] ;
9797 if ( value != null && value !== '' ) {
9898 css += ' ' + key + ': ' + value + separator ;
9999 }
100100 }
101+
101102 return css ;
102103}
103104
@@ -114,22 +115,26 @@ function to_css_name(name) {
114115
115116/**
116117 * @param {any } value
117- * @param {Record<string,any>| [Record<string,any>,Record<string,any>] } [styles]
118- * @returns {string| null }
118+ * @param {Record<string, any> | [Record<string, any>, Record<string, any>] } [styles]
119+ * @returns {string | null }
119120 */
120121export function to_style ( value , styles ) {
121122 if ( styles ) {
122123 var new_style = '' ;
124+
123125 /** @type {Record<string,any> | undefined } */
124126 var normal_styles ;
127+
125128 /** @type {Record<string,any> | undefined } */
126129 var important_styles ;
130+
127131 if ( Array . isArray ( styles ) ) {
128132 normal_styles = styles [ 0 ] ;
129133 important_styles = styles [ 1 ] ;
130134 } else {
131135 normal_styles = styles ;
132136 }
137+
133138 if ( value ) {
134139 value = String ( value )
135140 . replaceAll ( / \s * \/ \* .* ?\* \/ \s * / g, '' )
@@ -141,6 +146,7 @@ export function to_style(value, styles) {
141146 var in_comment = false ;
142147
143148 var reserved_names = [ ] ;
149+
144150 if ( normal_styles ) {
145151 reserved_names . push ( ...Object . keys ( normal_styles ) . map ( to_css_name ) ) ;
146152 }
@@ -150,6 +156,7 @@ export function to_style(value, styles) {
150156
151157 var start_index = 0 ;
152158 var name_index = - 1 ;
159+
153160 const len = value . length ;
154161 for ( var i = 0 ; i < len ; i ++ ) {
155162 var c = value [ i ] ;
@@ -171,20 +178,24 @@ export function to_style(value, styles) {
171178 } else if ( c === ')' ) {
172179 in_apo -- ;
173180 }
181+
174182 if ( ! in_comment && in_str === false && in_apo === 0 ) {
175- if ( c === ':' && name_index < 0 ) {
183+ if ( c === ':' && name_index === - 1 ) {
176184 name_index = i ;
177185 } else if ( c === ';' || i === len - 1 ) {
178- if ( name_index > 0 ) {
179- let name = to_css_name ( value . substring ( start_index , name_index ) . trim ( ) ) ;
186+ if ( name_index !== - 1 ) {
187+ var name = to_css_name ( value . substring ( start_index , name_index ) . trim ( ) ) ;
188+
180189 if ( ! reserved_names . includes ( name ) ) {
181190 if ( c !== ';' ) {
182191 i ++ ;
183192 }
184- const property = value . substring ( start_index , i ) . trim ( ) ;
193+
194+ var property = value . substring ( start_index , i ) . trim ( ) ;
185195 new_style += ' ' + property + ';' ;
186196 }
187197 }
198+
188199 start_index = i + 1 ;
189200 name_index = - 1 ;
190201 }
@@ -195,13 +206,14 @@ export function to_style(value, styles) {
195206 if ( normal_styles ) {
196207 new_style += append_styles ( normal_styles ) ;
197208 }
209+
198210 if ( important_styles ) {
199211 new_style += append_styles ( important_styles , true ) ;
200212 }
213+
201214 new_style = new_style . trim ( ) ;
202215 return new_style === '' ? null : new_style ;
203- } else if ( value == null ) {
204- return null ;
205216 }
206- return String ( value ) ;
217+
218+ return value == null ? null : String ( value ) ;
207219}
0 commit comments