561 B
561 B
Allow AstPath#call() to access property of nullish properties (#17860 by @fisker)
Previously, to check for a possible non-existent child node, we had to ensure the node existed first.
const isFoo = path.call(() => path.node?.type === "Foo", "foo", "bar");
// Uncaught TypeError: Cannot read properties of undefined (reading 'bar')
We have to
const isFoo =
path.node.foo?.bar &&
path.call(() => path.node?.type === "Foo", "foo", "bar");
Since Prettier main, accessing a property of nullish properties no longer throws errors.