Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public Node finishExportSpecifier(Node local, Node exported)
 {
     this.type = Syntax.ExportSpecifier;
     this.exported = exported ?? local;
     this.local = local;
     this.finish();
     return this;
 }
Exemplo n.º 3
0
 public Node finishImportSpecifier(Node local, Node imported)
 {
     this.type = Syntax.ImportSpecifier;
     this.local = local ?? imported;
     this.imported = imported;
     this.finish();
     return this;
 }
Exemplo n.º 4
0
 public Node finishThrowStatement(Node argument)
 {
     this.type = Syntax.ThrowStatement;
     this.argument = argument;
     this.finish();
     return this;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 7
0
 public Node finishSpreadElement(Node argument)
 {
     this.type = Syntax.SpreadElement;
     this.argument = argument;
     this.finish();
     return this;
 }
Exemplo n.º 8
0
        public Node parseProgram()
        {
            List<Node> body;
            Node node;

            peek();
            node = new Node();

            body = parseScriptBody();
            return node.finishProgram(body, state.sourceType);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 12
0
        public Node parseImportDefaultSpecifier()
        {
            // import <foo> ...;
            Node local;
            Node node = new Node();

            local = parseNonComputedProperty();

            return node.finishImportDefaultSpecifier(local);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 18
0
 public Node finishAssignmentPattern(Node left, Node right)
 {
     this.type = Syntax.AssignmentPattern;
     this.left = left;
     this.right = right;
     this.finish();
     return this;
 }
Exemplo n.º 19
0
 public Node finishRestElement(Node argument)
 {
     this.type = Syntax.RestElement;
     this.argument = argument;
     this.finish();
     return this;
 }
Exemplo n.º 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;
 }
Exemplo n.º 21
0
 public Node finishTemplateElement(Node value, object tail)
 {
     this.type = Syntax.TemplateElement;
     this.value = value;
     this.tail = tail;
     this.finish();
     return this;
 }
Exemplo n.º 22
0
 public Node finishCatchClause(Node param, List<Node> body)
 {
     this.type = Syntax.CatchClause;
     this.param = param;
     this.body = body;
     this.finish();
     return this;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 25
0
 public Node finishVariableDeclarator(Node id, object init)
 {
     this.type = Syntax.VariableDeclarator;
     this.id = id;
     this.init = init;
     this.finish();
     return this;
 }
Exemplo n.º 26
0
 public Node finishExpressionStatement(Node expression)
 {
     this.type = Syntax.ExpressionStatement;
     this.expression = expression;
     this.finish();
     return this;
 }
Exemplo n.º 27
0
 public Node finishImportNamespaceSpecifier(Node local)
 {
     this.type = Syntax.ImportNamespaceSpecifier;
     this.local = local;
     this.finish();
     return this;
 }
Exemplo n.º 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;
 }
Exemplo n.º 29
0
 public Node finishYieldExpression(Node argument, bool @delegate)
 {
     this.type = Syntax.YieldExpression;
     this.argument = argument;
     this.@delegate = @delegate;
     this.finish();
     return this;
 }
Exemplo n.º 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);
        }