<commit_before>/**
 * Traverses a {content, widgets, images} renderer props object,
 * such as `itemData.question`
 *
 * This traversal is deep and handles some widget prop upgrades
 * (TODO(aria): Handle minor prop upgrades :) )
 *
 * This is the right way to traverse itemData.
 *
 * NOTE: We should not expose this on the perseus API yet. Instead,
 * build the traversal method you want inside perseus, and use this
 * from that. We might eventually expose this, but I'd like to be
 * more confident in the interface provided first.
 */

var _ = require("underscore");

var Widgets = require("./widgets.js");

var deepCallbackFor = function(callback) {
    var deepCallback = function(widgetInfo, widgetId) {
        callback(widgetInfo, widgetId);

        // This doesn't modify the widget info if the widget info
        // is at a later version than is supported, which is important
        // for our latestVersion test below.
        var upgradedWidgetInfo = Widgets.upgradeWidgetInfoToLatestVersion(
            widgetInfo
        );
        var latestVersion = Widgets.getVersion(upgradedWidgetInfo.type);

        // Only traverse our children if we can understand this version
        // of the widget props.
        // TODO(aria): This will break if the traversal code assumes that
        // any props that usually get defaulted in are present. That is,
        // it can fail on minor version upgrades.
        // For this reason, and because the upgrade code doesn't handle
        // minor versions correctly (it doesn't report anything useful
        // about what minor version a widget is actually at, since it
        // doesn't have meaning in the context of upgrades), we
        // just check the major version here.
        // TODO(aria): This is seriously quirky and would be unpleasant
        // to think about while writing traverseChildWidgets code. Please
        // make all of this a little tighter.
        // I think once we use react class defaultProps instead of relying
        // on getDefaultProps, this will become easier.
        if (latestVersion && (
                upgradedWidgetInfo.version.major === latestVersion.major)) {
            Widgets.traverseChildWidgets(
                widgetInfo,
                deepCallback, // so that we traverse grandchildren, too!
                traverseRenderer // not deep because we are getting the
                                 // deepness from the deepCallback
            );
        }
    };
    return deepCallback;
};<commit_msg>[traversal] Fix bug where non-upgraded widgetInfo was used<commit_after>/**
 * Traverses a {content, widgets, images} renderer props object,
 * such as `itemData.question`
 *
 * This traversal is deep and handles some widget prop upgrades
 * (TODO(aria): Handle minor prop upgrades :) )
 *
 * This is the right way to traverse itemData.
 *
 * NOTE: We should not expose this on the perseus API yet. Instead,
 * build the traversal method you want inside perseus, and use this
 * from that. We might eventually expose this, but I'd like to be
 * more confident in the interface provided first.
 */

var _ = require("underscore");

var Widgets = require("./widgets.js");

var deepCallbackFor = function(callback) {
    var deepCallback = function(widgetInfo, widgetId) {
        callback(widgetInfo, widgetId);

        // This doesn't modify the widget info if the widget info
        // is at a later version than is supported, which is important
        // for our latestVersion test below.
        var upgradedWidgetInfo = Widgets.upgradeWidgetInfoToLatestVersion(
            widgetInfo
        );
        var latestVersion = Widgets.getVersion(upgradedWidgetInfo.type);

        // Only traverse our children if we can understand this version
        // of the widget props.
        // TODO(aria): This will break if the traversal code assumes that
        // any props that usually get defaulted in are present. That is,
        // it can fail on minor version upgrades.
        // For this reason, and because the upgrade code doesn't handle
        // minor versions correctly (it doesn't report anything useful
        // about what minor version a widget is actually at, since it
        // doesn't have meaning in the context of upgrades), we
        // just check the major version here.
        // TODO(aria): This is seriously quirky and would be unpleasant
        // to think about while writing traverseChildWidgets code. Please
        // make all of this a little tighter.
        // I think once we use react class defaultProps instead of relying
        // on getDefaultProps, this will become easier.
        if (latestVersion && (
                upgradedWidgetInfo.version.major === latestVersion.major)) {
            Widgets.traverseChildWidgets(
                upgradedWidgetInfo,
                deepCallback, // so that we traverse grandchildren, too!
                traverseRenderer // not deep because we are getting the
                                 // deepness from the deepCallback
            );
        }
    };
    return deepCallback;
};
{'fraction_non_alphanumeric': 0.0703232125367287, 'fraction_numerical': 0.0, 'mean_word_length': 2.37029702970297, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7415842', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1199, 'n_words': 563}