Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix whitespace bug #1790

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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