@@ -45,9 +45,11 @@ class I18NAttrVisitor extends BasicTemplateAstVisitor
4545
4646class I18NTextVisitor extends BasicTemplateAstVisitor
4747 implements ConfigurableVisitor {
48+ static Error = 'Each element containing text node should has an i18n attribute' ;
49+
4850 private hasI18n = false ;
4951 private nestedElements = [ ] ;
50- private visited = new Set < ast . TextAst > ( ) ;
52+ private visited = new Set < ast . TextAst | ast . BoundTextAst > ( ) ;
5153
5254 visitText ( text : ast . TextAst , context : BasicTemplateAstVisitor ) {
5355 if ( ! this . visited . has ( text ) ) {
@@ -62,14 +64,37 @@ class I18NTextVisitor extends BasicTemplateAstVisitor
6264 context . createFailure (
6365 span . start . offset ,
6466 span . end . offset - span . start . offset ,
65- 'Each element containing text node should has an i18n attribute'
67+ I18NTextVisitor . Error
6668 )
6769 ) ;
6870 }
6971 }
7072 super . visitText ( text , context ) ;
7173 }
7274
75+ visitBoundText ( text : ast . BoundTextAst , context : BasicTemplateAstVisitor ) {
76+ if ( ! this . visited . has ( text ) ) {
77+ this . visited . add ( text ) ;
78+ const val = text . value ;
79+ if (
80+ val instanceof ast . ASTWithSource &&
81+ val . ast instanceof ast . Interpolation
82+ ) {
83+ const textNonEmpty = val . ast . strings . some ( s => / \w + / . test ( s ) ) ;
84+ if ( textNonEmpty ) {
85+ const span = text . sourceSpan ;
86+ context . addFailure (
87+ context . createFailure (
88+ span . start . offset ,
89+ span . end . offset - span . start . offset ,
90+ I18NTextVisitor . Error
91+ )
92+ ) ;
93+ }
94+ }
95+ }
96+ }
97+
7398 visitElement ( element : ast . ElementAst , context : BasicTemplateAstVisitor ) {
7499 this . hasI18n = element . attrs . some ( e => e . name === 'i18n' ) ;
75100 this . nestedElements . push ( element . name ) ;
@@ -132,6 +157,16 @@ class I18NTemplateVisitor extends BasicTemplateAstVisitor {
132157 . forEach ( f => this . addFailure ( f ) ) ;
133158 super . visitText ( text , context ) ;
134159 }
160+
161+ visitBoundText ( text : ast . BoundTextAst , context : any ) : any {
162+ const options = this . getOptions ( ) ;
163+ this . visitors
164+ . filter ( v => options . indexOf ( v . getOption ( ) ) >= 0 )
165+ . map ( v => v . visitBoundText ( text , this ) )
166+ . filter ( f => ! ! f )
167+ . forEach ( f => this . addFailure ( f ) ) ;
168+ super . visitBoundText ( text , context ) ;
169+ }
135170}
136171
137172export class Rule extends Lint . Rules . AbstractRule {
0 commit comments