<commit_before>/// <reference path="traverse.ts"/>
/// <reference path="watch.ts"/>
/// <reference path="data.ts"/>
/// <reference path="expression.ts"/>
/// <reference path="config.ts"/>
/// <reference path="connect.ts"/>
/// <reference path="directives/definition.ts"/>

module Parse {

    /** A section contains directives and blocks */
    export class Section {

        /** A list of priorities that exist within this section */
        private priorities: number[] = [];

        /** Directives and sections nested within this block */
        private nested: { [priority: number]: Connect.Connectable[] } = {};

        /** @constructor */
        constructor( public root: HTMLElement ) {}

        /** Adds a connectable to this section */
        push ( priority: number, connectable: Connect.Connectable ) {
            priority = priority || 0;

            // If this specific priority has never been seen, register it
            if ( !this.nested[priority] ) {
                this.nested[priority] = [];
                this.priorities.push(priority);
                this.priorities.sort((a, b) => { return b - a; });
            }

            this.nested[priority].push(connectable);
        }

        /** Adds everything from another section to this section */
        merge ( section: Section ) {
            section.priorities.forEach(priority => {
                section.nested[priority].forEach(connectable => {
                    this.push(priority, connectable);
                });
            });
        }

        /** @inheritDoc Connect#connect */
        connect(): void {
            this.priorities.forEach(priority => {
                this.nested[priority].forEach(inner => {
                    if ( inner.connect ) {
                        inner.connect();
                    }
                });
            });
        }

        /** @inheritDoc Connect#disconnect */
        disconnect(): void {
            this.priorities.forEach(priority => {
                this.nested[priority].forEach(inner => {
                    if ( inner.disconnect ) {
                        inner.disconnect();
                    }
                });
            });
        }

        /** Disconnects this section and removes it */
        destroy(): void {
            this.disconnect();
            this.root.parentNode.removeChild(this.root);
            this.nested = null;
        }
    }

    /** A node that can be cloned to create new sections */
    export class Cloneable {

        /** @constructor */
        constructor (
            public root: HTMLElement,
            private attrs: Array<Attr>,
            private config: Config.Config
        ) {}

        /** Parses a cloned node and returns the parsed section */
        private parse( cloned: HTMLElement, data: Data.Data ): Section {<commit_msg>Reduce stack depth when connecting<commit_after>/// <reference path="traverse.ts"/>
/// <reference path="watch.ts"/>
/// <reference path="data.ts"/>
/// <reference path="expression.ts"/>
/// <reference path="config.ts"/>
/// <reference path="connect.ts"/>
/// <reference path="directives/definition.ts"/>

module Parse {

    /** A section contains directives and blocks */
    export class Section {

        /** A list of priorities that exist within this section */
        private priorities: number[] = [];

        /** Directives and sections nested within this block */
        private nested: { [priority: number]: Connect.Connectable[] } = {};

        /** @constructor */
        constructor( public root: HTMLElement ) {}

        /** Adds a connectable to this section */
        push ( priority: number, connectable: Connect.Connectable ) {
            priority = priority || 0;

            // If this specific priority has never been seen, register it
            if ( !this.nested[priority] ) {
                this.nested[priority] = [];
                this.priorities.push(priority);
                this.priorities.sort((a, b) => { return b - a; });
            }

            this.nested[priority].push(connectable);
        }

        /** Adds everything from another section to this section */
        merge ( section: Section ) {
            section.priorities.forEach(priority => {
                section.nested[priority].forEach(connectable => {
                    this.push(priority, connectable);
                });
            });
        }

        /** @inheritDoc Connect#connect */
        connect(): void {
            for (var i = 0; i < this.priorities.length; i++) {
                var priority = this.priorities[i];
                for (var j = 0; j < this.nested[priority].length; j++) {
                    var inner = this.nested[priority][j];
                    if ( inner.connect ) {
                        inner.connect();
                    }
                }
            }
        }

        /** @inheritDoc Connect#disconnect */
        disconnect(): void {
            for (var i = 0; i < this.priorities.length; i++) {
                var priority = this.priorities[i];
                for (var j = 0; j < this.nested[priority].length; j++) {
                    var inner = this.nested[priority][j];
                    if ( inner.disconnect ) {
                        inner.disconnect();
                    }
                }
            }
        }

        /** Disconnects this section and removes it */
        destroy(): void {
            this.disconnect();
            this.root.parentNode.removeChild(this.root);
            this.nested = null;
        }
    }

    /** A node that can be cloned to create new sections */
    export class Cloneable {

        /** @constructor */
        constructor (
            public root: HTMLElement,
            private attrs: Array<Attr>,
            private config: Config.Config
        ) {}

        /** Parses a cloned node and returns the parsed section */
        private parse( cloned: HTMLElement, data: Data.Data ): Section {
{'fraction_non_alphanumeric': 0.12706353176588295, 'fraction_numerical': 0.0010005002501250625, 'mean_word_length': 1.555602897315722, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '5746487', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1411, 'n_words': 388}