Skip to content

Commit 0ca9dd8

Browse files
committed
Skip emitting empty withConfig
1 parent 561ac8d commit 0ca9dd8

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/__tests__/baselines/minification-only/minify-css-to-use-with-transpilation.ts.baseline

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ TypeScript before transform:
4747
TypeScript after transform:
4848

4949
declare const styled: any;
50-
const Simple = styled.div.withConfig({}) \`width:100%;\`;
51-
const Interpolation = styled.div.withConfig({}) \`content:" \${props => props.text} ";\`;
52-
const SpecialCharacters = styled.div.withConfig({}) \`content:" \${props => props.text} ";color:red;\`;
53-
const Comment = styled.div.withConfig({}) \`color:red;\`;
54-
const Parens = styled.div.withConfig({}) \`&:hover{color:blue;}\`;
50+
const Simple = styled.div \`width:100%;\`;
51+
const Interpolation = styled.div \`content:" \${props => props.text} ";\`;
52+
const SpecialCharacters = styled.div \`content:" \${props => props.text} ";color:red;\`;
53+
const Comment = styled.div \`color:red;\`;
54+
const Parens = styled.div \`&:hover{color:blue;}\`;
5555
export {};
5656

5757

src/__tests__/baselines/minification-only/minify-css-to-use-without-transpilation.ts.baseline

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ TypeScript before transform:
6060
TypeScript after transform:
6161

6262
declare const styled: any;
63-
const Simple = styled.div.withConfig({}) \`width:100%;\`;
64-
const Interpolation = styled.div.withConfig({}) \`content:"https://test.com/\${props => props.endpoint}";\`;
65-
const SpecialCharacters = styled.div.withConfig({}) \`content:" \${props => props.text} ";color:red;\`;
66-
const Comment = styled.div.withConfig({}) \`width:100%;color:red;\`;
67-
const Parens = styled.div.withConfig({}) \`&:hover{color:blue;}color:red;\`;
68-
const UrlComments = styled.div.withConfig({}) \`color:red; background:red;border:1px solid green;\`;
63+
const Simple = styled.div \`width:100%;\`;
64+
const Interpolation = styled.div \`content:"https://test.com/\${props => props.endpoint}";\`;
65+
const SpecialCharacters = styled.div \`content:" \${props => props.text} ";color:red;\`;
66+
const Comment = styled.div \`width:100%;color:red;\`;
67+
const Parens = styled.div \`&:hover{color:blue;}color:red;\`;
68+
const UrlComments = styled.div \`color:red; background:red;border:1px solid green;\`;
6969
export {};
7070

7171

src/__tests__/baselines/minification-only/minify-single-line-comments-with-interpolations.ts.baseline

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ TypeScript before transform:
7575
TypeScript after transform:
7676

7777
declare const styled: any;
78-
const Test1 = styled.div.withConfig({}) \`width:100%;//\${'red'}\`;
79-
const Test2 = styled.div.withConfig({}) \`width:100%;//\${'red'}\`;
80-
const Test3 = styled.div.withConfig({}) \`width:100%;\${'red'};\`;
81-
const Test4 = styled.div.withConfig({}) \`width:100%;//\${'red'}\`;
82-
const Test5 = styled.div.withConfig({}) \`width:100%;//\${'red'}\${'blue'}\`;
83-
const Test6 = styled.div.withConfig({}) \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
84-
const Test7 = styled.div.withConfig({}) \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
85-
const Test8 = styled.dev.withConfig({}) \`color:/*\${'red'}*/blue;\`;
86-
const Test9 = styled.dev.withConfig({}) \`color://\${'red'}\\nblue\`;
78+
const Test1 = styled.div \`width:100%;//\${'red'}\`;
79+
const Test2 = styled.div \`width:100%;//\${'red'}\`;
80+
const Test3 = styled.div \`width:100%;\${'red'};\`;
81+
const Test4 = styled.div \`width:100%;//\${'red'}\`;
82+
const Test5 = styled.div \`width:100%;//\${'red'}\${'blue'}\`;
83+
const Test6 = styled.div \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
84+
const Test7 = styled.div \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
85+
const Test8 = styled.dev \`color:/*\${'red'}*/blue;\`;
86+
const Test9 = styled.dev \`color://\${'red'}\\nblue\`;
8787
export {};
8888

8989

src/createTransformer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ export function createTransformer({
197197
}
198198
}
199199

200-
return ts.createCall(
201-
ts.createPropertyAccess(node as ts.Expression, 'withConfig'),
202-
undefined,
203-
[ts.createObjectLiteral(styledConfig)]);
200+
if (styledConfig.length > 0) {
201+
return ts.createCall(
202+
ts.createPropertyAccess(node as ts.Expression, 'withConfig'),
203+
undefined,
204+
[ts.createObjectLiteral(styledConfig)]);
205+
}
204206
}
205207

206208
ts.forEachChild(node, n => {

0 commit comments

Comments
 (0)