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

convert @babel/traverse to TypeScript #12488

Merged
merged 17 commits into from
Jan 24, 2021

Conversation

zxbodya
Copy link
Contributor

@zxbodya zxbodya commented Dec 11, 2020

Q                       A
License MIT

@babel/traverse of #11578

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 11, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/38265/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 11, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9df3894:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo nicolo-ribaudo added the Flow -> TS Tracking repository migration from Flow to TS label Dec 11, 2020
@zxbodya zxbodya force-pushed the ts-migration/babel-traverse branch 2 times, most recently from fbf7978 to 1bb12e1 Compare December 15, 2020 23:10
@@ -23,7 +23,7 @@ const typeAnnotationInferringNodes = new WeakSet();
* todo: split up this method
*/

export function _getTypeAnnotation(): ?Object {
export function _getTypeAnnotation(): any | undefined | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

undefined | null can be removed since any already contains all types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, it can be removed - will update the PR

(adding special case for nullable any in flow to typescript tool, so it would be updated in other places as well)

@ovr
Copy link

ovr commented Jan 18, 2021

Any news on it? Thanks

@zxbodya
Copy link
Contributor Author

zxbodya commented Jan 18, 2021

Any news on it? Thanks

rebased resolving the conflict with changes in main
generally should be ready to merge - waiting for the review

!path.scope.getBinding(name, true) &&
property.isIdentifier &&
!path.scope.getBinding(name) &&
property.isIdentifier() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!


if (
object.isIdentifier() &&
name === "String" &&
!path.scope.getBinding(name, true) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt it should have been hasBinding(name, true), as the binding is never used later. Can you leave a todo note here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, added a comment
sounds like - this might be the case

import * as inferers from "./inferers";
import * as t from "@babel/types";

/**
* Infer the type of the current `NodePath`.
*/

export function getTypeAnnotation(): Object {
export function getTypeAnnotation(): t.FlowType {
Copy link
Contributor

Choose a reason for hiding this comment

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

It could also return TSType, we can leave is as-is and refine later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added t.FlowType type annotation, because in current implementation it uses t.anyTypeAnnotation() inside, so currently it probably is correct only for flow

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.

LGTM with some nits. This is awesome!

Makefile Outdated
@@ -36,6 +36,7 @@ generate-tsconfig:

generate-type-helpers:
$(YARN) gulp generate-type-helpers
node packages/babel-traverse/scripts/generateTypeHelpers.js
Copy link
Member

Choose a reason for hiding this comment

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

I'll push a commit to move this to gulp like the other generators.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I went ahead and pushed some commits rather than just leaving comments to speed up merging this PR.

I'm sorry you already had to rebase it: this PR is big and while I'm not satisfied with how @babel/traverse is typed, it's already better than what we had with Flow.

We'll need to come back and improve @babel/traverse types before publishing, but it's good enough for now.

@nicolo-ribaudo
Copy link
Member

GH correctly detects all the files in this PR as renamed, so there is no need to merge it as two commits.

@nicolo-ribaudo nicolo-ribaudo merged commit d98418e into babel:main Jan 24, 2021
Nicolò's ideal PR review order list automation moved this from To review to Done Jan 24, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the ts-migration/babel-traverse branch January 24, 2021 00:33
@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 Apr 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Flow -> TS Tracking repository migration from Flow to TS outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Development

Successfully merging this pull request may close these issues.

None yet

6 participants