<commit_before>const tmp = require('tmp');
const fs = require('fs');

function isReactComponent(source = '') {
  return source.indexOf('(_react.Component)') > -1;
}

function WebpackAccessibilityPlugin(options) {
  this.createElement = options.createElement;
  this.renderMarkup = options.renderMarkup;
}

WebpackAccessibilityPlugin.prototype.apply = (compiler) => {
  compiler.plugin('emit', (compilation, callback) => {
    // Explore each chunk (build output):
    compilation.chunks.forEach((chunk) => {
      // Start with application specific modules
      chunk.modules
        .filter(module => module.resource && module.resource.indexOf('node_modules') === -1 && module.resource.match(/\.(js|jsx)$/))
        .map(module => module._source._value) // eslint-disable-line no-underscore-dangle
        .filter(isReactComponent)
        .forEach((source) => {
          // Write to temporary file
          tmp.file({ postfix: '.js', dir: `${__dirname}/tmp` }, (tmpErr, path, fd, cleanupCallback) => {
            if (tmpErr) throw tmpErr;

            fs.writeFile(path, source, (err) => {
              if (err) throw err;

              const component = require(path).default; // eslint-disable-line
              const element = this.createElement(component);
              const markup = this.renderMarkup(element);

              // Run a11y report on markup!
              console.log(markup); // eslint-disable-line

              cleanupCallback();
            });
          });
        }, this);
    }, this);

    callback();
  });
};

module.exports = WebpackAccessibilityPlugin;<commit_msg>use class syntax for better this support.<commit_after>const tmp = require('tmp');
const fs = require('fs');

const isReactComponent = source => source.indexOf('(_react.Component)') > -1;

class AccessibilityWebpackPlugin {
  constructor(options) {
    this.createElement = options.createElement;
    this.renderMarkup = options.renderMarkup;
  }

  apply(compiler) {
    compiler.plugin('emit', (compilation, callback) => {
      // Explore each chunk (build output):
      compilation.chunks.forEach((chunk) => {
        // Start with application specific modules
        chunk.modules
          .filter(module => module.resource && module.resource.indexOf('node_modules') === -1 && module.resource.match(/\.(js|jsx)$/))
          .map(module => module._source._value) // eslint-disable-line no-underscore-dangle
          .filter(isReactComponent)
          .forEach((source) => {
            // Write to temporary file
            tmp.file({ postfix: '.js', dir: `${__dirname}/tmp` }, (tmpErr, path, fd, cleanupCallback) => {
              if (tmpErr) throw tmpErr;

              fs.writeFile(path, source, (err) => {
                if (err) throw err;

                const component = require(path).default; // eslint-disable-line
                const element = this.createElement(component);
                const markup = this.renderMarkup(element);

                // Run a11y report on markup!
                console.log(markup); // eslint-disable-line

                cleanupCallback();
              });
            });
          });
      });

      callback();
    });
  }
}

module.exports = AccessibilityWebpackPlugin;
{'fraction_non_alphanumeric': 0.14184615384615384, 'fraction_numerical': 0.0024615384615384616, 'mean_word_length': 2.3794178794178795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '1802542', 'n_tokens_mistral': 888, 'n_tokens_neox': 868, 'n_words': 187}