<commit_before>var path = require('path'),
    parser = require('./parser'),
    vm = require('vm');

module.exports = function(dust) {
  var compiler = require('./compiler')(dust);
  compiler.parse = parser.parse;
  dust.compile = compiler.compile;

  dust.loadSource = function(source, path) {
    return vm.runInNewContext(source, {dust: dust}, path);
  };

  dust.nextTick = process.nextTick;

  // expose optimizers in commonjs env too
  dust.optimizers = compiler.optimizers;
}<commit_msg>Cache VM context across `dust.loadSource` calls. Should fix issue #288.<commit_after>var path = require('path'),
    parser = require('./parser'),
    vm = require('vm');

module.exports = function(dust) {
  var compiler = require('./compiler')(dust);
  compiler.parse = parser.parse;
  dust.compile = compiler.compile;

  var context = vm.createContext({dust: dust});
  dust.loadSource = function(source, path) {
    return vm.runInContext(source, context, path);
  };

  dust.nextTick = process.nextTick;

  // expose optimizers in commonjs env too
  dust.optimizers = compiler.optimizers;
}
{'fraction_non_alphanumeric': 0.14613970588235295, 'fraction_numerical': 0.0027573529411764708, 'mean_word_length': 4.088785046728972, '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': '709558', 'n_tokens_mistral': 336, 'n_tokens_neox': 319, 'n_words': 80}