robfig / soy

Go implementation for Soy templates (Google Closure templates)
MIT License
172 stars 41 forks source link

fixed binary operation grouping with nullsafe-checks for soy2js #68

Closed creotutar closed 5 years ago

creotutar commented 5 years ago

Added grouping of the operands for binary options to stop grouping with nullsafe-checks. E.g. Given

{let $foo: 'test' /}
{let $bar: [:] /}
{let $baz: $foo or $bar?['nonexistantkey'] /}

soy2js translates the soy for baz into the following

var baz = (opt_data.foo || (opt_data.bar == null) ? null : opt_data.bar['nonexistantkey']);

which would evaluate to null when you would expect it to be test. Fixed so that it translates to

var baz = ((opt_data.foo) || ((opt_data.bar == null) ? null : opt_data.bar['nonexistantkey']));
robfig commented 5 years ago

Thanks very much for diagnosing and fixing with tests!