Skip to content

Improve expression statement handling and language extensions calls#1201

Merged
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
GlassBricks:expression-statement-improvements
Jan 4, 2022
Merged

Improve expression statement handling and language extensions calls#1201
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
GlassBricks:expression-statement-improvements

Conversation

@GlassBricks
Copy link
Copy Markdown
Contributor

These changes go together:

With preceding statements, table function language extensions (TableGet, TableSet, etc.) can now be used as expressions.
TableDelete functions are typed to return boolean, but previously the return value could never be used; these now return true to be similar to delete expressions. Other methods return nil.
Additionally, I fixed table function extensions that use preceding statements or spread arguments. This required some refactoring; The result is based on transformBuiltinCallExpression. This additionally avoids unnecessary calls to getTableExtensionKindForCall and fixes some other minor bugs that I found.

transformExpressionStatement now omits the statement entirely if the inner expression result is "synthetic" with no side effects (a temp variable, or a literal without a source map position). This removes unnecessary local ____ = ... in several cases (e.g. a?.b()). This also decouples transformExpressionStatement from other language features: now table call language extensions can be transformed as an expression, and its return value (nil or true) is omitted when in an expression statement (not used).

  • void expressions now also share some of this logic to omit unecessary local ____ = ....

@GlassBricks GlassBricks requested a review from lolleko January 2, 2022 16:44
@GlassBricks GlassBricks requested a review from lolleko January 3, 2022 17:27
@Perryvw Perryvw merged commit 3dc393e into TypeScriptToLua:master Jan 4, 2022
@GlassBricks GlassBricks deleted the expression-statement-improvements branch March 16, 2022 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants