Skip to content

Commit a9a298d

Browse files
authored
Merge branch 'master' into patch-1
2 parents 2fca9ba + 943ae36 commit a9a298d

File tree

11 files changed

+110
-19
lines changed

11 files changed

+110
-19
lines changed

CHANGELOG.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
## [Unreleased]
5+
6+
## [1.5.0]
7+
8+
- transform anonymous default exports (fix #371 in #367)
9+
- remove deprecated `.extend` transformation pattern (fix #48 in #370)
10+
11+
## [1.4.4]
12+
13+
- bugfix in minification of tabs (fix #142 in #152)
14+
15+
## [1.4.3]
16+
17+
- bugfix in minification (fix #44 in #45)
18+
19+
## [1.4.2]
20+
21+
- another important bugfix in minification (#40 by @Ky6uk, #41)
22+
23+
## [1.4.1]
24+
25+
- important bugfix in minification (#36, #39)
26+
27+
## [1.4.0]
28+
29+
- add experimental support of minification (#14, #35)
30+
- skip emitting empty `withConfig` (#37)
31+
32+
## [1.4.0-rc]
33+
34+
- add experimental support of minification (#14, #35)
35+
36+
## [1.3.0]
37+
38+
- improved detection of component names which fixes issues with jQuery and lodash (#33, #34)
39+
40+
## [1.2.0]
41+
42+
- add support of [style objects](https://www.styled-components.com/docs/advanced#style-objects) (#30, #32)
43+
44+
## [1.1.0]
45+
46+
- component id generation that helps with SSR (great contribution #21 by @fabyo82)
47+
- customizable identifiers of styled-components functions
48+
- display name generation can be turned off
49+
50+
## [1.1.0-rc]
51+
52+
- component id generation that helps with SSR (great contribution #21 by @fabyo82)
53+
- customizable identifiers of `styled-components` functions
54+
- display name generation can be turned off
55+
56+
## [1.0.0]
57+
58+
- The first official release!
59+
- updated `typescript` dependency to support TS 3.0+ (#17, fixed #15)
60+
- remove `ts-is-kind` dependency (#17, fixed #16)
61+
62+
## [0.0.7]
63+
64+
- updated `typescript` dependency to support TS 3.0+ (#17, fixed #15)
65+
- remove `ts-is-kind` dependency (#17, fixed #16)
66+
67+
[Unreleased]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.4.4...HEAD
68+
[1.4.4]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.4.3...1.4.4
69+
[1.4.3]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.4.2...1.4.3
70+
[1.4.2]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.4.1...1.4.2
71+
[1.4.1]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.4.0...1.4.1
72+
[1.4.0]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.3.0...1.4.0
73+
[1.4.0-rc]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.3.0...1.4.0-rc
74+
[1.3.0]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.2.0...1.3.0
75+
[1.2.0]: https://github.com/igorbek/typescript-plugin-styled-components/compare/1.1.0...1.2.0
76+
[1.1.0]: https://github.com/igorbek/typescript-plugin-styled-components/compare/v1.0.0...1.1.0
77+
[1.1.0-rc]: https://github.com/igorbek/typescript-plugin-styled-components/compare/v1.0.0...1.1.0-rc
78+
[1.0.0]: https://github.com/igorbek/typescript-plugin-styled-components/compare/v0.0.7...v1.0.0
79+
[0.0.7]: https://github.com/igorbek/typescript-plugin-styled-components/compare/v0.0.6...v0.0.7

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ interface CustomStyledIdentifiers {
289289
keyframes: string[];
290290
css: string[];
291291
createGlobalStyle: string[];
292+
extend: string[];
292293
}
293294
```
294295

@@ -297,6 +298,7 @@ interface CustomStyledIdentifiers {
297298
- `keyframes` - list of identifiers of `keyframes` API (default `['keyframes']`)
298299
- `css` - list of identifiers of `css` API (default `['css']`)
299300
- `createGlobalStyle` - list of identifiers of `createGlobalStyle` API (default `['createGlobalStyle']`)
301+
- `extend` - list of identifiers of `extend` API (default `[]`). Note this API has been deprecated in `styled-components` so starting from `1.5` this option by default has empty set, which means it does not recognize this API by default.
300302

301303
Example
302304

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-plugin-styled-components",
3-
"version": "1.4.4",
3+
"version": "1.5.0",
44
"description": "TypeScript transformer for improving the debugging experience of styled-components",
55
"main": "dist/index.js",
66
"homepage": "https://github.com/Igorbek/typescript-plugin-styled-components",
@@ -21,7 +21,7 @@
2121
},
2222
"typings": "dist/index.d.ts",
2323
"peerDependencies": {
24-
"typescript": "^2.5.2 || ^3.0"
24+
"typescript": "^2.5.2 || ^3.0 || ^4.0"
2525
},
2626
"devDependencies": {
2727
"@types/jest": "^25.2.1",

src/__tests__/baselines/base/issue33.ts.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TypeScript after transform:
3939
declare const jQuery: any;
4040
declare const _: any;
4141
declare const Button: any;
42-
const Button1 = Button.extend.withConfig({ displayName: "Button1" }) \` color: red \`;
42+
const Button1 = Button.extend \` color: red \`;
4343
const Button2 = $.extend \` color: red \`;
4444
const Button3 = jQuery.extend \` color: red \`;
4545
const Button4 = _.extend \` color: red \`;

src/__tests__/baselines/base/sample1.ts.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ TypeScript after transform:
7878
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton" }) \`
7979
color: blue;
8080
\`;
81-
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton" }) \`
81+
const SuperButton = Button.extend \`
8282
color: super;
8383
\`;
8484
export default styled.link \`
8585
color: black;
8686
\`;
87-
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton" }) \`
87+
export const SmallButton = Button.extend \`
8888
font-size: .7em;
8989
\`;
9090
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton" }) \`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ TypeScript after transform:
7878
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton" })({
7979
color: 'blue'
8080
});
81-
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton" })({
81+
const SuperButton = Button.extend({
8282
color: 'super'
8383
});
8484
export default styled.link({
8585
color: 'black'
8686
});
87-
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton" })({
87+
export const SmallButton = Button.extend({
8888
fontSize: '.7em'
8989
});
9090
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton" })({

src/__tests__/baselines/ssr/issue33.ts.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TypeScript after transform:
3939
declare const jQuery: any;
4040
declare const _: any;
4141
declare const Button: any;
42-
const Button1 = Button.extend.withConfig({ displayName: "Button1", componentId: "sc-1iinolv" }) \` color: red \`;
42+
const Button1 = Button.extend \` color: red \`;
4343
const Button2 = $.extend \` color: red \`;
4444
const Button3 = jQuery.extend \` color: red \`;
4545
const Button4 = _.extend \` color: red \`;

src/__tests__/baselines/ssr/sample1.ts.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ TypeScript after transform:
7878
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton", componentId: "sc-ce0fkl" }) \`
7979
color: blue;
8080
\`;
81-
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton", componentId: "sc-10xv1bi" }) \`
81+
const SuperButton = Button.extend \`
8282
color: super;
8383
\`;
84-
export default styled.link \`
84+
export default styled.link.withConfig({ componentId: "sc-vba0dl" }) \`
8585
color: black;
8686
\`;
87-
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton", componentId: "sc-8sh5f7" }) \`
87+
export const SmallButton = Button.extend \`
8888
font-size: .7em;
8989
\`;
90-
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-v7haos" }) \`
90+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-ndnumj" }) \`
9191
font-size: .1em;
9292
\`;
9393

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ TypeScript after transform:
7878
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton", componentId: "sc-14ah7t" })({
7979
color: 'blue'
8080
});
81-
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton", componentId: "sc-1t5v351" })({
81+
const SuperButton = Button.extend({
8282
color: 'super'
8383
});
84-
export default styled.link({
84+
export default styled.link.withConfig({ componentId: "sc-8xjslt" })({
8585
color: 'black'
8686
});
87-
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton", componentId: "sc-ftk9hu" })({
87+
export const SmallButton = Button.extend({
8888
fontSize: '.7em'
8989
});
90-
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-15rszef" })({
90+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-ad4g7l" })({
9191
fontSize: '.1em'
9292
});
9393

src/createTransformer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ function isStyledFunction(node: ts.Node, identifiers: CustomStyledIdentifiers):
2828
return true;
2929
}
3030

31-
if (node.name.text === 'extend'
31+
if (isStyledExtendIdentifier(node.name.text, identifiers)
3232
&& isValidComponent(node.expression)) {
33-
3433
return true;
3534
}
3635

@@ -97,6 +96,10 @@ function isStyledCreateGlobalStyleIdentifier(name: string, { createGlobalStyle =
9796
return createGlobalStyle.indexOf(name) >= 0;
9897
}
9998

99+
function isStyledExtendIdentifier(name: string, { extend = [] }: CustomStyledIdentifiers) {
100+
return extend.indexOf(name) >= 0;
101+
}
102+
100103
function isMinifyableStyledFunction(node: ts.Node, identifiers: CustomStyledIdentifiers) {
101104
return isStyledFunction(node, identifiers)
102105
|| (
@@ -177,7 +180,7 @@ export function createTransformer({
177180
|| isCallExpression(node.parent)
178181
)
179182
&& node.parent.parent
180-
&& isVariableDeclaration(node.parent.parent)
183+
&& (isVariableDeclaration(node.parent.parent) || isExportAssignment(node.parent.parent))
181184
&& isStyledFunction(node, identifiers)
182185
) {
183186

0 commit comments

Comments
 (0)