Example #1
0
        // ECMA-262 13.3.3 Destructuring Binding Patterns

        public Node parseArrayPattern(List<Token> @params, string kind)
        {
            var node = new Node();
            List<Node> elements = new List<Node>();
            Node rest;
            Node restNode;
            expect("[");

            while (!match("]"))
            {
                if (match(","))
                {
                    lex();
                    elements.Add(null);
                }
                else
                {
                    if (match("..."))
                    {
                        restNode = new Node();
                        lex();
                        @params.Add(lookahead);
                        rest = parseVariableIdentifier(kind);
                        //rest = parseVariableIdentifier(@params, kind);
                        elements.Add(restNode.finishRestElement(rest));
                        break;
                    }
                    else
                    {
                        elements.Add(parsePatternWithDefault(@params, kind));
                    }
                    if (!match("]"))
                    {
                        expect(",");
                    }
                }

            }

            expect("]");

            return node.finishArrayPattern(elements);
        }