@@ -23,7 +23,8 @@ class ExportedFunctionParser {
2323 BooleanLiteral : 'boolean' ,
2424 NullLiteral : 'any' ,
2525 ObjectExpression : 'object' ,
26- ArrayExpression : 'array'
26+ ArrayExpression : 'array' ,
27+ UnaryExpression : 'number'
2728 } ;
2829 this . validateExpressions = {
2930 ObjectExpression : ( node , stack ) => {
@@ -41,6 +42,19 @@ class ExportedFunctionParser {
4142 } ,
4243 ArrayExpression : ( node , stack ) => {
4344 return node . elements . map ( ( el , i ) => this . validateDefaultParameterExpression ( i , el , stack ) ) ;
45+ } ,
46+ UnaryExpression : ( node , stack ) => {
47+ if ( node . argument . type === 'NumericLiteral' ) {
48+ if ( node . operator === '-' ) {
49+ return - node . argument . value ;
50+ } else if ( node . operator === '+' ) {
51+ return node . argument . value ;
52+ } else {
53+ throw new Error ( `Invalid UnaryExpression` ) ;
54+ }
55+ } else {
56+ throw new Error ( `Invalid UnaryExpression` ) ;
57+ }
4458 }
4559 } ;
4660 }
@@ -50,8 +64,11 @@ class ExportedFunctionParser {
5064 stack = ( stack || [ ] ) . slice ( 0 ) ;
5165 stack . push ( name ) ;
5266
53- if ( ! this . literals [ node . type ] ) {
54- throw new Error ( `(${ stack . join ( '.' ) } ) Expected ${ Object . keys ( this . literals ) . join ( ', ' ) } in Right-Hand of AssignmentPattern` ) ;
67+ let type = node . type ;
68+
69+ if ( ! this . literals [ type ] ) {
70+ console . log ( node ) ;
71+ throw new Error ( `(${ stack . join ( '.' ) } ) Expected ${ Object . keys ( this . literals ) . join ( ', ' ) } in Right-Hand of AssignmentPattern, got ${ type } .` ) ;
5572 }
5673
5774 if ( this . validateExpressions [ node . type ] ) {
@@ -107,7 +124,7 @@ class ExportedFunctionParser {
107124 return expression . right ;
108125 }
109126
110- parseParamsFromFunctionExpression ( functionExpression ) {
127+ parseParamsFromFunctionExpression ( functionExpression , fileString ) {
111128
112129 if ( ! functionExpression ) {
113130 return {
@@ -169,7 +186,15 @@ class ExportedFunctionParser {
169186 if ( ! this . validateFunctionParamName ( param . left . name ) ) {
170187 throw new Error ( `Invalid parameter name "${ param . left . name } "` ) ;
171188 }
172- let defaultValue = this . validateDefaultParameterExpression ( param . left . name , param . right ) ;
189+ let defaultValue ;
190+ try {
191+ defaultValue = this . validateDefaultParameterExpression ( param . left . name , param . right ) ;
192+ } catch ( e ) {
193+ throw new Error ( [
194+ `Invalid default parameter: ${ param . left . name } = ${ fileString . slice ( param . right . start , param . right . end ) } ` ,
195+ `(${ e . message } )`
196+ ] . join ( ' ' ) ) ;
197+ }
173198 formattedParam = {
174199 name : param . left . name ,
175200 type : this . literals [ param . right . type ] ,
@@ -287,7 +312,7 @@ class ExportedFunctionParser {
287312 }
288313
289314 let commentDefinition = this . commentDefinitionParser . parse ( name , comment ) ;
290- let functionDefinition = this . parseParamsFromFunctionExpression ( functionExpression ) ;
315+ let functionDefinition = this . parseParamsFromFunctionExpression ( functionExpression , fileString ) ;
291316
292317 let description = commentDefinition . description || '' ;
293318 let origins = commentDefinition . origins || null ;
0 commit comments