@sap-ux/cds-annotation-parser 0.1.13 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildAst = exports.locationToRange = void 0;
4
- const vscode_languageserver_types_1 = require("vscode-languageserver-types");
4
+ const text_document_utils_1 = require("@sap-ux/text-document-utils");
5
5
  const annotation_ast_nodes_1 = require("./annotation-ast-nodes");
6
6
  const factory_1 = require("../parser/factory");
7
7
  const expressions_1 = require("./expressions");
@@ -16,19 +16,18 @@ const utils_1 = require("../utils");
16
16
  * @returns Qualifier node
17
17
  */
18
18
  const createQualifier = (term) => {
19
- var _a, _b;
20
19
  const segment = term.segments.find((item) => item.value.includes('#'));
21
20
  let qRange;
22
21
  let qualifierValue = '';
23
22
  if ((0, utils_1.isDefined)(segment)) {
24
23
  const tokens = segment.value.split('#');
25
- segment.value = (_a = tokens.shift()) !== null && _a !== void 0 ? _a : '';
26
- qualifierValue = (_b = tokens.pop()) !== null && _b !== void 0 ? _b : '';
24
+ segment.value = tokens.shift() ?? '';
25
+ qualifierValue = tokens.pop() ?? '';
27
26
  const len = qualifierValue.length;
28
27
  if (segment.range) {
29
28
  qRange = {
30
- start: Object.assign(Object.assign({}, segment.range.end), { character: segment.range.end.character - len }),
31
- end: Object.assign({}, segment.range.end)
29
+ start: { ...segment.range.end, character: segment.range.end.character - len },
30
+ end: { ...segment.range.end }
32
31
  };
33
32
  segment.range.end.character = segment.range.end.character - len - 1;
34
33
  }
@@ -42,15 +41,14 @@ const createQualifier = (term) => {
42
41
  const compareTokensByPosition = (a, b) => {
43
42
  return a.startOffset - b.startOffset;
44
43
  };
45
- const adjustPosition = (position, offset) => vscode_languageserver_types_1.Position.create(position.line + offset.line, position.line === 0 ? position.character + offset.character : position.character);
44
+ const adjustPosition = (position, offset) => text_document_utils_1.Position.create(position.line + offset.line, position.line === 0 ? position.character + offset.character : position.character);
46
45
  const locationToRange = (location) => {
47
- var _a, _b, _c;
48
46
  return location
49
- ? vscode_languageserver_types_1.Range.create(location.startLine - 1, ((_a = location.startColumn) !== null && _a !== void 0 ? _a : 0) - 1, ((_b = location.endLine) !== null && _b !== void 0 ? _b : 0) - 1, (_c = location.endColumn) !== null && _c !== void 0 ? _c : 0)
47
+ ? text_document_utils_1.Range.create(location.startLine - 1, (location.startColumn ?? 0) - 1, (location.endLine ?? 0) - 1, location.endColumn ?? 0)
50
48
  : undefined;
51
49
  };
52
50
  exports.locationToRange = locationToRange;
53
- const existsAndNotRecovered = (nodes) => { var _a; return (0, utils_1.hasItems)(nodes) && !((_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.isInsertedInRecovery); };
51
+ const existsAndNotRecovered = (nodes) => (0, utils_1.hasItems)(nodes) && !nodes[0]?.isInsertedInRecovery;
54
52
  const vocabularyService = new odata_vocabularies_1.VocabularyService(true, true);
55
53
  const vocabularyAliases = [...vocabularyService.getVocabularies().values()].map((vocabulary) => vocabulary.defaultAlias);
56
54
  const supportedVocabularyAliases = new Set([...vocabularyAliases, ...vocabularyService.cdsVocabulary.groupNames]);
@@ -84,7 +82,7 @@ class CstToAstVisitor extends factory_1.Visitor {
84
82
  locationToRange(location) {
85
83
  const range = (0, exports.locationToRange)(location);
86
84
  if (this.startPosition && range) {
87
- return vscode_languageserver_types_1.Range.create(adjustPosition(range.start, this.startPosition), adjustPosition(range.end, this.startPosition));
85
+ return text_document_utils_1.Range.create(adjustPosition(range.start, this.startPosition), adjustPosition(range.end, this.startPosition));
88
86
  }
89
87
  return range;
90
88
  }
@@ -95,17 +93,16 @@ class CstToAstVisitor extends factory_1.Visitor {
95
93
  * @returns Range object
96
94
  */
97
95
  tokenToRange(token) {
98
- var _a, _b, _c, _d, _e, _f;
99
- const start = vscode_languageserver_types_1.Position.create(((_a = token.startLine) !== null && _a !== void 0 ? _a : 0) - 1, ((_b = token.startColumn) !== null && _b !== void 0 ? _b : 0) - 1);
100
- const line = (0, utils_1.hasNaNOrUndefined)(token.endLine) ? ((_c = token.startLine) !== null && _c !== void 0 ? _c : 0) - 1 : ((_d = token.endLine) !== null && _d !== void 0 ? _d : 0) - 1;
96
+ const start = text_document_utils_1.Position.create((token.startLine ?? 0) - 1, (token.startColumn ?? 0) - 1);
97
+ const line = (0, utils_1.hasNaNOrUndefined)(token.endLine) ? (token.startLine ?? 0) - 1 : (token.endLine ?? 0) - 1;
101
98
  const char = (0, utils_1.hasNaNOrUndefined)(token.endColumn)
102
- ? ((_e = token.startColumn) !== null && _e !== void 0 ? _e : 0) - 1 + token.image.length
103
- : (_f = token.endColumn) !== null && _f !== void 0 ? _f : 0;
104
- const end = vscode_languageserver_types_1.Position.create(line, char);
99
+ ? (token.startColumn ?? 0) - 1 + token.image.length
100
+ : token.endColumn ?? 0;
101
+ const end = text_document_utils_1.Position.create(line, char);
105
102
  if (this.startPosition) {
106
- return vscode_languageserver_types_1.Range.create(adjustPosition(start, this.startPosition), adjustPosition(end, this.startPosition));
103
+ return text_document_utils_1.Range.create(adjustPosition(start, this.startPosition), adjustPosition(end, this.startPosition));
107
104
  }
108
- return vscode_languageserver_types_1.Range.create(start, end);
105
+ return text_document_utils_1.Range.create(start, end);
109
106
  }
110
107
  /**
111
108
  * Converts CST token to AST token.
@@ -201,9 +198,7 @@ class CstToAstVisitor extends factory_1.Visitor {
201
198
  * @returns Annotation group object
202
199
  */
203
200
  toTopLevelAnnotationPathGroup(path, assignment, location) {
204
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
205
- const items = ((_c = (_b = (_a = assignment.children.value) === null || _a === void 0 ? void 0 : _a[0].children.struct) === null || _b === void 0 ? void 0 : _b[0].children.assignment) !== null && _c !== void 0 ? _c : []).map((childAssignment, index, childAssignments) => {
206
- var _a, _b, _c, _d;
201
+ const items = (assignment.children.value?.[0].children.struct?.[0].children.assignment ?? []).map((childAssignment, index, childAssignments) => {
207
202
  const annotation = this.visit(childAssignment);
208
203
  // check for specific situation where current child has no value and separating comma to next child is missing
209
204
  // then: current child value is represented by a path and next child path is empty
@@ -215,34 +210,34 @@ class CstToAstVisitor extends factory_1.Visitor {
215
210
  childAssignment.children.value[0].children.path) {
216
211
  // current child has no value (separating comma to next child is missing)
217
212
  const start = this.tokenToRange(childAssignment.children.Colon[0]).end;
218
- const end = (_d = (_c = this.locationToRange((_b = (_a = childAssignment.children.value) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.location)) === null || _c === void 0 ? void 0 : _c.start) !== null && _d !== void 0 ? _d : start;
213
+ const end = this.locationToRange(childAssignment.children.value?.[0]?.location)?.start ?? start;
219
214
  annotation.value = {
220
215
  type: annotation_ast_nodes_1.EMPTY_VALUE_TYPE,
221
- range: vscode_languageserver_types_1.Range.create(start, end)
216
+ range: text_document_utils_1.Range.create(start, end)
222
217
  };
223
218
  }
224
219
  return annotation;
225
220
  });
226
- const commas = this.getCommaToken((_f = (_e = (_d = assignment.children.value) === null || _d === void 0 ? void 0 : _d[0].children) === null || _e === void 0 ? void 0 : _e.struct) === null || _f === void 0 ? void 0 : _f[0].children.Comma);
221
+ const commas = this.getCommaToken(assignment.children.value?.[0].children?.struct?.[0].children.Comma);
227
222
  const ast = {
228
223
  type: annotation_ast_nodes_1.ANNOTATION_GROUP_TYPE,
229
224
  name: path.segments[0],
230
225
  items: {
231
226
  type: annotation_ast_nodes_1.ANNOTATION_GROUP_ITEMS_TYPE,
232
227
  items,
233
- range: this.locationToRange((_h = (_g = assignment.children.value) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.location),
228
+ range: this.locationToRange(assignment.children.value?.[0]?.location),
234
229
  commas
235
230
  },
236
231
  range: this.locationToRange(location)
237
232
  };
238
- if ((_j = assignment.children.Colon) === null || _j === void 0 ? void 0 : _j.length) {
233
+ if (assignment.children.Colon?.length) {
239
234
  ast.colon = {
240
235
  type: annotation_ast_nodes_1.TOKEN_TYPE,
241
236
  value: assignment.children.Colon[0].image,
242
237
  range: this.tokenToRange(assignment.children.Colon[0])
243
238
  };
244
239
  }
245
- if ((_l = (_k = assignment.children.value) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.children.struct) {
240
+ if (assignment.children.value?.[0]?.children.struct) {
246
241
  const struct = assignment.children.value[0].children.struct[0];
247
242
  if (existsAndNotRecovered(struct.children.LCurly)) {
248
243
  ast.items.openToken = this.createToken(struct.children.LCurly[0]);
@@ -260,8 +255,7 @@ class CstToAstVisitor extends factory_1.Visitor {
260
255
  * @returns Colon ast token or undefined if not found
261
256
  */
262
257
  getColon(assignment) {
263
- var _a;
264
- if ((_a = assignment.children.Colon) === null || _a === void 0 ? void 0 : _a.length) {
258
+ if (assignment.children.Colon?.length) {
265
259
  return {
266
260
  type: annotation_ast_nodes_1.TOKEN_TYPE,
267
261
  range: this.tokenToRange(assignment.children.Colon[0]),
@@ -313,7 +307,6 @@ class CstToAstVisitor extends factory_1.Visitor {
313
307
  * @returns Annotation ast node
314
308
  */
315
309
  toTopLevelAnnotation(assignment, location) {
316
- var _a;
317
310
  if ((0, utils_1.isDefined)(assignment.location) &&
318
311
  isNaN(assignment.location.startOffset) &&
319
312
  assignment.recoveredNode === true) {
@@ -342,7 +335,7 @@ class CstToAstVisitor extends factory_1.Visitor {
342
335
  },
343
336
  range: (0, range_1.copyRange)(range)
344
337
  };
345
- if ((_a = assignment.children.Colon) === null || _a === void 0 ? void 0 : _a.length) {
338
+ if (assignment.children.Colon?.length) {
346
339
  ast.colon = {
347
340
  type: annotation_ast_nodes_1.TOKEN_TYPE,
348
341
  range: this.tokenToRange(assignment.children.Colon[0]),
@@ -570,7 +563,6 @@ class CstToAstVisitor extends factory_1.Visitor {
570
563
  * @returns Expression value ast node
571
564
  */
572
565
  expression(context, location) {
573
- var _a, _b;
574
566
  /**
575
567
  * Builds operator.
576
568
  *
@@ -585,8 +577,8 @@ class CstToAstVisitor extends factory_1.Visitor {
585
577
  const openToken = existsAndNotRecovered(context.LParen) ? this.createToken(context.LParen[0]) : undefined;
586
578
  const closeToken = existsAndNotRecovered(context.RParen) ? this.createToken(context.RParen[0]) : undefined;
587
579
  const range = this.locationToRange(location);
588
- const operators = ((_a = context.Operator) !== null && _a !== void 0 ? _a : []).map((token) => buildOperator(token, this.tokenToRange(token)));
589
- const operands = ((_b = context.value) !== null && _b !== void 0 ? _b : []).map((token) => this.visit(token));
580
+ const operators = (context.Operator ?? []).map((token) => buildOperator(token, this.tokenToRange(token)));
581
+ const operands = (context.value ?? []).map((token) => this.visit(token));
590
582
  const expression = { operators, operands, openToken, closeToken, range };
591
583
  const unsupportedOperator = operators.find((operator) => {
592
584
  const operatorNames = expressions_1.operatorImageMap[operator.value.toUpperCase()];
@@ -594,7 +586,7 @@ class CstToAstVisitor extends factory_1.Visitor {
594
586
  });
595
587
  if (unsupportedOperator || !range) {
596
588
  const type = annotation_ast_nodes_1.UNSUPPORTED_OPERATOR_EXPRESSION_TYPE;
597
- return Object.assign(Object.assign({}, expression), { type, unsupportedOperator });
589
+ return { ...expression, type, unsupportedOperator };
598
590
  }
599
591
  try {
600
592
  const protoExpression = (0, expressions_1.rebuildNumberSigns)({ operators, operands, range });
@@ -612,7 +604,7 @@ class CstToAstVisitor extends factory_1.Visitor {
612
604
  }
613
605
  catch (e) {
614
606
  // expression did not follow grammar rules - return expression with empty operatorName
615
- return Object.assign(Object.assign({}, expression), { type: annotation_ast_nodes_1.INCORRECT_EXPRESSION_TYPE, message: e.toString() });
607
+ return { ...expression, type: annotation_ast_nodes_1.INCORRECT_EXPRESSION_TYPE, message: e.toString() };
616
608
  }
617
609
  }
618
610
  /**
@@ -623,12 +615,11 @@ class CstToAstVisitor extends factory_1.Visitor {
623
615
  * @returns Enum value ast node
624
616
  */
625
617
  enum(context, location) {
626
- var _a;
627
618
  const range = this.locationToRange(location);
628
619
  if (range) {
629
620
  range.start.character++;
630
621
  }
631
- const path = ((_a = context.path) === null || _a === void 0 ? void 0 : _a.length) === 1
622
+ const path = context.path?.length === 1
632
623
  ? this.visit(context.path[0])
633
624
  : {
634
625
  type: annotation_ast_nodes_1.PATH_TYPE,
@@ -651,9 +642,8 @@ class CstToAstVisitor extends factory_1.Visitor {
651
642
  * @returns String literal ast node
652
643
  */
653
644
  string(context, location) {
654
- var _a;
655
645
  const range = this.locationToRange(location);
656
- const value = ((_a = context.String) === null || _a === void 0 ? void 0 : _a.length) === 1 ? context.String[0].image : '';
646
+ const value = context.String?.length === 1 ? context.String[0].image : '';
657
647
  const ast = {
658
648
  type: annotation_ast_nodes_1.STRING_LITERAL_TYPE,
659
649
  value,
@@ -675,9 +665,8 @@ class CstToAstVisitor extends factory_1.Visitor {
675
665
  * @returns Multi line string literal ast node
676
666
  */
677
667
  multiLineString(context, location) {
678
- var _a;
679
668
  const range = this.locationToRange(location);
680
- const value = ((_a = context.MultiLineString) === null || _a === void 0 ? void 0 : _a.length) === 1 ? context.MultiLineString[0].image : '';
669
+ const value = context.MultiLineString?.length === 1 ? context.MultiLineString[0].image : '';
681
670
  const ast = {
682
671
  type: annotation_ast_nodes_1.MULTI_LINE_STRING_LITERAL_TYPE,
683
672
  stripIndentation: false,
@@ -700,9 +689,8 @@ class CstToAstVisitor extends factory_1.Visitor {
700
689
  * @returns Multi line string literal ast node
701
690
  */
702
691
  multiLineStringStripIndent(context, location) {
703
- var _a;
704
692
  const range = this.locationToRange(location);
705
- const value = ((_a = context.MultiLineString) === null || _a === void 0 ? void 0 : _a.length) === 1 ? context.MultiLineString[0].image : '';
693
+ const value = context.MultiLineString?.length === 1 ? context.MultiLineString[0].image : '';
706
694
  const ast = {
707
695
  type: annotation_ast_nodes_1.MULTI_LINE_STRING_LITERAL_TYPE,
708
696
  stripIndentation: true,
@@ -726,7 +714,7 @@ class CstToAstVisitor extends factory_1.Visitor {
726
714
  */
727
715
  collection(context, location) {
728
716
  const range = this.locationToRange(location);
729
- const commas = this.getCommaToken(context === null || context === void 0 ? void 0 : context.Comma);
717
+ const commas = this.getCommaToken(context?.Comma);
730
718
  const ast = {
731
719
  type: annotation_ast_nodes_1.COLLECTION_TYPE,
732
720
  items: (0, utils_1.hasItems)(context.collectionValue)
@@ -801,19 +789,18 @@ class CstToAstVisitor extends factory_1.Visitor {
801
789
  * @returns Identifier CST token with empty image nd adjusted range
802
790
  */
803
791
  identifierFromSeparatorToken(token) {
804
- var _a, _b;
805
792
  // Adjust range so it is the next character after separator
806
793
  return {
807
794
  image: '',
808
795
  startOffset: token.startOffset + 1,
809
796
  startLine: token.startLine,
810
- startColumn: ((_a = token.startColumn) !== null && _a !== void 0 ? _a : 0) + 1,
797
+ startColumn: (token.startColumn ?? 0) + 1,
811
798
  endOffset: token.endOffset,
812
799
  endLine: token.endLine,
813
800
  endColumn: token.endColumn,
814
801
  tokenType: tokens_1.tokenMap.Identifier,
815
802
  isInsertedInRecovery: true,
816
- tokenTypeIdx: (_b = tokens_1.tokenMap.Identifier.tokenTypeIdx) !== null && _b !== void 0 ? _b : -1
803
+ tokenTypeIdx: tokens_1.tokenMap.Identifier.tokenTypeIdx ?? -1
817
804
  };
818
805
  }
819
806
  /**
@@ -824,18 +811,17 @@ class CstToAstVisitor extends factory_1.Visitor {
824
811
  * @returns Empty identifier CST token
825
812
  */
826
813
  createEmptyIdentifier(start, end) {
827
- var _a, _b, _c, _d;
828
814
  return {
829
815
  image: '',
830
- startOffset: ((_a = start.endOffset) !== null && _a !== void 0 ? _a : 0) + 1,
816
+ startOffset: (start.endOffset ?? 0) + 1,
831
817
  startLine: start.endLine,
832
- startColumn: ((_b = start.endColumn) !== null && _b !== void 0 ? _b : 0) + 1,
818
+ startColumn: (start.endColumn ?? 0) + 1,
833
819
  endOffset: end.startOffset - 1,
834
820
  endLine: end.startLine,
835
- endColumn: ((_c = end.startColumn) !== null && _c !== void 0 ? _c : 0) - 1,
821
+ endColumn: (end.startColumn ?? 0) - 1,
836
822
  tokenType: tokens_1.tokenMap.Identifier,
837
823
  isInsertedInRecovery: true,
838
- tokenTypeIdx: (_d = tokens_1.tokenMap.Identifier.tokenTypeIdx) !== null && _d !== void 0 ? _d : -1
824
+ tokenTypeIdx: tokens_1.tokenMap.Identifier.tokenTypeIdx ?? -1
839
825
  };
840
826
  }
841
827
  /**
@@ -845,7 +831,6 @@ class CstToAstVisitor extends factory_1.Visitor {
845
831
  * @returns Array of objects consisting of identifier token and delimiter
846
832
  */
847
833
  getIdentifierToken(segment) {
848
- var _a;
849
834
  if ((0, utils_1.hasItems)(segment.children.NumberSign)) {
850
835
  if ((0, utils_1.hasItems)(segment.children.Identifier)) {
851
836
  segment.children.Identifier[0].image += '#';
@@ -880,7 +865,7 @@ class CstToAstVisitor extends factory_1.Visitor {
880
865
  ];
881
866
  }
882
867
  }
883
- return ((_a = segment.children.Identifier) !== null && _a !== void 0 ? _a : []).map((token) => ({
868
+ return (segment.children.Identifier ?? []).map((token) => ({
884
869
  token,
885
870
  delimiter: annotation_ast_nodes_1.Delimiter.none
886
871
  }));
@@ -894,11 +879,10 @@ class CstToAstVisitor extends factory_1.Visitor {
894
879
  * @returns Updated path segment node
895
880
  */
896
881
  setNewRangeForIdentifier(segment, index, key) {
897
- var _a, _b, _c;
898
882
  if ((0, utils_1.hasItems)(segment.children.Identifier)) {
899
- segment.children.Identifier[0].endColumn = (_a = segment.children[key]) === null || _a === void 0 ? void 0 : _a[index].endColumn;
900
- segment.children.Identifier[0].endLine = (_b = segment.children[key]) === null || _b === void 0 ? void 0 : _b[index].endLine;
901
- segment.children.Identifier[0].endOffset = (_c = segment.children[key]) === null || _c === void 0 ? void 0 : _c[index].endOffset;
883
+ segment.children.Identifier[0].endColumn = segment.children[key]?.[index].endColumn;
884
+ segment.children.Identifier[0].endLine = segment.children[key]?.[index].endLine;
885
+ segment.children.Identifier[0].endOffset = segment.children[key]?.[index].endOffset;
902
886
  }
903
887
  return segment;
904
888
  }
@@ -929,23 +913,18 @@ class CstToAstVisitor extends factory_1.Visitor {
929
913
  * @returns Path AST node
930
914
  */
931
915
  path(context, location) {
932
- var _a, _b, _c;
933
- const segments = ((_a = context.pathSegment) !== null && _a !== void 0 ? _a : [])
916
+ const segments = (context.pathSegment ?? [])
934
917
  .map((segment, i) => {
935
- var _a, _b, _c, _d, _e;
936
- const quotedIdentifiers = (_b = (_a = segment.children.quotedIdentifier) === null || _a === void 0 ? void 0 : _a.reduce((acc, quotedIdentifier) => {
918
+ const quotedIdentifiers = segment.children.quotedIdentifier?.reduce((acc, quotedIdentifier) => {
937
919
  return [
938
920
  ...acc,
939
- ...(quotedIdentifier.children.QuotedIdentifier || []).map((token, j) => {
940
- var _a;
941
- return ({
942
- token: this.recoverIdentifiers(token, j, (_a = quotedIdentifier.children.PathSegmentSeparator) !== null && _a !== void 0 ? _a : []),
943
- delimiter: annotation_ast_nodes_1.Delimiter.quoted
944
- });
945
- })
921
+ ...(quotedIdentifier.children.QuotedIdentifier || []).map((token, j) => ({
922
+ token: this.recoverIdentifiers(token, j, quotedIdentifier.children.PathSegmentSeparator ?? []),
923
+ delimiter: annotation_ast_nodes_1.Delimiter.quoted
924
+ }))
946
925
  ];
947
- }, [])) !== null && _b !== void 0 ? _b : [];
948
- const delimitedIdentifiers = ((_d = (_c = segment.children.delimitedIdentifier) === null || _c === void 0 ? void 0 : _c.reduce((acc, delimitedIdentifier) => {
926
+ }, []) ?? [];
927
+ const delimitedIdentifiers = (segment.children.delimitedIdentifier?.reduce((acc, delimitedIdentifier) => {
949
928
  if (!delimitedIdentifier.children.DelimitedIdentifier) {
950
929
  return [
951
930
  ...acc,
@@ -957,16 +936,13 @@ class CstToAstVisitor extends factory_1.Visitor {
957
936
  }
958
937
  return [
959
938
  ...acc,
960
- ...(delimitedIdentifier.children.DelimitedIdentifier || []).map((token, j) => {
961
- var _a;
962
- return ({
963
- token: this.recoverIdentifiers(token, j, (_a = delimitedIdentifier.children.PathSegmentSeparator) !== null && _a !== void 0 ? _a : []),
964
- delimiter: annotation_ast_nodes_1.Delimiter.exclamationSquareBrackets
965
- });
966
- })
939
+ ...(delimitedIdentifier.children.DelimitedIdentifier || []).map((token, j) => ({
940
+ token: this.recoverIdentifiers(token, j, delimitedIdentifier.children.PathSegmentSeparator ?? []),
941
+ delimiter: annotation_ast_nodes_1.Delimiter.exclamationSquareBrackets
942
+ }))
967
943
  ];
968
- }, [])) !== null && _d !== void 0 ? _d : []).map((identifier) => identifier);
969
- const separator = ((_e = context.PathSegmentSeparator) !== null && _e !== void 0 ? _e : [])[i - 1];
944
+ }, []) ?? []).map((identifier) => identifier);
945
+ const separator = (context.PathSegmentSeparator ?? [])[i - 1];
970
946
  const fromErrorRecovery = segment.recoveredNode && separator
971
947
  ? [{ token: this.identifierFromSeparatorToken(separator), delimiter: annotation_ast_nodes_1.Delimiter.none }]
972
948
  : [];
@@ -977,11 +953,9 @@ class CstToAstVisitor extends factory_1.Visitor {
977
953
  .sort((a, b) => compareTokensByPosition(a.token, b.token))
978
954
  .map(({ token, delimiter }) => this.tokenToIdentifier(token, delimiter));
979
955
  const separators = [
980
- ...((_b = context.pathSegment) !== null && _b !== void 0 ? _b : []).map((segment) => {
981
- var _a, _b, _c, _d;
982
- const quotedIdentifiers = (_b = (_a = segment.children.quotedIdentifier) === null || _a === void 0 ? void 0 : _a.reduce((acc, quotedIdentifier) => {
983
- var _a;
984
- const childrenSeparators = (_a = quotedIdentifier.children.PathSegmentSeparator) !== null && _a !== void 0 ? _a : [];
956
+ ...(context.pathSegment ?? []).map((segment) => {
957
+ const quotedIdentifiers = segment.children.quotedIdentifier?.reduce((acc, quotedIdentifier) => {
958
+ const childrenSeparators = quotedIdentifier.children.PathSegmentSeparator ?? [];
985
959
  return [
986
960
  ...acc,
987
961
  ...childrenSeparators.map((token) => ({
@@ -989,9 +963,8 @@ class CstToAstVisitor extends factory_1.Visitor {
989
963
  delimiter: annotation_ast_nodes_1.Delimiter.quoted
990
964
  }))
991
965
  ];
992
- }, [])) !== null && _b !== void 0 ? _b : [];
993
- const delimitedIdentifiers = (_d = (_c = segment.children.delimitedIdentifier) === null || _c === void 0 ? void 0 : _c.reduce((acc, delimitedIdentifier) => {
994
- var _a;
966
+ }, []) ?? [];
967
+ const delimitedIdentifiers = segment.children.delimitedIdentifier?.reduce((acc, delimitedIdentifier) => {
995
968
  if (!delimitedIdentifier.children.DelimitedIdentifier) {
996
969
  return [
997
970
  ...acc,
@@ -1001,7 +974,7 @@ class CstToAstVisitor extends factory_1.Visitor {
1001
974
  }
1002
975
  ];
1003
976
  }
1004
- const childrenSeparators = (_a = delimitedIdentifier.children.PathSegmentSeparator) !== null && _a !== void 0 ? _a : [];
977
+ const childrenSeparators = delimitedIdentifier.children.PathSegmentSeparator ?? [];
1005
978
  return [
1006
979
  ...acc,
1007
980
  ...childrenSeparators.map((token) => ({
@@ -1009,10 +982,10 @@ class CstToAstVisitor extends factory_1.Visitor {
1009
982
  delimiter: annotation_ast_nodes_1.Delimiter.exclamationSquareBrackets
1010
983
  }))
1011
984
  ];
1012
- }, [])) !== null && _d !== void 0 ? _d : [];
985
+ }, []) ?? [];
1013
986
  return [...quotedIdentifiers, ...delimitedIdentifiers];
1014
987
  }),
1015
- ((_c = context.PathSegmentSeparator) !== null && _c !== void 0 ? _c : []).map((token) => ({
988
+ (context.PathSegmentSeparator ?? []).map((token) => ({
1016
989
  token,
1017
990
  delimiter: annotation_ast_nodes_1.Delimiter.none
1018
991
  }))
@@ -1075,14 +1048,12 @@ class CstToAstVisitor extends factory_1.Visitor {
1075
1048
  * @returns AST record node
1076
1049
  */
1077
1050
  struct(context, location) {
1078
- var _a;
1079
1051
  const range = this.locationToRange(location);
1080
- const { properties: allProperties, annotations: allAnnotations } = ((_a = context.assignment) !== null && _a !== void 0 ? _a : [])
1052
+ const { properties: allProperties, annotations: allAnnotations } = (context.assignment ?? [])
1081
1053
  .filter((assignment) => {
1082
1054
  return (0, utils_1.hasItems)(assignment.children.path) || (0, utils_1.hasItems)(assignment.children.value);
1083
1055
  })
1084
1056
  .reduce(({ annotations, properties }, assignment, assignmentIndex, assignments) => {
1085
- var _a, _b, _c, _d, _e, _f, _g, _h;
1086
1057
  const { property, kind } = this.getRecordProperty(assignment);
1087
1058
  if (kind === 'annotation') {
1088
1059
  annotations.push(property);
@@ -1092,26 +1063,26 @@ class CstToAstVisitor extends factory_1.Visitor {
1092
1063
  }
1093
1064
  if ((0, utils_1.hasItems)(assignment.children.Colon) &&
1094
1065
  (!(0, utils_1.hasItems)(assignment.children.value) ||
1095
- (0, utils_1.hasNaNOrUndefined)((_b = (_a = assignment.children.value[0]) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.startOffset))) {
1066
+ (0, utils_1.hasNaNOrUndefined)(assignment.children.value[0]?.location?.startOffset))) {
1096
1067
  this.recoverFromMissingValue(assignment.children.Colon[0], property);
1097
1068
  }
1098
- else if (((_c = assignment.children) === null || _c === void 0 ? void 0 : _c.value) &&
1099
- ((_d = assignment.children) === null || _d === void 0 ? void 0 : _d.value.length) &&
1100
- ((_f = (_e = assignment.children.value[0]) === null || _e === void 0 ? void 0 : _e.children) === null || _f === void 0 ? void 0 : _f.path) &&
1069
+ else if (assignment.children?.value &&
1070
+ assignment.children?.value.length &&
1071
+ assignment.children.value[0]?.children?.path &&
1101
1072
  assignments[assignmentIndex + 1] &&
1102
- !((_g = assignments[assignmentIndex + 1].children) === null || _g === void 0 ? void 0 : _g.path)) {
1073
+ !assignments[assignmentIndex + 1].children?.path) {
1103
1074
  // missing value and comma: path for next property has been wrongly consumed as value for current property
1104
1075
  const start = this.tokenToRange(assignment.children.Colon[0]).end;
1105
- const end = (_h = this.locationToRange(assignment.children.value[0].location)) === null || _h === void 0 ? void 0 : _h.start;
1076
+ const end = this.locationToRange(assignment.children.value[0].location)?.start;
1106
1077
  property.value = {
1107
1078
  type: annotation_ast_nodes_1.EMPTY_VALUE_TYPE,
1108
- range: vscode_languageserver_types_1.Range.create(start, end !== null && end !== void 0 ? end : start)
1079
+ range: text_document_utils_1.Range.create(start, end ?? start)
1109
1080
  };
1110
1081
  }
1111
1082
  property.colon = this.getColon(assignment);
1112
1083
  return { properties, annotations };
1113
1084
  }, { annotations: [], properties: [] });
1114
- const commas = this.getCommaToken(context === null || context === void 0 ? void 0 : context.Comma);
1085
+ const commas = this.getCommaToken(context?.Comma);
1115
1086
  const ast = {
1116
1087
  type: annotation_ast_nodes_1.RECORD_TYPE,
1117
1088
  properties: allProperties,
@@ -1137,14 +1108,13 @@ class CstToAstVisitor extends factory_1.Visitor {
1137
1108
  * @returns Annotation AST node
1138
1109
  */
1139
1110
  assignment(context, location) {
1140
- var _a, _b, _c;
1141
1111
  const range = this.locationToRange(location);
1142
1112
  const ast = {
1143
1113
  type: annotation_ast_nodes_1.ANNOTATION_TYPE,
1144
1114
  term: this.getAssignmentKey(context, range),
1145
1115
  range
1146
1116
  };
1147
- if ((_a = context.Colon) === null || _a === void 0 ? void 0 : _a.length) {
1117
+ if (context.Colon?.length) {
1148
1118
  ast.colon = {
1149
1119
  type: annotation_ast_nodes_1.TOKEN_TYPE,
1150
1120
  value: context.Colon[0].image,
@@ -1158,7 +1128,7 @@ class CstToAstVisitor extends factory_1.Visitor {
1158
1128
  if (!ast.qualifier && ast.term.segments.length && ast.term.segments[0].value.includes('#')) {
1159
1129
  ast.qualifier = createQualifier(ast.term);
1160
1130
  }
1161
- if ((0, utils_1.hasItems)(context.value) && !(0, utils_1.hasNaNOrUndefined)((_c = (_b = context.value[0]) === null || _b === void 0 ? void 0 : _b.location) === null || _c === void 0 ? void 0 : _c.startOffset)) {
1131
+ if ((0, utils_1.hasItems)(context.value) && !(0, utils_1.hasNaNOrUndefined)(context.value[0]?.location?.startOffset)) {
1162
1132
  ast.value = this.visit(context.value[0]);
1163
1133
  }
1164
1134
  else if ((0, utils_1.hasItems)(context.Colon)) {
@@ -1186,7 +1156,7 @@ class CstToAstVisitor extends factory_1.Visitor {
1186
1156
  segments: [],
1187
1157
  separators: [],
1188
1158
  value: '',
1189
- range: vscode_languageserver_types_1.Range.create(start, end)
1159
+ range: text_document_utils_1.Range.create(start, end)
1190
1160
  };
1191
1161
  }
1192
1162
  /**
@@ -1198,7 +1168,7 @@ class CstToAstVisitor extends factory_1.Visitor {
1198
1168
  recoverFromMissingValue(colonToken, ast) {
1199
1169
  // adjust range
1200
1170
  const nextToken = findNextToken(this.tokenVector, colonToken.endOffset);
1201
- if (((nextToken === null || nextToken === void 0 ? void 0 : nextToken.image) === ',' || (nextToken === null || nextToken === void 0 ? void 0 : nextToken.image) === '}') && (nextToken === null || nextToken === void 0 ? void 0 : nextToken.startColumn)) {
1171
+ if ((nextToken?.image === ',' || nextToken?.image === '}') && nextToken?.startColumn) {
1202
1172
  if (ast.range) {
1203
1173
  // annotation range should end before comma
1204
1174
  ast.range.end = this.tokenToRange(nextToken).start;
@@ -1208,7 +1178,7 @@ class CstToAstVisitor extends factory_1.Visitor {
1208
1178
  const nextTokenRange = this.tokenToRange(nextToken);
1209
1179
  ast.value = {
1210
1180
  type: annotation_ast_nodes_1.EMPTY_VALUE_TYPE,
1211
- range: vscode_languageserver_types_1.Range.create(colonRange.end, nextTokenRange.start)
1181
+ range: text_document_utils_1.Range.create(colonRange.end, nextTokenRange.start)
1212
1182
  };
1213
1183
  }
1214
1184
  }