Skip to content

Commit

Permalink
Merge pull request #1790 from romainmenke/fix-whitespace-bug--passion…
Browse files Browse the repository at this point in the history
…ate-african-bush-elephant-9ae98c1a5a

fix whitespace bug
  • Loading branch information
ai committed Nov 10, 2022
2 parents cf9425a + 4b38845 commit 8086ea3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/container.js
Expand Up @@ -177,7 +177,7 @@ class Container extends Node {

insertBefore(exist, add) {
let existIndex = this.index(exist)
let type = exist === 0 ? 'prepend' : false
let type = existIndex === 0 ? 'prepend' : false
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
existIndex = this.index(exist)
for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
Expand Down
22 changes: 22 additions & 0 deletions test/container.test.ts
Expand Up @@ -654,6 +654,28 @@ test('insertBefore() receives pre-existing child node - b', () => {
is(a.toString(), 'a{ z-index: 1; align-items: start; color: red }')
})

test('insertBefore() has defined way of adding newlines', () => {
let root = parse('a {}')
root.insertBefore(root.first as Rule, 'b {}')
root.insertBefore(root.first as Rule, 'c {}')
is(root.toString(), 'c {}\nb {}\na {}')

root = parse('other {}a {}')
root.insertBefore(root.first as Rule, 'b {}')
root.insertBefore(root.first as Rule, 'c {}')
is(root.toString(), 'c {}b {}other {}a {}')

root = parse('other {}\na {}')
root.insertBefore(root.nodes[1] as Rule, 'b {}')
root.insertBefore(root.nodes[1] as Rule, 'c {}')
is(root.toString(), 'other {}\nc {}\nb {}\na {}')

root = parse('other {}a {}')
root.insertBefore(root.nodes[1] as Rule, 'b {}')
root.insertBefore(root.nodes[1] as Rule, 'c {}')
is(root.toString(), 'other {}c {}b {}a {}')
})

test('insertAfter() inserts child', () => {
let rule = parse('a { a: 1; b: 2 }').first as Rule
rule.insertAfter(0, { prop: 'c', value: '3' })
Expand Down

0 comments on commit 8086ea3

Please sign in to comment.