Code coverage report for lib/parser/utils/parserData.js

Statements: 100% (83 / 83)      Branches: 100% (16 / 16)      Functions: 100% (9 / 9)      Lines: 100% (80 / 80)      Ignored: none     

All files » lib/parser/utils/ » parserData.js
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161                                      1 1 21 21 21 21 21 21 21 21 21 21   1 21 21 21 21 76 76       1 21 21 21 21 10 10             1 21 21 21 21 21 21   21 23 23 23 23   23 89 89 89 89       21 21     1                                 183 183 183 632 632   183           1   174 174 174 275 275 503 503 264       264 2   264 264       174           1   31 31 31 40 40   31         1   1   1 1 1 1   1  
/**
CompilerData gives information to be used
to compile the AST to a data repersentation
of a command
There are 6 types of options
simple string:
a simple argument, each command treats them differently
selection:
there exists a list of arguments that the command will choose
one of them to use, if no selection argument is added the command uses the default one
parameters:
an argument that includes a parameter
numeric paramters:
an argument that includes a parameter that is limited to numbers
selection with parameters:
a selection argument which one or more of them is a parameter
flags:
a flag in the command
*/
var ParserData = (function () {
    function ParserData(config) {
        this.selectors = {};
        this.selectorOptions = {};
        this.visualSelectorOptions = {};
        this.parameterOptions = {};
        this.shortOptions = {};
        this.longOptions = {};
        this.flagOptions = {};
        this.setFlags(config.flags);
        this.setParameters(config.parameters);
        this.setSelector(config.selectors);
    }
    ParserData.prototype.setFlags = function (flags) {
        if (typeof flags === "undefined") { flags = {}; }
        this.flags = flags;
        var flagOptions = (this.flagOptions = {});
        for (var key in flags) {
            var value = flags[key];
            flagOptions[value.name] = value.option;
        }
    };
 
    ParserData.prototype.setParameters = function (parameters) {
        if (typeof parameters === "undefined") { parameters = {}; }
        this.parameters = parameters;
        var parameterOptions = this.parameterOptions;
        for (var key in parameters) {
            var value = parameters[key];
            parameterOptions[value.name] = value.option;
        }
    };
 
    /**
    Generates data to be used in selection tasks
    */
    ParserData.prototype.setSelector = function (selectorData) {
        if (typeof selectorData === "undefined") { selectorData = {}; }
        this.selectorData = selectorData;
        var selectors = this.selectors;
        var selectorOptions = this.selectorOptions;
        var visualSelectorOptions = this.visualSelectorOptions;
        var regexToReplace = / /g;
 
        for (var key in selectorData) {
            var subkeys = selectorData[key];
            var keySelector = selectors[subkeys.name] = {};
            var keySelectorOption = selectorOptions[subkeys.name] = {};
            var VisualSelectorOption = visualSelectorOptions[subkeys.name] = [];
 
            for (var subkey in subkeys.options) {
                var value = subkeys.options[subkey];
                keySelector[value.name] = value;
                keySelectorOption[value.name] = value.option;
                VisualSelectorOption.push(value.name);
            }
        }
 
        visualSelectorOptions.$selector = selectors;
        return this;
    };
 
    Object.defineProperty(ParserData.prototype, "componentFlags", {
        /**
        Sets the options for the normal options
        of a command, normally a one character option
        */
        //public setShortOptions(options){
        //  this.shortOptions = options
        //}
        /**
        Sets the options for the long variants of the options
        of a command, normally a an argument prefixed with 2
        hypens
        */
        //public setLongOptions(options){
        //  this.longOptions = options
        //}
        get: function () {
            var componentFlags = {};
            var flags = this.flags;
            for (var key in flags) {
                var value = flags[key];
                componentFlags[value.name] = value.active;
            }
            return componentFlags;
        },
        enumerable: true,
        configurable: true
    });
 
    Object.defineProperty(ParserData.prototype, "componentSelectors", {
        get: function () {
            var componentSelectors = {};
            var selectorData = this.selectorData;
            for (var key in selectorData) {
                var value = selectorData[key];
                for (var optionName in value.options) {
                    var option = value.options[optionName];
                    if (option.default) {
                        var valueObj = {
                            name: option.name,
                            type: option.type || "option"
                        };
                        if (option.defaultValue) {
                            valueObj['value'] = option.defaultValue;
                        }
                        componentSelectors[value.name] = valueObj;
                        break;
                    }
                }
            }
            return componentSelectors;
        },
        enumerable: true,
        configurable: true
    });
 
    Object.defineProperty(ParserData.prototype, "componentParameters", {
        get: function () {
            var componentParameters = {};
            var parameters = this.parameters;
            for (var key in parameters) {
                var value = parameters[key];
                componentParameters[value.name] = value.defaultValue || "";
            }
            return componentParameters;
        },
        enumerable: true,
        configurable: true
    });
    return ParserData;
})();
exports.ParserData = ParserData;
 
(function (SelectorOptionType) {
    SelectorOptionType[SelectorOptionType["OPTION"] = 0] = "OPTION";
    SelectorOptionType[SelectorOptionType["PARAMETER"] = 1] = "PARAMETER";
    SelectorOptionType[SelectorOptionType["NUMERIC_PARAMETER"] = 2] = "NUMERIC_PARAMETER";
})(exports.SelectorOptionType || (exports.SelectorOptionType = {}));
var SelectorOptionType = exports.SelectorOptionType;