fix(devtools-bundler-core): skip primitive values when walking AST children by AlemTuzlak · Pull Request #539 · TanStack/devtools · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/ast-child-keys-primitive.md
25 changes: 25 additions & 0 deletions packages/devtools-bundler-core/src/ast-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ describe('forEachChild', () => {

expect(visited).toEqual([real])
})

it('does not throw when a cached child key holds a primitive in a later node', () => {
// A regex literal has an object `value`, a string literal has a string
// `value`, and both share one type, so the cached keys include `value`.
const regexLiteral = {
type: 'ForEachSharedLiteral',
start: 0,
end: 6,
value: {},
} as unknown as Node
const stringLiteral = {
type: 'ForEachSharedLiteral',
start: 0,
end: 12,
value: 'use client',
} as unknown as Node

forEachChild(regexLiteral, () => {})

const visited: Array<Node> = []
expect(() =>
forEachChild(stringLiteral, (child) => visited.push(child)),
).not.toThrow()
expect(visited).toEqual([])
})
})

describe('walk', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/devtools-bundler-core/src/ast-utils.ts
Loading