Skip to content

Commit 27db4b2

Browse files
committed
Merge pull request #24 from iamvdo/master
Properly clone nodes in `ignoredAtRules`
2 parents 3b89cd4 + aa15289 commit 27db4b2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function addIgnoredAtRulesOnTop(styles, ignoredAtRules) {
109109
styles.nodes.unshift(ignoredAtRule)
110110
}
111111

112-
if (first) {
112+
if (first && first.before !== undefined) {
113113
first.before = "\n\n" + first.before
114114
}
115115
}
@@ -126,13 +126,17 @@ function readAtImport(atRule, options, cb, importedFiles, ignoredAtRules, media)
126126
// @todo extract what can be interesting from this one
127127
var parsedAtImport = parseImport(atRule.params, atRule.source)
128128

129+
130+
129131
// adjust media according to current scope
130132
media = parsedAtImport.media ? (media ? media + " and " : "") + parsedAtImport.media : (media ? media : null)
131133

132134
// just update protocol base uri (protocol://url) or protocol-relative (//url) if media needed
133135
if (parsedAtImport.uri.match(/^(?:[a-z]+:)?\/\//i)) {
134136
parsedAtImport.media = media
135-
ignoredAtRules.push([atRule, parsedAtImport])
137+
var atRuleCloned = atRule.clone()
138+
atRuleCloned.parent = atRule.parent.clone()
139+
ignoredAtRules.push([atRuleCloned, parsedAtImport])
136140
atRule.removeSelf()
137141
return
138142
}

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,20 @@ test("@import", function(t) {
6363
"should not fail with only one absolute import"
6464
)
6565

66+
base = "@import url('http://');\n@import 'test/fixtures/imports/foo.css';";
67+
t.equal(
68+
postcss()
69+
.use(atImport())
70+
.process(base)
71+
.css.trim(),
72+
"@import url('http://');\nfoo {}",
73+
"should not fail with absolute and local import"
74+
)
75+
6676
t.end()
6777
})
6878

79+
6980
test("@import error output", function(t) {
7081
var file = importsDir + "/import-missing.css"
7182
t.throws(

0 commit comments

Comments
 (0)