Add typings to create-class-features-plugin helper#13570
Add typings to create-class-features-plugin helper#13570nicolo-ribaudo merged 16 commits intobabel:mainfrom colinaaa:class-features-typings
create-class-features-plugin helper#13570Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/47661/ |
|
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:
|
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
|
Hi @nicolo-ribaudo, I did not find anything about babel/packages/babel-helper-create-class-features-plugin/src/features.ts Lines 148 to 149 in aa18da0 |
|
Yes it was a typo 😬 |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Thanks for all these type improvements!
packages/babel-helper-create-class-features-plugin/src/decorators.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-create-class-features-plugin/src/decorators.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-create-class-features-plugin/src/decorators.ts
Outdated
Show resolved
Hide resolved
| let resolvedLoose: boolean; | ||
| let higherPriorityPluginName: string; |
There was a problem hiding this comment.
These can also be undefined.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Nit: also update the comment here.
| const privateInVisitor = privateNameVisitorFactory({ | ||
| const privateInVisitor = privateNameVisitorFactory<{ | ||
| classRef: t.Identifier; | ||
| file: unknown; |
| for (const computedPath of computedPaths) { | ||
| const computedKey = computedPath.get("key"); | ||
| if (computedKey.isReferencedIdentifier()) { | ||
| // @ts-expect-error TODO: make isReferencedIdentifier return path is Identifier |
There was a problem hiding this comment.
If you'll want to open a PR to do this, it will be a welcome improvement!
packages/babel-helper-member-expression-to-functions/src/index.ts
Outdated
Show resolved
Hide resolved
...babel-plugin-proposal-class-properties/test/fixtures/private/static-self-method/options.json
Show resolved
Hide resolved
|
rebased to |
packages/babel-helper-member-expression-to-functions/src/index.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-member-expression-to-functions/src/index.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-member-expression-to-functions/src/index.ts
Outdated
Show resolved
Hide resolved
| boundGet() { | ||
| // noop | ||
| // we dont need boundGet here, but memberExpressionToFunctions handler needs it. | ||
| throw new Error(""); |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
Q for team: Is adding new type exports considered new features?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Q: Are these circular references good for TS?
There was a problem hiding this comment.
It seems that TS works pretty fine with these circular refs. Are there any better solutions?
packages/babel-helper-create-class-features-plugin/src/index.ts
Outdated
Show resolved
Hide resolved
packages/babel-helper-create-class-features-plugin/src/fields.ts
Outdated
Show resolved
Hide resolved
|
I merged the |
try to fix ci
use assertExpression instead of if-else Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
also replace assert with type cast
add File type
fix typo and simplify if-else logic
rebased to main
create-class-features-plugin helper
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.