@nocobase/plugin-flow-engine 2.1.0-beta.43 → 2.1.0-beta.45

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 (90) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +9 -9
  3. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  4. package/dist/node_modules/acorn/package.json +1 -1
  5. package/dist/node_modules/acorn-jsx/package.json +1 -1
  6. package/dist/node_modules/acorn-walk/package.json +1 -1
  7. package/dist/node_modules/ses/package.json +1 -1
  8. package/dist/node_modules/zod/package.json +1 -1
  9. package/dist/server/flow-surfaces/authoring-validation.js +160 -21
  10. package/dist/server/flow-surfaces/catalog.js +9 -5
  11. package/dist/server/flow-surfaces/chart-config.js +29 -6
  12. package/dist/server/flow-surfaces/contract-guard.js +39 -5
  13. package/dist/server/flow-surfaces/default-block-actions.js +2 -0
  14. package/dist/server/flow-surfaces/errors.d.ts +15 -0
  15. package/dist/server/flow-surfaces/errors.js +49 -3
  16. package/dist/server/flow-surfaces/filter-group.d.ts +7 -1
  17. package/dist/server/flow-surfaces/filter-group.js +175 -71
  18. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
  19. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
  20. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
  21. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
  22. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
  23. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
  24. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
  25. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
  26. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
  27. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
  28. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
  29. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
  30. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
  31. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
  32. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
  33. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
  34. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
  35. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
  36. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
  37. package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
  38. package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
  39. package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
  40. package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -11138
  41. package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
  42. package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
  43. package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
  44. package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
  45. package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
  46. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
  47. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
  48. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
  49. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
  50. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
  51. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
  52. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
  53. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
  54. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
  55. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
  56. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
  57. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
  58. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
  59. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
  60. package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
  61. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
  62. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
  63. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
  64. package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
  65. package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
  66. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
  67. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
  68. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
  69. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
  70. package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
  71. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
  72. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
  73. package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
  74. package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
  75. package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
  76. package/dist/server/flow-surfaces/service-helpers.js +105 -0
  77. package/dist/server/flow-surfaces/service-utils.d.ts +15 -3
  78. package/dist/server/flow-surfaces/service-utils.js +5 -4
  79. package/dist/server/flow-surfaces/service.d.ts +4 -0
  80. package/dist/server/flow-surfaces/service.js +360 -30
  81. package/dist/server/flow-surfaces/types.d.ts +3 -0
  82. package/dist/server/repository.d.ts +15 -1
  83. package/dist/server/repository.js +262 -23
  84. package/dist/server/template/contexts.d.ts +2 -0
  85. package/dist/server/template/contexts.js +34 -0
  86. package/dist/server/template/resolver.js +233 -22
  87. package/dist/swagger/flow-surfaces.d.ts +175 -0
  88. package/dist/swagger/flow-surfaces.js +130 -51
  89. package/dist/swagger/index.d.ts +175 -0
  90. package/package.json +2 -2
@@ -0,0 +1,661 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var bindings_exports = {};
28
+ __export(bindings_exports, {
29
+ addParameterBindings: () => addParameterBindings,
30
+ addSourceBinding: () => addSourceBinding,
31
+ collectArrayBindingPatternNames: () => collectArrayBindingPatternNames,
32
+ collectArrowParameterBindingNames: () => collectArrowParameterBindingNames,
33
+ collectBindingPatternNames: () => collectBindingPatternNames,
34
+ collectDestructuredVariableBindingNames: () => collectDestructuredVariableBindingNames,
35
+ collectMethodParameterBindingNames: () => collectMethodParameterBindingNames,
36
+ collectObjectBindingPatternNames: () => collectObjectBindingPatternNames,
37
+ collectParameterBindingNames: () => collectParameterBindingNames,
38
+ collectSourceBindings: () => collectSourceBindings,
39
+ collectStringLiteralBindings: () => collectStringLiteralBindings,
40
+ dedupeIndexedEntries: () => dedupeIndexedEntries,
41
+ extractBindingPatternNames: () => extractBindingPatternNames,
42
+ findArrowBodyRange: () => findArrowBodyRange,
43
+ findAstAncestor: () => findAstAncestor,
44
+ findBraceBodyAfter: () => findBraceBodyAfter,
45
+ findFollowingBraceRange: () => findFollowingBraceRange,
46
+ findFollowingStatementRange: () => findFollowingStatementRange,
47
+ findForHeaderRangeContaining: () => findForHeaderRangeContaining,
48
+ findForScopeForDeclaration: () => findForScopeForDeclaration,
49
+ findInnermostRange: () => findInnermostRange,
50
+ findNamedFunctionOrClassExpressionRange: () => findNamedFunctionOrClassExpressionRange,
51
+ findSingleStatementEnd: () => findSingleStatementEnd,
52
+ findSourceBindingByDeclaration: () => findSourceBindingByDeclaration,
53
+ getAstBindingScopeRange: () => getAstBindingScopeRange,
54
+ getAstExecutionScopeRange: () => getAstExecutionScopeRange,
55
+ isAstAlwaysExecutedInCurrentExecutionScope: () => isAstAlwaysExecutedInCurrentExecutionScope,
56
+ isAstDefinitelyEnumerableComputedObjectKey: () => isAstDefinitelyEnumerableComputedObjectKey,
57
+ isAstDefinitelyEnumerableObjectProperty: () => isAstDefinitelyEnumerableObjectProperty,
58
+ isAstDefinitelyNonEmptyArrayElement: () => isAstDefinitelyNonEmptyArrayElement,
59
+ isAstDefinitelyNonEmptyForInSource: () => isAstDefinitelyNonEmptyForInSource,
60
+ isAstDefinitelyNonEmptyForOfSource: () => isAstDefinitelyNonEmptyForOfSource,
61
+ isAstFunctionLike: () => isAstFunctionLike,
62
+ isExpressionPrefixToken: () => isExpressionPrefixToken,
63
+ isNameBoundAtIndex: () => isNameBoundAtIndex,
64
+ isNamedFunctionOrClassExpression: () => isNamedFunctionOrClassExpression,
65
+ isSameAstRange: () => isSameAstRange,
66
+ isSourceAliasShadowedAtIndex: () => isSourceAliasShadowedAtIndex,
67
+ resolveBindingScope: () => resolveBindingScope,
68
+ unwrapAstChainExpression: () => unwrapAstChainExpression
69
+ });
70
+ module.exports = __toCommonJS(bindings_exports);
71
+ var import_source = require("./source");
72
+ function collectSourceBindings(masked, functionRanges, blockRanges, staticBlockRanges) {
73
+ const bindings = [];
74
+ for (const match of masked.matchAll(/\b(const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/g)) {
75
+ const kind = match[1];
76
+ const matchIndex = match.index || 0;
77
+ if ((kind === "function" || kind === "class") && isNamedFunctionOrClassExpression(masked, matchIndex, kind)) {
78
+ const expressionRange = findNamedFunctionOrClassExpressionRange(masked, matchIndex, kind);
79
+ if (expressionRange) {
80
+ bindings.push({
81
+ name: match[2],
82
+ declarationStart: matchIndex,
83
+ start: expressionRange.start,
84
+ end: expressionRange.end
85
+ });
86
+ }
87
+ continue;
88
+ }
89
+ addSourceBinding(
90
+ bindings,
91
+ functionRanges,
92
+ blockRanges,
93
+ staticBlockRanges,
94
+ masked,
95
+ match[2],
96
+ matchIndex,
97
+ masked.length,
98
+ kind
99
+ );
100
+ }
101
+ collectDestructuredVariableBindingNames(masked, functionRanges, blockRanges, staticBlockRanges, bindings);
102
+ collectParameterBindingNames(masked, bindings);
103
+ return bindings;
104
+ }
105
+ function collectStringLiteralBindings(source, masked, bindings) {
106
+ const entries = [];
107
+ const commentMasked = (0, import_source.maskJavaScriptComments)(source);
108
+ for (const match of commentMasked.matchAll(/\bconst\s+([A-Za-z_$][\w$]*)\s*=\s*(['"`])/g)) {
109
+ const declarationIndex = match.index || 0;
110
+ const literalStart = declarationIndex + match[0].lastIndexOf(match[2]);
111
+ const statementEnd = findSingleStatementEnd(masked, declarationIndex);
112
+ const literal = (0, import_source.readCompleteStringLiteral)(source.slice(literalStart, statementEnd));
113
+ if (!literal) {
114
+ continue;
115
+ }
116
+ const binding = findSourceBindingByDeclaration(bindings, match[1], declarationIndex);
117
+ entries.push({
118
+ name: match[1],
119
+ value: literal.value,
120
+ declarationStart: declarationIndex,
121
+ start: declarationIndex,
122
+ end: (binding == null ? void 0 : binding.end) ?? masked.length
123
+ });
124
+ }
125
+ return entries;
126
+ }
127
+ function isNamedFunctionOrClassExpression(masked, keywordIndex, kind) {
128
+ let previous = (0, import_source.getPreviousSignificantTokenInfo)(masked, keywordIndex);
129
+ if (kind === "function" && (previous == null ? void 0 : previous.token) === "async") {
130
+ previous = (0, import_source.getPreviousSignificantTokenInfo)(masked, previous.start);
131
+ }
132
+ if (!previous) {
133
+ return false;
134
+ }
135
+ return isExpressionPrefixToken(previous.token);
136
+ }
137
+ function isExpressionPrefixToken(token) {
138
+ return [
139
+ "=",
140
+ "(",
141
+ "[",
142
+ ",",
143
+ ":",
144
+ "?",
145
+ "return",
146
+ "throw",
147
+ "yield",
148
+ "await",
149
+ "case",
150
+ "new",
151
+ "delete",
152
+ "void",
153
+ "typeof"
154
+ ].includes(token) || /^[!~+\-*%&|^<>]$/.test(token);
155
+ }
156
+ function findNamedFunctionOrClassExpressionRange(masked, keywordIndex, kind) {
157
+ if (kind === "function") {
158
+ const openParen = masked.indexOf("(", keywordIndex);
159
+ const closeParen = (0, import_source.findMatchingDelimiter)(masked, openParen);
160
+ const bodyRange = closeParen > openParen ? findBraceBodyAfter(masked, closeParen) : void 0;
161
+ return bodyRange ? { start: keywordIndex, end: bodyRange.end } : void 0;
162
+ }
163
+ const openBrace = masked.indexOf("{", keywordIndex);
164
+ const closeBrace = (0, import_source.findMatchingDelimiter)(masked, openBrace);
165
+ return closeBrace > openBrace ? { start: openBrace, end: closeBrace + 1 } : void 0;
166
+ }
167
+ function addSourceBinding(bindings, functionRanges, blockRanges, staticBlockRanges, masked, name, start, sourceEnd, kind) {
168
+ const scope = resolveBindingScope(masked, sourceEnd, start, kind, functionRanges, blockRanges, staticBlockRanges);
169
+ bindings.push({
170
+ name,
171
+ declarationStart: start,
172
+ start: scope.start,
173
+ end: scope.end
174
+ });
175
+ }
176
+ function resolveBindingScope(masked, sourceEnd, start, kind, functionRanges, blockRanges, staticBlockRanges) {
177
+ const forScope = ["const", "let", "class"].includes(kind) ? findForScopeForDeclaration(masked, start, blockRanges) : void 0;
178
+ if (forScope) {
179
+ return forScope;
180
+ }
181
+ if (["const", "let", "class"].includes(kind)) {
182
+ return findInnermostRange(start, blockRanges) || { start: 0, end: sourceEnd };
183
+ }
184
+ const functionScope = findInnermostRange(start, functionRanges);
185
+ if (functionScope) {
186
+ return functionScope;
187
+ }
188
+ const staticBlockScope = findInnermostRange(start, staticBlockRanges);
189
+ if (staticBlockScope) {
190
+ return staticBlockScope;
191
+ }
192
+ return { start: 0, end: sourceEnd };
193
+ }
194
+ function findForScopeForDeclaration(masked, start, blockRanges) {
195
+ const forHeader = findForHeaderRangeContaining(masked, start);
196
+ if (!forHeader) {
197
+ return void 0;
198
+ }
199
+ const bodyRange = findFollowingStatementRange(masked, forHeader.end, blockRanges);
200
+ return bodyRange ? { start: forHeader.start, end: bodyRange.end } : void 0;
201
+ }
202
+ function findForHeaderRangeContaining(masked, start) {
203
+ for (const match of masked.matchAll(/\bfor\s*(?:await\s*)?\(/g)) {
204
+ const openParen = masked.indexOf("(", match.index || 0);
205
+ const closeParen = (0, import_source.findMatchingDelimiter)(masked, openParen);
206
+ if (start > openParen && start < closeParen) {
207
+ return { start: openParen + 1, end: closeParen };
208
+ }
209
+ }
210
+ return void 0;
211
+ }
212
+ function findFollowingBraceRange(masked, afterIndex, blockRanges) {
213
+ let cursor = afterIndex + 1;
214
+ while (cursor < masked.length && /\s/.test(masked[cursor])) {
215
+ cursor += 1;
216
+ }
217
+ return masked[cursor] === "{" ? blockRanges.find((range) => range.start === cursor) : void 0;
218
+ }
219
+ function findFollowingStatementRange(masked, afterIndex, blockRanges) {
220
+ const braceRange = findFollowingBraceRange(masked, afterIndex, blockRanges);
221
+ if (braceRange) {
222
+ return braceRange;
223
+ }
224
+ let start = afterIndex + 1;
225
+ while (start < masked.length && /\s/.test(masked[start])) {
226
+ start += 1;
227
+ }
228
+ if (start >= masked.length) {
229
+ return void 0;
230
+ }
231
+ const end = findSingleStatementEnd(masked, start);
232
+ return end > start ? { start, end } : void 0;
233
+ }
234
+ function findSingleStatementEnd(masked, start) {
235
+ let parenDepth = 0;
236
+ let bracketDepth = 0;
237
+ let braceDepth = 0;
238
+ for (let index = start; index < masked.length; index += 1) {
239
+ const char = masked[index];
240
+ if (char === "(") {
241
+ parenDepth += 1;
242
+ } else if (char === ")" && parenDepth > 0) {
243
+ parenDepth -= 1;
244
+ } else if (char === "[") {
245
+ bracketDepth += 1;
246
+ } else if (char === "]" && bracketDepth > 0) {
247
+ bracketDepth -= 1;
248
+ } else if (char === "{") {
249
+ braceDepth += 1;
250
+ } else if (char === "}" && braceDepth > 0) {
251
+ braceDepth -= 1;
252
+ }
253
+ if (parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
254
+ if (char === ";") {
255
+ return index + 1;
256
+ }
257
+ if (char === "\n" || char === "\r") {
258
+ return index;
259
+ }
260
+ }
261
+ }
262
+ return masked.length;
263
+ }
264
+ function collectDestructuredVariableBindingNames(masked, functionRanges, blockRanges, staticBlockRanges, bindings) {
265
+ for (const match of masked.matchAll(/\b(const|let|var)\s*(\{|\[)/g)) {
266
+ const start = (match.index || 0) + match[0].length - 1;
267
+ const end = (0, import_source.findMatchingDelimiter)(masked, start);
268
+ if (end > start) {
269
+ extractBindingPatternNames(masked.slice(start, end + 1)).forEach((name) => {
270
+ addSourceBinding(
271
+ bindings,
272
+ functionRanges,
273
+ blockRanges,
274
+ staticBlockRanges,
275
+ masked,
276
+ name,
277
+ match.index || 0,
278
+ masked.length,
279
+ match[1]
280
+ );
281
+ });
282
+ }
283
+ }
284
+ }
285
+ function collectParameterBindingNames(masked, bindings) {
286
+ for (const match of masked.matchAll(/\bfunction\b[^(]*\(/g)) {
287
+ const openParen = masked.indexOf("(", match.index || 0);
288
+ const closeParen = (0, import_source.findMatchingDelimiter)(masked, openParen);
289
+ const bodyRange = findBraceBodyAfter(masked, closeParen);
290
+ if (closeParen > openParen && bodyRange) {
291
+ addParameterBindings(bindings, masked.slice(openParen + 1, closeParen), {
292
+ start: openParen + 1,
293
+ end: bodyRange.end
294
+ });
295
+ }
296
+ }
297
+ for (const match of masked.matchAll(/\bcatch\s*\(/g)) {
298
+ const openParen = masked.indexOf("(", match.index || 0);
299
+ const closeParen = (0, import_source.findMatchingDelimiter)(masked, openParen);
300
+ const bodyRange = findBraceBodyAfter(masked, closeParen);
301
+ if (closeParen > openParen && bodyRange) {
302
+ addParameterBindings(bindings, masked.slice(openParen + 1, closeParen), {
303
+ start: openParen + 1,
304
+ end: bodyRange.end
305
+ });
306
+ }
307
+ }
308
+ collectArrowParameterBindingNames(masked, bindings);
309
+ collectMethodParameterBindingNames(masked, bindings);
310
+ }
311
+ function collectArrowParameterBindingNames(masked, bindings) {
312
+ for (const match of masked.matchAll(/\(/g)) {
313
+ const openParen = match.index || 0;
314
+ const closeParen = (0, import_source.findMatchingDelimiter)(masked, openParen);
315
+ if (closeParen <= openParen) {
316
+ continue;
317
+ }
318
+ let cursor = closeParen + 1;
319
+ while (cursor < masked.length && /\s/.test(masked[cursor])) {
320
+ cursor += 1;
321
+ }
322
+ if (masked.slice(cursor, cursor + 2) !== "=>") {
323
+ continue;
324
+ }
325
+ const bodyRange = findArrowBodyRange(masked, cursor + 2);
326
+ if (bodyRange) {
327
+ addParameterBindings(bindings, masked.slice(openParen + 1, closeParen), {
328
+ start: openParen + 1,
329
+ end: bodyRange.end
330
+ });
331
+ }
332
+ }
333
+ for (const match of masked.matchAll(/\b([A-Za-z_$][\w$]*)\s*=>/g)) {
334
+ const arrowIndex = (match.index || 0) + match[0].lastIndexOf("=>");
335
+ const bodyRange = findArrowBodyRange(masked, arrowIndex + 2);
336
+ if (bodyRange) {
337
+ bindings.push({
338
+ name: match[1],
339
+ declarationStart: match.index || 0,
340
+ start: match.index || 0,
341
+ end: bodyRange.end
342
+ });
343
+ }
344
+ }
345
+ }
346
+ function collectMethodParameterBindingNames(masked, bindings) {
347
+ (0, import_source.collectMethodCandidates)(masked).forEach((candidate) => {
348
+ addParameterBindings(bindings, masked.slice(candidate.paramsStart, candidate.paramsEnd), {
349
+ start: candidate.paramsStart,
350
+ end: candidate.bodyRange.end
351
+ });
352
+ });
353
+ }
354
+ function findBraceBodyAfter(masked, afterIndex) {
355
+ let cursor = afterIndex + 1;
356
+ while (cursor < masked.length && /\s/.test(masked[cursor])) {
357
+ cursor += 1;
358
+ }
359
+ if (masked[cursor] !== "{") {
360
+ return void 0;
361
+ }
362
+ const closeBrace = (0, import_source.findMatchingDelimiter)(masked, cursor);
363
+ return closeBrace > cursor ? { start: cursor, end: closeBrace + 1 } : void 0;
364
+ }
365
+ function findArrowBodyRange(masked, afterArrowIndex) {
366
+ let start = afterArrowIndex;
367
+ while (start < masked.length && /\s/.test(masked[start])) {
368
+ start += 1;
369
+ }
370
+ if (masked[start] === "{") {
371
+ const closeBrace = (0, import_source.findMatchingDelimiter)(masked, start);
372
+ return closeBrace > start ? { start, end: closeBrace + 1 } : void 0;
373
+ }
374
+ const end = (0, import_source.findArrowExpressionEnd)(masked, start);
375
+ return end > start ? { start, end } : void 0;
376
+ }
377
+ function addParameterBindings(bindings, params, range) {
378
+ (0, import_source.splitTopLevel)(params, ",").forEach((param) => {
379
+ extractBindingPatternNames(param).forEach((name) => {
380
+ bindings.push({ name, declarationStart: range.start, ...range });
381
+ });
382
+ });
383
+ }
384
+ function extractBindingPatternNames(pattern) {
385
+ const names = /* @__PURE__ */ new Set();
386
+ collectBindingPatternNames(pattern, names);
387
+ return [...names];
388
+ }
389
+ function collectBindingPatternNames(pattern, names) {
390
+ const trimmed = (0, import_source.trimBindingElement)(pattern);
391
+ if (!trimmed) {
392
+ return;
393
+ }
394
+ if (trimmed.startsWith("{")) {
395
+ collectObjectBindingPatternNames(trimmed, names);
396
+ return;
397
+ }
398
+ if (trimmed.startsWith("[")) {
399
+ collectArrayBindingPatternNames(trimmed, names);
400
+ return;
401
+ }
402
+ const match = trimmed.match(/^([A-Za-z_$][\w$]*)\b/);
403
+ if (match) {
404
+ names.add(match[1]);
405
+ }
406
+ }
407
+ function collectObjectBindingPatternNames(pattern, names) {
408
+ const body = (0, import_source.stripEnclosure)(pattern, "{", "}");
409
+ (0, import_source.splitTopLevel)(body, ",").forEach((element) => {
410
+ const trimmed = element.trim();
411
+ if (!trimmed) {
412
+ return;
413
+ }
414
+ if (trimmed.startsWith("...")) {
415
+ collectBindingPatternNames(trimmed.slice(3), names);
416
+ return;
417
+ }
418
+ const colon = (0, import_source.findTopLevelChar)(trimmed, ":");
419
+ collectBindingPatternNames(colon >= 0 ? trimmed.slice(colon + 1) : trimmed, names);
420
+ });
421
+ }
422
+ function collectArrayBindingPatternNames(pattern, names) {
423
+ (0, import_source.splitTopLevel)((0, import_source.stripEnclosure)(pattern, "[", "]"), ",").forEach(
424
+ (element) => collectBindingPatternNames(element, names)
425
+ );
426
+ }
427
+ function findInnermostRange(index, ranges) {
428
+ return ranges.filter((range) => index >= range.start && index < range.end).sort((left, right) => left.end - left.start - (right.end - right.start))[0];
429
+ }
430
+ function isNameBoundAtIndex(bindings, name, index) {
431
+ return bindings.some((binding) => binding.name === name && index >= binding.start && index < binding.end);
432
+ }
433
+ function findSourceBindingByDeclaration(bindings, name, declarationStart) {
434
+ return bindings.find((entry) => entry.name === name && (entry.declarationStart ?? entry.start) === declarationStart);
435
+ }
436
+ function isSameAstRange(left, right) {
437
+ return left.start === right.start && left.end === right.end;
438
+ }
439
+ function isSourceAliasShadowedAtIndex(alias, bindings, index) {
440
+ const aliasDeclarationStart = alias.declarationStart ?? alias.start;
441
+ return bindings.some(
442
+ (binding) => binding.name === alias.name && index >= binding.start && index < binding.end && (binding.declarationStart ?? binding.start) !== aliasDeclarationStart
443
+ );
444
+ }
445
+ function isAstDefinitelyNonEmptyForInSource(node) {
446
+ const unwrapped = unwrapAstChainExpression(node);
447
+ if (!unwrapped) {
448
+ return false;
449
+ }
450
+ if (unwrapped.type === "ObjectExpression") {
451
+ return (unwrapped.properties || []).some(isAstDefinitelyEnumerableObjectProperty);
452
+ }
453
+ return false;
454
+ }
455
+ function isAstDefinitelyNonEmptyForOfSource(node) {
456
+ const unwrapped = unwrapAstChainExpression(node);
457
+ if (!unwrapped) {
458
+ return false;
459
+ }
460
+ if (unwrapped.type === "ArrayExpression") {
461
+ return (unwrapped.elements || []).some(isAstDefinitelyNonEmptyArrayElement);
462
+ }
463
+ return false;
464
+ }
465
+ function isAstDefinitelyNonEmptyArrayElement(element) {
466
+ if (!element) {
467
+ return true;
468
+ }
469
+ if (element.type === "SpreadElement") {
470
+ return isAstDefinitelyNonEmptyForOfSource(element.argument);
471
+ }
472
+ return true;
473
+ }
474
+ function isAstDefinitelyEnumerableObjectProperty(property) {
475
+ if (!property || property.type === "SpreadElement" || property.type !== "Property") {
476
+ return false;
477
+ }
478
+ if (property.computed) {
479
+ return isAstDefinitelyEnumerableComputedObjectKey(property.key);
480
+ }
481
+ const key = property.key;
482
+ const isProtoSetter = !property.method && !property.shorthand && (property.kind || "init") === "init" && ((key == null ? void 0 : key.type) === "Identifier" && key.name === "__proto__" || (key == null ? void 0 : key.type) === "Literal" && key.value === "__proto__");
483
+ if (isProtoSetter) {
484
+ return false;
485
+ }
486
+ if ((key == null ? void 0 : key.type) === "Identifier") {
487
+ return true;
488
+ }
489
+ if ((key == null ? void 0 : key.type) === "Literal") {
490
+ return true;
491
+ }
492
+ return true;
493
+ }
494
+ function isAstDefinitelyEnumerableComputedObjectKey(key) {
495
+ const unwrapped = unwrapAstChainExpression(key);
496
+ if (!unwrapped) {
497
+ return false;
498
+ }
499
+ if (unwrapped.type === "Literal") {
500
+ return typeof unwrapped.value === "string" || typeof unwrapped.value === "number" || typeof unwrapped.value === "boolean" || typeof unwrapped.value === "bigint" || unwrapped.value === null;
501
+ }
502
+ if (unwrapped.type === "TemplateLiteral") {
503
+ return (unwrapped.expressions || []).length === 0;
504
+ }
505
+ return false;
506
+ }
507
+ function findAstAncestor(ancestors, type) {
508
+ var _a;
509
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
510
+ if (((_a = ancestors[index]) == null ? void 0 : _a.type) === type) {
511
+ return ancestors[index];
512
+ }
513
+ }
514
+ return void 0;
515
+ }
516
+ function getAstExecutionScopeRange(ancestors, sourceLength) {
517
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
518
+ const node = ancestors[index];
519
+ if (!node) {
520
+ continue;
521
+ }
522
+ if (node.type === "Program" || node.type === "StaticBlock" || isAstFunctionLike(node)) {
523
+ return {
524
+ start: typeof node.start === "number" ? node.start : 0,
525
+ end: typeof node.end === "number" ? node.end : sourceLength
526
+ };
527
+ }
528
+ }
529
+ return { start: 0, end: sourceLength };
530
+ }
531
+ function isAstAlwaysExecutedInCurrentExecutionScope(ancestors) {
532
+ const conditionalAncestorTypes = /* @__PURE__ */ new Set([
533
+ "ConditionalExpression",
534
+ "DoWhileStatement",
535
+ "ForStatement",
536
+ "IfStatement",
537
+ "LogicalExpression",
538
+ "SwitchCase",
539
+ "SwitchStatement",
540
+ "WhileStatement",
541
+ "WithStatement"
542
+ ]);
543
+ const currentNodeIndex = ancestors.length - 1;
544
+ for (let index = currentNodeIndex - 1; index >= 0; index -= 1) {
545
+ const node = ancestors[index];
546
+ if (!node) {
547
+ continue;
548
+ }
549
+ if (node.type === "Program" || node.type === "StaticBlock" || isAstFunctionLike(node)) {
550
+ return true;
551
+ }
552
+ if (node.type === "ForInStatement" && !isAstDefinitelyNonEmptyForInSource(node.right)) {
553
+ return false;
554
+ }
555
+ if (node.type === "ForOfStatement" && !isAstDefinitelyNonEmptyForOfSource(node.right)) {
556
+ return false;
557
+ }
558
+ if (node.type === "CatchClause") {
559
+ return false;
560
+ }
561
+ if (node.type === "TryStatement") {
562
+ const child = ancestors[index + 1];
563
+ if (child !== node.block && child !== node.finalizer) {
564
+ return false;
565
+ }
566
+ continue;
567
+ }
568
+ if (conditionalAncestorTypes.has(node.type)) {
569
+ return false;
570
+ }
571
+ }
572
+ return true;
573
+ }
574
+ function getAstBindingScopeRange(ancestors, sourceLength, functionScoped = false) {
575
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
576
+ const node = ancestors[index];
577
+ if (!node || node.type === "VariableDeclarator" || node.type === "VariableDeclaration") {
578
+ continue;
579
+ }
580
+ if (functionScoped) {
581
+ if (node.type === "Program" || node.type === "StaticBlock" || isAstFunctionLike(node)) {
582
+ return {
583
+ start: typeof node.start === "number" ? node.start : 0,
584
+ end: typeof node.end === "number" ? node.end : sourceLength
585
+ };
586
+ }
587
+ continue;
588
+ }
589
+ if (node.type === "Program" || node.type === "BlockStatement" || node.type === "ForStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "SwitchStatement" || node.type === "StaticBlock" || isAstFunctionLike(node)) {
590
+ return {
591
+ start: typeof node.start === "number" ? node.start : 0,
592
+ end: typeof node.end === "number" ? node.end : sourceLength
593
+ };
594
+ }
595
+ }
596
+ return { start: 0, end: sourceLength };
597
+ }
598
+ function isAstFunctionLike(node) {
599
+ return !!node && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression");
600
+ }
601
+ function dedupeIndexedEntries(entries) {
602
+ const seen = /* @__PURE__ */ new Set();
603
+ return entries.filter((entry) => {
604
+ const key = `${entry.index}:${entry.match || ""}:${entry.capability || ""}:${entry.component || ""}`;
605
+ if (seen.has(key)) {
606
+ return false;
607
+ }
608
+ seen.add(key);
609
+ return true;
610
+ });
611
+ }
612
+ function unwrapAstChainExpression(node) {
613
+ let current = node;
614
+ while ((current == null ? void 0 : current.type) === "ChainExpression") {
615
+ current = current.expression;
616
+ }
617
+ return current;
618
+ }
619
+ // Annotate the CommonJS export names for ESM import in node:
620
+ 0 && (module.exports = {
621
+ addParameterBindings,
622
+ addSourceBinding,
623
+ collectArrayBindingPatternNames,
624
+ collectArrowParameterBindingNames,
625
+ collectBindingPatternNames,
626
+ collectDestructuredVariableBindingNames,
627
+ collectMethodParameterBindingNames,
628
+ collectObjectBindingPatternNames,
629
+ collectParameterBindingNames,
630
+ collectSourceBindings,
631
+ collectStringLiteralBindings,
632
+ dedupeIndexedEntries,
633
+ extractBindingPatternNames,
634
+ findArrowBodyRange,
635
+ findAstAncestor,
636
+ findBraceBodyAfter,
637
+ findFollowingBraceRange,
638
+ findFollowingStatementRange,
639
+ findForHeaderRangeContaining,
640
+ findForScopeForDeclaration,
641
+ findInnermostRange,
642
+ findNamedFunctionOrClassExpressionRange,
643
+ findSingleStatementEnd,
644
+ findSourceBindingByDeclaration,
645
+ getAstBindingScopeRange,
646
+ getAstExecutionScopeRange,
647
+ isAstAlwaysExecutedInCurrentExecutionScope,
648
+ isAstDefinitelyEnumerableComputedObjectKey,
649
+ isAstDefinitelyEnumerableObjectProperty,
650
+ isAstDefinitelyNonEmptyArrayElement,
651
+ isAstDefinitelyNonEmptyForInSource,
652
+ isAstDefinitelyNonEmptyForOfSource,
653
+ isAstFunctionLike,
654
+ isExpressionPrefixToken,
655
+ isNameBoundAtIndex,
656
+ isNamedFunctionOrClassExpression,
657
+ isSameAstRange,
658
+ isSourceAliasShadowedAtIndex,
659
+ resolveBindingScope,
660
+ unwrapAstChainExpression
661
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { AstCapabilityAlias, AstIdentifierBinding, AstIdentifierWrite, SourceRange } from '../internal-types';
10
+ export declare function collectAstIdentifierWritesFromAst(ast: any, source: string): AstIdentifierWrite[];
11
+ export declare function getAstWriteExecutionContext(ancestors: any[], sourceLength: number): {
12
+ alwaysRunsInExecutionScope: boolean;
13
+ executionScope: SourceRange;
14
+ };
15
+ export declare function findAstInnermostSynchronousIifeFunctionAncestorIndex(ancestors: any[]): number;
16
+ export declare function getAstLoopPatternTarget(left: any): any;
17
+ export declare function isAstForOfLoopVariableDeclaratorWithSourceTargets<T extends AstCapabilityAlias>(node: any, ancestors: any[], aliases: T[], identifierBindings: AstIdentifierBinding[]): boolean;
18
+ export declare function hasAstForOfSourceTargets<T extends AstCapabilityAlias>(sourceNode: any, aliases: T[], identifierBindings: AstIdentifierBinding[]): boolean;
19
+ export declare function collectAstForOfSourceTargets<T extends AstCapabilityAlias>(sourceNode: any, aliases: T[], identifierBindings: AstIdentifierBinding[], visit: (sourceTarget: any) => void): void;
20
+ export declare function collectAstForOfSourceTargetElementMembers<T extends AstCapabilityAlias>(sourceTarget: any, aliases: T[], identifierBindings: AstIdentifierBinding[]): Set<string>;