UNPKG

@sap/cds-compiler

Version:

CDS (Core Data Services) compiler and backends

35 lines (31 loc) 1.24 kB
'use strict'; // Only to be used with validator.js - a correct this value needs to be provided! /** * OData allows simple values only (val, -val, enum), no expressions or functions * Leave the default value check to the Database. * E.g. HANA allows functions on columns but only simple values on parameter definitions * * @param {CSN.Element} member Member to validate * @param {string} memberName Name of the member * @param {string} prop Property being looped over * @param {CSN.Path} path Path to the member */ function validateDefaultValues( member, memberName, prop, path ) { if (member.default && this.options.toOdata) { // unary minus is xpr: [ "-", { val: ... } ] if (member.default.xpr) { let i = 0; // consume all unary signs while (member.default.xpr[i] === '-' || member.default.xpr[i] === '+') i++; // TODO: This check only counts the number of leading signs, not inbetween (e.g. 1 - - 1). // The message also needs to be improved. if (i > 1) // eslint-disable-next-line cds-compiler/message-no-quotes this.error(null, path, {}, 'Illegal number of unary \'+\'/\'-\' operators'); } } } module.exports = { validateDefaultValues, };