<commit_before>"use strict";

var util = require("../../util");
var t    = require("../../types");

exports.ForOfStatement = function (node, parent, scope, context, file) {
  var callback = spec;
  if (file.isLoose("forOf")) callback = loose;

  var build  = callback(node, parent, scope, context, file);
  var declar = build.declar;
  var loop   = build.loop;
  var block  = loop.body;

  // inherit comments from the original loop
  t.inheritsComments(loop, node);

  // ensure that it's a block so we can take all it's statemetns
  t.ensureBlock(node);

  // add the value declaration to the new loop body
  if (declar){
    if (build.shouldUnshift) {
      block.body.unshift(declar);
    } else {
      block.body.push(declar);
    }
  }

  // push the rest of the original loop body onto our new body
  block.body = block.body.concat(node.body.body);<commit_msg>fix forOf scope declarations not propagating to new for loop - fixes #538<commit_after>"use strict";

var util = require("../../util");
var t    = require("../../types");

exports.ForOfStatement = function (node, parent, scope, context, file) {
  var callback = spec;
  if (file.isLoose("forOf")) callback = loose;

  var build  = callback(node, parent, scope, context, file);
  var declar = build.declar;
  var loop   = build.loop;
  var block  = loop.body;

  // inherit comments from the original loop
  t.inheritsComments(loop, node);

  // ensure that it's a block so we can take all it's statemetns
  t.ensureBlock(node);

  // add the value declaration to the new loop body
  if (declar){
    if (build.shouldUnshift) {
      block.body.unshift(declar);
    } else {
      block.body.push(declar);
    }
  }

  // push the rest of the original loop body onto our new body
  block.body = block.body.concat(node.body.body);

  // todo: find out why this is necessary? #538
  loop._scopeInfo = node._scopeInfo;
{'fraction_non_alphanumeric': 0.12911795961742828, 'fraction_numerical': 0.003188097768331562, 'mean_word_length': 3.0845986984815617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6607845', 'n_tokens_mistral': 605, 'n_tokens_neox': 582, 'n_words': 198}