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

[ts 4.7] Support optional variance annotations #14359

Merged
merged 9 commits into from May 17, 2022
Merged

[ts 4.7] Support optional variance annotations #14359

merged 9 commits into from May 17, 2022

Conversation

magic-akari
Copy link
Contributor

@magic-akari magic-akari commented Mar 15, 2022

Q                       A
Fixed Issues? Fixes #14442
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? New Feature
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR Implement Optional variance annotations

@magic-akari magic-akari marked this pull request as ready for review March 16, 2022 12:25
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some test cases?

// with plugins `jsx` and `typescript`
<in T>() => {}

It should throw SingleTypeParameterWithoutTrailingComma error.

And also a type-variance-like JSX element:

<in T>() => {}</in>

It should be parsed successfully.

this.word("out");
this.space();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a generator test case to packages/babel-generator/test/fixtures/typescript?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm investigating ci failures in main branch, but I don't know much about ts and jsx.
<in T>() => {}</in> will fail when BABEL_8_BREAKING is enabled.
Can someone tell me if this is a problem with the parser or with the test?

@JLHwung JLHwung added PR: New Feature 🚀 A type of pull request used for our changelog categories area: typescript labels Mar 16, 2022
@magic-akari
Copy link
Contributor Author

Test Added. please do not merge until microsoft/TypeScript#48240 is merged.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.18.0 milestone Mar 22, 2022
@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Mar 22, 2022
@nicolo-ribaudo
Copy link
Member

cc @bradzacher if you have any comment regarding the AST shape

Comment on lines +1045 to +1046
in?: boolean,
out?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sold on using boolean flags as it locks us in with naming but I guess that this is the same thing we did with class property modifiers as well so it's not like we're breaking convention in the AST.

Given the precedence - this is probably the best approach, so LGTM

@magic-akari
Copy link
Contributor Author

@JLHwung
Variance annotations is not supported on generic function type parameters.
What should we do?

@JLHwung
Copy link
Contributor

JLHwung commented Apr 1, 2022

@magic-akari I think the AST shape is fine. We can add a allowedModifiers param to tsParseTypeParameter and handle it accordingly for every tsParseTypeParameter usage.

@JLHwung JLHwung self-requested a review April 1, 2022 18:40
@nicolo-ribaudo nicolo-ribaudo changed the title feat: support optional variance annotations [ts 4.7] Support optional variance annotations May 17, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 6415f09 into babel:main May 17, 2022
@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 Aug 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support TypeScript 4.7 in and out variance annotations
6 participants