@@ -178,6 +178,9 @@ export class Evaluator {
178
178
case ts . SyntaxKind . NullKeyword :
179
179
case ts . SyntaxKind . TrueKeyword :
180
180
case ts . SyntaxKind . FalseKeyword :
181
+ case ts . SyntaxKind . TemplateHead :
182
+ case ts . SyntaxKind . TemplateMiddle :
183
+ case ts . SyntaxKind . TemplateTail :
181
184
return true ;
182
185
case ts . SyntaxKind . ParenthesizedExpression :
183
186
const parenthesizedExpression = < ts . ParenthesizedExpression > node ;
@@ -211,6 +214,10 @@ export class Evaluator {
211
214
return true ;
212
215
}
213
216
break ;
217
+ case ts . SyntaxKind . TemplateExpression :
218
+ const templateExpression = < ts . TemplateExpression > node ;
219
+ return templateExpression . templateSpans . every (
220
+ span => this . isFoldableWorker ( span . expression , folding ) ) ;
214
221
}
215
222
}
216
223
return false ;
@@ -436,9 +443,11 @@ export class Evaluator {
436
443
}
437
444
return recordEntry ( typeReference , node ) ;
438
445
case ts . SyntaxKind . NoSubstitutionTemplateLiteral :
439
- return ( < ts . LiteralExpression > node ) . text ;
440
446
case ts . SyntaxKind . StringLiteral :
441
- return ( < ts . StringLiteral > node ) . text ;
447
+ case ts . SyntaxKind . TemplateHead :
448
+ case ts . SyntaxKind . TemplateTail :
449
+ case ts . SyntaxKind . TemplateMiddle :
450
+ return ( < ts . LiteralLikeNode > node ) . text ;
442
451
case ts . SyntaxKind . NumericLiteral :
443
452
return parseFloat ( ( < ts . LiteralExpression > node ) . text ) ;
444
453
case ts . SyntaxKind . AnyKeyword :
@@ -575,6 +584,36 @@ export class Evaluator {
575
584
case ts . SyntaxKind . FunctionExpression :
576
585
case ts . SyntaxKind . ArrowFunction :
577
586
return recordEntry ( errorSymbol ( 'Function call not supported' , node ) , node ) ;
587
+ case ts . SyntaxKind . TaggedTemplateExpression :
588
+ return recordEntry (
589
+ errorSymbol ( 'Tagged template expressions are not supported in metadata' , node ) , node ) ;
590
+ case ts . SyntaxKind . TemplateExpression :
591
+ const templateExpression = < ts . TemplateExpression > node ;
592
+ if ( this . isFoldable ( node ) ) {
593
+ return templateExpression . templateSpans . reduce (
594
+ ( previous , current ) => previous + < string > this . evaluateNode ( current . expression ) +
595
+ < string > this . evaluateNode ( current . literal ) ,
596
+ this . evaluateNode ( templateExpression . head ) ) ;
597
+ } else {
598
+ return templateExpression . templateSpans . reduce ( ( previous , current ) => {
599
+ const expr = this . evaluateNode ( current . expression ) ;
600
+ const literal = this . evaluateNode ( current . literal ) ;
601
+ if ( isFoldableError ( expr ) ) return expr ;
602
+ if ( isFoldableError ( literal ) ) return literal ;
603
+ if ( typeof previous === 'string' && typeof expr === 'string' &&
604
+ typeof literal === 'string' ) {
605
+ return previous + expr + literal ;
606
+ }
607
+ let result = expr ;
608
+ if ( previous !== '' ) {
609
+ result = { __symbolic : 'binop' , operator : '+' , left : previous , right : expr } ;
610
+ }
611
+ if ( literal != '' ) {
612
+ result = { __symbolic : 'binop' , operator : '+' , left : result , right : literal } ;
613
+ }
614
+ return result ;
615
+ } , this . evaluateNode ( templateExpression . head ) ) ;
616
+ }
578
617
}
579
618
return recordEntry ( errorSymbol ( 'Expression form not supported' , node ) , node ) ;
580
619
}
0 commit comments