@suss/adapter-ruby 0.24.1 → 0.24.2

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/index.cjs CHANGED
@@ -2944,7 +2944,7 @@ function clientCallUnits(root, pack, pattern, options) {
2944
2944
  continue;
2945
2945
  }
2946
2946
  for (const call of callsUnder(method)) {
2947
- const request = requestCall(call, method, pattern, options);
2947
+ const request = requestCall(call, method, root, pattern, options);
2948
2948
  if (request === null) {
2949
2949
  continue;
2950
2950
  }
@@ -2977,13 +2977,13 @@ function callsUnder(node, found = []) {
2977
2977
  }
2978
2978
  return found;
2979
2979
  }
2980
- function requestCall(call, method, pattern, options) {
2980
+ function requestCall(call, method, root, pattern, options) {
2981
2981
  const receiver = field(call, "receiver");
2982
2982
  const called = field(call, "method")?.text;
2983
2983
  if (receiver === null || called === void 0) {
2984
2984
  return null;
2985
2985
  }
2986
- const prefix = receiverPrefix(receiver, method, pattern, options);
2986
+ const prefix = receiverPrefix(receiver, method, root, pattern, options);
2987
2987
  if (prefix === null) {
2988
2988
  return null;
2989
2989
  }
@@ -3024,22 +3024,20 @@ function assignedCall(node, method) {
3024
3024
  const value = assignedValue(node.text, method);
3025
3025
  return value !== null && value.type === "call" ? value : null;
3026
3026
  }
3027
- function receiverPrefix(receiver, method, pattern, options) {
3027
+ function receiverPrefix(receiver, method, root, pattern, options) {
3028
3028
  if (namesConstant(receiver, pattern.constantName)) {
3029
3029
  return "";
3030
3030
  }
3031
3031
  if (receiver.type !== "identifier") {
3032
3032
  return null;
3033
3033
  }
3034
- const built = builtBy(receiver.text, method, pattern);
3034
+ const built = builtBy(receiver.text, method, root, pattern);
3035
3035
  if (built === null) {
3036
3036
  return null;
3037
3037
  }
3038
+ const args = readCallArgs(field(built, "arguments"));
3038
3039
  const keyword = pattern.builderUrlKeyword;
3039
- if (keyword === void 0) {
3040
- return "";
3041
- }
3042
- const base = readCallArgs(field(built, "arguments")).keyword[keyword];
3040
+ const base = (keyword === void 0 ? void 0 : args.keyword[keyword]) ?? args.positional[0];
3043
3041
  const path7 = base === void 0 ? null : (0, import_values5.pathOf)(evaluatedValue(base, options.facts));
3044
3042
  return path7 === void 0 || path7 === null ? "" : trimmed(path7);
3045
3043
  }
@@ -3049,15 +3047,36 @@ function trimmed(path7) {
3049
3047
  function namesConstant(receiver, constantName) {
3050
3048
  return (receiver.type === "constant" || receiver.type === "scope_resolution") && receiver.text === constantName;
3051
3049
  }
3052
- function builtBy(name, method, pattern) {
3050
+ function builtBy(name, method, root, pattern) {
3053
3051
  const builders = pattern.receiverBuilders ?? [];
3054
- const value = builders.length === 0 ? null : assignedValue(name, method);
3052
+ if (builders.length === 0) {
3053
+ return null;
3054
+ }
3055
+ const value = assignedValue(name, method) ?? valueMethodNamedReturns(name, root);
3055
3056
  if (value === null || value.type !== "call" || !builders.includes(field(value, "method")?.text ?? "")) {
3056
3057
  return null;
3057
3058
  }
3058
3059
  const receiver = field(value, "receiver");
3059
3060
  return receiver !== null && namesConstant(receiver, pattern.constantName) ? value : null;
3060
3061
  }
3062
+ function valueMethodNamedReturns(name, root) {
3063
+ const defined = methodDefinitions(root).find(
3064
+ (candidate) => field(candidate, "name")?.text === name
3065
+ );
3066
+ if (defined === void 0) {
3067
+ return null;
3068
+ }
3069
+ const body = field(defined, "body");
3070
+ const statements = body === null ? [] : body.namedChildren;
3071
+ const last = statements[statements.length - 1];
3072
+ if (last === void 0) {
3073
+ return null;
3074
+ }
3075
+ if (last.type === "operator_assignment" || last.type === "assignment") {
3076
+ return field(last, "right");
3077
+ }
3078
+ return last.type === "return" ? last.namedChildren[0] ?? null : last;
3079
+ }
3061
3080
  function assignedValue(name, method) {
3062
3081
  const body = field(method, "body");
3063
3082
  if (body === null) {
package/dist/index.js CHANGED
@@ -2906,7 +2906,7 @@ function clientCallUnits(root, pack, pattern, options) {
2906
2906
  continue;
2907
2907
  }
2908
2908
  for (const call of callsUnder(method)) {
2909
- const request = requestCall(call, method, pattern, options);
2909
+ const request = requestCall(call, method, root, pattern, options);
2910
2910
  if (request === null) {
2911
2911
  continue;
2912
2912
  }
@@ -2939,13 +2939,13 @@ function callsUnder(node, found = []) {
2939
2939
  }
2940
2940
  return found;
2941
2941
  }
2942
- function requestCall(call, method, pattern, options) {
2942
+ function requestCall(call, method, root, pattern, options) {
2943
2943
  const receiver = field(call, "receiver");
2944
2944
  const called = field(call, "method")?.text;
2945
2945
  if (receiver === null || called === void 0) {
2946
2946
  return null;
2947
2947
  }
2948
- const prefix = receiverPrefix(receiver, method, pattern, options);
2948
+ const prefix = receiverPrefix(receiver, method, root, pattern, options);
2949
2949
  if (prefix === null) {
2950
2950
  return null;
2951
2951
  }
@@ -2986,22 +2986,20 @@ function assignedCall(node, method) {
2986
2986
  const value = assignedValue(node.text, method);
2987
2987
  return value !== null && value.type === "call" ? value : null;
2988
2988
  }
2989
- function receiverPrefix(receiver, method, pattern, options) {
2989
+ function receiverPrefix(receiver, method, root, pattern, options) {
2990
2990
  if (namesConstant(receiver, pattern.constantName)) {
2991
2991
  return "";
2992
2992
  }
2993
2993
  if (receiver.type !== "identifier") {
2994
2994
  return null;
2995
2995
  }
2996
- const built = builtBy(receiver.text, method, pattern);
2996
+ const built = builtBy(receiver.text, method, root, pattern);
2997
2997
  if (built === null) {
2998
2998
  return null;
2999
2999
  }
3000
+ const args = readCallArgs(field(built, "arguments"));
3000
3001
  const keyword = pattern.builderUrlKeyword;
3001
- if (keyword === void 0) {
3002
- return "";
3003
- }
3004
- const base = readCallArgs(field(built, "arguments")).keyword[keyword];
3002
+ const base = (keyword === void 0 ? void 0 : args.keyword[keyword]) ?? args.positional[0];
3005
3003
  const path7 = base === void 0 ? null : pathOf(evaluatedValue(base, options.facts));
3006
3004
  return path7 === void 0 || path7 === null ? "" : trimmed(path7);
3007
3005
  }
@@ -3011,15 +3009,36 @@ function trimmed(path7) {
3011
3009
  function namesConstant(receiver, constantName) {
3012
3010
  return (receiver.type === "constant" || receiver.type === "scope_resolution") && receiver.text === constantName;
3013
3011
  }
3014
- function builtBy(name, method, pattern) {
3012
+ function builtBy(name, method, root, pattern) {
3015
3013
  const builders = pattern.receiverBuilders ?? [];
3016
- const value = builders.length === 0 ? null : assignedValue(name, method);
3014
+ if (builders.length === 0) {
3015
+ return null;
3016
+ }
3017
+ const value = assignedValue(name, method) ?? valueMethodNamedReturns(name, root);
3017
3018
  if (value === null || value.type !== "call" || !builders.includes(field(value, "method")?.text ?? "")) {
3018
3019
  return null;
3019
3020
  }
3020
3021
  const receiver = field(value, "receiver");
3021
3022
  return receiver !== null && namesConstant(receiver, pattern.constantName) ? value : null;
3022
3023
  }
3024
+ function valueMethodNamedReturns(name, root) {
3025
+ const defined = methodDefinitions(root).find(
3026
+ (candidate) => field(candidate, "name")?.text === name
3027
+ );
3028
+ if (defined === void 0) {
3029
+ return null;
3030
+ }
3031
+ const body = field(defined, "body");
3032
+ const statements = body === null ? [] : body.namedChildren;
3033
+ const last = statements[statements.length - 1];
3034
+ if (last === void 0) {
3035
+ return null;
3036
+ }
3037
+ if (last.type === "operator_assignment" || last.type === "assignment") {
3038
+ return field(last, "right");
3039
+ }
3040
+ return last.type === "return" ? last.namedChildren[0] ?? null : last;
3041
+ }
3023
3042
  function assignedValue(name, method) {
3024
3043
  const body = field(method, "body");
3025
3044
  if (body === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/adapter-ruby",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
4
4
  "type": "module",
5
5
  "description": "Read a Ruby codebase with suss and check what each Rails action or graphql-ruby resolver returns against the code that calls it.",
6
6
  "keywords": [
@@ -49,12 +49,12 @@
49
49
  "typecheck": "tsc --noEmit"
50
50
  },
51
51
  "dependencies": {
52
- "@suss/behavioral-ir": "0.24.1",
53
- "@suss/datalog": "0.24.1",
54
- "@suss/extractor": "0.24.1",
55
- "@suss/ir-core": "0.24.1",
56
- "@suss/resolution": "0.24.1",
57
- "@suss/values": "0.24.1",
52
+ "@suss/behavioral-ir": "0.24.2",
53
+ "@suss/datalog": "0.24.2",
54
+ "@suss/extractor": "0.24.2",
55
+ "@suss/ir-core": "0.24.2",
56
+ "@suss/resolution": "0.24.2",
57
+ "@suss/values": "0.24.2",
58
58
  "web-tree-sitter": "^0.26.11"
59
59
  },
60
60
  "devDependencies": {