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

fix(styled-components): handle topLevelIdent[localIdent] in template literal #233

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,16 @@ where
if let Some(root) = trace_root_value(expr) {
match root {
Expr::Lit(_) => true,
Expr::Ident(id) if is_top_level_ident(id) => {
if let Expr::Call(CallExpr { args, .. }) = expr {
args.iter()
.all(|arg| -> bool { is_direct_access(&arg.expr, is_top_level_ident) })
} else {
true
}
}
Expr::Ident(id) if is_top_level_ident(id) => match expr {
Expr::Call(CallExpr { args, .. }) => args
.iter()
.all(|arg| -> bool { is_direct_access(&arg.expr, is_top_level_ident) }),
Expr::Member(MemberExpr {
prop: MemberProp::Computed(ComputedPropName { expr, .. }),
..
}) => is_direct_access(expr, is_top_level_ident),
_ => true,
},
_ => false,
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,84 @@ function Home() {

const myCss = (x) => css`
margin: ${x}px;
`;
`;

const colorMap = {
orange: '#E3750E',
blue: '#38699F',
green: '#3F9348',
};

const colorMap2 = {
red: 'orange',
cyan: 'blue',
lime: 'green',
}

const LocalMemberInterpolation = (p) => {
const color = "red";

return (
<p
css={`
color: ${colorMap[color]};
`}
>
H
</p>
);
};

const LocalMemberInterpolation2 = (p) => {
const color = "red";

return (
<p
css={`
color: ${colorMap[colorMap2[color]]};
`}
>
H
</p>
);
};

const LocalMemberInterpolation3 = (p) => {
const color = "red";

return (
<p
css={`
color: ${colorMap[id(color)]};
`}
>
H
</p>
);
};

const LocalMemberInterpolation4 = () => {
return (
<p
css={`
color: ${colorMap["red"]};
`}
>
H
</p>
);
};

const LocalMemberCssHelperProp = (p) => {
const color = "red";

return (
<p
css={css`
color: ${colorMap[color]};
`}
>
H
</p>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,55 @@ function Home() {
const myCss = (x)=>css`
margin: ${x}px;
`;
const colorMap = {
orange: '#E3750E',
blue: '#38699F',
green: '#3F9348'
};
const colorMap2 = {
red: 'orange',
cyan: 'blue',
lime: 'green'
};
const LocalMemberInterpolation = (p)=>{
const color = "red";
return <_StyledP17 $_css18={colorMap[color]}>

H

</_StyledP17>;
};
const LocalMemberInterpolation2 = (p)=>{
const color = "red";
return <_StyledP18 $_css19={colorMap[colorMap2[color]]}>

H

</_StyledP18>;
};
const LocalMemberInterpolation3 = (p)=>{
const color = "red";
return <_StyledP19 $_css20={colorMap[id(color)]}>

H

</_StyledP19>;
};
const LocalMemberInterpolation4 = ()=>{
return <_StyledP20>

H

</_StyledP20>;
};
const LocalMemberCssHelperProp = (p)=>{
const color = "red";
return <_StyledP21 $_css21={colorMap[color]}>

H

</_StyledP21>;
};
var _StyledP = _styled("p")`flex: 1;`;
var _StyledP2 = _styled("p")`
flex: 1;
Expand Down Expand Up @@ -229,3 +278,18 @@ var _StyledDiv2 = _styled("div")`
/* indirect */
${(p)=>p.$_css17}
`;
var _StyledP17 = _styled("p")`
color: ${(p)=>p.$_css18};
`;
var _StyledP18 = _styled("p")`
color: ${(p)=>p.$_css19};
`;
var _StyledP19 = _styled("p")`
color: ${(p)=>p.$_css20};
`;
var _StyledP20 = _styled("p")`
color: ${colorMap["red"]};
`;
var _StyledP21 = _styled("p")`
color: ${(p)=>p.$_css21};
`;
Loading