@@ -4,10 +4,11 @@ const debug = require('../lib/debug');
4
4
const BaseResolver = require ( './base' ) ;
5
5
6
6
const {
7
- ObjectItem,
8
7
AnnotationItem,
9
8
ConstructItem,
9
+ ObjectItem,
10
10
FuncItem,
11
+ PropItem,
11
12
12
13
GrammerVar,
13
14
GrammerCall,
@@ -51,6 +52,7 @@ class ClientResolver extends BaseResolver {
51
52
constructor ( astNode , combinator , globalAst ) {
52
53
super ( astNode , combinator , globalAst ) ;
53
54
this . object = new ObjectItem ( 'client' ) ;
55
+ this . currThrows = { } ;
54
56
}
55
57
56
58
resolve ( ) {
@@ -117,11 +119,53 @@ class ClientResolver extends BaseResolver {
117
119
return object ;
118
120
}
119
121
122
+ resolveProps ( ast ) {
123
+ this . comments = ast . comments ;
124
+
125
+ ast . moduleBody . nodes . filter ( ( item ) => {
126
+ return item . type === 'type' ;
127
+ } ) . forEach ( item => {
128
+ const prop = new PropItem ( ) ;
129
+ prop . name = item . vid . lexeme . replace ( '@' , '_' ) ;
130
+ const type = item . value . lexeme ? item . value . lexeme : item . value . type ;
131
+ prop . type = type ;
132
+ if ( type === 'array' ) {
133
+ prop . itemType = item . value . subType ;
134
+ if ( ! _isBasicType ( item . value . subType . lexeme ) ) {
135
+ this . combinator . addModelInclude ( item . value . subType . lexeme ) ;
136
+ }
137
+ } else {
138
+ if ( ! _isBasicType ( type ) ) {
139
+ if ( item . value . idType && item . value . idType === 'module' ) {
140
+ this . combinator . addInclude ( type ) ;
141
+ } else if ( item . value && item . value . returnType ) {
142
+ if ( ! _isBasicType ( item . value . returnType . lexeme ) ) {
143
+ this . combinator . addModelInclude ( type ) ;
144
+ }
145
+ } else {
146
+ debug . stack ( item ) ;
147
+ }
148
+ }
149
+ }
150
+ prop . addModify ( Modify . protected ( ) ) ;
151
+ if ( item . tokenRange ) {
152
+ let comments = this . getFrontComments ( item . tokenRange [ 0 ] ) ;
153
+ if ( comments . length > 0 ) {
154
+ comments . forEach ( c => {
155
+ this . object . addBodyNode ( this . resolveAnnotation ( c , this . object . index ) ) ;
156
+ } ) ;
157
+ }
158
+ }
159
+ this . object . addBodyNode ( prop ) ;
160
+ } ) ;
161
+ }
162
+
120
163
resolveInitBody ( init ) {
121
164
const object = this . object ;
122
165
const combinator = this . combinator ;
123
166
124
167
let constructNode = new ConstructItem ( ) ;
168
+ this . currThrows = { } ;
125
169
if ( init . params && init . params . params ) {
126
170
init . params . params . forEach ( param => {
127
171
if ( param . paramType . idType && param . paramType . idType === 'model' ) {
@@ -140,10 +184,14 @@ class ClientResolver extends BaseResolver {
140
184
this . visitStmt ( constructNode , stmt , constructNode . index ) ;
141
185
} ) ;
142
186
}
187
+ if ( Object . keys ( this . currThrows ) . length > 0 ) {
188
+ constructNode . throws = Object . values ( this . currThrows ) ;
189
+ }
143
190
object . addBodyNode ( constructNode ) ;
144
191
}
145
192
146
193
resolveFunc ( func , ast , body ) {
194
+ this . currThrows = { } ;
147
195
if ( ast . annotation ) {
148
196
func . addAnnotation ( this . resolveAnnotation ( ast . annotation , func . index ) ) ;
149
197
}
@@ -248,6 +296,9 @@ class ClientResolver extends BaseResolver {
248
296
this . findComments ( func , body , 'between' ) ;
249
297
}
250
298
299
+ if ( Object . keys ( this . currThrows ) . length > 0 ) {
300
+ func . throws = Object . values ( this . currThrows ) ;
301
+ }
251
302
this . object . addBodyNode ( func ) ;
252
303
}
253
304
@@ -384,6 +435,7 @@ class ClientResolver extends BaseResolver {
384
435
] ) ,
385
436
new GrammerThrows ( null , [ exceptionParam ] )
386
437
] , catchException ) ;
438
+ this . currThrows [ Exceptions . base ( ) ] = Exceptions . base ( ) ;
387
439
this . requestBody ( ast , body , requestTryCatch ) ;
388
440
requestTryCatch . addCatch ( tryCatch ) ;
389
441
@@ -399,6 +451,7 @@ class ClientResolver extends BaseResolver {
399
451
]
400
452
)
401
453
) ;
454
+ this . currThrows [ '$ExceptionUnretryable' ] = this . combinator . addInclude ( '$ExceptionUnretryable' ) ;
402
455
}
403
456
404
457
requestBody ( ast , body , func ) {
@@ -789,6 +842,7 @@ class ClientResolver extends BaseResolver {
789
842
node . expr = new BehaviorToModel ( node . expr , stmt . expectedType . name ) ;
790
843
}
791
844
} else if ( stmt . type === 'throw' ) {
845
+ this . currThrows [ '$Exception' ] = this . combinator . addInclude ( '$Exception' ) ;
792
846
node = new GrammerThrows ( this . combinator . addInclude ( '$Exception' ) ) ;
793
847
if ( Array . isArray ( stmt . expr ) ) {
794
848
stmt . expr . forEach ( e => {
0 commit comments