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]: Typescript plugin fails on named tuple positions where the name is a reserved word in JS #13702
Comments
Hey @happycollision! 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." |
Thanks for the bug report! The problem is in the babel/packages/babel-parser/src/plugins/typescript/index.js Lines 882 to 892 in 1355d00
Keywords are not valid types (i.e.
If anyone wants to help fixing this bug and it is the first time that you contribute to Babel, follow these steps: (you need to have
|
Hi! Can I pick this bug? |
Sure, it's yours! If you need any help feel free to ask. |
Hey @nicolo-ribaudo pardon my ignorance, I'm new to this codebase and I was wondering if there is any documentation for the internal methods such as |
Nope, there are no docs available for internal parser methods, however you can ask on Slack and you will surely find someone that can help you.
|
@fedeci Thank you so much for the explanation. Will definitely use the slack channel for these sorts of queries in the future!! |
@aimanjaffer If you are asking because of this bug, please first leave some time (one more week) for @ChaitanyaGadodia since this bug is assigned to him 🙏 |
@nicolo-ribaudo Sure thing!! |
@nicolo-ribaudo |
I think the syntax is no correct, you should write this instead: `type FuncWithDescription = {
function: (...args: any[]) => any,
string: string
}
const fnWithDescriptions: FuncWithDescription[] = [
{
function: (a,b,c) => a+b+c,
string: 'Some string'
}
] |
@macluiggy @ozanhonamlioglu |
@nicolo-ribaudo I see there is a PR in draft state, is this issue still available? |
Hello! |
💻
How are you using Babel?
babel-loader (webpack)
Input code
https://babeljs.io/repl#?browsers=defaults&build=&builtIns=false&corejs=3.6&spec=false&loose=false&code_lz=C4TwDgpgBAYgrgOwMYHUCWwAWARCBnJAJzTGDQHsEoBeKAbQCgooAzRJMygLigAoA6QQENCAczw8hCEHQC6AShoA-KFJAAaJlDzBiCUTx17RDWQwZJKO1gnRZcBYqQoIJsdnZz4iJTgjk09FrMdLwAHlwIcAC2AEYQhIrUKmHqUABEhBDAcIRUWNBRcQnpsprMIeGRMfGEaSDVxYnKUGEAVBoZ0XAANmRgPSBQBVBFtXilpkA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.15.3&externalPlugins=&assumptions=%7B%7D
Configuration file name
No response
Configuration
See REPL link
Current and expected behavior
Current
It throws at line 2:
/repl.tsx: Unexpected token (2:2)
If you rename
function
tofn
, thenit throws at line 3:
Tuple members must be labeled with a simple identifier. (3:2)
Expected
It does not throw an error on either line. Why would I expect this? Because TS is totally fine with this same code: https://www.typescriptlang.org/play?ts=4.0.2#code/C4TwDgpgBAYgrgOwMYHUCWwAWARCBnJAJzTGDQHsEoBeKAbQFgAoKVqAM0STMoC4oAFADoRAQ0IBzPP1EIQdALoBKagD4oskABpmbKHmDEEE-gaMTmC5sySUDHBOiy4CxUhQTTYXJznxESHgRFGnpdNjoBAA9eBDgAWwAjCEIlGnUorSgAIkIIYDhCKixoOKSU7IUdFgjo2ITkwiyQevLU9KgogCptHPi4ABsyMAGQKBKoMsa8SssgA
Environment
See REPL link for env details
Possible solution
There are two ways to fix this problem, in my opinion
Option 1: Updated docs, and better error messages
Indicate in the docs (just like with other caveats) that there are certain tokens that are not acceptable for named tuple positions.
Then, ensure that the errors thrown in my example above clearly state this problem and/or reference the newly updated docs. I think the second error (
Tuple members must be labeled with a simple identifier.
) is possibly acknowledging this discrepancy, but it is not clear to me that the error is a known caveat vs an actual TS syntax issue. (The first error thrown against the wordfunction
, though, is quite vague.)Option 2: Update the TypeScript plugin to handle these names
I do not know how many words fail in the Babel plugin, and yet succeed in TS. I do know that the following are in the list:
function
string
number
Additional context
No response
The text was updated successfully, but these errors were encountered: