Skip to content

Commit 8086ea3

Browse files
authored
Merge pull request #1790 from romainmenke/fix-whitespace-bug--passionate-african-bush-elephant-9ae98c1a5a
fix whitespace bug
2 parents cf9425a + 4b38845 commit 8086ea3

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Container extends Node {
177177

178178
insertBefore(exist, add) {
179179
let existIndex = this.index(exist)
180-
let type = exist === 0 ? 'prepend' : false
180+
let type = existIndex === 0 ? 'prepend' : false
181181
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
182182
existIndex = this.index(exist)
183183
for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)

test/container.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,28 @@ test('insertBefore() receives pre-existing child node - b', () => {
654654
is(a.toString(), 'a{ z-index: 1; align-items: start; color: red }')
655655
})
656656

657+
test('insertBefore() has defined way of adding newlines', () => {
658+
let root = parse('a {}')
659+
root.insertBefore(root.first as Rule, 'b {}')
660+
root.insertBefore(root.first as Rule, 'c {}')
661+
is(root.toString(), 'c {}\nb {}\na {}')
662+
663+
root = parse('other {}a {}')
664+
root.insertBefore(root.first as Rule, 'b {}')
665+
root.insertBefore(root.first as Rule, 'c {}')
666+
is(root.toString(), 'c {}b {}other {}a {}')
667+
668+
root = parse('other {}\na {}')
669+
root.insertBefore(root.nodes[1] as Rule, 'b {}')
670+
root.insertBefore(root.nodes[1] as Rule, 'c {}')
671+
is(root.toString(), 'other {}\nc {}\nb {}\na {}')
672+
673+
root = parse('other {}a {}')
674+
root.insertBefore(root.nodes[1] as Rule, 'b {}')
675+
root.insertBefore(root.nodes[1] as Rule, 'c {}')
676+
is(root.toString(), 'other {}c {}b {}a {}')
677+
})
678+
657679
test('insertAfter() inserts child', () => {
658680
let rule = parse('a { a: 1; b: 2 }').first as Rule
659681
rule.insertAfter(0, { prop: 'c', value: '3' })

0 commit comments

Comments
 (0)