<commit_before>var postcss = require('postcss');

module.exports = postcss.plugin('postcss-responsive-properties', function (opts) {
    opts = opts || {};

    // Work with options here

    return function (css, result) {
 		
        var options = options || {};
        var root = css.root();

 		css.walkRules(function(rule) {

			if (rule.selector.indexOf(":") === rule.selector.length - 1) {
			    var parentProperty = rule;

	 			rule.each(function(decl, i) {
                    if (i === 0 || decl.type === "comment") {
                        return;
                    }
	 				var selector   = decl.parent.parent.selector;
	 				var breakpoint = !isNaN(decl.prop) ? decl.prop + "px" : "$" + decl.prop;
	 				var property   = decl.parent.selector;
	 				var value      = decl.value + ";";

	 				root.append("@media screen and (min-width: " + breakpoint + ") {"+ selector + " {" + property.slice(0, -1) + ": " + value + ";" + "} }");
	 			});
	 			parentProperty.replaceWith({prop: rule.selector.slice(0, -1), value: rule.nodes[0].value + ";"});
			}
 		});
    }
});<commit_msg>change way of appending generated rules<commit_after>var postcss = require('postcss');

function createMediaRule(root, r) {
    var createNewAR = true;

    root.walkAtRules(function(atrule) {
        if (atrule.params === r.breakpoint) {
            atrule.append(r);
            createNewAR = false;
        }
    });

    if (createNewAR) {
        var ar = postcss.atRule({
            type: 'atrule',
            name: 'media',
            params: r.breakpoint
        });
        ar.append(r);
        root.append(ar);
    }
}

module.exports = postcss.plugin('postcss-responsive-properties', function () {
    return function (css) {
        var root = css.root();

        css.walkRules(function (rule, i) {
            if (rule.selector.indexOf(':') === rule.selector.length - 1) {

                rule.walkDecls(function (decl, i) {
                    if (i === 0 || decl.type === 'comment') return;

                    var r = postcss.rule({
                        type: 'rule',
                        selector: decl.parent.parent.selector,
                        breakpoint: 'screen and (min-width: ' + (!isNaN(decl.prop) ? parseInt(decl.prop) + 'px' : '$' + decl.prop) + ')',
                        raws: {
                            semicolon: true
                        }
                    });
                    r.append({
                        type: 'decl',
                        prop: decl.parent.selector.slice(0, -1),
                        value: decl.value
                    });

                    createMediaRule(root, r);
                });

                rule.replaceWith({
                    type: 'decl',
                    prop: rule.selector.slice(0, -1),
                    value: rule.nodes[0].value + ';'
                });
            }
        });
    };
});
{'fraction_non_alphanumeric': 0.15178571428571427, 'fraction_numerical': 0.004807692307692308, 'mean_word_length': 1.4644670050761421, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5156222', 'n_tokens_mistral': 895, 'n_tokens_neox': 813, 'n_words': 163}