@@ -44,6 +44,7 @@ import {
4444 IfBlockNode ,
4545 Node ,
4646 OptionsNode ,
47+ StyleDirectiveNode ,
4748 TextNode ,
4849} from './nodes' ;
4950
@@ -572,6 +573,28 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
572573 ? ''
573574 : concat ( [ '=' , ...printJsExpression ( ) ] ) ,
574575 ] ) ;
576+ case 'StyleDirective' :
577+ if ( isOrCanBeConvertedToShorthand ( node ) ) {
578+ if ( options . svelteStrictMode ) {
579+ return concat ( [ line , 'style:' , node . name , '="{' , node . name , '}"' ] ) ;
580+ } else if ( options . svelteAllowShorthand ) {
581+ return concat ( [ line , 'style:' , node . name ] ) ;
582+ } else {
583+ return concat ( [ line , 'style:' , node . name , '={' , node . name , '}' ] ) ;
584+ }
585+ } else {
586+ if ( node . value === true ) {
587+ return concat ( [ line , 'style:' , node . name ] ) ;
588+ }
589+
590+ const quotes = ! isLoneMustacheTag ( node . value ) || options . svelteStrictMode ;
591+ const attrNodeValue = printAttributeNodeValue ( path , print , quotes , node ) ;
592+ if ( quotes ) {
593+ return concat ( [ line , 'style:' , node . name , '=' , '"' , attrNodeValue , '"' ] ) ;
594+ } else {
595+ return concat ( [ line , 'style:' , node . name , '=' , attrNodeValue ] ) ;
596+ }
597+ }
575598 case 'Let' :
576599 return concat ( [
577600 line ,
@@ -732,7 +755,7 @@ function printAttributeNodeValue(
732755 path : FastPath < any > ,
733756 print : PrintFn ,
734757 quotes : boolean ,
735- node : AttributeNode ,
758+ node : AttributeNode | StyleDirectiveNode ,
736759) {
737760 const valueDocs = path . map ( ( childPath ) => childPath . call ( print ) , 'value' ) ;
738761
0 commit comments