Skip to content

Commit

Permalink
Fixed: regression of 5.0.2: AST parent references were not updated
Browse files Browse the repository at this point in the history
Close #25
  • Loading branch information
MoOx committed Feb 16, 2015
1 parent e985ca6 commit 7b5fa01
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-import",
"version": "5.0.2",
"version": "5.0.3",
"description": "PostCSS plugin to import CSS files",
"keywords": [
"css",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/ignore.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@import url('//css');
@import url(//css);

@media (min-width: 25em) {
@media (min-width: 25em){
ignore{}
}

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/modules.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.nested{}
.byHand{}
.dep{}
@media screen {
@media screen{
.dep{}
}

Expand All @@ -12,7 +12,7 @@
.web-nested{}
.web-byHand{}
.web-dep{}
@media screen {
@media screen{
.web-dep{}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/recursive.expected.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@media (min-width: 25em) {
@media (min-width: 25em){
bar{}

foo.recursive{}
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/simple.expected.css
Original file line number Diff line number Diff line change
@@ -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{}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 7b5fa01

Please sign in to comment.