@abaplint/transpiler 2.13.76 → 2.13.77

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.
@@ -73,8 +73,10 @@ class FieldChainTranspiler {
73
73
  else if (c.get() instanceof core_1.Expressions.AttributeName) {
74
74
  const interfaceName = traversal.isInterfaceAttribute(c.getFirstToken());
75
75
  let name = c.getFirstToken().getStr().toLowerCase();
76
- if (context instanceof abaplint.BasicTypes.ObjectReferenceType) {
77
- const cdef = traversal.findClassDefinition(context.getIdentifierName(), scope);
76
+ const attributeContext = context;
77
+ context = traversal.narrowContextAttribute(context, c.getFirstToken().getStr(), scope);
78
+ if (attributeContext instanceof abaplint.BasicTypes.ObjectReferenceType) {
79
+ const cdef = traversal.findClassDefinition(attributeContext.getIdentifierName(), scope);
78
80
  const tokenName = c.getFirstToken().getStr();
79
81
  const attr = cdef?.getAttributes().findByName(tokenName);
80
82
  // Do not mark constants as private JS fields. Constants are exposed on instances via constructor copying.
@@ -106,6 +108,7 @@ class FieldChainTranspiler {
106
108
  }
107
109
  else if (c.get() instanceof core_1.Expressions.ComponentName) {
108
110
  const name = c.getFirstToken().getStr().toLowerCase();
111
+ context = traversal_1.Traversal.narrowContextComponent(context, c.getFirstToken().getStr());
109
112
  if (traversal_1.Traversal.isBracketComponent(name)) {
110
113
  ret.append(`["` + name + `"]`, c, traversal);
111
114
  }
@@ -135,6 +138,9 @@ class FieldChainTranspiler {
135
138
  }
136
139
  else if (c instanceof core_1.Nodes.ExpressionNode
137
140
  && c.get() instanceof core_1.Expressions.TableExpression) {
141
+ if (context instanceof abaplint.BasicTypes.TableType) {
142
+ context = context.getRowType();
143
+ }
138
144
  ret = new _1.TableExpressionTranspiler().transpile(c, traversal, ret);
139
145
  }
140
146
  }
@@ -55,6 +55,9 @@ class TargetTranspiler {
55
55
  context = scope?.findVariable(c.getFirstToken().getStr())?.getType();
56
56
  }
57
57
  else if (c.get() instanceof core_1.Expressions.TableExpression && c instanceof core_1.Nodes.ExpressionNode) {
58
+ if (context instanceof abaplint.BasicTypes.TableType) {
59
+ context = context.getRowType();
60
+ }
58
61
  ret = new _1.TableExpressionTranspiler().transpile(c, traversal, ret);
59
62
  }
60
63
  else if (c.get() instanceof core_1.Expressions.InlineData && c instanceof core_1.Nodes.ExpressionNode) {
@@ -71,6 +74,7 @@ class TargetTranspiler {
71
74
  }
72
75
  else if (c.get() instanceof core_1.Expressions.ComponentName) {
73
76
  const name = c.getFirstToken().getStr().toLowerCase();
77
+ context = traversal_1.Traversal.narrowContextComponent(context, c.getFirstToken().getStr());
74
78
  if (traversal_1.Traversal.isBracketComponent(name)) {
75
79
  ret.append(`["` + name + `"]`, c, traversal);
76
80
  }
@@ -81,8 +85,10 @@ class TargetTranspiler {
81
85
  else if (c.get() instanceof core_1.Expressions.AttributeName) {
82
86
  let prefix = "";
83
87
  let postfix = "";
84
- if (context instanceof abaplint.BasicTypes.ObjectReferenceType) {
85
- const cdef = traversal.findClassDefinition(context.getIdentifierName(), scope);
88
+ const attributeContext = context;
89
+ context = traversal.narrowContextAttribute(context, c.getFirstToken().getStr(), scope);
90
+ if (attributeContext instanceof abaplint.BasicTypes.ObjectReferenceType) {
91
+ const cdef = traversal.findClassDefinition(attributeContext.getIdentifierName(), scope);
86
92
  const attr = cdef?.getAttributes().findByName(c.getFirstToken().getStr());
87
93
  if (attr?.getVisibility() === abaplint.Visibility.Private) {
88
94
  const id = scope?.getParent()?.getParent()?.getIdentifier();
@@ -71,6 +71,9 @@ export declare class Traversal {
71
71
  constructorPrototypePrefix(token: abaplint.Token, def: abaplint.Types.MethodDefinition | undefined, enclosingClass?: string): string | undefined;
72
72
  private isBuiltinVariable;
73
73
  isTypePool(token: abaplint.Token): string | undefined;
74
+ static narrowContextComponent(context: abaplint.AbstractType | undefined, name: string): abaplint.AbstractType | undefined;
75
+ narrowContextAttribute(context: abaplint.AbstractType | undefined, name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
76
+ private static dereferenceContext;
74
77
  isInterfaceAttribute(token: abaplint.Token): string | undefined;
75
78
  findReadOrWriteReference(token: abaplint.Token): abaplint.Identifier | undefined;
76
79
  private findInferredTypeReference;
@@ -517,6 +517,45 @@ class Traversal {
517
517
  }
518
518
  return undefined;
519
519
  }
520
+ // narrows the current type context of a chain, ie. "ls_struct-comp" or "lt_tab[ 1 ]-comp"
521
+ static narrowContextComponent(context, name) {
522
+ const structure = Traversal.dereferenceContext(context);
523
+ if (structure instanceof abaplint.BasicTypes.StructureType) {
524
+ return structure.getComponentByName(name);
525
+ }
526
+ return undefined;
527
+ }
528
+ // narrows the current type context of a chain, ie. "lo_ref->attr"
529
+ narrowContextAttribute(context, name, scope) {
530
+ if (context instanceof abaplint.BasicTypes.ObjectReferenceType === false) {
531
+ return undefined;
532
+ }
533
+ let identifierName = context.getIdentifierName();
534
+ const visited = new Set();
535
+ while (identifierName !== undefined && visited.has(identifierName.toUpperCase()) === false) {
536
+ visited.add(identifierName.toUpperCase());
537
+ const def = this.findClassDefinition(identifierName, scope) || this.findInterfaceDefinition(identifierName, scope);
538
+ if (def === undefined) {
539
+ return undefined;
540
+ }
541
+ const type = def.getAttributes().findByName(name)?.getType();
542
+ if (type !== undefined) {
543
+ return type;
544
+ }
545
+ identifierName = def.getSuperClass();
546
+ }
547
+ return undefined;
548
+ }
549
+ static dereferenceContext(context) {
550
+ let ret = context;
551
+ if (ret instanceof abaplint.BasicTypes.TableType) {
552
+ ret = ret.getRowType();
553
+ }
554
+ if (ret instanceof abaplint.BasicTypes.DataReference) {
555
+ ret = ret.getType();
556
+ }
557
+ return ret;
558
+ }
520
559
  // returns the interface name if interfaced
521
560
  isInterfaceAttribute(token) {
522
561
  const ref = this.findReadOrWriteReference(token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.13.76",
3
+ "version": "2.13.77",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",