@abaplint/core 2.85.16 → 2.85.17

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.
@@ -4547,6 +4547,7 @@ export declare enum ScopeType {
4547
4547
  Method = "method",
4548
4548
  MethodInstance = "method_instance",
4549
4549
  For = "for",
4550
+ Let = "let",
4550
4551
  OpenSQL = "open_sql"
4551
4552
  }
4552
4553
 
@@ -887,14 +887,14 @@ BuiltIn.methods = [
887
887
  {
888
888
  name: "STRLEN",
889
889
  mandatory: {
890
- "val": new basic_1.StringType(),
890
+ "val": new basic_1.CLikeType(),
891
891
  },
892
892
  return: new basic_1.IntegerType(),
893
893
  },
894
894
  {
895
895
  name: "SUBSTRING",
896
896
  mandatory: {
897
- "val": new basic_1.StringType(),
897
+ "val": new basic_1.CLikeType(),
898
898
  },
899
899
  optional: {
900
900
  "off": new basic_1.IntegerType(),
@@ -906,7 +906,7 @@ BuiltIn.methods = [
906
906
  {
907
907
  name: "SUBSTRING_AFTER",
908
908
  mandatory: {
909
- "val": new basic_1.StringType(),
909
+ "val": new basic_1.CLikeType(),
910
910
  },
911
911
  optional: {
912
912
  "sub": new basic_1.StringType(),
@@ -922,7 +922,7 @@ BuiltIn.methods = [
922
922
  {
923
923
  name: "SUBSTRING_BEFORE",
924
924
  mandatory: {
925
- "val": new basic_1.StringType(),
925
+ "val": new basic_1.CLikeType(),
926
926
  },
927
927
  optional: {
928
928
  "sub": new basic_1.StringType(),
@@ -938,7 +938,7 @@ BuiltIn.methods = [
938
938
  {
939
939
  name: "SUBSTRING_FROM",
940
940
  mandatory: {
941
- "val": new basic_1.StringType(),
941
+ "val": new basic_1.CLikeType(),
942
942
  },
943
943
  optional: {
944
944
  "sub": new basic_1.StringType(),
@@ -954,7 +954,7 @@ BuiltIn.methods = [
954
954
  {
955
955
  name: "SUBSTRING_TO",
956
956
  mandatory: {
957
- "val": new basic_1.StringType(),
957
+ "val": new basic_1.CLikeType(),
958
958
  },
959
959
  optional: {
960
960
  "sub": new basic_1.StringType(),
@@ -17,6 +17,7 @@ var ScopeType;
17
17
  ScopeType["Method"] = "method";
18
18
  ScopeType["MethodInstance"] = "method_instance";
19
19
  ScopeType["For"] = "for";
20
+ ScopeType["Let"] = "let";
20
21
  ScopeType["OpenSQL"] = "open_sql";
21
22
  })(ScopeType = exports.ScopeType || (exports.ScopeType = {}));
22
23
  //# sourceMappingURL=_scope_type.js.map
@@ -78,7 +78,8 @@ class TypeUtils {
78
78
  }
79
79
  return false;
80
80
  }
81
- else if (target instanceof basic_1.ObjectReferenceType || target instanceof basic_1.GenericObjectReferenceType) {
81
+ else if (target instanceof basic_1.ObjectReferenceType
82
+ || target instanceof basic_1.GenericObjectReferenceType) {
82
83
  if (source instanceof basic_1.ObjectReferenceType
83
84
  || source instanceof basic_1.GenericObjectReferenceType
84
85
  || source instanceof basic_1.VoidType
@@ -120,10 +121,12 @@ class TypeUtils {
120
121
  }
121
122
  else if (target instanceof basic_1.IntegerType
122
123
  || target instanceof basic_1.StringType) {
123
- if (source instanceof basic_1.DataReference
124
+ if (source instanceof basic_1.TableType && source.isWithHeader() === false) {
125
+ return false;
126
+ }
127
+ else if (source instanceof basic_1.DataReference
124
128
  || source instanceof basic_1.ObjectReferenceType
125
- || source instanceof basic_1.GenericObjectReferenceType
126
- || source instanceof basic_1.TableType) {
129
+ || source instanceof basic_1.GenericObjectReferenceType) {
127
130
  return false;
128
131
  }
129
132
  return true;
@@ -10,9 +10,10 @@ class CondBody {
10
10
  if (node === undefined) {
11
11
  return targetType;
12
12
  }
13
+ let scoped = false;
13
14
  const l = node.findDirectExpression(Expressions.Let);
14
15
  if (l) {
15
- new let_1.Let().runSyntax(l, scope, filename);
16
+ scoped = new let_1.Let().runSyntax(l, scope, filename);
16
17
  }
17
18
  for (const s of node.findDirectExpressions(Expressions.Cond)) {
18
19
  new cond_1.Cond().runSyntax(s, scope, filename);
@@ -26,6 +27,9 @@ class CondBody {
26
27
  new source_1.Source().runSyntax(s, scope, filename);
27
28
  }
28
29
  }
30
+ if (scoped === true) {
31
+ scope.pop(node.getLastToken().getEnd());
32
+ }
29
33
  return targetType ? targetType : type;
30
34
  }
31
35
  }
@@ -9,13 +9,17 @@ class ConvBody {
9
9
  if (node === undefined) {
10
10
  return;
11
11
  }
12
+ let scoped = false;
12
13
  const l = node.findDirectExpression(Expressions.Let);
13
14
  if (l) {
14
- new let_1.Let().runSyntax(l, scope, filename);
15
+ scoped = new let_1.Let().runSyntax(l, scope, filename);
15
16
  }
16
17
  for (const s of node.findDirectExpressions(Expressions.Source)) {
17
18
  new source_1.Source().runSyntax(s, scope, filename);
18
19
  }
20
+ if (scoped === true) {
21
+ scope.pop(node.getLastToken().getEnd());
22
+ }
19
23
  }
20
24
  }
21
25
  exports.ConvBody = ConvBody;
@@ -7,12 +7,14 @@ const source_1 = require("./source");
7
7
  const inline_loop_definition_1 = require("./inline_loop_definition");
8
8
  const _scope_type_1 = require("../_scope_type");
9
9
  const component_cond_1 = require("./component_cond");
10
+ const cond_1 = require("./cond");
10
11
  class For {
11
12
  runSyntax(node, scope, filename) {
12
13
  const inlineLoop = node.findDirectExpressions(Expressions.InlineLoopDefinition);
13
14
  const inlineField = node.findAllExpressions(Expressions.InlineFieldDefinition);
14
15
  const addScope = inlineLoop.length > 0 || inlineField.length > 0;
15
16
  if (addScope) {
17
+ // this scope is popped in parent expressions
16
18
  scope.push(_scope_type_1.ScopeType.For, "FOR", node.getFirstToken().getStart(), filename);
17
19
  }
18
20
  for (const s of inlineLoop) {
@@ -27,11 +29,9 @@ class For {
27
29
  for (const s of node.findDirectExpressions(Expressions.ComponentCond)) {
28
30
  new component_cond_1.ComponentCond().runSyntax(s, scope, filename);
29
31
  }
30
- /*
31
- if (addScope) {
32
- scope.pop(node.getLastToken().getEnd());
32
+ for (const s of node.findDirectExpressions(Expressions.Cond)) {
33
+ new cond_1.Cond().runSyntax(s, scope, filename);
33
34
  }
34
- */
35
35
  }
36
36
  }
37
37
  exports.For = For;
@@ -9,8 +9,9 @@ const unknown_type_1 = require("../../types/basic/unknown_type");
9
9
  const _reference_1 = require("../_reference");
10
10
  class InlineFieldDefinition {
11
11
  runSyntax(node, scope, filename) {
12
+ var _a;
12
13
  let type = undefined;
13
- const field = node.findDirectExpression(Expressions.Field);
14
+ const field = (_a = node.findDirectExpression(Expressions.Field)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
14
15
  if (field === undefined) {
15
16
  return;
16
17
  }
@@ -25,8 +26,12 @@ class InlineFieldDefinition {
25
26
  if (type === undefined) {
26
27
  type = new unknown_type_1.UnknownType("InlineFieldDefinition, fallback");
27
28
  }
28
- const identifier = new _typed_identifier_1.TypedIdentifier(field.getFirstToken(), filename, type, ["inline" /* InlineDefinition */]);
29
- scope.addReference(field.getFirstToken(), identifier, _reference_1.ReferenceType.DataWriteReference, filename);
29
+ const name = field.getStr();
30
+ if (scope.findVariable(name) !== undefined) {
31
+ throw new Error(`Variable ${name} already defined`);
32
+ }
33
+ const identifier = new _typed_identifier_1.TypedIdentifier(field, filename, type, ["inline" /* InlineDefinition */]);
34
+ scope.addReference(field, identifier, _reference_1.ReferenceType.DataWriteReference, filename);
30
35
  scope.addIdentifier(identifier);
31
36
  }
32
37
  }
@@ -3,14 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Let = void 0;
4
4
  const Expressions = require("../../2_statements/expressions");
5
5
  const inline_field_definition_1 = require("./inline_field_definition");
6
+ const _scope_type_1 = require("../_scope_type");
6
7
  class Let {
7
8
  runSyntax(node, scope, filename) {
8
9
  if (node === undefined) {
9
- return;
10
+ return false;
10
11
  }
12
+ scope.push(_scope_type_1.ScopeType.Let, "LET", node.getFirstToken().getStart(), filename);
11
13
  for (const f of node.findDirectExpressions(Expressions.InlineFieldDefinition)) {
12
14
  new inline_field_definition_1.InlineFieldDefinition().runSyntax(f, scope, filename);
13
15
  }
16
+ return true;
14
17
  }
15
18
  }
16
19
  exports.Let = Let;
@@ -12,14 +12,15 @@ class ValueBody {
12
12
  if (node === undefined) {
13
13
  return targetType;
14
14
  }
15
- const letNode = node.findDirectExpression(Expressions.Let);
16
- if (letNode) {
17
- new let_1.Let().runSyntax(letNode, scope, filename);
18
- }
19
15
  const forNode = node.findDirectExpression(Expressions.For);
20
16
  if (forNode) {
21
17
  new for_1.For().runSyntax(forNode, scope, filename);
22
18
  }
19
+ let scoped = false;
20
+ const letNode = node.findDirectExpression(Expressions.Let);
21
+ if (letNode) {
22
+ scoped = new let_1.Let().runSyntax(letNode, scope, filename);
23
+ }
23
24
  for (const s of node.findDirectExpressions(Expressions.FieldAssignment)) {
24
25
  new field_assignment_1.FieldAssignment().runSyntax(s, scope, filename, targetType);
25
26
  }
@@ -27,6 +28,9 @@ class ValueBody {
27
28
  for (const s of node.findDirectExpressions(Expressions.Source)) {
28
29
  type = new source_1.Source().runSyntax(s, scope, filename);
29
30
  }
31
+ if (scoped === true) {
32
+ scope.pop(node.getLastToken().getEnd());
33
+ }
30
34
  if (scope.getType() === _scope_type_1.ScopeType.For) {
31
35
  scope.pop(node.getLastToken().getEnd());
32
36
  }
@@ -68,7 +68,7 @@ class Registry {
68
68
  }
69
69
  static abaplintVersion() {
70
70
  // magic, see build script "version.sh"
71
- return "2.85.16";
71
+ return "2.85.17";
72
72
  }
73
73
  getDDICReferences() {
74
74
  return this.references;
@@ -913,7 +913,7 @@ ${indentation} output = ${topTarget}.`;
913
913
  const uniqueName = this.uniqueName(i.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
914
914
  const type = this.findType(i, lowFile, highSyntax);
915
915
  const indent = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
916
- const bodyCode = this.buildCondBody(body, uniqueName, indent);
916
+ const bodyCode = this.buildCondBody(body, uniqueName, indent, lowFile, highSyntax);
917
917
  const abap = `DATA ${uniqueName} TYPE ${type}.\n` + bodyCode;
918
918
  const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, node.getFirstToken().getStart(), abap);
919
919
  const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, i.getFirstToken().getStart(), i.getLastToken().getEnd(), uniqueName);
@@ -922,13 +922,13 @@ ${indentation} output = ${topTarget}.`;
922
922
  }
923
923
  return undefined;
924
924
  }
925
- buildCondBody(body, uniqueName, indent) {
926
- let code = indent;
925
+ buildCondBody(body, uniqueName, indent, lowFile, highSyntax) {
926
+ let code = "";
927
927
  for (const c of body.getChildren()) {
928
928
  if (c instanceof nodes_1.TokenNode) {
929
929
  switch (c.getFirstToken().getStr().toUpperCase()) {
930
930
  case "WHEN":
931
- code += "IF ";
931
+ code += indent + "IF ";
932
932
  break;
933
933
  case "THEN":
934
934
  code += ".\n";
@@ -943,11 +943,14 @@ ${indentation} output = ${topTarget}.`;
943
943
  else if (c.get() instanceof Expressions.Cond) {
944
944
  code += c.concatTokens();
945
945
  }
946
+ else if (c.get() instanceof Expressions.Let) {
947
+ code += this.outlineLet(c, indent, highSyntax, lowFile);
948
+ }
946
949
  else if (c.get() instanceof Expressions.Source) {
947
950
  code += indent + " " + uniqueName + " = " + c.concatTokens() + ".\n";
948
951
  }
949
952
  else {
950
- throw "buildCondBody, unexpected expression";
953
+ throw "buildCondBody, unexpected expression, " + c.get().constructor.name;
951
954
  }
952
955
  }
953
956
  code += indent + "ENDIF.\n";
@@ -25,7 +25,9 @@ class UseNew extends _abap_rule_1.ABAPRule {
25
25
  shortDescription: `Checks for deprecated CREATE OBJECT statements.`,
26
26
  extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-new-to-create-object
27
27
 
28
- If the target variable is referenced in the CREATE OBJECT statement, no errors are issued`,
28
+ If the target variable is referenced in the CREATE OBJECT statement, no errors are issued
29
+
30
+ Applicable from v740sp02 and up`,
29
31
  badExample: `CREATE OBJECT ref.`,
30
32
  goodExample: `ref = NEW #( ).`,
31
33
  tags: [_irule_1.RuleTag.Upport, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.85.16",
3
+ "version": "2.85.17",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",