Skip to content

Commit 7b5fa01

Browse files
committed
Fixed: regression of 5.0.2: AST parent references were not updated
Close #25
1 parent e985ca6 commit 7b5fa01

8 files changed

+32
-11
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 5.0.3 - 2015-02-16
2+
3+
- Fixed: regression of 5.0.2: AST parent references were not updated ([#25](https://github.com/postcss/postcss-import/issues/25))
4+
15
# 5.0.2 - 2015-02-14
26

37
- Fixed: indentation and code style are now preserved ([#20](https://github.com/postcss/postcss-import/issues/20))

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function insertRules(atRule, parsedAtImport, newStyles) {
220220
params: parsedAtImport.media
221221
})
222222

223-
// keep ast clean
223+
// keep AST clean
224224
newNodes.forEach(function(node) {node.parent = wrapper})
225225
wrapper.source = atRule.source
226226

@@ -235,6 +235,10 @@ function insertRules(atRule, parsedAtImport, newStyles) {
235235
else if (newNodes && newNodes.length) {
236236
newNodes[0].before = atRule.before
237237
}
238+
239+
// keep AST clean
240+
newNodes.forEach(function(node) {node.parent = atRule.parent})
241+
238242
// replace atRule by imported nodes
239243
var nodes = atRule.parent.nodes
240244
nodes.splice.apply(nodes, [nodes.indexOf(atRule), 0].concat(newNodes))

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-import",
3-
"version": "5.0.2",
3+
"version": "5.0.3",
44
"description": "PostCSS plugin to import CSS files",
55
"keywords": [
66
"css",

test/fixtures/ignore.expected.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@import url('//css');
1515
@import url(//css);
1616

17-
@media (min-width: 25em) {
17+
@media (min-width: 25em){
1818
ignore{}
1919
}
2020

test/fixtures/modules.expected.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.nested{}
44
.byHand{}
55
.dep{}
6-
@media screen {
6+
@media screen{
77
.dep{}
88
}
99

@@ -12,7 +12,7 @@
1212
.web-nested{}
1313
.web-byHand{}
1414
.web-dep{}
15-
@media screen {
15+
@media screen{
1616
.web-dep{}
1717
}
1818

test/fixtures/recursive.expected.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@media (min-width: 25em) {
1+
@media (min-width: 25em){
22
bar{}
33

44
foo.recursive{}

test/fixtures/simple.expected.css

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
foo{}
2-
@media screen {
2+
@media screen{
33
foo{}
44
}
55
bar{}
6-
@media screen {
6+
@media screen{
77
bar{}
88
}
99
baz{}
10-
@media screen {
10+
@media screen{
1111
baz{}
1212
}
1313
foobar{}
14-
@media screen and (min-width: 25em) {
14+
@media screen and (min-width: 25em){
1515
foobar{}
1616
}
1717
foobarbaz{}
18-
@media print, screen and (min-width: 25em) {
18+
@media print, screen and (min-width: 25em){
1919
foobarbaz{}
2020
}
2121

test/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,16 @@ test("import relative files using path option only", function(t) {
138138
)
139139
t.end()
140140
})
141+
142+
test("inlined @import should keep PostCSS AST references clean", function(t) {
143+
var root = postcss()
144+
.use(atImport())
145+
.process("@import 'test/fixtures/imports/foo.css';\nbar{}")
146+
.root
147+
root.nodes.forEach(function(node) {
148+
t.equal(root, node.parent)
149+
})
150+
151+
t.end()
152+
})
153+

0 commit comments

Comments
 (0)