-
-
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
Trailing comma incorrectly kept when stripping types for ...rest param #1573
Comments
It seems like this is the cause: swc/ecmascript/codegen/src/lib.rs Lines 1629 to 1645 in df2a926
It tries to emit a trailing comma if the input has a trailing comma, but this picks up the trailing comma of the type annotation. Should this functionality just be removed? |
@danopia You are correct, thanks! I'll update the pr. |
swc_bundler: - Ensure that denoland/deno#10141 is fixed. - Run deno tests on ci. - Support nested `export *`. (denoland/deno#10153, denoland/deno#10174) swc_ecma_codegen: - Remove `,` after rest elements. (#1573, denoland/deno#10167) swc_ecma_transforms_optimization: - Don't drop items used by the discriminant of a switch. swc_ecma_transforms_typescript: - Remove constructors without a body.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
When accepting an options argument in a function, often times I want certain options to be kept separate. I achieve this by setting up an object splat, or whatever they're called, and putting a rest param afterwards to catch the rest.
The issue that I see is that swc is lifting out the trailing comma, if any, from within the TypeScript type clause for the overall parameter, and dropping it into the splat which creates a syntax error.
Input code
Output code
Note that removing the type's inner trailing comma removes it from the output as well, producing valid code:
Input code
Output code
Config
I'm nominally using Deno, so to recreate this bug I wrote a very basic
.swcrc
:Expected behavior
The inner comma probably shouldn't get lifted out of the type signatures in general. I don't see when that would be useful
Version
Additional context
It seems that using semicolons instead of commas inside the type is a valid workaround.
The text was updated successfully, but these errors were encountered: