@@ -8,6 +8,8 @@ import * as postcss from 'postcss';
8
8
import * as LoaderUtils from 'loader-utils' ;
9
9
import generate from 'babel-generator' ;
10
10
import transformVariants , { isVariant } from './transformVariants' ;
11
+ import HTMLTagList from './HTMLTagList' ;
12
+ import * as ComponentRef from './ComponentRef' ;
11
13
12
14
const LOADER = require . resolve ( '../webpack' ) ;
13
15
@@ -53,14 +55,22 @@ function renderToCSS(source: string, _config: RenderConfig): string {
53
55
function renderToJS ( source : string , config : RenderConfig ) : string {
54
56
let root = postcss . parse ( source ) ;
55
57
let statements = [ ] ;
56
- let component = 'div' ;
58
+ let component = types . stringLiteral ( 'div' ) ;
57
59
root . walkRules ( node => {
58
60
if ( isVariant ( node ) ) {
59
61
return ;
60
62
}
61
63
node . walkDecls ( decl => {
62
64
if ( decl . prop === 'base' ) {
63
- component = decl . value ;
65
+ if ( HTMLTagList [ decl . value ] ) {
66
+ component = types . stringLiteral ( decl . value ) ;
67
+ } else {
68
+ let componentRef = ComponentRef . parse ( decl . value ) ;
69
+ component = types . identifier ( node . selector + '__Base' ) ;
70
+ statements . unshift (
71
+ ComponentRef . importDeclaration ( component , decl . value )
72
+ ) ;
73
+ }
64
74
}
65
75
} ) ;
66
76
statements . push ( exportComponent ( node . selector , component , node . selector ) ) ;
@@ -92,7 +102,7 @@ function exportComponent(name: string, component: string, className: string) {
92
102
types . memberExpression (
93
103
types . identifier ( 'React' ) ,
94
104
types . identifier ( 'createElement' ) ) ,
95
- [ types . stringLiteral ( component ) , propsNode ]
105
+ [ component , propsNode ]
96
106
) ;
97
107
let componentNode = types . functionDeclaration (
98
108
types . identifier ( name ) ,
0 commit comments