@abaplint/transpiler 2.14.2 → 2.14.3

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.
@@ -107,6 +107,8 @@ export declare class Traversal {
107
107
  findCurrentDoOrWhileIndexBackup(node: abaplint.Nodes.StatementNode): string | undefined;
108
108
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
109
109
  setValues(identifier: abaplint.TypedIdentifier, name: string): string;
110
+ /** position of an enumerated value in its TYPES BEGIN OF ENUM, counting from 0 */
111
+ private findEnumValueIndex;
110
112
  static setValues(identifier: abaplint.TypedIdentifier, name: string): string;
111
113
  buildInternalName(name: string, def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
112
114
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
@@ -629,13 +629,20 @@ class Traversal {
629
629
  if (ref === undefined) {
630
630
  return undefined;
631
631
  }
632
- // local
632
+ // local, also when the interface is declared in another include of the same object,
633
+ // eg. a local interface in the locals_imp of a class, used in its test classes
633
634
  if (ref.getFilename() === this.getFilename()) {
634
635
  const scope = this.findCurrentScopeByToken(ref.getToken());
635
636
  if (scope?.getIdentifier().stype === abaplint.ScopeType.Interface) {
636
637
  return scope?.getIdentifier().sname;
637
638
  }
638
639
  }
640
+ else if (this.getCurrentObject().getABAPFileByName(ref.getFilename()) !== undefined) {
641
+ const scope = this.spaghetti.lookupPosition(ref.getStart(), ref.getFilename());
642
+ if (scope?.getIdentifier().stype === abaplint.ScopeType.Interface) {
643
+ return scope?.getIdentifier().sname;
644
+ }
645
+ }
639
646
  // global
640
647
  for (const obj of this.reg.getObjectsByType("INTF")) {
641
648
  if (obj.getFiles().some(f => f.getFilename() === ref.getFilename())) {
@@ -1000,8 +1007,33 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
1000
1007
  return `abap.Classes['${name}'] = ${Traversal.escapeNamespace(def.getName().toLowerCase())};`;
1001
1008
  }
1002
1009
  setValues(identifier, name) {
1010
+ // an enumerated value of a class or interface, declared without STRUCTURE: number the
1011
+ // values in the order they are declared, like the STRUCTURE components in setValues below
1012
+ if (identifier.getValue() === "novalueClassAttributeEnum"
1013
+ && !(identifier.getType() instanceof abaplint.BasicTypes.StructureType)) {
1014
+ const index = this.findEnumValueIndex(identifier);
1015
+ return index === undefined ? "" : Traversal.prefixVariable(name) + ".set(" + index + ");\n";
1016
+ }
1003
1017
  return Traversal.setValues(identifier, name);
1004
1018
  }
1019
+ /** position of an enumerated value in its TYPES BEGIN OF ENUM, counting from 0 */
1020
+ findEnumValueIndex(identifier) {
1021
+ // the enum can be declared in another object, eg. a global interface the class implements
1022
+ const filename = identifier.getFilename();
1023
+ const raw = this.reg.getFileByName(filename);
1024
+ const obj = raw === undefined ? undefined : this.reg.findObjectForFile(raw);
1025
+ const file = obj instanceof abaplint.ABAPObject ? obj.getABAPFileByName(filename) : undefined;
1026
+ for (const enumeration of file?.getStructure()?.findAllStructures(abaplint.Structures.TypeEnum) || []) {
1027
+ const values = enumeration.getChildren().filter(c => c instanceof abaplint.Nodes.StatementNode
1028
+ && (c.get() instanceof abaplint.Statements.Type || c.get() instanceof abaplint.Statements.TypeEnum));
1029
+ const index = values.findIndex(v => v
1030
+ .findFirstExpression(abaplint.Expressions.NamespaceSimpleName)?.getFirstToken().getStart().equals(identifier.getStart()));
1031
+ if (index >= 0) {
1032
+ return index;
1033
+ }
1034
+ }
1035
+ return undefined;
1036
+ }
1005
1037
  static setValues(identifier, name) {
1006
1038
  const val = identifier.getValue();
1007
1039
  let ret = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.14.2",
3
+ "version": "2.14.3",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "author": "abaplint",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@abaplint/core": "^2.120.71",
32
+ "@abaplint/core": "^2.120.72",
33
33
  "source-map": "^0.8.0"
34
34
  },
35
35
  "devDependencies": {