@@ -24,7 +24,12 @@ export default function(babel) {
24
24
Program ( path ) {
25
25
path . traverse ( {
26
26
JSXAttribute ( path ) {
27
- const { isVModel, modifiers, valuePath } = parseVModel ( t , path )
27
+ const parsed = parseVModel ( t , path )
28
+ if ( ! parsed ) {
29
+ return
30
+ }
31
+
32
+ const { isVModel, modifiers, valuePath } = parsed
28
33
29
34
if ( isVModel ) {
30
35
const parent = path . parentPath
@@ -46,23 +51,21 @@ export default function(babel) {
46
51
* @returns Object<{ isVModel: boolean, modifiers: Set<string>, valuePath: Path<Expression>}>
47
52
*/
48
53
const parseVModel = ( t , path ) => {
49
- let isVModel = false
54
+ if (
55
+ ( t . isJSXNamespacedName ( path . get ( 'name' ) ) && ! equalCamel ( path . get ( 'name.namespace.name' ) . node , 'v-model' ) ) ||
56
+ ! equalCamel ( path . get ( 'name.name' ) . node , 'v-model' )
57
+ ) {
58
+ return null
59
+ }
50
60
let modifiers = null
51
61
if ( ! t . isJSXExpressionContainer ( path . get ( 'value' ) ) ) {
52
- return { isVModel : false }
53
- } else if ( t . isJSXIdentifier ( path . get ( 'name' ) ) && equalCamel ( path . get ( 'name.name' ) . node , 'v-model' ) ) {
54
- isVModel = true
62
+ throw new Error ( 'You have to use JSX Expression inside your v-model' )
63
+ } else if ( t . isJSXIdentifier ( path . get ( 'name' ) ) ) {
55
64
modifiers = new Set ( )
56
- } else if (
57
- t . isJSXNamespacedName ( path . get ( 'name' ) ) &&
58
- t . isJSXIdentifier ( path . get ( 'name.namespace' ) ) &&
59
- equalCamel ( path . get ( 'name.namespace.name' ) . node , 'v-model' )
60
- ) {
61
- isVModel = true
65
+ } else {
62
66
modifiers = new Set ( path . get ( 'name.name.name' ) . node . split ( '-' ) )
63
67
}
64
68
return {
65
- isVModel,
66
69
modifiers : modifiers ,
67
70
valuePath : isVModel ? path . get ( 'value.expression' ) : null ,
68
71
}
0 commit comments