Ejemplo n.º 1
0
            protected override AstNode?After(AstNode node, bool inList)
            {
                if (node is AstToplevel toplevel && _shadowedWindow)
                {
                    var newVar = new AstVar(toplevel);
                    var name   = new AstSymbolVar("global");
                    newVar.Definitions.Add(new AstVarDef(toplevel, name, new AstSymbolRef("window")));
                    toplevel.Body.Insert(0) = newVar;
                }

                return(node);
            }
Ejemplo n.º 2
0
            protected override AstNode?Before(AstNode node, bool inList)
            {
                if (node.IsSymbolDef().IsGlobalSymbol() is {} symbolName)
                {
                    if (symbolName == "global")
                    {
                        foreach (var parent in Parents())
                        {
                            if (parent is AstScope scope)
                            {
                                if (scope.Variables !.ContainsKey("window") || scope.Functions !.ContainsKey("window"))
                                {
                                    _shadowedWindow = true;
                                    return(null);
                                }
                            }
                        }

                        return(new AstSymbolRef(node, "window"));
                    }
                }

                if (node is AstSimpleStatement simpleStatement && simpleStatement.Body is AstAssign assigment &&
                    assigment.Operator == Operator.Assignment)
                {
                    if (assigment.Left is AstDot dot && dot.PropertyAsString == "exports" &&
                        dot.Expression.IsSymbolDef().IsGlobalSymbol() == "module")
                    {
                        var res    = new AstVar(node);
                        var newVar = new AstSymbolVar(assigment.Left, _varName);
                        ResultingSymbol = newVar;
                        res.Definitions.Add(new AstVarDef(assigment.Left, newVar, assigment.Right));
                        return(Transform(res));
                    }
                }

                return(null);
            }
Ejemplo n.º 3
0
        AstNode ParseVarId(VariableKind kind)
        {
            var id = ParseBindingAtom();

            CheckLVal(id, true, kind);
            if (id is AstSymbol)
            {
                if (kind == VariableKind.Let)
                {
                    id = new AstSymbolLet((AstSymbol)id);
                }
                else if (kind == VariableKind.Const)
                {
                    id = new AstSymbolConst((AstSymbol)id);
                }
                else
                {
                    id = new AstSymbolVar((AstSymbol)id);
                }
            }

            return(id);
        }