示例#1
0
        public override object ConstValue(IConstEvalCtx ctx = null)
        {
            var expr = Expression.ConstValue(ctx);
            var prop = Property;

            if (prop is AstNode node)
            {
                prop = node.ConstValue(ctx?.StripPathResolver());
            }
            if (prop == null)
            {
                return(null);
            }
            prop = TypeConverter.ToString(prop);
            if (expr is IReadOnlyDictionary <object, object> dict)
            {
                if (dict.TryGetValue(prop, out var res))
                {
                    return(res);
                }
                return(AstUndefined.Instance);
            }

            if (expr is JsModule module && ctx != null)
            {
                return(ctx.ConstValue(ctx, module, prop));
            }

            return(null);
        }
示例#2
0
            public object ConstValue(IConstEvalCtx ctx, JsModule module, object export)
            {
                if (module.Name == "bobril" && export is string expName)
                {
                    if (expName == "asset" || expName == "styleDef" || expName == "styleDefEx" || expName == "sprite")
                    {
                        return(new JsModuleExport(module.Name, expName));
                    }
                }

                if (module.Name == "bobril-g11n" && export is string expName2)
                {
                    if (expName2 == "t" || expName2 == "f" || expName2 == "dt")
                    {
                        return(new JsModuleExport(module.Name, expName2));
                    }
                }
                return(_ctx.ConstValue(ctx, module, export));
            }
示例#3
0
    protected override void Visit(AstNode node)
    {
        if (IsExportsAssignVoid0(node))
        {
            StopDescending();
            return;
        }
        if (node is AstDot dot)
        {
            StopDescending();
            if (IsExports(dot.Expression) && (string)dot.Property == _export)
            {
                var parent = Parent();
                if (parent is AstAssign assign && assign.Operator == Operator.Assignment && assign.Left == node)
                {
                    Result         = assign.Right;
                    CompleteResult = false;
                }
            }
        }

        if (node is AstCall call && call.Expression is AstSymbol symbol && (symbol.Name == "__exportStar" && call.Args.Count == 2 || symbol.Name == "__export" && call.Args.Count == 1) && call.Args[0] is AstCall)
        {
            var module = call.Args[0].ConstValue(_ctx);
            if (module is JsModule)
            {
                var res = _ctx.ConstValue(_ctx, (JsModule)module, _export);
                if (res != null)
                {
                    Result         = TypeConverter.ToAst(res);
                    CompleteResult = false;
                }
            }
        }

        if (node is AstAssign assign2 && assign2.Operator == Operator.Assignment && IsExports(assign2.Left))
        {
            StopDescending();
            Result         = assign2.Right;
            CompleteResult = true;
        }
    }