Skip to content

Commit

Permalink
Consistently name aspects in singular as well (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady authored Jul 18, 2024
1 parent 31ee68f commit 32780c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/unit/aspects.test.js
Original file line number Diff line number Diff line change
@@ -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())
})
5 changes: 5 additions & 0 deletions test/unit/files/aspects/model.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace aspect_test;

aspect Persons {}

entity Authors: Persons {}

0 comments on commit 32780c0

Please sign in to comment.