<commit_before>﻿import * as ts from "typescript";
import * as errors from "./../../errors";
import {changeChildOrder, getGeneralFormatting} from "./../../manipulation";
import {Constructor} from "./../../Constructor";
import {Node} from "./../common";

export interface ChildOrderableNode {
    /**
     * Sets the child order of the node within the parent.
     */
    setOrder(order: number): this;
}

export function ChildOrderableNode<T extends Constructor<Node>>(Base: T): Constructor<ChildOrderableNode> & T {
    return class extends Base implements ChildOrderableNode {
        setOrder(order: number) {
            const childIndex = this.getChildIndex();
            errors.throwIfOutOfRange(order, [0, this.getChildCount() - 1], nameof(order));

            if (childIndex === order)
                return this;

            changeChildOrder({
                parent: this.getParentSyntaxList() || this.getParentOrThrow(),
                getSiblingFormatting: getGeneralFormatting,
                oldIndex: childIndex,
                newIndex: order
            });
            return this;
        }
    };
}
<commit_msg>fix: #244 - Fixes setOrder() bug where verify fails incorrectly.<commit_after>﻿import * as ts from "typescript";
import * as errors from "./../../errors";
import {changeChildOrder, getGeneralFormatting} from "./../../manipulation";
import {Constructor} from "./../../Constructor";
import {Node} from "./../common";

export interface ChildOrderableNode {
    /**
     * Sets the child order of the node within the parent.
     */
    setOrder(order: number): this;
}

export function ChildOrderableNode<T extends Constructor<Node>>(Base: T): Constructor<ChildOrderableNode> & T {
    return class extends Base implements ChildOrderableNode {
        setOrder(order: number) {
            const childIndex = this.getChildIndex();
            const parent = this.getParentSyntaxList() || this.getParentSyntaxListOrThrow();
            errors.throwIfOutOfRange(order, [0, parent.getChildCount() - 1], nameof(order));

            if (childIndex === order)
                return this;

            changeChildOrder({
                parent,
                getSiblingFormatting: getGeneralFormatting,
                oldIndex: childIndex,
                newIndex: order
            });
            return this;
        }
    };
}

{'fraction_non_alphanumeric': 0.12055837563451777, 'fraction_numerical': 0.002961082910321489, 'mean_word_length': 2.393113342898135, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3002755', 'n_tokens_mistral': 615, 'n_tokens_neox': 597, 'n_words': 170}