Skip to content

Commit 9ee4d72

Browse files
committed
Add support of style objects (implements #30)
1 parent c7a0c4d commit 9ee4d72

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/__tests__/baselines/base/style-objects.ts.baseline

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ TypeScript before transform:
6868
TypeScript after transform:
6969

7070
declare const styled: any;
71-
const Button = styled.button({
71+
const Button = styled.button.withConfig({ displayName: "Button" })({
7272
color: 'red'
7373
});
7474
declare const nonStyled: any;
7575
const NonButton = nonStyled.button({
7676
color: 'red'
7777
});
78-
const OtherButton = styled(Button)({
78+
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton" })({
7979
color: 'blue'
8080
});
81-
const SuperButton = Button.extend({
81+
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton" })({
8282
color: 'super'
8383
});
8484
export default styled.link({
8585
color: 'black'
8686
});
87-
export const SmallButton = Button.extend({
87+
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton" })({
8888
fontSize: '.7em'
8989
});
90-
const MiniButton = styled(SmallButton).attrs({ size: 'mini' })({
90+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton" })({
9191
fontSize: '.1em'
9292
});
9393

src/__tests__/baselines/ssr/style-objects.ts.baseline

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ TypeScript before transform:
6868
TypeScript after transform:
6969

7070
declare const styled: any;
71-
const Button = styled.button({
71+
const Button = styled.button.withConfig({ displayName: "Button", componentId: "sc-7b7p9e" })({
7272
color: 'red'
7373
});
7474
declare const nonStyled: any;
7575
const NonButton = nonStyled.button({
7676
color: 'red'
7777
});
78-
const OtherButton = styled(Button)({
78+
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton", componentId: "sc-14ah7t" })({
7979
color: 'blue'
8080
});
81-
const SuperButton = Button.extend({
81+
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton", componentId: "sc-1t5v351" })({
8282
color: 'super'
8383
});
8484
export default styled.link({
8585
color: 'black'
8686
});
87-
export const SmallButton = Button.extend({
87+
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton", componentId: "sc-ftk9hu" })({
8888
fontSize: '.7em'
8989
});
90-
const MiniButton = styled(SmallButton).attrs({ size: 'mini' })({
90+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-15rszef" })({
9191
fontSize: '.1em'
9292
});
9393

src/createTransformer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ export function createTransformer({
128128
const visitor: ts.Visitor = (node) => {
129129
if (
130130
node.parent
131-
&& isTaggedTemplateExpression(node.parent)
132-
&& node.parent.tag === node
131+
&& (
132+
isTaggedTemplateExpression(node.parent) && node.parent.tag === node
133+
|| isCallExpression(node.parent)
134+
)
133135
&& node.parent.parent
134136
&& isVariableDeclaration(node.parent.parent)
135137
&& isStyledFunction(node, identifiers)

0 commit comments

Comments
 (0)