kaleidawave / prism

(No longer in development). Experimental compiler for building isomorphic web applications with web components.
MIT License
110 stars 1 forks source link

Unnecessary expression construction #27

Closed kaleidawave closed 3 years ago

kaleidawave commented 3 years ago

The static method Expression.fromTokens is used as the path for all "value" parsing. The fromTokens method will return a ValueTypes rather than a Expression

https://github.com/kaleidawave/prism/blob/8ddcc756aac618b41aaa39aa95ba1318ebd07464/src/chef/javascript/components/value/expression.ts#L286

Currently if there is a field in something like array literal, right hand side of assignment or if condition Expression.fromTokens is called.

This is okay but the fromTokens originally was for just expressions and there is a relic left in from that in which a Expression is eagerly created/constructed but then may be never used and dropped.

https://github.com/kaleidawave/prism/blob/8ddcc756aac618b41aaa39aa95ba1318ebd07464/src/chef/javascript/components/value/expression.ts#L287-L288

https://github.com/kaleidawave/prism/blob/8ddcc756aac618b41aaa39aa95ba1318ebd07464/src/chef/javascript/components/value/expression.ts#L557

Expression should be constructed later if it encounters a operation and never if it is just a variable or literal

Fixing this would also get rid of the temp //ts-ignore with the invalid expression constructor arguments

I think Expression.fromTokens can stay as the entry for "value" parsing but there could be instead parseValue in the same way there is parseStatement...? 🤔

As this is a very hot path this is important performance issue