@@ -116,27 +116,30 @@ const isEmitter = (module) => {
116
116
return true
117
117
}
118
118
}
119
- const isOptional = ( param ) => {
119
+ const isOptional = ( param , defaultReturn ) => {
120
+ if ( typeof defaultReturn === 'undefined' ) {
121
+ defaultReturn = true
122
+ }
120
123
// Does the description contain the word "optional"?
121
124
if ( / o p t i o n a l / i. test ( param . description ) ) {
122
125
return true
123
126
}
124
127
125
128
// Did we pass a "required"?
126
- if ( param . required ) {
129
+ if ( typeof param . required !== 'undefined' ) {
127
130
return ! param . required
128
131
}
129
132
130
133
// Does the description not contain the word "required"?
131
- if ( param . description && ! / r e q u i r e d / i. test ( param . description ) ) {
134
+ if ( param . description && ! / r e q u i r e d / i. test ( param . description ) && / \( . + \) / . test ( param . description ) ) {
132
135
return true
133
136
}
134
137
135
138
// Let's be optimistic - having optional props marked as required
136
139
// ruins the developer experience, why a false negative is only
137
140
// slightly annoying
138
141
debug ( `Could not determine optionality for ${ param . name } ` )
139
- return true
142
+ return defaultReturn
140
143
}
141
144
142
145
const genMethodString = ( paramInterfaces , module , moduleMethod , parameters , returns , includeType , paramTypePrefix ) => {
@@ -166,7 +169,7 @@ const genMethodString = (paramInterfaces, module, moduleMethod, parameters, retu
166
169
}
167
170
168
171
const name = paramify ( param . name )
169
- const optional = isOptional ( param ) ? '?' : ''
172
+ const optional = isOptional ( param , false ) ? '?' : ''
170
173
171
174
// Figure out this parameter's type
172
175
let type
0 commit comments