Skip to content

Implement support for void expression - #1148

Merged
Perryvw merged 2 commits into
masterfrom
void-expression
Oct 26, 2021
Merged

Implement support for void expression#1148
Perryvw merged 2 commits into
masterfrom
void-expression

Conversation

@Perryvw

@Perryvw Perryvw commented Oct 23, 2021

Copy link
Copy Markdown
Member

Adds support for the void expression: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void

This doubly fixes #1102: It no longer crashes on the unsupportedNodeKind because we now correctly use ts.getOriginalNode, but also this expression is not unsupported anymore :)

@Perryvw
Perryvw requested review from lolleko and tomblind October 23, 2021 19:58

@tomblind tomblind left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth stripping the IIFE if the void expression is an expression statement, especially since a common use of the keyword is to formally declare that a call to an async function should not be awaited.

@GlassBricks

GlassBricks commented Oct 24, 2021

Copy link
Copy Markdown
Contributor

It might also be worth replacing the IIFE with just nil if the expression is just a number or string literal, as maybe people want to use void 0 as a shorthand for undefined. This would also (potentially) allow us to use typescript's existing transformES2020 to do optional chaining with preceding statements in the future, as it uses void 0.

It may be noted that the IIFE can be omitted if we use preceding statements. Another weird option is <expression> and nil or nil which is always nil.

@Perryvw
Perryvw merged commit 8f70f50 into master Oct 26, 2021
@Perryvw
Perryvw deleted the void-expression branch October 26, 2021 17:41
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.

Crash when using void on an async IIFE with a floating promise

3 participants