Unverified Commit 4264408b authored by LongYinan's avatar LongYinan Committed by GitHub

Fix emotion shouldForwardProp options breaks component selectors (#39390)

fixes https://github.com/vercel/next.js/issues/38291



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent b30ae643
...@@ -62,7 +62,9 @@ export const Pink = styled(Basic)({ ...@@ -62,7 +62,9 @@ export const Pink = styled(Basic)({
color: 'hotpink', color: 'hotpink',
}) })
export const BasicExtended = styled(Basic)`` export const BasicExtended = styled(Basic, {
shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'),
})``
export const ComponentSelectorsExtended = styled.div` export const ComponentSelectorsExtended = styled.div`
${BasicExtended} { ${BasicExtended} {
......
...@@ -480,6 +480,20 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -480,6 +480,20 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
if let Some(cm) = self.create_sourcemap(expr.span.lo()) { if let Some(cm) = self.create_sourcemap(expr.span.lo()) {
expr.args.push(cm.as_arg()); expr.args.push(cm.as_arg());
} }
if let Some(ExprOrSpread { expr, .. }) = c.args.get_mut(1) {
if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut()
{
props.extend(args_props);
} else {
c.args.push(
Expr::Object(ObjectLit {
span: DUMMY_SP,
props: args_props,
})
.as_arg(),
);
}
} else {
c.args.push( c.args.push(
Expr::Object(ObjectLit { Expr::Object(ObjectLit {
span: DUMMY_SP, span: DUMMY_SP,
...@@ -492,6 +506,7 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -492,6 +506,7 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
} }
} }
} }
}
// styled.div({}) // styled.div({})
// customEmotionReact.css({}) // customEmotionReact.css({})
Expr::Member(m) => { Expr::Member(m) => {
...@@ -592,7 +607,19 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -592,7 +607,19 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
}), }),
))); )));
} }
if let Some(ExprOrSpread { expr, .. }) = callee.args.get_mut(1) {
if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut() {
props.extend(object_props);
} else {
callee.args.push(
Expr::Object(ObjectLit {
span: DUMMY_SP,
props: object_props,
})
.as_arg(),
);
}
} else {
callee.args.push( callee.args.push(
Expr::Object(ObjectLit { Expr::Object(ObjectLit {
span: DUMMY_SP, span: DUMMY_SP,
...@@ -600,6 +627,7 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -600,6 +627,7 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
}) })
.as_arg(), .as_arg(),
); );
}
return Expr::Call(CallExpr { return Expr::Call(CallExpr {
span: DUMMY_SP, span: DUMMY_SP,
callee: callee.as_callee(), callee: callee.as_callee(),
......
...@@ -28,6 +28,12 @@ const DivContainer2 = styled.div` ...@@ -28,6 +28,12 @@ const DivContainer2 = styled.div`
background: red; background: red;
` `
const ContainerWithOptions = styled('div', {
shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'),
})`
color: hotpink;
`
const SpanContainer = styled('span')({ const SpanContainer = styled('span')({
background: 'yellow', background: 'yellow',
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment