diff --git a/CHANGELOG.md b/CHANGELOG.md index 774f2a9f..b62bec62 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 5.0.3 - 2015-02-16 + +- Fixed: regression of 5.0.2: AST parent references were not updated ([#25](https://github.com/postcss/postcss-import/issues/25)) + # 5.0.2 - 2015-02-14 - Fixed: indentation and code style are now preserved ([#20](https://github.com/postcss/postcss-import/issues/20)) diff --git a/index.js b/index.js index f076c36d..d0578591 100755 --- a/index.js +++ b/index.js @@ -220,7 +220,7 @@ function insertRules(atRule, parsedAtImport, newStyles) { params: parsedAtImport.media }) - // keep ast clean + // keep AST clean newNodes.forEach(function(node) {node.parent = wrapper}) wrapper.source = atRule.source @@ -235,6 +235,10 @@ function insertRules(atRule, parsedAtImport, newStyles) { else if (newNodes && newNodes.length) { newNodes[0].before = atRule.before } + + // keep AST clean + newNodes.forEach(function(node) {node.parent = atRule.parent}) + // replace atRule by imported nodes var nodes = atRule.parent.nodes nodes.splice.apply(nodes, [nodes.indexOf(atRule), 0].concat(newNodes)) diff --git a/package.json b/package.json index 86cace3d..125d6150 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-import", - "version": "5.0.2", + "version": "5.0.3", "description": "PostCSS plugin to import CSS files", "keywords": [ "css", diff --git a/test/fixtures/ignore.expected.css b/test/fixtures/ignore.expected.css index 033f48b3..1c7013f5 100644 --- a/test/fixtures/ignore.expected.css +++ b/test/fixtures/ignore.expected.css @@ -14,7 +14,7 @@ @import url('//css'); @import url(//css); -@media (min-width: 25em) { +@media (min-width: 25em){ ignore{} } diff --git a/test/fixtures/modules.expected.css b/test/fixtures/modules.expected.css index fc2287b4..4fa34101 100644 --- a/test/fixtures/modules.expected.css +++ b/test/fixtures/modules.expected.css @@ -3,7 +3,7 @@ .nested{} .byHand{} .dep{} -@media screen { +@media screen{ .dep{} } @@ -12,7 +12,7 @@ .web-nested{} .web-byHand{} .web-dep{} -@media screen { +@media screen{ .web-dep{} } diff --git a/test/fixtures/recursive.expected.css b/test/fixtures/recursive.expected.css index 19ac12d1..808988d0 100755 --- a/test/fixtures/recursive.expected.css +++ b/test/fixtures/recursive.expected.css @@ -1,4 +1,4 @@ -@media (min-width: 25em) { +@media (min-width: 25em){ bar{} foo.recursive{} diff --git a/test/fixtures/simple.expected.css b/test/fixtures/simple.expected.css index 0fac7973..f67047c3 100755 --- a/test/fixtures/simple.expected.css +++ b/test/fixtures/simple.expected.css @@ -1,21 +1,21 @@ foo{} -@media screen { +@media screen{ foo{} } bar{} -@media screen { +@media screen{ bar{} } baz{} -@media screen { +@media screen{ baz{} } foobar{} -@media screen and (min-width: 25em) { +@media screen and (min-width: 25em){ foobar{} } foobarbaz{} -@media print, screen and (min-width: 25em) { +@media print, screen and (min-width: 25em){ foobarbaz{} } diff --git a/test/index.js b/test/index.js index 25468985..43b25ab3 100755 --- a/test/index.js +++ b/test/index.js @@ -138,3 +138,16 @@ test("import relative files using path option only", function(t) { ) t.end() }) + +test("inlined @import should keep PostCSS AST references clean", function(t) { + var root = postcss() + .use(atImport()) + .process("@import 'test/fixtures/imports/foo.css';\nbar{}") + .root + root.nodes.forEach(function(node) { + t.equal(root, node.parent) + }) + + t.end() +}) +