diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed4d982..597f429f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## Version 0.24.0 - TBD ### Fixed - Suppressed an error that would incorrectly point out naming clashes when an entity was named in singular inflection in the model +- CDS aspects now also generate a aspect-function in singular inflection, similar to how entities do ### Changed - Aspects generate named classes again so that tooltips will show more meaningful provenance for properties diff --git a/lib/visitor.js b/lib/visitor.js index 1c01f999..97a66332 100644 --- a/lib/visitor.js +++ b/lib/visitor.js @@ -374,14 +374,14 @@ class Visitor { #printAspect(fq, aspect) { LOG.debug(`Printing aspect ${fq}`) - const { namespace, entityName } = this.entityRepository.getByFq(fq) + const { namespace, entityName, inflection } = this.entityRepository.getByFq(fq) const file = this.fileRepository.getNamespaceFile(namespace) // aspects are technically classes and can therefore be added to the list of defined classes. // Still, when using them as mixins for a class, they need to already be defined. // So we separate them into another buffer which is printed before the classes. file.addClass(entityName, fq) file.aspects.add(`// the following represents the CDS aspect '${entityName}'`) - this.#aspectify(fq, aspect, file.aspects, { cleanName: entityName }) + this.#aspectify(fq, aspect, file.aspects, { cleanName: inflection.singular }) } #printEvent(fq, event) { diff --git a/test/unit/aspects.test.js b/test/unit/aspects.test.js new file mode 100644 index 00000000..95a55659 --- /dev/null +++ b/test/unit/aspects.test.js @@ -0,0 +1,13 @@ +'use strict' + +const { beforeAll, describe, test, expect } = require('@jest/globals') +const { locations, prepareUnitTest } = require('../util') + +// FIXME: missing: inline enums (entity Foo { bar: String enum { ... }}) +describe('CDS Aspects', () => { + let astw + + beforeAll(async () => astw = (await prepareUnitTest('aspects/model.cds', locations.testOutput('aspect_test'))).astw) + + test('Aspect in Singular Form', () => expect(astw.tree.find(n => n.name === '_PersonAspect')).toBeTruthy()) +}) \ No newline at end of file diff --git a/test/unit/files/aspects/model.cds b/test/unit/files/aspects/model.cds new file mode 100644 index 00000000..de15d508 --- /dev/null +++ b/test/unit/files/aspects/model.cds @@ -0,0 +1,5 @@ +namespace aspect_test; + +aspect Persons {} + +entity Authors: Persons {} \ No newline at end of file