@steedos/service-metadata-objects 3.0.0-beta.8 → 3.0.0-beta.80

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.
@@ -25,27 +25,60 @@ const isAmisFormula = (formula: string) => {
25
25
  // return result;
26
26
  // }
27
27
 
28
- function extractAmisFormulaVariableNames(node) {
29
- const result = [];
28
+ function extractAmisFormulaVariableNames(data) {
29
+ const variables = new Set();
30
30
 
31
31
  function traverse(node) {
32
- if (!node) return;
32
+ if (!node || typeof node !== "object") return;
33
33
 
34
- // 如果是变量节点,收集它的name
35
- if (node.type === "variable") {
36
- result.push(node.name);
34
+ // 处理普通变量(排除作为getter host的情况)
35
+ if (node.type === "variable" && !isGetterHost(node)) {
36
+ variables.add(node.name);
37
+ }
38
+ // 处理最外层的getter(不处理嵌套的getter host)
39
+ else if (node.type === "getter" && !isGetterHost(node)) {
40
+ const path = getFullGetterPath(node);
41
+ if (path) variables.add(path);
37
42
  }
38
43
 
39
44
  // 递归遍历所有子节点
40
45
  for (const key in node) {
41
- if (typeof node[key] === "object" && node[key] !== null) {
46
+ if (key !== "parent" && typeof node[key] === "object") {
47
+ // 设置父节点引用
48
+ node[key].parent = node;
42
49
  traverse(node[key]);
43
50
  }
44
51
  }
45
52
  }
46
53
 
47
- traverse(node);
48
- return result;
54
+ function isGetterHost(node) {
55
+ return (
56
+ node.parent && node.parent.type === "getter" && node.parent.host === node
57
+ );
58
+ }
59
+
60
+ function getFullGetterPath(getterNode) {
61
+ const parts = [getterNode.key.name];
62
+ let current = getterNode.host;
63
+
64
+ // 向上追溯host
65
+ while (current) {
66
+ if (current.type === "getter") {
67
+ parts.unshift(current.key.name);
68
+ current = current.host;
69
+ } else if (current.type === "variable") {
70
+ parts.unshift(current.name);
71
+ return parts.join(".");
72
+ } else {
73
+ break;
74
+ }
75
+ }
76
+
77
+ return null;
78
+ }
79
+
80
+ traverse(data);
81
+ return Array.from(variables);
49
82
  }
50
83
 
51
84
  /**
@@ -55,7 +88,8 @@ function extractAmisFormulaVariableNames(node) {
55
88
  export const pickFormulaVars = (formula: string): Array<string> => {
56
89
  if (isAmisFormula(formula)) {
57
90
  const result = extractAmisFormulaVariableNames(parse(formula));
58
- return result;
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ return result as any;
59
93
  }
60
94
  return extract(formula);
61
95
  };