@sap/cds-compiler 2.4.4 → 2.10.2

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +241 -1
  2. package/bin/.eslintrc.json +17 -0
  3. package/bin/cds_update_identifiers.js +8 -7
  4. package/bin/cdsc.js +180 -132
  5. package/bin/cdshi.js +18 -11
  6. package/bin/cdsse.js +38 -32
  7. package/bin/cdsv2m.js +8 -7
  8. package/doc/CHANGELOG_BETA.md +36 -1
  9. package/lib/api/main.js +81 -100
  10. package/lib/api/options.js +17 -11
  11. package/lib/api/validate.js +12 -8
  12. package/lib/backends.js +0 -81
  13. package/lib/base/keywords.js +32 -2
  14. package/lib/base/location.js +2 -2
  15. package/lib/base/message-registry.js +66 -4
  16. package/lib/base/messages.js +84 -27
  17. package/lib/base/model.js +2 -61
  18. package/lib/checks/arrayOfs.js +0 -1
  19. package/lib/checks/defaultValues.js +27 -2
  20. package/lib/checks/elements.js +1 -6
  21. package/lib/checks/enricher.js +8 -2
  22. package/lib/checks/foreignKeys.js +0 -6
  23. package/lib/checks/managedWithoutKeys.js +17 -0
  24. package/lib/checks/nonexpandableStructured.js +38 -0
  25. package/lib/checks/onConditions.js +9 -45
  26. package/lib/checks/queryNoDbArtifacts.js +27 -9
  27. package/lib/checks/selectItems.js +25 -2
  28. package/lib/checks/types.js +26 -2
  29. package/lib/checks/unknownMagic.js +38 -0
  30. package/lib/checks/utils.js +61 -0
  31. package/lib/checks/validator.js +66 -13
  32. package/lib/compiler/assert-consistency.js +24 -12
  33. package/lib/compiler/builtins.js +2 -0
  34. package/lib/compiler/checks.js +6 -4
  35. package/lib/compiler/definer.js +101 -39
  36. package/lib/compiler/index.js +88 -59
  37. package/lib/compiler/resolver.js +455 -209
  38. package/lib/compiler/shared.js +57 -33
  39. package/lib/edm/annotations/genericTranslation.js +183 -187
  40. package/lib/edm/csn2edm.js +128 -99
  41. package/lib/edm/edm.js +18 -21
  42. package/lib/edm/edmPreprocessor.js +361 -127
  43. package/lib/edm/edmUtils.js +103 -33
  44. package/lib/gen/Dictionary.json +74 -28
  45. package/lib/gen/language.checksum +1 -1
  46. package/lib/gen/language.interp +18 -4
  47. package/lib/gen/language.tokens +124 -118
  48. package/lib/gen/languageLexer.interp +13 -1
  49. package/lib/gen/languageLexer.js +870 -839
  50. package/lib/gen/languageLexer.tokens +116 -111
  51. package/lib/gen/languageParser.js +5894 -5614
  52. package/lib/json/from-csn.js +152 -67
  53. package/lib/json/to-csn.js +334 -135
  54. package/lib/language/antlrParser.js +4 -3
  55. package/lib/language/errorStrategy.js +1 -0
  56. package/lib/language/genericAntlrParser.js +24 -14
  57. package/lib/language/language.g4 +188 -128
  58. package/lib/main.d.ts +435 -0
  59. package/lib/main.js +31 -7
  60. package/lib/model/api.js +78 -0
  61. package/lib/model/csnRefs.js +463 -187
  62. package/lib/model/csnUtils.js +280 -136
  63. package/lib/model/enrichCsn.js +75 -4
  64. package/lib/model/revealInternalProperties.js +2 -1
  65. package/lib/modelCompare/compare.js +70 -25
  66. package/lib/optionProcessor.js +13 -10
  67. package/lib/render/.eslintrc.json +4 -1
  68. package/lib/render/DuplicateChecker.js +8 -5
  69. package/lib/render/toCdl.js +123 -40
  70. package/lib/render/toHdbcds.js +156 -65
  71. package/lib/render/toSql.js +87 -11
  72. package/lib/render/utils/common.js +55 -9
  73. package/lib/render/utils/sql.js +3 -3
  74. package/lib/sql-identifier.js +6 -1
  75. package/lib/transform/{sql → db}/.eslintrc.json +0 -0
  76. package/lib/transform/{sql → db}/assertUnique.js +7 -8
  77. package/lib/transform/{sql → db}/constraints.js +35 -20
  78. package/lib/transform/db/draft.js +353 -0
  79. package/lib/transform/db/expansion.js +582 -0
  80. package/lib/transform/db/flattening.js +325 -0
  81. package/lib/transform/{sql → db}/groupByOrderBy.js +8 -16
  82. package/lib/transform/{sql → db}/helpers.js +0 -0
  83. package/lib/transform/{sql → db}/transformExists.js +256 -60
  84. package/lib/transform/forHanaNew.js +216 -765
  85. package/lib/transform/forOdataNew.js +60 -56
  86. package/lib/transform/localized.js +48 -26
  87. package/lib/transform/odata/attachPath.js +19 -4
  88. package/lib/transform/odata/expandStructKeysInAssociations.js +2 -2
  89. package/lib/transform/odata/generateForeignKeyElements.js +13 -12
  90. package/lib/transform/odata/referenceFlattener.js +60 -36
  91. package/lib/transform/odata/sortByAssociationDependency.js +4 -4
  92. package/lib/transform/odata/structuralPath.js +76 -0
  93. package/lib/transform/odata/structureFlattener.js +21 -22
  94. package/lib/transform/odata/toFinalBaseType.js +5 -5
  95. package/lib/transform/odata/typesExposure.js +27 -17
  96. package/lib/transform/odata/utils.js +2 -2
  97. package/lib/transform/transformUtilsNew.js +141 -77
  98. package/lib/transform/translateAssocsToJoins.js +17 -14
  99. package/lib/transform/universalCsnEnricher.js +67 -0
  100. package/lib/utils/file.js +0 -11
  101. package/lib/utils/moduleResolve.js +6 -8
  102. package/lib/utils/timetrace.js +6 -1
  103. package/package.json +2 -1
  104. package/lib/base/deepCopy.js +0 -66
  105. package/lib/json/walker.js +0 -26
  106. package/lib/utils/string.js +0 -17
@@ -10,7 +10,7 @@
10
10
 
11
11
  const antlr4 = require('antlr4');
12
12
 
13
- const { makeMessageFunction, CompileMessage } = require('../base/messages');
13
+ const { CompileMessage } = require('../base/messages');
14
14
  const errorStrategy = require('./errorStrategy');
15
15
 
16
16
  const Parser = require('../gen/languageParser').languageParser;
@@ -112,7 +112,7 @@ const rules = {
112
112
  expr: { func: 'conditionEOF', returns: 'cond' }, // yes, condition
113
113
  };
114
114
 
115
- function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl' ) {
115
+ function parse( source, filename = '<undefined>.cds', options = {}, messageFunctions, rule = 'cdl' ) {
116
116
  const lexer = new Lexer( new antlr4.InputStream(source) );
117
117
  const tokenStream = new RewriteTypeTokenStream(lexer);
118
118
  /** @type {object} */
@@ -121,7 +121,7 @@ function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl'
121
121
 
122
122
  parser.filename = filename;
123
123
  parser.options = options;
124
- parser.$message = makeMessageFunction( parser, options, 'parse' ); // sets parser.messages
124
+ parser.$messageFunctions = messageFunctions;
125
125
 
126
126
  initTokenRewrite( parser, tokenStream );
127
127
  // comment the following 2 lines if you want to output the parser errors directly:
@@ -162,6 +162,7 @@ function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl'
162
162
  if (rulespec.$frontend)
163
163
  ast.$frontend = rulespec.$frontend;
164
164
 
165
+ // TODO: clarify with LSP colleagues: still necessary?
165
166
  if (parser.messages) {
166
167
  Object.defineProperty( ast, 'messages',
167
168
  { value: parser.messages, configurable: true, writable: true } );
@@ -245,6 +245,7 @@ function reportIgnoredWith( recognizer, t ) {
245
245
  }
246
246
 
247
247
  function consumeUntil( recognizer, set ) {
248
+ // TODO: add trace
248
249
  if (SEMI == null)
249
250
  SEMI = recognizer.literalNames.indexOf( "';'" );
250
251
  if (RBRACE == null)
@@ -13,6 +13,14 @@ const locUtils = require('../base/location');
13
13
  const { parseDocComment } = require('./docCommentParser');
14
14
  const { functionsWithoutParens, specialFunctions } = require('../compiler/builtins');
15
15
 
16
+
17
+ // Push message `msg` with location `loc` to array of errors:
18
+ function _message( parser, severity, id, loc, ...args ) {
19
+ const msg = parser.$messageFunctions[severity]; // set in antlrParser.js
20
+ return msg( id,
21
+ (loc instanceof antlr4.CommonToken) ? parser.tokenLocation(loc) : loc, ...args );
22
+ }
23
+
16
24
  // Class which is to be used as grammar option with
17
25
  // grammar <name> options { superclass = genericAntlrParser; }
18
26
  //
@@ -34,10 +42,10 @@ function GenericAntlrParser( ...args ) {
34
42
 
35
43
  GenericAntlrParser.prototype = Object.assign(
36
44
  Object.create( antlr4.Parser.prototype ), {
37
- message: function(...args) { return message.call(this, 'message', ...args); },
38
- error: function(...args) { return message.call(this, 'error', ...args); },
39
- warning: function(...args) { return message.call(this, 'warning', ...args); },
40
- info: function(...args) { return message.call(this, 'info', ...args); },
45
+ message: function(...args) { return _message( this, 'message', ...args ); },
46
+ error: function(...args) { return _message( this, 'error', ...args ); },
47
+ warning: function(...args) { return _message( this, 'warning', ...args ); },
48
+ info: function(...args) { return _message( this, 'info', ...args ); },
41
49
  attachLocation,
42
50
  startLocation,
43
51
  tokenLocation,
@@ -69,6 +77,7 @@ GenericAntlrParser.prototype = Object.assign(
69
77
  noAssignmentInSameLine,
70
78
  noSemicolonHere,
71
79
  setLocalToken,
80
+ setLocalTokenIfBefore,
72
81
  excludeExpected,
73
82
  isStraightBefore,
74
83
  meltKeywordToIdentifier,
@@ -110,14 +119,6 @@ const quotedLiteralPatterns = {
110
119
  },
111
120
  };
112
121
 
113
-
114
- // Push message `msg` with location `loc` to array of errors:
115
- function message( severity, id, loc, ...args ) {
116
- const msg = this.$message[severity];
117
- return msg( id, // function $message is set in antlrParser.js
118
- (loc instanceof antlr4.CommonToken) ? this.tokenLocation(loc) : loc, ...args );
119
- }
120
-
121
122
  // Use the following function for language constructs which we (currently)
122
123
  // just being able to parse, in able to run tests from HANA CDS. As soon as we
123
124
  // create ASTs for the language construct and put it into a CSN, a
@@ -183,6 +184,14 @@ function setLocalToken( string, tokenName, notBefore, inSameLine ) {
183
184
  ll1.type = this.constructor[tokenName];
184
185
  }
185
186
 
187
+ function setLocalTokenIfBefore( string, tokenName, before, inSameLine ) {
188
+ const ll1 = this.getCurrentToken();
189
+ if (ll1.text.toUpperCase() === string &&
190
+ (!inSameLine || this._input.LT(-1).line === ll1.line) &&
191
+ (!before || before && before.test( this._input.LT(2).text )))
192
+ ll1.type = this.constructor[tokenName];
193
+ }
194
+
186
195
  // // Special function for rule `requiredSemi` before return $ctx
187
196
  // function braceForSemi() {
188
197
  // if (RBRACE == null)
@@ -305,7 +314,7 @@ function combinedLocation( start, end ) {
305
314
  return locUtils.combinedLocation( start, end );
306
315
  }
307
316
 
308
- function surroundByParens( expr, open, close ) {
317
+ function surroundByParens( expr, open, close, asQuery = false ) {
309
318
  if (!expr)
310
319
  return expr;
311
320
  const location = this.tokenLocation( open, close );
@@ -313,7 +322,7 @@ function surroundByParens( expr, open, close ) {
313
322
  expr.$parens.push( location );
314
323
  else
315
324
  expr.$parens = [ location ];
316
- return expr;
325
+ return (asQuery) ? { query: expr, location } : expr;
317
326
  }
318
327
 
319
328
  function unaryOpForParens( query, val ) {
@@ -362,6 +371,7 @@ function fragileAlias( ast, safe = false ) {
362
371
  else // configurable error
363
372
  this.message( 'syntax-fragile-alias', ast.location, { keyword: 'as' },
364
373
  'Please add the keyword $(KEYWORD) in front of the alias name' );
374
+ return ast;
365
375
  }
366
376
 
367
377
  // Return AST for identifier token `token`. Also check that identifer is not empty.