generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap unusual identifiers in quotes (#134)
* Wrap unusual identifiers in quotes * Add changelog entry * Handle empty identifiers and add test stubs * Add test case * Lint * Bump version to 0.15.0 * Fix identifier regex
- Loading branch information
Showing
10 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const isValidIdent = /^[_$a-zA-Z][$\w]*$/ | ||
|
||
/** | ||
* Normalises an identifier to a valid JavaScript identifier. | ||
* I.e. either the identifier itself or a quoted string. | ||
* @param {string} ident the identifier to normalise | ||
* @returns {string} the normalised identifier | ||
*/ | ||
const normalise = ident => ident && !isValidIdent.test(ident) | ||
? `"${ident}"` | ||
: ident | ||
|
||
module.exports = { | ||
normalise | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const fs = require('fs').promises | ||
const path = require('path') | ||
const cds2ts = require('../../lib/compile') | ||
const { ASTWrapper } = require('../ast') | ||
const { locations } = require('../util') | ||
|
||
const dir = locations.testOutput('enums_test') | ||
|
||
describe('Delimited Identifiers', () => { | ||
let astw | ||
|
||
beforeEach(async () => await fs.unlink(dir).catch(() => {})) | ||
beforeAll(async () => { | ||
const paths = await cds2ts | ||
.compileFromFile(locations.unit.files('delimident/model.cds'), { outputDirectory: dir, inlineDeclarations: 'structured' }) | ||
astw = new ASTWrapper(path.join(paths[1], 'index.ts')) | ||
}) | ||
|
||
test('Properties in Aspect Present', () => { | ||
expect(astw.getAspectProperty('_FooAspect', 'sap-icon://a')).toBeTruthy() | ||
const nested = astw.getAspectProperty('_FooAspect', 'sap-icon://b') | ||
expect(nested).toBeTruthy() | ||
expect(nested.type.subtypes[0].members[0].name).toBe('sap-icon://c') | ||
const actions = astw.getAspectProperty('_FooAspect', 'actions') | ||
expect(actions.type.members.find(fn => fn.name === 'sap-icon://f')).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace delimited_identifiers_test; | ||
|
||
entity Foo { | ||
![sap-icon://a]: String; | ||
![sap-icon://b]: { | ||
![sap-icon://c]: String; | ||
}; | ||
c: String enum { | ||
![sap-icon://d] | ||
}; | ||
} actions { | ||
action ![sap-icon://f]() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters