<commit_before>import NodePatcher from './NodePatcher';
import type { Node, ParseContext, Editor } from './types';

export default class FunctionPatcher extends NodePatcher {
  constructor(node: Node, context: ParseContext, editor: Editor, parameters: Array<NodePatcher>, body: ?NodePatcher) {
    super(node, context, editor);
    this.parameters = parameters;
    this.body = body;

    let { source } = context;
    while (source[this.after - '\n'.length] === '\n') {
      this.after -= '\n'.length;
    }
    while (source[this.end - '\n'.length] === '\n') {
      this.end -= '\n'.length;
    }

    body.setImplicitlyReturns();
  }

  patch({ method=false }={}) {
    let { parameters, body, node, context } = this;
    let tokens = context.tokensForNode(node);
    let isStatement = !this.willPatchAsExpression();

    if (isStatement) {
      this.insertAtStart('(');
    }

    this.patchFunctionStart({ method }, tokens);
    parameters.forEach(parameter => parameter.patch());
    if (body) {
      body.patch({ function: true, leftBrace: false });
    }

    if (isStatement) {
      this.insertAtEnd(')');
    }
  }

  patchFunctionStart({ method=false }, tokens) {
    let arrowIndex = 0;

    if (!method) {
      this.insertAtStart('function');
    }<commit_msg>Fix functions with empty bodies.<commit_after>import NodePatcher from './NodePatcher';
import type { Node, ParseContext, Editor } from './types';

export default class FunctionPatcher extends NodePatcher {
  constructor(node: Node, context: ParseContext, editor: Editor, parameters: Array<NodePatcher>, body: ?NodePatcher) {
    super(node, context, editor);
    this.parameters = parameters;
    this.body = body;

    let { source } = context;
    while (source[this.after - '\n'.length] === '\n') {
      this.after -= '\n'.length;
    }
    while (source[this.end - '\n'.length] === '\n') {
      this.end -= '\n'.length;
    }
  }

  initialize() {
    if (this.body) {
      this.body.setImplicitlyReturns();
    }
  }

  patch({ method=false }={}) {
    let { parameters, body, node, context } = this;
    let tokens = context.tokensForNode(node);
    let isStatement = !this.willPatchAsExpression();

    if (isStatement) {
      this.insertAtStart('(');
    }

    this.patchFunctionStart({ method }, tokens);
    parameters.forEach(parameter => parameter.patch());
    if (body) {
      body.patch({ leftBrace: false });
    } else {
      // No body, so BlockPatcher can't insert it for us.
      this.insertAtEnd('}');
    }

    if (isStatement) {
      this.insertAtEnd(')');
    }
  }

  patchFunctionStart({ method=false }, tokens) {
    let arrowIndex = 0;

    if (!method) {
      this.insertAtStart('function');
    }
{'fraction_non_alphanumeric': 0.15868924889543445, 'fraction_numerical': 0.0007363770250368188, 'mean_word_length': 2.954876273653566, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6251936', 'n_tokens_mistral': 842, 'n_tokens_neox': 821, 'n_words': 198}