@abaplint/core 2.113.82 → 2.113.84

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.
@@ -6,7 +6,8 @@ const expressions_1 = require("../expressions");
6
6
  const version_1 = require("../../../version");
7
7
  class Module {
8
8
  getMatcher() {
9
- const ret = (0, combi_1.seq)("MODULE", expressions_1.FormName, (0, combi_1.opt)((0, combi_1.alt)("INPUT", "OUTPUT", "ON CHAIN-REQUEST")));
9
+ const sw = (0, combi_1.seq)("SWITCH", expressions_1.NamespaceSimpleName);
10
+ const ret = (0, combi_1.seq)("MODULE", expressions_1.FormName, (0, combi_1.opt)((0, combi_1.alt)("INPUT", "OUTPUT", "ON CHAIN-REQUEST", "ON CHAIN-INPUT", sw)));
10
11
  return (0, combi_1.verNot)(version_1.Version.Cloud, ret);
11
12
  }
12
13
  }
@@ -85,10 +85,55 @@ class Select {
85
85
  for (const s of node.findDirectExpressions(Expressions.SQLOrderBy)) {
86
86
  new sql_order_by_1.SQLOrderBy().runSyntax(s, input);
87
87
  }
88
+ if (this.isStrictMode(node)) {
89
+ this.strictModeChecks(node, input);
90
+ }
88
91
  if (input.scope.getType() === _scope_type_1.ScopeType.OpenSQL) {
89
92
  input.scope.pop(node.getLastToken().getEnd());
90
93
  }
91
94
  }
95
+ // there are multiple rules, but gotta start somewhere
96
+ isStrictMode(node) {
97
+ const into = node.findDirectExpressionsMulti([Expressions.SQLIntoList, Expressions.SQLIntoStructure, Expressions.SQLIntoTable])[0];
98
+ const where = node.findDirectExpression(Expressions.SQLCond);
99
+ // INTO is after WHERE
100
+ if (into && where && into.getFirstToken().getStart().isAfter(where.getFirstToken().getStart())) {
101
+ return true;
102
+ }
103
+ // FIELDS is used
104
+ if (node.findFirstExpression(Expressions.SQLFields)) {
105
+ return true;
106
+ }
107
+ // any field is escaped with @
108
+ for (const source of node.findAllExpressions(Expressions.SQLSource)) {
109
+ if (source.getFirstToken().getStr() === "@") {
110
+ return true;
111
+ }
112
+ }
113
+ // comma used in FROM
114
+ const fieldList = node.findFirstExpression(Expressions.SQLFieldList);
115
+ if (fieldList && fieldList.findDirectTokenByText(",")) {
116
+ return true;
117
+ }
118
+ return false;
119
+ }
120
+ strictModeChecks(node, input) {
121
+ const sources = node.findAllExpressions(Expressions.SQLSource);
122
+ for (const source of sources) {
123
+ const first = source.getFirstChild();
124
+ if ((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.SQLAliasField) {
125
+ continue;
126
+ }
127
+ else if ((first === null || first === void 0 ? void 0 : first.getFirstToken().getStr()) === "@") {
128
+ continue;
129
+ }
130
+ else if ((first === null || first === void 0 ? void 0 : first.getChildren()[0].get()) instanceof Expressions.Constant) {
131
+ continue;
132
+ }
133
+ const message = `SELECT: "${source.concatTokens()}" must be escaped with @ in strict mode`;
134
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
135
+ }
136
+ }
92
137
  handleInto(node, input, fields, dbSources) {
93
138
  const intoTable = node.findDirectExpression(Expressions.SQLIntoTable);
94
139
  if (intoTable) {
@@ -5,6 +5,7 @@ const Expressions = require("../../2_statements/expressions");
5
5
  const select_1 = require("../expressions/select");
6
6
  class Select {
7
7
  runSyntax(node, input) {
8
+ // for UNION statements there are multiple select parts
8
9
  const selects = node.findDirectExpressions(Expressions.Select);
9
10
  for (let i = 0; i < selects.length; i++) {
10
11
  const last = i === selects.length - 1;
@@ -67,7 +67,7 @@ class Registry {
67
67
  }
68
68
  static abaplintVersion() {
69
69
  // magic, see build script "version.sh"
70
- return "2.113.82";
70
+ return "2.113.84";
71
71
  }
72
72
  getDDICReferences() {
73
73
  return this.ddicReferences;
@@ -403,6 +403,10 @@ Make sure to test the downported code, it might not always be completely correct
403
403
  if (found) {
404
404
  return found;
405
405
  }
406
+ found = this.downportSQLMoveInto(low, high, lowFile, highSyntax);
407
+ if (found) {
408
+ return found;
409
+ }
406
410
  found = this.downportSQLExtras(low, high, lowFile, highSyntax);
407
411
  if (found) {
408
412
  return found;
@@ -536,6 +540,39 @@ Make sure to test the downported code, it might not always be completely correct
536
540
  return undefined;
537
541
  }
538
542
  //////////////////////////////////////////
543
+ /** move INTO from after WHERE to after FROM */
544
+ downportSQLMoveInto(low, high, lowFile, _highSyntax) {
545
+ var _a;
546
+ if (!(low.get() instanceof _statement_1.Unknown)) {
547
+ return undefined;
548
+ }
549
+ // note: SQLCond is also used in JOIN(FROM) conditions
550
+ const where = (_a = high.findFirstExpression(Expressions.Select)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.SQLCond);
551
+ if (where === undefined) {
552
+ return undefined;
553
+ }
554
+ let into = high.findFirstExpression(Expressions.SQLIntoList);
555
+ if (into === undefined) {
556
+ into = high.findFirstExpression(Expressions.SQLIntoStructure);
557
+ }
558
+ if (into === undefined) {
559
+ into = high.findFirstExpression(Expressions.SQLIntoTable);
560
+ }
561
+ if (into === undefined) {
562
+ return undefined;
563
+ }
564
+ if (where.getLastToken().getEnd().isBefore(into.getFirstToken().getStart()) === false) {
565
+ return undefined;
566
+ }
567
+ const from = high.findFirstExpression(Expressions.SQLFrom);
568
+ if (from === undefined) {
569
+ return undefined;
570
+ }
571
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, from.getLastToken().getEnd(), ` ` + into.concatTokens());
572
+ const fix2 = edit_helper_1.EditHelper.deleteRange(lowFile, into.getFirstToken().getStart(), into.getLastToken().getEnd());
573
+ const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
574
+ return issue_1.Issue.atToken(lowFile, low.getFirstToken(), "SQL, move INTO", this.getMetadata().key, this.conf.severity, fix);
575
+ }
539
576
  /** removes @'s and commas */
540
577
  downportSQLExtras(low, high, lowFile, highSyntax) {
541
578
  if (!(low.get() instanceof _statement_1.Unknown)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.113.82",
3
+ "version": "2.113.84",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",