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); }
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), AstSymbol key => key.Name, _ => null }; if (keyString != null) { output.PrintPropertyName(keyString); } else { output.Print("["); Key.Print(output); output.Print("]"); } ((AstLambda)Value).DoPrint(output, true); } }