Visitar URL original
fix(traverse): do not return null NodePath in getCompletionRecords for IfStatement without alternate by rohanbuildai · Pull Request #18584 · babel/babel · GitHub
Skip to content

fix(traverse): do not return null NodePath in getCompletionRecords for IfStatement without alternate - #18584

Open
rohanbuildai wants to merge 1 commit into
babel:mainfrom
rohanbuildai:fix/traverse-completion-records-null
Open

rohanbuildai wants to merge 1 commit into
babel:mainfrom
rohanbuildai:fix/traverse-completion-records-null

Conversation

@rohanbuildai

@rohanbuildai rohanbuildai commented Nov 11, 2026 •

Copy link
Copy Markdown
Q A
Fixed Issues? Fixes #18583
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

Note: This pull request description was generated with the assistance of an LLM.

When getCompletionRecords traverses an IfStatement without an alternate branch (e.g. if (c) { return 1; }), path.get("alternate") yields a NodePath<null> where .node is null.

Currently, addCompletionRecords checks if (path). Because the NodePath instance is truthy, it forwards the null path to _getCompletionRecords, which defaults to pushing a NormalCompletion with node: null. This results in getCompletionRecords() returning paths that have no underlying AST node and this is obviously going to solve the problem by ensuring addCompletionRecords checks if (path?.hasNode()) before collecting records.

We also remove the @ts-expect-error FIXME: path may be NodePath<null> comment as the check is now type-safe and add a unit test in packages/babel-traverse/test/family.js.

Assisted-by: Gemini 3.8 Flash

…r IfStatement without alternate Assisted-by: Gemini 3.8 Flash
@babel-bot

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 168f3ea

@rohanbuildai
rohanbuildai marked this pull request as ready for review November 11, 2026 09:53

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[babel-traverse] getCompletionRecords returns NodePath<null> for IfStatement without alternate

2 participants