@nocobase/plugin-flow-engine 2.1.0-alpha.40 → 2.1.0-alpha.46
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/client/index.js +1 -1
- package/dist/externalVersion.js +9 -9
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/apply/compiler.js +28 -14
- package/dist/server/flow-surfaces/apply/matching.js +2 -0
- package/dist/server/flow-surfaces/authoring-validation.d.ts +1 -0
- package/dist/server/flow-surfaces/authoring-validation.js +1453 -151
- package/dist/server/flow-surfaces/blueprint/compile-blocks.js +21 -3
- package/dist/server/flow-surfaces/blueprint/compile-plan.js +9 -9
- package/dist/server/flow-surfaces/blueprint/normalize-document.js +5 -1
- package/dist/server/flow-surfaces/catalog.js +26 -9
- package/dist/server/flow-surfaces/chart-config.js +231 -14
- package/dist/server/flow-surfaces/compose-compiler.d.ts +2 -0
- package/dist/server/flow-surfaces/compose-compiler.js +2 -0
- package/dist/server/flow-surfaces/compose-runtime.js +4 -7
- package/dist/server/flow-surfaces/configure-options.js +19 -8
- package/dist/server/flow-surfaces/contract-guard.js +40 -6
- package/dist/server/flow-surfaces/default-block-actions.js +2 -0
- package/dist/server/flow-surfaces/errors.d.ts +15 -0
- package/dist/server/flow-surfaces/errors.js +49 -3
- package/dist/server/flow-surfaces/event-flow-normalizer.d.ts +19 -0
- package/dist/server/flow-surfaces/event-flow-normalizer.js +128 -0
- package/dist/server/flow-surfaces/filter-group.d.ts +9 -1
- package/dist/server/flow-surfaces/filter-group.js +402 -3
- package/dist/server/flow-surfaces/locator.js +16 -2
- package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
- package/dist/server/flow-surfaces/route-sync.js +19 -2
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
- package/dist/server/flow-surfaces/runjs-authoring/ctx-libs-member-mismatch-stop/index.js +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
- package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -7033
- package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
- package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
- package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
- package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
- package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
- package/dist/server/flow-surfaces/service-helpers.js +105 -0
- package/dist/server/flow-surfaces/service-utils.d.ts +17 -3
- package/dist/server/flow-surfaces/service-utils.js +14 -5
- package/dist/server/flow-surfaces/service.d.ts +74 -15
- package/dist/server/flow-surfaces/service.js +1781 -193
- package/dist/server/flow-surfaces/template-service-utils.d.ts +1 -0
- package/dist/server/flow-surfaces/types.d.ts +3 -0
- package/dist/server/repository.d.ts +12 -1
- package/dist/server/repository.js +195 -23
- package/dist/swagger/flow-surfaces.d.ts +180 -2
- package/dist/swagger/flow-surfaces.examples.d.ts +11 -37
- package/dist/swagger/flow-surfaces.examples.js +6 -6
- package/dist/swagger/flow-surfaces.js +136 -54
- package/dist/swagger/index.d.ts +180 -2
- package/package.json +2 -2
|
@@ -0,0 +1,1777 @@
|
|
|
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_values_exports = {};
|
|
28
|
+
__export(static_values_exports, {
|
|
29
|
+
addAstFunctionParamBindings: () => addAstFunctionParamBindings,
|
|
30
|
+
collectAstArrayRestCarrierSourceTargets: () => collectAstArrayRestCarrierSourceTargets,
|
|
31
|
+
collectAstArraySpreadCarrierCopies: () => collectAstArraySpreadCarrierCopies,
|
|
32
|
+
collectAstCarrierCandidateMembers: () => collectAstCarrierCandidateMembers,
|
|
33
|
+
collectAstCarrierSourceTargets: () => collectAstCarrierSourceTargets,
|
|
34
|
+
collectAstDynamicCarrierSourceTargets: () => collectAstDynamicCarrierSourceTargets,
|
|
35
|
+
collectAstKnownCarrierMembers: () => collectAstKnownCarrierMembers,
|
|
36
|
+
collectAstLiteralSpreadCarrierCopies: () => collectAstLiteralSpreadCarrierCopies,
|
|
37
|
+
collectAstObjectPatternAliases: () => collectAstObjectPatternAliases,
|
|
38
|
+
collectAstObjectPatternPathAliases: () => collectAstObjectPatternPathAliases,
|
|
39
|
+
collectAstObjectPatternStaticMembers: () => collectAstObjectPatternStaticMembers,
|
|
40
|
+
collectAstObjectRestCarrierSourceTargets: () => collectAstObjectRestCarrierSourceTargets,
|
|
41
|
+
collectAstObjectSpreadCarrierCopies: () => collectAstObjectSpreadCarrierCopies,
|
|
42
|
+
collectAstPatternBindingIdentifiers: () => collectAstPatternBindingIdentifiers,
|
|
43
|
+
collectAstPatternCarrierSourceTargets: () => collectAstPatternCarrierSourceTargets,
|
|
44
|
+
collectAstPatternCarrierSourceTargetsFromSourceTarget: () => collectAstPatternCarrierSourceTargetsFromSourceTarget,
|
|
45
|
+
collectAstPatternDefaultValueAliases: () => collectAstPatternDefaultValueAliases,
|
|
46
|
+
collectAstPatternDefaultValueAliasesWithSource: () => collectAstPatternDefaultValueAliasesWithSource,
|
|
47
|
+
collectAstPatternMemberExpressions: () => collectAstPatternMemberExpressions,
|
|
48
|
+
collectAstPatternRestCarrierSourceTargets: () => collectAstPatternRestCarrierSourceTargets,
|
|
49
|
+
collectAstPatternRestCarrierSourceTargetsRec: () => collectAstPatternRestCarrierSourceTargetsRec,
|
|
50
|
+
collectAstPatternSourceTargets: () => collectAstPatternSourceTargets,
|
|
51
|
+
collectAstPatternSourceTargetsRec: () => collectAstPatternSourceTargetsRec,
|
|
52
|
+
collectAstRestCarrierAliasCopies: () => collectAstRestCarrierAliasCopies,
|
|
53
|
+
collectAstStaticCarrierMemberSourceTargets: () => collectAstStaticCarrierMemberSourceTargets,
|
|
54
|
+
collectAstStaticCarrierMembers: () => collectAstStaticCarrierMembers,
|
|
55
|
+
compareAstAliasPrecedence: () => compareAstAliasPrecedence,
|
|
56
|
+
createAstAmbiguousSourceTarget: () => createAstAmbiguousSourceTarget,
|
|
57
|
+
createAstFallbackSourceTarget: () => createAstFallbackSourceTarget,
|
|
58
|
+
createAstPatternSourceTarget: () => createAstPatternSourceTarget,
|
|
59
|
+
createMaybeAstPatternSourceTarget: () => createMaybeAstPatternSourceTarget,
|
|
60
|
+
dedupeAstResourceEntries: () => dedupeAstResourceEntries,
|
|
61
|
+
findUnboundCtxMatches: () => findUnboundCtxMatches,
|
|
62
|
+
getAstAliasPrecedenceStart: () => getAstAliasPrecedenceStart,
|
|
63
|
+
getAstAliasRootName: () => getAstAliasRootName,
|
|
64
|
+
getAstArrayCarrierMemberSourceTarget: () => getAstArrayCarrierMemberSourceTarget,
|
|
65
|
+
getAstAssignmentTargetScope: () => getAstAssignmentTargetScope,
|
|
66
|
+
getAstBindingIdentifierName: () => getAstBindingIdentifierName,
|
|
67
|
+
getAstBindingIdentifierNode: () => getAstBindingIdentifierNode,
|
|
68
|
+
getAstMemberAliasLookup: () => getAstMemberAliasLookup,
|
|
69
|
+
getAstMemberAssignmentTargetScope: () => getAstMemberAssignmentTargetScope,
|
|
70
|
+
getAstMemberRootIdentifier: () => getAstMemberRootIdentifier,
|
|
71
|
+
getAstMemberWriteLookup: () => getAstMemberWriteLookup,
|
|
72
|
+
getAstObjectCarrierMemberSourceTarget: () => getAstObjectCarrierMemberSourceTarget,
|
|
73
|
+
getAstObjectPatternFromValue: () => getAstObjectPatternFromValue,
|
|
74
|
+
getAstPatternMemberSourceTarget: () => getAstPatternMemberSourceTarget,
|
|
75
|
+
getAstPatternSourceRoot: () => getAstPatternSourceRoot,
|
|
76
|
+
getAstPatternTargetAliasLookup: () => getAstPatternTargetAliasLookup,
|
|
77
|
+
getAstSpreadMemberSourceTarget: () => getAstSpreadMemberSourceTarget,
|
|
78
|
+
getAstStaticArrayElementCount: () => getAstStaticArrayElementCount,
|
|
79
|
+
getAstStaticCarrierMemberSourceTarget: () => getAstStaticCarrierMemberSourceTarget,
|
|
80
|
+
getAstStaticCarrierMemberValue: () => getAstStaticCarrierMemberValue,
|
|
81
|
+
getAstStaticMemberKey: () => getAstStaticMemberKey,
|
|
82
|
+
getAstStaticPropertyName: () => getAstStaticPropertyName,
|
|
83
|
+
getCtxMethodName: () => getCtxMethodName,
|
|
84
|
+
getRunJsObjectProperty: () => getRunJsObjectProperty,
|
|
85
|
+
getRunJsObjectPropertyByPath: () => getRunJsObjectPropertyByPath,
|
|
86
|
+
getRunJsObjectPropertyLookup: () => getRunJsObjectPropertyLookup,
|
|
87
|
+
hasAstActiveBinding: () => hasAstActiveBinding,
|
|
88
|
+
hasAstShadowBinding: () => hasAstShadowBinding,
|
|
89
|
+
isAstCtxApiAliasAssignmentOperator: () => isAstCtxApiAliasAssignmentOperator,
|
|
90
|
+
isAstDefiniteAssignmentOperator: () => isAstDefiniteAssignmentOperator,
|
|
91
|
+
isAstDynamicMemberAliasMatch: () => isAstDynamicMemberAliasMatch,
|
|
92
|
+
isCtxIdentifier: () => isCtxIdentifier,
|
|
93
|
+
isCtxRootFromAst: () => isCtxRootFromAst,
|
|
94
|
+
isUnshadowedCtxIdentifier: () => isUnshadowedCtxIdentifier,
|
|
95
|
+
resolveAstActiveIdentifierBinding: () => resolveAstActiveIdentifierBinding,
|
|
96
|
+
resolveAstAliasBinding: () => resolveAstAliasBinding,
|
|
97
|
+
resolveAstDynamicAliasBinding: () => resolveAstDynamicAliasBinding,
|
|
98
|
+
resolveAstMemberAliasBinding: () => resolveAstMemberAliasBinding,
|
|
99
|
+
resolveAstNamedAliasBinding: () => resolveAstNamedAliasBinding,
|
|
100
|
+
resolveAstResourceTypeExpression: () => resolveAstResourceTypeExpression,
|
|
101
|
+
resolveAstStaticStringValue: () => resolveAstStaticStringValue,
|
|
102
|
+
resolveAstStaticTemplateLiteralValue: () => resolveAstStaticTemplateLiteralValue,
|
|
103
|
+
resolveCtxMethodCall: () => resolveCtxMethodCall,
|
|
104
|
+
resolveRunJsStaticObjectExpression: () => resolveRunJsStaticObjectExpression,
|
|
105
|
+
resolveRunJsStaticObjectExpressionRec: () => resolveRunJsStaticObjectExpressionRec,
|
|
106
|
+
resolveRunJsStaticString: () => resolveRunJsStaticString,
|
|
107
|
+
trimAstAliasesAfterWrites: () => trimAstAliasesAfterWrites
|
|
108
|
+
});
|
|
109
|
+
module.exports = __toCommonJS(static_values_exports);
|
|
110
|
+
var import_internal_types = require("../internal-types");
|
|
111
|
+
var import_constants = require("../runtime/constants");
|
|
112
|
+
var import_surface = require("../runtime/surface");
|
|
113
|
+
var import_bindings = require("./bindings");
|
|
114
|
+
var import_source = require("./source");
|
|
115
|
+
function resolveCtxMethodCall(node, aliases, identifierBindings) {
|
|
116
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
|
|
117
|
+
const directMethod = getCtxMethodName(callee, identifierBindings);
|
|
118
|
+
if (directMethod) {
|
|
119
|
+
return {
|
|
120
|
+
capability: `ctx.${directMethod}`,
|
|
121
|
+
method: directMethod
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if ((callee == null ? void 0 : callee.type) === "Identifier") {
|
|
125
|
+
const alias = resolveAstAliasBinding(callee.name, node.start || 0, aliases, identifierBindings);
|
|
126
|
+
if (alias) {
|
|
127
|
+
return alias;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
function getCtxMethodName(node, identifierBindings) {
|
|
133
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
134
|
+
if (!member || member.type !== "MemberExpression" || !isUnshadowedCtxIdentifier(member.object, identifierBindings)) {
|
|
135
|
+
return "";
|
|
136
|
+
}
|
|
137
|
+
const propertyName = getAstStaticPropertyName(member);
|
|
138
|
+
return import_constants.AST_CTX_METHOD_NAMES.has(propertyName) ? propertyName : "";
|
|
139
|
+
}
|
|
140
|
+
function getAstStaticPropertyName(node) {
|
|
141
|
+
const property = (node == null ? void 0 : node.key) || (node == null ? void 0 : node.property);
|
|
142
|
+
if (!property) {
|
|
143
|
+
return "";
|
|
144
|
+
}
|
|
145
|
+
if (!node.computed && property.type === "Identifier") {
|
|
146
|
+
return property.name;
|
|
147
|
+
}
|
|
148
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(property);
|
|
149
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "Literal" && (typeof unwrapped.value === "string" || typeof unwrapped.value === "number")) {
|
|
150
|
+
return String(unwrapped.value);
|
|
151
|
+
}
|
|
152
|
+
const value = resolveAstStaticStringValue(property, "");
|
|
153
|
+
return typeof value === "string" ? value : "";
|
|
154
|
+
}
|
|
155
|
+
function getAstStaticMemberKey(node) {
|
|
156
|
+
const property = (node == null ? void 0 : node.key) || (node == null ? void 0 : node.property);
|
|
157
|
+
if (!property) {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
if (!node.computed && property.type === "Identifier") {
|
|
161
|
+
return property.name;
|
|
162
|
+
}
|
|
163
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(property);
|
|
164
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "Literal") {
|
|
165
|
+
if (typeof unwrapped.value === "string" || typeof unwrapped.value === "number") {
|
|
166
|
+
return String(unwrapped.value);
|
|
167
|
+
}
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
const value = resolveAstStaticStringValue(property, "");
|
|
171
|
+
return typeof value === "string" ? value : "";
|
|
172
|
+
}
|
|
173
|
+
function isCtxIdentifier(node) {
|
|
174
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
175
|
+
return (unwrapped == null ? void 0 : unwrapped.type) === "Identifier" && unwrapped.name === "ctx";
|
|
176
|
+
}
|
|
177
|
+
function isUnshadowedCtxIdentifier(node, identifierBindings) {
|
|
178
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
179
|
+
if (!isCtxIdentifier(unwrapped)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const index = typeof unwrapped.start === "number" ? unwrapped.start : 0;
|
|
183
|
+
return !hasAstActiveBinding("ctx", index, identifierBindings);
|
|
184
|
+
}
|
|
185
|
+
function isCtxRootFromAst(node, aliases, identifierBindings) {
|
|
186
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
187
|
+
if (!unwrapped) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
191
|
+
return isCtxRootFromAst(unwrapped.consequent, aliases, identifierBindings) || isCtxRootFromAst(unwrapped.alternate, aliases, identifierBindings);
|
|
192
|
+
}
|
|
193
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
194
|
+
return isCtxRootFromAst(unwrapped.left, aliases, identifierBindings) || isCtxRootFromAst(unwrapped.right, aliases, identifierBindings);
|
|
195
|
+
}
|
|
196
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
197
|
+
const expressions = unwrapped.expressions || [];
|
|
198
|
+
return isCtxRootFromAst(expressions[expressions.length - 1], aliases, identifierBindings);
|
|
199
|
+
}
|
|
200
|
+
if (unwrapped.type === "AssignmentExpression" && isAstCtxApiAliasAssignmentOperator(unwrapped.operator)) {
|
|
201
|
+
return isCtxRootFromAst(unwrapped.right, aliases, identifierBindings);
|
|
202
|
+
}
|
|
203
|
+
if (isUnshadowedCtxIdentifier(unwrapped, identifierBindings)) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
if (unwrapped.type !== "Identifier") {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const index = typeof unwrapped.start === "number" ? unwrapped.start : 0;
|
|
210
|
+
return !!resolveAstAliasBinding(unwrapped.name, index, aliases, identifierBindings);
|
|
211
|
+
}
|
|
212
|
+
function hasAstActiveBinding(name, index, identifierBindings) {
|
|
213
|
+
return identifierBindings.some((binding) => binding.name === name && index >= binding.start && index < binding.end);
|
|
214
|
+
}
|
|
215
|
+
function isAstCtxApiAliasAssignmentOperator(operator) {
|
|
216
|
+
return operator === "=" || operator === "||=" || operator === "&&=" || operator === "??=";
|
|
217
|
+
}
|
|
218
|
+
function isAstDefiniteAssignmentOperator(operator) {
|
|
219
|
+
return operator === "=" || operator === "&&=";
|
|
220
|
+
}
|
|
221
|
+
function getAstAssignmentTargetScope(target, ancestors, sourceLength, identifierBindings) {
|
|
222
|
+
const fallbackScope = (0, import_bindings.getAstBindingScopeRange)(ancestors, sourceLength);
|
|
223
|
+
if ((target == null ? void 0 : target.type) === "Identifier") {
|
|
224
|
+
const index = typeof target.start === "number" ? target.start : 0;
|
|
225
|
+
const binding = resolveAstActiveIdentifierBinding(target.name, index, identifierBindings);
|
|
226
|
+
if (binding) {
|
|
227
|
+
const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, sourceLength);
|
|
228
|
+
if (binding.start < executionScope.start && binding.end >= executionScope.end) {
|
|
229
|
+
return fallbackScope;
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
start: binding.start,
|
|
233
|
+
end: binding.end
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return fallbackScope;
|
|
238
|
+
}
|
|
239
|
+
function getAstMemberAssignmentTargetScope(target, ancestors, sourceLength, identifierBindings) {
|
|
240
|
+
const fallbackScope = (0, import_bindings.getAstBindingScopeRange)(ancestors, sourceLength);
|
|
241
|
+
const lookup = getAstMemberAliasLookup(target);
|
|
242
|
+
if (!lookup) {
|
|
243
|
+
return fallbackScope;
|
|
244
|
+
}
|
|
245
|
+
const binding = resolveAstActiveIdentifierBinding(lookup.rootName, lookup.index, identifierBindings);
|
|
246
|
+
if (!binding) {
|
|
247
|
+
return fallbackScope;
|
|
248
|
+
}
|
|
249
|
+
const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, sourceLength);
|
|
250
|
+
if (binding.start < executionScope.start && binding.end >= executionScope.end) {
|
|
251
|
+
return fallbackScope;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
start: binding.start,
|
|
255
|
+
end: binding.end
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function findUnboundCtxMatches(masked, pattern, bindings) {
|
|
259
|
+
return (0, import_source.findMatches)(masked, pattern).filter((entry) => !(0, import_bindings.isNameBoundAtIndex)(bindings, "ctx", entry.index));
|
|
260
|
+
}
|
|
261
|
+
function dedupeAstResourceEntries(entries) {
|
|
262
|
+
const seen = /* @__PURE__ */ new Set();
|
|
263
|
+
return entries.filter((entry) => {
|
|
264
|
+
const key = `${entry.ruleId}:${entry.capability}:${entry.index}`;
|
|
265
|
+
if (seen.has(key)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
seen.add(key);
|
|
269
|
+
return true;
|
|
270
|
+
}).sort((left, right) => left.index - right.index);
|
|
271
|
+
}
|
|
272
|
+
function resolveAstResourceTypeExpression(node, source, stringBindings, identifierBindings) {
|
|
273
|
+
const resolved = resolveAstStaticStringValue(node, source);
|
|
274
|
+
if (typeof resolved === "string") {
|
|
275
|
+
return { status: "resolved", value: resolved };
|
|
276
|
+
}
|
|
277
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
278
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "Identifier") {
|
|
279
|
+
const binding = resolveAstAliasBinding(unwrapped.name, unwrapped.start || 0, stringBindings, identifierBindings);
|
|
280
|
+
if (binding) {
|
|
281
|
+
return { status: "resolved", value: binding.value };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "MemberExpression") {
|
|
285
|
+
const binding = resolveAstMemberAliasBinding(unwrapped, stringBindings, identifierBindings);
|
|
286
|
+
if (binding) {
|
|
287
|
+
return { status: "resolved", value: binding.value };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const templateValue = resolveAstStaticTemplateLiteralValue(unwrapped, source, stringBindings, identifierBindings);
|
|
291
|
+
if (typeof templateValue === "string") {
|
|
292
|
+
return { status: "resolved", value: templateValue };
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
status: "unresolved",
|
|
296
|
+
expression: source.slice((node == null ? void 0 : node.start) || 0, (node == null ? void 0 : node.end) || (node == null ? void 0 : node.start) || 0).trim()
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function resolveAstStaticStringValue(node, source) {
|
|
300
|
+
var _a, _b, _c, _d;
|
|
301
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
302
|
+
if (!unwrapped) {
|
|
303
|
+
return void 0;
|
|
304
|
+
}
|
|
305
|
+
if (unwrapped.type === "Literal" && typeof unwrapped.value === "string") {
|
|
306
|
+
return unwrapped.value;
|
|
307
|
+
}
|
|
308
|
+
if (unwrapped.type === "TemplateLiteral" && !((_a = unwrapped.expressions) == null ? void 0 : _a.length)) {
|
|
309
|
+
return ((_d = (_c = (_b = unwrapped.quasis) == null ? void 0 : _b[0]) == null ? void 0 : _c.value) == null ? void 0 : _d.cooked) ?? source.slice(unwrapped.start + 1, unwrapped.end - 1);
|
|
310
|
+
}
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
function resolveAstStaticTemplateLiteralValue(node, source, stringBindings, identifierBindings) {
|
|
314
|
+
var _a, _b;
|
|
315
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
316
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "TemplateLiteral" || !(unwrapped.expressions || []).length) {
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
const quasis = unwrapped.quasis || [];
|
|
320
|
+
const expressions = unwrapped.expressions || [];
|
|
321
|
+
let value = "";
|
|
322
|
+
for (let index = 0; index < quasis.length; index += 1) {
|
|
323
|
+
const quasi = quasis[index];
|
|
324
|
+
value += ((_a = quasi == null ? void 0 : quasi.value) == null ? void 0 : _a.cooked) ?? ((_b = quasi == null ? void 0 : quasi.value) == null ? void 0 : _b.raw) ?? "";
|
|
325
|
+
if (index >= expressions.length) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const expression = resolveAstResourceTypeExpression(expressions[index], source, stringBindings, identifierBindings);
|
|
329
|
+
if (expression.status !== "resolved") {
|
|
330
|
+
return void 0;
|
|
331
|
+
}
|
|
332
|
+
value += expression.value;
|
|
333
|
+
}
|
|
334
|
+
return value;
|
|
335
|
+
}
|
|
336
|
+
function resolveAstAliasBinding(name, index, aliases, identifierBindings) {
|
|
337
|
+
const candidates = aliases.filter((entry) => entry.name === name && index >= entry.start && index < entry.end).sort((left, right) => right.start - left.start);
|
|
338
|
+
return candidates.find((entry) => !hasAstShadowBinding(name, index, entry, identifierBindings));
|
|
339
|
+
}
|
|
340
|
+
function resolveAstMemberAliasBinding(node, aliases, identifierBindings) {
|
|
341
|
+
const lookup = getAstMemberAliasLookup(node);
|
|
342
|
+
if (!lookup) {
|
|
343
|
+
return void 0;
|
|
344
|
+
}
|
|
345
|
+
return resolveAstNamedAliasBinding(lookup.aliasName, lookup.index, lookup.rootName, aliases, identifierBindings);
|
|
346
|
+
}
|
|
347
|
+
function getAstMemberAliasLookup(node) {
|
|
348
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
349
|
+
if ((member == null ? void 0 : member.type) !== "MemberExpression") {
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
const memberKey = getAstStaticMemberKey(member);
|
|
353
|
+
if (!memberKey) {
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
const object = (0, import_bindings.unwrapAstChainExpression)(member.object);
|
|
357
|
+
if ((object == null ? void 0 : object.type) === "Identifier") {
|
|
358
|
+
return {
|
|
359
|
+
aliasName: `${object.name}.${memberKey}`,
|
|
360
|
+
index: typeof member.start === "number" ? member.start : typeof object.start === "number" ? object.start : 0,
|
|
361
|
+
rootName: object.name
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const objectLookup = getAstMemberAliasLookup(object);
|
|
365
|
+
if (!objectLookup) {
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
aliasName: `${objectLookup.aliasName}.${memberKey}`,
|
|
370
|
+
index: typeof member.start === "number" ? member.start : objectLookup.index,
|
|
371
|
+
rootName: objectLookup.rootName
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function getAstMemberWriteLookup(node) {
|
|
375
|
+
const staticLookup = getAstMemberAliasLookup(node);
|
|
376
|
+
if (staticLookup) {
|
|
377
|
+
return staticLookup;
|
|
378
|
+
}
|
|
379
|
+
const root = getAstMemberRootIdentifier(node);
|
|
380
|
+
if (!root) {
|
|
381
|
+
return void 0;
|
|
382
|
+
}
|
|
383
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
384
|
+
return {
|
|
385
|
+
aliasName: root.name,
|
|
386
|
+
index: typeof (member == null ? void 0 : member.start) === "number" ? member.start : root.index,
|
|
387
|
+
rootName: root.name
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function getAstMemberRootIdentifier(node) {
|
|
391
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
392
|
+
if (!unwrapped) {
|
|
393
|
+
return void 0;
|
|
394
|
+
}
|
|
395
|
+
if (unwrapped.type === "Identifier") {
|
|
396
|
+
return {
|
|
397
|
+
index: typeof unwrapped.start === "number" ? unwrapped.start : 0,
|
|
398
|
+
name: unwrapped.name
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
if (unwrapped.type !== "MemberExpression") {
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
return getAstMemberRootIdentifier(unwrapped.object);
|
|
405
|
+
}
|
|
406
|
+
function getAstAliasRootName(name) {
|
|
407
|
+
return String(name || "").split(".")[0] || name;
|
|
408
|
+
}
|
|
409
|
+
function resolveAstNamedAliasBinding(name, index, rootName, aliases, identifierBindings) {
|
|
410
|
+
const candidates = aliases.filter((entry) => entry.name === name && index >= entry.start && index < entry.end).sort((left, right) => right.start - left.start);
|
|
411
|
+
return candidates.find(
|
|
412
|
+
(entry) => !hasAstShadowBinding(rootName || getAstAliasRootName(name), index, entry, identifierBindings)
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
function resolveAstDynamicAliasBinding(name, index, rootName, aliases, identifierBindings) {
|
|
416
|
+
const candidates = aliases.filter(
|
|
417
|
+
(entry) => entry.name !== name && index >= entry.start && index < entry.end && isAstDynamicMemberAliasMatch(entry.name, name)
|
|
418
|
+
).sort((left, right) => right.start - left.start);
|
|
419
|
+
return candidates.find(
|
|
420
|
+
(entry) => !hasAstShadowBinding(rootName || getAstAliasRootName(name), index, entry, identifierBindings)
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
function compareAstAliasPrecedence(left, right) {
|
|
424
|
+
if (left.start !== right.start) {
|
|
425
|
+
return left.start - right.start;
|
|
426
|
+
}
|
|
427
|
+
return getAstAliasPrecedenceStart(left) - getAstAliasPrecedenceStart(right);
|
|
428
|
+
}
|
|
429
|
+
function getAstAliasPrecedenceStart(alias) {
|
|
430
|
+
return typeof alias.precedenceStart === "number" ? alias.precedenceStart : alias.start;
|
|
431
|
+
}
|
|
432
|
+
function isAstDynamicMemberAliasMatch(patternName, name) {
|
|
433
|
+
if (!patternName.includes(import_internal_types.AST_DYNAMIC_MEMBER_ALIAS)) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
const patternParts = patternName.split(".");
|
|
437
|
+
const nameParts = name.split(".");
|
|
438
|
+
return patternParts.length === nameParts.length && patternParts.every((part, index) => part === import_internal_types.AST_DYNAMIC_MEMBER_ALIAS || part === nameParts[index]);
|
|
439
|
+
}
|
|
440
|
+
function resolveAstActiveIdentifierBinding(name, index, identifierBindings) {
|
|
441
|
+
return identifierBindings.filter((binding) => binding.name === name && index >= binding.start && index < binding.end).sort(
|
|
442
|
+
(left, right) => left.end - left.start - (right.end - right.start) || right.start - left.start || right.end - left.end
|
|
443
|
+
)[0];
|
|
444
|
+
}
|
|
445
|
+
function hasAstShadowBinding(name, index, alias, identifierBindings) {
|
|
446
|
+
return identifierBindings.some(
|
|
447
|
+
(binding) => binding.name === name && binding.start > alias.start && index >= binding.start && index < binding.end
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
function addAstFunctionParamBindings(bindings, node, sourceLength) {
|
|
451
|
+
const scope = {
|
|
452
|
+
start: typeof node.start === "number" ? node.start : 0,
|
|
453
|
+
end: typeof node.end === "number" ? node.end : sourceLength
|
|
454
|
+
};
|
|
455
|
+
for (const param of node.params || []) {
|
|
456
|
+
collectAstPatternBindingIdentifiers(param, (name, bindingNode) => {
|
|
457
|
+
bindings.push({
|
|
458
|
+
name,
|
|
459
|
+
start: typeof (bindingNode == null ? void 0 : bindingNode.start) === "number" ? bindingNode.start : scope.start,
|
|
460
|
+
end: scope.end
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function collectAstPatternBindingIdentifiers(node, addBinding) {
|
|
466
|
+
if (!node) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (node.type === "Identifier") {
|
|
470
|
+
addBinding(node.name, node);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (node.type === "AssignmentPattern") {
|
|
474
|
+
collectAstPatternBindingIdentifiers(node.left, addBinding);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (node.type === "RestElement") {
|
|
478
|
+
collectAstPatternBindingIdentifiers(node.argument, addBinding);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (node.type === "ArrayPattern") {
|
|
482
|
+
for (const element of node.elements || []) {
|
|
483
|
+
collectAstPatternBindingIdentifiers(element, addBinding);
|
|
484
|
+
}
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (node.type === "ObjectPattern") {
|
|
488
|
+
for (const property of node.properties || []) {
|
|
489
|
+
if (!property) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (property.type === "RestElement") {
|
|
493
|
+
collectAstPatternBindingIdentifiers(property.argument, addBinding);
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (property.type === "Property") {
|
|
497
|
+
collectAstPatternBindingIdentifiers(property.value, addBinding);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function collectAstObjectPatternAliases(pattern, addAlias) {
|
|
503
|
+
for (const property of pattern.properties || []) {
|
|
504
|
+
if (!property || property.type !== "Property") {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
const member = getAstStaticPropertyName(property);
|
|
508
|
+
const alias = getAstBindingIdentifierName(property.value);
|
|
509
|
+
const aliasNode = getAstBindingIdentifierNode(property.value);
|
|
510
|
+
if (member && alias) {
|
|
511
|
+
addAlias(alias, member, aliasNode);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function collectAstObjectPatternPathAliases(pattern, addAlias, parentMembers = []) {
|
|
516
|
+
for (const property of pattern.properties || []) {
|
|
517
|
+
if (!property || property.type !== "Property") {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
const member = getAstStaticPropertyName(property);
|
|
521
|
+
if (!member) {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const members = [...parentMembers, member];
|
|
525
|
+
const alias = getAstBindingIdentifierName(property.value);
|
|
526
|
+
const aliasNode = getAstBindingIdentifierNode(property.value);
|
|
527
|
+
if (alias) {
|
|
528
|
+
addAlias(alias, members, aliasNode);
|
|
529
|
+
}
|
|
530
|
+
const nestedPattern = getAstObjectPatternFromValue(property.value);
|
|
531
|
+
if (nestedPattern) {
|
|
532
|
+
collectAstObjectPatternPathAliases(nestedPattern, addAlias, members);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function collectAstPatternDefaultValueAliases(pattern, addAlias) {
|
|
537
|
+
if (!pattern) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (pattern.type === "AssignmentPattern") {
|
|
541
|
+
collectAstPatternBindingIdentifiers(pattern.left, (alias, aliasNode) => {
|
|
542
|
+
addAlias(alias, pattern.right, aliasNode, pattern.left);
|
|
543
|
+
});
|
|
544
|
+
collectAstPatternDefaultValueAliases(pattern.left, addAlias);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (pattern.type === "ObjectPattern") {
|
|
548
|
+
for (const property of pattern.properties || []) {
|
|
549
|
+
if (!property) {
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (property.type === "RestElement") {
|
|
553
|
+
collectAstPatternDefaultValueAliases(property.argument, addAlias);
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (property.type === "Property") {
|
|
557
|
+
collectAstPatternDefaultValueAliases(property.value, addAlias);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (pattern.type === "ArrayPattern") {
|
|
563
|
+
for (const element of pattern.elements || []) {
|
|
564
|
+
collectAstPatternDefaultValueAliases(element, addAlias);
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (pattern.type === "RestElement") {
|
|
569
|
+
collectAstPatternDefaultValueAliases(pattern.argument, addAlias);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function collectAstPatternDefaultValueAliasesWithSource(pattern, sourceTarget, addAlias) {
|
|
573
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(pattern);
|
|
574
|
+
if (!unwrapped) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (unwrapped.type === "AssignmentPattern") {
|
|
578
|
+
collectAstPatternBindingIdentifiers(unwrapped.left, (alias, aliasNode) => {
|
|
579
|
+
addAlias(alias, unwrapped.right, aliasNode, unwrapped.left, sourceTarget);
|
|
580
|
+
});
|
|
581
|
+
collectAstPatternDefaultValueAliasesWithSource(unwrapped.left, sourceTarget, addAlias);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (unwrapped.type === "ObjectPattern") {
|
|
585
|
+
for (const property of unwrapped.properties || []) {
|
|
586
|
+
if (!property) {
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (property.type === "RestElement") {
|
|
590
|
+
collectAstPatternDefaultValueAliasesWithSource(property.argument, void 0, addAlias);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (property.type !== "Property") {
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
const member = getAstStaticPropertyName(property);
|
|
597
|
+
collectAstPatternDefaultValueAliasesWithSource(
|
|
598
|
+
property.value,
|
|
599
|
+
member ? getAstPatternMemberSourceTarget(sourceTarget, member) : void 0,
|
|
600
|
+
addAlias
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (unwrapped.type === "ArrayPattern") {
|
|
606
|
+
for (let index = 0; index < (unwrapped.elements || []).length; index += 1) {
|
|
607
|
+
collectAstPatternDefaultValueAliasesWithSource(
|
|
608
|
+
unwrapped.elements[index],
|
|
609
|
+
getAstPatternMemberSourceTarget(sourceTarget, String(index)),
|
|
610
|
+
addAlias
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (unwrapped.type === "RestElement") {
|
|
616
|
+
collectAstPatternDefaultValueAliasesWithSource(unwrapped.argument, void 0, addAlias);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function collectAstPatternSourceTargets(pattern, sourceNode, visit) {
|
|
620
|
+
collectAstPatternSourceTargetsRec(pattern, createAstPatternSourceTarget(sourceNode), visit);
|
|
621
|
+
}
|
|
622
|
+
function collectAstPatternCarrierSourceTargets(pattern, sourceNode, aliases, identifierBindings, visit) {
|
|
623
|
+
collectAstPatternCarrierSourceTargetsFromSourceTarget(
|
|
624
|
+
pattern,
|
|
625
|
+
createAstPatternSourceTarget(sourceNode),
|
|
626
|
+
aliases,
|
|
627
|
+
identifierBindings,
|
|
628
|
+
visit
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
function collectAstPatternCarrierSourceTargetsFromSourceTarget(pattern, sourceTarget, aliases, identifierBindings, visit) {
|
|
632
|
+
collectAstPatternSourceTargetsRec(pattern, sourceTarget, (target, patternSourceTarget) => {
|
|
633
|
+
const targetLookup = getAstPatternTargetAliasLookup(target);
|
|
634
|
+
if (!targetLookup) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
collectAstCarrierSourceTargets(
|
|
638
|
+
target,
|
|
639
|
+
targetLookup.aliasName,
|
|
640
|
+
patternSourceTarget,
|
|
641
|
+
aliases,
|
|
642
|
+
identifierBindings,
|
|
643
|
+
visit
|
|
644
|
+
);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
function collectAstPatternSourceTargetsRec(pattern, sourceTarget, visit) {
|
|
648
|
+
var _a;
|
|
649
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(pattern);
|
|
650
|
+
if (!unwrapped) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (unwrapped.type === "Identifier" || unwrapped.type === "MemberExpression") {
|
|
654
|
+
visit(unwrapped, sourceTarget);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (unwrapped.type === "AssignmentPattern") {
|
|
658
|
+
collectAstPatternSourceTargetsRec(unwrapped.left, sourceTarget, visit);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (unwrapped.type === "RestElement") {
|
|
662
|
+
collectAstPatternSourceTargetsRec(unwrapped.argument, sourceTarget, visit);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (unwrapped.type === "ObjectPattern") {
|
|
666
|
+
for (const property of unwrapped.properties || []) {
|
|
667
|
+
if (!property || property.type !== "Property") {
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const member = getAstStaticPropertyName(property);
|
|
671
|
+
if (!member) {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
collectAstPatternSourceTargetsRec(property.value, getAstPatternMemberSourceTarget(sourceTarget, member), visit);
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (unwrapped.type === "ArrayPattern") {
|
|
679
|
+
for (let index = 0; index < (unwrapped.elements || []).length; index += 1) {
|
|
680
|
+
if (((_a = unwrapped.elements[index]) == null ? void 0 : _a.type) === "RestElement") {
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
collectAstPatternSourceTargetsRec(
|
|
684
|
+
unwrapped.elements[index],
|
|
685
|
+
getAstPatternMemberSourceTarget(sourceTarget, String(index)),
|
|
686
|
+
visit
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function collectAstPatternRestCarrierSourceTargets(pattern, sourceNode, aliases, identifierBindings, visit) {
|
|
692
|
+
collectAstPatternRestCarrierSourceTargetsRec(
|
|
693
|
+
pattern,
|
|
694
|
+
createAstPatternSourceTarget(sourceNode),
|
|
695
|
+
aliases,
|
|
696
|
+
identifierBindings,
|
|
697
|
+
visit
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
function collectAstPatternRestCarrierSourceTargetsRec(pattern, sourceTarget, aliases, identifierBindings, visit) {
|
|
701
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(pattern);
|
|
702
|
+
if (!unwrapped) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
if (unwrapped.type === "AssignmentPattern") {
|
|
706
|
+
collectAstPatternRestCarrierSourceTargetsRec(unwrapped.left, sourceTarget, aliases, identifierBindings, visit);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (unwrapped.type === "ObjectPattern") {
|
|
710
|
+
const excludedMembers = collectAstObjectPatternStaticMembers(unwrapped);
|
|
711
|
+
for (const property of unwrapped.properties || []) {
|
|
712
|
+
if (!property) {
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (property.type === "RestElement") {
|
|
716
|
+
collectAstObjectRestCarrierSourceTargets(
|
|
717
|
+
property.argument,
|
|
718
|
+
sourceTarget,
|
|
719
|
+
excludedMembers,
|
|
720
|
+
aliases,
|
|
721
|
+
identifierBindings,
|
|
722
|
+
visit
|
|
723
|
+
);
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if (property.type !== "Property") {
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
const member = getAstStaticPropertyName(property);
|
|
730
|
+
if (!member) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
collectAstPatternRestCarrierSourceTargetsRec(
|
|
734
|
+
property.value,
|
|
735
|
+
getAstPatternMemberSourceTarget(sourceTarget, member),
|
|
736
|
+
aliases,
|
|
737
|
+
identifierBindings,
|
|
738
|
+
visit
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (unwrapped.type === "ArrayPattern") {
|
|
744
|
+
for (let index = 0; index < (unwrapped.elements || []).length; index += 1) {
|
|
745
|
+
const element = unwrapped.elements[index];
|
|
746
|
+
if (!element) {
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
if (element.type === "RestElement") {
|
|
750
|
+
collectAstArrayRestCarrierSourceTargets(
|
|
751
|
+
element.argument,
|
|
752
|
+
sourceTarget,
|
|
753
|
+
index,
|
|
754
|
+
aliases,
|
|
755
|
+
identifierBindings,
|
|
756
|
+
visit
|
|
757
|
+
);
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
collectAstPatternRestCarrierSourceTargetsRec(
|
|
761
|
+
element,
|
|
762
|
+
getAstPatternMemberSourceTarget(sourceTarget, String(index)),
|
|
763
|
+
aliases,
|
|
764
|
+
identifierBindings,
|
|
765
|
+
visit
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function collectAstObjectRestCarrierSourceTargets(target, sourceTarget, excludedMembers, aliases, identifierBindings, visit) {
|
|
771
|
+
const targetLookup = getAstPatternTargetAliasLookup(target);
|
|
772
|
+
if (!targetLookup) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
collectAstCarrierCandidateMembers(sourceTarget == null ? void 0 : sourceTarget.node, aliases, identifierBindings).forEach((member) => {
|
|
776
|
+
if (excludedMembers.has(member)) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const memberSourceTarget = getAstStaticCarrierMemberSourceTarget(sourceTarget == null ? void 0 : sourceTarget.node, member);
|
|
780
|
+
if (!memberSourceTarget) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
visit({
|
|
784
|
+
sourceTarget: memberSourceTarget,
|
|
785
|
+
target,
|
|
786
|
+
targetAliasName: `${targetLookup.aliasName}.${member}`
|
|
787
|
+
});
|
|
788
|
+
});
|
|
789
|
+
collectAstRestCarrierAliasCopies(
|
|
790
|
+
sourceTarget,
|
|
791
|
+
targetLookup.aliasName,
|
|
792
|
+
aliases,
|
|
793
|
+
identifierBindings,
|
|
794
|
+
(suffix, sourceAlias) => {
|
|
795
|
+
const firstMember = suffix.split(".")[0];
|
|
796
|
+
if (!firstMember || excludedMembers.has(firstMember)) {
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
visit({
|
|
800
|
+
sourceAlias,
|
|
801
|
+
target,
|
|
802
|
+
targetAliasName: `${targetLookup.aliasName}.${suffix}`
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
collectAstObjectSpreadCarrierCopies(
|
|
807
|
+
sourceTarget == null ? void 0 : sourceTarget.node,
|
|
808
|
+
targetLookup.aliasName,
|
|
809
|
+
aliases,
|
|
810
|
+
identifierBindings,
|
|
811
|
+
(suffix, sourceAlias, spreadSourceTarget) => {
|
|
812
|
+
const firstMember = suffix.split(".")[0];
|
|
813
|
+
if (!firstMember || excludedMembers.has(firstMember)) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
visit({
|
|
817
|
+
sourceAlias,
|
|
818
|
+
sourceTarget: spreadSourceTarget,
|
|
819
|
+
target,
|
|
820
|
+
targetAliasName: `${targetLookup.aliasName}.${suffix}`
|
|
821
|
+
});
|
|
822
|
+
},
|
|
823
|
+
excludedMembers
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
function collectAstCarrierSourceTargets(target, targetAliasName, sourceTarget, aliases, identifierBindings, visit) {
|
|
827
|
+
collectAstKnownCarrierMembers(sourceTarget == null ? void 0 : sourceTarget.node, (member, valueNode) => {
|
|
828
|
+
visit({
|
|
829
|
+
sourceTarget: createAstPatternSourceTarget(valueNode),
|
|
830
|
+
target,
|
|
831
|
+
targetAliasName: `${targetAliasName}.${member}`
|
|
832
|
+
});
|
|
833
|
+
});
|
|
834
|
+
collectAstRestCarrierAliasCopies(
|
|
835
|
+
sourceTarget,
|
|
836
|
+
targetAliasName,
|
|
837
|
+
aliases,
|
|
838
|
+
identifierBindings,
|
|
839
|
+
(suffix, sourceAlias) => {
|
|
840
|
+
visit({
|
|
841
|
+
sourceAlias,
|
|
842
|
+
target,
|
|
843
|
+
targetAliasName: `${targetAliasName}.${suffix}`
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
collectAstLiteralSpreadCarrierCopies(
|
|
848
|
+
sourceTarget == null ? void 0 : sourceTarget.node,
|
|
849
|
+
targetAliasName,
|
|
850
|
+
aliases,
|
|
851
|
+
identifierBindings,
|
|
852
|
+
(suffix, sourceAlias, spreadSourceTarget) => {
|
|
853
|
+
visit({
|
|
854
|
+
sourceAlias,
|
|
855
|
+
sourceTarget: spreadSourceTarget,
|
|
856
|
+
target,
|
|
857
|
+
targetAliasName: `${targetAliasName}.${suffix}`
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
);
|
|
861
|
+
collectAstDynamicCarrierSourceTargets(sourceTarget == null ? void 0 : sourceTarget.node, (suffix, dynamicSourceTarget) => {
|
|
862
|
+
visit({
|
|
863
|
+
sourceTarget: dynamicSourceTarget,
|
|
864
|
+
target,
|
|
865
|
+
targetAliasName: `${targetAliasName}.${suffix}`
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
function collectAstArrayRestCarrierSourceTargets(target, sourceTarget, restStartIndex, aliases, identifierBindings, visit) {
|
|
870
|
+
const targetLookup = getAstPatternTargetAliasLookup(target);
|
|
871
|
+
if (!targetLookup) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
const mapRestSuffix = (suffix) => {
|
|
875
|
+
const [sourceIndexText, ...restSuffixParts] = suffix.split(".");
|
|
876
|
+
const restSuffix = restSuffixParts.length ? `.${restSuffixParts.join(".")}` : "";
|
|
877
|
+
if (sourceIndexText === import_internal_types.AST_DYNAMIC_MEMBER_ALIAS) {
|
|
878
|
+
return `${import_internal_types.AST_DYNAMIC_MEMBER_ALIAS}${restSuffix}`;
|
|
879
|
+
}
|
|
880
|
+
const sourceIndex = Number(sourceIndexText);
|
|
881
|
+
if (!Number.isInteger(sourceIndex) || sourceIndex < restStartIndex) {
|
|
882
|
+
return "";
|
|
883
|
+
}
|
|
884
|
+
return `${sourceIndex - restStartIndex}${restSuffix}`;
|
|
885
|
+
};
|
|
886
|
+
collectAstKnownCarrierMembers(sourceTarget == null ? void 0 : sourceTarget.node, (member, valueNode) => {
|
|
887
|
+
const sourceIndex = Number(member);
|
|
888
|
+
if (!Number.isInteger(sourceIndex) || sourceIndex < restStartIndex) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
visit({
|
|
892
|
+
sourceTarget: createAstPatternSourceTarget(valueNode),
|
|
893
|
+
target,
|
|
894
|
+
targetAliasName: `${targetLookup.aliasName}.${sourceIndex - restStartIndex}`
|
|
895
|
+
});
|
|
896
|
+
});
|
|
897
|
+
collectAstRestCarrierAliasCopies(
|
|
898
|
+
sourceTarget,
|
|
899
|
+
targetLookup.aliasName,
|
|
900
|
+
aliases,
|
|
901
|
+
identifierBindings,
|
|
902
|
+
(suffix, sourceAlias) => {
|
|
903
|
+
const mappedSuffix = mapRestSuffix(suffix);
|
|
904
|
+
if (!mappedSuffix) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
visit({
|
|
908
|
+
sourceAlias,
|
|
909
|
+
target,
|
|
910
|
+
targetAliasName: `${targetLookup.aliasName}.${mappedSuffix}`
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
);
|
|
914
|
+
collectAstArraySpreadCarrierCopies(
|
|
915
|
+
sourceTarget == null ? void 0 : sourceTarget.node,
|
|
916
|
+
targetLookup.aliasName,
|
|
917
|
+
aliases,
|
|
918
|
+
identifierBindings,
|
|
919
|
+
(suffix, sourceAlias, spreadSourceTarget) => {
|
|
920
|
+
const mappedSuffix = mapRestSuffix(suffix);
|
|
921
|
+
if (!mappedSuffix) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
visit({
|
|
925
|
+
sourceAlias,
|
|
926
|
+
sourceTarget: spreadSourceTarget,
|
|
927
|
+
target,
|
|
928
|
+
targetAliasName: `${targetLookup.aliasName}.${mappedSuffix}`
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
function collectAstRestCarrierAliasCopies(sourceTarget, targetAliasName, aliases, identifierBindings, visit) {
|
|
934
|
+
const sourceAliasName = sourceTarget == null ? void 0 : sourceTarget.aliasName;
|
|
935
|
+
if (!sourceAliasName) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const sourcePrefix = `${sourceAliasName}.`;
|
|
939
|
+
const sourceIndex = sourceTarget.index || 0;
|
|
940
|
+
const rootName = sourceTarget.rootName || getAstAliasRootName(sourceAliasName);
|
|
941
|
+
const copied = /* @__PURE__ */ new Set();
|
|
942
|
+
const sourceAliases = aliases.filter((entry) => entry.name.startsWith(sourcePrefix) && sourceIndex >= entry.start && sourceIndex < entry.end).sort((left, right) => right.start - left.start);
|
|
943
|
+
for (const sourceAlias of sourceAliases) {
|
|
944
|
+
const suffix = sourceAlias.name.slice(sourcePrefix.length);
|
|
945
|
+
if (!suffix || copied.has(`${targetAliasName}.${suffix}`)) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
if (hasAstShadowBinding(rootName, sourceIndex, sourceAlias, identifierBindings)) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
copied.add(`${targetAliasName}.${suffix}`);
|
|
952
|
+
visit(suffix, sourceAlias);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
function collectAstLiteralSpreadCarrierCopies(sourceNode, targetAliasName, aliases, identifierBindings, visit) {
|
|
956
|
+
collectAstObjectSpreadCarrierCopies(sourceNode, targetAliasName, aliases, identifierBindings, visit);
|
|
957
|
+
collectAstArraySpreadCarrierCopies(sourceNode, targetAliasName, aliases, identifierBindings, visit);
|
|
958
|
+
}
|
|
959
|
+
function collectAstCarrierCandidateMembers(sourceNode, aliases, identifierBindings) {
|
|
960
|
+
const members = /* @__PURE__ */ new Set();
|
|
961
|
+
collectAstStaticCarrierMembers(sourceNode, (member) => members.add(member));
|
|
962
|
+
collectAstKnownCarrierMembers(sourceNode, (member) => members.add(member));
|
|
963
|
+
collectAstLiteralSpreadCarrierCopies(sourceNode, "__candidate__", aliases, identifierBindings, (suffix) => {
|
|
964
|
+
const firstMember = suffix.split(".")[0];
|
|
965
|
+
if (firstMember) {
|
|
966
|
+
members.add(firstMember);
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
collectAstDynamicCarrierSourceTargets(sourceNode, (suffix) => {
|
|
970
|
+
const firstMember = suffix.split(".")[0];
|
|
971
|
+
if (firstMember) {
|
|
972
|
+
members.add(firstMember);
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
return members;
|
|
976
|
+
}
|
|
977
|
+
function collectAstObjectSpreadCarrierCopies(sourceNode, targetAliasName, aliases, identifierBindings, visit, excludedMembers = /* @__PURE__ */ new Set()) {
|
|
978
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(sourceNode);
|
|
979
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "ObjectExpression") {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const seenMembers = new Set(excludedMembers);
|
|
983
|
+
for (let index = (unwrapped.properties || []).length - 1; index >= 0; index -= 1) {
|
|
984
|
+
const property = unwrapped.properties[index];
|
|
985
|
+
if (!property) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
if (property.type === "Property") {
|
|
989
|
+
const member = getAstStaticMemberKey(property);
|
|
990
|
+
if (member) {
|
|
991
|
+
seenMembers.add(member);
|
|
992
|
+
}
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (property.type !== "SpreadElement") {
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
const sourceTarget = createAstPatternSourceTarget(property.argument);
|
|
999
|
+
const visitSpreadMember = (suffix, sourceAlias, spreadSourceTarget) => {
|
|
1000
|
+
const firstMember = suffix.split(".")[0];
|
|
1001
|
+
if (!firstMember || seenMembers.has(firstMember)) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
seenMembers.add(firstMember);
|
|
1005
|
+
visit(suffix, sourceAlias, spreadSourceTarget);
|
|
1006
|
+
};
|
|
1007
|
+
collectAstRestCarrierAliasCopies(
|
|
1008
|
+
sourceTarget,
|
|
1009
|
+
targetAliasName,
|
|
1010
|
+
aliases,
|
|
1011
|
+
identifierBindings,
|
|
1012
|
+
(suffix, sourceAlias) => visitSpreadMember(suffix, sourceAlias, sourceTarget)
|
|
1013
|
+
);
|
|
1014
|
+
collectAstStaticCarrierMemberSourceTargets(
|
|
1015
|
+
property.argument,
|
|
1016
|
+
(suffix, spreadSourceTarget) => visitSpreadMember(suffix, void 0, spreadSourceTarget)
|
|
1017
|
+
);
|
|
1018
|
+
collectAstDynamicCarrierSourceTargets(property.argument, (suffix, dynamicSourceTarget) => {
|
|
1019
|
+
visitSpreadMember(suffix, void 0, dynamicSourceTarget);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
function collectAstDynamicCarrierSourceTargets(sourceNode, visit) {
|
|
1024
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(sourceNode);
|
|
1025
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "ObjectExpression") {
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
for (const property of unwrapped.properties || []) {
|
|
1029
|
+
if (!property || property.type !== "Property") {
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
const member = getAstStaticMemberKey(property);
|
|
1033
|
+
if (member) {
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
visit(
|
|
1037
|
+
import_internal_types.AST_DYNAMIC_MEMBER_ALIAS,
|
|
1038
|
+
createAstAmbiguousSourceTarget(createAstPatternSourceTarget(property.value || property))
|
|
1039
|
+
);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function collectAstArraySpreadCarrierCopies(sourceNode, targetAliasName, aliases, identifierBindings, visit) {
|
|
1043
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(sourceNode);
|
|
1044
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "ArrayExpression") {
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
let concreteIndexOffset = 0;
|
|
1048
|
+
let hasUnboundedSpread = false;
|
|
1049
|
+
for (const element of unwrapped.elements || []) {
|
|
1050
|
+
if (!element) {
|
|
1051
|
+
if (!hasUnboundedSpread) {
|
|
1052
|
+
concreteIndexOffset += 1;
|
|
1053
|
+
}
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
if (element.type !== "SpreadElement") {
|
|
1057
|
+
if (!hasUnboundedSpread) {
|
|
1058
|
+
concreteIndexOffset += 1;
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
visit(import_internal_types.AST_DYNAMIC_MEMBER_ALIAS, void 0, createAstPatternSourceTarget(element));
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (hasUnboundedSpread) {
|
|
1065
|
+
const sourceTarget2 = createAstPatternSourceTarget(element.argument);
|
|
1066
|
+
const mapUnboundedSpreadSuffix = (suffix) => {
|
|
1067
|
+
const [, ...restSuffixParts] = suffix.split(".");
|
|
1068
|
+
const restSuffix = restSuffixParts.length ? `.${restSuffixParts.join(".")}` : "";
|
|
1069
|
+
return `${import_internal_types.AST_DYNAMIC_MEMBER_ALIAS}${restSuffix}`;
|
|
1070
|
+
};
|
|
1071
|
+
collectAstRestCarrierAliasCopies(
|
|
1072
|
+
sourceTarget2,
|
|
1073
|
+
targetAliasName,
|
|
1074
|
+
aliases,
|
|
1075
|
+
identifierBindings,
|
|
1076
|
+
(suffix, sourceAlias) => {
|
|
1077
|
+
visit(mapUnboundedSpreadSuffix(suffix), sourceAlias, sourceTarget2);
|
|
1078
|
+
}
|
|
1079
|
+
);
|
|
1080
|
+
collectAstStaticCarrierMemberSourceTargets(element.argument, (suffix, spreadSourceTarget) => {
|
|
1081
|
+
visit(mapUnboundedSpreadSuffix(suffix), void 0, spreadSourceTarget);
|
|
1082
|
+
});
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
const sourceTarget = createAstPatternSourceTarget(element.argument);
|
|
1086
|
+
const mapSpreadSuffix = (suffix) => {
|
|
1087
|
+
const [sourceIndexText, ...restSuffixParts] = suffix.split(".");
|
|
1088
|
+
const sourceIndex = Number(sourceIndexText);
|
|
1089
|
+
if (!Number.isInteger(sourceIndex) || sourceIndex < 0) {
|
|
1090
|
+
return "";
|
|
1091
|
+
}
|
|
1092
|
+
const restSuffix = restSuffixParts.length ? `.${restSuffixParts.join(".")}` : "";
|
|
1093
|
+
const targetIndex = hasUnboundedSpread ? sourceIndex : sourceIndex + concreteIndexOffset;
|
|
1094
|
+
return `${targetIndex}${restSuffix}`;
|
|
1095
|
+
};
|
|
1096
|
+
collectAstRestCarrierAliasCopies(
|
|
1097
|
+
sourceTarget,
|
|
1098
|
+
targetAliasName,
|
|
1099
|
+
aliases,
|
|
1100
|
+
identifierBindings,
|
|
1101
|
+
(suffix, sourceAlias) => {
|
|
1102
|
+
const mappedSuffix = mapSpreadSuffix(suffix);
|
|
1103
|
+
if (!mappedSuffix) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
visit(mappedSuffix, sourceAlias, sourceTarget);
|
|
1107
|
+
}
|
|
1108
|
+
);
|
|
1109
|
+
collectAstStaticCarrierMemberSourceTargets(element.argument, (suffix, spreadSourceTarget) => {
|
|
1110
|
+
const mappedSuffix = mapSpreadSuffix(suffix);
|
|
1111
|
+
if (!mappedSuffix) {
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
visit(mappedSuffix, void 0, spreadSourceTarget);
|
|
1115
|
+
});
|
|
1116
|
+
const spreadLength = getAstStaticArrayElementCount(element.argument);
|
|
1117
|
+
if (!hasUnboundedSpread && typeof spreadLength === "number") {
|
|
1118
|
+
concreteIndexOffset += spreadLength;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
hasUnboundedSpread = true;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
function collectAstStaticCarrierMemberSourceTargets(node, visit) {
|
|
1125
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1126
|
+
if (!unwrapped) {
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1130
|
+
const seenMembers = /* @__PURE__ */ new Set();
|
|
1131
|
+
for (let index = (unwrapped.properties || []).length - 1; index >= 0; index -= 1) {
|
|
1132
|
+
const property = unwrapped.properties[index];
|
|
1133
|
+
if (!property) {
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
if (property.type === "SpreadElement") {
|
|
1137
|
+
collectAstStaticCarrierMemberSourceTargets(property.argument, (member2, sourceTarget) => {
|
|
1138
|
+
if (seenMembers.has(member2)) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
seenMembers.add(member2);
|
|
1142
|
+
visit(member2, sourceTarget);
|
|
1143
|
+
});
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
if (property.type !== "Property") {
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
const member = getAstStaticMemberKey(property);
|
|
1150
|
+
if (!member) {
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
if (seenMembers.has(member)) {
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
seenMembers.add(member);
|
|
1157
|
+
visit(member, createAstPatternSourceTarget(property.value));
|
|
1158
|
+
}
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
if (unwrapped.type === "ArrayExpression") {
|
|
1162
|
+
let targetIndex = 0;
|
|
1163
|
+
for (const element of unwrapped.elements || []) {
|
|
1164
|
+
if (!element) {
|
|
1165
|
+
targetIndex += 1;
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
if (element.type !== "SpreadElement") {
|
|
1169
|
+
visit(String(targetIndex), createAstPatternSourceTarget(element));
|
|
1170
|
+
targetIndex += 1;
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
const spreadLength = getAstStaticArrayElementCount(element.argument);
|
|
1174
|
+
if (typeof spreadLength !== "number") {
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
collectAstStaticCarrierMemberSourceTargets(element.argument, (member, sourceTarget) => {
|
|
1178
|
+
const sourceIndex = Number(member);
|
|
1179
|
+
if (!Number.isInteger(sourceIndex) || sourceIndex < 0) {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
visit(String(targetIndex + sourceIndex), sourceTarget);
|
|
1183
|
+
});
|
|
1184
|
+
targetIndex += spreadLength;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function getAstStaticArrayElementCount(node) {
|
|
1189
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1190
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "ArrayExpression") {
|
|
1191
|
+
return void 0;
|
|
1192
|
+
}
|
|
1193
|
+
let count = 0;
|
|
1194
|
+
for (const element of unwrapped.elements || []) {
|
|
1195
|
+
if (!element) {
|
|
1196
|
+
count += 1;
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (element.type !== "SpreadElement") {
|
|
1200
|
+
count += 1;
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
const spreadLength = getAstStaticArrayElementCount(element.argument);
|
|
1204
|
+
if (typeof spreadLength !== "number") {
|
|
1205
|
+
return void 0;
|
|
1206
|
+
}
|
|
1207
|
+
count += spreadLength;
|
|
1208
|
+
}
|
|
1209
|
+
return count;
|
|
1210
|
+
}
|
|
1211
|
+
function collectAstObjectPatternStaticMembers(pattern) {
|
|
1212
|
+
const members = /* @__PURE__ */ new Set();
|
|
1213
|
+
for (const property of (pattern == null ? void 0 : pattern.properties) || []) {
|
|
1214
|
+
if (!property || property.type !== "Property") {
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
const member = getAstStaticPropertyName(property);
|
|
1218
|
+
if (member) {
|
|
1219
|
+
members.add(member);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return members;
|
|
1223
|
+
}
|
|
1224
|
+
function getAstPatternTargetAliasLookup(target) {
|
|
1225
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
|
|
1226
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "Identifier") {
|
|
1227
|
+
return {
|
|
1228
|
+
aliasName: unwrapped.name,
|
|
1229
|
+
index: typeof unwrapped.start === "number" ? unwrapped.start : 0,
|
|
1230
|
+
rootName: unwrapped.name
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
return getAstMemberAliasLookup(unwrapped);
|
|
1234
|
+
}
|
|
1235
|
+
function collectAstPatternMemberExpressions(pattern, visit) {
|
|
1236
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(pattern);
|
|
1237
|
+
if (!unwrapped) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
if (unwrapped.type === "MemberExpression") {
|
|
1241
|
+
visit(unwrapped);
|
|
1242
|
+
return;
|
|
1243
|
+
}
|
|
1244
|
+
if (unwrapped.type === "AssignmentPattern") {
|
|
1245
|
+
collectAstPatternMemberExpressions(unwrapped.left, visit);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
if (unwrapped.type === "RestElement") {
|
|
1249
|
+
collectAstPatternMemberExpressions(unwrapped.argument, visit);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
if (unwrapped.type === "ObjectPattern") {
|
|
1253
|
+
for (const property of unwrapped.properties || []) {
|
|
1254
|
+
if (!property) {
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
collectAstPatternMemberExpressions(property.type === "Property" ? property.value : property.argument, visit);
|
|
1258
|
+
}
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (unwrapped.type === "ArrayPattern") {
|
|
1262
|
+
for (const element of unwrapped.elements || []) {
|
|
1263
|
+
collectAstPatternMemberExpressions(element, visit);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
function createAstPatternSourceTarget(node) {
|
|
1268
|
+
const sourceRoot = getAstPatternSourceRoot(node);
|
|
1269
|
+
return {
|
|
1270
|
+
node,
|
|
1271
|
+
aliasName: sourceRoot == null ? void 0 : sourceRoot.aliasName,
|
|
1272
|
+
rootName: sourceRoot == null ? void 0 : sourceRoot.rootName,
|
|
1273
|
+
index: (sourceRoot == null ? void 0 : sourceRoot.index) ?? (typeof (node == null ? void 0 : node.start) === "number" ? node.start : 0)
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
function createMaybeAstPatternSourceTarget(node) {
|
|
1277
|
+
return node ? createAstPatternSourceTarget(node) : void 0;
|
|
1278
|
+
}
|
|
1279
|
+
function getAstPatternMemberSourceTarget(sourceTarget, member) {
|
|
1280
|
+
const memberSourceTarget = getAstStaticCarrierMemberSourceTarget(sourceTarget == null ? void 0 : sourceTarget.node, member);
|
|
1281
|
+
if (memberSourceTarget) {
|
|
1282
|
+
return memberSourceTarget;
|
|
1283
|
+
}
|
|
1284
|
+
const sourceRoot = (sourceTarget == null ? void 0 : sourceTarget.aliasName) ? sourceTarget : getAstPatternSourceRoot(sourceTarget == null ? void 0 : sourceTarget.node);
|
|
1285
|
+
if (sourceRoot == null ? void 0 : sourceRoot.aliasName) {
|
|
1286
|
+
return {
|
|
1287
|
+
aliasName: `${sourceRoot.aliasName}.${member}`,
|
|
1288
|
+
rootName: sourceRoot.rootName,
|
|
1289
|
+
index: sourceRoot.index ?? (sourceTarget == null ? void 0 : sourceTarget.index) ?? 0
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
return { index: (sourceTarget == null ? void 0 : sourceTarget.index) ?? 0 };
|
|
1293
|
+
}
|
|
1294
|
+
function getAstStaticCarrierMemberSourceTarget(node, member) {
|
|
1295
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1296
|
+
if (!unwrapped) {
|
|
1297
|
+
return void 0;
|
|
1298
|
+
}
|
|
1299
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1300
|
+
return getAstObjectCarrierMemberSourceTarget(unwrapped, member);
|
|
1301
|
+
}
|
|
1302
|
+
if (unwrapped.type === "ArrayExpression") {
|
|
1303
|
+
return getAstArrayCarrierMemberSourceTarget(unwrapped, member);
|
|
1304
|
+
}
|
|
1305
|
+
return void 0;
|
|
1306
|
+
}
|
|
1307
|
+
function getAstObjectCarrierMemberSourceTarget(node, member) {
|
|
1308
|
+
var _a;
|
|
1309
|
+
const fallbackSourceTargets = [];
|
|
1310
|
+
for (let index = (node.properties || []).length - 1; index >= 0; index -= 1) {
|
|
1311
|
+
const property = node.properties[index];
|
|
1312
|
+
if (!property) {
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
if (property.type === "SpreadElement") {
|
|
1316
|
+
const spreadTarget = getAstSpreadMemberSourceTarget(property.argument, member);
|
|
1317
|
+
if (spreadTarget) {
|
|
1318
|
+
fallbackSourceTargets.push(spreadTarget);
|
|
1319
|
+
}
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
if (property.type !== "Property") {
|
|
1323
|
+
return createAstFallbackSourceTarget(fallbackSourceTargets, property.start || node.start || 0);
|
|
1324
|
+
}
|
|
1325
|
+
const propertyKey = getAstStaticMemberKey(property);
|
|
1326
|
+
if (!propertyKey) {
|
|
1327
|
+
fallbackSourceTargets.push(createAstAmbiguousSourceTarget(createAstPatternSourceTarget(property.value)));
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
if (propertyKey !== member) {
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
const propertyTarget = createAstPatternSourceTarget(property.value);
|
|
1334
|
+
if (!fallbackSourceTargets.length) {
|
|
1335
|
+
return propertyTarget;
|
|
1336
|
+
}
|
|
1337
|
+
return createAstFallbackSourceTarget(
|
|
1338
|
+
[...fallbackSourceTargets, propertyTarget],
|
|
1339
|
+
typeof ((_a = property.value) == null ? void 0 : _a.start) === "number" ? property.value.start : property.start || node.start || 0
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
return createAstFallbackSourceTarget(fallbackSourceTargets, node.start || 0);
|
|
1343
|
+
}
|
|
1344
|
+
function getAstArrayCarrierMemberSourceTarget(node, member) {
|
|
1345
|
+
const targetIndex = Number(member);
|
|
1346
|
+
if (!Number.isInteger(targetIndex) || targetIndex < 0) {
|
|
1347
|
+
return void 0;
|
|
1348
|
+
}
|
|
1349
|
+
const fallbackSourceTargets = [];
|
|
1350
|
+
let concreteIndex = 0;
|
|
1351
|
+
let hasSpreadBefore = false;
|
|
1352
|
+
for (const element of node.elements || []) {
|
|
1353
|
+
if (!element) {
|
|
1354
|
+
if (!hasSpreadBefore && concreteIndex === targetIndex && !fallbackSourceTargets.length) {
|
|
1355
|
+
return void 0;
|
|
1356
|
+
}
|
|
1357
|
+
concreteIndex += 1;
|
|
1358
|
+
continue;
|
|
1359
|
+
}
|
|
1360
|
+
if (element.type === "SpreadElement") {
|
|
1361
|
+
const spreadLength = getAstStaticArrayElementCount(element.argument);
|
|
1362
|
+
if (!hasSpreadBefore && typeof spreadLength === "number") {
|
|
1363
|
+
const spreadIndex = targetIndex - concreteIndex;
|
|
1364
|
+
if (spreadIndex < 0) {
|
|
1365
|
+
return createAstFallbackSourceTarget(fallbackSourceTargets, node.start || 0);
|
|
1366
|
+
}
|
|
1367
|
+
if (spreadIndex < spreadLength) {
|
|
1368
|
+
return getAstSpreadMemberSourceTarget(element.argument, String(spreadIndex));
|
|
1369
|
+
}
|
|
1370
|
+
concreteIndex += spreadLength;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
const spreadMember = hasSpreadBefore ? String(targetIndex) : String(targetIndex - concreteIndex);
|
|
1374
|
+
if (targetIndex >= concreteIndex || hasSpreadBefore) {
|
|
1375
|
+
const spreadTarget = getAstSpreadMemberSourceTarget(element.argument, spreadMember);
|
|
1376
|
+
if (spreadTarget) {
|
|
1377
|
+
fallbackSourceTargets.push(hasSpreadBefore ? createAstAmbiguousSourceTarget(spreadTarget) : spreadTarget);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
hasSpreadBefore = true;
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
if (!hasSpreadBefore && concreteIndex === targetIndex) {
|
|
1384
|
+
const elementTarget = createAstPatternSourceTarget(element);
|
|
1385
|
+
if (!fallbackSourceTargets.length) {
|
|
1386
|
+
return elementTarget;
|
|
1387
|
+
}
|
|
1388
|
+
return createAstFallbackSourceTarget(
|
|
1389
|
+
[...fallbackSourceTargets, elementTarget],
|
|
1390
|
+
typeof element.start === "number" ? element.start : node.start || 0
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
if (hasSpreadBefore) {
|
|
1394
|
+
fallbackSourceTargets.push(createAstAmbiguousSourceTarget(createAstPatternSourceTarget(element)));
|
|
1395
|
+
}
|
|
1396
|
+
concreteIndex += 1;
|
|
1397
|
+
}
|
|
1398
|
+
return createAstFallbackSourceTarget(fallbackSourceTargets, node.start || 0);
|
|
1399
|
+
}
|
|
1400
|
+
function createAstAmbiguousSourceTarget(sourceTarget) {
|
|
1401
|
+
return sourceTarget ? { ...sourceTarget, ambiguous: true } : void 0;
|
|
1402
|
+
}
|
|
1403
|
+
function getAstSpreadMemberSourceTarget(spreadArgument, member) {
|
|
1404
|
+
const sourceRoot = getAstPatternSourceRoot(spreadArgument);
|
|
1405
|
+
if (sourceRoot == null ? void 0 : sourceRoot.aliasName) {
|
|
1406
|
+
return {
|
|
1407
|
+
aliasName: `${sourceRoot.aliasName}.${member}`,
|
|
1408
|
+
rootName: sourceRoot.rootName,
|
|
1409
|
+
index: sourceRoot.index ?? (typeof (spreadArgument == null ? void 0 : spreadArgument.start) === "number" ? spreadArgument.start : 0)
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
return getAstStaticCarrierMemberSourceTarget(spreadArgument, member);
|
|
1413
|
+
}
|
|
1414
|
+
function createAstFallbackSourceTarget(fallbackSourceTargets, index) {
|
|
1415
|
+
const targets = fallbackSourceTargets.filter(Boolean);
|
|
1416
|
+
return targets.length ? {
|
|
1417
|
+
fallbackSourceTargets: targets,
|
|
1418
|
+
index
|
|
1419
|
+
} : void 0;
|
|
1420
|
+
}
|
|
1421
|
+
function getAstPatternSourceRoot(node) {
|
|
1422
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1423
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) === "Identifier") {
|
|
1424
|
+
return {
|
|
1425
|
+
aliasName: unwrapped.name,
|
|
1426
|
+
index: typeof unwrapped.start === "number" ? unwrapped.start : 0,
|
|
1427
|
+
rootName: unwrapped.name
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
return getAstMemberAliasLookup(unwrapped);
|
|
1431
|
+
}
|
|
1432
|
+
function getAstStaticCarrierMemberValue(node, member) {
|
|
1433
|
+
var _a;
|
|
1434
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1435
|
+
if (!unwrapped) {
|
|
1436
|
+
return void 0;
|
|
1437
|
+
}
|
|
1438
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1439
|
+
for (let index = (unwrapped.properties || []).length - 1; index >= 0; index -= 1) {
|
|
1440
|
+
const property = unwrapped.properties[index];
|
|
1441
|
+
if (!property) {
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
if (property.type !== "Property") {
|
|
1445
|
+
return void 0;
|
|
1446
|
+
}
|
|
1447
|
+
const propertyKey = getAstStaticMemberKey(property);
|
|
1448
|
+
if (!propertyKey) {
|
|
1449
|
+
return void 0;
|
|
1450
|
+
}
|
|
1451
|
+
if (propertyKey === member) {
|
|
1452
|
+
return property.value;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (unwrapped.type === "ArrayExpression") {
|
|
1457
|
+
const index = Number(member);
|
|
1458
|
+
if (Number.isInteger(index) && index >= 0) {
|
|
1459
|
+
const element = (_a = unwrapped.elements) == null ? void 0 : _a[index];
|
|
1460
|
+
return element && element.type !== "SpreadElement" ? element : void 0;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return void 0;
|
|
1464
|
+
}
|
|
1465
|
+
function collectAstKnownCarrierMembers(node, visit) {
|
|
1466
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1467
|
+
if (!unwrapped) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1471
|
+
const seenMembers = /* @__PURE__ */ new Set();
|
|
1472
|
+
for (let index = (unwrapped.properties || []).length - 1; index >= 0; index -= 1) {
|
|
1473
|
+
const property = unwrapped.properties[index];
|
|
1474
|
+
if (!property) {
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
if (property.type !== "Property") {
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
const member = getAstStaticMemberKey(property);
|
|
1481
|
+
if (!member) {
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
if (seenMembers.has(member)) {
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
seenMembers.add(member);
|
|
1488
|
+
visit(member, property.value, property.value || property);
|
|
1489
|
+
}
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
if (unwrapped.type === "ArrayExpression") {
|
|
1493
|
+
for (let index = 0; index < (unwrapped.elements || []).length; index += 1) {
|
|
1494
|
+
const element = unwrapped.elements[index];
|
|
1495
|
+
if (!element || element.type === "SpreadElement") {
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
visit(String(index), element, element);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function collectAstStaticCarrierMembers(node, visit) {
|
|
1503
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1504
|
+
if (!unwrapped) {
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1508
|
+
for (const property of unwrapped.properties || []) {
|
|
1509
|
+
if (!property || property.type !== "Property") {
|
|
1510
|
+
continue;
|
|
1511
|
+
}
|
|
1512
|
+
const member = getAstStaticMemberKey(property);
|
|
1513
|
+
if (member) {
|
|
1514
|
+
visit(member, property.value, property.value || property);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
if (unwrapped.type === "ArrayExpression") {
|
|
1520
|
+
for (let index = 0; index < (unwrapped.elements || []).length; index += 1) {
|
|
1521
|
+
const element = unwrapped.elements[index];
|
|
1522
|
+
if (!element || element.type === "SpreadElement") {
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
visit(String(index), element, element);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
function getAstBindingIdentifierNode(node) {
|
|
1530
|
+
var _a;
|
|
1531
|
+
if ((node == null ? void 0 : node.type) === "Identifier") {
|
|
1532
|
+
return node;
|
|
1533
|
+
}
|
|
1534
|
+
if ((node == null ? void 0 : node.type) === "AssignmentPattern" && ((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
|
|
1535
|
+
return node.left;
|
|
1536
|
+
}
|
|
1537
|
+
return void 0;
|
|
1538
|
+
}
|
|
1539
|
+
function getAstBindingIdentifierName(node) {
|
|
1540
|
+
var _a;
|
|
1541
|
+
if ((node == null ? void 0 : node.type) === "Identifier") {
|
|
1542
|
+
return node.name;
|
|
1543
|
+
}
|
|
1544
|
+
if ((node == null ? void 0 : node.type) === "AssignmentPattern" && ((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
|
|
1545
|
+
return node.left.name;
|
|
1546
|
+
}
|
|
1547
|
+
return "";
|
|
1548
|
+
}
|
|
1549
|
+
function getAstObjectPatternFromValue(node) {
|
|
1550
|
+
var _a;
|
|
1551
|
+
if ((node == null ? void 0 : node.type) === "ObjectPattern") {
|
|
1552
|
+
return node;
|
|
1553
|
+
}
|
|
1554
|
+
if ((node == null ? void 0 : node.type) === "AssignmentPattern" && ((_a = node.left) == null ? void 0 : _a.type) === "ObjectPattern") {
|
|
1555
|
+
return node.left;
|
|
1556
|
+
}
|
|
1557
|
+
return void 0;
|
|
1558
|
+
}
|
|
1559
|
+
function trimAstAliasesAfterWrites(aliases, writes, identifierBindings) {
|
|
1560
|
+
return aliases.map((alias) => {
|
|
1561
|
+
const aliasDeclarationStart = alias.declarationStart ?? alias.start;
|
|
1562
|
+
const aliasRootName = getAstAliasRootName(alias.name);
|
|
1563
|
+
const nextWrite = writes.filter(
|
|
1564
|
+
(write) => (write.name === alias.name || alias.name.includes(".") && write.name === aliasRootName) && write.index > aliasDeclarationStart && write.index >= alias.start && write.index < alias.end && write.alwaysRunsInExecutionScope && (0, import_bindings.isSameAstRange)(write.executionScope, alias.executionScope) && !hasAstShadowBinding(aliasRootName, write.index, alias, identifierBindings)
|
|
1565
|
+
).sort((left, right) => left.index - right.index)[0];
|
|
1566
|
+
return nextWrite ? { ...alias, end: nextWrite.index } : alias;
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
function resolveRunJsStaticString(node, source, stringBindings, identifierBindings) {
|
|
1570
|
+
if (!node) {
|
|
1571
|
+
return void 0;
|
|
1572
|
+
}
|
|
1573
|
+
const resolved = resolveAstResourceTypeExpression(node, source, stringBindings, identifierBindings);
|
|
1574
|
+
return resolved.status === "resolved" ? resolved.value : void 0;
|
|
1575
|
+
}
|
|
1576
|
+
function resolveRunJsStaticObjectExpression(node, identifierBindings, staticFilterValueBindings) {
|
|
1577
|
+
return resolveRunJsStaticObjectExpressionRec(node, identifierBindings, staticFilterValueBindings);
|
|
1578
|
+
}
|
|
1579
|
+
function resolveRunJsStaticObjectExpressionRec(node, identifierBindings, staticFilterValueBindings, seen = /* @__PURE__ */ new Set()) {
|
|
1580
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1581
|
+
if (!unwrapped) {
|
|
1582
|
+
return void 0;
|
|
1583
|
+
}
|
|
1584
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
1585
|
+
return unwrapped;
|
|
1586
|
+
}
|
|
1587
|
+
if (unwrapped.type === "Identifier") {
|
|
1588
|
+
const binding = resolveAstAliasBinding(
|
|
1589
|
+
unwrapped.name,
|
|
1590
|
+
unwrapped.start || 0,
|
|
1591
|
+
staticFilterValueBindings,
|
|
1592
|
+
identifierBindings
|
|
1593
|
+
);
|
|
1594
|
+
if (!binding || seen.has(binding)) {
|
|
1595
|
+
return void 0;
|
|
1596
|
+
}
|
|
1597
|
+
const nextSeen = new Set(seen);
|
|
1598
|
+
nextSeen.add(binding);
|
|
1599
|
+
return resolveRunJsStaticObjectExpressionRec(
|
|
1600
|
+
binding.valueNode,
|
|
1601
|
+
identifierBindings,
|
|
1602
|
+
staticFilterValueBindings,
|
|
1603
|
+
nextSeen
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
if (unwrapped.type === "MemberExpression") {
|
|
1607
|
+
const object = resolveRunJsStaticObjectExpressionRec(
|
|
1608
|
+
unwrapped.object,
|
|
1609
|
+
identifierBindings,
|
|
1610
|
+
staticFilterValueBindings,
|
|
1611
|
+
seen
|
|
1612
|
+
);
|
|
1613
|
+
if (!object) {
|
|
1614
|
+
return void 0;
|
|
1615
|
+
}
|
|
1616
|
+
const memberName = getAstStaticPropertyName(unwrapped);
|
|
1617
|
+
if (!memberName) {
|
|
1618
|
+
return void 0;
|
|
1619
|
+
}
|
|
1620
|
+
const property = getRunJsObjectProperty(object, [memberName], identifierBindings, staticFilterValueBindings);
|
|
1621
|
+
return resolveRunJsStaticObjectExpressionRec(property == null ? void 0 : property.value, identifierBindings, staticFilterValueBindings, seen);
|
|
1622
|
+
}
|
|
1623
|
+
return void 0;
|
|
1624
|
+
}
|
|
1625
|
+
function getRunJsObjectProperty(node, names, identifierBindings, staticFilterValueBindings) {
|
|
1626
|
+
const lookup = getRunJsObjectPropertyLookup(node, names, identifierBindings, staticFilterValueBindings);
|
|
1627
|
+
return lookup.status === "found" ? lookup.property : void 0;
|
|
1628
|
+
}
|
|
1629
|
+
function getRunJsObjectPropertyByPath(node, members, identifierBindings, staticFilterValueBindings) {
|
|
1630
|
+
let current = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1631
|
+
let property;
|
|
1632
|
+
for (let index = 0; index < members.length; index += 1) {
|
|
1633
|
+
const member = members[index];
|
|
1634
|
+
property = getRunJsObjectProperty(current, [member], identifierBindings, staticFilterValueBindings);
|
|
1635
|
+
if (!property) {
|
|
1636
|
+
return void 0;
|
|
1637
|
+
}
|
|
1638
|
+
current = resolveRunJsStaticObjectExpression(
|
|
1639
|
+
property.value,
|
|
1640
|
+
identifierBindings || [],
|
|
1641
|
+
staticFilterValueBindings || []
|
|
1642
|
+
);
|
|
1643
|
+
if (!current && index < members.length - 1) {
|
|
1644
|
+
return void 0;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
return property;
|
|
1648
|
+
}
|
|
1649
|
+
function getRunJsObjectPropertyLookup(node, names, identifierBindings, staticFilterValueBindings) {
|
|
1650
|
+
const object = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1651
|
+
if ((object == null ? void 0 : object.type) !== "ObjectExpression") {
|
|
1652
|
+
return { status: "missing" };
|
|
1653
|
+
}
|
|
1654
|
+
const nameSet = new Set(names.map((name) => name.toLowerCase()));
|
|
1655
|
+
const properties = object.properties || [];
|
|
1656
|
+
for (let index = properties.length - 1; index >= 0; index -= 1) {
|
|
1657
|
+
const property = properties[index];
|
|
1658
|
+
if (!property) {
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
if (property.type === "SpreadElement") {
|
|
1662
|
+
if (identifierBindings && staticFilterValueBindings) {
|
|
1663
|
+
const spreadObject = resolveRunJsStaticObjectExpression(
|
|
1664
|
+
property.argument,
|
|
1665
|
+
identifierBindings,
|
|
1666
|
+
staticFilterValueBindings
|
|
1667
|
+
);
|
|
1668
|
+
if (spreadObject) {
|
|
1669
|
+
const spreadLookup = getRunJsObjectPropertyLookup(
|
|
1670
|
+
spreadObject,
|
|
1671
|
+
names,
|
|
1672
|
+
identifierBindings,
|
|
1673
|
+
staticFilterValueBindings
|
|
1674
|
+
);
|
|
1675
|
+
if (spreadLookup.status !== "missing") {
|
|
1676
|
+
return spreadLookup;
|
|
1677
|
+
}
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
return { status: "unknown" };
|
|
1682
|
+
}
|
|
1683
|
+
if (property.type !== "Property") {
|
|
1684
|
+
return { status: "unknown" };
|
|
1685
|
+
}
|
|
1686
|
+
const propertyName = (0, import_surface.normalizeText)(getAstStaticPropertyName(property));
|
|
1687
|
+
if (!propertyName) {
|
|
1688
|
+
return { status: "unknown" };
|
|
1689
|
+
}
|
|
1690
|
+
if (nameSet.has(propertyName.toLowerCase())) {
|
|
1691
|
+
return { status: "found", property };
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return { status: "missing" };
|
|
1695
|
+
}
|
|
1696
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1697
|
+
0 && (module.exports = {
|
|
1698
|
+
addAstFunctionParamBindings,
|
|
1699
|
+
collectAstArrayRestCarrierSourceTargets,
|
|
1700
|
+
collectAstArraySpreadCarrierCopies,
|
|
1701
|
+
collectAstCarrierCandidateMembers,
|
|
1702
|
+
collectAstCarrierSourceTargets,
|
|
1703
|
+
collectAstDynamicCarrierSourceTargets,
|
|
1704
|
+
collectAstKnownCarrierMembers,
|
|
1705
|
+
collectAstLiteralSpreadCarrierCopies,
|
|
1706
|
+
collectAstObjectPatternAliases,
|
|
1707
|
+
collectAstObjectPatternPathAliases,
|
|
1708
|
+
collectAstObjectPatternStaticMembers,
|
|
1709
|
+
collectAstObjectRestCarrierSourceTargets,
|
|
1710
|
+
collectAstObjectSpreadCarrierCopies,
|
|
1711
|
+
collectAstPatternBindingIdentifiers,
|
|
1712
|
+
collectAstPatternCarrierSourceTargets,
|
|
1713
|
+
collectAstPatternCarrierSourceTargetsFromSourceTarget,
|
|
1714
|
+
collectAstPatternDefaultValueAliases,
|
|
1715
|
+
collectAstPatternDefaultValueAliasesWithSource,
|
|
1716
|
+
collectAstPatternMemberExpressions,
|
|
1717
|
+
collectAstPatternRestCarrierSourceTargets,
|
|
1718
|
+
collectAstPatternRestCarrierSourceTargetsRec,
|
|
1719
|
+
collectAstPatternSourceTargets,
|
|
1720
|
+
collectAstPatternSourceTargetsRec,
|
|
1721
|
+
collectAstRestCarrierAliasCopies,
|
|
1722
|
+
collectAstStaticCarrierMemberSourceTargets,
|
|
1723
|
+
collectAstStaticCarrierMembers,
|
|
1724
|
+
compareAstAliasPrecedence,
|
|
1725
|
+
createAstAmbiguousSourceTarget,
|
|
1726
|
+
createAstFallbackSourceTarget,
|
|
1727
|
+
createAstPatternSourceTarget,
|
|
1728
|
+
createMaybeAstPatternSourceTarget,
|
|
1729
|
+
dedupeAstResourceEntries,
|
|
1730
|
+
findUnboundCtxMatches,
|
|
1731
|
+
getAstAliasPrecedenceStart,
|
|
1732
|
+
getAstAliasRootName,
|
|
1733
|
+
getAstArrayCarrierMemberSourceTarget,
|
|
1734
|
+
getAstAssignmentTargetScope,
|
|
1735
|
+
getAstBindingIdentifierName,
|
|
1736
|
+
getAstBindingIdentifierNode,
|
|
1737
|
+
getAstMemberAliasLookup,
|
|
1738
|
+
getAstMemberAssignmentTargetScope,
|
|
1739
|
+
getAstMemberRootIdentifier,
|
|
1740
|
+
getAstMemberWriteLookup,
|
|
1741
|
+
getAstObjectCarrierMemberSourceTarget,
|
|
1742
|
+
getAstObjectPatternFromValue,
|
|
1743
|
+
getAstPatternMemberSourceTarget,
|
|
1744
|
+
getAstPatternSourceRoot,
|
|
1745
|
+
getAstPatternTargetAliasLookup,
|
|
1746
|
+
getAstSpreadMemberSourceTarget,
|
|
1747
|
+
getAstStaticArrayElementCount,
|
|
1748
|
+
getAstStaticCarrierMemberSourceTarget,
|
|
1749
|
+
getAstStaticCarrierMemberValue,
|
|
1750
|
+
getAstStaticMemberKey,
|
|
1751
|
+
getAstStaticPropertyName,
|
|
1752
|
+
getCtxMethodName,
|
|
1753
|
+
getRunJsObjectProperty,
|
|
1754
|
+
getRunJsObjectPropertyByPath,
|
|
1755
|
+
getRunJsObjectPropertyLookup,
|
|
1756
|
+
hasAstActiveBinding,
|
|
1757
|
+
hasAstShadowBinding,
|
|
1758
|
+
isAstCtxApiAliasAssignmentOperator,
|
|
1759
|
+
isAstDefiniteAssignmentOperator,
|
|
1760
|
+
isAstDynamicMemberAliasMatch,
|
|
1761
|
+
isCtxIdentifier,
|
|
1762
|
+
isCtxRootFromAst,
|
|
1763
|
+
isUnshadowedCtxIdentifier,
|
|
1764
|
+
resolveAstActiveIdentifierBinding,
|
|
1765
|
+
resolveAstAliasBinding,
|
|
1766
|
+
resolveAstDynamicAliasBinding,
|
|
1767
|
+
resolveAstMemberAliasBinding,
|
|
1768
|
+
resolveAstNamedAliasBinding,
|
|
1769
|
+
resolveAstResourceTypeExpression,
|
|
1770
|
+
resolveAstStaticStringValue,
|
|
1771
|
+
resolveAstStaticTemplateLiteralValue,
|
|
1772
|
+
resolveCtxMethodCall,
|
|
1773
|
+
resolveRunJsStaticObjectExpression,
|
|
1774
|
+
resolveRunJsStaticObjectExpressionRec,
|
|
1775
|
+
resolveRunJsStaticString,
|
|
1776
|
+
trimAstAliasesAfterWrites
|
|
1777
|
+
});
|