1+ import getSequenceExpressionValue from './getSequenceExpressionValue'
12import { useTopLevelImportPathMatchers } from './options'
23
34const VALID_TOP_LEVEL_IMPORT_PATH_MATCHERS = [
@@ -81,6 +82,15 @@ export const isStyled = t => (tag, state) => {
8182 ) {
8283 // styled.something()
8384 return isStyled ( t ) ( tag . callee . object , state )
85+ } else if (
86+ t . isCallExpression ( tag ) &&
87+ t . isSequenceExpression ( tag . callee ) &&
88+ t . isMemberExpression ( getSequenceExpressionValue ( tag . callee ) ) &&
89+ getSequenceExpressionValue ( tag . callee ) . property . name !==
90+ 'default' /** ignore default for #93 below */
91+ ) {
92+ // (..., styled).something()
93+ return isStyled ( t ) ( getSequenceExpressionValue ( tag . callee ) , state )
8494 } else {
8595 return (
8696 ( t . isMemberExpression ( tag ) &&
@@ -94,6 +104,12 @@ export const isStyled = t => (tag, state) => {
94104 importLocalName ( 'default' , state , {
95105 cacheIdentifier : tag . callee . name ,
96106 } ) ) ||
107+ ( t . isCallExpression ( tag ) &&
108+ t . isSequenceExpression ( tag . callee ) &&
109+ getSequenceExpressionValue ( tag . callee ) . name ===
110+ importLocalName ( 'default' , state , {
111+ cacheIdentifier : getSequenceExpressionValue ( tag . callee ) . name ,
112+ } ) ) ||
97113 /**
98114 * #93 Support require()
99115 * styled-components might be imported using a require()
@@ -111,6 +127,13 @@ export const isStyled = t => (tag, state) => {
111127 t . isMemberExpression ( tag . callee ) &&
112128 tag . callee . property . name === 'default' &&
113129 tag . callee . object . name === state . styledRequired ) ||
130+ ( state . styledRequired &&
131+ t . isCallExpression ( tag ) &&
132+ t . isSequenceExpression ( tag . callee ) &&
133+ t . isMemberExpression ( getSequenceExpressionValue ( tag . callee ) ) &&
134+ getSequenceExpressionValue ( tag . callee ) . property . name === 'default' &&
135+ getSequenceExpressionValue ( tag . callee ) . object . name ===
136+ state . styledRequired ) ||
114137 ( importLocalName ( 'default' , state ) &&
115138 t . isMemberExpression ( tag ) &&
116139 t . isMemberExpression ( tag . object ) &&
0 commit comments