@@ -20,26 +20,29 @@ export function partition(nodes: HtmlAst[], errors: ParseError[], implicitTags:
20
20
let parts : Part [ ] = [ ] ;
21
21
22
22
for ( let i = 0 ; i < nodes . length ; ++ i ) {
23
- let n = nodes [ i ] ;
24
- let temp : HtmlAst [ ] = [ ] ;
25
- if ( _isOpeningComment ( n ) ) {
26
- let i18n = ( < HtmlCommentAst > n ) . value . replace ( / ^ i 1 8 n : ? / , '' ) . trim ( ) ;
27
- i ++ ;
28
- while ( ! _isClosingComment ( nodes [ i ] ) ) {
29
- temp . push ( nodes [ i ++ ] ) ;
30
- if ( i === nodes . length ) {
31
- errors . push ( new I18nError ( n . sourceSpan , 'Missing closing \'i18n\' comment.' ) ) ;
32
- break ;
33
- }
23
+ let node = nodes [ i ] ;
24
+ let msgNodes : HtmlAst [ ] = [ ] ;
25
+ // Nodes between `<!-- i18n -->` and `<!-- /i18n -->`
26
+ if ( _isOpeningComment ( node ) ) {
27
+ let i18n = ( < HtmlCommentAst > node ) . value . replace ( / ^ i 1 8 n : ? / , '' ) . trim ( ) ;
28
+
29
+ while ( ++ i < nodes . length && ! _isClosingComment ( nodes [ i ] ) ) {
30
+ msgNodes . push ( nodes [ i ] ) ;
31
+ }
32
+
33
+ if ( i === nodes . length ) {
34
+ errors . push ( new I18nError ( node . sourceSpan , 'Missing closing \'i18n\' comment.' ) ) ;
35
+ break ;
34
36
}
35
- parts . push ( new Part ( null , null , temp , i18n , true ) ) ;
36
-
37
- } else if ( n instanceof HtmlElementAst ) {
38
- let i18n = _findI18nAttr ( n ) ;
39
- let hasI18n : boolean = isPresent ( i18n ) || implicitTags . indexOf ( n . name ) > - 1 ;
40
- parts . push ( new Part ( n , null , n . children , isPresent ( i18n ) ? i18n . value : null , hasI18n ) ) ;
41
- } else if ( n instanceof HtmlTextAst ) {
42
- parts . push ( new Part ( null , n , null , null , false ) ) ;
37
+
38
+ parts . push ( new Part ( null , null , msgNodes , i18n , true ) ) ;
39
+ } else if ( node instanceof HtmlElementAst ) {
40
+ // Node with an `i18n` attribute
41
+ let i18n = _findI18nAttr ( node ) ;
42
+ let hasI18n : boolean = isPresent ( i18n ) || implicitTags . indexOf ( node . name ) > - 1 ;
43
+ parts . push ( new Part ( node , null , node . children , isPresent ( i18n ) ? i18n . value : null , hasI18n ) ) ;
44
+ } else if ( node instanceof HtmlTextAst ) {
45
+ parts . push ( new Part ( null , node , null , null , false ) ) ;
43
46
}
44
47
}
45
48
0 commit comments