postcss / postcss-mixins

PostCSS plugin for mixins
MIT License
466 stars 47 forks source link

Unexpected behaviour with ampersand parent selectors inside of mixin #70

Closed ajlond123 closed 7 years ago

ajlond123 commented 7 years ago

There seems to be an issue with using ampersand parent selectors inside of mixins. Please see examples below.

Mixin

@define-mixin themify $theme {
    &.theme-$(theme) {
        @mixin-content;
    }

    .theme-$(theme) & {
        @mixin-content;
    }
}

Input

.test {
    background-color: pink;
    color: blue;
    width: 150px;
    height: 150px;

    @add-mixin themify dark {
        background-color: black;
        color: white;
    };
}

Output

.test {
    background-color: pink;
    color: blue;
    width: 150px;
    height: 150px;

    .theme-dark & {
        background-color: black;
        color: white;
    }
}

.test.theme-dark {
    background-color: black;
    color: white;
}

Expected Output

.test {
    background-color: pink;
    color: blue;
    width: 150px;
    height: 150px;
}

.theme-dark .test {
    background-color: black;
    color: white;
}

.test.theme-dark {
    background-color: black;
    color: white;
}
ai commented 7 years ago

Show me your PostCSS config

ajlond123 commented 7 years ago
module.exports = {
    plugins: [
        require('postcss-import'),
        require('postcss-mixins'),
        require('postcss-simple-vars'),
        require('postcss-extend'),
        require('postcss-cssnext')({
            browsers: ['last 2 versions', '> 5%'],
            features: {
                customProperties : {
                    warnings: false
                }
            },
            warnForDuplicates: false
        }),
        require('postcss-short-color'),
        require('postcss-pxtorem')({
            propWhiteList: ['font-size', 'letter-spacing', 'line-height'],
            mediaQuery: 0
        }),
        require('lost'),
        require('mdcss')
    ]
};
ai commented 7 years ago

You don’t have postcss-nested plugin to support .theme-dark &. postcss-nesting is postcss-cssnext has different API.

ajlond123 commented 7 years ago

Thanks!