From 7533f08d41a8c7962102bc4c9d38223bef983d39 Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Tue, 4 Jun 2024 17:17:13 -0400 Subject: [PATCH] support binary expression --- packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js | 5 ++++- .../sx-prop/test-cases/sx-value-callback.actual.js | 8 ++++++++ .../sx-prop/test-cases/sx-value-callback.expected.js | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js b/packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js index 5716d987038c6d..a6fbaf5cc9c763 100644 --- a/packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js +++ b/packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js @@ -222,7 +222,10 @@ export default function sxV6(file, api, options) { (returnExpression.type === 'CallExpression' && getObjectKey(returnExpression.callee)?.name === 'theme') || (returnExpression.type === 'MemberExpression' && - getObjectKey(returnExpression)?.name === 'theme') + getObjectKey(returnExpression)?.name === 'theme') || + (returnExpression.type === 'BinaryExpression' && + (getObjectKey(returnExpression.left)?.name === 'theme' || + getObjectKey(returnExpression.right)?.name === 'theme')) ) { data.replaceValue?.(returnExpression); rootThemeCallback(data); diff --git a/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.actual.js b/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.actual.js index 4bfadb23faefa3..6b2198915f6538 100644 --- a/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.actual.js +++ b/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.actual.js @@ -87,3 +87,11 @@ function FacebookCircularProgress(props) { p: 4, }} >; + + theme.zIndex.drawer + 1 }} + open={open} + onClick={handleClose} +> + +; diff --git a/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.expected.js b/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.expected.js index 2de44415a2ba23..36ec3622a5c194 100644 --- a/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.expected.js +++ b/packages/mui-codemod/src/v6.0.0/sx-prop/test-cases/sx-value-callback.expected.js @@ -98,3 +98,14 @@ function FacebookCircularProgress(props) { p: 4 })} >; + + ({ + color: '#fff', + zIndex: theme.zIndex.drawer + 1 + })} + open={open} + onClick={handleClose} +> + +;