Skip to content

Commit

Permalink
[codemod] Skip sx spread transformation (#43291)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Aug 14, 2024
1 parent 769e9a3 commit 8968394
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export default function sxV6(file, api, options) {
}
if (data.node.argument.type === 'ConditionalExpression') {
const isSxSpread =
(data.node.argument.test.type === 'CallExpression' &&
data.node.argument.test.callee.type === 'MemberExpression' &&
data.node.argument.test.callee.object.name === 'Array' &&
data.node.argument.test.callee.property.name === 'isArray') ||
(data.node.argument.consequent.type === 'Identifier' &&
data.node.argument.consequent.name === 'sx') ||
(data.node.argument.alternate.type === 'Identifier' &&
Expand Down
24 changes: 24 additions & 0 deletions packages/mui-codemod/src/v6.0.0/sx-prop/sx-v6.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,29 @@ describe('@mui/codemod', () => {
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});

describe('inheritance sx-v6', () => {
it('should do nothing', () => {
const actual = transform(
{ source: read('./test-cases/sx-inheritance.actual.js') },
{ jscodeshift },
{},
);

const expected = read('./test-cases/sx-inheritance.expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent', () => {
const actual = transform(
{ source: read('./test-cases/sx-inheritance.expected.js') },
{ jscodeshift },
{},
);

const expected = read('./test-cases/sx-inheritance.expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Layout
{...layoutProps}
{...slotProps.layout}
slots={slots}
slotProps={slotProps}
sx={[
...(Array.isArray(sx) ? sx : [sx]),
...(Array.isArray(slotProps?.layout?.sx) ? slotProps.layout.sx : [slotProps.layout.sx]),
]}
className={clsx(className, slotProps.layout.className)}
ref={ref}
/>;

<FormControl
disabled={disabled}
id={id}
sx={[...(Array.isArray(formControlSx) ? formControlSx : [formControlSx])]}
/>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Layout
{...layoutProps}
{...slotProps.layout}
slots={slots}
slotProps={slotProps}
sx={[
...(Array.isArray(sx) ? sx : [sx]),
...(Array.isArray(slotProps?.layout?.sx) ? slotProps.layout.sx : [slotProps.layout.sx]),
]}
className={clsx(className, slotProps.layout.className)}
ref={ref}
/>;

<FormControl
disabled={disabled}
id={id}
sx={[...(Array.isArray(formControlSx) ? formControlSx : [formControlSx])]}
/>;

0 comments on commit 8968394

Please sign in to comment.