<commit_before>import MagicString from 'magic-string';
import NodePatcher from '../patchers/NodePatcher.js';
import PatchError from '../utils/PatchError.js';
import parse from '../utils/parse.js';
import type { Node, ParseContext, Editor } from '../patchers/types.js';
import { basename } from 'path';
import { childPropertyNames } from '../utils/traverse.js';
import { logger } from '../utils/debug.js';

export default class TransformCoffeeScriptStage {
  static run(content: string, filename: string): { code: string, map: Object } {
    let log = logger(this.name);
    log(content);

    let ast = parse(content);
    let editor = new MagicString(content);
    let stage = new this(ast, ast.context, editor);
    let patcher = stage.build();
    patcher.patch();
    return {
      code: editor.toString(),
      map: editor.generateMap({
        source: filename,
        file: `${basename(filename, this.inputExtension)}-${this.name}${this.outputExtension}`,
        includeContent: true
      })
    };
  }

  static get inputExtension() {
    return '.coffee';
  }

  static get outputExtension() {
    return '.js';
  }

  constructor(ast: Node, context: ParseContext, editor: Editor) {
    this.ast = ast;
    this.context = context;
    this.editor = editor;
    this.root = null;
    this.patchers = [];
  }

  /* eslint-disable no-unused-vars */
  /**
   * This should be overridden in subclasses.
   */
  patcherConstructorForNode(node: Node): ?Class<NodePatcher> {
    return null;
  }
  /* eslint-enable no-unused-vars */

  build(): NodePatcher {
    this.root = this.patcherForNode(this.ast);
    this.patchers.forEach(patcher => patcher.initialize());
    return this.root;
  }

  patcherForNode(node: Node, parent: ?Class<NodePatcher>=null, property: ?string=null): NodePatcher {
    let constructor = this._patcherConstructorForNode(node);

    if (parent) {
      let override = parent.patcherClassForChildNode(node, property);
      if (override) {
        constructor = override;
      }
    }

    let children = childPropertyNames(node).map(name => {
      let child = node[name];
      if (!child) {
        return null;
      } else if (Array.isArray(child)) {
        return child.map(item =>
          this.patcherForNode(item, constructor, name)
        );
      } else {
        return this.patcherForNode(child, constructor, name);
      }
    });

    let patcher = new constructor(node, this.context, this.editor, ...children);<commit_msg>Use the line style for disabling eslint.<commit_after>import MagicString from 'magic-string';
import NodePatcher from '../patchers/NodePatcher.js';
import PatchError from '../utils/PatchError.js';
import parse from '../utils/parse.js';
import type { Node, ParseContext, Editor } from '../patchers/types.js';
import { basename } from 'path';
import { childPropertyNames } from '../utils/traverse.js';
import { logger } from '../utils/debug.js';

export default class TransformCoffeeScriptStage {
  static run(content: string, filename: string): { code: string, map: Object } {
    let log = logger(this.name);
    log(content);

    let ast = parse(content);
    let editor = new MagicString(content);
    let stage = new this(ast, ast.context, editor);
    let patcher = stage.build();
    patcher.patch();
    return {
      code: editor.toString(),
      map: editor.generateMap({
        source: filename,
        file: `${basename(filename, this.inputExtension)}-${this.name}${this.outputExtension}`,
        includeContent: true
      })
    };
  }

  static get inputExtension() {
    return '.coffee';
  }

  static get outputExtension() {
    return '.js';
  }

  constructor(ast: Node, context: ParseContext, editor: Editor) {
    this.ast = ast;
    this.context = context;
    this.editor = editor;
    this.root = null;
    this.patchers = [];
  }

  /**
   * This should be overridden in subclasses.
   */
  patcherConstructorForNode(node: Node): ?Class<NodePatcher> { // eslint-disable-line no-unused-vars
    return null;
  }

  build(): NodePatcher {
    this.root = this.patcherForNode(this.ast);
    this.patchers.forEach(patcher => patcher.initialize());
    return this.root;
  }

  patcherForNode(node: Node, parent: ?Class<NodePatcher>=null, property: ?string=null): NodePatcher {
    let constructor = this._patcherConstructorForNode(node);

    if (parent) {
      let override = parent.patcherClassForChildNode(node, property);
      if (override) {
        constructor = override;
      }
    }

    let children = childPropertyNames(node).map(name => {
      let child = node[name];
      if (!child) {
        return null;
      } else if (Array.isArray(child)) {
        return child.map(item =>
          this.patcherForNode(item, constructor, name)
        );
      } else {
        return this.patcherForNode(child, constructor, name);
      }
    });

    let patcher = new constructor(node, this.context, this.editor, ...children);
{'fraction_non_alphanumeric': 0.1374493927125506, 'fraction_numerical': 0.0, 'mean_word_length': 3.0072992700729926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '5887607', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1438, 'n_words': 361}