Repository navigation
improve type checking speed - #18623
Merged
Merged
Conversation
Checking that a generic type argument satisfies `t.Node` compares it
with the union of all node types, which is slow when the argument is a
conditional type such as `Extract<...>` or `NonNullable<...>`:
- `NodePath`'s `P` default (`NonNullable<t.ParentMaps[...]>`)
- `VisitNode<S, ToNode<K>>` in `VisitorProp`
- `NodePath<Extract<N, { type: T }>>` in the internal `setType` helper
Bind the first two with `infer U extends t.Node`, which gives the same
types for every instantiation, and narrow the path union directly in
`setType`. This saves about 2s of `@babel/traverse`'s type check.
Assisted-by: Claude Opus 5.5
- `cloneNode` passed `node` narrowed to `NonNullable<T>` to
`cloneNodeInternal`, so `T` was inferred as `NonNullable<T>` and
checked against `t.Node | undefined | null`. Pass `<T>` explicitly.
- The type predicates of `is()` were checked against `t.Node` while
`Extract<t.Node, { type: T }>` was still a union of conditional types.
Bind it with `infer N extends t.Node`, which gives the same type for
every `T`.
This saves about 1.3s of `@babel/types`'s type check.
Assisted-by: Claude Opus 5.5
Declaration emit printed some inferred types in full, and every project that depends on these packages parses the result: - `mixinPlugins` in `@babel/parser` inlined the class returned by each plugin (`plugin-utils.d.ts`: 537 KB -> 0.8 KB). - `getCachedPaths`, `replaceInline`, `replaceExpressionWithStatements` and `replaceWithSourceString` in `@babel/traverse` inlined the union of every `NodePath` (`cache.d.ts`: 268 KB -> 0.6 KB, `replacement.d.ts`: 324 KB -> 1.9 KB). The annotations are the types TypeScript inferred. Assisted-by: Claude Opus 5.5
`options.ts` took the `Plugin` alias from `plugin-utils.ts`, so the declarations of `@babel/parser`'s public options loaded `plugin-utils.d.ts` and through it the declarations of every parser plugin. Projects that only use the options type no longer parse the `estree` and `v8intrinsic` plugin declarations (about 97 KB). Assisted-by: Claude Opus 5.5
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63312 |
|
commit: |
JLHwung
marked this pull request as ready for review
November 14, 2026 18:59
Collaborator
|
Backported to 7.x in #18670. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make tscheckspeedIn this PR we implement a few typing refactors to improve the
make tscheckperformance, the overall walltime (make tscheck) has been improved from 65s to 49s. This PR can be reviewed by commits.