Simplify optional chaining expressions where possible#1381
Simplify optional chaining expressions where possible#1381Perryvw merged 7 commits intoTypeScriptToLua:masterfrom
Conversation
| isDelete?: ts.DeleteExpression | ||
| ): ExpressionWithThisValue { | ||
| const luaTemp = context.createTempNameForNode(node); | ||
| const luaTempName = context.createTempName("opt"); |
There was a problem hiding this comment.
Why change this from what it was?
There was a problem hiding this comment.
"node" was too generic and so confusing; there are a lot of variables, TS and Lua, in the body.
There was a problem hiding this comment.
It wasn't actually "node" literal though, it was already deducing a very specific name based on what the node is, see the changes in the snapshots where it changed ____table_has_result_0 to ___opt_0
There was a problem hiding this comment.
Sorry, earlier I thought the comment was addressing something else.
The reason for this is that long-ish optional chains, which are somewhat common, generate long names such as "____a_b_c_foo_result_c_1". "____opt" is shorter and still signifies what the original TS was.
This shouldn't depend on strictNullChecks
This tests that the output statements are correct.
This PR simplifies/reduces the lua output of optional chains, in the most common cases.
andstatement (a and a.b) instead of an if statement where possible.