<commit_before>'use strict'

const vm = require('vm')
const teoria = require('teoria')

module.exports = (cmd, context, filename, callback) => {
    // make a proxy of context, allowing us to guess notes
    const contextProxy = {
        get(target, name) {
            if (!(name in target) || /^fs$/i.test(name)) {
                // replace "s" in the middle of a 2-3 char note string with a sharp
                const adjustedForSharp = name.replace(/^([a-g])s($|(?=[0-8]$))/i, '$1#')
                let note
                try {
                    note = new teoria.note(adjustedForSharp).toString()
                } catch (e) {
                    throw Error(`Unrecognized input: "${name}"`)
                }
                return note
            } else return target[name]
        }
    }

    const result = vm.runInNewContext(cmd, new Proxy(context, contextProxy))
    callback(null, result)
}<commit_msg>Bugfix: ensure local variables allowed<commit_after>'use strict'

const vm = require('vm')
const teoria = require('teoria')

let sandbox

module.exports = (cmd, context, filename, callback) => {
    // make a proxy of context, allowing us to guess notes
    const contextProxy = {
        get(target, name) {
            if (!(name in target) || /^fs$/i.test(name)) {
                // replace "s" in the middle of a 2-3 char note string with a sharp
                const adjustedForSharp = name.replace(/^([a-g])s($|(?=[0-8]$))/i, '$1#')
                let note
                try {
                    note = new teoria.note(adjustedForSharp).toString()
                } catch (e) {
                    throw Error(`Unrecognized input: "${name}"`)
                }
                return note
            } else return target[name]
        }
    }

    sandbox = sandbox || vm.createContext(new Proxy(context, contextProxy))
    const result = vm.runInContext(cmd, sandbox)
    callback(null, result)
}
{'fraction_non_alphanumeric': 0.13081695966907964, 'fraction_numerical': 0.005170630816959669, 'mean_word_length': 1.8624260355029585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7272492', 'n_tokens_mistral': 566, 'n_tokens_neox': 527, 'n_words': 159}