@@ -14,6 +14,7 @@ import Animation from './Animation';
1414import Action from './Action' ;
1515import { string_literal } from '../utils/stringify' ;
1616import { Literal } from 'estree' ;
17+ import Text from './Text' ;
1718
1819export default class DynamicElement extends Node {
1920 type : 'DynamicElement' ;
@@ -30,6 +31,7 @@ export default class DynamicElement extends Node {
3031 animation ?: Animation = null ;
3132 children : INode [ ] ;
3233 scope : TemplateScope ;
34+ needs_manual_style_scoping : boolean ;
3335
3436 constructor ( component : Component , parent , scope , info ) {
3537 super ( component , parent , scope , info ) ;
@@ -96,4 +98,37 @@ export default class DynamicElement extends Node {
9698
9799 this . children = map_children ( component , this , this . scope , info . children ) ;
98100 }
101+
102+ add_css_class ( ) {
103+ if ( this . attributes . some ( attr => attr . is_spread ) ) {
104+ this . needs_manual_style_scoping = true ;
105+ return ;
106+ }
107+
108+ const { id } = this . component . stylesheet ;
109+
110+ const class_attribute = this . attributes . find ( a => a . name === 'class' ) ;
111+
112+ if ( class_attribute && ! class_attribute . is_true ) {
113+ if ( class_attribute . chunks . length === 1 && class_attribute . chunks [ 0 ] . type === 'Text' ) {
114+ ( class_attribute . chunks [ 0 ] as Text ) . data += ` ${ id } ` ;
115+ } else {
116+ ( class_attribute . chunks as Node [ ] ) . push (
117+ new Text ( this . component , this , this . scope , {
118+ type : 'Text' ,
119+ data : ` ${ id } ` ,
120+ synthetic : true
121+ } as any )
122+ ) ;
123+ }
124+ } else {
125+ this . attributes . push (
126+ new Attribute ( this . component , this , this . scope , {
127+ type : 'Attribute' ,
128+ name : 'class' ,
129+ value : [ { type : 'Text' , data : id , synthetic : true } ]
130+ } as any )
131+ ) ;
132+ }
133+ }
99134}
0 commit comments