-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@swc/wasm-typescript
incorrect output for return
followed by a type with a newline
#9878
Comments
Given this kind of thing is already handled for async functions by bringing forward the opening parenthesis, I'd suggest doing the same here. That will also avoid the debugger stepping into the const f = async <
T
>()=>0; const f = async (
)=>0; ^^^ Existing solution |
I can confirm this issue also applies to |
@magic-akari Can you take a look? |
throw <
T
>(v: T) => v;
You may wish to reuse the test cases that were added for this issue in |
Describe the bug
Type stripping has an edge case where it can have the wrong output when there is a
return
followed by a type with a newline, because of the no-lineterminator-here restriction afterreturn
.Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.7.1&code=H4sIAAAAAAAAA0srzUsuyczPU0jT0FSo5uIsSi0pLcpTsAmx4%2BLk1KiwUgjRtLWrsOaq5QIAdBqy7yoAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D&strip-types=
SWC Info output
No response
Expected behavior
The output should have the same semantics as the input. The easiest way to get this would be to add in
0,
after thereturn
as inor to move the initial parenthesis as in
Actual behavior
Because of the newline, the
return
is treated as having no operator.Version
1.7.1
Additional context
Issue comes from node: nodejs/node#56597 (comment)
Note that the same bug occurs with
throw
instead ofreturn
. It probably would also occur foryield
but that doesn't parse at all.The text was updated successfully, but these errors were encountered: