Skip to content
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 in typescript spread #10769

Closed
jandolezal71 opened this issue Nov 26, 2019 · 7 comments · Fixed by #10800
Closed

Trailing comma in typescript spread #10769

jandolezal71 opened this issue Nov 26, 2019 · 7 comments · Fixed by #10800
Assignees
Labels
area: typescript good first issue i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@jandolezal71
Copy link

jandolezal71 commented Nov 26, 2019

Bug Report

Hi,

we have problem with trailing comma in typescript after upgrade to @babel/core to 7.7.4.

We installed new prettier (https://github.com/prettier/prettier/blob/master/CHANGELOG.md#1182), which was injected trailing comma after rest in type, but babel-parser don't like it.

tsc command will not produce any errors, so trailing commas are fine in TS.

Cannot be this relevant to "final fix" #10491 ?

Error:

SyntaxError: /my-project/src/file.ts: Unexpected trailing comma after rest element (12:12)

  10 | 	string,
  11 | 	string,
> 12 | 	...string[],
     | 	           ^
  13 | ];
  14 | 
  15 | export default function createChainableTypeChecker<T>(
    at Object.raise (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:6975:17)
    at Object.raiseTrailingCommaAfterRest (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8881:10)
    at Object.checkCommaAfterRest (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:8869:14)
    at Object.tsParseTupleElementType (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4876:12)
    at Object.tsParseDelimitedListWorker (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4519:23)
    at Object.tsParseDelimitedList (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4508:25)
    at Object.tsParseBracketedList (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4554:25)
    at Object.tsParseTupleType (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4859:30)
    at Object.tsParseNonArrayType (/my-project/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:5001:21)

Ts file:

type ValidateArgs = [
	{
		[key: string]: any;
	},
	string,
	string,
	...string[],
];

package.json

    "@babel/core": "^7.7.4",
    "@babel/plugin-proposal-object-rest-spread": "^7.7.4",
    "@babel/preset-env": "^7.7.4",
    "@babel/preset-typescript": "^7.7.4",
  • Babel version(s): 7.7.4
  • Node/npm version: 12.10
  • OS: Ubuntu 19
  • Prettier: 1.19.1
@babel-bot
Copy link
Collaborator

Hey @jandolezal71! 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."

@JLHwung
Copy link
Contributor

JLHwung commented Nov 26, 2019

This issue can reproduced in babel 7.0.0. So it's not a regression.

@nicolo-ribaudo
Copy link
Member

I believe that this is a bug in TypeScript itself, and I have opened an issue asking which is the correct behavior.

microsoft/TypeScript#35375

@jandolezal71
Copy link
Author

Thank you Nicolò for processing this request.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Dec 3, 2019

If anyone wants to submit a PR, probably deleting the check for the rest comma from the tsParseTupleElementType parser function would be enough, but we'll also need tests.

tsParseTupleElementType(): N.TsType {

If it is the first time that you contribute to Babel, follow these steps: (you need to have make and yarn available on your machine)

  1. Write a comment here to let other possible contributors know that you are working on this bug.
  2. Fork the repo
  3. Run git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
  4. Run yarn && make bootstrap
  5. Wait ⏳
  6. Run make watch (or make build whenever you change a file)
  7. Add a test (only input.js; output.json will be automatically generated)
  8. Update the code!
  9. yarn jest babel-parser to run the tests
    • If some test outputs don't match but the new results are correct, you can delete the bad output.json files and run the tests again
    • If you prefer, you can run OVERWRITE=true yarn jest babel-parser and they will be automatically updated.
  10. If it is working, run make test to run all the tests
  11. Run git push and open a PR!

@yeonjuan
Copy link
Contributor

yeonjuan commented Dec 3, 2019

@nicolo-ribaudo I will pick this up :)

@nicolo-ribaudo
Copy link
Member

Sure!

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 17, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript good first issue i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants