/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/upgrade/src/lib/ast/modifiers.ts
28 строк
779 B
Julius Marminge
chore: `@trpc/upgrade` with queryOptions API codemod (#6262)
18 фев 2025, 01:43
Не верифицирован
18 фев 2025, 01:43
6627c5a
Код
Авторство
О чём код?
import type { Identifier, JSCodeshift, MemberExpression } from 'jscodeshift'; /** * Replaces the identifier for the root path key * of a member expression * * For dot notation like `rootKey.x.y.z` the AST * is constructed with the `rootKey` being nested deep * inside a wrapper MemberExpression holding `rootKey.x` * and so on * * This function helps replace the `rootKey` identifier with * the provided identifier node */ export function replaceMemberExpressionRootIndentifier( j: JSCodeshift, expr: MemberExpression, id: Identifier, ): boolean { if (j.Identifier.check(expr.object)) { expr.object = id; return true; } return !j.MemberExpression.check(expr.object) ? false : replaceMemberExpressionRootIndentifier(j, expr.object, id); }