<commit_before>import {plugin} from 'postcss';

function minimiseWhitespace (rule) {
    rule.raws.before = rule.raws.between = rule.raws.after = '';
    rule.raws.semicolon = false;
}

export default plugin('cssnano-core', () => {
    return css => {
        css.walkDecls(decl => {
            // Ensure that !important values do not have any excess whitespace
            if (decl.important) {
                decl.raws.important = '!important';
            }
            // Remove whitespaces around ie 9 hack
            decl.value = decl.value.replace(/\s*(\\9)\s*/, '$1');
            // Remove extra semicolons and whitespace before the declaration
            if (decl.raws.before) {
                decl.raws.before = decl.raws.before.replace(/[;\s]/g, '');
            }
            decl.raws.between = ':';
            decl.raws.semicolon = false;
        });

        css.walkRules(minimiseWhitespace);
        css.walkAtRules(minimiseWhitespace);

        // Remove final newline
        css.raws.after = '';
    };
});<commit_msg>Reduce AST iterations in the core processor.<commit_after>import {plugin} from 'postcss';

function minimiseWhitespace (node) {
    if (node.type === 'decl') {
        // Ensure that !important values do not have any excess whitespace
        if (node.important) {
            node.raws.important = '!important';
        }
        // Remove whitespaces around ie 9 hack
        node.value = node.value.replace(/\s*(\\9)\s*/, '$1');
        // Remove extra semicolons and whitespace before the declaration
        if (node.raws.before) {
            node.raws.before = node.raws.before.replace(/[;\s]/g, '');
        }
        node.raws.between = ':';
        node.raws.semicolon = false;
    } else if (node.type === 'rule' || node.type === 'atrule') {
        node.raws.before = node.raws.between = node.raws.after = '';
        node.raws.semicolon = false;
    }
}

export default plugin('cssnano-core', () => {
    return css => {
        css.walk(minimiseWhitespace);
        // Remove final newline
        css.raws.after = '';
    };
});
{'fraction_non_alphanumeric': 0.14703065134099616, 'fraction_numerical': 0.0028735632183908046, 'mean_word_length': 2.0144300144300145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '7271418', 'n_tokens_mistral': 642, 'n_tokens_neox': 633, 'n_words': 137}