@@ -1637,6 +1637,10 @@ function doRender(data, options, reducer, level = 0, indents = []) {
16371637 str = options . removeComments ? '' : node . val ;
16381638 }
16391639 else if ( node . typ == 'Declaration' ) {
1640+ if ( node . val . length == 0 ) {
1641+ console . error ( `invalid declaration` , node ) ;
1642+ return '' ;
1643+ }
16401644 str = `${ node . nam } :${ options . indent } ${ node . val . reduce ( reducer , '' ) . trimEnd ( ) } ;` ;
16411645 }
16421646 else if ( node . typ == 'AtRule' && ! ( 'chi' in node ) ) {
@@ -2029,6 +2033,9 @@ class PropertyMap {
20292033 this . pattern = config . pattern . split ( / \s / ) ;
20302034 }
20312035 add ( declaration ) {
2036+ for ( const val of declaration . val ) {
2037+ Object . defineProperty ( val , 'propertyName' , { enumerable : false , writable : true , value : declaration . nam } ) ;
2038+ }
20322039 if ( declaration . nam == this . config . shorthand ) {
20332040 this . declarations = new Map ;
20342041 this . declarations . set ( declaration . nam , declaration ) ;
@@ -2062,7 +2069,7 @@ class PropertyMap {
20622069 i -- ;
20632070 continue ;
20642071 }
2065- if ( matchType ( acc [ i ] , props ) ) {
2072+ if ( ( 'propertyName' in acc [ i ] && acc [ i ] . propertyName == property ) || matchType ( acc [ i ] , props ) ) {
20662073 if ( 'prefix' in props && props . previous != null && ! ( props . previous in tokens ) ) {
20672074 return acc ;
20682075 }
@@ -2196,10 +2203,12 @@ class PropertyMap {
21962203 }
21972204 else {
21982205 let count = 0 ;
2206+ let match ;
21992207 const separator = this . config . separator ;
22002208 const tokens = { } ;
22012209 // @ts -ignore
2202- /* const valid: string[] =*/ Object . entries ( this . config . properties ) . reduce ( ( acc , curr ) => {
2210+ /* const valid: string[] =*/
2211+ Object . entries ( this . config . properties ) . reduce ( ( acc , curr ) => {
22032212 if ( ! this . declarations . has ( curr [ 0 ] ) ) {
22042213 if ( curr [ 1 ] . required ) {
22052214 acc . push ( curr [ 0 ] ) ;
@@ -2208,33 +2217,39 @@ class PropertyMap {
22082217 }
22092218 let current = 0 ;
22102219 const props = this . config . properties [ curr [ 0 ] ] ;
2211- const declaration = this . declarations . get ( curr [ 0 ] ) ;
2212- // @ts -ignore
2213- for ( const val of ( declaration instanceof PropertySet ? [ ...declaration ] [ 0 ] : declaration ) . val ) {
2214- if ( separator != null && separator . typ == val . typ && eq ( separator , val ) ) {
2215- current ++ ;
2216- if ( tokens [ curr [ 0 ] ] . length == current ) {
2217- tokens [ curr [ 0 ] ] . push ( [ ] ) ;
2220+ const properties = this . declarations . get ( curr [ 0 ] ) ;
2221+ for ( const declaration of [ ( properties instanceof PropertySet ? [ ...properties ] [ 0 ] : properties ) ] ) {
2222+ // @ts -ignore
2223+ for ( const val of declaration . val ) {
2224+ if ( separator != null && separator . typ == val . typ && eq ( separator , val ) ) {
2225+ current ++ ;
2226+ if ( tokens [ curr [ 0 ] ] . length == current ) {
2227+ tokens [ curr [ 0 ] ] . push ( [ ] ) ;
2228+ }
2229+ continue ;
22182230 }
2219- continue ;
2220- }
2221- if ( val . typ == 'Whitespace' || val . typ == 'Comment' ) {
2222- continue ;
2223- }
2224- if ( props . multiple && props . separator != null && props . separator . typ == val . typ && eq ( props . separator , val ) ) {
2225- continue ;
2226- }
2227- if ( matchType ( val , curr [ 1 ] ) ) {
2228- if ( ! ( curr [ 0 ] in tokens ) ) {
2229- tokens [ curr [ 0 ] ] = [ [ ] ] ;
2231+ if ( val . typ == 'Whitespace' || val . typ == 'Comment' ) {
2232+ continue ;
2233+ }
2234+ if ( props . multiple && props . separator != null && props . separator . typ == val . typ && eq ( props . separator , val ) ) {
2235+ continue ;
2236+ }
2237+ match = matchType ( val , curr [ 1 ] ) ;
2238+ if ( isShorthand ) {
2239+ isShorthand = match ;
2240+ }
2241+ if ( ( 'propertyName' in val && val . propertyName == property ) || match ) {
2242+ if ( ! ( curr [ 0 ] in tokens ) ) {
2243+ tokens [ curr [ 0 ] ] = [ [ ] ] ;
2244+ }
2245+ // is default value
2246+ tokens [ curr [ 0 ] ] [ current ] . push ( val ) ;
2247+ // continue;
2248+ }
2249+ else {
2250+ acc . push ( curr [ 0 ] ) ;
2251+ break ;
22302252 }
2231- // is default value
2232- tokens [ curr [ 0 ] ] [ current ] . push ( val ) ;
2233- // continue;
2234- }
2235- else {
2236- acc . push ( curr [ 0 ] ) ;
2237- break ;
22382253 }
22392254 }
22402255 if ( count == 0 ) {
@@ -2243,7 +2258,7 @@ class PropertyMap {
22432258 return acc ;
22442259 } , [ ] ) ;
22452260 count ++ ;
2246- if ( Object . entries ( this . config . properties ) . some ( entry => {
2261+ if ( ! isShorthand || Object . entries ( this . config . properties ) . some ( entry => {
22472262 // missing required property
22482263 return entry [ 1 ] . required && ! ( entry [ 0 ] in tokens ) ;
22492264 } ) || ! Object . values ( tokens ) . every ( v => v . length == count ) ) {
0 commit comments