Skip to content

Add typings to create-class-features-plugin helper#13570

Merged
nicolo-ribaudo merged 16 commits intobabel:mainfrom
colinaaa:class-features-typings
Aug 2, 2021
Merged

Add typings to create-class-features-plugin helper#13570
nicolo-ribaudo merged 16 commits intobabel:mainfrom
colinaaa:class-features-typings

Conversation

@colinaaa
Copy link
Copy Markdown
Contributor

@colinaaa colinaaa commented Jul 17, 2021

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

I was trying to read codes in babel-helper-create-class-features-plugin, then I found that most of its code are written without typings. So I tried to add the correct typings to it, hopefully it can help others to read the code easier.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Jul 17, 2021

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

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jul 17, 2021

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 0bc80ca:

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 Jul 17, 2021
@colinaaa colinaaa marked this pull request as ready for review July 19, 2021 05:06
@colinaaa
Copy link
Copy Markdown
Contributor Author

Hi @nicolo-ribaudo, I did not find anything about path.isPrivateMethod. Is this a typo to path.isClassPrivateMethod or it's something special?

// NOTE: path.isPrivateMethod() it isn't supported in <7.2.0
if (path.isPrivateMethod?.()) {

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Yes it was a typo 😬

Copy link
Copy Markdown
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.

Thanks for all these type improvements!

Comment on lines +69 to +70
let resolvedLoose: boolean;
let higherPriorityPluginName: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These can also be undefined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would be nice to enable strict mode, while adding improving type coverage… - or at least strictNullChecks which will catch things like this

however, not sure if it can be easily done for single package… probably this would require to revert project references configuration and fix circular dependencies…

@@ -146,7 +150,7 @@ export function verifyUsedFeatures(path, file) {
}

// NOTE: path.isPrivateMethod() it isn't supported in <7.2.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: also update the comment here.

const privateInVisitor = privateNameVisitorFactory({
const privateInVisitor = privateNameVisitorFactory<{
classRef: t.Identifier;
file: unknown;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also here

for (const computedPath of computedPaths) {
const computedKey = computedPath.get("key");
if (computedKey.isReferencedIdentifier()) {
// @ts-expect-error TODO: make isReferencedIdentifier return path is Identifier
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you'll want to open a PR to do this, it will be a welcome improvement!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will do that!

@colinaaa
Copy link
Copy Markdown
Contributor Author

rebased to main to make CI pass

boundGet() {
// noop
// we dont need boundGet here, but memberExpressionToFunctions handler needs it.
throw new Error("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Throwing exception is definitely not noop. I am good with either make it an noop or throw an explicit error here.

import type { Visitor } from "./types";

export type { Visitor };
export type { Visitor, Binding };
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung Jul 20, 2021

Choose a reason for hiding this comment

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

Q for team: Is adding new type exports considered new features?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, we strip away types before publishing so no (at least, for now).


export interface HandlerState<State = {}> extends Handler<State> {
handle(
this: HandlerState<State> & State,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Q: Are these circular references good for TS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems that TS works pretty fine with these circular refs. Are there any better solutions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure there is any🤔

@nicolo-ribaudo
Copy link
Copy Markdown
Member

nicolo-ribaudo commented Jul 28, 2021

I merged the path.get PR on main: if you rebase this one we can rely on it (if needed).

Copy link
Copy Markdown
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.

Thanks!

@nicolo-ribaudo nicolo-ribaudo changed the title Add typings to create class features plugin helper Add typings to create-class-features-plugin helper Aug 2, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit 1960f23 into babel:main Aug 2, 2021
@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 Nov 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 2, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants