@@ -177,7 +177,27 @@ class ServiceInstanceFromConstructor extends ServiceInstance {
177
177
}
178
178
179
179
/**
180
- * A read to `this` variable which represents the service whose definition encloses this variable access.
180
+ * A read to `this` variable which represents the service whose definition encloses
181
+ * this variable access.
182
+ * e.g.1. Given this code:
183
+ * ``` javascript
184
+ * const cds = require("@sap/cds");
185
+ * module.exports = class SomeService extends cds.ApplicationService {
186
+ * init() {
187
+ * this.on("SomeEvent", (req) => { ... } )
188
+ * }
189
+ * }
190
+ * ```
191
+ * This class captures the access to the `this` variable as in `this.on(...)`.
192
+ *
193
+ * e.g.2. Given this code:
194
+ * ``` javascript
195
+ * const cds = require('@sap/cds');
196
+ * module.exports = cds.service.impl (function() {
197
+ * this.on("SomeEvent", (req) => { ... })
198
+ * })
199
+ * ```
200
+ * This class captures the access to the `this` variable as in `this.on(...)`.
181
201
*/
182
202
class ServiceInstanceFromThisNode extends ServiceInstance , ThisNode {
183
203
UserDefinedApplicationService userDefinedApplicationService ;
@@ -294,6 +314,17 @@ class DbServiceInstanceFromCdsConnectTo extends ServiceInstanceFromCdsConnectTo,
294
314
override UserDefinedApplicationService getDefinition ( ) { none ( ) }
295
315
}
296
316
317
+ /**
318
+ * The 0-th parameter of an exported closure that represents the service being implemented. e.g.
319
+ * ``` javascript
320
+ * const cds = require('@sap/cds')
321
+ * module.exports = (srv) => {
322
+ * srv.on("SomeEvent1", (req) => { ... })
323
+ * }
324
+ * ```
325
+ * This class captures the `srv` parameter of the exported arrow function. Also see
326
+ * `ServiceInstanceFromImplMethodCallClosureParameter` which is similar to this.
327
+ */
297
328
class ServiceInstanceFromExportedClosureParameter extends ServiceInstance {
298
329
ExportedClosureApplicationServiceDefinition exportedClosure ;
299
330
@@ -302,6 +333,30 @@ class ServiceInstanceFromExportedClosureParameter extends ServiceInstance {
302
333
override UserDefinedApplicationService getDefinition ( ) { result = exportedClosure }
303
334
}
304
335
336
+ /**
337
+ * The 0-th parameter of a callback (usually an arrow function) passed to `cds.service.impl` that
338
+ * represents the service being implemented. e.g.
339
+ * ``` javascript
340
+ * const cds = require('@sap/cds')
341
+ * module.exports = cds.service.impl((srv) => {
342
+ * srv.on("SomeEvent1", (req) => { ... })
343
+ * })
344
+ * ```
345
+ * This class captures the `srv` parameter of the exported arrow function. Also see
346
+ * `ServiceInstanceFromExportedClosureParameter` which is similar to this.
347
+ */
348
+ class ServiceInstanceFromImplMethodCallClosureParameter extends ServiceInstance , ParameterNode {
349
+ ImplMethodCallApplicationServiceDefinition implMethodCallApplicationServiceDefinition ;
350
+
351
+ ServiceInstanceFromImplMethodCallClosureParameter ( ) {
352
+ this = implMethodCallApplicationServiceDefinition .getInitFunction ( ) .getParameter ( 0 )
353
+ }
354
+
355
+ override UserDefinedApplicationService getDefinition ( ) {
356
+ result = implMethodCallApplicationServiceDefinition
357
+ }
358
+ }
359
+
305
360
/**
306
361
* A call to `before`, `on`, or `after` on an `cds.ApplicationService`.
307
362
* It registers an handler to be executed when an event is fired,
@@ -559,7 +614,7 @@ class ES6ApplicationServiceDefinition extends ClassNode, UserDefinedApplicationS
559
614
* })
560
615
* ```
561
616
* This class captures the call `cds.service.impl (function() { ... })`.
562
- *
617
+ *
563
618
* e.g.2. Given this code:
564
619
* ``` javascript
565
620
* const cds = require('@sap/cds')
0 commit comments