feat: support styled-components Foo.extend.attrs()`` (#4434)

* Support styled-components Foo.extend.attrs()``

* update snapshot
master
Lucas Duailibe 2018-05-07 06:38:19 -03:00 committed by Evilebot Tnawi
parent cc4392e5c0
commit f6b22e3fd1
3 changed files with 21 additions and 3 deletions

View File

@ -371,7 +371,7 @@ function isStyledComponents(path) {
// styled.foo``
isStyledIdentifier(tag.object) ||
// Component.extend``
(/^[A-Z]/.test(tag.object.name) && tag.property.name === "extend")
isStyledExtend(tag)
);
case "CallExpression":
@ -379,9 +379,11 @@ function isStyledComponents(path) {
// styled(Component)``
isStyledIdentifier(tag.callee) ||
(tag.callee.type === "MemberExpression" &&
// styled.foo.attr({})``
((tag.callee.object.type === "MemberExpression" &&
isStyledIdentifier(tag.callee.object.object)) ||
// styled.foo.attr({})``
(isStyledIdentifier(tag.callee.object.object) ||
// Component.extend.attr({)``
isStyledExtend(tag.callee.object))) ||
// styled(Component).attr({})``
(tag.callee.object.type === "CallExpression" &&
isStyledIdentifier(tag.callee.object.callee))))
@ -415,4 +417,8 @@ function isStyledIdentifier(node) {
return node.type === "Identifier" && node.name === "styled";
}
function isStyledExtend(node) {
return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
}
module.exports = embed;

View File

@ -21,6 +21,10 @@ border-color : tomato
\`;
Button.extend.attr({})\`
border-color : black;
\`
styled(ExistingComponent)\`
color : papayawhip ; background-color: firebrick\`;
@ -94,6 +98,10 @@ const TomatoButton = Button.extend\`
border-color: tomato;
\`;
Button.extend.attr({})\`
border-color: black;
\`;
styled(ExistingComponent)\`
color: papayawhip;
background-color: firebrick;

View File

@ -18,6 +18,10 @@ border-color : tomato
`;
Button.extend.attr({})`
border-color : black;
`
styled(ExistingComponent)`
color : papayawhip ; background-color: firebrick`;