Skip to content

Commit

Permalink
Add source property for newly created nodes
Browse files Browse the repository at this point in the history
- From the PostCSS Plugins Guidelines:
    2.3. Set correct source property for each created nodes.

Fixes #4
  • Loading branch information
justim committed Jul 22, 2015
1 parent 4457154 commit 9f49ef6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = postcss.plugin('postcss-svg-fallback', function(options) {
var newImage;
var newRule;
var newDecl;
var matchedBackgroundImageDecl;

// skip our added rules
if (rule.selector.indexOf(fallbackSelector) !== -1) {
Expand All @@ -45,6 +46,7 @@ module.exports = postcss.plugin('postcss-svg-fallback', function(options) {

if (backgroundImageMatch) {
backgroundImage = backgroundImageMatch[1];
matchedBackgroundImageDecl = decl;
}
}

Expand All @@ -70,10 +72,13 @@ module.exports = postcss.plugin('postcss-svg-fallback', function(options) {
});

newRule = postcss.rule({ selector: fallbackSelector + ' ' + rule.selector });
newRule.source = rule.source;

newDecl = postcss.decl({
prop: 'background-image',
value: 'url(' + newImage + ')'
});
newDecl.source = matchedBackgroundImageDecl.source;

newRule.append(newDecl);
rule.parent.insertAfter(rule, newRule);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "git://github.com/justim/postcss-svg-fallback"
},
"version": "1.0.0",
"version": "1.0.1",
"main": "index.js",
"dependencies": {
"postcss": "~4.1.9",
Expand Down

0 comments on commit 9f49ef6

Please sign in to comment.