Skip to content

Commit

Permalink
[pigment-css] Fix propTypes removal during eval stage
Browse files Browse the repository at this point in the history
Conditional assignment of propTypes was not handled resulting in error
while using prod builds of material-ui.
  • Loading branch information
brijeshb42 committed Mar 28, 2024
1 parent 933b6f4 commit b292796
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/pigment-css-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@types/stylis": "^4.2.5",
"chai": "^4.4.1",
"prettier": "^3.2.5",
"prop-types": "^15.8.1",
"react": "^18.2.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export const removePropTypesPlugin = declare<{}>((api) => {
if (!property.isIdentifier({ name: 'propTypes' })) {
return;
}
if (path.parentPath.isExpressionStatement()) {
path.parentPath.remove();
const parentExpression = path.findParent((p) => p.isExpressionStatement());
if (parentExpression) {
parentExpression.remove();
}
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { styled, keyframes } from '@pigment-css/react';
import PropTypes from 'prop-types';

const rotateKeyframe = keyframes({
from: {
Expand Down Expand Up @@ -34,3 +35,18 @@ const SliderRail2 = styled.span`
display: none;
}
`;

export function App() {
return (
<Component>
<SliderRail />
<SliderRail2 />
</Component>
);
}

process.env.NODE_ENV !== 'production'
? (App.propTypes = {
children: PropTypes.element,
})
: void 0;
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import { styled as _styled, styled as _styled2, styled as _styled3 } from '@pigment-css/react';
import _theme from '@pigment-css/react/theme';
import PropTypes from 'prop-types';
const Component = /*#__PURE__*/ _styled('div')({
classes: ['c1h7nuob'],
});
const SliderRail = /*#__PURE__*/ _styled2('span', {
name: 'MuiSlider',
slot: 'Rail',
})({
classes: ['s13xim6i', 's13xim6i-1'],
});
const SliderRail2 = /*#__PURE__*/ _styled3('span')({
classes: ['s1emg10t'],
});
export function App() {
return (
<Component>
<SliderRail />
<SliderRail2 />
</Component>
);
}
process.env.NODE_ENV !== 'production'
? (App.propTypes = {
children: PropTypes.element,
})
: void 0;
14 changes: 14 additions & 0 deletions packages/pigment-css-react/tests/styled/fixtures/styled.input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { styled, keyframes } from '@pigment-css/react';
import PropTypes from 'prop-types';

const rotateKeyframe = keyframes({
from: {
Expand Down Expand Up @@ -32,3 +33,16 @@ const SliderRail2 = styled.span`
display: none;
}
`;

export function App() {
return (
<Component>
<SliderRail />
<SliderRail2 />
</Component>
);
}

App.propTypes = {
children: PropTypes.element,
};
12 changes: 12 additions & 0 deletions packages/pigment-css-react/tests/styled/fixtures/styled.output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { styled as _styled, styled as _styled2, styled as _styled3 } from '@pigment-css/react';
import _theme from '@pigment-css/react/theme';
import PropTypes from 'prop-types';
const Component = /*#__PURE__*/ _styled('div')({
classes: ['c1aiqtje'],
});
Expand All @@ -12,3 +13,14 @@ export const SliderRail = /*#__PURE__*/ _styled2('span', {
const SliderRail2 = /*#__PURE__*/ _styled3('span')({
classes: ['shdkmm7'],
});
export function App() {
return (
<Component>
<SliderRail />
<SliderRail2 />
</Component>
);
}
App.propTypes = {
children: PropTypes.element,
};
5 changes: 4 additions & 1 deletion packages/pigment-css-react/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export async function runTransformation(
babelrc: false,
plugins: ['@babel/plugin-syntax-jsx'],
},
tagResolver(_source: string, tag: string) {
tagResolver(source: string, tag: string) {
if (source !== '@pigment-css/react') {
return null;
}
return require.resolve(`../exports/${tag}`);
},
};
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b292796

Please sign in to comment.