binary-parser icon indicating copy to clipboard operation
binary-parser copied to clipboard

Support for names with non-alphanumeric characters?

Open ericman314 opened this issue 8 years ago • 0 comments

I noticed in the API documentation that "name should consist only of alphanumeric characters and start with an alphabet." It looks like this is because the compiled code uses dot notation to access properties:

Context.prototype.generateVariable = function(name) {
    var arr = [];

    Array.prototype.push.apply(arr, this.scopes[this.scopes.length - 1]);
    if (name) {
        arr.push(name);
    }

    return arr.join('.');
};

Would there be any harm in using array bracket notation instead, so that any valid property name can be used as a name? It's not very elegant, but something like:

Context.prototype.generateVariable = function(name) {
    var arr = [];

    Array.prototype.push.apply(arr, this.scopes[this.scopes.length - 1]);
    if (name) {
        arr.push(name);
    }
    
    return arr[0] + arr.slice(1).map(function(x) { return '["' + x + '"]'; }).join('');
};

ericman314 avatar Dec 02 '17 16:12 ericman314