mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
Fix append() failing after mutating nodes through .parent
This commit is contained in:
+1
-1
@@ -326,7 +326,7 @@ class Container extends Node {
|
||||
i.raws.before = sample.raws.before.replace(/\S/g, '')
|
||||
}
|
||||
}
|
||||
i.parent = this
|
||||
i.parent = this.proxyOf
|
||||
return i
|
||||
})
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import postcss, {
|
||||
Container,
|
||||
Root,
|
||||
Rule,
|
||||
AtRule,
|
||||
Declaration,
|
||||
Plugin,
|
||||
PluginCreator,
|
||||
@@ -1552,4 +1553,50 @@ test('marks cleaned nodes as dirty on moving in a document', () => {
|
||||
])
|
||||
})
|
||||
|
||||
test('append works after reassigning nodes through .parent', async () => {
|
||||
let plugin: Plugin = {
|
||||
postcssPlugin: 'test',
|
||||
|
||||
Rule(rule) {
|
||||
if (
|
||||
!(
|
||||
rule.selector === '.nested' &&
|
||||
rule.nodes.length === 1 &&
|
||||
rule.nodes[0].type === 'atrule'
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
let atrule = rule.nodes[0]
|
||||
|
||||
atrule.append(rule.clone({ nodes: [] }).append(...atrule.nodes))
|
||||
|
||||
rule.after(atrule)
|
||||
rule.remove()
|
||||
},
|
||||
|
||||
OnceExit(root) {
|
||||
let firstNode = root.nodes[0] as AtRule
|
||||
let secondNode = root.nodes[1] as AtRule
|
||||
let rule2 = secondNode.nodes[0]
|
||||
rule2.parent!.nodes = rule2.parent!.nodes
|
||||
firstNode.append(...secondNode.nodes)
|
||||
secondNode.remove()
|
||||
}
|
||||
}
|
||||
|
||||
let { css } = await postcss([plugin]).process(
|
||||
postcss.parse(
|
||||
`@media (min-width: 640px) { .page { width: auto; } } .nested { @media (min-width: 640px) { width: auto; } }`
|
||||
),
|
||||
{ from: 'whatever' }
|
||||
)
|
||||
|
||||
is(
|
||||
css,
|
||||
'@media (min-width: 640px) { .page { width: auto; } .nested { width: auto } }'
|
||||
)
|
||||
})
|
||||
|
||||
test.run()
|
||||
|
||||
Reference in New Issue
Block a user