示例#1
0
        public Node parseExportAllDeclaration(Node node)
        {
            string src = null;

            // covers:
            // export * from "foo";
            expect("*");
            if (!matchContextualKeyword("from"))
            {
                throwError(lookahead.value != null
                    ? Messages.UnexpectedToken
                    : Messages.MissingFromClause, lookahead.value);
            }
            lex();
            //src = parseModuleSpecifier();
            consumeSemicolon();

            return node.finishExportAllDeclaration(src);
        }
示例#2
0
 public Node finishExportSpecifier(Node local, Node exported)
 {
     this.type = Syntax.ExportSpecifier;
     this.exported = exported ?? local;
     this.local = local;
     this.finish();
     return this;
 }
示例#3
0
 public Node finishImportSpecifier(Node local, Node imported)
 {
     this.type = Syntax.ImportSpecifier;
     this.local = local ?? imported;
     this.imported = imported;
     this.finish();
     return this;
 }
示例#4
0
 public Node finishThrowStatement(Node argument)
 {
     this.type = Syntax.ThrowStatement;
     this.argument = argument;
     this.finish();
     return this;
 }
示例#5
0
 public Node finishUnaryExpression(string @operator, Node argument)
 {
     this.type = (@operator == "++" || @operator == "--") ? Syntax.UpdateExpression : Syntax.UnaryExpression;
     this.@operator = @operator;
     this.argument = argument;
     this.prefix = true;
     this.finish();
     return this;
 }
示例#6
0
 public Node finishProperty(string kind, Node key, bool computed, Node value, bool method, bool shorthand)
 {
     this.type = Syntax.Property;
     this.key = key;
     this.computed = computed;
     this.value = value;
     this.kind = kind;
     this.method = method;
     this.shorthand = shorthand;
     this.finish();
     return this;
 }
示例#7
0
 public Node finishSpreadElement(Node argument)
 {
     this.type = Syntax.SpreadElement;
     this.argument = argument;
     this.finish();
     return this;
 }
示例#8
0
        public Node parseProgram()
        {
            List<Node> body;
            Node node;

            peek();
            node = new Node();

            body = parseScriptBody();
            return node.finishProgram(body, state.sourceType);
        }
示例#9
0
 public Node finishArrowFunctionExpression(List<Node> @params, object defaults, List<Node> body, Node expression)
 {
     this.type = Syntax.ArrowFunctionExpression;
     this.id = null;
     this.@params = @params;
     this.defaults = defaults;
     this.body = body;
     this.generator = false;
     this.expression = expression;
     this.finish();
     return this;
 }
示例#10
0
        public Node parseImportNamespaceSpecifier()
        {
            // import <* as foo> ...;
            Node local;
            Node node = new Node();

            expect("*");
            if (!matchContextualKeyword("as"))
            {
                throwError(Messages.NoAsAfterImportNamespace);
            }
            lex();
            local = parseNonComputedProperty();

            return node.finishImportNamespaceSpecifier(local);
        }
示例#11
0
        public Node parseImportDeclaration()
        {
            List<Node> specifiers = new List<Node>();
            Node src;
            Node node = new Node();

            if (state.inFunctionBody)
            {
                throwError(Messages.IllegalImportDeclaration);
            }

            expectKeyword("import");

            if (lookahead.type == TokenType.StringLiteral)
            {
                // import "foo";
                src = parseModuleSpecifier();
            }
            else
            {

                if (match("{"))
                {
                    // import {bar}
                    specifiers = specifiers.Concat(parseNamedImports()).ToList();
                }
                else if (match("*"))
                {
                    // import * as foo
                    specifiers.Add(parseImportNamespaceSpecifier());
                }
                else if (isIdentifierName(lookahead) && !matchKeyword("default"))
                {
                    // import foo
                    specifiers.Add(parseImportDefaultSpecifier());
                    if (match(","))
                    {
                        lex();
                        if (match("*"))
                        {
                            // import foo, * as foo
                            specifiers.Add(parseImportNamespaceSpecifier());
                        }
                        else if (match("{"))
                        {
                            // import foo, {bar}
                            specifiers = specifiers.Concat(parseNamedImports()).ToList();
                        }
                        else
                        {
                            throwUnexpectedToken(lookahead);
                        }
                    }
                }
                else
                {
                    throwUnexpectedToken(lex());
                }

                if (!matchContextualKeyword("from"))
                {
                    throwError(
                        string.IsNullOrEmpty(lookahead.value) ? Messages.UnexpectedToken : Messages.MissingFromClause,
                        lookahead.value);
                }
                lex();
                src = parseModuleSpecifier();
            }

            consumeSemicolon();
            return node.finishImportDeclaration(specifiers, src.ToString());
        }
示例#12
0
        public Node parseImportDefaultSpecifier()
        {
            // import <foo> ...;
            Node local;
            Node node = new Node();

            local = parseNonComputedProperty();

            return node.finishImportDefaultSpecifier(local);
        }
示例#13
0
        // ECMA-262 15.2.2 Imports
        public Node parseImportSpecifier()
        {
            // import {<foo as bar>} ...;
            Node local = null;
            Node imported;
            Node node = new Node();

            imported = parseNonComputedProperty();
            if (matchContextualKeyword("as"))
            {
                lex();
                local = parseVariableIdentifier();
            }

            return node.finishImportSpecifier(local, imported);
        }
示例#14
0
        public Node parseExportDeclaration()
        {
            var node = new Node();
            if (state.inFunctionBody)
            {
                throwError(Messages.IllegalExportDeclaration);
            }

            expectKeyword("export");

            if (matchKeyword("default"))
            {
                return parseExportDefaultDeclaration(node);
            }
            if (match("*"))
            {
                return parseExportAllDeclaration(node);
            }
            return parseExportNamedDeclaration(node);
        }
示例#15
0
 public Node finishFunctionExpression(Node id, List<Node> @params, object defaults, List<Node> body,
     bool generator)
 {
     this.type = Syntax.FunctionExpression;
     this.id = id;
     this.@params = @params;
     this.defaults = defaults;
     this.body = body;
     this.generator = generator;
     this.expression = null;
     this.finish();
     return this;
 }
示例#16
0
 public Node finishAssignmentExpression(string @operator, Node left, Node right)
 {
     this.type = Syntax.AssignmentExpression;
     this.@operator = @operator;
     this.left = left;
     this.right = right;
     this.finish();
     return this;
 }
示例#17
0
 public Node finishPostfixExpression(string @operator, Node argument)
 {
     this.type = Syntax.UpdateExpression;
     this.@operator = @operator;
     this.argument = argument;
     this.prefix = false;
     this.finish();
     return this;
 }
示例#18
0
 public Node finishAssignmentPattern(Node left, Node right)
 {
     this.type = Syntax.AssignmentPattern;
     this.left = left;
     this.right = right;
     this.finish();
     return this;
 }
示例#19
0
 public Node finishRestElement(Node argument)
 {
     this.type = Syntax.RestElement;
     this.argument = argument;
     this.finish();
     return this;
 }
示例#20
0
 public Node finishBinaryExpression(string @operator, Node left, Node right)
 {
     this.type = (@operator == "||" || @operator == "&&")
         ? Syntax.LogicalExpression
         : Syntax.BinaryExpression;
     this.@operator = @operator;
     this.left = left;
     this.right = right;
     this.finish();
     return this;
 }
示例#21
0
 public Node finishTemplateElement(Node value, object tail)
 {
     this.type = Syntax.TemplateElement;
     this.value = value;
     this.tail = tail;
     this.finish();
     return this;
 }
示例#22
0
 public Node finishCatchClause(Node param, List<Node> body)
 {
     this.type = Syntax.CatchClause;
     this.param = param;
     this.body = body;
     this.finish();
     return this;
 }
示例#23
0
 public Node finishTryStatement(Node block, Node handler, Node finalizer)
 {
     this.type = Syntax.TryStatement;
     this.block = block;
     this.guardedHandlers = new List<object>();
     this.handlers = handler != null ? new List<object>() { handler } : new List<object>();
     this.handler = handler;
     this.finalizer = finalizer;
     this.finish();
     return this;
 }
示例#24
0
 public Node finishClassExpression(Node id, Node superClass, List<Node> body)
 {
     this.type = Syntax.ClassExpression;
     this.id = id;
     this.superClass = superClass;
     this.body = body;
     this.finish();
     return this;
 }
示例#25
0
 public Node finishVariableDeclarator(Node id, object init)
 {
     this.type = Syntax.VariableDeclarator;
     this.id = id;
     this.init = init;
     this.finish();
     return this;
 }
示例#26
0
 public Node finishExpressionStatement(Node expression)
 {
     this.type = Syntax.ExpressionStatement;
     this.expression = expression;
     this.finish();
     return this;
 }
示例#27
0
 public Node finishImportNamespaceSpecifier(Node local)
 {
     this.type = Syntax.ImportNamespaceSpecifier;
     this.local = local;
     this.finish();
     return this;
 }
示例#28
0
 public Node finishForInStatement(Node left, Node right, List<Node> body)
 {
     this.type = Syntax.ForInStatement;
     this.left = left;
     this.right = right;
     this.body = body;
     this.each = false;
     this.finish();
     return this;
 }
示例#29
0
 public Node finishYieldExpression(Node argument, bool @delegate)
 {
     this.type = Syntax.YieldExpression;
     this.argument = argument;
     this.@delegate = @delegate;
     this.finish();
     return this;
 }
示例#30
0
        public Node parseExportDefaultDeclaration(Node node)
        {
            Node declaration = null,
                expression = null;

            // covers:
            // export default ...
            expectKeyword("default");

            if (matchKeyword("function"))
            {
                // covers:
                // export default function foo () {}
                // export default function () {}
                declaration = parseFunctionDeclaration(new Node(), true);
                return node.finishExportDefaultDeclaration(declaration);
            }
            if (matchKeyword("class"))
            {
                declaration = parseClassDeclaration(true);
                return node.finishExportDefaultDeclaration(declaration);
            }

            if (matchContextualKeyword("from"))
            {
                throwError(string.Format(Messages.UnexpectedToken, lookahead.value));
            }

            // covers:
            // export default {};
            // export default [];
            // export default (1 + 2);
            if (match("{"))
            {
                expression = parseObjectInitializer();
            }
            else if (match("["))
            {
                expression = parseArrayInitializer();
            }
            else
            {
                expression = parseAssignmentExpression();
            }
            consumeSemicolon();
            return node.finishExportDefaultDeclaration(expression);
        }