'use strict';

/**
 * Created by godsong on 16/6/21.
 */
var fs = require('fs');
var text = fs.readFileSync('./in.txt').toString();
var properties = [];
var propertyNames = new Set();
text.split('\n').forEach(function (line) {
    line = line.trim();
    if (!line || line.indexOf('//') == 0 || line.indexOf('alias_for') >= 0) {
        return;
    }
    var name = line.split(' ')[0];
    var entry = { name: name };
    propertyNames.add(name);
    var longhands = line.split('longhands=')[1];
    longhands = longhands && longhands.split(',')[0];
    if (longhands) {
        entry['longhands'] = longhands.split(';');
    }
    properties.push(entry);
});

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
    for (var _iterator = properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var property = _step.value;

        var longhands = property["longhands"];
        var lhs = [];
        if (longhands) {
            var _iteratorNormalCompletion2 = true;
            var _didIteratorError2 = false;
            var _iteratorError2 = undefined;

            try {
                for (var _iterator2 = longhands[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
                    var longhand = _step2.value;

                    if (propertyNames.has(longhand)) {
                        lhs.push(longhand);
                    }
                }
            } catch (err) {
                _didIteratorError2 = true;
                _iteratorError2 = err;
            } finally {
                try {
                    if (!_iteratorNormalCompletion2 && _iterator2.return) {
                        _iterator2.return();
                    }
                } finally {
                    if (_didIteratorError2) {
                        throw _iteratorError2;
                    }
                }
            }
        }
        if (lhs.length > 0) {
            property["longhands"] = lhs;
        } else {
            delete property["longhands"];
        }
    }
} catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
} finally {
    try {
        if (!_iteratorNormalCompletion && _iterator.return) {
            _iterator.return();
        }
    } finally {
        if (_didIteratorError) {
            throw _iteratorError;
        }
    }
}

fs.writeFileSync('./out.txt', JSON.stringify(properties));