This repository was archived by the owner on Aug 21, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,19 @@ function unroll(node) {
19
19
return ;
20
20
}
21
21
22
- for ( let i = 1 ; i < node . repeat . count ; i ++ ) {
22
+ for ( let i = 0 ; i < node . repeat . count ; i ++ ) {
23
23
const clone = node . clone ( true ) ;
24
- clone . repeat . value = i ;
24
+ clone . repeat . value = i + 1 ;
25
25
clone . walk ( unroll ) ;
26
- node . parent . insertBefore ( clone , node ) ;
26
+ if ( clone . isGroup ) {
27
+ while ( clone . children . length > 0 ) {
28
+ clone . firstChild . repeat = clone . repeat ;
29
+ node . parent . insertBefore ( clone . firstChild , node ) ;
30
+ }
31
+ } else {
32
+ node . parent . insertBefore ( clone , node ) ;
33
+ }
27
34
}
28
-
29
- node . repeat . value = node . repeat . count ;
35
+
36
+ node . parent . removeChild ( node ) ;
30
37
}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ describe('Parser', () => {
32
32
describe ( 'Expand' , ( ) => {
33
33
it ( 'unroll repeated elements' , ( ) => {
34
34
assert . equal ( expand ( 'a*2>b*3' ) , '<a*2@1><b*3@1></b><b*3@2></b><b*3@3></b></a><a*2@2><b*3@1></b><b*3@2></b><b*3@3></b></a>' ) ;
35
- assert . equal ( expand ( 'a>(b+c)*2' ) , '<a>(<b ></b><c></c>) *2@1(<b ></b><c></c>)*2@2 </a>' ) ;
35
+ assert . equal ( expand ( 'a>(b+c)*2' ) , '<a><b*2@1 ></b><c*2@1 ></c><b *2@2 ></b><c*2@2 ></c></a>' ) ;
36
36
} ) ;
37
37
} ) ;
38
38
} ) ;
You can’t perform that action at this time.
0 commit comments