Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigment-css] Fix propTypes removal during eval stage #41695

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +39 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if the propTypes are not handled? I guess the test will throw during evaluation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Contributor Author

@brijeshb42 brijeshb42 Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During evaluation, App gets set to null. So we are setting a value to null object resulting in the error.


App = null;

App.propTypes = {}

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.

Loading