/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/mui-codemod/src/util/assignObject.js
26 строк
1 KB
Siriwat K
[codemod] Add accordion props deprecation (#40771)
30 янв 2024, 06:56
Не верифицирован
30 янв 2024, 06:56
c479c9b
Код
Авторство
О чём код?
/** * Pushes an expression to a known object. handles local object and variable declaration. * * @param {import('jscodeshift')} j * @param {{ target: import('jscodeshift').JSXAttribute; expression: import('ast-types/gen/kinds').ExpressionKind; key: string }} options * * @example push expression to `slots.transition` => <Component slots={{ transition: <expression> }} /> * @example push expression to `slots.transition` => <Component slots={{ ...slots, transition: <expression> }} /> */ export default function assignObject(j, options) { const { target, expression, key } = options; if (target && target.type === 'JSXAttribute') { const expContainer = /** @type import('jscodeshift').JSXExpressionContainer */ (target.value); if (expContainer.expression.type === 'ObjectExpression') { // case `<prop>={{ ... }}` expContainer.expression.properties.push(j.objectProperty(j.identifier(key), expression)); } else if (expContainer.expression.type === 'Identifier') { // case `<prop>={outerVariable} expContainer.expression = j.objectExpression([ j.spreadElement(j.identifier(expContainer.expression.name)), j.objectProperty(j.identifier(key), expression), ]); } } }