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); }
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); }
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); }