@cap-js/cds-typer 0.33.0 → 0.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/enum.js +5 -1
- package/lib/file.js +1 -1
- package/lib/printers/javascript.js +12 -5
- package/package.json +2 -3
package/lib/components/enum.js
CHANGED
|
@@ -122,9 +122,13 @@ const isInlineEnumType = (element, csn) => element.enum
|
|
|
122
122
|
* ```
|
|
123
123
|
* @param {string} name - the enum name
|
|
124
124
|
* @param {[string, string][]} kvs - a list of key-value pairs. Values that are falsey are replaced by
|
|
125
|
+
* @param {import('../printers/javascript').Printer} jsp - the printer to use
|
|
125
126
|
*/
|
|
126
127
|
// ??= for inline enums. If there is some static property of that name, we don't want to override it (for example: ".actions"
|
|
127
|
-
const stringifyEnumImplementation = (name, kvs
|
|
128
|
+
const stringifyEnumImplementation = (name, kvs, jsp) => jsp.printExport(
|
|
129
|
+
name,
|
|
130
|
+
`{ ${kvs.map(([k,v]) => `${normalise(k)}: ${v}`).join(', ')} }`,
|
|
131
|
+
{ coalesce: true })
|
|
128
132
|
|
|
129
133
|
|
|
130
134
|
module.exports = {
|
package/lib/file.js
CHANGED
|
@@ -577,7 +577,7 @@ class SourceFile extends File {
|
|
|
577
577
|
.concat(jsp.printSingleLineComment('actions'))
|
|
578
578
|
.concat(this.operations.names.map(name => jsp.printExport(name, stringIdent(name))))
|
|
579
579
|
.concat(jsp.printSingleLineComment('enums'))
|
|
580
|
-
.concat(this.enums.data.map(({name, kvs}) => stringifyEnumImplementation(name, kvs)))
|
|
580
|
+
.concat(this.enums.data.map(({name, kvs}) => stringifyEnumImplementation(name, kvs, jsp)))
|
|
581
581
|
.join('\n') + '\n'
|
|
582
582
|
}
|
|
583
583
|
}
|
|
@@ -48,10 +48,11 @@ class JavaScriptPrinter {
|
|
|
48
48
|
* @abstract
|
|
49
49
|
* @param {string} name - name the export should be known as
|
|
50
50
|
* @param {string} value - the value of the export
|
|
51
|
+
* @param {{coalesce?: boolean}} [options] - additional options
|
|
51
52
|
* @returns {string}
|
|
52
53
|
*/
|
|
53
54
|
// eslint-disable-next-line no-unused-vars
|
|
54
|
-
printExport (name, value) {
|
|
55
|
+
printExport (name, value, options = {}) {
|
|
55
56
|
throw Error('not implemented')
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -88,9 +89,12 @@ class ESMPrinter extends JavaScriptPrinter {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/** @type {JavaScriptPrinter['printExport']} */
|
|
91
|
-
printExport (name, value) {
|
|
92
|
+
printExport (name, value, options) {
|
|
93
|
+
const op = options?.coalesce
|
|
94
|
+
? '??='
|
|
95
|
+
: '='
|
|
92
96
|
return name.includes('.')
|
|
93
|
-
? `${name}
|
|
97
|
+
? `${name} ${op} ${value}`
|
|
94
98
|
: `export const ${name} = ${value}`
|
|
95
99
|
}
|
|
96
100
|
|
|
@@ -117,8 +121,11 @@ class CJSPrinter extends JavaScriptPrinter {
|
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
/** @type {JavaScriptPrinter['printExport']} */
|
|
120
|
-
printExport (name, value) {
|
|
121
|
-
|
|
124
|
+
printExport (name, value, options) {
|
|
125
|
+
const op = options?.coalesce
|
|
126
|
+
? '??='
|
|
127
|
+
: '='
|
|
128
|
+
return `module.exports.${name} ${op} ${value}`
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
/** @type {JavaScriptPrinter['printDefaultExport']} */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/cds-typer",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "Generates .ts files for a CDS model to receive code completion in VS Code",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "github:cap-js/cds-typer",
|
|
@@ -46,11 +46,10 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@cap-js/cds-types": "^0",
|
|
48
48
|
"@sap/cds": "^8",
|
|
49
|
-
"@stylistic/eslint-plugin-js": "^
|
|
49
|
+
"@stylistic/eslint-plugin-js": "^4.2.0",
|
|
50
50
|
"acorn": "^8.10.0",
|
|
51
51
|
"eslint": "^9",
|
|
52
52
|
"eslint-plugin-jsdoc": "^50.2.2",
|
|
53
|
-
"globals": "^15.0.0",
|
|
54
53
|
"typescript": ">=4.6.4"
|
|
55
54
|
},
|
|
56
55
|
"cds": {
|