protected void PrintGetterSetter(OutputContext output, string type, bool @static)
        {
            if (@static)
            {
                output.Print("static");
                output.Space();
            }

            if (type != null)
            {
                output.Print(type);
                output.Space();
            }

            if (Key is AstSymbolMethod symbolMethod)
            {
                output.PrintPropertyName(symbolMethod.Name);
            }
            else
            {
                output.Print("[");
                ((AstNode)Key).Print(output);
                output.Print("]");
            }

            ((AstLambda)Value).DoPrint(output, true);
        }
Beispiel #2
0
    public override void CodeGen(OutputContext output)
    {
        string GetName(AstSymbol symbol)
        {
            return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name);
        }

        var allowShortHand = output.Options.Ecma >= 6;
        var keyString      = Key switch
        {
            AstString str => str.Value,
            AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
            AstSymbolRef _ => null,
            AstSymbol key => GetName(key),
            _ => null
        };

        if (allowShortHand &&
            Value is AstSymbol value && keyString != null &&
            GetName(value) == keyString &&
            OutputContext.IsIdentifierString(keyString) &&
            OutputContext.IsIdentifier(keyString)
            )
        {
            output.PrintPropertyName(keyString);
        }
Beispiel #3
0
        public override void CodeGen(OutputContext output)
        {
            string GetName(AstSymbol symbol)
            {
                return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name);
            }

            var    allowShortHand = output.Options.Shorthand;
            string?keyString      = null;

            if (Key is AstSymbol)
            {
                keyString = GetName((AstSymbol)Key);
            }
            else if (Key is AstString str)
            {
                keyString = str.Value;
            }

            if (allowShortHand &&
                Value is AstSymbol && keyString != null &&
                GetName((AstSymbol)Value) == keyString &&
                OutputContext.IsIdentifierString(keyString) &&
                OutputContext.IsIdentifier(keyString)
                )
            {
                output.PrintPropertyName(keyString);
            }
            else if (allowShortHand &&
                     Value is AstDefaultAssign defAssign && keyString != null &&
                     defAssign.Left is AstSymbol &&
                     OutputContext.IsIdentifierString(keyString) &&
                     GetName((AstSymbol)defAssign.Left) == keyString
                     )
            {
                output.PrintPropertyName(keyString);
                output.Space();
                output.Print("=");
                output.Space();
                defAssign.Right.Print(output);
            }
Beispiel #4
0
        public override void CodeGen(OutputContext output)
        {
            string GetName(AstSymbol symbol)
            {
                return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name);
            }

            var allowShortHand = output.Options.Shorthand;
            var keyString      = Key switch
            {
                AstString str => str.Value,
                AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
                AstSymbol key => GetName(key),
                _ => null
            };

            if (allowShortHand &&
                Value is AstSymbol && keyString != null &&
                GetName((AstSymbol)Value) == keyString &&
                OutputContext.IsIdentifierString(keyString) &&
                OutputContext.IsIdentifier(keyString)
                )
            {
                output.PrintPropertyName(keyString);
            }
            else if (allowShortHand &&
                     Value is AstDefaultAssign defAssign && keyString != null &&
                     defAssign.Left is AstSymbol &&
                     OutputContext.IsIdentifierString(keyString) &&
                     GetName((AstSymbol)defAssign.Left) == keyString
                     )
            {
                output.PrintPropertyName(keyString);
                output.Space();
                output.Print("=");
                output.Space();
                defAssign.Right.Print(output);
            }
Beispiel #5
0
    protected void PrintGetterSetter(OutputContext output, string?type, bool @static)
    {
        if (@static)
        {
            output.Print("static");
            output.Space();
        }

        if (type != null)
        {
            output.Print(type);
            output.Space();
        }

        var keyString = Key switch
        {
            AstString str => str.Value,
            AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
            AstSymbolRef => null,
            AstSymbol key => key.Name,
            _ => null
        };

        if (keyString != null)
        {
            output.PrintPropertyName(keyString);
        }
        else
        {
            output.Print("[");
            Key.Print(output);
            output.Print("]");
        }

        ((AstLambda)Value).DoPrint(output, true);
    }
}