<commit_before>'use strict';

var j = require('jfp');

function isLocationMatch(location, token) {
    return token.loc.start.line === location[0] && 
           token.loc.start.column === location[1] - 1;
}

function isValueMatch(token, value) {
    return token.value === value;
}

function isBadIndex (index){
    return j.either(-1, index, 'number') === -1;
}

function hasNoBounds (start, end){
    return j.isNull(start) || j.isNull(end);
}

function seek(directionIncrement, tokens, value, index) {
    return j.recur(seekAction, index);

    function seekAction(recur, index) {
        index = j.isUndefined(tokens[index]) ? -1 : index;

        var isStopState = index === -1 || isValueMatch(tokens[index], value);

        return isStopState ? index : recur(index + directionIncrement);
    }
}

var seekUp = j.partial(seek, -1);
var seekDown = j.partial(seek, 1);

function updateState(currentState, tokens, index) {
    var token = j.either({}, j.deref(index.toString(), tokens));
    
    switch (token.value) {
        case '{':
            return j.cons('{', currentState);
        case '}':
            return j.dropLast(currentState);
        case undefined:
            return [];
        default:
            return currentState;
    }
}

function findStartToken(tokens, coords) {
    return j.recur(findAction, 0);

    function findAction(recur, index) {
        var locationMatches = isLocationMatch(coords.start, tokens[index]);
        
        return locationMatches ? index : recur(index + 1);
    }
}

function findScopeTop(tokens, index) {
    return j.pipeline(index,
        j.partial(seekUp, tokens, 'function'),
        j.partial(seekDown, tokens, '{'));
}

function findScopeBottom(tokens, index) {
    return j.recur(findAction, [], tokens, index);

    function findAction(recur, state, tokens, index) {
        index = j.isUndefined(tokens[index]) ? -1 : index;

        var currentState = updateState(state, tokens, index);<commit_msg>Fixed unexpectedly broken extract variable action.:<commit_after>'use strict';

var j = require('jfp');

function isLocationMatch(location, token) {
    return token.loc.start.line === location[0] + 1 && 
           token.loc.start.column === location[1] - 1;
}

function isValueMatch(token, value) {
    return token.value === value;
}

function isBadIndex (index){
    return j.either(-1, index, 'number') === -1;
}

function hasNoBounds (start, end){
    return j.isNull(start) || j.isNull(end);
}

function seek(directionIncrement, tokens, value, index) {
    return j.recur(seekAction, index);

    function seekAction(recur, index) {
        index = j.isUndefined(tokens[index]) ? -1 : index;

        var isStopState = index === -1 || isValueMatch(tokens[index], value);

        return isStopState ? index : recur(index + directionIncrement);
    }
}

var seekUp = j.partial(seek, -1);
var seekDown = j.partial(seek, 1);

function updateState(currentState, tokens, index) {
    var token = j.either({}, j.deref(index.toString(), tokens));
    
    switch (token.value) {
        case '{':
            return j.cons('{', currentState);
        case '}':
            return j.dropLast(currentState);
        case undefined:
            return [];
        default:
            return currentState;
    }
}

function findStartToken(tokens, coords) {
    return j.recur(findAction, 0);

    function findAction(recur, index) {
        var locationMatches = isLocationMatch(coords.start, tokens[index]);
        return locationMatches ? index : recur(index + 1);
    }
}

function findScopeTop(tokens, index) {
    return j.pipeline(index,
        j.partial(seekUp, tokens, 'function'),
        j.partial(seekDown, tokens, '{'));
}

function findScopeBottom(tokens, index) {
    return j.recur(findAction, [], tokens, index);

    function findAction(recur, state, tokens, index) {
        index = j.isUndefined(tokens[index]) ? -1 : index;

        var currentState = updateState(state, tokens, index);
{'fraction_non_alphanumeric': 0.1410611013326628, 'fraction_numerical': 0.006286145335680161, 'mean_word_length': 3.067484662576687, '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': '5815340', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1202, 'n_words': 289}