@@ -177,7 +177,27 @@ class ServiceInstanceFromConstructor extends ServiceInstance {
177177}
178178
179179/**
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(...)`.
181201 */
182202class ServiceInstanceFromThisNode extends ServiceInstance , ThisNode {
183203 UserDefinedApplicationService userDefinedApplicationService ;
@@ -294,6 +314,17 @@ class DbServiceInstanceFromCdsConnectTo extends ServiceInstanceFromCdsConnectTo,
294314 override UserDefinedApplicationService getDefinition ( ) { none ( ) }
295315}
296316
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+ */
297328class ServiceInstanceFromExportedClosureParameter extends ServiceInstance {
298329 ExportedClosureApplicationServiceDefinition exportedClosure ;
299330
@@ -302,6 +333,30 @@ class ServiceInstanceFromExportedClosureParameter extends ServiceInstance {
302333 override UserDefinedApplicationService getDefinition ( ) { result = exportedClosure }
303334}
304335
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+
305360/**
306361 * A call to `before`, `on`, or `after` on an `cds.ApplicationService`.
307362 * It registers an handler to be executed when an event is fired,
@@ -559,7 +614,7 @@ class ES6ApplicationServiceDefinition extends ClassNode, UserDefinedApplicationS
559614 * })
560615 * ```
561616 * This class captures the call `cds.service.impl (function() { ... })`.
562- *
617+ *
563618 * e.g.2. Given this code:
564619 * ``` javascript
565620 * const cds = require('@sap/cds')
0 commit comments