bolt icon indicating copy to clipboard operation
bolt copied to clipboard

Simplify expressions

Open mckoss opened this issue 10 years ago • 3 comments

Do simplification based on the ast tree rather than the textual representation. I'd like to provide a simplify() function that will convert:

validate: true => remove write: false => remove read: false => remove

as well as simple expression simplifications:

true || exp => true false || exp => exp true && exp => exp false && exp => false !(a == b) => a != b !(a != b) => a == b !(a < b) => a >= b (etc) !!a => a == true

The latter can arise from trivial conditional rules, or when trivial base rules are combined with more complex validation expression in derived Types.

mckoss avatar Sep 02 '15 15:09 mckoss

worth a look https://github.com/firebase/blaze_compiler/blob/master/src/optimizer.ts

tomlarkworthy avatar Sep 02 '15 16:09 tomlarkworthy

Just as small optimisation, string rules expressions "true" and "false" could be converted to boolean.

e.g. {".write": "true"} => {".write": true}

matjaz avatar Sep 02 '15 17:09 matjaz

Also - parent() and child() references are sometime generated non-optimally. That was something Blaze also optimized.

mckoss avatar Oct 29 '15 21:10 mckoss