<commit_before>import Q from 'q';
import Snap from 'snapsvg';

import javascript from './javascript/parser.js';

export default class Parser {
  constructor() {
    this.state = {
      groupCounter: 1,
      renderCounter: 0,
      maxCounter: 0,
      cancelRender: false,
      warnings: []
    };
  }

  parse(expression) {
    var deferred = Q.defer();

    setTimeout(() => {
      try {
        javascript.Parser.SyntaxNode.state = this.state;

        this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
        deferred.resolve(this);
      }
      catch(e) {
        deferred.reject(e);
      }
    });

    return deferred.promise;
  }

  render(containerElement, svgBase) {
    var svg;

    containerElement.innerHTML += svgBase;

    svg = Snap(containerElement.querySelector('svg'));

    return this.parsed.render(svg.group())
      .then(result => {
        var box = result.getBBox();

        result.transform(Snap.matrix()
          .translate(10 - box.x, 10 - box.y));
        svg.attr({
          width: box.width + 20,
          height: box.height + 20
        });
      });
  }

  cancel() {
    this.state.cancelRender = true;
  }

  get warnings() {
    return this.state.warnings;
  }
}<commit_msg>Fixing issue with multiple SVG elements being rendered at once<commit_after>import Q from 'q';
import Snap from 'snapsvg';

import javascript from './javascript/parser.js';

export default class Parser {
  constructor() {
    this.state = {
      groupCounter: 1,
      renderCounter: 0,
      maxCounter: 0,
      cancelRender: false,
      warnings: []
    };
  }

  parse(expression) {
    var deferred = Q.defer();

    setTimeout(() => {
      try {
        javascript.Parser.SyntaxNode.state = this.state;

        this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
        deferred.resolve(this);
      }
      catch(e) {
        deferred.reject(e);
      }
    });

    return deferred.promise;
  }

  render(containerElement, svgBase) {
    var svg;

    containerElement.innerHTML = svgBase;

    svg = Snap(containerElement.querySelector('svg'));

    return this.parsed.render(svg.group())
      .then(result => {
        var box = result.getBBox();

        result.transform(Snap.matrix()
          .translate(10 - box.x, 10 - box.y));
        svg.attr({
          width: box.width + 20,
          height: box.height + 20
        });
      });
  }

  cancel() {
    this.state.cancelRender = true;
  }

  get warnings() {
    return this.state.warnings;
  }
}
{'fraction_non_alphanumeric': 0.13974663499604117, 'fraction_numerical': 0.00870942201108472, 'mean_word_length': 2.150872817955112, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5601296', 'n_tokens_mistral': 838, 'n_tokens_neox': 778, 'n_words': 161}