Not a THRE.js user myself, but I’ll pitch in my 2 cents anyway:
The 2 main objections here are relatively easy to resolve within TSL.
- For streight-up math expressions, just have some API function that takes in a templated string of a single-line math expressions, and it should be able to be substituted directly to code that both WGSL and GLSL should be able to ingest as-is, because they both support the same basic operators and parenthesis rules. Whenever any expression-node is passed into the templated string, it would automatically be converted into a variable which would be reused as-needed in the expression conversion and in any other place, which leads me to…
- In any case where the same expression object is being passed into multiple places, instead of letting it get evaluated multiple times, just convert it to a variable at the outset, and memoise that to the object-id of that expression. Pretty sure js supports checking object identity, not just equality, so that should be trivial to memoise into some semi-global map. As long as expression objects are immutable, this should work.