File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed
test/fixtures/19-transpile-require-default Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 11import * as t from 'babel-types'
22
33const importLocalName = ( name , state ) => {
4- const imports = state . file . metadata . modules . imports
5- const styledImports = imports . find ( x => x . source === 'styled-components' )
6- if ( styledImports ) {
7- const specifier = styledImports . specifiers . find ( x => x . imported === name )
8- if ( specifier ) {
9- return specifier . local
4+ let localName = name === 'default' ? 'styled' : name
5+
6+ state . file . path . traverse ( {
7+ ImportDeclaration : {
8+ exit ( path ) {
9+ const { node } = path
10+
11+ if ( node . source . value === 'styled-components' ) {
12+ for ( const specifier of path . get ( 'specifiers' ) ) {
13+ if ( specifier . isImportDefaultSpecifier ( ) ) {
14+ localName = specifier . node . local . name
15+ }
16+
17+ if ( specifier . isImportSpecifier ( ) && specifier . node . imported . name === name ) {
18+ localName = specifier . node . local . name
19+ }
20+
21+ if ( specifier . isImportNamespaceSpecifier ( ) ) {
22+ localName = specifier . node . local . name
23+ }
24+ }
25+ }
26+ }
1027 }
11- }
12- // import not found - return default name
13- return name === 'default' ? 'styled' : name
28+ } )
29+
30+ return localName
1431}
1532
1633export const isStyled = ( tag , state ) => {
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ const styled_default = require("styled-components/no-parser");
33const TestNormal = styled . div . withConfig ( {
44 displayName : "before__TestNormal" ,
55 componentId : "y0c69d-0"
6- } ) ( [ [ "{width: 100%;}" ] ] ) ;
6+ } ) ( [ [ "{width:100%;}" ] ] ) ;
77
88const Test = styled_default . default . div . withConfig ( {
99 displayName : "before__Test" ,
1010 componentId : "y0c69d-1"
11- } ) ( [ [ "{width: 100%;}" ] ] ) ;
11+ } ) ( [ [ "{width:100%;}" ] ] ) ;
1212
1313const TestCallExpression = styled_default . default ( Test ) . withConfig ( {
1414 displayName : "before__TestCallExpression" ,
1515 componentId : "y0c69d-2"
16- } ) ( [ [ "{height: 20px;}" ] ] ) ;
16+ } ) ( [ [ "{height:20px;}" ] ] ) ;
You can’t perform that action at this time.
0 commit comments