<commit_before>var errors = require('./errors');
var execute = require('./execute');

module.exports = function getAssignable(expression, ctx) {
    var currentNode = expression;

    var isMap = false;
    var variableName, variableIndexExpression, variableIndex;
    var variable;

    while (!variableName) {
        if (currentNode.type === "Expression") currentNode = currentNode.expression;
        else if (currentNode.type === "Identifier") variableName = currentNode.name;
        else if (currentNode.type === "MemberExpression") {
            isMap = true;
            variableIndexExpression = currentNode.property;
            currentNode = currentNode.map;
        } else if (currentNode.type === "MapExpression" && isMap) variable = execute(currentNode.map, ctx);
        else errors.referenceError("Invalid assignable expression");
    }

    var variableScopeName, scope;
    if (isMap) {
        variableIndex = execute(variableIndexExpression, ctx);
        if (variableName) variable = ctx.getVariable(variableName);
        if (!variable || !variable.isMap) errors.typeError("Cannot use index of a non-map");
    } else {
        variableScopeName = ctx.findVariableScope(variableName);
        if (variableScopeName === false) variableScopeName = 0;
        scope = ctx.scopes[variableScopeName];
    }

    return {
        isAssignable: true,
        getValue: function() {
            if (isMap) return variable.getIndex(variableIndex);
            return ctx.getVariableIn(variableName, scope);
        },
        setValue: function(newValue) {
            if (isMap) variable.setIndex(variableIndex, newValue);
            else ctx.setVariableIn(variableName, newValue, scope);
        }
    };
};<commit_msg>set 'out' variables to null<commit_after>var errors = require('./errors');
var execute = require('./execute');

module.exports = function getAssignable(expression, ctx) {
    var currentNode = expression;

    var isMap = false;
    var variableName, variableIndexExpression, variableIndex;
    var variable;

    while (!variableName) {
        if (currentNode.type === "Expression") currentNode = currentNode.expression;
        else if (currentNode.type === "Identifier") variableName = currentNode.name;
        else if (currentNode.type === "MemberExpression") {
            isMap = true;
            variableIndexExpression = currentNode.property;
            currentNode = currentNode.map;
        } else if (currentNode.type === "MapExpression" && isMap) variable = execute(currentNode.map, ctx);
        else errors.referenceError("Invalid assignable expression");
    }

    var variableScopeName, scope;
    if (isMap) {
        variableIndex = execute(variableIndexExpression, ctx);
        if (variableName) variable = ctx.getVariable(variableName);
        if (!variable || !variable.isMap) errors.typeError("Cannot use index of a non-map");
    } else {
        variableScopeName = ctx.findVariableScope(variableName);
        if (variableScopeName === false) {
            variableScopeName = 0;
            ctx.setVariable(variableName, null, 0);
        }
        scope = ctx.scopes[variableScopeName];
    }

    return {
        isAssignable: true,
        getValue: function() {
            if (isMap) return variable.getIndex(variableIndex);
            return ctx.getVariableIn(variableName, scope);
        },
        setValue: function(newValue) {
            if (isMap) variable.setIndex(variableIndex, newValue);
            else ctx.setVariableIn(variableName, newValue, scope);
        }
    };
};
{'fraction_non_alphanumeric': 0.1111734980348119, 'fraction_numerical': 0.0008422234699606962, 'mean_word_length': 2.877040261153428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7428218', 'n_tokens_mistral': 924, 'n_tokens_neox': 910, 'n_words': 227}