@valtzu/codemirror-lang-el 0.6.2 → 0.7.0

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.
package/dist/tooltip.js CHANGED
@@ -1,7 +1,21 @@
1
1
  import { StateField } from '@codemirror/state';
2
- import { showTooltip, hoverTooltip, EditorView } from '@codemirror/view';
2
+ import { showTooltip, hoverTooltip } from '@codemirror/view';
3
3
  import { syntaxTree } from '@codemirror/language';
4
4
 
5
+ var ELScalar;
6
+ (function (ELScalar) {
7
+ ELScalar["Bool"] = "bool";
8
+ ELScalar["Number"] = "number";
9
+ ELScalar["String"] = "string";
10
+ ELScalar["Null"] = "null";
11
+ ELScalar["Any"] = "any";
12
+ })(ELScalar || (ELScalar = {}));
13
+
14
+ // @ts-ignore
15
+ const t = {
16
+ deserialize: (str) => str,
17
+ };
18
+
5
19
  const createInfoElement = (html) => {
6
20
  const dom = document.createElement("div");
7
21
  dom.innerHTML = html;
@@ -38,12 +52,16 @@ const resolveIdentifier = (nodeName, identifier, config) => {
38
52
  }
39
53
  };
40
54
  function resolveTypes(state, node, config, matchExact) {
41
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
55
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
42
56
  let types = new Set();
43
57
  if (!node) {
44
58
  return types;
45
59
  }
46
- if (node.name === 'Call' && node.firstChild && node.lastChild) {
60
+ let type;
61
+ if (typeof (type = node.type.prop(t)) !== "undefined") {
62
+ types.add(type);
63
+ }
64
+ else if (node.name === 'Call' && node.firstChild && node.lastChild) {
47
65
  resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
48
66
  }
49
67
  else if (node.name === 'Variable') {
@@ -79,17 +97,32 @@ function resolveTypes(state, node, config, matchExact) {
79
97
  resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
80
98
  resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
81
99
  }
82
- else if (node.name === 'BinaryExpression' && ((_k = (_j = node.firstChild) === null || _j === void 0 ? void 0 : _j.nextSibling) === null || _k === void 0 ? void 0 : _k.name) == 'Operator' && node.lastChild) {
100
+ else if (node.name === 'BinaryExpression' && ((_j = node.firstChild) === null || _j === void 0 ? void 0 : _j.nextSibling) && ((_l = (_k = node.firstChild) === null || _k === void 0 ? void 0 : _k.nextSibling) === null || _l === void 0 ? void 0 : _l.nextSibling)) {
83
101
  const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
84
- if (operator == '?:' || operator == '??') {
85
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
86
- }
87
102
  if (operator == '?:' || operator == '??' || operator == '?') {
88
- resolveTypes(state, node.lastChild, config).forEach(x => types.add(x));
103
+ if (operator == '?:' || operator == '??') {
104
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
105
+ }
106
+ resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
107
+ }
108
+ else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
109
+ types.add(ELScalar.Bool);
110
+ }
111
+ else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
112
+ types.add(ELScalar.Number);
113
+ }
114
+ }
115
+ else if (node.name === 'UnaryExpression' && node.firstChild) {
116
+ const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
117
+ if (['not', '!'].includes(operator)) {
118
+ types.add(ELScalar.Bool);
119
+ }
120
+ else if (['+', '-'].includes(operator)) {
121
+ types.add(ELScalar.Number);
89
122
  }
90
123
  }
91
124
  if (types.size === 0) {
92
- types.add('any');
125
+ types.add(ELScalar.Any);
93
126
  }
94
127
  return types;
95
128
  }
@@ -106,6 +139,7 @@ const keywords = [
106
139
  { name: 'not' },
107
140
  { name: 'or' },
108
141
  { name: 'and' },
142
+ { name: 'xor' },
109
143
  ];
110
144
 
111
145
  function getNodeOrdinal(node) {
@@ -128,7 +162,7 @@ function getCursorTooltips(state) {
128
162
  return state.selection.ranges
129
163
  .filter(range => range.empty)
130
164
  .map(range => {
131
- var _a;
165
+ var _a, _b;
132
166
  const tree = syntaxTree(state);
133
167
  const node = tree.resolveInner(range.from, 0);
134
168
  const args = resolveArguments(node);
@@ -140,7 +174,7 @@ function getCursorTooltips(state) {
140
174
  return null;
141
175
  }
142
176
  const n = args.childAfter(range.from - 1);
143
- const argName = (_a = fn.args) === null || _a === void 0 ? void 0 : _a[n ? getNodeOrdinal(n) : 0];
177
+ const argName = (_b = (_a = fn.args) === null || _a === void 0 ? void 0 : _a[n ? getNodeOrdinal(n) : 0]) === null || _b === void 0 ? void 0 : _b.name;
144
178
  if (n && n.from !== range.from || !argName) {
145
179
  return null;
146
180
  }
@@ -215,17 +249,5 @@ const keywordTooltip = hoverTooltip((view, pos, side) => {
215
249
  create: () => ({ dom: createInfoElement(info) }),
216
250
  };
217
251
  });
218
- const cursorTooltipBaseTheme = EditorView.baseTheme({
219
- ".cm-tooltip.cm-tooltip-cursor": {
220
- boxShadow: 'rgba(0, 0, 0, .15) 0 1px 2px',
221
- border: "1px solid rgba(127, 127, 127, .2)",
222
- padding: "2px 7px",
223
- borderRadius: "4px",
224
- "& .cm-tooltip-arrow:before": {},
225
- "& .cm-tooltip-arrow:after": {
226
- borderTopColor: "transparent"
227
- }
228
- }
229
- });
230
252
 
231
- export { cursorTooltipBaseTheme, cursorTooltipField, keywordTooltip };
253
+ export { cursorTooltipField, keywordTooltip };
package/dist/utils.cjs ADDED
@@ -0,0 +1,150 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var ELScalar;
6
+ (function (ELScalar) {
7
+ ELScalar["Bool"] = "bool";
8
+ ELScalar["Number"] = "number";
9
+ ELScalar["String"] = "string";
10
+ ELScalar["Null"] = "null";
11
+ ELScalar["Any"] = "any";
12
+ })(ELScalar || (ELScalar = {}));
13
+
14
+ // @ts-ignore
15
+ const t = {
16
+ deserialize: (str) => str,
17
+ };
18
+
19
+ const createInfoElement = (html) => {
20
+ const dom = document.createElement("div");
21
+ dom.innerHTML = html;
22
+ dom.className = 'cm-diagnostic';
23
+ return dom;
24
+ };
25
+ function resolveFunctionDefinition(node, state, config) {
26
+ var _a;
27
+ if (!node) {
28
+ return undefined;
29
+ }
30
+ let identifier;
31
+ if (node.name === 'ObjectAccess' && node.lastChild) {
32
+ const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
33
+ const types = Array.from(resolveTypes(state, leftArgument, config));
34
+ identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
35
+ return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
36
+ }
37
+ else if (node.name === 'Function') {
38
+ identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
39
+ return resolveCallable(identifier, config);
40
+ }
41
+ }
42
+ const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.functions) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier); };
43
+ const resolveIdentifier = (nodeName, identifier, config) => {
44
+ var _a;
45
+ switch (nodeName) {
46
+ case 'Method':
47
+ case 'Function':
48
+ return resolveCallable(identifier, config);
49
+ case 'Property':
50
+ case 'Variable':
51
+ return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
52
+ }
53
+ };
54
+ function resolveTypes(state, node, config, matchExact) {
55
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
56
+ let types = new Set();
57
+ if (!node) {
58
+ return types;
59
+ }
60
+ let type;
61
+ if (typeof (type = node.type.prop(t)) !== "undefined") {
62
+ types.add(type);
63
+ }
64
+ else if (node.name === 'Call' && node.firstChild && node.lastChild) {
65
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
66
+ }
67
+ else if (node.name === 'Variable') {
68
+ const varName = state.sliceDoc(node.from, node.to) || '';
69
+ // @ts-ignore
70
+ (_b = (_a = resolveIdentifier(node.name, varName, config)) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.forEach((x) => types.add(x));
71
+ }
72
+ else if (node.name === 'Function') {
73
+ const varName = state.sliceDoc(node.from, node.to) || '';
74
+ // @ts-ignore
75
+ (_d = (_c = resolveIdentifier(node.name, varName, config)) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
76
+ }
77
+ else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
78
+ const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
79
+ (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
80
+ var _a, _b, _c, _d;
81
+ // @ts-ignore
82
+ (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
83
+ });
84
+ }
85
+ else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
86
+ const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
87
+ (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
88
+ var _a, _b, _c, _d;
89
+ // @ts-ignore
90
+ (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
91
+ });
92
+ }
93
+ else if (node.name === 'Application' && node.firstChild) {
94
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
95
+ }
96
+ else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
97
+ resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
98
+ resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
99
+ }
100
+ else if (node.name === 'BinaryExpression' && ((_j = node.firstChild) === null || _j === void 0 ? void 0 : _j.nextSibling) && ((_l = (_k = node.firstChild) === null || _k === void 0 ? void 0 : _k.nextSibling) === null || _l === void 0 ? void 0 : _l.nextSibling)) {
101
+ const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
102
+ if (operator == '?:' || operator == '??' || operator == '?') {
103
+ if (operator == '?:' || operator == '??') {
104
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
105
+ }
106
+ resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
107
+ }
108
+ else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
109
+ types.add(ELScalar.Bool);
110
+ }
111
+ else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
112
+ types.add(ELScalar.Number);
113
+ }
114
+ }
115
+ else if (node.name === 'UnaryExpression' && node.firstChild) {
116
+ const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
117
+ if (['not', '!'].includes(operator)) {
118
+ types.add(ELScalar.Bool);
119
+ }
120
+ else if (['+', '-'].includes(operator)) {
121
+ types.add(ELScalar.Number);
122
+ }
123
+ }
124
+ if (types.size === 0) {
125
+ types.add(ELScalar.Any);
126
+ }
127
+ return types;
128
+ }
129
+ function getExpressionLanguageConfig(state) {
130
+ return state.languageDataAt('expressionLanguageConfig', 0)[0];
131
+ }
132
+ const keywords = [
133
+ { name: 'starts with', info: 'Check if a string starts with a specific string' },
134
+ { name: 'ends with', info: 'Check if a string ends with a specific string' },
135
+ { name: 'contains', info: 'Check if a string is not included in another string' },
136
+ { name: 'matches', info: 'Check if a string matches a regex pattern' },
137
+ { name: 'not in', info: 'Check if a value is not included in an array' },
138
+ { name: 'in', info: 'Check if a value is included in an array' },
139
+ { name: 'not' },
140
+ { name: 'or' },
141
+ { name: 'and' },
142
+ { name: 'xor' },
143
+ ];
144
+
145
+ exports.createInfoElement = createInfoElement;
146
+ exports.getExpressionLanguageConfig = getExpressionLanguageConfig;
147
+ exports.keywords = keywords;
148
+ exports.resolveFunctionDefinition = resolveFunctionDefinition;
149
+ exports.resolveIdentifier = resolveIdentifier;
150
+ exports.resolveTypes = resolveTypes;
@@ -0,0 +1,53 @@
1
+ import { SyntaxNode } from "@lezer/common";
2
+ import { EditorState } from "@codemirror/state";
3
+ /**
4
+ * Represents a variable or a property of an object
5
+ */
6
+ interface ELIdentifier {
7
+ name: string;
8
+ detail?: string;
9
+ info?: string;
10
+ type?: string[];
11
+ }
12
+ /**
13
+ * Represents a function or a method of an object
14
+ */
15
+ interface ELFunction {
16
+ name: string;
17
+ args: ELParameter[];
18
+ info?: string;
19
+ returnType?: string[];
20
+ }
21
+ interface ELParameter {
22
+ name: string;
23
+ type?: string[];
24
+ info?: string;
25
+ optional?: boolean;
26
+ }
27
+ interface ELType {
28
+ identifiers?: ELIdentifier[];
29
+ functions?: ELFunction[];
30
+ info?: string;
31
+ }
32
+ interface ExpressionLanguageConfig {
33
+ types?: {
34
+ [key: string]: ELType;
35
+ };
36
+ identifiers?: ELIdentifier[];
37
+ functions?: ELFunction[];
38
+ }
39
+ interface ELKeyword {
40
+ name: string;
41
+ detail?: string;
42
+ info?: string;
43
+ }
44
+ declare const createInfoElement: (html: string) => HTMLDivElement;
45
+ declare function resolveFunctionDefinition(node: SyntaxNode | null, state: EditorState, config: ExpressionLanguageConfig): ELFunction | undefined;
46
+ declare const resolveIdentifier: (nodeName: 'Method' | 'Property' | 'Function' | 'Variable', identifier?: string, config?: {
47
+ identifiers?: ELIdentifier[];
48
+ functions?: ELFunction[];
49
+ }) => ELIdentifier | ELFunction | undefined;
50
+ declare function resolveTypes(state: EditorState, node: SyntaxNode | undefined, config: ExpressionLanguageConfig, matchExact: boolean): Set<string>;
51
+ declare function getExpressionLanguageConfig(state: EditorState): ExpressionLanguageConfig;
52
+ declare const keywords: ELKeyword[];
53
+ export { createInfoElement, resolveFunctionDefinition, resolveIdentifier, resolveTypes, getExpressionLanguageConfig, keywords };
@@ -0,0 +1,53 @@
1
+ import { SyntaxNode } from "@lezer/common";
2
+ import { EditorState } from "@codemirror/state";
3
+ /**
4
+ * Represents a variable or a property of an object
5
+ */
6
+ interface ELIdentifier {
7
+ name: string;
8
+ detail?: string;
9
+ info?: string;
10
+ type?: string[];
11
+ }
12
+ /**
13
+ * Represents a function or a method of an object
14
+ */
15
+ interface ELFunction {
16
+ name: string;
17
+ args: ELParameter[];
18
+ info?: string;
19
+ returnType?: string[];
20
+ }
21
+ interface ELParameter {
22
+ name: string;
23
+ type?: string[];
24
+ info?: string;
25
+ optional?: boolean;
26
+ }
27
+ interface ELType {
28
+ identifiers?: ELIdentifier[];
29
+ functions?: ELFunction[];
30
+ info?: string;
31
+ }
32
+ interface ExpressionLanguageConfig {
33
+ types?: {
34
+ [key: string]: ELType;
35
+ };
36
+ identifiers?: ELIdentifier[];
37
+ functions?: ELFunction[];
38
+ }
39
+ interface ELKeyword {
40
+ name: string;
41
+ detail?: string;
42
+ info?: string;
43
+ }
44
+ declare const createInfoElement: (html: string) => HTMLDivElement;
45
+ declare function resolveFunctionDefinition(node: SyntaxNode | null, state: EditorState, config: ExpressionLanguageConfig): ELFunction | undefined;
46
+ declare const resolveIdentifier: (nodeName: 'Method' | 'Property' | 'Function' | 'Variable', identifier?: string, config?: {
47
+ identifiers?: ELIdentifier[];
48
+ functions?: ELFunction[];
49
+ }) => ELIdentifier | ELFunction | undefined;
50
+ declare function resolveTypes(state: EditorState, node: SyntaxNode | undefined, config: ExpressionLanguageConfig, matchExact: boolean): Set<string>;
51
+ declare function getExpressionLanguageConfig(state: EditorState): ExpressionLanguageConfig;
52
+ declare const keywords: ELKeyword[];
53
+ export { createInfoElement, resolveFunctionDefinition, resolveIdentifier, resolveTypes, getExpressionLanguageConfig, keywords };
package/dist/utils.js ADDED
@@ -0,0 +1,141 @@
1
+ var ELScalar;
2
+ (function (ELScalar) {
3
+ ELScalar["Bool"] = "bool";
4
+ ELScalar["Number"] = "number";
5
+ ELScalar["String"] = "string";
6
+ ELScalar["Null"] = "null";
7
+ ELScalar["Any"] = "any";
8
+ })(ELScalar || (ELScalar = {}));
9
+
10
+ // @ts-ignore
11
+ const t = {
12
+ deserialize: (str) => str,
13
+ };
14
+
15
+ const createInfoElement = (html) => {
16
+ const dom = document.createElement("div");
17
+ dom.innerHTML = html;
18
+ dom.className = 'cm-diagnostic';
19
+ return dom;
20
+ };
21
+ function resolveFunctionDefinition(node, state, config) {
22
+ var _a;
23
+ if (!node) {
24
+ return undefined;
25
+ }
26
+ let identifier;
27
+ if (node.name === 'ObjectAccess' && node.lastChild) {
28
+ const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
29
+ const types = Array.from(resolveTypes(state, leftArgument, config));
30
+ identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
31
+ return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
32
+ }
33
+ else if (node.name === 'Function') {
34
+ identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
35
+ return resolveCallable(identifier, config);
36
+ }
37
+ }
38
+ const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.functions) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier); };
39
+ const resolveIdentifier = (nodeName, identifier, config) => {
40
+ var _a;
41
+ switch (nodeName) {
42
+ case 'Method':
43
+ case 'Function':
44
+ return resolveCallable(identifier, config);
45
+ case 'Property':
46
+ case 'Variable':
47
+ return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
48
+ }
49
+ };
50
+ function resolveTypes(state, node, config, matchExact) {
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
52
+ let types = new Set();
53
+ if (!node) {
54
+ return types;
55
+ }
56
+ let type;
57
+ if (typeof (type = node.type.prop(t)) !== "undefined") {
58
+ types.add(type);
59
+ }
60
+ else if (node.name === 'Call' && node.firstChild && node.lastChild) {
61
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
62
+ }
63
+ else if (node.name === 'Variable') {
64
+ const varName = state.sliceDoc(node.from, node.to) || '';
65
+ // @ts-ignore
66
+ (_b = (_a = resolveIdentifier(node.name, varName, config)) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.forEach((x) => types.add(x));
67
+ }
68
+ else if (node.name === 'Function') {
69
+ const varName = state.sliceDoc(node.from, node.to) || '';
70
+ // @ts-ignore
71
+ (_d = (_c = resolveIdentifier(node.name, varName, config)) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
72
+ }
73
+ else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
74
+ const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
75
+ (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
76
+ var _a, _b, _c, _d;
77
+ // @ts-ignore
78
+ (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
79
+ });
80
+ }
81
+ else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
82
+ const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
83
+ (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
84
+ var _a, _b, _c, _d;
85
+ // @ts-ignore
86
+ (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
87
+ });
88
+ }
89
+ else if (node.name === 'Application' && node.firstChild) {
90
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
91
+ }
92
+ else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
93
+ resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
94
+ resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
95
+ }
96
+ else if (node.name === 'BinaryExpression' && ((_j = node.firstChild) === null || _j === void 0 ? void 0 : _j.nextSibling) && ((_l = (_k = node.firstChild) === null || _k === void 0 ? void 0 : _k.nextSibling) === null || _l === void 0 ? void 0 : _l.nextSibling)) {
97
+ const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
98
+ if (operator == '?:' || operator == '??' || operator == '?') {
99
+ if (operator == '?:' || operator == '??') {
100
+ resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
101
+ }
102
+ resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
103
+ }
104
+ else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
105
+ types.add(ELScalar.Bool);
106
+ }
107
+ else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
108
+ types.add(ELScalar.Number);
109
+ }
110
+ }
111
+ else if (node.name === 'UnaryExpression' && node.firstChild) {
112
+ const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
113
+ if (['not', '!'].includes(operator)) {
114
+ types.add(ELScalar.Bool);
115
+ }
116
+ else if (['+', '-'].includes(operator)) {
117
+ types.add(ELScalar.Number);
118
+ }
119
+ }
120
+ if (types.size === 0) {
121
+ types.add(ELScalar.Any);
122
+ }
123
+ return types;
124
+ }
125
+ function getExpressionLanguageConfig(state) {
126
+ return state.languageDataAt('expressionLanguageConfig', 0)[0];
127
+ }
128
+ const keywords = [
129
+ { name: 'starts with', info: 'Check if a string starts with a specific string' },
130
+ { name: 'ends with', info: 'Check if a string ends with a specific string' },
131
+ { name: 'contains', info: 'Check if a string is not included in another string' },
132
+ { name: 'matches', info: 'Check if a string matches a regex pattern' },
133
+ { name: 'not in', info: 'Check if a value is not included in an array' },
134
+ { name: 'in', info: 'Check if a value is included in an array' },
135
+ { name: 'not' },
136
+ { name: 'or' },
137
+ { name: 'and' },
138
+ { name: 'xor' },
139
+ ];
140
+
141
+ export { createInfoElement, getExpressionLanguageConfig, keywords, resolveFunctionDefinition, resolveIdentifier, resolveTypes };
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "access": "public",
44
44
  "registry": "https://registry.npmjs.org/"
45
45
  },
46
- "version": "0.6.2"
46
+ "version": "0.7.0"
47
47
  }