Skip to content

Remove deprecated .extend transformation pattern #370

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

Merged
merged 8 commits into from
Apr 2, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

- transform anonymous default exports (fix #371 in #367)
- remove deprecated .extend transformation pattern (fix #48 in #370)

## [1.4.4]

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/baselines/base/issue33.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TypeScript after transform:
declare const jQuery: any;
declare const _: any;
declare const Button: any;
const Button1 = Button.extend.withConfig({ displayName: "Button1" }) \` color: red \`;
const Button1 = Button.extend \` color: red \`;
const Button2 = $.extend \` color: red \`;
const Button3 = jQuery.extend \` color: red \`;
const Button4 = _.extend \` color: red \`;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/baselines/base/sample1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ TypeScript after transform:
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton" }) \`
color: blue;
\`;
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton" }) \`
const SuperButton = Button.extend \`
color: super;
\`;
export default styled.link \`
color: black;
\`;
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton" }) \`
export const SmallButton = Button.extend \`
font-size: .7em;
\`;
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton" }) \`
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/baselines/base/style-objects.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ TypeScript after transform:
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton" })({
color: 'blue'
});
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton" })({
const SuperButton = Button.extend({
color: 'super'
});
export default styled.link({
color: 'black'
});
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton" })({
export const SmallButton = Button.extend({
fontSize: '.7em'
});
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton" })({
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/baselines/ssr/issue33.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TypeScript after transform:
declare const jQuery: any;
declare const _: any;
declare const Button: any;
const Button1 = Button.extend.withConfig({ displayName: "Button1", componentId: "sc-1iinolv" }) \` color: red \`;
const Button1 = Button.extend \` color: red \`;
const Button2 = $.extend \` color: red \`;
const Button3 = jQuery.extend \` color: red \`;
const Button4 = _.extend \` color: red \`;
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/baselines/ssr/sample1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ TypeScript after transform:
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton", componentId: "sc-ce0fkl" }) \`
color: blue;
\`;
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton", componentId: "sc-10xv1bi" }) \`
const SuperButton = Button.extend \`
color: super;
\`;
export default styled.link.withConfig({ componentId: "sc-iechwg" }) \`
export default styled.link.withConfig({ componentId: "sc-vba0dl" }) \`
color: black;
\`;
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton", componentId: "sc-3ane8u" }) \`
export const SmallButton = Button.extend \`
font-size: .7em;
\`;
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-12a48t6" }) \`
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-ndnumj" }) \`
font-size: .1em;
\`;

Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/baselines/ssr/style-objects.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ TypeScript after transform:
const OtherButton = styled(Button).withConfig({ displayName: "OtherButton", componentId: "sc-14ah7t" })({
color: 'blue'
});
const SuperButton = Button.extend.withConfig({ displayName: "SuperButton", componentId: "sc-1t5v351" })({
const SuperButton = Button.extend({
color: 'super'
});
export default styled.link.withConfig({ componentId: "sc-115bov" })({
export default styled.link.withConfig({ componentId: "sc-8xjslt" })({
color: 'black'
});
export const SmallButton = Button.extend.withConfig({ displayName: "SmallButton", componentId: "sc-blt0bk" })({
export const SmallButton = Button.extend({
fontSize: '.7em'
});
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-96ogu9" })({
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "MiniButton", componentId: "sc-ad4g7l" })({
fontSize: '.1em'
});

Expand Down
7 changes: 5 additions & 2 deletions src/createTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ function isStyledFunction(node: ts.Node, identifiers: CustomStyledIdentifiers):
return true;
}

if (node.name.text === 'extend'
if (isStyledExtendIdentifier(node.name.text, identifiers)
&& isValidComponent(node.expression)) {

return true;
}

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

function isStyledExtendIdentifier(name: string, { extend = [] }: CustomStyledIdentifiers) {
return extend.indexOf(name) >= 0;
}

function isMinifyableStyledFunction(node: ts.Node, identifiers: CustomStyledIdentifiers) {
return isStyledFunction(node, identifiers)
|| (
Expand Down
7 changes: 7 additions & 0 deletions src/models/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ export interface CustomStyledIdentifiers {
* @defaultValue `['createGlobalStyle']`
*/
createGlobalStyle?: string[];

/**
* Identifiers of `extend` function.
*
* @defaultValue `[]`
*/
extend?: string[];
}