コード例 #1
0
ファイル: Esprima.cs プロジェクト: alfredoaguirre/Esprima.Net
        // ECMA-262 14.5 Class Definitions
        public Node parseClassBody()
        {
            Node classBody;
            Token token;
            bool isStatic, hasConstructor = false;
            List<Node> body;

            Node method;
            bool computed;
            Node key = null;

            classBody = new Node();

            expect("{");
            body = new List<Node>();
            while (!match("}"))
            {
                if (match(";"))
                {
                    lex();
                }
                else
                {
                    method = new Node();
                    token = lookahead;
                    isStatic = false;
                    computed = match("[");
                    if (match("*"))
                    {
                        lex();
                    }
                    else
                    {
                        key = parseObjectPropertyKey();
                        if (key.name == "static" && (lookaheadPropertyName() || match("*")))
                        {
                            token = lookahead;
                            isStatic = true;
                            computed = match("[");
                            if (match("*"))
                            {
                                lex();
                            }
                            else
                            {
                                key = parseObjectPropertyKey();
                            }
                        }
                    }
                    method = tryParseMethodDefinition(token, key, computed, method);
                    if (method != null)
                    {
                        // method["static"] = isStatic; // jscs:ignore requireDotNotation
                        if (method.kind == "init")
                        {
                            method.kind = "method";
                        }
                        if (!isStatic)
                        {
                            if (!method.computed && (method.key.name != null || method.key.value.ToString() == "constructor"))
                            {
                                if (method.kind != "method" || !method.method || method.value.generator)
                                {
                                    throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);
                                }
                                if (hasConstructor)
                                {
                                    throwUnexpectedToken(token, Messages.DuplicateConstructor);
                                }
                                else
                                {
                                    hasConstructor = true;
                                }
                                method.kind = "constructor";
                            }
                        }
                        else
                        {
                            if (!method.computed && (method.key.name != null || method.key.value.ToString() == "prototype"))
                            {
                                throwUnexpectedToken(token, Messages.StaticPrototype);
                            }
                        }
                        method.type = Syntax.MethodDefinition;
                        //delete
                        method.method = false;
                        //delete
                        method.shorthand = false;
                        body.Add(method);
                    }
                    else
                    {
                        throwUnexpectedToken(lookahead);
                    }
                }
            }
            lex();
            return classBody.finishClassBody(body);
        }