@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,23 @@
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 { AstFunctionBinding, AstIdentifierBinding, AstIdentifierWrite, AstStaticObjectAliasCopy, StaticFilterValueBinding, StaticStringBinding } from '../internal-types';
10
+ export declare function collectAstIdentifierBindingsFromAst(ast: any, source: string): AstIdentifierBinding[];
11
+ export declare function collectAstFunctionBindingsFromAst(ast: any, source: string): AstFunctionBinding[];
12
+ export declare function collectStaticStringBindingsFromAst(ast: any, source: string, seedStringBindings?: StaticStringBinding[], identifierBindings?: AstIdentifierBinding[]): StaticStringBinding[];
13
+ export declare function isStaticStringBindingActiveAtIndex(binding: StaticStringBinding, index: number, writes: AstIdentifierWrite[], identifierBindings: AstIdentifierBinding[]): boolean;
14
+ export declare function trimStaticStringBindingsAfterWrites(bindings: StaticStringBinding[], writes: AstIdentifierWrite[], identifierBindings: AstIdentifierBinding[]): StaticStringBinding[];
15
+ export declare function collectStaticFilterValueBindingsFromAst(ast: any, source: string, identifierBindings: AstIdentifierBinding[]): StaticFilterValueBinding[];
16
+ export declare function trimStaticFilterValueBindingsAfterWrites(bindings: StaticFilterValueBinding[], writes: AstIdentifierWrite[], identifierBindings: AstIdentifierBinding[]): StaticFilterValueBinding[];
17
+ export declare function collectAstStaticBindingWritesFromAst(ast: any, source: string, identifierBindings: AstIdentifierBinding[]): AstIdentifierWrite[];
18
+ export declare function collectAstStaticObjectAliasCopiesFromAst(ast: any, source: string, identifierBindings: AstIdentifierBinding[]): AstStaticObjectAliasCopy[];
19
+ export declare function resolveAstStaticAliasCopySourceName(node: any, aliases: AstStaticObjectAliasCopy[], identifierBindings: AstIdentifierBinding[]): string | undefined;
20
+ export declare function collectAstStaticAliasCopyWrites(writes: AstIdentifierWrite[], aliases: AstStaticObjectAliasCopy[], identifierBindings: AstIdentifierBinding[]): AstIdentifierWrite[];
21
+ export declare function getAstIdentifierWriteKey(write: AstIdentifierWrite): string;
22
+ export declare function isAstStaticObjectAliasCopyActiveAtIndex(alias: AstStaticObjectAliasCopy, index: number, identifierBindings: AstIdentifierBinding[]): boolean;
23
+ export declare function isAstStaticObjectAliasCopySourceActiveAtIndex(alias: AstStaticObjectAliasCopy, index: number, identifierBindings: AstIdentifierBinding[]): boolean;
@@ -0,0 +1,618 @@
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 static_bindings_exports = {};
28
+ __export(static_bindings_exports, {
29
+ collectAstFunctionBindingsFromAst: () => collectAstFunctionBindingsFromAst,
30
+ collectAstIdentifierBindingsFromAst: () => collectAstIdentifierBindingsFromAst,
31
+ collectAstStaticAliasCopyWrites: () => collectAstStaticAliasCopyWrites,
32
+ collectAstStaticBindingWritesFromAst: () => collectAstStaticBindingWritesFromAst,
33
+ collectAstStaticObjectAliasCopiesFromAst: () => collectAstStaticObjectAliasCopiesFromAst,
34
+ collectStaticFilterValueBindingsFromAst: () => collectStaticFilterValueBindingsFromAst,
35
+ collectStaticStringBindingsFromAst: () => collectStaticStringBindingsFromAst,
36
+ getAstIdentifierWriteKey: () => getAstIdentifierWriteKey,
37
+ isAstStaticObjectAliasCopyActiveAtIndex: () => isAstStaticObjectAliasCopyActiveAtIndex,
38
+ isAstStaticObjectAliasCopySourceActiveAtIndex: () => isAstStaticObjectAliasCopySourceActiveAtIndex,
39
+ isStaticStringBindingActiveAtIndex: () => isStaticStringBindingActiveAtIndex,
40
+ resolveAstStaticAliasCopySourceName: () => resolveAstStaticAliasCopySourceName,
41
+ trimStaticFilterValueBindingsAfterWrites: () => trimStaticFilterValueBindingsAfterWrites,
42
+ trimStaticStringBindingsAfterWrites: () => trimStaticStringBindingsAfterWrites
43
+ });
44
+ module.exports = __toCommonJS(static_bindings_exports);
45
+ var import_walk = require("./walk");
46
+ var import_bindings = require("./bindings");
47
+ var import_execution = require("./execution");
48
+ var import_static_values = require("./static-values");
49
+ function collectAstIdentifierBindingsFromAst(ast, source) {
50
+ const bindings = [];
51
+ const addBinding = (name, node, scope, declarationStart, unavailableRanges) => {
52
+ if (!name) {
53
+ return;
54
+ }
55
+ bindings.push({
56
+ name,
57
+ declarationStart: typeof declarationStart === "number" ? declarationStart : typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
58
+ unavailableRanges,
59
+ start: scope.start,
60
+ end: scope.end
61
+ });
62
+ };
63
+ (0, import_walk.walkAstAncestor)(ast, {
64
+ VariableDeclarator(node, ancestors) {
65
+ var _a;
66
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
67
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, (declaration == null ? void 0 : declaration.kind) === "var");
68
+ const unavailableRanges = (declaration == null ? void 0 : declaration.kind) === "var" ? void 0 : getForHeadUnavailableBindingRanges(declaration, ancestors);
69
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
70
+ const declarationStart = (declaration == null ? void 0 : declaration.kind) === "var" ? scope.start : typeof node.end === "number" ? node.end : typeof node.start === "number" ? node.start : scope.start;
71
+ addBinding(node.id.name, node.id, scope, declarationStart, unavailableRanges);
72
+ return;
73
+ }
74
+ collectAstPatternBindingDeclarations(
75
+ node.id,
76
+ (name, bindingNode, declarationStart) => addBinding(
77
+ name,
78
+ bindingNode,
79
+ scope,
80
+ (declaration == null ? void 0 : declaration.kind) === "var" ? scope.start : declarationStart,
81
+ unavailableRanges
82
+ )
83
+ );
84
+ },
85
+ FunctionDeclaration(node, ancestors) {
86
+ var _a;
87
+ const parentScope = (0, import_bindings.getAstBindingScopeRange)(ancestors.slice(0, -1), source.length);
88
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
89
+ addBinding(node.id.name, node.id, parentScope, parentScope.start);
90
+ }
91
+ (0, import_static_values.addAstFunctionParamBindings)(bindings, node, source.length);
92
+ },
93
+ FunctionExpression(node) {
94
+ var _a;
95
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
96
+ bindings.push({
97
+ name: node.id.name,
98
+ start: typeof node.id.start === "number" ? node.id.start : typeof node.start === "number" ? node.start : 0,
99
+ end: typeof node.end === "number" ? node.end : source.length
100
+ });
101
+ }
102
+ (0, import_static_values.addAstFunctionParamBindings)(bindings, node, source.length);
103
+ },
104
+ ArrowFunctionExpression(node) {
105
+ (0, import_static_values.addAstFunctionParamBindings)(bindings, node, source.length);
106
+ },
107
+ ClassDeclaration(node, ancestors) {
108
+ var _a;
109
+ const parentScope = (0, import_bindings.getAstBindingScopeRange)(ancestors.slice(0, -1), source.length);
110
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
111
+ addBinding(node.id.name, node.id, parentScope);
112
+ }
113
+ },
114
+ ClassExpression(node) {
115
+ var _a;
116
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
117
+ bindings.push({
118
+ name: node.id.name,
119
+ start: typeof node.id.start === "number" ? node.id.start : typeof node.start === "number" ? node.start : 0,
120
+ end: typeof node.end === "number" ? node.end : source.length
121
+ });
122
+ }
123
+ },
124
+ CatchClause(node) {
125
+ const scope = {
126
+ start: typeof node.start === "number" ? node.start : 0,
127
+ end: typeof node.end === "number" ? node.end : source.length
128
+ };
129
+ (0, import_static_values.collectAstPatternBindingIdentifiers)(node.param, (name, bindingNode) => addBinding(name, bindingNode, scope));
130
+ }
131
+ });
132
+ return bindings;
133
+ }
134
+ function getForHeadUnavailableBindingRanges(declaration, ancestors) {
135
+ var _a, _b;
136
+ const parent = ancestors[ancestors.length - 3];
137
+ if ((parent == null ? void 0 : parent.type) !== "ForOfStatement" && (parent == null ? void 0 : parent.type) !== "ForInStatement" || parent.left !== declaration || typeof ((_a = parent.right) == null ? void 0 : _a.start) !== "number" || typeof ((_b = parent.right) == null ? void 0 : _b.end) !== "number") {
138
+ return void 0;
139
+ }
140
+ return [
141
+ {
142
+ start: parent.right.start,
143
+ end: parent.right.end
144
+ }
145
+ ];
146
+ }
147
+ function collectAstPatternBindingDeclarations(node, addBinding, declarationStart) {
148
+ if (!node) {
149
+ return;
150
+ }
151
+ const fallbackStart = typeof declarationStart === "number" ? declarationStart : typeof node.end === "number" ? node.end : typeof node.start === "number" ? node.start : 0;
152
+ if (node.type === "Identifier") {
153
+ addBinding(node.name, node, fallbackStart);
154
+ return;
155
+ }
156
+ if (node.type === "AssignmentPattern") {
157
+ collectAstPatternBindingDeclarations(
158
+ node.left,
159
+ addBinding,
160
+ typeof node.end === "number" ? node.end : fallbackStart
161
+ );
162
+ return;
163
+ }
164
+ if (node.type === "RestElement") {
165
+ collectAstPatternBindingDeclarations(
166
+ node.argument,
167
+ addBinding,
168
+ typeof node.end === "number" ? node.end : fallbackStart
169
+ );
170
+ return;
171
+ }
172
+ if (node.type === "ArrayPattern") {
173
+ for (const element of node.elements || []) {
174
+ collectAstPatternBindingDeclarations(element, addBinding);
175
+ }
176
+ return;
177
+ }
178
+ if (node.type === "ObjectPattern") {
179
+ for (const property of node.properties || []) {
180
+ if (!property) {
181
+ continue;
182
+ }
183
+ if (property.type === "RestElement") {
184
+ collectAstPatternBindingDeclarations(
185
+ property.argument,
186
+ addBinding,
187
+ typeof property.end === "number" ? property.end : void 0
188
+ );
189
+ continue;
190
+ }
191
+ if (property.type === "Property") {
192
+ collectAstPatternBindingDeclarations(property.value, addBinding);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ function collectAstFunctionBindingsFromAst(ast, source) {
198
+ const bindings = [];
199
+ const addBinding = (name, functionNode, scope, declarationNode, bindingStart = scope.start, hoisted = false) => {
200
+ if (!name || !(0, import_bindings.isAstFunctionLike)(functionNode)) {
201
+ return;
202
+ }
203
+ bindings.push({
204
+ name,
205
+ functionNode,
206
+ declarationStart: typeof (declarationNode == null ? void 0 : declarationNode.start) === "number" ? declarationNode.start : typeof functionNode.start === "number" ? functionNode.start : scope.start,
207
+ start: bindingStart,
208
+ end: scope.end,
209
+ hoisted,
210
+ scopeStart: scope.start
211
+ });
212
+ };
213
+ (0, import_walk.walkAstAncestor)(ast, {
214
+ FunctionDeclaration(node, ancestors) {
215
+ var _a;
216
+ const parentScope = (0, import_bindings.getAstBindingScopeRange)(ancestors.slice(0, -1), source.length);
217
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
218
+ addBinding(node.id.name, node, parentScope, node.id, parentScope.start, true);
219
+ }
220
+ },
221
+ VariableDeclarator(node, ancestors) {
222
+ var _a;
223
+ if (((_a = node.id) == null ? void 0 : _a.type) !== "Identifier") {
224
+ return;
225
+ }
226
+ const functionNode = (0, import_bindings.unwrapAstChainExpression)(node.init);
227
+ if (!(0, import_bindings.isAstFunctionLike)(functionNode)) {
228
+ return;
229
+ }
230
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
231
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, (declaration == null ? void 0 : declaration.kind) === "var");
232
+ addBinding(
233
+ node.id.name,
234
+ functionNode,
235
+ scope,
236
+ node.id,
237
+ typeof node.id.start === "number" ? node.id.start : scope.start
238
+ );
239
+ },
240
+ AssignmentExpression(node, ancestors) {
241
+ var _a;
242
+ if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "Identifier") {
243
+ return;
244
+ }
245
+ const functionNode = (0, import_bindings.unwrapAstChainExpression)(node.right);
246
+ if (!(0, import_bindings.isAstFunctionLike)(functionNode)) {
247
+ return;
248
+ }
249
+ const scope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
250
+ addBinding(
251
+ node.left.name,
252
+ functionNode,
253
+ scope,
254
+ node.left,
255
+ typeof node.left.start === "number" ? node.left.start : scope.start
256
+ );
257
+ }
258
+ });
259
+ return bindings;
260
+ }
261
+ function collectStaticStringBindingsFromAst(ast, source, seedStringBindings = [], identifierBindings = []) {
262
+ const bindings = [];
263
+ const availableBindings = [...seedStringBindings];
264
+ const writes = collectAstStaticBindingWritesFromAst(ast, source, identifierBindings);
265
+ const aliasCopies = collectAstStaticObjectAliasCopiesFromAst(ast, source, identifierBindings);
266
+ const addBinding = (name, value, node, scope, declarationStart, executionScope) => {
267
+ const binding = {
268
+ declarationStart,
269
+ executionScope,
270
+ name,
271
+ value,
272
+ start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : declarationStart,
273
+ end: scope.end
274
+ };
275
+ bindings.push(binding);
276
+ availableBindings.push(binding);
277
+ };
278
+ const copyMemberBindings = (sourceName, targetName, node, scope, declarationStart, executionScope) => {
279
+ const exactBinding = availableBindings.find(
280
+ (binding) => binding.name === sourceName && isStaticStringBindingActiveAtIndex(binding, declarationStart, writes, identifierBindings)
281
+ );
282
+ if (exactBinding && !availableBindings.some((binding) => binding.name === targetName && binding.start >= declarationStart)) {
283
+ addBinding(targetName, exactBinding.value, node, scope, declarationStart, executionScope);
284
+ }
285
+ const prefix = `${sourceName}.`;
286
+ const sourceBindings = availableBindings.filter(
287
+ (binding) => binding.name.startsWith(prefix) && isStaticStringBindingActiveAtIndex(binding, declarationStart, writes, identifierBindings)
288
+ );
289
+ for (const sourceBinding of sourceBindings) {
290
+ const name = `${targetName}${sourceBinding.name.slice(sourceName.length)}`;
291
+ if (availableBindings.some((binding) => binding.name === name && binding.start >= declarationStart)) {
292
+ continue;
293
+ }
294
+ addBinding(name, sourceBinding.value, node, scope, declarationStart, executionScope);
295
+ }
296
+ };
297
+ const collectMemberBindings = (prefix, valueNode, scope, declarationStart, executionScope, bindingStartNode) => {
298
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(valueNode);
299
+ if ((unwrapped == null ? void 0 : unwrapped.type) !== "ObjectExpression") {
300
+ return;
301
+ }
302
+ const seenMembers = /* @__PURE__ */ new Set();
303
+ for (let index = (unwrapped.properties || []).length - 1; index >= 0; index -= 1) {
304
+ const property = unwrapped.properties[index];
305
+ if (!property) {
306
+ continue;
307
+ }
308
+ if (property.type === "SpreadElement") {
309
+ break;
310
+ }
311
+ if (property.type !== "Property") {
312
+ break;
313
+ }
314
+ const member = (0, import_static_values.getAstStaticMemberKey)(property);
315
+ if (!member) {
316
+ break;
317
+ }
318
+ if (seenMembers.has(member)) {
319
+ continue;
320
+ }
321
+ seenMembers.add(member);
322
+ const bindingName = `${prefix}.${member}`;
323
+ const resolved = (0, import_static_values.resolveRunJsStaticString)(property.value, source, availableBindings, identifierBindings);
324
+ if (typeof resolved === "string") {
325
+ addBinding(bindingName, resolved, bindingStartNode, scope, declarationStart, executionScope);
326
+ continue;
327
+ }
328
+ collectMemberBindings(bindingName, property.value, scope, declarationStart, executionScope, bindingStartNode);
329
+ }
330
+ };
331
+ (0, import_walk.walkAstAncestor)(ast, {
332
+ VariableDeclarator(node, ancestors) {
333
+ var _a, _b;
334
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
335
+ if ((declaration == null ? void 0 : declaration.kind) !== "const") {
336
+ return;
337
+ }
338
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, (declaration == null ? void 0 : declaration.kind) === "var");
339
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
340
+ const declarationStart = typeof node.start === "number" ? node.start : scope.start;
341
+ if (((_a = node.id) == null ? void 0 : _a.type) === "ObjectPattern") {
342
+ const sourceName2 = resolveAstStaticAliasCopySourceName(node.init, aliasCopies, identifierBindings);
343
+ if (!sourceName2) {
344
+ return;
345
+ }
346
+ (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (name, members, aliasNode) => {
347
+ const aliasDeclarationStart = typeof (aliasNode == null ? void 0 : aliasNode.start) === "number" ? aliasNode.start : declarationStart;
348
+ copyMemberBindings(
349
+ `${sourceName2}.${members.join(".")}`,
350
+ name,
351
+ aliasNode || node,
352
+ scope,
353
+ aliasDeclarationStart,
354
+ executionScope
355
+ );
356
+ });
357
+ return;
358
+ }
359
+ if (((_b = node.id) == null ? void 0 : _b.type) !== "Identifier") {
360
+ return;
361
+ }
362
+ const resolved = (0, import_static_values.resolveRunJsStaticString)(node.init, source, availableBindings, identifierBindings);
363
+ if (typeof resolved === "string") {
364
+ addBinding(node.id.name, resolved, node, scope, declarationStart, executionScope);
365
+ }
366
+ collectMemberBindings(node.id.name, node.init, scope, declarationStart, executionScope, node);
367
+ const sourceName = resolveAstStaticAliasCopySourceName(node.init, aliasCopies, identifierBindings);
368
+ if (sourceName) {
369
+ copyMemberBindings(sourceName, node.id.name, node, scope, declarationStart, executionScope);
370
+ }
371
+ }
372
+ });
373
+ return trimStaticStringBindingsAfterWrites(bindings, writes, identifierBindings);
374
+ }
375
+ function isStaticStringBindingActiveAtIndex(binding, index, writes, identifierBindings) {
376
+ if (index < binding.start || index >= binding.end) {
377
+ return false;
378
+ }
379
+ const declarationStart = binding.declarationStart ?? binding.start;
380
+ const rootName = (0, import_static_values.getAstAliasRootName)(binding.name);
381
+ const executionScope = binding.executionScope;
382
+ if ((0, import_static_values.hasAstShadowBinding)(rootName, index, binding, identifierBindings)) {
383
+ return false;
384
+ }
385
+ if (!executionScope) {
386
+ return true;
387
+ }
388
+ return !writes.some(
389
+ (write) => (write.name === binding.name || binding.name.startsWith(`${write.name}.`)) && write.index > declarationStart && write.index >= binding.start && write.index < index && write.alwaysRunsInExecutionScope && (0, import_bindings.isSameAstRange)(write.executionScope, executionScope) && !(0, import_static_values.hasAstShadowBinding)(rootName, write.index, binding, identifierBindings)
390
+ );
391
+ }
392
+ function trimStaticStringBindingsAfterWrites(bindings, writes, identifierBindings) {
393
+ return bindings.map((binding) => {
394
+ const declarationStart = binding.declarationStart ?? binding.start;
395
+ const rootName = (0, import_static_values.getAstAliasRootName)(binding.name);
396
+ const executionScope = binding.executionScope;
397
+ const nextWrite = writes.filter(
398
+ (write) => (write.name === binding.name || binding.name.startsWith(`${write.name}.`)) && write.index > declarationStart && write.index >= binding.start && write.index < binding.end && write.alwaysRunsInExecutionScope && !!executionScope && (0, import_bindings.isSameAstRange)(write.executionScope, executionScope) && !(0, import_static_values.hasAstShadowBinding)(rootName, write.index, binding, identifierBindings)
399
+ ).sort((left, right) => left.index - right.index)[0];
400
+ return nextWrite ? { ...binding, end: nextWrite.index } : binding;
401
+ });
402
+ }
403
+ function collectStaticFilterValueBindingsFromAst(ast, source, identifierBindings) {
404
+ const bindings = [];
405
+ const availableBindings = [];
406
+ const writes = collectAstStaticBindingWritesFromAst(ast, source, identifierBindings);
407
+ const getActiveBindings = (index) => trimStaticFilterValueBindingsAfterWrites(availableBindings, writes, identifierBindings).filter(
408
+ (binding) => index >= binding.start && index < binding.end
409
+ );
410
+ const addBinding = (name, valueNode, node, scope, declarationStart, executionScope) => {
411
+ const binding = {
412
+ declarationStart,
413
+ executionScope,
414
+ name,
415
+ start: typeof (node == null ? void 0 : node.end) === "number" ? node.end : declarationStart,
416
+ end: scope.end,
417
+ valueNode
418
+ };
419
+ bindings.push(binding);
420
+ availableBindings.push(binding);
421
+ };
422
+ (0, import_walk.walkAstAncestor)(ast, {
423
+ VariableDeclarator(node, ancestors) {
424
+ var _a, _b;
425
+ if (!node.init) {
426
+ return;
427
+ }
428
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
429
+ if ((declaration == null ? void 0 : declaration.kind) !== "const") {
430
+ return;
431
+ }
432
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length);
433
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
434
+ const declarationStart = typeof node.start === "number" ? node.start : scope.start;
435
+ if (((_a = node.id) == null ? void 0 : _a.type) === "ObjectPattern") {
436
+ const sourceObject = (0, import_static_values.resolveRunJsStaticObjectExpression)(
437
+ node.init,
438
+ identifierBindings,
439
+ getActiveBindings(declarationStart)
440
+ );
441
+ if (!sourceObject) {
442
+ return;
443
+ }
444
+ (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (name, members, aliasNode) => {
445
+ const property = (0, import_static_values.getRunJsObjectPropertyByPath)(
446
+ sourceObject,
447
+ members,
448
+ identifierBindings,
449
+ getActiveBindings(declarationStart)
450
+ );
451
+ if (property) {
452
+ addBinding(
453
+ name,
454
+ property.value,
455
+ aliasNode || node,
456
+ scope,
457
+ typeof (aliasNode == null ? void 0 : aliasNode.start) === "number" ? aliasNode.start : declarationStart,
458
+ executionScope
459
+ );
460
+ }
461
+ });
462
+ return;
463
+ }
464
+ if (((_b = node.id) == null ? void 0 : _b.type) !== "Identifier") {
465
+ return;
466
+ }
467
+ addBinding(node.id.name, node.init, node, scope, declarationStart, executionScope);
468
+ }
469
+ });
470
+ return trimStaticFilterValueBindingsAfterWrites(bindings, writes, identifierBindings);
471
+ }
472
+ function trimStaticFilterValueBindingsAfterWrites(bindings, writes, identifierBindings) {
473
+ return bindings.map((binding) => {
474
+ const nextWrite = writes.filter(
475
+ (write) => (write.name === binding.name || write.name.startsWith(`${binding.name}.`)) && write.index > binding.declarationStart && write.index >= binding.start && write.index < binding.end && write.alwaysRunsInExecutionScope && (0, import_bindings.isSameAstRange)(write.executionScope, binding.executionScope) && !(0, import_static_values.hasAstShadowBinding)(binding.name, write.index, binding, identifierBindings)
476
+ ).sort((left, right) => left.index - right.index)[0];
477
+ return nextWrite ? { ...binding, end: nextWrite.index } : binding;
478
+ });
479
+ }
480
+ function collectAstStaticBindingWritesFromAst(ast, source, identifierBindings) {
481
+ const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
482
+ const aliasCopies = collectAstStaticObjectAliasCopiesFromAst(ast, source, identifierBindings);
483
+ return [...writes, ...collectAstStaticAliasCopyWrites(writes, aliasCopies, identifierBindings)];
484
+ }
485
+ function collectAstStaticObjectAliasCopiesFromAst(ast, source, identifierBindings) {
486
+ const aliases = [];
487
+ const resolveSourceName = (node) => resolveAstStaticAliasCopySourceName(node, aliases, identifierBindings);
488
+ (0, import_walk.walkAstAncestor)(ast, {
489
+ VariableDeclarator(node, ancestors) {
490
+ var _a, _b;
491
+ if (!node.init) {
492
+ return;
493
+ }
494
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
495
+ if ((declaration == null ? void 0 : declaration.kind) !== "const") {
496
+ return;
497
+ }
498
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length);
499
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
500
+ const addAlias = (name, sourceName2, aliasNode) => {
501
+ if (!sourceName2 || sourceName2 === name || sourceName2.startsWith(`${name}.`)) {
502
+ return;
503
+ }
504
+ aliases.push({
505
+ declarationStart: typeof node.start === "number" ? node.start : scope.start,
506
+ executionScope,
507
+ name,
508
+ sourceName: sourceName2,
509
+ start: typeof (aliasNode == null ? void 0 : aliasNode.start) === "number" ? aliasNode.start : typeof node.start === "number" ? node.start : scope.start,
510
+ end: scope.end
511
+ });
512
+ };
513
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
514
+ addAlias(node.id.name, resolveSourceName(node.init), node);
515
+ return;
516
+ }
517
+ if (((_b = node.id) == null ? void 0 : _b.type) !== "ObjectPattern") {
518
+ return;
519
+ }
520
+ const sourceName = resolveSourceName(node.init);
521
+ if (!sourceName) {
522
+ return;
523
+ }
524
+ (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (name, members, aliasNode) => {
525
+ addAlias(name, `${sourceName}.${members.join(".")}`, aliasNode || node);
526
+ });
527
+ }
528
+ });
529
+ return aliases;
530
+ }
531
+ function resolveAstStaticAliasCopySourceName(node, aliases, identifierBindings) {
532
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
533
+ if (!unwrapped) {
534
+ return void 0;
535
+ }
536
+ if (unwrapped.type === "Identifier") {
537
+ const alias = (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
538
+ return (alias == null ? void 0 : alias.sourceName) || unwrapped.name;
539
+ }
540
+ if (unwrapped.type !== "MemberExpression") {
541
+ return void 0;
542
+ }
543
+ const lookup = (0, import_static_values.getAstMemberAliasLookup)(unwrapped);
544
+ if (!lookup) {
545
+ return void 0;
546
+ }
547
+ const rootAlias = (0, import_static_values.resolveAstAliasBinding)(lookup.rootName, lookup.index, aliases, identifierBindings);
548
+ if (!rootAlias) {
549
+ return lookup.aliasName;
550
+ }
551
+ const suffix = lookup.aliasName.slice(lookup.rootName.length);
552
+ return `${rootAlias.sourceName}${suffix}`;
553
+ }
554
+ function collectAstStaticAliasCopyWrites(writes, aliases, identifierBindings) {
555
+ const mirroredWrites = [];
556
+ const seen = new Set(writes.map((write) => getAstIdentifierWriteKey(write)));
557
+ const queue = [...writes];
558
+ const addMirroredWrite = (write, name) => {
559
+ if (!name || name === write.name) {
560
+ return;
561
+ }
562
+ const mirroredWrite = { ...write, name };
563
+ const key = getAstIdentifierWriteKey(mirroredWrite);
564
+ if (seen.has(key)) {
565
+ return;
566
+ }
567
+ seen.add(key);
568
+ mirroredWrites.push(mirroredWrite);
569
+ queue.push(mirroredWrite);
570
+ };
571
+ for (let index = 0; index < queue.length; index += 1) {
572
+ const write = queue[index];
573
+ for (const alias of aliases) {
574
+ if (!isAstStaticObjectAliasCopyActiveAtIndex(alias, write.index, identifierBindings)) {
575
+ continue;
576
+ }
577
+ if (write.name.startsWith(`${alias.name}.`)) {
578
+ addMirroredWrite(write, `${alias.sourceName}${write.name.slice(alias.name.length)}`);
579
+ }
580
+ if ((write.name === alias.sourceName || write.name.startsWith(`${alias.sourceName}.`)) && isAstStaticObjectAliasCopySourceActiveAtIndex(alias, write.index, identifierBindings)) {
581
+ addMirroredWrite(write, `${alias.name}${write.name.slice(alias.sourceName.length)}`);
582
+ }
583
+ }
584
+ }
585
+ return mirroredWrites;
586
+ }
587
+ function getAstIdentifierWriteKey(write) {
588
+ return [
589
+ write.name,
590
+ write.index,
591
+ write.alwaysRunsInExecutionScope ? "1" : "0",
592
+ write.executionScope.start,
593
+ write.executionScope.end
594
+ ].join(":");
595
+ }
596
+ function isAstStaticObjectAliasCopyActiveAtIndex(alias, index, identifierBindings) {
597
+ return index >= alias.start && index < alias.end && !(0, import_static_values.hasAstShadowBinding)((0, import_static_values.getAstAliasRootName)(alias.name), index, alias, identifierBindings);
598
+ }
599
+ function isAstStaticObjectAliasCopySourceActiveAtIndex(alias, index, identifierBindings) {
600
+ return !(0, import_static_values.hasAstShadowBinding)((0, import_static_values.getAstAliasRootName)(alias.sourceName), index, alias, identifierBindings);
601
+ }
602
+ // Annotate the CommonJS export names for ESM import in node:
603
+ 0 && (module.exports = {
604
+ collectAstFunctionBindingsFromAst,
605
+ collectAstIdentifierBindingsFromAst,
606
+ collectAstStaticAliasCopyWrites,
607
+ collectAstStaticBindingWritesFromAst,
608
+ collectAstStaticObjectAliasCopiesFromAst,
609
+ collectStaticFilterValueBindingsFromAst,
610
+ collectStaticStringBindingsFromAst,
611
+ getAstIdentifierWriteKey,
612
+ isAstStaticObjectAliasCopyActiveAtIndex,
613
+ isAstStaticObjectAliasCopySourceActiveAtIndex,
614
+ isStaticStringBindingActiveAtIndex,
615
+ resolveAstStaticAliasCopySourceName,
616
+ trimStaticFilterValueBindingsAfterWrites,
617
+ trimStaticStringBindingsAfterWrites
618
+ });