Skip to content
This repository was archived by the owner on Aug 21, 2019. It is now read-only.

Commit edfa66c

Browse files
authored
Merge pull request #3 from ramya-rao-a/fix-formatting-for-groups
Remove group node to avoid extra newline and indent
2 parents 8c1cbd8 + fc9a50f commit edfa66c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ function unroll(node) {
1919
return;
2020
}
2121

22-
for (let i = 1; i < node.repeat.count; i++) {
22+
for (let i = 0; i < node.repeat.count; i++) {
2323
const clone = node.clone(true);
24-
clone.repeat.value = i;
24+
clone.repeat.value = i+1;
2525
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+
}
2734
}
28-
29-
node.repeat.value = node.repeat.count;
35+
36+
node.parent.removeChild(node);
3037
}

test/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Parser', () => {
3232
describe('Expand', () => {
3333
it('unroll repeated elements', () => {
3434
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>');
3636
});
3737
});
3838
});

0 commit comments

Comments
 (0)