Skip to content

Conversation

@liuxingbaoyu
Copy link
Member

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

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 30, 2025

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

Comment on lines 82 to 88
skipKeys: Record<string, boolean> | null = null;
parentPath: NodePath_Final = null;
parentPath: NodePath_Final | null = null;
container: t.Node | Array<t.Node> | null = null;
listKey: string | null = null;
listKey: string | null | undefined = null;
key: string | number | null = null;
node: t.Node | null = null;
type: t.Node["type"] | null = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we could define more properties as non-null, such as container, like we did with parentPath.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a bit hesitant to do the same with scope.parent.

Comment on lines 456 to 462
interface NodePath<
N extends t.Node | null,
T extends t.Node["type"] = NonNullable<N>["type"],
> extends InstanceType<typeof NodePath_Final>,
Copy link
Member Author

Choose a reason for hiding this comment

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

NodePath<null> was introduced here, but it was not used more in path.get because it would be very cumbersome to use if we used strict null and non-null.
Suggestions welcome!

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems the ecosystem has moved to a stricter null, I'll double-check.

Comment on lines 69 to 74
self.replaceWith({
type: "BlockStatement",
directives: [],
body: [],
} as t.BlockStatement);
} satisfies t.BlockStatement);
return true;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a very good fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, though looking back I think we could just use the blockStatement builder, since the @babel/types is already a dependency of @babel/traverse.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 30, 2025

Open in StackBlitz

commit: 2b67663

@liuxingbaoyu liuxingbaoyu force-pushed the strictNullChecks-traverse branch from bf1c9f0 to e0bcaa6 Compare September 12, 2025 12:32
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.

This PR looks good to me in general. Nice work.

binding: Binding,
path: NodePath,
name: string,
name: string | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

The name here is passed from a name property of an Identifier, I think it should be always a string unless the AST is malformed.

return getTypeAnnotationBindingConstantViolations(

const testType = getConditionalAnnotation(binding, path, name);

Can we remove the optional marker here?

if (types.length) {
return {
// @ts-expect-error FIXME: may return undefined
typeAnnotation: createUnionType(types),
Copy link
Contributor

Choose a reason for hiding this comment

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

The createUnionType will return something as long as types are either all Flow types or TS types. The parser will not mix flow types with ts types, so if there are any outliers, they should be considered malformed AST. In this case can we use the definite marker here?

// We also move past any constant violations.
for (const violationPath of binding.constantViolations) {
// @ts-expect-error comparing undefined and number
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The getAttachmentParentForPath now always return a NodePath, does TS throw an error because we are comparing string to number?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems that it is because key may be null.

@liuxingbaoyu liuxingbaoyu force-pushed the strictNullChecks-traverse branch from bceb22f to d423e2f Compare September 29, 2025 22:01
@liuxingbaoyu
Copy link
Member Author

I pushed fa9e572 (#17499) to fix issues I encountered while upgrading the ecosystem.

@liuxingbaoyu liuxingbaoyu added the PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release label Sep 29, 2025
@liuxingbaoyu
Copy link
Member Author

I'm marking this as a bug fix because this fixes compatibility issues with strictNullChecks.

block!: t.Pattern | t.Scopable;

inited;
declare inited;
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid declare here? We want them to be defined as own properties.

@nicolo-ribaudo nicolo-ribaudo force-pushed the strictNullChecks-traverse branch from ce2662e to 2b67663 Compare October 3, 2025 14:03
This was referenced Nov 27, 2025
@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 Jan 3, 2026
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants