summaryrefslogtreecommitdiff
path: root/node_modules/postcss-flexbugs-fixes/bugs/bug81a.js
blob: c232d063c0568e70d240eb8095b5a34261af9b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var postcss = require('postcss');

module.exports = function(decl) {
    var regex = /(\d{1,}) (\d{1,}) (calc\(.*?\))/g;
    var matches = regex.exec(decl.value);
    if (decl.prop === 'flex' && matches) {
        var grow = postcss.decl({
            prop: 'flex-grow',
            value: matches[1],
            source: decl.source
        });
        var shrink = postcss.decl({
            prop: 'flex-shrink',
            value: matches[2],
            source: decl.source
        });
        var basis = postcss.decl({
            prop: 'flex-basis',
            value: matches[3],
            source: decl.source
        });
        decl.parent.insertBefore(decl, grow);
        decl.parent.insertBefore(decl, shrink);
        decl.parent.insertBefore(decl, basis);
        decl.remove();
    }
};