<commit_before>var webworkify = require('webworkify');
var queryParams = require('./query-params');
var utils = require('./utils');
var Renderer = require('./renderer');

var Base64 = require('js-base64').Base64;

function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles) {
  var renderer = new Renderer(editor, this, updateFiles);

  var compileJSON;
  var compilerAcceptsMultipleFiles;

  var previousInput = '';
  var sourceAnnotations = [];

  var cachedRemoteFiles = {};
  var worker = null;

  var compileTimeout = null;

  function onChange () {
    var input = editor.getValue();
    if (input === '') {
      editor.setCacheFileContent('');
      return;
    }
    if (input === previousInput) {
      return;
    }
    previousInput = input;
    if (compileTimeout) {
      window.clearTimeout(compileTimeout);
    }
    compileTimeout = window.setTimeout(compile, 300);
  }

  editor.onChangeSetup(onChange);

  var compile = function (missingInputs) {
    editor.clearAnnotations();
    sourceAnnotations = [];
    outputField.empty();
    var input = editor.getValue();
    editor.setCacheFileContent(input)

    var files = {};
    files[editor.getCacheFile()] = input;
    gatherImports(files, missingInputs, function (input, error) {
      outputField.empty();
      if (input === null) {
        renderer.error(error);
      } else {
        var optimize = queryParams.get().optimize;
        compileJSON(input, optimize ? 1 : 0);
      }
    });
  };
  this.compile = compile;

  this.addAnnotation = function (annotation) {
    sourceAnnotations[sourceAnnotations.length] = annotation;
    editor.setAnnotations(sourceAnnotations);
  };

  function onCompilerLoaded (setVersionText) {
    if (worker === null) {
      var compile;
      var missingInputs = [];
      if ('_compileJSONCallback' in Module) {
        compilerAcceptsMultipleFiles = true;
        var missingInputsCallback = Module.Runtime.addFunction(function (path, contents, error) {
          missingInputs.push(Module.Pointer_stringify(path));
        });
        var compileInternal = Module.cwrap('compileJSONCallback', 'string', [ 'string', 'number', 'number' ]);
        compile = function (input, optimize) {
          missingInputs.length = 0;
          return compileInternal(input, optimize, missingInputsCallback);
        };
      } else if ('_compileJSONMulti' in Module) {
        compilerAcceptsMultipleFiles = true;
        compile = Module.cwrap('compileJSONMulti', 'string', [ 'string', 'number' ]);
      } else {
        compilerAcceptsMultipleFiles = false;
        compile = Module.cwrap('compileJSON', 'string', [ 'string', 'number' ]);
      }
      compileJSON = function (source, optimize, cb) {
        try {
          var result = compile(source, optimize);
        } catch (exception) {
          result = JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception });
        }
        compilationFinished(result, missingInputs);
      };
      setVersionText(Module.cwrap('version', 'string', [])());
    }
    previousInput = '';
    onChange();
  };
  this.onCompilerLoaded = onCompilerLoaded;<commit_msg>Compiler: onCompilerLoaded is not public anymore<commit_after>var webworkify = require('webworkify');
var queryParams = require('./query-params');
var utils = require('./utils');
var Renderer = require('./renderer');

var Base64 = require('js-base64').Base64;

function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles) {
  var renderer = new Renderer(editor, this, updateFiles);

  var compileJSON;
  var compilerAcceptsMultipleFiles;

  var previousInput = '';
  var sourceAnnotations = [];

  var cachedRemoteFiles = {};
  var worker = null;

  var compileTimeout = null;

  function onChange () {
    var input = editor.getValue();
    if (input === '') {
      editor.setCacheFileContent('');
      return;
    }
    if (input === previousInput) {
      return;
    }
    previousInput = input;
    if (compileTimeout) {
      window.clearTimeout(compileTimeout);
    }
    compileTimeout = window.setTimeout(compile, 300);
  }

  editor.onChangeSetup(onChange);

  var compile = function (missingInputs) {
    editor.clearAnnotations();
    sourceAnnotations = [];
    outputField.empty();
    var input = editor.getValue();
    editor.setCacheFileContent(input)

    var files = {};
    files[editor.getCacheFile()] = input;
    gatherImports(files, missingInputs, function (input, error) {
      outputField.empty();
      if (input === null) {
        renderer.error(error);
      } else {
        var optimize = queryParams.get().optimize;
        compileJSON(input, optimize ? 1 : 0);
      }
    });
  };
  this.compile = compile;

  this.addAnnotation = function (annotation) {
    sourceAnnotations[sourceAnnotations.length] = annotation;
    editor.setAnnotations(sourceAnnotations);
  };

  function onCompilerLoaded (setVersionText) {
    if (worker === null) {
      var compile;
      var missingInputs = [];
      if ('_compileJSONCallback' in Module) {
        compilerAcceptsMultipleFiles = true;
        var missingInputsCallback = Module.Runtime.addFunction(function (path, contents, error) {
          missingInputs.push(Module.Pointer_stringify(path));
        });
        var compileInternal = Module.cwrap('compileJSONCallback', 'string', [ 'string', 'number', 'number' ]);
        compile = function (input, optimize) {
          missingInputs.length = 0;
          return compileInternal(input, optimize, missingInputsCallback);
        };
      } else if ('_compileJSONMulti' in Module) {
        compilerAcceptsMultipleFiles = true;
        compile = Module.cwrap('compileJSONMulti', 'string', [ 'string', 'number' ]);
      } else {
        compilerAcceptsMultipleFiles = false;
        compile = Module.cwrap('compileJSON', 'string', [ 'string', 'number' ]);
      }
      compileJSON = function (source, optimize, cb) {
        try {
          var result = compile(source, optimize);
        } catch (exception) {
          result = JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception });
        }
        compilationFinished(result, missingInputs);
      };
      setVersionText(Module.cwrap('version', 'string', [])());
    }
    previousInput = '';
    onChange();
  };
{'fraction_non_alphanumeric': 0.1299730543667776, 'fraction_numerical': 0.0038040893961008085, 'mean_word_length': 3.1134289439374183, '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': '70932', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1733, 'n_words': 390}