11import * as t from '@babel/types' ;
22import { NodePath } from '@babel/traverse' ;
33import { createIdentifier } from './utils' ;
4- import { State , ExcludesBoolean } from './' ;
4+ import { State , ExcludesBoolean } from '.' ;
5+
6+ type Tag = t . Identifier | t . MemberExpression | t . StringLiteral | t . CallExpression ;
57
68/**
79 * Get JSX element type
@@ -17,32 +19,31 @@ const getType = (path: NodePath<t.JSXOpeningElement>) => {
1719 }
1820 return t . isJSXIdentifier ( attribute . get ( 'name' ) )
1921 && ( attribute . get ( 'name' ) as NodePath < t . JSXIdentifier > ) . get ( 'name' ) === 'type'
20- && t . isStringLiteral ( attribute . get ( 'value' ) )
21- } ,
22- ) ;
22+ && t . isStringLiteral ( attribute . get ( 'value' ) ) ;
23+ } ) ;
2324
2425 return typePath ? typePath . get ( 'value.value' ) : '' ;
2526} ;
2627
2728const parseModifiers = ( value : t . Expression ) => {
2829 let modifiers : string [ ] = [ ] ;
2930 if ( t . isArrayExpression ( value ) ) {
30- modifiers = ( value as t . ArrayExpression ) . elements . map ( el => t . isStringLiteral ( el ) ? el . value : '' ) . filter ( Boolean )
31+ modifiers = ( value as t . ArrayExpression ) . elements . map ( ( el ) => ( t . isStringLiteral ( el ) ? el . value : '' ) ) . filter ( Boolean ) ;
3132 }
3233 return modifiers ;
33- }
34+ } ;
3435
3536const parseDirectives = ( args : {
3637 name : string ,
3738 path : NodePath < t . JSXAttribute > ,
3839 value : t . StringLiteral | t . Expression | null ,
3940 state : State ,
40- tag : t . Identifier | t . MemberExpression | t . StringLiteral | t . CallExpression ,
41+ tag : Tag ,
4142 isComponent : boolean
4243} ) => {
4344 const {
4445 name, path, value, state, tag, isComponent,
45- } = args
46+ } = args ;
4647 let modifiers : string [ ] = name . split ( '_' ) ;
4748 let arg ;
4849 let val ;
@@ -93,14 +94,19 @@ const parseDirectives = (args: {
9394 } ;
9495} ;
9596
96- const resolveDirective = ( path : NodePath < t . JSXAttribute > , state : State , tag : any , directiveName : string ) => {
97+ const resolveDirective = (
98+ path : NodePath < t . JSXAttribute > ,
99+ state : State ,
100+ tag : Tag ,
101+ directiveName : string ,
102+ ) => {
97103 if ( directiveName === 'show' ) {
98104 return createIdentifier ( state , 'vShow' ) ;
99105 }
100106 if ( directiveName === 'model' ) {
101107 let modelToUse ;
102108 const type = getType ( path . parentPath as NodePath < t . JSXOpeningElement > ) ;
103- switch ( tag . value ) {
109+ switch ( ( tag as t . StringLiteral ) . value ) {
104110 case 'select' :
105111 modelToUse = createIdentifier ( state , 'vModelSelect' ) ;
106112 break ;
0 commit comments