@abaplint/transpiler 2.10.66 → 2.10.67

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.
@@ -1 +1,3 @@
1
- export declare const FEATURE_FLAGS: {};
1
+ export declare const FEATURE_FLAGS: {
2
+ PRIVATE_ATTRIBUTES: boolean;
3
+ };
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FEATURE_FLAGS = void 0;
4
- exports.FEATURE_FLAGS = {};
4
+ exports.FEATURE_FLAGS = {
5
+ PRIVATE_ATTRIBUTES: true,
6
+ };
5
7
  //# sourceMappingURL=feature_flags.js.map
@@ -8,6 +8,7 @@ export declare class ClassImplementationTranspiler implements IStructureTranspil
8
8
  /** Finds static attributes + constants including those from interfaces (from superclass is ingored) */
9
9
  private findStaticAttributes;
10
10
  private buildTypes;
11
+ private buildPrivate;
11
12
  /** this builds the part after the class, containing the static variables/constants */
12
13
  private buildStatic;
13
14
  private buildConstructor;
@@ -5,6 +5,7 @@ const abaplint = require("@abaplint/core");
5
5
  const traversal_1 = require("../traversal");
6
6
  const transpile_types_1 = require("../transpile_types");
7
7
  const chunk_1 = require("../chunk");
8
+ const feature_flags_1 = require("../feature_flags");
8
9
  class ClassImplementationTranspiler {
9
10
  transpile(node, traversal) {
10
11
  const ret = new chunk_1.Chunk();
@@ -73,6 +74,22 @@ class ClassImplementationTranspiler {
73
74
  }
74
75
  return ret;
75
76
  }
77
+ buildPrivate(node, traversal) {
78
+ if (node === undefined || feature_flags_1.FEATURE_FLAGS.PRIVATE_ATTRIBUTES === false) {
79
+ return "";
80
+ }
81
+ const cdef = traversal.getClassDefinition(node.getFirstToken());
82
+ if (cdef === undefined) {
83
+ return "ERROR_CDEF_NOT_FOUND";
84
+ }
85
+ let ret = "";
86
+ for (const attr of cdef.getAttributes().getAll()) {
87
+ if (attr.getVisibility() === abaplint.Visibility.Private) {
88
+ ret += "#" + traversal_1.Traversal.escapeNamespace(attr.getName().toLowerCase()) + ";\n";
89
+ }
90
+ }
91
+ return ret;
92
+ }
76
93
  /** this builds the part after the class, containing the static variables/constants */
77
94
  buildStatic(node, traversal) {
78
95
  if (node === undefined) {
@@ -144,8 +161,9 @@ class ClassImplementationTranspiler {
144
161
  if (ret === "") {
145
162
  return ret;
146
163
  }
164
+ const privates = this.buildPrivate(node.findFirstExpression(abaplint.Expressions.ClassName), traversal);
147
165
  // note: for CALL TRANSFORMATION, its nice that the values are initialized by the JS constructor,
148
- return "constructor() {\n" + ret + "}\n";
166
+ return privates + "constructor() {\n" + ret + "}\n";
149
167
  }
150
168
  }
151
169
  exports.ClassImplementationTranspiler = ClassImplementationTranspiler;
@@ -22,6 +22,7 @@ export declare class Traversal {
22
22
  private fuctionGroupWorkaround;
23
23
  getInterfaceDefinition(token: abaplint.Token): abaplint.IInterfaceDefinition | undefined;
24
24
  getClassDefinition(token: abaplint.Token): abaplint.IClassDefinition | undefined;
25
+ private isPrivateAttribute;
25
26
  private isClassAttribute;
26
27
  prefixAndName(t: abaplint.Token, filename?: string): string;
27
28
  private isStaticClassAttribute;
@@ -9,6 +9,7 @@ const transpile_types_1 = require("./transpile_types");
9
9
  const chunk_1 = require("./chunk");
10
10
  const expressions_1 = require("./expressions");
11
11
  const keywords_1 = require("./keywords");
12
+ const feature_flags_1 = require("./feature_flags");
12
13
  class Traversal {
13
14
  constructor(spaghetti, file, obj, reg, options) {
14
15
  this.scopeCache = undefined;
@@ -124,6 +125,22 @@ class Traversal {
124
125
  }
125
126
  return undefined;
126
127
  }
128
+ isPrivateAttribute(token) {
129
+ const scope = this.findCurrentScopeByToken(token);
130
+ if (scope === undefined) {
131
+ throw new Error("isPrivateAttribute, unable to lookup position");
132
+ }
133
+ const name = token.getStr();
134
+ if (name.toLowerCase() === "me") {
135
+ return false;
136
+ }
137
+ const found = scope.findVariable(name);
138
+ if (found instanceof abaplint.Types.ClassAttribute
139
+ && found.getVisibility() === abaplint.Visibility.Private) {
140
+ return true;
141
+ }
142
+ return false;
143
+ }
127
144
  isClassAttribute(token) {
128
145
  const scope = this.findCurrentScopeByToken(token);
129
146
  if (scope === undefined) {
@@ -165,7 +182,11 @@ class Traversal {
165
182
  return name;
166
183
  }
167
184
  else if (this.isClassAttribute(t)) {
168
- name = "this." + Traversal.escapeNamespace(name);
185
+ let escaped = Traversal.escapeNamespace(name);
186
+ if (feature_flags_1.FEATURE_FLAGS.PRIVATE_ATTRIBUTES === true && this.isPrivateAttribute(t)) {
187
+ escaped = "#" + escaped;
188
+ }
189
+ name = "this." + escaped;
169
190
  }
170
191
  else if (this.isBuiltinVariable(t)) {
171
192
  name = "abap.builtin." + name.toLowerCase().replace("%", "$");
@@ -380,14 +401,19 @@ class Traversal {
380
401
  buildThisAttributes(def, cName) {
381
402
  let ret = "";
382
403
  for (const a of def.getAttributes()?.getAll() || []) {
383
- const escaped = Traversal.escapeNamespace(a.getName().toLowerCase());
404
+ let escaped = Traversal.escapeNamespace(a.getName().toLowerCase());
384
405
  if (a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === true) {
385
406
  ret += "this." + escaped + " = " + cName + "." + escaped + ";\n";
386
- continue;
387
407
  }
388
- const name = "this." + escaped;
389
- ret += name + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
390
- ret += this.setValues(a, name);
408
+ else {
409
+ if (feature_flags_1.FEATURE_FLAGS.PRIVATE_ATTRIBUTES === true
410
+ && a.getVisibility() === abaplint.Visibility.Private) {
411
+ escaped = "#" + escaped;
412
+ }
413
+ const name = "this." + escaped;
414
+ ret += name + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
415
+ ret += this.setValues(a, name);
416
+ }
391
417
  }
392
418
  return ret;
393
419
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.10.66",
3
+ "version": "2.10.67",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",