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
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.
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
The static method
Expression.fromTokens
is used as the path for all "value" parsing. ThefromTokens
method will return aValueTypes
rather than aExpression
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 argumentsI think
Expression.fromTokens
can stay as the entry for "value" parsing but there could be insteadparseValue
in the same way there isparseStatement
...? 🤔As this is a very hot path this is important performance issue