@abaplint/core 2.120.90 → 2.120.92

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.
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Data = void 0;
4
4
  const combi_1 = require("../combi");
5
5
  const expressions_1 = require("../expressions");
6
+ const tokens_1 = require("../../1_lexer/tokens");
6
7
  class Data {
7
8
  getMatcher() {
8
- return (0, combi_1.seq)("DATA", expressions_1.DataDefinition, (0, combi_1.optPrio)("%_PREDEFINED"));
9
+ // unnamed field, only relevant inside DATA BEGIN OF
10
+ const unnamed = (0, combi_1.seq)((0, combi_1.altPrio)((0, combi_1.tok)(tokens_1.WParenLeft), (0, combi_1.tok)(tokens_1.ParenLeft)), expressions_1.Integer, (0, combi_1.altPrio)((0, combi_1.tok)(tokens_1.ParenRightW), (0, combi_1.tok)(tokens_1.ParenRight)));
11
+ return (0, combi_1.seq)("DATA", (0, combi_1.altPrio)(expressions_1.DataDefinition, unnamed), (0, combi_1.optPrio)("%_PREDEFINED"));
9
12
  }
10
13
  }
11
14
  exports.Data = Data;
@@ -275,6 +275,7 @@ class ABAPFileInformationParser {
275
275
  }
276
276
  parseAttributes(node, visibility) {
277
277
  var _a;
278
+ var _b;
278
279
  if (node === undefined) {
279
280
  return [];
280
281
  }
@@ -291,7 +292,10 @@ class ABAPFileInformationParser {
291
292
  }
292
293
  }
293
294
  for (const d of data) {
294
- const name = d.findFirstExpression(Expressions.DefinitionName).getFirstToken();
295
+ const name = (_a = d.findFirstExpression(Expressions.DefinitionName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
296
+ if (name === undefined) {
297
+ continue;
298
+ }
295
299
  ret.push({
296
300
  name: name.getStr(),
297
301
  identifier: new _identifier_1.Identifier(name, this.filename),
@@ -305,7 +309,7 @@ class ABAPFileInformationParser {
305
309
  classData.push(structure.findDirectStatement(Statements.ClassDataBegin));
306
310
  }
307
311
  for (const d of classData) {
308
- const name = ((_a = d.findFirstExpression(Expressions.DefinitionName)) !== null && _a !== void 0 ? _a : d.findDirectExpression(Expressions.NamespaceSimpleName)).getFirstToken();
312
+ const name = ((_b = d.findFirstExpression(Expressions.DefinitionName)) !== null && _b !== void 0 ? _b : d.findDirectExpression(Expressions.NamespaceSimpleName)).getFirstToken();
309
313
  ret.push({
310
314
  name: name.getStr(),
311
315
  identifier: new _identifier_1.Identifier(name, this.filename),
@@ -88,6 +88,8 @@ class NewObject {
88
88
  }
89
89
  }
90
90
  else if (typeName === "#" && targetType) {
91
+ const tid = new _typed_identifier_1.TypedIdentifier(typeToken, input.filename, targetType);
92
+ input.scope.addReference(typeToken, tid, _reference_1.ReferenceType.InferredType, input.filename);
91
93
  ret = targetType;
92
94
  }
93
95
  else if (typeName === "#") {
@@ -70,6 +70,11 @@ class Data {
70
70
  for (const c of node.getChildren()) {
71
71
  const ctyp = c.get();
72
72
  if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Data) {
73
+ const unnamedLength = c.findDirectExpression(Expressions.Integer);
74
+ if (unnamedLength && c.findDirectExpression(Expressions.DataDefinition) === undefined) {
75
+ components.push({ name: "", type: new Basic.CharacterType(parseInt(unnamedLength.concatTokens(), 10)) });
76
+ continue;
77
+ }
73
78
  const found = new data_1.Data().runSyntax(c, input);
74
79
  if (found) {
75
80
  components.push({ name: found.getName(), type: found.getType() });
@@ -14,6 +14,9 @@ class StructureType extends _abstract_type_1.AbstractType {
14
14
  }
15
15
  this.indexed = {};
16
16
  for (const c of components) {
17
+ if (c.name === "") {
18
+ continue; // unnamed field, eg. "DATA: BEGIN OF str, (10), END OF str."
19
+ }
17
20
  const upper = c.name.toUpperCase();
18
21
  if (this.indexed[upper] !== undefined) {
19
22
  throw new Error("Structure, duplicate field name \"" + upper + "\", " + qualifiedName);
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.90";
78
+ return "2.120.92";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.AbapdocShortLink = exports.AbapdocShortLinkConf = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
39
+ const issue_1 = require("../issue");
40
+ const _abap_rule_1 = require("./_abap_rule");
41
+ const _basic_rule_config_1 = require("./_basic_rule_config");
42
+ const _irule_1 = require("./_irule");
43
+ const _statement_1 = require("../abap/2_statements/statements/_statement");
44
+ const position_1 = require("../position");
45
+ const edit_helper_1 = require("../edit_helper");
46
+ class AbapdocShortLinkConf extends _basic_rule_config_1.BasicRuleConfig {
47
+ }
48
+ exports.AbapdocShortLinkConf = AbapdocShortLinkConf;
49
+ class AbapdocShortLink extends _abap_rule_1.ABAPRule {
50
+ constructor() {
51
+ super(...arguments);
52
+ this.conf = new AbapdocShortLinkConf();
53
+ }
54
+ getMetadata() {
55
+ return {
56
+ key: "abapdoc_short_link",
57
+ title: "Use short form of ABAP Doc links",
58
+ shortDescription: `Reports ABAP Doc links to components of the current global class or interface which repeat the object name.`,
59
+ extendedInformation: `Links to components of the same repository object can omit the object name and start with a period,
60
+ {@link zif_foo.data:field} can be written as {@link .data:field}.
61
+
62
+ Only checks ABAP Doc inside the definition of the global class or interface.
63
+
64
+ https://github.com/SAP/abap-file-formats/issues/880`,
65
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
66
+ badExample: `INTERFACE zif_foo PUBLIC.
67
+ "! Same as {@link zif_foo.data:bar}
68
+ DATA foo TYPE string.
69
+ DATA bar TYPE string.
70
+ ENDINTERFACE.`,
71
+ goodExample: `INTERFACE zif_foo PUBLIC.
72
+ "! Same as {@link .data:bar}
73
+ DATA foo TYPE string.
74
+ DATA bar TYPE string.
75
+ ENDINTERFACE.`,
76
+ };
77
+ }
78
+ getConfig() {
79
+ return this.conf;
80
+ }
81
+ setConfig(conf) {
82
+ this.conf = conf;
83
+ }
84
+ runParsed(file, obj) {
85
+ var _a;
86
+ const issues = [];
87
+ const objectType = obj.getType();
88
+ if (objectType !== "CLAS" && objectType !== "INTF") {
89
+ return [];
90
+ }
91
+ const objectName = obj.getName().toLowerCase();
92
+ let definition = false;
93
+ for (const statement of file.getStatements()) {
94
+ const type = statement.get();
95
+ if (type instanceof Statements.ClassDefinition || type instanceof Statements.Interface) {
96
+ const name = (_a = statement.findFirstExpression(Expressions.ClassName)) !== null && _a !== void 0 ? _a : statement.findFirstExpression(Expressions.InterfaceName);
97
+ definition = (name === null || name === void 0 ? void 0 : name.getFirstToken().getStr().toLowerCase()) === objectName;
98
+ continue;
99
+ }
100
+ else if (type instanceof Statements.EndClass || type instanceof Statements.EndInterface) {
101
+ definition = false;
102
+ continue;
103
+ }
104
+ else if (definition === false || !(type instanceof _statement_1.Comment)) {
105
+ continue;
106
+ }
107
+ const token = statement.getFirstToken();
108
+ const str = token.getStr();
109
+ if (str.startsWith(`"!`) === false) {
110
+ continue;
111
+ }
112
+ const regex = /\{@link\s+((?:(\w+):)?([\w/]+))\./gi;
113
+ let match;
114
+ while ((match = regex.exec(str)) !== null) {
115
+ const kind = match[2];
116
+ if (match[3].toLowerCase() !== objectName
117
+ || (kind !== undefined && kind.toLowerCase() !== objectType.toLowerCase())) {
118
+ continue;
119
+ }
120
+ const row = token.getStart().getRow();
121
+ const col = token.getStart().getCol() + match.index + match[0].length - 1 - match[1].length;
122
+ const start = new position_1.Position(row, col);
123
+ const end = new position_1.Position(row, col + match[1].length);
124
+ const fix = edit_helper_1.EditHelper.deleteRange(file, start, end);
125
+ const message = `Use short form of ABAP Doc link, remove "${match[1]}"`;
126
+ issues.push(issue_1.Issue.atRange(file, start, end, message, this.getMetadata().key, this.conf.severity, fix));
127
+ }
128
+ }
129
+ return issues;
130
+ }
131
+ }
132
+ exports.AbapdocShortLink = AbapdocShortLink;
133
+ //# sourceMappingURL=abapdoc_short_link.js.map
@@ -3387,12 +3387,9 @@ ${indentation} output = ${uniqueName}.\n`;
3387
3387
  }
3388
3388
  }
3389
3389
  /** NEW into a data reference creates data, CREATE OBJECT cannot: "target = NEW #|type( [value] )"
3390
- * with a variable typed REF TO a data type becomes CREATE DATA plus the assignment of the value */
3390
+ * with a target typed REF TO a data type becomes CREATE DATA plus the assignment of the value */
3391
3391
  newDataReference(high, target, found, lowFile, highSyntax) {
3392
3392
  var _a, _b, _c;
3393
- if (target.getChildren().length !== 1 || !(((_a = target.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.TargetField)) {
3394
- return undefined;
3395
- }
3396
3393
  const children = found.getChildren();
3397
3394
  const value = found.findDirectExpression(Expressions.Source);
3398
3395
  // NEW, the type, "(", optionally one value, ")"
@@ -3400,12 +3397,23 @@ ${indentation} output = ${uniqueName}.\n`;
3400
3397
  return undefined;
3401
3398
  }
3402
3399
  const name = target.concatTokens();
3400
+ const typeExpr = found.findDirectExpression(Expressions.TypeNameOrInfer);
3401
+ const typeName = typeExpr === null || typeExpr === void 0 ? void 0 : typeExpr.concatTokens();
3403
3402
  const spag = highSyntax.spaghetti.lookupPosition(high.getFirstToken().getStart(), lowFile.getFilename());
3404
- const type = (_b = spag === null || spag === void 0 ? void 0 : spag.findVariable(name)) === null || _b === void 0 ? void 0 : _b.getType();
3403
+ let type = undefined;
3404
+ if (typeName === "#") {
3405
+ // the type of the target, as inferred by the syntax check
3406
+ const typeToken = typeExpr.getFirstToken();
3407
+ const resolved = (_a = spag === null || spag === void 0 ? void 0 : spag.getData().references.find(r => r.referenceType === _reference_1.ReferenceType.InferredType
3408
+ && r.position.getStart().equals(typeToken.getStart()))) === null || _a === void 0 ? void 0 : _a.resolved;
3409
+ type = resolved instanceof _typed_identifier_1.TypedIdentifier ? resolved.getType() : undefined;
3410
+ }
3411
+ else if (target.getChildren().length === 1 && ((_b = target.getFirstChild()) === null || _b === void 0 ? void 0 : _b.get()) instanceof Expressions.TargetField) {
3412
+ type = (_c = spag === null || spag === void 0 ? void 0 : spag.findVariable(name)) === null || _c === void 0 ? void 0 : _c.getType();
3413
+ }
3405
3414
  if (!(type instanceof basic_1.DataReference)) {
3406
3415
  return undefined;
3407
3416
  }
3408
- const typeName = (_c = found.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _c === void 0 ? void 0 : _c.concatTokens();
3409
3417
  const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
3410
3418
  let abap = `CREATE DATA ${name}` + (typeName === "#" ? "" : ` TYPE ${typeName}`) + ".";
3411
3419
  if (value === undefined) {
@@ -3453,7 +3461,7 @@ ${indentation} output = ${uniqueName}.\n`;
3453
3461
  }
3454
3462
  }
3455
3463
  else {
3456
- throw new Error("newParameters, downport, unexpected");
3464
+ return undefined; // not an object, CREATE OBJECT does not apply
3457
3465
  }
3458
3466
  }
3459
3467
  if (cdef && cdef.getMethodDefinitions === undefined) {
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ForbiddenKernelWrite = exports.ForbiddenKernelWriteConf = void 0;
37
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
38
+ const Statements = __importStar(require("../abap/2_statements/statements"));
39
+ const _abap_rule_1 = require("./_abap_rule");
40
+ const _basic_rule_config_1 = require("./_basic_rule_config");
41
+ const issue_1 = require("../issue");
42
+ const _irule_1 = require("./_irule");
43
+ class ForbiddenKernelWriteConf extends _basic_rule_config_1.BasicRuleConfig {
44
+ constructor() {
45
+ super(...arguments);
46
+ /** Objects allowed to use WRITE '@KERNEL', array of string regex matched against the object name.
47
+ * Empty, the default, allows every object
48
+ * @uniqueItems true
49
+ */
50
+ this.allow = [];
51
+ }
52
+ }
53
+ exports.ForbiddenKernelWriteConf = ForbiddenKernelWriteConf;
54
+ class ForbiddenKernelWrite extends _abap_rule_1.ABAPRule {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.conf = new ForbiddenKernelWriteConf();
58
+ this.allow = [];
59
+ }
60
+ getMetadata() {
61
+ return {
62
+ key: "forbidden_kernel_write",
63
+ title: "Forbidden kernel WRITE",
64
+ shortDescription: `Forbid WRITE '@KERNEL' outside the listed objects`,
65
+ extendedInformation: `The transpiler emits the literal of WRITE '@KERNEL ...' as raw JavaScript,
66
+ which runs with the privileges of the host. Open-abap uses this for its kernel classes, code compiled by a host it did not write should not.
67
+
68
+ allow is a list of regex, case insensitive, matched against the object name, eg. ["^CL_", "^KERNEL_"].
69
+ An empty list, the default, allows every object. To forbid WRITE '@KERNEL' everywhere use a regex matching no name, eg. ["^$"].`,
70
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Security],
71
+ badExample: `WRITE '@KERNEL process.exit(1);'.`,
72
+ };
73
+ }
74
+ getConfig() {
75
+ return this.conf;
76
+ }
77
+ setConfig(conf) {
78
+ this.conf = conf;
79
+ if (this.conf.allow === undefined) {
80
+ this.conf.allow = [];
81
+ }
82
+ this.allow = this.conf.allow.map(a => new RegExp(a, "i"));
83
+ }
84
+ runParsed(file, obj) {
85
+ var _a;
86
+ if (this.allow.length === 0 || this.allow.some(a => a.test(obj.getName()))) {
87
+ return [];
88
+ }
89
+ const ret = [];
90
+ for (const s of file.getStatements()) {
91
+ if (!(s.get() instanceof Statements.Write)) {
92
+ continue;
93
+ }
94
+ // same check as the transpiler, statements/write.ts
95
+ const source = (_a = s.findDirectExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens();
96
+ if ((source === null || source === void 0 ? void 0 : source.startsWith("'@KERNEL ")) === true) {
97
+ const message = "WRITE '@KERNEL' not allowed in " + obj.getName();
98
+ ret.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity));
99
+ }
100
+ }
101
+ return ret;
102
+ }
103
+ }
104
+ exports.ForbiddenKernelWrite = ForbiddenKernelWrite;
105
+ //# sourceMappingURL=forbidden_kernel_write.js.map
@@ -19,6 +19,7 @@ __exportStar(require("./abapdoc"), exports);
19
19
  __exportStar(require("./abapdoc_html_tag"), exports);
20
20
  __exportStar(require("./abapdoc_leading_at"), exports);
21
21
  __exportStar(require("./abapdoc_parameter_names"), exports);
22
+ __exportStar(require("./abapdoc_short_link"), exports);
22
23
  __exportStar(require("./abapdoc_shorttext_length"), exports);
23
24
  __exportStar(require("./add_test_attributes"), exports);
24
25
  __exportStar(require("./aff_and_xml"), exports);
@@ -93,6 +94,7 @@ __exportStar(require("./exporting"), exports);
93
94
  __exportStar(require("./final_newline"), exports);
94
95
  __exportStar(require("./fm_global_parameters_obsolete"), exports);
95
96
  __exportStar(require("./forbidden_identifier"), exports);
97
+ __exportStar(require("./forbidden_kernel_write"), exports);
96
98
  __exportStar(require("./forbidden_pseudo_and_pragma"), exports);
97
99
  __exportStar(require("./forbidden_void_type"), exports);
98
100
  __exportStar(require("./form_tables_obsolete"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.90",
3
+ "version": "2.120.92",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",