<commit_before>using Braille.AssemblyTransform;
using Braille.JSAst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Braille.MethodTransform
{
    class BlockBuilder
    {
        public List<JSStatement> Statements = new List<JSStatement>();

        private int depth;
        private bool hasBranching;

        public BlockBuilder(int depth)
        {
            this.depth = depth;
        }

        public IEnumerable<JSStatement> Build()
        {
            if (hasBranching)
            {
                yield return new JSStatement
                {
                    Expression = new JSVariableDelcaration
                    {
                        Name = "__braille_pos_" + depth + "__",
                        Value = new JSNumberLiteral { Value = 0, IsHex = true }
                    }
                };

                yield return new JSWhileLoopStatement
                {
                    Condition = new JSBoolLiteral
                    {
                        Value = true
                    },
                    Statements = new List<JSStatement> 
                    {
                        new JSSwitchStatement
                        {
                            Value = new JSIdentifier { Name = "__braille_pos_" + depth + "__" },
                            Statements = Statements
                        }
                    }
                };
            }
            else
            {
                foreach (var stmnt in Statements)
                    yield return stmnt;
            }
        }

        internal void InsertLabel(int p)
        {
            if (false == hasBranching)
                Statements.Insert(0, new JSSwitchCase { Value = new JSNumberLiteral { Value = 0, IsHex = true } });

            hasBranching = true;

            Statements.Add(new JSSwitchCase { Value = new JSNumberLiteral { Value = p, IsHex = true } });
        }

        internal void AddStatements(IEnumerable<JSStatement> statements)
        {
            Statements.AddRange(statements);
        }
    }
}<commit_msg>Generate valid js<commit_after>using Braille.AssemblyTransform;
using Braille.JSAst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Braille.MethodTransform
{
    class BlockBuilder
    {
        public List<JSStatement> Statements = new List<JSStatement>();

        private int depth;
        private bool hasBranching;

        public BlockBuilder(int depth)
        {
            this.depth = depth;
        }

        public IEnumerable<JSStatement> Build()
        {
            if (hasBranching)
            {
                yield return new JSStatement
                {
                    Expression = new JSVariableDelcaration
                    {
                        Name = "__braille_pos_" + depth + "__",
                        Value = new JSNumberLiteral { Value = 0, IsHex = true }
                    }
                };

                yield return new JSWhileLoopStatement
                {
                    Condition = new JSBoolLiteral
                    {
                        Value = true
                    },
                    Statements = new List<JSStatement> 
                    {
                        new JSSwitchStatement
                        {
                            Value = new JSIdentifier { Name = "__braille_pos_" + depth + "__" },
                            Statements = Statements
                        }
                    }
                };
            }
            else
            {
                foreach (var stmnt in Statements.Where(s => !(s.Expression is JSBreakExpression)))
                    yield return stmnt;
            }
        }

        internal void InsertLabel(int p)
        {
            if (false == hasBranching)
                Statements.Insert(0, new JSSwitchCase { Value = new JSNumberLiteral { Value = 0, IsHex = true } });

            hasBranching = true;

            Statements.Add(new JSSwitchCase { Value = new JSNumberLiteral { Value = p, IsHex = true } });
        }

        internal void AddStatements(IEnumerable<JSStatement> statements)
        {
            Statements.AddRange(statements);
        }
    }
}
{'fraction_non_alphanumeric': 0.06902161282825936, 'fraction_numerical': 0.0013943760167325122, 'mean_word_length': 1.1487768347478782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '1781608', 'n_tokens_mistral': 1038, 'n_tokens_neox': 985, 'n_words': 241}