travco / postcss-extend

A PostCSS plugin to minimize the number of repeat-selectors and rules you write
MIT License
114 stars 8 forks source link

Adding check for undefined raws in "safeCopyDeclarations" func #24

Closed kayeouh closed 8 years ago

kayeouh commented 8 years ago

I was getting this weird error while extending from within a @media declaration. Using the readme example, I put in this:

.potato {
  color: white;
  outline: brown;
  font-family: sans-serif;
}
@media (width > 600px) {
  .potato:first {
    float: center;
  }
  .spud {
    @extend .potato;
    color: red;
    font-size: 4em;
  }
}

which was being output as:

.potato{
    color: white;
    outline: brown;
    font-family: sans-serif;
}
@media (width > 600px){
    .potato:first, .spud:first{
        float: center;
    }
    .spud{
        color: red;
        font-size: 4em;undefined    outline: brown;undefined    font-family: sans-serif;
    }
}

I'm not sure whether one of my upstream plugins is messing with my declaration raws (probably is the case), but the issue for me was an empty node.raws, so the cloned node's "before," "after," and "between" raw props were all getting instantiated as "undefined" in the "safeCopyDeclarations" function. This fix just checks to make sure node.raws has each property before assigning them to the cloned node.

Let me know if this looks alright; thanks!

travco commented 8 years ago

Sorry for the delay, looks good. I'll get it pushed up to NPM (hopefully later today) when I chance to make a test or two that would break in the previous version.

kayeouh commented 8 years ago

Awesome; thank you! :D