예제 #1
0
        public override void VisitSwitchStatement(SwitchStatementSyntax node)
        {
            var afterSwitchState = GetNextState();

            var sectionStates      = node.Sections.Select(x => GetNextState()).ToArray();
            var newSwitchStatement = Js.Switch(
                (JsExpression)node.Expression.Accept(Transformer),
                node.Sections
                .Select((x, i) =>
            {
                var section = Js.Section(x.Labels.Select(y => y.Value != null ? Js.CaseLabel((JsExpression)y.Value.Accept(Transformer)) : Js.DefaultLabel()).ToArray());
                section.Statements.AddRange(GotoStateStatements(sectionStates[i]));
                return(section);
            })
                .ToArray());

            CurrentState.Add(newSwitchStatement);
            GotoState(afterSwitchState);

            Accept(() =>
            {
                for (var i = 0; i < node.Sections.Count; i++)
                {
                    var section      = node.Sections[i];
                    var sectionState = sectionStates[i];
                    CurrentState     = sectionState;
                    foreach (var statement in section.Statements)
                    {
                        AcceptStatement(statement);
                    }
                }
            }, afterSwitchState);

            CurrentState = afterSwitchState;
        }