@@ -14,11 +14,20 @@ import * as debugGenerator from "debug";
14
14
import { GlimmerAnalysis } from "./Analyzer" ;
15
15
import { getEmberBuiltInStates , isEmberBuiltIn } from "./EmberBuiltins" ;
16
16
import { ResolvedFile } from "./Template" ;
17
- import { cssBlockError } from "./utils" ;
17
+ import {
18
+ cssBlockError ,
19
+ isBooleanLiteral ,
20
+ isConcatStatement ,
21
+ isElementNode ,
22
+ isMustacheStatement ,
23
+ isStringLiteral ,
24
+ isSubExpression ,
25
+ isTextNode ,
26
+ } from "./utils" ;
18
27
19
28
// Expressions may be null when ElementAnalyzer is used in the second pass analysis
20
29
// to re-acquire analysis data for rewrites without storing AST nodes.
21
- export type TernaryExpression = AST . Expression | null ;
30
+ export type TernaryExpression = AST . Expression | AST . MustacheStatement | null ;
22
31
export type StringExpression = AST . MustacheStatement | AST . ConcatStatement | null ;
23
32
export type BooleanExpression = AST . Expression | AST . MustacheStatement ;
24
33
export type TemplateElement = ElementAnalysis < BooleanExpression , StringExpression , TernaryExpression > ;
@@ -309,6 +318,14 @@ export class ElementAnalyzer {
309
318
if ( value . value ) {
310
319
element . addStaticClass ( block . rootClass ) ;
311
320
}
321
+ } else if ( isMustacheStatement ( value ) || isSubExpression ( value ) ) {
322
+ // We don't have a way to represent a simple boolean conditional for classes like we do for states.
323
+ // The rewrite might be slightly simpler if we add that.
324
+ element . addDynamicClasses ( {
325
+ condition : value ,
326
+ whenTrue : [ block . rootClass ] ,
327
+ whenFalse : [ ] ,
328
+ } ) ;
312
329
}
313
330
}
314
331
@@ -393,28 +410,6 @@ export class ElementAnalyzer {
393
410
}
394
411
}
395
412
396
- function isStringLiteral ( value : AST . Node | undefined ) : value is AST . StringLiteral {
397
- return value !== undefined && value . type === "StringLiteral" ;
398
- }
399
- function isConcatStatement ( value : AST . Node | undefined ) : value is AST . ConcatStatement {
400
- return ! ! value && value . type === "ConcatStatement" ;
401
- }
402
- function isTextNode ( value : AST . Node | undefined ) : value is AST . TextNode {
403
- return ! ! value && value . type === "TextNode" ;
404
- }
405
- function isBooleanLiteral ( value : AST . Node | undefined ) : value is AST . BooleanLiteral {
406
- return ! ! value && value . type === "BooleanLiteral" ;
407
- }
408
- function isMustacheStatement ( value : AST . Node | undefined ) : value is AST . MustacheStatement {
409
- return ! ! value && value . type === "MustacheStatement" ;
410
- }
411
- function isSubExpression ( value : AST . Node | undefined ) : value is AST . SubExpression {
412
- return ! ! value && value . type === "SubExpression" ;
413
- }
414
- function isElementNode ( value : AST . Node | undefined ) : value is AST . ElementNode {
415
- return ! ! value && value . type === "ElementNode" ;
416
- }
417
-
418
413
function isStyleIfHelper ( node : AST . MustacheStatement | AST . SubExpression ) : "style-if" | "style-unless" | undefined {
419
414
if ( node . path . type !== "PathExpression" ) { return undefined ; }
420
415
let parts : string [ ] = ( node . path ) . parts ;
0 commit comments