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
[Bug]: Edge case in TSX: <T,>(t: T) => t
#13778
Comments
Hey @hyrious! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
Possible solution: keep trailing comma in type list: // in babel-parser/src/plugins/typescript/index.js tsParseDelimitedListWorker:
let comma = false;
// ...for (;;) {...
if (this.tsIsListTerminator(kind)) {
result.hasTrailingComma = comma;
break;
}
if (this.eat(tt.comma)) {
comma = true;
continue;
}
// in babel-generator/src/generators/typescript.ts TSTypeParameterInstantiation:
if (node.params.hasTrailingComma) this.token(",");
this.token(">"); |
We can just always unconditionally print a trailing comma. |
@hyrious Since you already looked at the If it is the first time that you contribute to Babel, follow these steps: (you need to have
|
@nicolo-ribaudo Thank you for inviting me. However I'll not be able to use *nix system in the next few days. The "solution" I posted above was just a quick & dirty hack into node_modules, it just passed this single edge case and didn't follow common practices (it stores a value in an array). It's difficult for me to refactor it into a more robust one in such large code base. Always printing trailing comma in type list seems promising but may break many other things. I don't know it very much. So I'll leave this chance to other experienced programmers. |
Hi! Can I pick this bug? |
It's yours! |
If this issue is not maintained since September, can I take it? Thanks. |
Yes 👍 |
Hi @nicolo-ribaudo, I have a question I am planning to put my test input into babel-generator/test/fixtures/typescript/arrow-function-generic-tsx Also any hint that you want to support me is nice for me. Thanks |
Do you have a branch or draft PR I could look at to see why it's not working? |
In that screenshot I actually didn't changed or added any files, I just run the jest generator directly, so i can't give you valuable branch name. See, nothing is changed. |
@nicolo-ribaudo I think there is a problem. When I run Then I removed every entry that has a test with t.stringLiteral inside babel-generator/test/index.js After I run I am thinking that babel-generator/test/index.js has an error and because of that this is happening. |
Did you run |
This is my head hash ddd93b9 which is the current. And yes I exactly did the steps you specified in here
I am actually able to generate output.js files but the only way to generate them is to remove everything Are you able to run |
Yes, |
Okay, never mind then, probably it is related to my env. |
Hey @nicolo-ribaudo Thanks |
Anyway, I just separated my test codes, after a while reviewing test folders, it seems using separated folder for this case is fine. |
💻
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
The current output:
This is valid in TS, but invalid in TSX, because
<T>
is treated as a tag in TSX context.Expected output:
Environment
Possible solution
No response
Additional context
Original Issue: vitejs/vite#4949.
The text was updated successfully, but these errors were encountered: