Skip to content

[lexical-utils] Documentation Update: describe $reverseDfs instead of $reverseDfsIterator - #8962

Merged
etrepum merged 1 commit into
facebook:mainfrom
luantaraschi:docs/reverse-dfs-jsdoc
Aug 7, 2026
Merged

[lexical-utils] Documentation Update: describe $reverseDfs instead of $reverseDfsIterator#8962
etrepum merged 1 commit into
facebook:mainfrom
luantaraschi:docs/reverse-dfs-jsdoc

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Description

$reverseDfs carries the JSDoc block of $reverseDfsIterator, copied word for word, so three of its statements describe a different function.

/**
 * $dfs iterator (right to left). Tree traversal is done on the fly as new values are requested with O(1) memory.
 * ...
 * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
 */
export function $reverseDfs(
  startNode?: LexicalNode,
  endNode?: LexicalNode,
): DFSNode[] {
  return Array.from($reverseDfsIterator(startNode, endNode));
}

It is not an iterator, it returns DFSNode[]. Traversal is not done on the fly, Array.from runs it to completion before returning. Memory is not O(1) for the same reason. The @returns line then tells the reader to expect an iterator.

$dfs is the same shape, Array.from over its iterator, and its doc gets this right: "It will then return all the nodes found in the search in an array of objects". $reverseDfs now says the same thing.

Two things were also missing that both $dfs and $dfsIterator document and that apply here equally:

  • the children-only spine, with the pointer to $reverseDfsWithSlots, which exists and is the slot-aware counterpart
  • that an ElementNode passed as endNode stops the traversal before its children

No behavior change, and the wording follows $dfs so the pair reads consistently.

Test plan

Before

// hovering $reverseDfs in an editor
(startNode?: LexicalNode, endNode?: LexicalNode) => DFSNode[]
// "$dfs iterator (right to left) ... O(1) memory"
// "@returns An iterator, each yielded value is a DFSNode"

After

(startNode?: LexicalNode, endNode?: LexicalNode) => DFSNode[]
// "Right-to-left mirror of $dfs. It returns all the nodes found in the search in an array of objects."
// "@returns An array of objects of all the nodes found by the search, including their depth into the tree."

pnpm run prettier and pnpm run tsc are clean. The lexical-utils unit suite passes, 225 tests across 15 files.

… $reverseDfsIterator

## Description

`$reverseDfs` carried the JSDoc of `$reverseDfsIterator` verbatim, so it called
itself an iterator, claimed traversal happens on the fly with O(1) memory, and
documented `@returns` as an iterator. It returns `DFSNode[]` built by
`Array.from`, exactly like `$dfs`, whose doc already says so.

Also added the two notes `$dfs` and `$dfsIterator` carry and that apply here:
the children-only spine with the pointer to `$reverseDfsWithSlots`, and that an
ElementNode endNode stops before its children.

No behavior change.

## Test plan

### Before

"@returns An iterator, each yielded value is a DFSNode" on a function returning
DFSNode[].

### After

Wording follows $dfs. prettier and tsc clean, lexical-utils unit suite 225
passing.
Copilot AI lite review requested due to automatic review settings August 7, 2026 18:38
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 7, 2026 6:40pm
lexical-playground Ready Ready Preview Aug 7, 2026 6:40pm

Request Review

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 7, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 7, 2026
Merged via the queue into facebook:main with commit 554c127 Aug 7, 2026
13 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants