@@ -37,7 +37,7 @@ export class RuntimeDataGenerator {
37
37
}
38
38
sourceClassIndex ( className : string ) : number {
39
39
if ( ! this . sourceClassIndices . has ( className ) ) {
40
- this . sourceClassIndices . set ( className , this . sourceClassIndices . size ) ;
40
+ throw new Error ( "[internal error] unknown class" ) ;
41
41
}
42
42
return this . sourceClassIndices . get ( className ) ! ;
43
43
}
@@ -78,6 +78,7 @@ export class RuntimeDataGenerator {
78
78
debug ( `There are ${ stylesInUse . size } styles in use.` ) ;
79
79
let styleRequirements : StyleRequirements = { } ;
80
80
for ( let style of stylesInUse ) {
81
+ this . sourceClassIndices . set ( this . cssClass ( style ) , this . styleIndex ( style ) ) ;
81
82
if ( isAttrValue ( style ) ) {
82
83
styleRequirements [ this . styleIndex ( style ) ] = [ Operator . AND , this . styleIndex ( style . blockClass ) ] ;
83
84
}
@@ -105,10 +106,26 @@ export class RuntimeDataGenerator {
105
106
getOptimizations ( stylesInUse : Set < Style > ) : Array < OptimizationEntry > {
106
107
let optimizations = new Array < OptimizationEntry > ( ) ;
107
108
for ( let style of stylesInUse ) {
108
- if ( this . styleMapping . isStyledAfterOptimization ( { name : "class" , value : this . cssClass ( style ) } ) ) {
109
+ let attr = { name : "class" , value : this . cssClass ( style ) } ;
110
+ if ( this . styleMapping . isStyledAfterOptimization ( attr ) ) {
109
111
optimizations . push ( [ this . outputClassIndex ( style ) , this . styleIndex ( style ) ] ) ;
110
112
continue ;
111
113
}
114
+
115
+ if ( this . styleMapping . replacedAttributes . containsKey ( attr ) ) {
116
+ let replacedWith = this . styleMapping . replacedAttributes . getValue ( attr ) ! ;
117
+ optimizations . push ( [ this . outputClassIndex ( replacedWith . value ) , this . styleIndex ( style ) ] ) ;
118
+ continue ;
119
+ }
120
+
121
+ if ( this . styleMapping . linkedAttributes . containsKey ( attr ) ) {
122
+ let links = this . styleMapping . linkedAttributes . getValue ( attr ) ;
123
+ for ( let link of links ) {
124
+ let exceptions = link . unless . map ( u => this . sourceClassIndex ( ( < SimpleAttribute > u ) . value ) ) ;
125
+ let expr : AndStyleExpression = [ Operator . AND , this . styleIndex ( style ) , [ Operator . NOT , [ Operator . OR , ...exceptions ] ] ] ;
126
+ optimizations . push ( [ this . outputClassIndex ( link . to . value ) , expr ] ) ;
127
+ }
128
+ }
112
129
}
113
130
return optimizations ;
114
131
}
0 commit comments