<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var assert = require('assert');
var Parser = require('jade/lib/parser.js');
var jade = require('jade/lib/runtime.js');
var React = require('react');
var staticModule = require('static-module');
var resolve = require('resolve');
var uglify = require('uglify-js');
var Compiler = require('./lib/compiler.js');
var JavaScriptCompressor = require('./lib/java-script-compressor.js');

var reactRuntimePath = require.resolve('react');

exports = (module.exports = browserifySupport);
function browserifySupport(options, extra) {
  function transform(filename) {
    function clientRequire(path) {
      return require(clientRequire.resolve(path));
    }
    clientRequire.resolve = function (path) {
      return resolve.sync(path, {
        basedir: path.dirname(filename)
      });
    };
    return staticModule({
    'react-jade': {
        compileFile: function (jadeFile, localOptions) {
          localOptions = localOptions || {};
          for (var key in options) {
            if ((key in options) && !(key in localOptions))
            localOptions[key] = options[key];
          }
          localOptions.outputFile = filename;
          return compileFileClient(jadeFile, localOptions);
        }
      }
    }, {
      vars: {
        __dirname: path.dirname(filename),
        __filename: path.resolve(filename),
        path: path,
        require: clientRequire
      }
    });
  }
  if (typeof options === 'string') {
    var file = options;
    options = extra || {};
    return transform(file);
  } else {
    options = options || {};
    return transform;
  }
}

function parseFile(filename, options) {
  var str = fs.readFileSync(filename, 'utf8');
  var options = options || {};
  options.filename = path.resolve(filename);
  var parser = new Parser(str, options.filename, options);
  var tokens;
  try {
    // Parse
    tokens = parser.parse();
  } catch (err) {
    parser = parser.context();
    jade.rethrow(err, parser.filename, parser.lexer.lineno, parser.input);
  }
  var compiler = new Compiler(tokens);
  var js = 'exports = function (locals) {' +
    'function jade_join_classes(val) {' +
    'return Array.isArray(val) ? val.map(jade_join_classes).filter(function (val) { return val != null && val !== ""; }).join(" ") : val;' +
    '};' +
    'var jade_interp;' +
    'jade_variables(locals);' +
    compiler.compile() +
    '}';
  try {
    Function('', js);
  } catch (ex) {
    console.log(js);
    throw ex;
  }
  var ast = uglify.parse(js, {filename: filename});
<commit_msg>Comment on interim check that jade compiles to sane js<commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var assert = require('assert');
var Parser = require('jade/lib/parser.js');
var jade = require('jade/lib/runtime.js');
var React = require('react');
var staticModule = require('static-module');
var resolve = require('resolve');
var uglify = require('uglify-js');
var Compiler = require('./lib/compiler.js');
var JavaScriptCompressor = require('./lib/java-script-compressor.js');

var reactRuntimePath = require.resolve('react');

exports = (module.exports = browserifySupport);
function browserifySupport(options, extra) {
  function transform(filename) {
    function clientRequire(path) {
      return require(clientRequire.resolve(path));
    }
    clientRequire.resolve = function (path) {
      return resolve.sync(path, {
        basedir: path.dirname(filename)
      });
    };
    return staticModule({
    'react-jade': {
        compileFile: function (jadeFile, localOptions) {
          localOptions = localOptions || {};
          for (var key in options) {
            if ((key in options) && !(key in localOptions))
            localOptions[key] = options[key];
          }
          localOptions.outputFile = filename;
          return compileFileClient(jadeFile, localOptions);
        }
      }
    }, {
      vars: {
        __dirname: path.dirname(filename),
        __filename: path.resolve(filename),
        path: path,
        require: clientRequire
      }
    });
  }
  if (typeof options === 'string') {
    var file = options;
    options = extra || {};
    return transform(file);
  } else {
    options = options || {};
    return transform;
  }
}

function parseFile(filename, options) {
  var str = fs.readFileSync(filename, 'utf8');
  var options = options || {};
  options.filename = path.resolve(filename);
  var parser = new Parser(str, options.filename, options);
  var tokens;
  try {
    // Parse
    tokens = parser.parse();
  } catch (err) {
    parser = parser.context();
    jade.rethrow(err, parser.filename, parser.lexer.lineno, parser.input);
  }
  var compiler = new Compiler(tokens);
  var js = 'exports = function (locals) {' +
    'function jade_join_classes(val) {' +
    'return Array.isArray(val) ? val.map(jade_join_classes).filter(function (val) { return val != null && val !== ""; }).join(" ") : val;' +
    '};' +
    'var jade_interp;' +
    'jade_variables(locals);' +
    compiler.compile() +
    '}';
    
  // Check that the compiled JavaScript code is valid thus far.
  // uglify-js throws very cryptic errors when it fails to parse code.  
  try {
    Function('', js);
  } catch (ex) {
    console.log(js);
    throw ex;
  }
  
  var ast = uglify.parse(js, {filename: filename});

{'fraction_non_alphanumeric': 0.1498510796723753, 'fraction_numerical': 0.00037230081906180194, 'mean_word_length': 3.0337837837837838, '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': '429338', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1608, 'n_words': 390}