@@ -19,6 +19,7 @@ import { minifyTemplate } from './minify';
1919 * styled.tag
2020 * Component.extend
2121 * styled(Component)
22+ * styled('tag')
2223 * styledFunction.attrs(attributes)
2324*/
2425function isStyledFunction ( node : ts . Node , identifiers : CustomStyledIdentifiers ) : boolean {
@@ -84,6 +85,30 @@ function isStyledAttrs(node: ts.Node, identifiers: CustomStyledIdentifiers) {
8485 && isStyledFunction ( ( node as ts . PropertyAccessExpression ) . expression , identifiers ) ;
8586}
8687
88+ function isStyledKeyframesIdentifier ( name : string , { keyframes = [ 'keyframes' ] } : CustomStyledIdentifiers ) {
89+ return keyframes . indexOf ( name ) >= 0 ;
90+ }
91+
92+ function isStyledCssIdentifier ( name : string , { css = [ 'css' ] } : CustomStyledIdentifiers ) {
93+ return css . indexOf ( name ) >= 0 ;
94+ }
95+
96+ function isStyledCreateGlobalStyleIdentifier ( name : string , { createGlobalStyle = [ 'createGlobalStyle' ] } : CustomStyledIdentifiers ) {
97+ return createGlobalStyle . indexOf ( name ) >= 0 ;
98+ }
99+
100+ function isMinifyableStyledFunction ( node : ts . Node , identifiers : CustomStyledIdentifiers ) {
101+ return isStyledFunction ( node , identifiers )
102+ || (
103+ isIdentifier ( node )
104+ && (
105+ isStyledKeyframesIdentifier ( node . text , identifiers )
106+ || isStyledCssIdentifier ( node . text , identifiers )
107+ || isStyledCreateGlobalStyleIdentifier ( node . text , identifiers )
108+ )
109+ ) ;
110+ }
111+
87112function defaultGetDisplayName ( filename : string , bindingName : string | undefined ) : string | undefined {
88113 return bindingName ;
89114}
@@ -135,7 +160,7 @@ export function createTransformer({
135160 if (
136161 minify
137162 && isTaggedTemplateExpression ( node )
138- && isStyledFunction ( node . tag , identifiers )
163+ && isMinifyableStyledFunction ( node . tag , identifiers )
139164 ) {
140165 const minifiedTemplate = minifyTemplate ( node . template ) ;
141166 if ( minifiedTemplate && minifiedTemplate !== node . template ) {
0 commit comments