@saptools/service-flow 0.1.22 → 0.1.23

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.
@@ -859,13 +859,17 @@ function connectFactFromCall(call) {
859
859
  }
860
860
  function unwrapCall(expr) {
861
861
  if (ts5.isAwaitExpression(expr)) return unwrapCall(expr.expression);
862
+ if (ts5.isParenthesizedExpression(expr)) return unwrapCall(expr.expression);
862
863
  if (ts5.isAsExpression(expr) || ts5.isSatisfiesExpression(expr)) return unwrapCall(expr.expression);
864
+ if (ts5.isTypeAssertionExpression(expr)) return unwrapCall(expr.expression);
863
865
  if (ts5.isCallExpression(expr)) return expr;
864
866
  return void 0;
865
867
  }
866
868
  function unwrapIdentityExpression(expr) {
867
869
  if (ts5.isAwaitExpression(expr)) return unwrapIdentityExpression(expr.expression);
870
+ if (ts5.isParenthesizedExpression(expr)) return unwrapIdentityExpression(expr.expression);
868
871
  if (ts5.isAsExpression(expr) || ts5.isSatisfiesExpression(expr)) return unwrapIdentityExpression(expr.expression);
872
+ if (ts5.isTypeAssertionExpression(expr)) return unwrapIdentityExpression(expr.expression);
869
873
  return expr;
870
874
  }
871
875
  function findConnectInExpression(expr) {
@@ -1129,18 +1133,17 @@ async function parseServiceBindings(repoPath, filePath) {
1129
1133
  const sourceFile = normalizePath(filePath);
1130
1134
  return [...out].reverse().find((row) => row.variableName === variableName && row.sourceFile === sourceFile);
1131
1135
  }
1132
- function cloneAliasBinding(decl, sourceName, aliasKind) {
1133
- if (!ts5.isIdentifier(decl.name)) return;
1136
+ function cloneAliasBinding(targetName, sourceName, aliasKind, node) {
1134
1137
  const existing = bindingForVariable(sourceName);
1135
1138
  if (!existing) return;
1136
1139
  out.push({
1137
1140
  ...existing,
1138
- variableName: decl.name.text,
1139
- sourceLine: lineOf4(sourceFileAst, decl),
1141
+ variableName: targetName,
1142
+ sourceLine: lineOf4(sourceFileAst, node),
1140
1143
  helperChain: [
1141
1144
  ...existing.helperChain ?? [],
1142
1145
  {
1143
- callerVariable: decl.name.text,
1146
+ callerVariable: targetName,
1144
1147
  aliasOf: sourceName,
1145
1148
  aliasKind,
1146
1149
  scopeRule: "same-file-source-order"
@@ -1152,25 +1155,25 @@ async function parseServiceBindings(repoPath, filePath) {
1152
1155
  if (!ts5.isIdentifier(decl.name) || !decl.initializer) return;
1153
1156
  const unwrapped = unwrapIdentityExpression(decl.initializer);
1154
1157
  if (!ts5.isIdentifier(unwrapped)) return;
1155
- cloneAliasBinding(decl, unwrapped.text, "identity");
1158
+ cloneAliasBinding(decl.name.text, unwrapped.text, "identity", decl);
1156
1159
  }
1157
- async function recordVariable(decl) {
1158
- if (!ts5.isIdentifier(decl.name) || !decl.initializer) return;
1159
- const call = unwrapCall(decl.initializer);
1160
+ async function recordBindingFromExpression(targetName, expr, node, aliasKind) {
1161
+ const call = unwrapCall(expr);
1160
1162
  if (!call) return;
1161
1163
  const direct = connectFactFromCall(call);
1162
1164
  if (direct)
1163
1165
  out.push({
1164
- variableName: decl.name.text,
1166
+ variableName: targetName,
1165
1167
  ...direct,
1166
1168
  sourceFile: normalizePath(filePath),
1167
- sourceLine: lineOf4(sourceFileAst, decl)
1169
+ sourceLine: lineOf4(sourceFileAst, node),
1170
+ helperChain: aliasKind === "assignment" ? [{ callerVariable: targetName, assignedFrom: call.expression.getText(sourceFileAst), aliasKind, scopeRule: "same-file-source-order" }] : void 0
1168
1171
  });
1169
1172
  else if (ts5.isIdentifier(call.expression)) {
1170
1173
  const resolved = await importedHelper(call.expression.text);
1171
1174
  if (resolved)
1172
1175
  out.push({
1173
- variableName: decl.name.text,
1176
+ variableName: targetName,
1174
1177
  alias: resolved.helper.alias,
1175
1178
  aliasExpr: resolved.helper.aliasExpr,
1176
1179
  destinationExpr: resolved.helper.destinationExpr,
@@ -1178,10 +1181,11 @@ async function parseServiceBindings(repoPath, filePath) {
1178
1181
  isDynamic: resolved.helper.isDynamic,
1179
1182
  placeholders: resolved.helper.placeholders,
1180
1183
  sourceFile: normalizePath(filePath),
1181
- sourceLine: lineOf4(sourceFileAst, decl),
1184
+ sourceLine: lineOf4(sourceFileAst, node),
1182
1185
  helperChain: [
1183
1186
  {
1184
- callerVariable: decl.name.text,
1187
+ callerVariable: targetName,
1188
+ ...aliasKind === "assignment" ? { assignedFrom: call.expression.text, aliasKind, scopeRule: "same-file-source-order" } : {},
1185
1189
  importedHelper: call.expression.text,
1186
1190
  importSource: resolved.imp.sourceFile,
1187
1191
  exportedSymbol: resolved.imp.exportedName,
@@ -1192,6 +1196,10 @@ async function parseServiceBindings(repoPath, filePath) {
1192
1196
  });
1193
1197
  }
1194
1198
  }
1199
+ async function recordVariable(decl) {
1200
+ if (!ts5.isIdentifier(decl.name) || !decl.initializer) return;
1201
+ await recordBindingFromExpression(decl.name.text, decl.initializer, decl, "declaration");
1202
+ }
1195
1203
  async function helpersForCall(call) {
1196
1204
  if (!ts5.isIdentifier(call.expression)) return [];
1197
1205
  const local = localObjectHelpers.get(call.expression.text) ?? [];
@@ -1224,6 +1232,39 @@ async function parseServiceBindings(repoPath, filePath) {
1224
1232
  });
1225
1233
  }
1226
1234
  }
1235
+ async function recordDestructuredAssignment(pattern, expr, node) {
1236
+ const call = unwrapCall(expr);
1237
+ if (!call) return;
1238
+ const helpers = await helpersForCall(call);
1239
+ if (helpers.length === 0) return;
1240
+ for (const prop of pattern.properties) {
1241
+ let propertyName;
1242
+ let targetName;
1243
+ if (ts5.isShorthandPropertyAssignment(prop)) {
1244
+ propertyName = prop.name.text;
1245
+ targetName = prop.name.text;
1246
+ } else if (ts5.isPropertyAssignment(prop)) {
1247
+ propertyName = ts5.isIdentifier(prop.name) || ts5.isStringLiteralLike(prop.name) ? prop.name.text : void 0;
1248
+ targetName = ts5.isIdentifier(prop.initializer) ? prop.initializer.text : void 0;
1249
+ }
1250
+ if (!propertyName || !targetName) continue;
1251
+ const matches = helpers.filter((row) => row.helper.returnedProperty === propertyName);
1252
+ if (matches.length !== 1) continue;
1253
+ const resolved = matches[0];
1254
+ out.push({
1255
+ variableName: targetName,
1256
+ alias: resolved.helper.alias,
1257
+ aliasExpr: resolved.helper.aliasExpr,
1258
+ destinationExpr: resolved.helper.destinationExpr,
1259
+ servicePathExpr: resolved.helper.servicePathExpr,
1260
+ isDynamic: resolved.helper.isDynamic,
1261
+ placeholders: resolved.helper.placeholders,
1262
+ sourceFile: normalizePath(filePath),
1263
+ sourceLine: lineOf4(sourceFileAst, node),
1264
+ helperChain: [{ callerVariable: targetName, assignedFrom: call.expression.getText(sourceFileAst), aliasKind: "assignment", scopeRule: "same-file-source-order", returnedProperty: propertyName, importSource: resolved.imp?.sourceFile, exportedSymbol: resolved.imp?.exportedName, helperSourceFile: resolved.helper.sourceFile, helperSourceLine: resolved.helper.sourceLine }]
1265
+ });
1266
+ }
1267
+ }
1227
1268
  function recordDestructuredClassHelper(decl) {
1228
1269
  if (!ts5.isObjectBindingPattern(decl.name) || !decl.initializer) return;
1229
1270
  const call = unwrapCall(decl.initializer);
@@ -1256,20 +1297,40 @@ async function parseServiceBindings(repoPath, filePath) {
1256
1297
  });
1257
1298
  }
1258
1299
  }
1259
- const declarations = [];
1260
- function collectDeclarations(node) {
1261
- if (ts5.isVariableDeclaration(node)) declarations.push(node);
1262
- ts5.forEachChild(node, collectDeclarations);
1263
- }
1264
- collectDeclarations(sourceFileAst);
1265
- for (const decl of declarations) {
1266
- await recordDestructuredHelper(decl);
1267
- recordDestructuredClassHelper(decl);
1268
- await recordVariable(decl);
1269
- recordIdentityAlias(decl);
1270
- if (ts5.isIdentifier(decl.name) && decl.initializer && ts5.isCallExpression(decl.initializer) && ts5.isPropertyAccessExpression(decl.initializer.expression) && decl.initializer.expression.name.text === "tx" && ts5.isIdentifier(decl.initializer.expression.expression)) {
1271
- cloneAliasBinding(decl, decl.initializer.expression.expression.text, "transaction");
1300
+ const events = [];
1301
+ function collectEvents(node) {
1302
+ if (ts5.isVariableDeclaration(node)) events.push({ pos: node.getStart(sourceFileAst), node });
1303
+ if (ts5.isBinaryExpression(node) && node.operatorToken.kind === ts5.SyntaxKind.EqualsToken)
1304
+ events.push({ pos: node.getStart(sourceFileAst), node });
1305
+ ts5.forEachChild(node, collectEvents);
1306
+ }
1307
+ collectEvents(sourceFileAst);
1308
+ events.sort((a, b) => a.pos - b.pos);
1309
+ for (const event of events) {
1310
+ if (ts5.isVariableDeclaration(event.node)) {
1311
+ const decl = event.node;
1312
+ await recordDestructuredHelper(decl);
1313
+ recordDestructuredClassHelper(decl);
1314
+ await recordVariable(decl);
1315
+ recordIdentityAlias(decl);
1316
+ if (ts5.isIdentifier(decl.name) && decl.initializer && ts5.isCallExpression(decl.initializer) && ts5.isPropertyAccessExpression(decl.initializer.expression) && decl.initializer.expression.name.text === "tx" && ts5.isIdentifier(decl.initializer.expression.expression)) {
1317
+ cloneAliasBinding(decl.name.text, decl.initializer.expression.expression.text, "transaction", decl);
1318
+ }
1319
+ continue;
1320
+ }
1321
+ const assignment = event.node;
1322
+ if (ts5.isIdentifier(assignment.left)) {
1323
+ const rhs = unwrapIdentityExpression(assignment.right);
1324
+ if (ts5.isIdentifier(rhs)) {
1325
+ cloneAliasBinding(assignment.left.text, rhs.text, "identity-assignment", assignment);
1326
+ continue;
1327
+ }
1328
+ await recordBindingFromExpression(assignment.left.text, assignment.right, assignment, "assignment");
1329
+ continue;
1272
1330
  }
1331
+ const left = ts5.isParenthesizedExpression(assignment.left) ? assignment.left.expression : assignment.left;
1332
+ if (ts5.isObjectLiteralExpression(left))
1333
+ await recordDestructuredAssignment(left, assignment.right, assignment);
1273
1334
  }
1274
1335
  return out;
1275
1336
  }
@@ -2372,4 +2433,4 @@ export {
2372
2433
  linkWorkspace,
2373
2434
  trace
2374
2435
  };
2375
- //# sourceMappingURL=chunk-JIY37C44.js.map
2436
+ //# sourceMappingURL=chunk-LCXDOSWL.js.map