<commit_before>/* @flow */
import React from 'react';
import ReactDOM from 'react-dom';

type Props = {
  data: string,
};

export default class JavaScript extends React.Component {
  props: Props;

  componentDidMount(): void {
    if (this.refs.here) {
      try {
        // Compatibility with Jupyter/notebook JS evaluation.  Set element so
        // the user has a handle on the context of the current output.
        const element = ReactDOM.findDOMNode(this.refs.here); // eslint-disable-line
        eval(this.props.data); // eslint-disable-line
      } catch (err) {
        console.error('Could not execute user Javascript', err); //eslint-disable-line
      }
    }
  }

  shouldComponentUpdate(): boolean {
    return false;
  }

  render(): ?React.Element<any> {
    return (
      <div ref="here" />
    );
  }
}<commit_msg>refactor(javascript-transform): rely on callback refs, more informative error handling<commit_after>/* @flow */
import React from 'react';
import ReactDOM from 'react-dom';

type Props = {
  data: string,
};

export default class JavaScript extends React.Component {
  props: Props;

  componentDidMount(): void {
    // Compatibility with Jupyter/notebook JS evaluation.  Set element so
    // the user has a handle on the context of the current output.
    const element = this.el;
    try {
      eval(this.props.data); // eslint-disable-line no-eval
    } catch (err) {
      const pre = document.createElement('pre');
      if (err.stack) {
        pre.textContent = err.stack;
      } else {
        pre.textContent = err;
      }
      element.appendChild(pre);
    }
  }

  shouldComponentUpdate(): boolean {
    return false;
  }

  render(): ?React.Element<any> {
    return (
      <div ref={(el) => { this.el = el; }} />
    );
  }
}
{'fraction_non_alphanumeric': 0.12612107623318386, 'fraction_numerical': 0.0, 'mean_word_length': 2.591549295774648, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '5444148', 'n_tokens_mistral': 548, 'n_tokens_neox': 537, 'n_words': 154}