@@ -40,12 +40,15 @@ const mapNativeType = (/** @type {string} */ nativeType) => {
40
40
* @param {SourceCode } sourceCode
41
41
*/
42
42
function getComponentPropData ( prop , sourceCode ) {
43
+ if ( prop . propName === null ) {
44
+ throw new Error ( 'Unexpected prop with null name.' )
45
+ }
43
46
if ( prop . type !== 'object' ) {
44
47
throw new Error ( `Unexpected prop type: ${ prop . type } .` )
45
48
}
46
49
const type = optionGetType ( prop . value , sourceCode )
47
50
if ( type === null ) {
48
- throw new Error ( `Unexpected prop type: ${ prop . type } . ` )
51
+ throw new Error ( `Unable to read prop type` )
49
52
}
50
53
const required = optionGetRequired ( prop . value )
51
54
const defaultValue = optionGetDefault ( prop . value )
@@ -69,33 +72,10 @@ function optionGetType(node, sourceCode) {
69
72
return mapNativeType ( node . name )
70
73
}
71
74
case 'ObjectExpression' : {
72
- // foo: {
73
75
const typeProperty = utils . findProperty ( node , 'type' )
74
76
if ( typeProperty == null ) {
75
77
return null
76
78
}
77
- if ( typeProperty . value . type === 'TSAsExpression' ) {
78
- const typeAnnotation = typeProperty . value . typeAnnotation
79
- if ( typeAnnotation . typeName . name !== 'PropType' ) {
80
- return null
81
- }
82
-
83
- // in some project configuration parser populates deprecated field `typeParameters` instead of `typeArguments`
84
- const typeArguments =
85
- 'typeArguments' in typeProperty . value
86
- ? typeAnnotation . typeArguments
87
- : typeAnnotation . typeParameters
88
-
89
- const typeArgument = Array . isArray ( typeArguments )
90
- ? typeArguments [ 0 ] . params [ 0 ]
91
- : typeArguments . params [ 0 ]
92
-
93
- if ( typeArgument === undefined ) {
94
- return null
95
- }
96
-
97
- return sourceCode . getText ( typeArgument )
98
- }
99
79
return optionGetType ( typeProperty . value , sourceCode )
100
80
}
101
81
case 'ArrayExpression' : {
@@ -111,6 +91,29 @@ function optionGetType(node, sourceCode) {
111
91
. filter ( Boolean )
112
92
. join ( ' | ' )
113
93
}
94
+ case 'TSAsExpression' : {
95
+ const typeAnnotation = node . typeAnnotation
96
+ if ( typeAnnotation . typeName . name !== 'PropType' ) {
97
+ return null
98
+ }
99
+
100
+ // in some project configuration parser populates deprecated field `typeParameters` instead of `typeArguments`
101
+ const typeArguments =
102
+ 'typeArguments' in node
103
+ ? typeAnnotation . typeArguments
104
+ : typeAnnotation . typeParameters
105
+
106
+ const typeArgument = Array . isArray ( typeArguments )
107
+ ? typeArguments [ 0 ] . params [ 0 ]
108
+ : typeArguments . params [ 0 ]
109
+
110
+ if ( typeArgument === undefined ) {
111
+ return null
112
+ }
113
+
114
+ return sourceCode . getText ( typeArgument )
115
+ }
116
+
114
117
case 'FunctionExpression' :
115
118
case 'ArrowFunctionExpression' : {
116
119
return null
0 commit comments