Ejemplo n.º 1
0
        internal static CodeNode Parse(ParseInfo state, ref int index)
        {
            if (!Parser.Validate(state.Code, "export", ref index))
            {
                return(null);
            }

            Tools.SkipSpaces(state.Code, ref index);

            var result   = new ExportStatement();
            var reexport = 0;

            if (Parser.Validate(state.Code, "*", ref index))
            {
                reexport = 1;
            }
            else if (Parser.Validate(state.Code, "default", ref index))
            {
                reexport = -1;
                Tools.SkipSpaces(state.Code, ref index);
                result._map.Add(new KeyValuePair <string, Expression>("", (Expression)ExpressionTree.Parse(state, ref index)));
            }
            else if (state.Code[index] == '{')
            {
                parseExportMap(result, state, ref index);
            }
            else
            {
                reexport = -1;
                var definition =
                    VariableDefinition.Parse(state, ref index)
                    ?? ClassDefinition.Parse(state, ref index)
                    ?? FunctionDefinition.Parse(state, ref index, BaseLibrary.FunctionKind.Function);

                if (definition == null)
                {
                    ExceptionHelper.ThrowSyntaxError(Strings.UnexpectedToken, state.Code, index);
                }

                result._internalDefinition = definition;
            }

            Tools.SkipSpaces(state.Code, ref index);

            if (Parser.Validate(state.Code, "from", ref index))
            {
                if (reexport == -1)
                {
                    ExceptionHelper.ThrowSyntaxError("Reexport is not allowed with this syntax", state.Code, index - 4);
                }

                Tools.SkipSpaces(state.Code, ref index);

                var start = index;
                if (!Parser.ValidateString(state.Code, ref index, false))
                {
                    ExceptionHelper.ThrowSyntaxError("Expected module name", state.Code, index);
                }

                result._reexportSourceModuleName = Tools.Unescape(state.Code.Substring(start + 1, index - start - 2), false);
            }
            else if (reexport == 1)
            {
                ExceptionHelper.ThrowSyntaxError("Expected 'from'", state.Code, index);
            }

            return(result);
        }