示例#1
0
        // ECMA-262 13.3.1 Let and Const Declarations

        public Node parseLexicalBinding(string kind, Options options)
        {
            Node init = null;
            Node id;
            Node node = new Node();
            List<Token> @params = new List<Token>();

            id = parsePattern(@params, kind);

            // ECMA-262 12.2.1
            if (strict && id.type == Syntax.Identifier && isRestrictedWord(id.name))
            {
                tolerateError(Messages.StrictVarName);
            }

            if (kind == "const")
            {
                if (!matchKeyword("in") && !matchContextualKeyword("of"))
                {
                    expect("=");
                    init = isolateCoverGrammar(parseAssignmentExpression);
                }
            }
            else if ((!options.inFor && id.type != Syntax.Identifier) || match("="))
            {
                expect("=");
                init = isolateCoverGrammar(parseAssignmentExpression);
            }

            return node.finishVariableDeclarator(id, init);
        }
示例#2
0
        public Node parseVariableDeclaration(Options options)
        {
            Node init = null;
            Node id, node = new Node();
            List<Token> @params = new List<Token>();

            id = parsePattern(@params, "var");

            // ECMA-262 12.2.1
            if (strict && isRestrictedWord(id.name))
            {
                tolerateError(Messages.StrictVarName);
            }

            if (match("="))
            {
                lex();
                init = isolateCoverGrammar(parseAssignmentExpression);
            }
            else if (id.type != Syntax.Identifier && !options.inFor)
            {
                expect("=");
            }

            return node.finishVariableDeclarator(id, init);
        }