@abaplint/transpiler-cli 2.14.37 → 2.14.38

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.
Files changed (2) hide show
  1. package/build/bundle.js +942 -147
  2. package/package.json +3 -3
package/build/bundle.js CHANGED
@@ -5588,10 +5588,14 @@ exports.CorrespondingBodyBase = CorrespondingBodyBase;
5588
5588
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5589
5589
  exports.CorrespondingBodyMapping = void 0;
5590
5590
  const combi_1 = __webpack_require__(/*! ../combi */ "./node_modules/@abaplint/core/build/src/abap/2_statements/combi.js");
5591
+ const tokens_1 = __webpack_require__(/*! ../../1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
5591
5592
  const _1 = __webpack_require__(/*! . */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js");
5592
5593
  class CorrespondingBodyMapping extends combi_1.Expression {
5593
5594
  getRunnable() {
5594
- const mapping = (0, combi_1.seq)("MAPPING", (0, combi_1.plus)((0, combi_1.seq)(_1.ComponentName, "=", _1.ComponentChain)));
5595
+ const single = (0, combi_1.seq)(_1.ComponentName, "=", _1.ComponentChain);
5596
+ // mapping rule for a sub structure or tabular component, with its own MAPPING and EXCEPT
5597
+ const nested = (0, combi_1.seq)((0, combi_1.tok)(tokens_1.WParenLeftW), single, (0, combi_1.optPrio)(CorrespondingBodyMapping), (0, combi_1.optPrio)((0, combi_1.seq)("EXCEPT", (0, combi_1.alt)((0, combi_1.plus)(_1.Field), "*"))), (0, combi_1.tok)(tokens_1.WParenRightW));
5598
+ const mapping = (0, combi_1.seq)("MAPPING", (0, combi_1.plus)((0, combi_1.alt)(single, nested)));
5595
5599
  return mapping;
5596
5600
  }
5597
5601
  }
@@ -30547,11 +30551,17 @@ class TypeUtils {
30547
30551
  return false;
30548
30552
  }
30549
30553
  }
30550
- if (node && builtin === false && this.isFunctionalMethodResult(node)
30551
- && this.isFunctionalResultAssignable(source, target) === false) {
30554
+ const functionalResult = node !== undefined && builtin === false && this.isFunctionalMethodResult(node);
30555
+ if (functionalResult && this.isFunctionalResultAssignable(source, target) === false) {
30552
30556
  return false;
30553
30557
  }
30554
- if (calculated) {
30558
+ // a structure, table or reference returned by a functional method follows the same rule as a variable
30559
+ const strictResult = functionalResult && (source instanceof basic_1.StructureType
30560
+ || source instanceof basic_1.TableType
30561
+ || source instanceof basic_1.DataReference
30562
+ || source instanceof basic_1.ObjectReferenceType
30563
+ || source instanceof basic_1.GenericObjectReferenceType);
30564
+ if (calculated && strictResult === false) {
30555
30565
  return this.isAssignable(source, target);
30556
30566
  }
30557
30567
  // an elementary text field is not compatible with a structure, also not with a flat character-like one
@@ -30888,8 +30898,40 @@ class TypeUtils {
30888
30898
  else if (source instanceof basic_1.TableType && target instanceof basic_1.TableType) {
30889
30899
  return this.isAssignableStructureTyping(source.getRowType(), target.getRowType());
30890
30900
  }
30901
+ else if (source instanceof basic_1.CharacterType && target instanceof basic_1.StructureType) {
30902
+ // an elementary actual must be character-like, the formal structure purely character-like
30903
+ const length = this.characterLikeStructureLength(target);
30904
+ return length !== undefined && source.getLength() >= length;
30905
+ }
30891
30906
  return this.isAssignableStrict(source, target, node);
30892
30907
  }
30908
+ // returns the total length if the structure is flat and purely character-like, otherwise undefined
30909
+ characterLikeStructureLength(type) {
30910
+ let length = 0;
30911
+ for (const component of type.getComponents()) {
30912
+ const t = component.type;
30913
+ if (t instanceof basic_1.CharacterType || t instanceof basic_1.NumericType) {
30914
+ length += t.getLength();
30915
+ }
30916
+ else if (t instanceof basic_1.DateType) {
30917
+ length += 8;
30918
+ }
30919
+ else if (t instanceof basic_1.TimeType) {
30920
+ length += 6;
30921
+ }
30922
+ else if (t instanceof basic_1.StructureType) {
30923
+ const sub = this.characterLikeStructureLength(t);
30924
+ if (sub === undefined) {
30925
+ return undefined;
30926
+ }
30927
+ length += sub;
30928
+ }
30929
+ else {
30930
+ return undefined;
30931
+ }
30932
+ }
30933
+ return length;
30934
+ }
30893
30935
  isAssignable(source, target) {
30894
30936
  if (source === undefined || target === undefined) {
30895
30937
  return true;
@@ -35320,7 +35362,7 @@ const assert_error_1 = __webpack_require__(/*! ../assert_error */ "./node_module
35320
35362
  const tokens_1 = __webpack_require__(/*! ../../1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
35321
35363
  class FormParam {
35322
35364
  static runSyntax(node, input) {
35323
- var _a, _b, _c;
35365
+ var _a, _b, _c, _d;
35324
35366
  const formParamName = node.findFirstExpression(expressions_1.FormParamName);
35325
35367
  if (formParamName === undefined) {
35326
35368
  throw new assert_error_1.AssertError("FormParam, could not find FormParamName");
@@ -35335,6 +35377,14 @@ class FormParam {
35335
35377
  let type;
35336
35378
  if (typeName) {
35337
35379
  type = (_b = input.scope.findType(typeName)) === null || _b === void 0 ? void 0 : _b.getType();
35380
+ if (type === undefined) {
35381
+ // STRUCTURE can also refer to a program-local data object
35382
+ type = (_c = input.scope.findVariable(typeName)) === null || _c === void 0 ? void 0 : _c.getType();
35383
+ if (type instanceof basic_1.TableType && type.isWithHeader()) {
35384
+ // a table with header line refers to its header line
35385
+ type = type.getRowType();
35386
+ }
35387
+ }
35338
35388
  if (type === undefined) {
35339
35389
  type = input.scope.getDDIC().lookupTableOrView(typeName).type;
35340
35390
  }
@@ -35349,7 +35399,7 @@ class FormParam {
35349
35399
  return new _typed_identifier_1.TypedIdentifier(nameToken, input.filename, basic_1.AnyType.get(), ["form_parameter" /* IdentifierMeta.FormParameter */]);
35350
35400
  }
35351
35401
  let bfound = new basic_types_1.BasicTypes(input).parseType(node);
35352
- const typeName = (_c = node.findFirstExpression(expressions_1.TypeName)) === null || _c === void 0 ? void 0 : _c.concatTokens().toUpperCase();
35402
+ const typeName = (_d = node.findFirstExpression(expressions_1.TypeName)) === null || _d === void 0 ? void 0 : _d.concatTokens().toUpperCase();
35353
35403
  const hasExplicitLength = node.findFirstExpression(expressions_1.Length) !== undefined
35354
35404
  || node.findFirstExpression(expressions_1.ConstantFieldLength) !== undefined;
35355
35405
  // the length cannot be specified for FORM parameters, so these types are generic
@@ -38889,6 +38939,7 @@ class Source {
38889
38939
  {
38890
38940
  const foundType = this.determineType(node, input, targetType);
38891
38941
  if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) === true
38942
+ && !(foundType instanceof basic_1.DataType)
38892
38943
  && ((_b = node.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _b === void 0 ? void 0 : _b.concatTokens()) === "#"
38893
38944
  && !(0, version_1.releaseAtLeast)(input.scope.getRelease(), version_1.Release.v756)
38894
38945
  && input.scope.getLanguageVersion() !== version_1.LanguageVersion.Cloud
@@ -44580,8 +44631,12 @@ class DeleteInternal {
44580
44631
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
44581
44632
  return;
44582
44633
  }
44583
- if (targetType instanceof basic_1.TableType && targetType.isWithHeader() === false) {
44634
+ if (targetType instanceof basic_1.TableType
44635
+ && targetType.isWithHeader() === false
44636
+ && targetType.isGeneric() === false
44637
+ && this.isBodyOfTableWithHeader(target, input) === false) {
44584
44638
  // short forms, "DELETE itab." deletes the current line inside a LOOP, otherwise both use the header line
44639
+ // generically typed tables are not checked statically
44585
44640
  const children = node.getChildren().length;
44586
44641
  const short = children === 3 && input.inLoop !== true;
44587
44642
  const shortTable = children === 4 && node.findDirectTokenByText("TABLE") !== undefined;
@@ -44603,6 +44658,16 @@ class DeleteInternal {
44603
44658
  component_cond_1.ComponentCond.runSyntax(t, input, targetType);
44604
44659
  }
44605
44660
  }
44661
+ // "DELETE itab[]." where itab has a header line, eg. a FORM TABLES parameter
44662
+ isBodyOfTableWithHeader(target, input) {
44663
+ var _a;
44664
+ const children = target.getChildren();
44665
+ if (children.length !== 2 || !(children[1].get() instanceof Expressions.TableBody)) {
44666
+ return false;
44667
+ }
44668
+ const type = (_a = input.scope.findVariable(children[0].concatTokens())) === null || _a === void 0 ? void 0 : _a.getType();
44669
+ return type instanceof basic_1.TableType && type.isWithHeader();
44670
+ }
44606
44671
  }
44607
44672
  exports.DeleteInternal = DeleteInternal;
44608
44673
  //# sourceMappingURL=delete_internal.js.map
@@ -44781,14 +44846,16 @@ class Describe {
44781
44846
  for (const s of node.findDirectExpressions(Expressions.FieldChain)) {
44782
44847
  field_chain_1.FieldChain.runSyntax(s, input, _reference_1.ReferenceType.DataReadReference);
44783
44848
  }
44784
- const linesTarget = node.findExpressionAfterToken("LINES");
44785
- if ((linesTarget === null || linesTarget === void 0 ? void 0 : linesTarget.get()) instanceof Expressions.Target) {
44786
- const inline = linesTarget === null || linesTarget === void 0 ? void 0 : linesTarget.findDirectExpression(Expressions.InlineData);
44787
- if (inline) {
44788
- inline_data_1.InlineData.runSyntax(inline, input, basic_1.IntegerType.get());
44789
- }
44790
- else {
44791
- target_1.Target.runSyntax(linesTarget, input);
44849
+ for (const addition of ["LINES", "KIND", "OCCURS"]) {
44850
+ const target = node.findExpressionAfterToken(addition);
44851
+ if ((target === null || target === void 0 ? void 0 : target.get()) instanceof Expressions.Target) {
44852
+ const inline = target.findDirectExpression(Expressions.InlineData);
44853
+ if (inline) {
44854
+ inline_data_1.InlineData.runSyntax(inline, input, addition === "KIND" ? new basic_1.CharacterType(1) : basic_1.IntegerType.get());
44855
+ }
44856
+ else {
44857
+ target_1.Target.runSyntax(target, input);
44858
+ }
44792
44859
  }
44793
44860
  }
44794
44861
  const typeTarget = node.findExpressionAfterToken("TYPE");
@@ -76757,7 +76824,7 @@ class Registry {
76757
76824
  }
76758
76825
  static abaplintVersion() {
76759
76826
  // magic, see build script "version.js"
76760
- return "2.120.116";
76827
+ return "2.120.118";
76761
76828
  }
76762
76829
  getDDICReferences() {
76763
76830
  return this.ddicReferences;
@@ -80591,8 +80658,7 @@ If BEGIN OF has an INCLUDE TYPE its ignored
80591
80658
  Also note that clean ABAP does not recommend aligning TYPE clauses:
80592
80659
  https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-align-type-clauses`,
80593
80660
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix],
80594
- badExample: `
80595
- TYPES: BEGIN OF foo,
80661
+ badExample: `TYPES: BEGIN OF foo,
80596
80662
  bar TYPE i,
80597
80663
  foobar TYPE i,
80598
80664
  END OF foo.
@@ -80603,8 +80669,7 @@ INTERFACE lif.
80603
80669
  foo TYPE i
80604
80670
  foobar TYPE i.
80605
80671
  ENDINTERFACE.`,
80606
- goodExample: `
80607
- TYPES: BEGIN OF foo,
80672
+ goodExample: `TYPES: BEGIN OF foo,
80608
80673
  bar TYPE i,
80609
80674
  foobar TYPE i,
80610
80675
  END OF foo.
@@ -93357,12 +93422,10 @@ class EmptyEvent extends _abap_rule_1.ABAPRule {
93357
93422
  shortDescription: `Empty selection screen or list processing event block`,
93358
93423
  extendedInformation: ``,
93359
93424
  tags: [_irule_1.RuleTag.SingleFile],
93360
- badExample: `
93361
- INITIALIZATION.
93425
+ badExample: `INITIALIZATION.
93362
93426
  WRITE 'hello'.
93363
93427
  END-OF-SELECTION.`,
93364
- goodExample: `
93365
- START-OF-SELECTION.
93428
+ goodExample: `START-OF-SELECTION.
93366
93429
  PERFORM sdf.
93367
93430
  COMMIT WORK.`,
93368
93431
  };
@@ -101477,18 +101540,14 @@ class ManyParentheses extends _abap_rule_1.ABAPRule {
101477
101540
  title: "Too many parentheses",
101478
101541
  shortDescription: `Searches for expressions where extra parentheses can safely be removed`,
101479
101542
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
101480
- badExample: `
101481
- IF ( destination IS INITIAL ).
101543
+ badExample: `IF ( destination IS INITIAL ).
101482
101544
  ENDIF.
101483
101545
  IF foo = boo AND ( bar = lar AND moo = loo ).
101484
- ENDIF.
101485
- `,
101486
- goodExample: `
101487
- IF destination IS INITIAL.
101546
+ ENDIF.`,
101547
+ goodExample: `IF destination IS INITIAL.
101488
101548
  ENDIF.
101489
101549
  IF foo = boo AND bar = lar AND moo = loo.
101490
- ENDIF.
101491
- `,
101550
+ ENDIF.`,
101492
101551
  };
101493
101552
  }
101494
101553
  getConfig() {
@@ -101713,12 +101772,10 @@ class MaxOneMethodParameterPerLine extends _abap_rule_1.ABAPRule {
101713
101772
  title: "Max one method parameter definition per line",
101714
101773
  shortDescription: `Keep max one method parameter description per line`,
101715
101774
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix],
101716
- badExample: `
101717
- METHODS apps_scope_token
101775
+ badExample: `METHODS apps_scope_token
101718
101776
  IMPORTING
101719
101777
  body TYPE bodyapps_scope_token client_id TYPE str.`,
101720
- goodExample: `
101721
- METHODS apps_scope_token
101778
+ goodExample: `METHODS apps_scope_token
101722
101779
  IMPORTING
101723
101780
  body TYPE bodyapps_scope_token
101724
101781
  client_id TYPE str.`,
@@ -106047,21 +106104,19 @@ class OmitReceiving extends _abap_rule_1.ABAPRule {
106047
106104
  shortDescription: `Omit RECEIVING`,
106048
106105
  extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-receiving`,
106049
106106
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
106050
- badExample: `
106051
- upload_pack(
106052
- EXPORTING
106053
- io_client = lo_client
106054
- iv_url = iv_url
106055
- iv_deepen_level = iv_deepen_level
106056
- it_hashes = lt_hashes
106057
- RECEIVING
106058
- rt_objects = et_objects ).`,
106059
- goodExample: `
106060
- et_objects = upload_pack(
106061
- io_client = lo_client
106062
- iv_url = iv_url
106063
- iv_deepen_level = iv_deepen_level
106064
- it_hashes = lt_hashes ).`,
106107
+ badExample: `upload_pack(
106108
+ EXPORTING
106109
+ io_client = lo_client
106110
+ iv_url = iv_url
106111
+ iv_deepen_level = iv_deepen_level
106112
+ it_hashes = lt_hashes
106113
+ RECEIVING
106114
+ rt_objects = et_objects ).`,
106115
+ goodExample: `et_objects = upload_pack(
106116
+ io_client = lo_client
106117
+ iv_url = iv_url
106118
+ iv_deepen_level = iv_deepen_level
106119
+ it_hashes = lt_hashes ).`,
106065
106120
  };
106066
106121
  }
106067
106122
  getConfig() {
@@ -106902,7 +106957,7 @@ class PreferAbapBoolValues extends _abap_rule_1.ABAPRule {
106902
106957
  title: "Prefer abap_true and abap_false",
106903
106958
  shortDescription: `Use abap_true and abap_false instead of 'X' and ' ' for abap_bool variables`,
106904
106959
  // eslint-disable-next-line max-len
106905
- extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-abap_false-and-abap_undefined-for-abap_bool-variables`,
106960
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-and-abap_false-for-comparisons`,
106906
106961
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
106907
106962
  badExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = 'X'.`,
106908
106963
  goodExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = abap_true.`,
@@ -122740,6 +122795,440 @@ function unescape(str) {
122740
122795
 
122741
122796
  /***/ },
122742
122797
 
122798
+ /***/ "./node_modules/@abaplint/transpiler/build/src/cds_metadata.js"
122799
+ /*!*********************************************************************!*\
122800
+ !*** ./node_modules/@abaplint/transpiler/build/src/cds_metadata.js ***!
122801
+ \*********************************************************************/
122802
+ (__unused_webpack_module, exports, __webpack_require__) {
122803
+
122804
+ "use strict";
122805
+
122806
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
122807
+ if (k2 === undefined) k2 = k;
122808
+ var desc = Object.getOwnPropertyDescriptor(m, k);
122809
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
122810
+ desc = { enumerable: true, get: function() { return m[k]; } };
122811
+ }
122812
+ Object.defineProperty(o, k2, desc);
122813
+ }) : (function(o, m, k, k2) {
122814
+ if (k2 === undefined) k2 = k;
122815
+ o[k2] = m[k];
122816
+ }));
122817
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
122818
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
122819
+ }) : function(o, v) {
122820
+ o["default"] = v;
122821
+ });
122822
+ var __importStar = (this && this.__importStar) || (function () {
122823
+ var ownKeys = function(o) {
122824
+ ownKeys = Object.getOwnPropertyNames || function (o) {
122825
+ var ar = [];
122826
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
122827
+ return ar;
122828
+ };
122829
+ return ownKeys(o);
122830
+ };
122831
+ return function (mod) {
122832
+ if (mod && mod.__esModule) return mod;
122833
+ var result = {};
122834
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
122835
+ __setModuleDefault(result, mod);
122836
+ return result;
122837
+ };
122838
+ })();
122839
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
122840
+ exports.CDSMetadata = void 0;
122841
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
122842
+ const cds = abaplint.ExpressionsCDS;
122843
+ /** The metadata of a CDS entity, as far as it is written in its own source: its annotations, its
122844
+ * elements and its associations. Associations a projection or a view exposes from its source are
122845
+ * taken from that source's metadata. Metadata extensions (DDLX) are not merged. */
122846
+ class CDSMetadata {
122847
+ reg;
122848
+ cache = new Map();
122849
+ constructor(reg) {
122850
+ this.reg = reg;
122851
+ }
122852
+ build(obj) {
122853
+ const key = obj.getName().toUpperCase();
122854
+ if (this.cache.has(key)) {
122855
+ return this.cache.get(key);
122856
+ }
122857
+ this.cache.set(key, undefined); // cycle guard, associations can point back
122858
+ const tree = obj.getTree() ?? (obj.parse(), obj.getTree());
122859
+ const result = tree === undefined ? undefined : this.definition(tree);
122860
+ this.cache.set(key, result);
122861
+ return result;
122862
+ }
122863
+ definition(root) {
122864
+ const result = {
122865
+ definitionType: this.definitionType(root),
122866
+ root: root.findDirectTokenByText("ROOT") !== undefined,
122867
+ annotations: [],
122868
+ fields: [],
122869
+ associations: [],
122870
+ };
122871
+ for (const child of root.getChildren()) {
122872
+ if (child.get() instanceof cds.CDSAnnotation) {
122873
+ result.annotations.push(CDSMetadata.annotation(child));
122874
+ }
122875
+ else {
122876
+ break;
122877
+ }
122878
+ }
122879
+ const def = root.get();
122880
+ if (def instanceof cds.CDSDefineView || def instanceof cds.CDSDefineProjection) {
122881
+ const select = def instanceof cds.CDSDefineView ? root.findFirstExpression(cds.CDSSelect) : root;
122882
+ if (select !== undefined) {
122883
+ for (const a of select.findDirectExpressions(cds.CDSAssociation)) {
122884
+ result.associations.push(this.association(a, "ASSOCIATION"));
122885
+ }
122886
+ for (const c of select.findDirectExpressions(cds.CDSComposition)) {
122887
+ result.associations.push(this.association(c, "COMPOSITION"));
122888
+ }
122889
+ for (const e of select.findDirectExpressions(cds.CDSElement)) {
122890
+ this.element(e, result, this.sources(root));
122891
+ }
122892
+ }
122893
+ }
122894
+ else {
122895
+ this.signature(root, result);
122896
+ }
122897
+ return result;
122898
+ }
122899
+ definitionType(root) {
122900
+ const def = root.get();
122901
+ if (def instanceof cds.CDSDefineView) {
122902
+ return root.findDirectTokenByText("ENTITY") ? "VIEW_ENTITY" : "VIEW";
122903
+ }
122904
+ else if (def instanceof cds.CDSDefineProjection) {
122905
+ return "PROJECTION_VIEW";
122906
+ }
122907
+ else if (def instanceof cds.CDSDefineAbstract) {
122908
+ return "ABSTRACT_ENTITY";
122909
+ }
122910
+ else if (def instanceof cds.CDSDefineCustom) {
122911
+ return "CUSTOM_ENTITY";
122912
+ }
122913
+ else if (def instanceof cds.CDSDefineTableFunction) {
122914
+ return "TABLE_FUNCTION";
122915
+ }
122916
+ else if (def instanceof cds.CDSDefineHierarchy) {
122917
+ return "HIERARCHY";
122918
+ }
122919
+ else if (def instanceof cds.CDSDefineTableEntity) {
122920
+ return "TABLE_ENTITY";
122921
+ }
122922
+ else if (def instanceof cds.CDSDefineExternalEntity) {
122923
+ return "EXTERNAL_ENTITY";
122924
+ }
122925
+ return def.constructor.name;
122926
+ }
122927
+ /** The entities selected or projected from, for the associations they expose */
122928
+ sources(root) {
122929
+ const ret = [];
122930
+ if (root.get() instanceof cds.CDSDefineProjection) {
122931
+ // the first name is the projection's own, the second the projected entity
122932
+ const name = root.findDirectExpressions(cds.CDSName)[1];
122933
+ if (name) {
122934
+ ret.push(name.concatTokens().toUpperCase());
122935
+ }
122936
+ }
122937
+ for (const s of root.findAllExpressions(cds.CDSSource)) {
122938
+ const name = s.findDirectExpression(cds.CDSPrefixedName) ?? s.getFirstChild();
122939
+ if (name) {
122940
+ ret.push(name.concatTokens().replace(/ /g, "").toUpperCase());
122941
+ }
122942
+ }
122943
+ return ret;
122944
+ }
122945
+ sourceAssociation(sources, name) {
122946
+ for (const source of sources) {
122947
+ const obj = this.reg.getObject("DDLS", source);
122948
+ const found = obj ? this.build(obj)?.associations.find(a => a.name.toUpperCase() === name.toUpperCase()) : undefined;
122949
+ if (found) {
122950
+ return found;
122951
+ }
122952
+ }
122953
+ return undefined;
122954
+ }
122955
+ element(e, result, sources) {
122956
+ const annotations = e.findDirectExpressions(cds.CDSAnnotation).map(a => CDSMetadata.annotation(a));
122957
+ const prefixed = e.findDirectExpression(cds.CDSPrefixedName);
122958
+ const path = prefixed?.findAllExpressions(cds.CDSName).map(n => n.concatTokens()) ?? [];
122959
+ const as = e.findDirectExpressions(cds.CDSAs).map(a => this.alias(a)).find(a => a !== undefined);
122960
+ const redirected = this.redirection(e) ?? e.findDirectExpressions(cds.CDSAs).map(a => this.redirection(a)).find(r => r);
122961
+ let name = as;
122962
+ if (name === undefined && path.length > 0) {
122963
+ name = redirected ? path[0] : path[path.length - 1];
122964
+ }
122965
+ if (name === undefined && e.findDirectTokenByText("VIRTUAL")) {
122966
+ name = e.findFirstExpression(cds.CDSName)?.concatTokens();
122967
+ }
122968
+ if (name === undefined) {
122969
+ return;
122970
+ }
122971
+ // an exposed association, declared here or in a source
122972
+ const exposes = path.length > 0 ? path[path.length - 1] : name;
122973
+ const declared = path.length === 1
122974
+ ? result.associations.find(a => a.name.toUpperCase() === exposes.toUpperCase()) : undefined;
122975
+ if (declared) {
122976
+ declared.exposed = true;
122977
+ declared.annotations.push(...annotations);
122978
+ if (redirected) {
122979
+ declared.target = redirected.target;
122980
+ }
122981
+ return;
122982
+ }
122983
+ const inherited = redirected !== undefined || path.length > 0 ? this.sourceAssociation(sources, exposes) : undefined;
122984
+ if (inherited || redirected) {
122985
+ result.associations.push({
122986
+ name: name,
122987
+ target: redirected?.target ?? inherited.target,
122988
+ type: redirected?.type ?? inherited.type,
122989
+ cardinality: inherited?.cardinality,
122990
+ condition: inherited?.condition,
122991
+ defaultFilter: inherited?.defaultFilter,
122992
+ exposed: true,
122993
+ annotations: annotations,
122994
+ });
122995
+ return;
122996
+ }
122997
+ result.fields.push({
122998
+ name: name,
122999
+ key: e.findDirectTokenByText("KEY") !== undefined,
123000
+ virtual: e.findDirectTokenByText("VIRTUAL") !== undefined,
123001
+ annotations: annotations,
123002
+ });
123003
+ }
123004
+ alias(as) {
123005
+ const ret = [];
123006
+ for (const c of as.getChildren().slice(1)) {
123007
+ if (c.concatTokens().startsWith(":")) {
123008
+ break;
123009
+ }
123010
+ ret.push(c.concatTokens());
123011
+ }
123012
+ return ret.length > 0 ? ret.join("") : undefined;
123013
+ }
123014
+ /** ": REDIRECTED TO [PARENT | COMPOSITION CHILD] target", in an element or its alias */
123015
+ redirection(node) {
123016
+ const children = node.getChildren();
123017
+ const to = children.findIndex(c => c instanceof abaplint.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "TO"
123018
+ && children.some(r => r instanceof abaplint.Nodes.TokenNode && r.getFirstToken().getStr().toUpperCase() === "REDIRECTED"));
123019
+ if (to < 0) {
123020
+ return undefined;
123021
+ }
123022
+ const rest = children.slice(to + 1).map(c => c.concatTokens().toUpperCase());
123023
+ const target = children.slice(to + 1).find(c => c.get() instanceof cds.CDSName)?.concatTokens();
123024
+ if (target === undefined) {
123025
+ return undefined;
123026
+ }
123027
+ let type = "ASSOCIATION";
123028
+ if (rest.includes("PARENT")) {
123029
+ type = "TO_PARENT";
123030
+ }
123031
+ else if (rest.includes("CHILD")) {
123032
+ type = "COMPOSITION";
123033
+ }
123034
+ return { target, type };
123035
+ }
123036
+ /** abstract and custom entities and table functions list their elements inline: name : type ; */
123037
+ signature(root, result) {
123038
+ let inBody = false;
123039
+ let annotations = [];
123040
+ let key = false;
123041
+ let name;
123042
+ let assoc;
123043
+ for (const child of root.getChildren()) {
123044
+ const text = child instanceof abaplint.Nodes.TokenNode ? child.getFirstToken().getStr().toUpperCase() : "";
123045
+ if (inBody === false) {
123046
+ inBody = text === "{";
123047
+ continue;
123048
+ }
123049
+ if (child.get() instanceof cds.CDSAnnotation) {
123050
+ annotations.push(CDSMetadata.annotation(child));
123051
+ }
123052
+ else if (text === "KEY") {
123053
+ key = true;
123054
+ }
123055
+ else if (child.get() instanceof cds.CDSName && name === undefined) {
123056
+ name = child.concatTokens();
123057
+ }
123058
+ else if (child.get() instanceof cds.CDSAssociation || child.get() instanceof cds.CDSComposition) {
123059
+ assoc = child;
123060
+ }
123061
+ else if (text === ";" || text === "}") {
123062
+ if (name !== undefined && assoc !== undefined) {
123063
+ const a = this.association(assoc, assoc.get() instanceof cds.CDSComposition ? "COMPOSITION" : "ASSOCIATION");
123064
+ a.name = name;
123065
+ a.exposed = true;
123066
+ a.annotations = annotations;
123067
+ result.associations.push(a);
123068
+ }
123069
+ else if (name !== undefined) {
123070
+ result.fields.push({ name, key, virtual: false, annotations });
123071
+ }
123072
+ annotations = [];
123073
+ key = false;
123074
+ name = undefined;
123075
+ assoc = undefined;
123076
+ if (text === "}") {
123077
+ return;
123078
+ }
123079
+ }
123080
+ }
123081
+ }
123082
+ association(node, type) {
123083
+ const relation = node.findDirectExpression(cds.CDSRelation);
123084
+ const skip = new Set();
123085
+ relation?.findDirectExpressions(cds.CDSAs).forEach(a => skip.add(a));
123086
+ relation?.findDirectExpressions(cds.CDSParametersSelect).forEach(a => skip.add(a));
123087
+ const target = relation?.getChildren().filter(c => !skip.has(c)).map(c => c.concatTokens().replace(/ /g, "")).join("") || "";
123088
+ const as = relation?.findDirectExpression(cds.CDSAs);
123089
+ const conditions = node.findDirectExpressions(cds.CDSCondition);
123090
+ // the words before the target: ASSOCIATION [0..1] TO, ASSOCIATION OF MANY TO ONE, COMPOSITION OF ONE TO MANY, ...
123091
+ const words = [];
123092
+ for (const c of node.getChildren()) {
123093
+ if (c === relation) {
123094
+ break;
123095
+ }
123096
+ words.push(...c.concatTokens().toUpperCase().split(/\s+|(?=\[|\]|\.\.)|(?<=\[|\]|\.\.)/).filter(w => w !== ""));
123097
+ }
123098
+ if (words.includes("PARENT")) {
123099
+ type = "TO_PARENT";
123100
+ }
123101
+ return {
123102
+ name: (as ? this.alias(as) : undefined) ?? target,
123103
+ target: target,
123104
+ type: type,
123105
+ cardinality: this.cardinality(words, type),
123106
+ condition: conditions[0] ? CDSMetadata.text(conditions[0]) : undefined,
123107
+ defaultFilter: conditions[1] ? CDSMetadata.text(conditions[1]) : undefined,
123108
+ exposed: false,
123109
+ annotations: [],
123110
+ };
123111
+ }
123112
+ cardinality(words, type) {
123113
+ if (type === "TO_PARENT") {
123114
+ return { min: 1, max: 1 };
123115
+ }
123116
+ const open = words.indexOf("[");
123117
+ if (open >= 0) {
123118
+ const inside = words.slice(open + 1, words.indexOf("]")).join("").split("..");
123119
+ const num = (s) => s === "*" ? "*" : parseInt(s, 10);
123120
+ // [n] is [0..n]
123121
+ return inside.length === 1 ? { min: 0, max: num(inside[0]) } : { min: num(inside[0]), max: num(inside[1]) };
123122
+ }
123123
+ // the target side is the last one: TO ONE, OF MANY TO ONE, OF EXACT ONE, ONE TO MANY TO
123124
+ const sides = words.filter(w => w !== "ASSOCIATION" && w !== "COMPOSITION" && w !== "OF")
123125
+ .join(" ").split("TO").map(s => s.trim()).filter(s => s !== "");
123126
+ const side = sides[sides.length - 1];
123127
+ if (side === "EXACT ONE") {
123128
+ return { min: 1, max: 1 };
123129
+ }
123130
+ else if (side === "ONE") {
123131
+ return { min: 0, max: 1 };
123132
+ }
123133
+ else if (side === "MANY") {
123134
+ return { min: 0, max: "*" };
123135
+ }
123136
+ return type === "COMPOSITION" ? { min: 0, max: "*" } : { min: 0, max: 1 };
123137
+ }
123138
+ ///////////////////////////////
123139
+ /** the source text, tokens separated by single spaces except around path dots: $projection.id = _Item.id */
123140
+ static text(node) {
123141
+ let ret = "";
123142
+ let previous = "";
123143
+ for (const token of node.getTokens().map(t => t.getStr())) {
123144
+ ret += (ret === "" || token === "." || previous === "." ? "" : " ") + token;
123145
+ previous = token;
123146
+ }
123147
+ return ret;
123148
+ }
123149
+ static annotation(node) {
123150
+ const children = node.getChildren();
123151
+ const colon = children.findIndex(c => c instanceof abaplint.Nodes.TokenNode && c.getFirstToken().getStr() === ":");
123152
+ const nameParts = (colon < 0 ? children : children.slice(0, colon)).map(c => c.concatTokens());
123153
+ const name = nameParts.join("").replace(/\s/g, "").replace(/^@<?/, "");
123154
+ const valueNode = colon < 0 ? undefined : children[colon + 1];
123155
+ // an annotation without a value is true
123156
+ const value = valueNode instanceof abaplint.Nodes.ExpressionNode ? CDSMetadata.value(valueNode) : true;
123157
+ return { name, value };
123158
+ }
123159
+ static value(node) {
123160
+ const type = node.get();
123161
+ if (type instanceof cds.CDSAnnotationArray) {
123162
+ return node.getChildren()
123163
+ .filter((c) => c instanceof abaplint.Nodes.ExpressionNode)
123164
+ .map(c => CDSMetadata.value(c));
123165
+ }
123166
+ else if (type instanceof cds.CDSAnnotationObject) {
123167
+ const record = {};
123168
+ let path = [];
123169
+ let assigned = false;
123170
+ for (const c of node.getChildren()) {
123171
+ if (c.get() instanceof cds.CDSName) {
123172
+ path.push(c.concatTokens());
123173
+ }
123174
+ else if (c instanceof abaplint.Nodes.ExpressionNode) {
123175
+ CDSMetadata.set(record, path, CDSMetadata.value(c));
123176
+ assigned = true;
123177
+ }
123178
+ else {
123179
+ const text = c.getFirstToken().getStr();
123180
+ if ((text === "," || text === "}") && path.length > 0) {
123181
+ if (assigned === false) {
123182
+ CDSMetadata.set(record, path, true);
123183
+ }
123184
+ path = [];
123185
+ assigned = false;
123186
+ }
123187
+ }
123188
+ }
123189
+ return record;
123190
+ }
123191
+ return CDSMetadata.simple(node);
123192
+ }
123193
+ static simple(node) {
123194
+ const tokens = node.getTokens().map(t => t.getStr());
123195
+ const first = tokens[0] ?? "";
123196
+ if (first.startsWith("'")) {
123197
+ return first.substring(1, first.length - 1).replace(/''/g, "'");
123198
+ }
123199
+ else if (first === "#" && tokens[1] === "(") {
123200
+ return { "#()": tokens.slice(2, tokens.length - 1).join(" ") };
123201
+ }
123202
+ else if (first.startsWith("#")) {
123203
+ return { "#": first.substring(1) };
123204
+ }
123205
+ const lower = tokens.join("").toLowerCase();
123206
+ if (lower === "true" || lower === "false") {
123207
+ return lower === "true";
123208
+ }
123209
+ else if (lower === "null") {
123210
+ return null;
123211
+ }
123212
+ const num = Number(tokens.join(""));
123213
+ return isNaN(num) ? tokens.join("") : num;
123214
+ }
123215
+ static set(record, path, value) {
123216
+ let current = record;
123217
+ for (const part of path.slice(0, path.length - 1)) {
123218
+ const next = current[part];
123219
+ if (typeof next !== "object" || next === null || Array.isArray(next)) {
123220
+ current[part] = {};
123221
+ }
123222
+ current = current[part];
123223
+ }
123224
+ current[path[path.length - 1]] = value;
123225
+ }
123226
+ }
123227
+ exports.CDSMetadata = CDSMetadata;
123228
+ //# sourceMappingURL=cds_metadata.js.map
123229
+
123230
+ /***/ },
123231
+
122743
123232
  /***/ "./node_modules/@abaplint/transpiler/build/src/chunk.js"
122744
123233
  /*!**************************************************************!*\
122745
123234
  !*** ./node_modules/@abaplint/transpiler/build/src/chunk.js ***!
@@ -123165,14 +123654,21 @@ class CDSDatabaseView {
123165
123654
  for (const join of select.findDirectExpressions(cds.CDSJoin)) {
123166
123655
  from.push(this.join(join));
123167
123656
  }
123168
- const elements = select.findDirectExpressions(cds.CDSElement);
123657
+ // associations are not columns, neither are virtual elements
123658
+ const associations = this.associationNames(select);
123659
+ const elements = select.findDirectExpressions(cds.CDSElement).filter(e => {
123660
+ const path = e.findDirectExpression(cds.CDSPrefixedName)?.findAllExpressions(cds.CDSName) || [];
123661
+ const last = path[path.length - 1]?.concatTokens().toUpperCase();
123662
+ return e.findDirectTokenByText("VIRTUAL") === undefined && (last === undefined || !associations.has(last));
123663
+ });
123169
123664
  if (elements.length === 0) {
123170
123665
  return this.unsupported("expected explicit projected fields");
123171
123666
  }
123172
123667
  const columns = elements.map(e => this.element(e)).join(", ");
123173
123668
  let where = "";
123174
123669
  for (const child of select.getChildren()) {
123175
- if (child === source || child.get() instanceof cds.CDSJoin || child.get() instanceof cds.CDSElement) {
123670
+ if (child === source || child.get() instanceof cds.CDSJoin || child.get() instanceof cds.CDSElement
123671
+ || child.get() instanceof cds.CDSAssociation || child.get() instanceof cds.CDSComposition) {
123176
123672
  continue;
123177
123673
  }
123178
123674
  else if (child.get() instanceof cds.CDSWhere) {
@@ -123185,6 +123681,26 @@ class CDSDatabaseView {
123185
123681
  const distinct = select.findDirectTokenByText("DISTINCT") ? "DISTINCT " : "";
123186
123682
  return `CREATE VIEW ${this.quote(this.viewName)} AS SELECT ${distinct}${columns} FROM ${from.join(" ")}${where};`;
123187
123683
  }
123684
+ /** Aliases of the associations declared here or in the CDS sources, they can be exposed as elements */
123685
+ associationNames(select) {
123686
+ const ret = new Set();
123687
+ for (const a of [...select.findDirectExpressions(cds.CDSAssociation), ...select.findDirectExpressions(cds.CDSComposition)]) {
123688
+ const relation = a.findDirectExpression(cds.CDSRelation);
123689
+ const name = relation?.findDirectExpression(cds.CDSAs)?.findDirectExpression(cds.CDSName) || relation?.getFirstChild();
123690
+ if (name) {
123691
+ ret.add(name.concatTokens().toUpperCase());
123692
+ }
123693
+ }
123694
+ for (const s of select.findAllExpressions(cds.CDSSource)) {
123695
+ const name = s.findDirectExpression(cds.CDSPrefixedName)?.concatTokens().replace(/ /g, "");
123696
+ const ddls = name ? this.reg.getObject("DDLS", name) : undefined;
123697
+ ddls?.parse();
123698
+ for (const a of ddls?.getParsedData()?.associations || []) {
123699
+ ret.add((a.as || a.name).toUpperCase());
123700
+ }
123701
+ }
123702
+ return ret;
123703
+ }
123188
123704
  source(node) {
123189
123705
  const nameNode = node.findDirectExpression(cds.CDSPrefixedName);
123190
123706
  if (nameNode === undefined) {
@@ -125531,14 +126047,83 @@ const type_name_or_infer_1 = __webpack_require__(/*! ./type_name_or_infer */ "./
125531
126047
  const component_chain_1 = __webpack_require__(/*! ./component_chain */ "./node_modules/@abaplint/transpiler/build/src/expressions/component_chain.js");
125532
126048
  const unique_identifier_1 = __webpack_require__(/*! ../unique_identifier */ "./node_modules/@abaplint/transpiler/build/src/unique_identifier.js");
125533
126049
  class CorrespondingBodyTranspiler {
125534
- transpile(typ, body, traversal) {
126050
+ /** genericTarget: code of the target the result is assigned to, used when the inferred type is generic,
126051
+ * the result then gets the runtime type of the target, eg. "ct = CORRESPONDING #( ... )" with
126052
+ * "CHANGING ct TYPE STANDARD TABLE" */
126053
+ transpile(typ, body, traversal, genericTarget) {
125535
126054
  if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
125536
126055
  throw new Error("CorrespondingBodyTranspiler, Expected TypeNameOrInfer");
125537
126056
  }
125538
126057
  const type = new type_name_or_infer_1.TypeNameOrInfer().findType(typ, traversal);
126058
+ if (genericTarget !== undefined && type.isGeneric() === true) {
126059
+ return this.transpileGeneric(body, traversal, genericTarget);
126060
+ }
126061
+ const { source, base, mapping } = this.parseBody(body, traversal);
125539
126062
  let target = traversal.toType(type);
125540
- let source;
126063
+ if (base !== undefined) {
126064
+ target = `abap.statements.moveCorresponding(${base.getCode()}, ${target})`;
126065
+ }
125541
126066
  const isTableType = type instanceof core_1.BasicTypes.TableType;
126067
+ const ret = new chunk_1.Chunk();
126068
+ const id = unique_identifier_1.UniqueIdentifier.get();
126069
+ const sourceId = unique_identifier_1.UniqueIdentifier.get();
126070
+ ret.appendString("(await (async () => {\n");
126071
+ ret.appendString(`const ${id} = ${target};\n`);
126072
+ ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
126073
+ if (isTableType) {
126074
+ const rowTargetType = traversal.toType(type.getRowType());
126075
+ const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
126076
+ const targetRowId = unique_identifier_1.UniqueIdentifier.get();
126077
+ ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
126078
+ ret.appendString(`const ${targetRowId} = ${rowTargetType};\n`);
126079
+ ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
126080
+ ret.appendString(this.mappingCode(mapping, targetRowId, sourceRowId, traversal));
126081
+ ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
126082
+ ret.appendString("}\n");
126083
+ }
126084
+ else {
126085
+ ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
126086
+ ret.appendString(this.mappingCode(mapping, id, sourceId, traversal));
126087
+ }
126088
+ ret.appendString("return " + id + ";\n");
126089
+ ret.appendString("})())");
126090
+ return ret;
126091
+ }
126092
+ /** the type is only known at runtime, it is taken from the target, a table or a structure */
126093
+ transpileGeneric(body, traversal, genericTarget) {
126094
+ const { source, base, mapping } = this.parseBody(body, traversal);
126095
+ const ret = new chunk_1.Chunk();
126096
+ const id = unique_identifier_1.UniqueIdentifier.get();
126097
+ const sourceId = unique_identifier_1.UniqueIdentifier.get();
126098
+ const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
126099
+ const targetRowId = unique_identifier_1.UniqueIdentifier.get();
126100
+ ret.appendString("(await (async () => {\n");
126101
+ const pointer = `(${genericTarget} instanceof abap.types.FieldSymbol ? ${genericTarget}.getPointer() : ${genericTarget})`;
126102
+ ret.appendString(`const ${id} = ${pointer}.clone();\n`);
126103
+ ret.appendString(`${id}.clear();\n`);
126104
+ if (base !== undefined) {
126105
+ ret.appendString(`${id}.set(${base.getCode()});\n`);
126106
+ }
126107
+ ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
126108
+ ret.appendString(`if (${id} instanceof abap.types.Table || ${id} instanceof abap.types.HashedTable) {\n`);
126109
+ ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
126110
+ ret.appendString(`const ${targetRowId} = ${id}.getRowType().clone();\n`);
126111
+ ret.appendString(`${targetRowId}.clear();\n`);
126112
+ ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
126113
+ ret.appendString(this.mappingCode(mapping, targetRowId, sourceRowId, traversal));
126114
+ ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
126115
+ ret.appendString("}\n");
126116
+ ret.appendString("} else {\n");
126117
+ ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
126118
+ ret.appendString(this.mappingCode(mapping, id, sourceId, traversal));
126119
+ ret.appendString("}\n");
126120
+ ret.appendString("return " + id + ";\n");
126121
+ ret.appendString("})())");
126122
+ return ret;
126123
+ }
126124
+ parseBody(body, traversal) {
126125
+ let source;
126126
+ let base;
125542
126127
  const mapping = [];
125543
126128
  for (const child of body.getChildren()) {
125544
126129
  const c = child.get();
@@ -125546,8 +126131,7 @@ class CorrespondingBodyTranspiler {
125546
126131
  source = traversal.traverse(child);
125547
126132
  }
125548
126133
  else if (c instanceof core_1.Expressions.CorrespondingBodyBase && child instanceof core_1.Nodes.ExpressionNode) {
125549
- source = traversal.traverse(child?.findDirectExpression(core_1.Expressions.Source));
125550
- target = `abap.statements.moveCorresponding(${source.getCode()}, ${target})`;
126134
+ base = traversal.traverse(child.findDirectExpression(core_1.Expressions.Source));
125551
126135
  }
125552
126136
  else if (c instanceof core_1.Expressions.CorrespondingBodyMapping && child instanceof core_1.Nodes.ExpressionNode) {
125553
126137
  let mappingRow = { componentName: undefined, componentChain: undefined };
@@ -125566,38 +126150,16 @@ class CorrespondingBodyTranspiler {
125566
126150
  throw new Error("CorrespondingBodyTranspiler, todo, " + c.constructor.name + ", " + body.concatTokens());
125567
126151
  }
125568
126152
  }
125569
- const ret = new chunk_1.Chunk();
125570
- const id = unique_identifier_1.UniqueIdentifier.get();
125571
- const sourceId = unique_identifier_1.UniqueIdentifier.get();
125572
- ret.appendString("(await (async () => {\n");
125573
- ret.appendString(`const ${id} = ${target};\n`);
125574
- ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
125575
- if (isTableType) {
125576
- const rowTargetType = traversal.toType(type.getRowType());
125577
- const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
125578
- const targetRowId = unique_identifier_1.UniqueIdentifier.get();
125579
- ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
125580
- ret.appendString(`const ${targetRowId} = ${rowTargetType};\n`);
125581
- ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
125582
- for (const map of mapping) {
125583
- const componentName = map.componentName.concatTokens().toLowerCase();
125584
- const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
125585
- ret.appendString(`${targetRowId}.get().${componentName}.set(${sourceRowId}.get().${chain});\n`);
125586
- }
125587
- ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
125588
- ret.appendString("}\n");
125589
- }
125590
- else {
125591
- ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
125592
- for (const map of mapping) {
125593
- const componentName = map.componentName.concatTokens().toLowerCase();
125594
- const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
125595
- ret.appendString(`${id}.get().${componentName}.set(${sourceId}.get().${chain});\n`);
125596
- }
126153
+ return { source: source, base, mapping };
126154
+ }
126155
+ mappingCode(mapping, targetId, sourceId, traversal) {
126156
+ let code = "";
126157
+ for (const map of mapping) {
126158
+ const componentName = map.componentName.concatTokens().toLowerCase();
126159
+ const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
126160
+ code += `${targetId}.get().${componentName}.set(${sourceId}.get().${chain});\n`;
125597
126161
  }
125598
- ret.appendString("return " + id + ";\n");
125599
- ret.appendString("})())");
125600
- return ret;
126162
+ return code;
125601
126163
  }
125602
126164
  }
125603
126165
  exports.CorrespondingBodyTranspiler = CorrespondingBodyTranspiler;
@@ -131030,6 +131592,108 @@ exports.HandleABAP = HandleABAP;
131030
131592
 
131031
131593
  /***/ },
131032
131594
 
131595
+ /***/ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js"
131596
+ /*!****************************************************************************************!*\
131597
+ !*** ./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js ***!
131598
+ \****************************************************************************************/
131599
+ (__unused_webpack_module, exports, __webpack_require__) {
131600
+
131601
+ "use strict";
131602
+
131603
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
131604
+ if (k2 === undefined) k2 = k;
131605
+ var desc = Object.getOwnPropertyDescriptor(m, k);
131606
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
131607
+ desc = { enumerable: true, get: function() { return m[k]; } };
131608
+ }
131609
+ Object.defineProperty(o, k2, desc);
131610
+ }) : (function(o, m, k, k2) {
131611
+ if (k2 === undefined) k2 = k;
131612
+ o[k2] = m[k];
131613
+ }));
131614
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
131615
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
131616
+ }) : function(o, v) {
131617
+ o["default"] = v;
131618
+ });
131619
+ var __importStar = (this && this.__importStar) || (function () {
131620
+ var ownKeys = function(o) {
131621
+ ownKeys = Object.getOwnPropertyNames || function (o) {
131622
+ var ar = [];
131623
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
131624
+ return ar;
131625
+ };
131626
+ return ownKeys(o);
131627
+ };
131628
+ return function (mod) {
131629
+ if (mod && mod.__esModule) return mod;
131630
+ var result = {};
131631
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
131632
+ __setModuleDefault(result, mod);
131633
+ return result;
131634
+ };
131635
+ })();
131636
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
131637
+ exports.HandleDataDefinition = void 0;
131638
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
131639
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
131640
+ const transpile_types_1 = __webpack_require__(/*! ../transpile_types */ "./node_modules/@abaplint/transpiler/build/src/transpile_types.js");
131641
+ const type_factory_registry_1 = __webpack_require__(/*! ../type_factory_registry */ "./node_modules/@abaplint/transpiler/build/src/type_factory_registry.js");
131642
+ // CDS entities: the row type like tables and views, plus the CDS metadata, eg. for XCO
131643
+ class HandleDataDefinition {
131644
+ metadata;
131645
+ constructor(metadata) {
131646
+ this.metadata = metadata;
131647
+ }
131648
+ runObject(obj, reg) {
131649
+ if (obj.findSourceFile() === undefined) {
131650
+ return [];
131651
+ }
131652
+ const filename = obj.getName().toLowerCase().replace(/\//g, "#") + ".ddls.mjs";
131653
+ const cds = this.metadata.build(obj);
131654
+ const type = this.withoutAssociations(obj.parseType(reg), cds);
131655
+ const typeFactory = new type_factory_registry_1.TypeFactoryRegistry(filename);
131656
+ const body = `abap.DDIC["${obj.getName().toUpperCase()}"] = {
131657
+ "objectType": "DDLS",
131658
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
131659
+ "keyFields": ${JSON.stringify(cds?.fields.filter(f => f.key).map(f => f.name.toUpperCase()) ?? [])},
131660
+ "description": ${JSON.stringify(obj.getDescription())},
131661
+ "sqlViewName": ${JSON.stringify(obj.getSQLViewName())},
131662
+ "cds": ${JSON.stringify(cds)},
131663
+ };`;
131664
+ const chunk = new chunk_1.Chunk(body);
131665
+ const helpers = typeFactory.finalize(chunk);
131666
+ const outputChunk = helpers === "" ? chunk : new chunk_1.Chunk(helpers).appendChunk(chunk);
131667
+ const output = {
131668
+ object: {
131669
+ name: obj.getName(),
131670
+ type: obj.getType(),
131671
+ },
131672
+ filename: filename,
131673
+ chunk: outputChunk,
131674
+ requires: [],
131675
+ exports: [],
131676
+ };
131677
+ return [output];
131678
+ }
131679
+ /** exposed associations are elements of the signature, but not components of the row type */
131680
+ withoutAssociations(type, cds) {
131681
+ if (!(type instanceof abaplint.BasicTypes.StructureType) || cds === undefined) {
131682
+ return type;
131683
+ }
131684
+ const associations = new Set(cds.associations.map(a => a.name.toUpperCase()));
131685
+ const components = type.getComponents().filter(c => !associations.has(c.name.toUpperCase()));
131686
+ if (components.length === type.getComponents().length) {
131687
+ return type;
131688
+ }
131689
+ return new abaplint.BasicTypes.StructureType(components, type.getQualifiedName(), type.getDDICName(), type.getDescription());
131690
+ }
131691
+ }
131692
+ exports.HandleDataDefinition = HandleDataDefinition;
131693
+ //# sourceMappingURL=handle_data_definition.js.map
131694
+
131695
+ /***/ },
131696
+
131033
131697
  /***/ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_element.js"
131034
131698
  /*!*************************************************************************************!*\
131035
131699
  !*** ./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_element.js ***!
@@ -131759,6 +132423,8 @@ const handle_abap_1 = __webpack_require__(/*! ./handlers/handle_abap */ "./node_
131759
132423
  const handle_data_element_1 = __webpack_require__(/*! ./handlers/handle_data_element */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_element.js");
131760
132424
  const handle_table_type_1 = __webpack_require__(/*! ./handlers/handle_table_type */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_table_type.js");
131761
132425
  const handle_view_1 = __webpack_require__(/*! ./handlers/handle_view */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_view.js");
132426
+ const handle_data_definition_1 = __webpack_require__(/*! ./handlers/handle_data_definition */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js");
132427
+ const cds_metadata_1 = __webpack_require__(/*! ./cds_metadata */ "./node_modules/@abaplint/transpiler/build/src/cds_metadata.js");
131762
132428
  const handle_enqu_1 = __webpack_require__(/*! ./handlers/handle_enqu */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_enqu.js");
131763
132429
  const handle_type_pool_1 = __webpack_require__(/*! ./handlers/handle_type_pool */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_type_pool.js");
131764
132430
  const handle_w3mi_1 = __webpack_require__(/*! ./handlers/handle_w3mi */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_w3mi.js");
@@ -131805,6 +132471,7 @@ class Transpiler {
131805
132471
  databaseSetup: dbSetup,
131806
132472
  reg: reg,
131807
132473
  };
132474
+ const cdsMetadata = new cds_metadata_1.CDSMetadata(reg);
131808
132475
  progress?.set(reg.getObjectCount().total, "Building");
131809
132476
  for (const obj of reg.getObjects()) {
131810
132477
  await progress?.tick("Building, " + obj.getName());
@@ -131832,6 +132499,9 @@ class Transpiler {
131832
132499
  else if (obj instanceof abaplint.Objects.View) {
131833
132500
  output.objects.push(...new handle_view_1.HandleView().runObject(obj, reg));
131834
132501
  }
132502
+ else if (obj instanceof abaplint.Objects.DataDefinition) {
132503
+ output.objects.push(...new handle_data_definition_1.HandleDataDefinition(cdsMetadata).runObject(obj, reg));
132504
+ }
131835
132505
  else if (obj instanceof abaplint.Objects.LockObject) {
131836
132506
  output.objects.push(...new handle_enqu_1.HandleEnqu().runObject(obj, reg));
131837
132507
  }
@@ -131986,12 +132656,12 @@ class Initialization {
131986
132656
  script(reg, dbSetup, options, useImport) {
131987
132657
  let ret = "";
131988
132658
  if (useImport === true) {
131989
- ret = `/* eslint-disable import/newline-after-import */
132659
+ ret = `/* eslint-disable import/newline-after-import */
131990
132660
  import "./_top.mjs";\n`;
131991
132661
  }
131992
132662
  else {
131993
- ret = `/* eslint-disable import/newline-after-import */
131994
- import runtime from "@abaplint/runtime";
132663
+ ret = `/* eslint-disable import/newline-after-import */
132664
+ import runtime from "@abaplint/runtime";
131995
132665
  globalThis.abap = new runtime.ABAP();\n`;
131996
132666
  }
131997
132667
  if (options?.setup?.filename === undefined || options?.setup?.filename === "") {
@@ -132059,7 +132729,8 @@ globalThis.abap = new runtime.ABAP();\n`;
132059
132729
  || obj instanceof abaplint.Objects.WebMIME
132060
132730
  || obj instanceof abaplint.Objects.TypePool
132061
132731
  || obj instanceof abaplint.Objects.TableType
132062
- || obj instanceof abaplint.Objects.View) {
132732
+ || obj instanceof abaplint.Objects.View
132733
+ || (obj instanceof abaplint.Objects.DataDefinition && obj.findSourceFile() !== undefined)) {
132063
132734
  list.push(imp(this.layout.objectModule(obj)));
132064
132735
  }
132065
132736
  }
@@ -132261,7 +132932,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
132261
132932
  exports.OutputLayout = exports.DDIC_MODULE = exports.DDIC_TYPES = void 0;
132262
132933
  exports.importPath = importPath;
132263
132934
  /** Object types whose module only sets abap.DDIC[...] */
132264
- exports.DDIC_TYPES = new Set(["DTEL", "TABL", "TTYP", "VIEW"]);
132935
+ exports.DDIC_TYPES = new Set(["DDLS", "DTEL", "TABL", "TTYP", "VIEW"]);
132265
132936
  /** Per folder module holding all its DDIC definitions. Object filenames never start
132266
132937
  * with an underscore, so it cannot collide with an object module. Loading tens of
132267
132938
  * thousands of tiny modules dominates startup, one module per folder avoids that. */
@@ -132846,64 +133517,82 @@ var __importStar = (this && this.__importStar) || (function () {
132846
133517
  };
132847
133518
  })();
132848
133519
  Object.defineProperty(exports, "__esModule", ({ value: true }));
132849
- exports.sharedMedium = sharedMedium;
133520
+ exports.dataClusterMedium = dataClusterMedium;
132850
133521
  exports.mediumOptions = mediumOptions;
132851
133522
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
132852
- function sharedMedium(node, keyword, traversal) {
133523
+ function word(node) {
133524
+ return node instanceof abaplint.Nodes.TokenNode ? node.getFirstToken().getStr().toUpperCase() : "";
133525
+ }
133526
+ function dataClusterMedium(node, keyword, traversal) {
132853
133527
  const children = node.getChildren();
132854
- let at = -1;
132855
- for (let i = 0; i < children.length - 1; i++) {
132856
- const here = children[i];
132857
- const next = children[i + 1];
132858
- if (here instanceof abaplint.Nodes.TokenNode && here.getFirstToken().getStr().toUpperCase() === keyword
132859
- && next instanceof abaplint.Nodes.TokenNode && next.getFirstToken().getStr().toUpperCase() === "SHARED") {
132860
- at = i + 1;
132861
- break;
132862
- }
132863
- }
132864
- if (at < 0) {
133528
+ const at = children.findIndex(c => word(c) === keyword) + 1;
133529
+ if (at === 0) {
132865
133530
  return undefined;
132866
133531
  }
132867
- const kind = children[at + 1]?.getFirstToken().getStr().toUpperCase();
132868
- if (kind !== "MEMORY" && kind !== "BUFFER") {
132869
- return undefined;
133532
+ let ret;
133533
+ let additions;
133534
+ if (word(children[at]) === "MEMORY") {
133535
+ ret = { medium: "MEMORY" };
133536
+ additions = at + 1;
132870
133537
  }
132871
- const tableNode = children[at + 2];
132872
- const areaNode = children[at + 4];
132873
- if (!(tableNode instanceof abaplint.Nodes.ExpressionNode) || areaNode === undefined) {
132874
- return undefined;
133538
+ else if (word(children[at]) === "DATA" && word(children[at + 1]) === "BUFFER"
133539
+ && children[at + 2] instanceof abaplint.Nodes.ExpressionNode) {
133540
+ return { medium: "DATA BUFFER", buffer: traversal.traverse(children[at + 2]).getCode() };
132875
133541
  }
132876
- const ret = {
132877
- medium: kind === "MEMORY" ? "SHARED MEMORY" : "SHARED BUFFER",
132878
- table: tableNode.concatTokens().toUpperCase(),
132879
- area: areaNode.getFirstToken().getStr().toUpperCase(),
132880
- };
132881
- // after the "( ar )": the additions in any order, ID / CLIENT followed by
132882
- // a Source; FROM wa (EXPORT) and TO wa (IMPORT) name the dbtab's work area,
132883
- // whose extra fields have no place in this store and are not read
132884
- for (let i = at + 6; i < children.length - 1; i++) {
133542
+ else {
133543
+ // DATABASE dbtab(ar) ... / SHARED MEMORY|BUFFER dbtab(ar) ...
133544
+ let tableAt;
133545
+ if (word(children[at]) === "DATABASE") {
133546
+ ret = { medium: "DATABASE" };
133547
+ tableAt = at + 1;
133548
+ }
133549
+ else if (word(children[at]) === "SHARED" && (word(children[at + 1]) === "MEMORY" || word(children[at + 1]) === "BUFFER")) {
133550
+ ret = { medium: word(children[at + 1]) === "MEMORY" ? "SHARED MEMORY" : "SHARED BUFFER" };
133551
+ tableAt = at + 2;
133552
+ }
133553
+ else {
133554
+ return undefined;
133555
+ }
133556
+ const tableNode = children[tableAt];
133557
+ const areaNode = children[tableAt + 2];
133558
+ if (!(tableNode instanceof abaplint.Nodes.ExpressionNode) || areaNode === undefined) {
133559
+ return undefined;
133560
+ }
133561
+ ret.table = tableNode.concatTokens().toUpperCase();
133562
+ ret.area = areaNode.getFirstToken().getStr().toUpperCase();
133563
+ additions = tableAt + 4;
133564
+ }
133565
+ // the additions in any order, ID / CLIENT followed by a Source; FROM wa
133566
+ // (EXPORT) and TO wa (IMPORT) name the dbtab's work area, whose extra
133567
+ // fields have no place in this store and are not read
133568
+ for (let i = additions; i < children.length - 1; i++) {
132885
133569
  const here = children[i];
132886
133570
  const next = children[i + 1];
132887
133571
  if (!(here instanceof abaplint.Nodes.TokenNode) || !(next instanceof abaplint.Nodes.ExpressionNode)) {
132888
133572
  continue;
132889
133573
  }
132890
- const word = here.getFirstToken().getStr().toUpperCase();
132891
- if (word === "ID") {
133574
+ if (word(here) === "ID") {
132892
133575
  ret.id = traversal.traverse(next).getCode();
132893
133576
  }
132894
- else if (word === "CLIENT") {
133577
+ else if (word(here) === "CLIENT") {
132895
133578
  ret.client = traversal.traverse(next).getCode();
132896
133579
  }
133580
+ else if (word(here) === "USING") {
133581
+ return undefined;
133582
+ }
132897
133583
  }
132898
- if (ret.id === undefined) {
133584
+ if (ret.medium !== "MEMORY" && ret.id === undefined) {
132899
133585
  return undefined;
132900
133586
  }
132901
133587
  return ret;
132902
133588
  }
132903
133589
  function mediumOptions(medium) {
132904
- return `medium: ${JSON.stringify(medium.medium)}, table: ${JSON.stringify(medium.table)}, `
132905
- + `area: ${JSON.stringify(medium.area)}, id: ${medium.id}`
132906
- + (medium.client === undefined ? "" : `, client: ${medium.client}`);
133590
+ return `medium: ${JSON.stringify(medium.medium)}`
133591
+ + (medium.table === undefined ? "" : `, table: ${JSON.stringify(medium.table)}`)
133592
+ + (medium.area === undefined ? "" : `, area: ${JSON.stringify(medium.area)}`)
133593
+ + (medium.id === undefined ? "" : `, id: ${medium.id}`)
133594
+ + (medium.client === undefined ? "" : `, client: ${medium.client}`)
133595
+ + (medium.buffer === undefined ? "" : `, buffer: ${medium.buffer}`);
132907
133596
  }
132908
133597
  //# sourceMappingURL=_data_cluster.js.map
132909
133598
 
@@ -136156,9 +136845,14 @@ exports.DataTranspiler = DataTranspiler;
136156
136845
  Object.defineProperty(exports, "__esModule", ({ value: true }));
136157
136846
  exports.DeleteClusterTranspiler = void 0;
136158
136847
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
136848
+ const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
136159
136849
  class DeleteClusterTranspiler {
136160
- transpile(_node, _traversal) {
136161
- return new chunk_1.Chunk(`throw new Error("DELETE CLUSTER, not supported, transpiler");`);
136850
+ transpile(node, traversal) {
136851
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
136852
+ if (medium === undefined) {
136853
+ return new chunk_1.Chunk(`throw new Error("DELETE CLUSTER, not supported, transpiler");`);
136854
+ }
136855
+ return new chunk_1.Chunk(`abap.statements.deleteCluster({${(0, _data_cluster_1.mediumOptions)(medium)}});`);
136162
136856
  }
136163
136857
  }
136164
136858
  exports.DeleteClusterTranspiler = DeleteClusterTranspiler;
@@ -136441,9 +137135,14 @@ exports.DeleteInternalTranspiler = DeleteInternalTranspiler;
136441
137135
  Object.defineProperty(exports, "__esModule", ({ value: true }));
136442
137136
  exports.DeleteMemoryTranspiler = void 0;
136443
137137
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137138
+ const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
136444
137139
  class DeleteMemoryTranspiler {
136445
- transpile(_node, _traversal) {
136446
- return new chunk_1.Chunk(`throw new Error("DeleteMemory, not supported, transpiler");`);
137140
+ transpile(node, traversal) {
137141
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
137142
+ if (medium === undefined) {
137143
+ return new chunk_1.Chunk(`throw new Error("DeleteMemory, not supported, transpiler");`);
137144
+ }
137145
+ return new chunk_1.Chunk(`abap.statements.deleteCluster({${(0, _data_cluster_1.mediumOptions)(medium)}});`);
136447
137146
  }
136448
137147
  }
136449
137148
  exports.DeleteMemoryTranspiler = DeleteMemoryTranspiler;
@@ -137371,7 +138070,7 @@ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/tr
137371
138070
  const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
137372
138071
  class ExportTranspiler {
137373
138072
  transpile(node, traversal) {
137374
- const medium = (0, _data_cluster_1.sharedMedium)(node, "TO", traversal);
138073
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "TO", traversal);
137375
138074
  const parameters = medium === undefined ? undefined : this.parameters(node, traversal);
137376
138075
  if (medium === undefined || parameters === undefined) {
137377
138076
  return new chunk_1.Chunk(`throw new Error("Export, transpiler todo");`);
@@ -137959,12 +138658,47 @@ exports.FreeTranspiler = FreeTranspiler;
137959
138658
 
137960
138659
  "use strict";
137961
138660
 
138661
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
138662
+ if (k2 === undefined) k2 = k;
138663
+ var desc = Object.getOwnPropertyDescriptor(m, k);
138664
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
138665
+ desc = { enumerable: true, get: function() { return m[k]; } };
138666
+ }
138667
+ Object.defineProperty(o, k2, desc);
138668
+ }) : (function(o, m, k, k2) {
138669
+ if (k2 === undefined) k2 = k;
138670
+ o[k2] = m[k];
138671
+ }));
138672
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
138673
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
138674
+ }) : function(o, v) {
138675
+ o["default"] = v;
138676
+ });
138677
+ var __importStar = (this && this.__importStar) || (function () {
138678
+ var ownKeys = function(o) {
138679
+ ownKeys = Object.getOwnPropertyNames || function (o) {
138680
+ var ar = [];
138681
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
138682
+ return ar;
138683
+ };
138684
+ return ownKeys(o);
138685
+ };
138686
+ return function (mod) {
138687
+ if (mod && mod.__esModule) return mod;
138688
+ var result = {};
138689
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
138690
+ __setModuleDefault(result, mod);
138691
+ return result;
138692
+ };
138693
+ })();
137962
138694
  Object.defineProperty(exports, "__esModule", ({ value: true }));
137963
138695
  exports.FreeMemoryTranspiler = void 0;
138696
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
137964
138697
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137965
138698
  class FreeMemoryTranspiler {
137966
- transpile(_node, _traversal) {
137967
- return new chunk_1.Chunk(`throw new Error("FreeMemory, not supported, transpiler");`);
138699
+ transpile(node, traversal) {
138700
+ const id = node.findDirectExpression(abaplint.Expressions.Source);
138701
+ return new chunk_1.Chunk(`abap.statements.freeMemory({${id === undefined ? "" : "id: " + traversal.traverse(id).getCode()}});`);
137968
138702
  }
137969
138703
  }
137970
138704
  exports.FreeMemoryTranspiler = FreeMemoryTranspiler;
@@ -138812,7 +139546,7 @@ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/tr
138812
139546
  const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
138813
139547
  class ImportTranspiler {
138814
139548
  transpile(node, traversal) {
138815
- const medium = (0, _data_cluster_1.sharedMedium)(node, "FROM", traversal);
139549
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
138816
139550
  const parameters = medium === undefined ? undefined : this.parameters(node, traversal);
138817
139551
  if (medium === undefined || parameters === undefined) {
138818
139552
  return new chunk_1.Chunk(`throw new Error("Import, transpiler todo");`);
@@ -139526,6 +140260,11 @@ class InsertInternalTranspiler {
139526
140260
  if (index) {
139527
140261
  options.push("index: " + traversal.traverse(index).getCode());
139528
140262
  }
140263
+ else if (!concat.startsWith("INSERT LINES OF ") && !concat.includes(" INTO TABLE ") && concat.includes(" INTO ")
140264
+ && node.findDirectExpression(abaplint.Expressions.Target) !== undefined) {
140265
+ // INSERT wa INTO itab: in a LOOP over itab, in front of the current row
140266
+ options.push("currentRow: true");
140267
+ }
139529
140268
  if (concat.includes(" REFERENCE INTO ")) {
139530
140269
  const targets = node.findDirectExpressions(abaplint.Expressions.Target);
139531
140270
  options.push("referenceInto: " + traversal.traverse(targets[1]).getCode());
@@ -140955,6 +141694,8 @@ exports.MoveTranspiler = void 0;
140955
141694
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
140956
141695
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
140957
141696
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/transpiler/build/src/expressions/source.js");
141697
+ const type_name_or_infer_1 = __webpack_require__(/*! ../expressions/type_name_or_infer */ "./node_modules/@abaplint/transpiler/build/src/expressions/type_name_or_infer.js");
141698
+ const corresponding_body_1 = __webpack_require__(/*! ../expressions/corresponding_body */ "./node_modules/@abaplint/transpiler/build/src/expressions/corresponding_body.js");
140958
141699
  class MoveTranspiler {
140959
141700
  transpile(node, traversal) {
140960
141701
  const sourceExpression = node.findDirectExpression(abaplint.Expressions.Source);
@@ -140974,10 +141715,15 @@ class MoveTranspiler {
140974
141715
  ret.appendString(target + `.set(abap.alphaIn(${tSource.getCode()}, ${target}, ${target}));`);
140975
141716
  return ret;
140976
141717
  }
140977
- let source = this.isInt8Calculation(node, sourceExpression, targetExpressions.length, traversal)
140978
- ? new source_1.SourceTranspiler(false, true).transpile(sourceExpression, traversal)
140979
- : traversal.traverse(sourceExpression);
140980
141718
  const second = node.getChildren()[1]?.concatTokens();
141719
+ let source = second === "=" && targetExpressions.length === 1
141720
+ ? this.correspondingGeneric(sourceExpression, targets[0], traversal)
141721
+ : undefined;
141722
+ if (source === undefined) {
141723
+ source = this.isInt8Calculation(node, sourceExpression, targetExpressions.length, traversal)
141724
+ ? new source_1.SourceTranspiler(false, true).transpile(sourceExpression, traversal)
141725
+ : traversal.traverse(sourceExpression);
141726
+ }
140981
141727
  switch (second) {
140982
141728
  case "?=":
140983
141729
  ret.appendString("await abap.statements.cast(")
@@ -141039,6 +141785,22 @@ class MoveTranspiler {
141039
141785
  }
141040
141786
  return ret;
141041
141787
  }
141788
+ // "target = CORRESPONDING #( ... )" with a generic target, eg. "CHANGING ct TYPE STANDARD TABLE",
141789
+ // the type of the result is only known at runtime, so the target is passed on
141790
+ correspondingGeneric(source, target, traversal) {
141791
+ const children = source?.getChildren() || [];
141792
+ const typ = source?.findDirectExpression(abaplint.Expressions.TypeNameOrInfer);
141793
+ const body = source?.findDirectExpression(abaplint.Expressions.CorrespondingBody);
141794
+ if (children.length !== 5
141795
+ || children[0].concatTokens().toUpperCase() !== "CORRESPONDING"
141796
+ || typ === undefined
141797
+ || typ.concatTokens() !== "#"
141798
+ || body === undefined
141799
+ || new type_name_or_infer_1.TypeNameOrInfer().findTypeOrUndefined(typ, traversal)?.isGeneric() !== true) {
141800
+ return undefined;
141801
+ }
141802
+ return new corresponding_body_1.CorrespondingBodyTranspiler().transpile(typ, body, traversal, target.getCode());
141803
+ }
141042
141804
  // The calculation type of an arithmetic expression comes from its operands and the target
141043
141805
  // field, the type with the largest range wins. With operands of type i or int8 it is int8
141044
141806
  // when the target or an operand is int8: i * i into int8 is exact up to 2^62, and "/"
@@ -142088,6 +142850,22 @@ class RaiseEventTranspiler {
142088
142850
  if (parameters) {
142089
142851
  extra = "," + new expressions_1.ParameterListSTranspiler().transpile(parameters, traversal).getCode();
142090
142852
  }
142853
+ // a static event: handlers may only react when the class of this statement is theirs, it is passed along
142854
+ const def = traversal.getClassDefinition(node.getFirstToken());
142855
+ const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
142856
+ let search = def;
142857
+ let isStatic = false;
142858
+ while (search !== undefined) {
142859
+ const event = search.getEvents().find(e => e.getName().toLowerCase() === eventName);
142860
+ if (event !== undefined) {
142861
+ isStatic = event.isStatic();
142862
+ break;
142863
+ }
142864
+ search = search.getSuperClass() ? traversal.findClassDefinition(search.getSuperClass(), scope) : undefined;
142865
+ }
142866
+ if (isStatic === true && def !== undefined) {
142867
+ extra = (extra === "" ? ", undefined" : extra) + ", " + traversal_1.Traversal.escapeNamespace(def.getName().toLowerCase());
142868
+ }
142091
142869
  return new chunk_1.Chunk().append(`await abap.statements.raiseEvent(this.${eventName}, this.me${extra});`, node, traversal);
142092
142870
  }
142093
142871
  }
@@ -143880,6 +144658,7 @@ class SetHandlerTranspiler {
143880
144658
  const methods = [];
143881
144659
  let eventClass = undefined;
143882
144660
  let eventName = undefined;
144661
+ let forClass = "";
143883
144662
  for (const m of node.findDirectExpressions(abaplint.Expressions.MethodSource)) {
143884
144663
  // the handler method is registered as a reference, it is dispatched dynamically when the event is raised,
143885
144664
  // so no static binding even if the SET HANDLER is inside a constructor
@@ -143896,6 +144675,7 @@ class SetHandlerTranspiler {
143896
144675
  }
143897
144676
  eventName = method.def.getEventName();
143898
144677
  eventClass = this.findEventClass(method.def, traversal, scope);
144678
+ forClass = this.findForClass(method.def, eventClass, traversal, scope);
143899
144679
  }
143900
144680
  }
143901
144681
  let f = undefined;
@@ -143911,9 +144691,23 @@ class SetHandlerTranspiler {
143911
144691
  if (activationExpression) {
143912
144692
  activation = ", " + new expressions_1.SourceTranspiler().transpile(activationExpression, traversal).getCode();
143913
144693
  }
143914
- return new chunk_1.Chunk().append(`abap.statements.setHandler({EVENT_NAME: "${eventName}", EVENT_CLASS: "${eventClass}"}, [${methods.join(",")}], ${f}${activation});`, node, traversal);
144694
+ return new chunk_1.Chunk().append(`abap.statements.setHandler({EVENT_NAME: "${eventName}", EVENT_CLASS: "${eventClass}"${forClass}}, [${methods.join(",")}], ${f}${activation});`, node, traversal);
143915
144695
  }
143916
144696
  ///////////////////////////////////////////////////////////////////////
144697
+ /** a handler FOR EVENT ... OF a subclass of the class declaring the event only reacts to that subclass */
144698
+ findForClass(mdef, eventClass, traversal, scope) {
144699
+ const own = traversal.findClassDefinition(mdef.getEventClass(), scope);
144700
+ if (own === undefined || traversal.buildInternalName(own.getName(), own) === eventClass) {
144701
+ return "";
144702
+ }
144703
+ let def = own;
144704
+ let event = undefined;
144705
+ while (def !== undefined && event === undefined) {
144706
+ event = def.getEvents().find(e => e.getName().toUpperCase() === mdef.getEventName()?.toUpperCase());
144707
+ def = def.getSuperClass() ? traversal.findClassDefinition(def.getSuperClass(), scope) : undefined;
144708
+ }
144709
+ return `, FOR_CLASS: "${traversal.buildInternalName(own.getName(), own)}", STATIC: ${event?.isStatic() === true}`;
144710
+ }
143917
144711
  findEventClass(mdef, traversal, scope) {
143918
144712
  let def = traversal.findClassDefinition(mdef.getEventClass(), scope);
143919
144713
  if (def === undefined) {
@@ -148633,11 +149427,11 @@ class TranspileTypes {
148633
149427
  extra = "{qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
148634
149428
  }
148635
149429
  }
148636
- else if (type instanceof abaplint.BasicTypes.DecFloat34Type
148637
- || type instanceof abaplint.BasicTypes.DecFloat16Type) {
148638
- // decfloat16 runs on the runtime's decfloat34, an exact decimal: the
148639
- // 16 digit rounding and range of decfloat16 are not modelled, and RTTI
148640
- // describes such a field as a decfloat34
149430
+ else if (type instanceof abaplint.BasicTypes.DecFloat16Type) {
149431
+ // the range of decfloat16 is not modelled
149432
+ resolved = "DecFloat16";
149433
+ }
149434
+ else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
148641
149435
  resolved = "DecFloat34";
148642
149436
  }
148643
149437
  else if (type instanceof abaplint.BasicTypes.EnumType) {
@@ -150814,6 +151608,7 @@ const defaultAllowedObjectTypes = [
150814
151608
  "CHKO",
150815
151609
  "CHKV",
150816
151610
  "CLAS",
151611
+ "DCLS",
150817
151612
  "DDLS",
150818
151613
  "DDLX",
150819
151614
  "DEVC",