Skip to content

Commit

Permalink
Merge pull request #24 from iamvdo/master
Browse files Browse the repository at this point in the history
Properly clone nodes in `ignoredAtRules`
  • Loading branch information
MoOx committed Feb 13, 2015
2 parents 3b89cd4 + aa15289 commit 27db4b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function addIgnoredAtRulesOnTop(styles, ignoredAtRules) {
styles.nodes.unshift(ignoredAtRule)
}

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



// adjust media according to current scope
media = parsedAtImport.media ? (media ? media + " and " : "") + parsedAtImport.media : (media ? media : null)

// just update protocol base uri (protocol://url) or protocol-relative (//url) if media needed
if (parsedAtImport.uri.match(/^(?:[a-z]+:)?\/\//i)) {
parsedAtImport.media = media
ignoredAtRules.push([atRule, parsedAtImport])
var atRuleCloned = atRule.clone()
atRuleCloned.parent = atRule.parent.clone()
ignoredAtRules.push([atRuleCloned, parsedAtImport])
atRule.removeSelf()
return
}
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ test("@import", function(t) {
"should not fail with only one absolute import"
)

base = "@import url('http://');\n@import 'test/fixtures/imports/foo.css';";
t.equal(
postcss()
.use(atImport())
.process(base)
.css.trim(),
"@import url('http://');\nfoo {}",
"should not fail with absolute and local import"
)

t.end()
})


test("@import error output", function(t) {
var file = importsDir + "/import-missing.css"
t.throws(
Expand Down

0 comments on commit 27db4b2

Please sign in to comment.